Good.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\GoodLog;
  4. use think\App;
  5. use think\facade\Db;
  6. //线上商品
  7. class Good extends Base
  8. {
  9. private $acton=[
  10. "allotsend"=>'调拨发货',
  11. "allotin"=>'调拨入库',
  12. "allotincheck"=>'调拨验货',
  13. 'CGD'=>'采购单',
  14. 'BHD'=>'备库单',
  15. 'FKD'=>'备库反馈单',
  16. 'RKD'=>'入库单',
  17. 'ZXQRD'=>'咨询单',
  18. 'XSQRD'=>'销售单',
  19. 'PDD'=>'盘点单',
  20. 'DBD'=>'调拨单',
  21. 'CKD'=>'出库单',
  22. 'CGTHD'=>'采购退货单',
  23. 'XSTHD'=>'销售退货单',
  24. 'CGGCD'=>'采购工差单',
  25. 'ZXGCD'=>'咨询工差单'
  26. ];
  27. public $noble=[];
  28. public function __construct(App $app)
  29. {
  30. parent::__construct($app);
  31. $this->noble=\think\facade\Config::get("noble");
  32. }
  33. public function list(){
  34. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  35. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  36. $where =[["a.is_del","=",0]];
  37. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? trim($this->post['cat_id']):"";
  38. if($cat_id!==""){
  39. $where[]=['a.cat_id',"=",$cat_id];
  40. }
  41. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  42. if($good_name!==""){
  43. $where[]=['a.good_name',"like","%$good_name%"];
  44. }
  45. $skucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode'])
  46. :"";
  47. if($skucode!==""){
  48. $where [] = ['b.skucode',"like","%$skucode%"];
  49. }
  50. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  51. if($start!==""){
  52. $where[]=['a.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  53. }
  54. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  55. if($end!==""){
  56. $where[]=['a.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  57. }
  58. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !=="" ? intval($this->post['is_stock'])
  59. :"";
  60. if($is_stock!==""){
  61. $where[]=['is_stock',"=",$is_stock];
  62. }
  63. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? intval($this->post['good_type'])
  64. :"";
  65. if($good_type!==""){
  66. $where[]=['good_type',"=",$good_type];
  67. }
  68. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  69. :"";
  70. if($supplierNo!==""){
  71. $where[]=['a.supplierNo',"=",$supplierNo];
  72. }
  73. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :"";
  74. if($companyNo!==""){
  75. $where[]=['a.companyNo',"like","%$companyNo%"];
  76. }
  77. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  78. if($creater!==""){
  79. $where[]=['a.creater',"like","%$creater%"];
  80. }
  81. $createrid = isset($this->post['createrid']) && $this->post['createrid'] !=="" ? intval($this->post['createrid']):"";
  82. if($createrid!==""){
  83. $where[]=['a.createrid',"=",$createrid];
  84. }
  85. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
  86. :"";
  87. if($status!==""){
  88. $where[]=['a.status',"=",$status];
  89. }
  90. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code'])
  91. :"";
  92. if($platform_code!==""){
  93. //$platform = Db::name("good_platform")->where(["platform_code"=>$platform_code,"is_del"=>0])->column
  94. //("spuCode");
  95. $where[]=["platform_code","=",$platform_code];
  96. }
  97. $plat_code = isset($this->post['plat_code']) && $this->post['plat_code'] !=="" ? trim($this->post['plat_code'])
  98. :"";
  99. if($plat_code!==""){
  100. $where[]=["b.plat_code","like","%$plat_code%"];
  101. }
  102. $exam_status = isset($this->post['exam_status']) && $this->post['exam_status'] !=="" ? intval($this->post['exam_status'])
  103. :"";
  104. if($exam_status!==""){
  105. $where[]=['b.exam_status',"=",$exam_status];
  106. }
  107. $brand_id = isset($this->post['brand_id']) && $this->post['brand_id'] !=="" ? intval($this->post['brand_id'])
  108. :"";
  109. if($brand_id!==""){
  110. $where[]=['a.brand_id',"=",$brand_id];
  111. }
  112. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where($where)
  113. ->count();
  114. $total = ceil($count / $size);
  115. $page = $page >= $total ? $total : $page;
  116. $list = Db::name('good')
  117. ->alias("a")
  118. ->field("b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.*,b.addtime,b.updatetime,b.exam_status,gb.createrid purchase_id,gb.creater purchase")//成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  119. ->leftJoin("good_platform b","a.spuCode=b.spuCode")
  120. ->leftJoin("good_basic gb","gb.spuCode=a.spuCode")
  121. ->where($where)
  122. ->page($page,$size)
  123. ->order("b.addtime desc")
  124. ->select();
  125. $data=[];
  126. foreach ($list as $value){
  127. $value['cat_info']= made($value['cat_id'],[]);
  128. $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
  129. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
  130. $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en']:"";
  131. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  132. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  133. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  134. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  135. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  136. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  137. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  138. $value['company'] = isset($company['company'])?$company['company']:"";
  139. $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
  140. $value['status']=$value['exam_status'];
  141. $value['exclusive']=makeExcluse($value['is_exclusive']);
  142. $value['good_info_img']=$value['good_info_img'];
  143. $value['good_img']=$value['good_img'];
  144. $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
  145. $speclist=[];
  146. if(!empty($spec)){
  147. foreach ($spec as $val){
  148. $temp=[];
  149. $temp['spec_id']=$val['spec_id'];
  150. $temp['spec_value_id']=$val['spec_value_id'];
  151. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  152. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  153. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  154. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  155. $speclist[]=$temp;
  156. }
  157. }
  158. $value['specinfo']=$speclist;
  159. $value['noble_name']=isset($value['noble_metal'])&&$value['noble_metal']!=0?$this->noble[$value['noble_metal']] :"";
  160. $data[]=$value;
  161. }
  162. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  163. }
  164. public function info(){
  165. $skucode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
  166. if($skucode==""){
  167. return error_show(1005,"参数skuCode不能为空");
  168. }
  169. $good_platform = Db::name("good_platform")->where(['skuCode'=>$skucode,"is_del"=>0])->find();
  170. if($good_platform==false){
  171. return error_show(1004,"未找到商品数据");
  172. }
  173. $data = Db::name("good")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->find();
  174. if($data==false){
  175. return error_show(1004,"未找到商品数据");
  176. }
  177. $plat =Db::name("platform")->where(["id"=>$good_platform['platform_code']])->find();
  178. $data['skuCode']=$good_platform['skuCode'];
  179. $data['platform_code']=$good_platform['id'];
  180. $data['platform_code_en']=isset($plat['platform_code'])?$plat['platform_code']:"";
  181. $data['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  182. $data['online_reason']=$good_platform['online_reason'];
  183. $data['online_time']=$good_platform['online_time'];
  184. $data['online_remark']=$good_platform['online_remark'];
  185. $data['exam_status']=$good_platform['exam_status'];
  186. $data['is_online']=$good_platform['is_online'];
  187. $data['plat_code']=$good_platform['plat_code'];
  188. $data['exclusive']=makeExcluse($data['is_exclusive']);
  189. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  190. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  191. $data['cat_info'] = made($data['cat_id'],[]);
  192. $spec = Db::name("good_spec")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
  193. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  194. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  195. $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
  196. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  197. $data['company'] = isset($company['company'])?$company['company']:"";
  198. if($data['brand_id']!=0){
  199. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  200. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  201. }else{
  202. $data["brand_name"]="";
  203. $data["brand_id"]="";
  204. }
  205. $data['origin_place_cn']="";
  206. $data['delivery_place_cn']="";
  207. if($data['delivery_place']!==""){
  208. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  209. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['delivery_place']);
  210. $data['delivery_place_cn']=GetAddr(json_encode($place));
  211. }
  212. if($data['origin_place']!==""){
  213. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  214. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['origin_place']);
  215. $data['origin_place_cn']=GetAddr(json_encode($place));
  216. }
  217. $excluse = makeExcluse($data['is_exclusive']);
  218. $data['exclusive']=$excluse;
  219. $data["good_info_img"]=$data['good_info_img']!=""? $data['good_info_img']:[];
  220. $data["good_img"]=$data['good_img']!=""? $data['good_img']:[];
  221. $speclist=[];
  222. if(!empty($spec)){
  223. foreach ($spec as $value){
  224. $temp=[];
  225. $temp['id']=$value['id'];
  226. $temp['spuCode']=$value['spuCode'];
  227. $temp['spec_id']=$value['spec_id'];
  228. $temp['spec_value_id']=$value['spec_value_id'];
  229. $temp['is_del']=$value['is_del'];
  230. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  231. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  232. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  233. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  234. $speclist[]=$temp;
  235. }
  236. }
  237. $data["speclist"]=empty($speclist)?[]:$speclist;
  238. $ladder = Db::name("good_ladder")->where(['skuCode'=>$skucode,"is_del"=>0])->select()->toArray();
  239. $data["ladderlist"]=!empty($ladder)?$ladder:[];
  240. $nakelist = Db::name("good_nake")->where(['spuCode'=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
  241. $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  242. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  243. $nakearry=[];
  244. if(!empty($nakelist)){
  245. foreach ($nakelist as $value){
  246. $value['sale_price'] =$value['nake_total'];
  247. $nakearry[]=$value;
  248. }
  249. }
  250. $proof =Db::name("good_proof")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  251. $data['proof'] = isset($proof)&&$proof!=false? $proof:[];
  252. $data["nakelist"]=$nakearry;
  253. return app_show(0,"获取成功",$data);
  254. }
  255. public function SetWarn(){
  256. $condition=["is_del"=>0];
  257. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  258. if($wsm_code!=""){
  259. $condition["wsm_code"] = $wsm_code;
  260. }else{
  261. return error_show(1004,"参数wsm_code 不能为空");
  262. }
  263. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  264. if($type_code!=""){
  265. $condition["good_type_code"] = $type_code;
  266. }else{
  267. return error_show(1004,"参数type_code 不能为空");
  268. }
  269. $good= Db::name("good_stock")->where($condition)->find();
  270. if(empty($good)){
  271. return error_show(1005,"未找到数据");
  272. }
  273. $warn_stock = isset($this->post['warn_stock']) &&$this->post['warn_stock'] !=="" ? intval($this->post['warn_stock']):"";
  274. if($warn_stock===""){
  275. return error_show(1005,"参数warn_stock 不能为空");
  276. }
  277. $good['warn_stock'] = $warn_stock;
  278. $good['updatetime'] = date("Y-m-d H:i:s");
  279. $up= Db::name("good_stock")->save($good);
  280. if($up){
  281. //商品变动日志表,good_log_code字段存储仓库编码
  282. $data = ['good_log_code' => $wsm_code, "stock_id" => $good['id'], "type" => 1, 'stock' => $warn_stock, "stock_name" => "warn_stock"];
  283. GoodLog::LogAdd($this->post['token'],$data,'setwarn');
  284. return app_show(0,"预警库存更新成功");
  285. }else{
  286. return error_show(1005,"预警库存更新失败");
  287. }
  288. }
  289. public function SetStatus(){
  290. $id = isset($this->post['id']) &&$this->post['id'] !=="" ? intval($this->post['id']):"";
  291. if($id===""){
  292. return error_show(1005,"参数id 不能为空");
  293. }
  294. $good= Db::name("good_type")->where(["id"=>$id,"is_del"=>0])->find();
  295. if(empty($good)){
  296. return error_show(1005,"未找到数据");
  297. }
  298. $good['status'] = $good['status']==1?0 :1;
  299. $good['updatetime'] = date("Y-m-d H:i:s");
  300. $msg = $good['status']==1?"下架" :"上架";
  301. $up= Db::name("good_type")->save($good);
  302. return $up ? app_show(0,"商品{$msg}成功"): error_show(1005,"商品{$msg}失败");
  303. }
  304. public function GetStock(){
  305. $condition = [["a.is_del","=",0]];
  306. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  307. if($type_code!==""){
  308. $condition[]=["a.spuCode","=",$type_code];
  309. }
  310. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  311. :"";
  312. if($wsm_code!==""){
  313. //$condition["a.wsm_code"]=$wsm_code;
  314. $condition[]=["a.wsm_code","=",$type_code];
  315. }
  316. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  317. :"";
  318. if($suplierNo!==""){
  319. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  320. $condition[]=["a.wsm_code","in",$wsmcode];
  321. }
  322. $list = Db::name("good_stock")->alias("a")->join("warehouse_info b","a.wsm_code=b.wsm_code","left")->join("supplier c","b.supplierNo=c.code","left")
  323. ->where($condition)->field("a.id,b.name as wsm_name,c.code,c.name,a.wait_in_stock,a.wait_out_stock,a.usable_stock,a.intra_stock,a.total_stock,a.status,a.warn_stock")->select();
  324. if(empty($list)){
  325. return error_show(1004,"未找到数据");
  326. }
  327. return app_show(0,"获取成功",$list);
  328. }
  329. /**
  330. * @return \think\response\Json|void
  331. * @throws \think\db\exception\DataNotFoundException
  332. * @throws \think\db\exception\DbException
  333. * @throws \think\db\exception\ModelNotFoundException
  334. */
  335. public function GetStockBet(){
  336. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  337. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  338. $condition = [["is_del","=",0]];
  339. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  340. if($type_code!==""){
  341. $condition[]=["spuCode","like","%{$type_code}%"];
  342. }
  343. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  344. :"";
  345. if($wsm_code!==""){
  346. $condition[]=["wsm_code","=",$wsm_code];
  347. }
  348. $suplierNo = isset($this->post['suplierNo']) &&$this->post['suplierNo'] !=="" ? trim($this->post['suplierNo']):"";
  349. if($suplierNo!==""){
  350. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  351. $condition[]=["wsm_code","in",$wsmcode];
  352. }
  353. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  354. if ($companyNo !== "") {
  355. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  356. $condition[]=["wsm_code","in",$wsmcode];
  357. }
  358. $start = isset($this->post['start']) &&$this->post['start'] !=="" ? $this->post['start']:"";
  359. $end = isset($this->post['end']) &&$this->post['end'] !=="" ? $this->post['end']:"";
  360. if($start!=""){
  361. $condition[]=["addtime",">=",$start];
  362. }
  363. if($end!=""){
  364. $condition[]=["addtime","<=",$end];
  365. }
  366. $count = Db::name("good_stock")->where($condition)->count();
  367. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  368. $list = Db::name("good_stock")->where($condition)->page($page,$size)->order("addtime desc")->select();
  369. $data=[];
  370. foreach ($list as $key=>$value){
  371. $temp=[];
  372. if($value['wsm_code']!=""){
  373. $wsm = Db::name("warehouse_info")
  374. ->alias("a")
  375. ->leftJoin("supplier b","a.supplierNo=b.code")
  376. ->leftJoin("business bus","a.companyNo=bus.companyNo")
  377. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  378. ->field("a.name as wsm_name,wsm_code,a.supplierNo,b.name supplierName,a.companyNo,bus.company")
  379. ->find();
  380. }
  381. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  382. $temp['wsm_code']=$value['wsm_code'];
  383. $temp['supplier_code']=isset($wsm['supplierNo'])?$wsm['supplierNo']:"";
  384. $temp['supplier_name']=isset($wsm['supplierName'])?$wsm['supplierName']:"";
  385. $temp['company_no']=isset($wsm['companyNo'])?$wsm['companyNo']:"";
  386. $temp['company_name']=isset($wsm['company'])?$wsm['company']:"";
  387. if($value['spuCode']!=""){
  388. $good=Db::name("good")
  389. ->alias('g')
  390. ->field('g.*,b.brand_name,u.unit')
  391. ->where(["g.spuCode"=>$value['spuCode'],"g.is_del"=>0])
  392. ->leftJoin('brand b','b.id=g.brand_id')
  393. ->leftJoin('unit u','u.id=g.good_unit')
  394. ->find();
  395. //规格信息
  396. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  397. $speclist = [];
  398. if (!empty($spec)) {
  399. foreach ($spec as $val) {
  400. $tmp = [];
  401. $tmp['spec_id'] = $val['spec_id'];
  402. $tmp['spec_value_id'] = $val['spec_value_id'];
  403. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  404. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  405. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  406. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  407. $speclist[] = $tmp;
  408. }
  409. }
  410. $temp['specinfo'] = $speclist;
  411. }
  412. $temp['good_code']=isset($good['spuCode'])?$good['spuCode']:"";
  413. // $temp['type_code']=isset($good['type_code'])?$good['type_code']:"";
  414. $temp['good_name']=isset($good['good_name'])?$good['good_name']:"";
  415. $temp['unit']=isset($good['unit'])?$good['unit']:"";
  416. $temp['brand_name']=isset($good['brand_name'])?$good['brand_name']:"";
  417. // $temp['attribute']=isset($good['attribute'])?$good['attribute']:"";
  418. $temp['sort_f']=isset($good['cat_id'])?$good['cat_id']:"";
  419. $temp['cat_info']=isset($good['cat_id'])?made($good['cat_id']):"";
  420. $temp['usable_stock'] = $value['usable_stock'];
  421. $temp['wait_in_stock'] = $value['wait_in_stock'];
  422. $temp['wait_out_stock'] = $value['wait_out_stock'];
  423. $temp['intra_stock'] = $value['intra_stock'];
  424. $temp['total_stock'] = $value['total_stock'];
  425. $temp['warn_stock'] = $value['warn_stock'];
  426. $temp['id'] = $value['id'];
  427. $temp['out_total'] =0;
  428. $temp['in_total'] = 0;
  429. $temp['addtime'] = $value['addtime'];
  430. $data[]=$temp;
  431. }
  432. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  433. }
  434. /**
  435. * @return \think\response\Json|void
  436. * @throws \think\db\exception\DataNotFoundException
  437. * @throws \think\db\exception\DbException
  438. * @throws \think\db\exception\ModelNotFoundException
  439. * @throws \think\exception\DbException
  440. */
  441. public function GetStockWsm(){
  442. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  443. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  444. $condition = [["is_del","=",0]];
  445. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  446. if($wsm_code!==""){
  447. $condition[]=["wsm_code","=",$wsm_code];
  448. }
  449. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  450. if($suplierNo!==""){
  451. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  452. $condition[]=["wsm_code","in",$wsmcode];
  453. }
  454. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  455. if ($companyNo !== "") {
  456. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  457. $condition[]=["wsm_code","in",$wsmcode];
  458. }
  459. $build= Db::name("good_stock")->where($condition)->group("wsm_code")->field("wsm_code")->buildSql();
  460. $count = Db::table($build." a")->count();
  461. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  462. $list = Db::name("good_stock")
  463. ->where($condition)
  464. ->page($page,$size)
  465. ->group("wsm_code")
  466. ->field("wsm_code,sum(wait_in_stock) wait_in_stock,sum(wait_out_stock) wait_out_stock,sum(usable_stock) usable_stock,sum(intra_stock) intra_stock,sum(warn_stock) warn_stock,sum(total_stock) total_stock")
  467. ->select()
  468. ->toArray();
  469. $data=[];
  470. foreach ($list as $key=>$value){
  471. $temp=[];
  472. if($value['wsm_code']!=""){
  473. $wsm = Db::name("warehouse_info")
  474. ->alias("a")
  475. ->leftJoin("business bus", "bus.companyNo=a.companyNo")
  476. ->leftJoin("supplier b","a.supplierNo=b.code")
  477. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  478. ->field("a.name as wsm_name,wsm_code,a.supplierNo,b.name supplierName,a.companyNo,bus.company")
  479. ->find();
  480. $good = Db::name("good_stock")
  481. ->alias("a")
  482. ->leftJoin("good c","c.spuCode=a.spuCode")
  483. ->where(["a.wsm_code"=>$value['wsm_code'],"a.is_del"=>0,"c.is_del"=>0])
  484. ->select()
  485. ->toArray();
  486. //商品单位和品牌
  487. $good_unit_s = Db::name("unit")->whereIn('id', array_column($good, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
  488. $brands = Db::name("brand")->whereIn('id', array_column($good, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
  489. foreach ($good as &$item_good){
  490. //规格信息
  491. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $item_good['spuCode'], "is_del" => 0])->select()->toArray();
  492. $speclist = [];
  493. if (!empty($spec)) {
  494. foreach ($spec as $val) {
  495. $tmp = [];
  496. $tmp['spec_id'] = $val['spec_id'];
  497. $tmp['spec_value_id'] = $val['spec_value_id'];
  498. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  499. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  500. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  501. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  502. $speclist[] = $tmp;
  503. }
  504. }
  505. $item_good['specinfo'] = $speclist;
  506. $item_good['unit'] = $good_unit_s[$item_good['good_unit']]??'';
  507. $item_good['brand_name'] = $brands[$item_good['brand_id']]??'';
  508. $item_good['can'] = made($item_good['cat_id'],[]);
  509. }
  510. }
  511. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  512. $temp['wsm_code']=$value['wsm_code'];
  513. $temp['supplier_code']=isset($wsm['supplierNo'])?$wsm['supplierNo']:"";
  514. $temp['supplier_name']=isset($wsm['supplierName'])?$wsm['supplierName']:"";
  515. $temp['company_no']=isset($wsm['companyNo'])?$wsm['companyNo']:"";
  516. $temp['company_name']=isset($wsm['company'])?$wsm['company']:"";
  517. $temp['usable_stock'] = $value['usable_stock'];
  518. $temp['wait_in_stock'] = $value['wait_in_stock'];
  519. $temp['wait_out_stock'] = $value['wait_out_stock'];
  520. $temp['intra_stock'] = $value['intra_stock'];
  521. $temp['total_stock'] = $value['total_stock'];
  522. // $temp['warn_stock'] = $value['warn_stock'];
  523. $temp['child']=isset($good)&&!empty($good) ? $good:[];
  524. $data[]=$temp;
  525. }
  526. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  527. }
  528. public function GetStockGod(){
  529. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  530. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  531. $condition = [["b.is_del","=",0],["c.usable_stock",">",0]];
  532. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  533. if($type_code!==""){
  534. $condition[]=["b.spuCode","like","%{$type_code}%"];
  535. }
  536. $count = Db::name("good")->alias("b")
  537. ->join("good_stock c","c.spuCode = b.spuCode","left")
  538. ->where($condition)
  539. ->group("b.spuCode,b.good_name,b.good_unit,b.cat_id,b.craft_desc,b.addtime")
  540. ->count();
  541. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  542. $list = Db::name("good")
  543. ->alias("b")
  544. ->join("good_stock c","c.spuCode = b.spuCode","left")
  545. ->where($condition)
  546. ->field("b.spuCode,b.good_name,b.good_unit,b.brand_id,b.cat_id,b.craft_desc,b.addtime,sum(c.wait_in_stock) wait_in_stock,sum(c.wait_out_stock) wait_out_stock,sum(c.usable_stock) usable_stock,sum(c.intra_stock) intra_stock,sum(c.warn_stock) warn_stock,sum(c.total_stock) total_stock")
  547. ->page($page,$size)
  548. ->order("b.addtime desc")
  549. ->group("b.spuCode,b.good_name,b.good_unit,b.brand_id,b.cat_id,b.craft_desc,b.addtime")
  550. ->select()
  551. ->toArray();
  552. // echo Db::name("good_type")->getLastSql();
  553. $data=[];
  554. if($list) {
  555. //商品单位和品牌
  556. $good_unit_s = Db::name("unit")->whereIn('id', array_column($list, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
  557. $brands = Db::name("brand")->whereIn('id', array_column($list, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
  558. foreach ($list as $key => $value) {
  559. $temp = [];
  560. if ($value['spuCode'] != "") {
  561. $child = Db::name("good_stock")
  562. ->alias("a")
  563. ->join("warehouse_info b", "a.wsm_code=b.wsm_code", "left")
  564. ->join("business bus", "bus.companyNo=b.companyNo", "left")
  565. ->join("supplier s", "s.code=b.supplierNo", "left")
  566. ->where(['a.spuCode' => $value['spuCode'], "b.wsm_type" => 1, "a.is_del" => 0])
  567. ->field("a.wsm_code,b.name wsm_name,a.wait_in_stock,a.wait_out_stock,a.usable_stock,a.intra_stock,a.total_stock,a.warn_stock,b.supplierNo,s.name supplierName,b.companyNo,bus.company")
  568. ->select()
  569. ->toArray();
  570. }
  571. $temp['good_name'] = $value['good_name'];
  572. $temp['good_code'] = $value['spuCode'];
  573. $temp['type_code'] = '';
  574. // $unit = Db::name("unit")->where(['id' => $value['good_unit']])->find();
  575. $temp['unit'] =$good_unit_s[$value['spuCode']]??'';
  576. $temp['brand_name'] =$brands[$value['brand_id']]??'';
  577. $temp['sort_f'] = isset($value['cat_id']) ? made($value['cat_id']) : [];
  578. $temp['sort_f'] = implode('/', array_column($temp['sort_f'], 'name'));//由于这个字段原样在页面显示,所以在这里特意拼接成字符串
  579. $temp['attribute'] = $value['craft_desc'];
  580. $temp['addtime'] = $value['addtime'];
  581. $temp['usable_stock'] = isset($value['usable_stock']) ? $value['usable_stock'] : "";
  582. $temp['wait_in_stock'] = isset($value['wait_in_stock']) ? $value['wait_in_stock'] : "";
  583. $temp['wait_out_stock'] = isset($value['wait_out_stock']) ? $value['wait_out_stock'] : "";
  584. $temp['intra_stock'] = isset($value['intra_stock']) ? $value['intra_stock'] : "";
  585. $temp['total_stock'] = isset($value['total_stock']) ? $value['total_stock'] : "";
  586. // $temp['warn_stock'] = isset($value['warn_stock'])? $value['warn_stock']:"";
  587. $temp['child'] = isset($child) && !empty($child) ? $child : [];
  588. //规格信息
  589. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  590. $speclist = [];
  591. if (!empty($spec)) {
  592. foreach ($spec as $val) {
  593. $tmp = [];
  594. $tmp['spec_id'] = $val['spec_id'];
  595. $tmp['spec_value_id'] = $val['spec_value_id'];
  596. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  597. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  598. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  599. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  600. $speclist[] = $tmp;
  601. }
  602. }
  603. $temp['specinfo'] = $speclist;
  604. $data[] = $temp;
  605. }
  606. }
  607. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  608. }
  609. /**
  610. * @return \think\response\Json|void
  611. * @throws \think\db\exception\DataNotFoundException
  612. * @throws \think\db\exception\DbException
  613. * @throws \think\db\exception\ModelNotFoundException
  614. */
  615. public function Stat(){
  616. $condition =[["is_del","=",0]];
  617. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  618. if($wsm_code!=""){
  619. //$condition["wsm_code"] = $wsm_code;
  620. $condition[]=["wsm_code","=",$wsm_code];
  621. }
  622. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  623. if($suplierNo!==""){
  624. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  625. $condition[]=["wsm_code","in",$wsmcode];
  626. }
  627. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  628. if ($companyNo !== "") {
  629. // $where['khNo'] = $khNo;
  630. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  631. $condition[]=["wsm_code","in",$wsmcode];
  632. }
  633. // $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  634. // if($type_code!=""){
  635. // $condition[] = ["good_type_code","=",$type_code];
  636. // }
  637. $statlist = Db::name("good_stock")->where($condition)->field("sum(wait_in_stock) as wait_in_stock,sum(wait_out_stock) as wait_out_stock ,sum(usable_stock) as usable_stock,sum(intra_stock) as intra_stock,sum(total_stock) as total_stock,sum(warn_stock) as warn_stock")->find();
  638. return app_show(0,"获取成功",$statlist);
  639. }
  640. public function all(){
  641. $condtion=["a.is_del"=>0,"b.is_del"=>0];
  642. $wsmcode =isset($this->post['wsmcode']) &&$this->post['wsmcode'] !=="" ? trim($this->post['wsmcode']):"";
  643. if($wsmcode!=""){
  644. $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code");
  645. $condtion["b.type_code"] = $typecode;
  646. }
  647. $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  648. if($good_code!=""){
  649. $condtion['b.type_code'] = $good_code;
  650. }
  651. $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code'])
  652. :"";
  653. if($goodcode!=""){
  654. $condtion['a.good_code'] = $goodcode;
  655. }
  656. $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name'])
  657. :"";
  658. if($good_name!=""){
  659. $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'");
  660. }
  661. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  662. if($supplierNo!=""){
  663. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  664. if(empty($supplier)){
  665. return error_show(1004,"未找到供应商信息");
  666. }
  667. $condtion["a.gys_code"] = $supplierNo;
  668. }
  669. $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  670. ->where($condtion)->field("b.id,a.good_code,a.good_name,a.good_desc,a.brand,a.original_price,a.cg_saler,a.good_type,a.market_fee,a.gys_code,a.unit,
  671. a.sort_f,a.sort_s,a.sort_t,b.color,b.material,b.specs,b.is_main,b.type_code,b.attribute,b.status as bstatus,a.addtime,a.updatetime")
  672. ->select();
  673. $data=[];
  674. foreach ($list as $key=>$value){
  675. $stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock");
  676. $value['usable_stock']=$stock;
  677. $supplier = Db::name("supplier")->where(["code"=>$value['gys_code']])->find();
  678. $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
  679. $data[]=$value;
  680. }
  681. return app_show(0,"获取成功",$data);
  682. }
  683. public function loglist(){
  684. $page = isset($this->post['page']) && $this->post['page']!==""? intval($this->post['page']) :"1";
  685. $size = isset($this->post['size']) && $this->post['size']!==""? intval($this->post['size']) :"10";
  686. $where=[];
  687. $wsm_code= isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  688. if($wsm_code!=""){
  689. $where[]=['b.wsm_code',"like","%$wsm_code%"];
  690. }
  691. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  692. if($supplierNo!=""){
  693. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  694. if(empty($supplier)){
  695. return error_show(1004,"未找到供应商信息");
  696. }
  697. $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"supplierNo"=>$supplierNo])->column("wsm_code");
  698. $where[]=['b.wsm_code',"in",$wsmcode];
  699. }
  700. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  701. if ($companyNo !== "") {
  702. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  703. $condition[]=["b.wsm_code","in",$wsmcode];
  704. }
  705. $count = Db::name("good_log")
  706. ->alias('a')
  707. ->join("good_stock b","b.id=a.id","left")
  708. ->where($where)
  709. ->count();
  710. $total = ceil($count/$size);
  711. $page = $total>=$page ? $page :$total;
  712. $list = Db::name("good_log")
  713. ->alias('a')
  714. ->join("good_stock b","b.id=a.stock_id","left")
  715. ->where($where)
  716. ->page($page,$size)
  717. ->order("a.addtime desc")
  718. ->field("a.good_log_code,a.action_name,a.type,a.stock_name,a.stock,a.action_type,b.spuCode,a.addtime,a.action_uid,b.wsm_code")
  719. ->select()
  720. ->toArray();
  721. $data=[];
  722. $action_uids = array_column($list, 'action_uid');
  723. $action_uids = array_unique($action_uids);
  724. $item = [];
  725. foreach ($action_uids as $action_uid) {
  726. $items = Db::name("depart_user")->where('uid', $action_uid)->column("itemid");
  727. foreach ($items as $it) {
  728. $item[$action_uid][] = implode('/', array_column(GetPart($it), 'name'));
  729. }
  730. }
  731. foreach ($list as $value){
  732. $wsm = Db::name("warehouse_info")
  733. ->alias("a")
  734. ->Join("supplier b","a.supplierNo=b.code","left")
  735. ->Join("business bus","bus.companyNo=a.companyNo","left")
  736. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  737. ->field("a.name as wsm_name,wsm_code,b.code,b.name,bus.company,bus.companyNo")
  738. ->find();
  739. $godd =Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  740. $value['good_name']=isset($godd['good_name'])? $godd['good_name']:"";
  741. $value['cat_id']=isset($godd['cat_id'])? $godd['cat_id']:"";
  742. $int = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  743. $value['wsm_name'] =$wsm['wsm_name'];
  744. $value['wsm_code'] =$wsm['wsm_code'];
  745. $value['code'] =$wsm['code'];
  746. $value['name'] =$wsm['name'];
  747. $value['action_type_cn'] =$this->acton[$value['action_type']];
  748. $value['item'] =$item[$value['action_uid']];
  749. $value['can'] =$int;
  750. $value['company'] =$wsm['company']??'';
  751. $value['companyNo'] =$wsm['companyNo']??'';
  752. $data[]=$value;
  753. }
  754. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  755. }
  756. public function goodlist(){
  757. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  758. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  759. $where =[["a.is_del","=",0],["b.exam_status","=",6],["b.is_del","=",0],["c.is_del","=",0],["c.status","=",1]];
  760. $paltcode = isset($this->post["platform_code"])&& $this->post["platform_code"]!=""? trim($this->post["platform_code"]):"";
  761. if($paltcode!=""){
  762. $where[]=["platform_code","=",$paltcode];
  763. }
  764. $companyNo = isset($this->post["companyNo"])&& $this->post["companyNo"]!=""? trim($this->post["companyNo"])
  765. :"";
  766. if($companyNo!=""){
  767. $where[]=["companyNo","like","%$companyNo%"];
  768. }
  769. $cat_id = isset($this->post["cat_id"])&& $this->post["cat_id"]!==""? intval($this->post["cat_id"]):"";
  770. if($cat_id!==""){
  771. $where[]=["cat_id","=",$cat_id];
  772. }
  773. $buy_num = isset($this->post["buy_num"])&& $this->post["buy_num"]!==""? intval($this->post["buy_num"]):"";
  774. if($buy_num!==""){
  775. $where[]=["min_num","<=",$buy_num];
  776. }
  777. $price = isset($this->post["price"])&& $this->post["price"]!==""? floatval($this->post["price"]):"";
  778. if($buy_num!==""){
  779. $where[]=["sale_price","<=",$price];
  780. }
  781. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->leftJoin("good_ladder c","b.skuCode=c.skuCode")
  782. ->where($where)->count();
  783. $total = ceil($count / $size);
  784. $page = $page >= $total ? $total : $page;
  785. $list = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->leftJoin("good_ladder c","b.skuCode=c.skuCode")->where($where)->page
  786. ($page,$size)->field("c.id,c.min_num,c.sale_price,.a.good_name,a.spuCode,a.cat_id,a.brand_id,a.companyNo,a.supplierNo,a.good_unit,b.skuCode,b.platform_code,b.plat_code,b.id as good_id,b.addtime,b.updatetime,b.exam_status")
  787. ->order("b.addtime desc")
  788. ->select();
  789. $data=[];
  790. foreach ($list as $value){
  791. $value['cat_info']= made($value['cat_id'],[]);
  792. $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
  793. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
  794. $value['platform_code_en'] = isset($platform['platform_code']) ? $platform['platform_code']:"";
  795. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  796. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  797. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  798. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  799. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  800. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  801. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  802. $value['company'] = isset($company['company'])?$company['company']:"";
  803. $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
  804. $value['status']=$value['exam_status'];
  805. $data[]=$value;
  806. }
  807. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  808. }
  809. }