Good.php 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\GoodLog;
  4. use think\App;
  5. use think\db\Raw;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. //线上商品
  9. class Good extends Base
  10. {
  11. private $acton=[];
  12. public $noble=[];
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. $this->noble=\think\facade\Config::get("noble");
  17. $order=\think\facade\Config::get("order");
  18. $this->acton=$order['order_type'];
  19. }
  20. public function list(){
  21. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  22. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  23. $where =[["a.is_del","=",0]];
  24. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? trim($this->post['cat_id']):"";
  25. if($cat_id!==""){
  26. $where[]=['a.cat_id',"=",$cat_id];
  27. }
  28. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  29. if($good_name!==""){
  30. $where[]=['a.good_name',"like","%$good_name%"];
  31. }
  32. $skucode = isset($this->post['skucode']) && $this->post['skucode'] !=="" ? trim($this->post['skucode']):"";
  33. if($skucode!==""){
  34. $where [] = ['b.skucode',"like","%$skucode%"];
  35. }
  36. $spucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode']):"";
  37. if($spucode!==""){
  38. $where [] = ['b.spucode',"like","%$spucode%"];
  39. }
  40. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  41. if($start!==""){
  42. $where[]=['b.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  43. }
  44. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  45. if($end!==""){
  46. $where[]=['b.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  47. }
  48. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !=="" ? intval($this->post['is_stock'])
  49. :"";
  50. if($is_stock!==""){
  51. $where[]=['a.is_stock',"=",$is_stock];
  52. }
  53. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? intval($this->post['good_type'])
  54. :"";
  55. if($good_type!==""){
  56. $where[]=['a.good_type',"=",$good_type];
  57. }
  58. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  59. :"";
  60. if($supplierNo!==""){
  61. $where[]=['a.supplierNo',"=",$supplierNo];
  62. }
  63. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :"";
  64. if($companyNo!==""){
  65. $where[]=['a.companyNo',"like","%$companyNo%"];
  66. }
  67. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  68. if($creater!==""){
  69. $where[]=['a.creater',"like","%$creater%"];
  70. }
  71. $createrid = isset($this->post['createrid']) && $this->post['createrid'] !=="" ? intval($this->post['createrid']):"";
  72. if($createrid!==""){
  73. $where[]=['a.createrid',"=",$createrid];
  74. }
  75. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
  76. :"";
  77. if($status!==""){
  78. $where[]=['a.status',"=",$status];
  79. }
  80. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code'])
  81. :"";
  82. if($platform_code!==""){
  83. //$platform = Db::name("good_platform")->where(["platform_code"=>$platform_code,"is_del"=>0])->column
  84. //("spuCode");
  85. $where[]=["platform_code","=",$platform_code];
  86. }
  87. $plat_code = isset($this->post['plat_code']) && $this->post['plat_code'] !=="" ? trim($this->post['plat_code'])
  88. :"";
  89. if($plat_code!==""){
  90. $where[]=["b.plat_code","like","%$plat_code%"];
  91. }
  92. $exam_status = isset($this->post['exam_status']) && $this->post['exam_status'] !=="" ? intval($this->post['exam_status'])
  93. :"";
  94. if($exam_status!==""){
  95. $where[]=['b.exam_status',"=",$exam_status];
  96. }
  97. $brand_id = isset($this->post['brand_id']) && $this->post['brand_id'] !=="" ? intval($this->post['brand_id'])
  98. :"";
  99. if($brand_id!==""){
  100. $where[]=['a.brand_id',"=",$brand_id];
  101. }
  102. $role=$this->checkRole();
  103. if(!empty($role['write']) ){
  104. $where[]=["a.createrid","in",$role['write']];
  105. }
  106. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  107. if ($company_name !== "") $where[] = ["a.createrid", 'in', get_company_item_user_by_name($company_name)];
  108. // if(!empty($role['platform']) ){
  109. // $where[]=["b.platform_code","in",$role['platform']];
  110. // }
  111. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where($where)
  112. ->count();
  113. $total = ceil($count / $size);
  114. $page = $page >= $total ? $total : $page;
  115. $list = Db::name('good')
  116. ->alias("a")
  117. ->field("b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.cat_id,a.good_name,a.good_img,a.good_info_img,a.good_thumb_img,b.createrid,a.is_exclusive,a.brand_id,a.supplierNo,a.good_unit,a.noble_metal,a.companyNo,a.spuCode,a.good_type,b.creater,b.addtime,b.updatetime,b.exam_status,a.createrid purchase_id,a.creater purchase,u.itemid")//成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  118. ->leftJoin("good_platform b","a.spuCode=b.spuCode")
  119. // ->leftJoin("good_basic gb","gb.spuCode=a.spuCode")
  120. ->leftJoin("depart_user u", "u.uid=a.createrid AND u.is_del=0")
  121. ->where($where)
  122. ->page($page,$size)
  123. ->order("b.addtime desc")
  124. ->cursor();
  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. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  161. $data[]=$value;
  162. }
  163. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  164. }
  165. //获取跟有赞对接的平台所属的商品上线信息
  166. public function listByYz(){
  167. $param = $this->request->only([
  168. 'page'=>1,
  169. 'size'=>10,
  170. 'cat_id'=>'',
  171. 'good_name'=>'',
  172. 'skucode'=>'',
  173. 'spucode'=>'',
  174. 'start'=>'',
  175. 'end'=>'',
  176. ''=>'',
  177. ''=>'',
  178. ],'post','trim');
  179. // $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  180. // $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  181. $where =[["a.is_del","=",0]];
  182. // $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? trim($this->post['cat_id']):"";
  183. if($param['cat_id']!=="") $where[]=['a.cat_id',"=",$param['cat_id']];
  184. // $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  185. if($param['good_name']!=="") $where[]=['a.good_name','like','%'.$param['good_name'].'%'];
  186. // $skucode = isset($this->post['skucode']) && $this->post['skucode'] !=="" ? trim($this->post['skucode']):"";
  187. if($param['skucode']!=='') $where [] = ['b.skucode','like','%'.$param['skucode'].'%'];
  188. // $spucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode']):"";
  189. if($param['spucode']!=='') $where [] = ['b.spucode','like','%'.$param['spucode'].'%'];
  190. // $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  191. if($param['start']!=='') $where[]=['b.addtime','>=',date('Y-m-d H:i:s',strtotime($param['start']))];
  192. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  193. if($end!==""){
  194. $where[]=['b.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  195. }
  196. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !=="" ? intval($this->post['is_stock'])
  197. :"";
  198. if($is_stock!==""){
  199. $where[]=['a.is_stock',"=",$is_stock];
  200. }
  201. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? intval($this->post['good_type'])
  202. :"";
  203. if($good_type!==""){
  204. $where[]=['a.good_type',"=",$good_type];
  205. }
  206. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  207. :"";
  208. if($supplierNo!==""){
  209. $where[]=['a.supplierNo',"=",$supplierNo];
  210. }
  211. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :"";
  212. if($companyNo!==""){
  213. $where[]=['a.companyNo',"like","%$companyNo%"];
  214. }
  215. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  216. if($creater!==""){
  217. $where[]=['a.creater',"like","%$creater%"];
  218. }
  219. $createrid = isset($this->post['createrid']) && $this->post['createrid'] !=="" ? intval($this->post['createrid']):"";
  220. if($createrid!==""){
  221. $where[]=['a.createrid',"=",$createrid];
  222. }
  223. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
  224. :"";
  225. if($status!==""){
  226. $where[]=['a.status',"=",$status];
  227. }
  228. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code'])
  229. :"";
  230. if($platform_code!==""){
  231. //$platform = Db::name("good_platform")->where(["platform_code"=>$platform_code,"is_del"=>0])->column
  232. //("spuCode");
  233. $where[]=["platform_code","=",$platform_code];
  234. }
  235. $plat_code = isset($this->post['plat_code']) && $this->post['plat_code'] !=="" ? trim($this->post['plat_code'])
  236. :"";
  237. if($plat_code!==""){
  238. $where[]=["b.plat_code","like","%$plat_code%"];
  239. }
  240. $exam_status = isset($this->post['exam_status']) && $this->post['exam_status'] !=="" ? intval($this->post['exam_status'])
  241. :"";
  242. if($exam_status!==""){
  243. $where[]=['b.exam_status',"=",$exam_status];
  244. }
  245. $brand_id = isset($this->post['brand_id']) && $this->post['brand_id'] !=="" ? intval($this->post['brand_id'])
  246. :"";
  247. if($brand_id!==""){
  248. $where[]=['a.brand_id',"=",$brand_id];
  249. }
  250. $role=$this->checkRole();
  251. if(!empty($role['write']) ){
  252. $where[]=["a.createrid","in",$role['write']];
  253. }
  254. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  255. if ($company_name !== "") $where[] = ["a.createrid", 'in', get_company_item_user_by_name($company_name)];
  256. // if(!empty($role['platform']) ){
  257. // $where[]=["b.platform_code","in",$role['platform']];
  258. // }
  259. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where($where)
  260. ->count();
  261. $total = ceil($count / $size);
  262. $page = $page >= $total ? $total : $page;
  263. $list = Db::name('good')
  264. ->alias("a")
  265. ->field("b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.cat_id,a.good_name,a.good_img,a.good_info_img,a.good_thumb_img,b.createrid,a.is_exclusive,a.brand_id,a.supplierNo,a.good_unit,a.noble_metal,a.companyNo,a.spuCode,a.good_type,b.creater,b.addtime,b.updatetime,b.exam_status,a.createrid purchase_id,a.creater purchase,u.itemid")//成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  266. ->leftJoin("good_platform b","a.spuCode=b.spuCode")
  267. // ->leftJoin("good_basic gb","gb.spuCode=a.spuCode")
  268. ->leftJoin("depart_user u", "u.uid=a.createrid AND u.is_del=0")
  269. ->where($where)
  270. ->page($page,$size)
  271. ->order("b.addtime desc")
  272. ->cursor();
  273. $data=[];
  274. foreach ($list as $value){
  275. $value['cat_info']= made($value['cat_id'],[]);
  276. $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
  277. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
  278. $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en']:"";
  279. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  280. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  281. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  282. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  283. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  284. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  285. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  286. $value['company'] = isset($company['company'])?$company['company']:"";
  287. $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
  288. $value['status']=$value['exam_status'];
  289. $value['exclusive']=makeExcluse($value['is_exclusive']);
  290. // $value['good_info_img']=$value['good_info_img'];
  291. // $value['good_img']=$value['good_img'];
  292. $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
  293. $speclist=[];
  294. if(!empty($spec)){
  295. foreach ($spec as $val){
  296. $temp=[];
  297. $temp['spec_id']=$val['spec_id'];
  298. $temp['spec_value_id']=$val['spec_value_id'];
  299. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  300. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  301. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  302. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  303. $speclist[]=$temp;
  304. }
  305. }
  306. $value['specinfo']=$speclist;
  307. $value['noble_name']=isset($value['noble_metal'])&&$value['noble_metal']!=0?$this->noble[$value['noble_metal']] :"";
  308. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  309. $data[]=$value;
  310. }
  311. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  312. }
  313. public function info(){
  314. $skucode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
  315. if($skucode==""){
  316. return error_show(1005,"参数skuCode不能为空");
  317. }
  318. $good_platform = Db::name("good_platform")->where(['skuCode'=>$skucode,"is_del"=>0])->find();
  319. if($good_platform==false){
  320. return error_show(1004,"未找到商品数据");
  321. }
  322. $data = Db::name("good")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->find();
  323. if($data==false){
  324. return error_show(1004,"未找到商品数据");
  325. }
  326. $plat =Db::name("platform")->where(["id"=>$good_platform['platform_code']])->find();
  327. $data['skuCode']=$good_platform['skuCode'];
  328. $data['platform_code']=$good_platform['id'];
  329. $data['platform_code_en']=isset($plat['platform_code'])?$plat['platform_code']:"";
  330. $data['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  331. $data['online_reason']=$good_platform['online_reason'];
  332. $data['online_time']=$good_platform['online_time'];
  333. $data['online_remark']=$good_platform['online_remark'];
  334. $data['exam_status']=$good_platform['exam_status'];
  335. $data['is_online']=$good_platform['is_online'];
  336. $data['plat_code']=$good_platform['plat_code'];
  337. $data['exclusive']=makeExcluse($data['is_exclusive']);
  338. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  339. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  340. $data['cat_info'] = made($data['cat_id'],[]);
  341. $spec = Db::name("good_spec")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
  342. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  343. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  344. $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
  345. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  346. $data['company'] = isset($company['company'])?$company['company']:"";
  347. if($data['brand_id']!=0){
  348. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  349. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  350. }else{
  351. $data["brand_name"]="";
  352. $data["brand_id"]="";
  353. }
  354. $data['origin_place_cn']="";
  355. $data['delivery_place_cn']="";
  356. if($data['delivery_place']!==""){
  357. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  358. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['delivery_place']);
  359. $data['delivery_place_cn']=GetAddr(json_encode($place));
  360. }
  361. if($data['origin_place']!==""){
  362. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  363. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['origin_place']);
  364. $data['origin_place_cn']=GetAddr(json_encode($place));
  365. }
  366. $excluse = makeExcluse($data['is_exclusive']);
  367. $data['exclusive']=$excluse;
  368. $data["good_info_img"]=$data['good_info_img']!=""? $data['good_info_img']:[];
  369. $data["good_img"]=$data['good_img']!=""? $data['good_img']:[];
  370. $speclist=[];
  371. if(!empty($spec)){
  372. foreach ($spec as $value){
  373. $temp=[];
  374. $temp['id']=$value['id'];
  375. $temp['spuCode']=$value['spuCode'];
  376. $temp['spec_id']=$value['spec_id'];
  377. $temp['spec_value_id']=$value['spec_value_id'];
  378. $temp['is_del']=$value['is_del'];
  379. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  380. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  381. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  382. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  383. $speclist[]=$temp;
  384. }
  385. }
  386. $data["speclist"]=empty($speclist)?[]:$speclist;
  387. $ladder = Db::name("good_ladder")->where(['skuCode'=>$skucode,"is_del"=>0])->select()->toArray();
  388. $data["ladderlist"]=!empty($ladder)?$ladder:[];
  389. $nakelist = Db::name("good_nake")->where(['spuCode'=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
  390. // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  391. $cat_top_list = $data['cat_info'];
  392. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  393. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  394. $gold_price=0;
  395. if ($data['is_gold_price']==1 && $cat_top_id==6) {
  396. $gold_price = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->value('price', 0);
  397. }
  398. $data['gold_price'] =$gold_price;
  399. $nakearry=[];
  400. if(!empty($nakelist)){
  401. //实时金价
  402. foreach ($nakelist as $value){
  403. $value['sale_price'] =$value['nake_total'];
  404. //计算最终售价
  405. if ($data['is_gold_price']==1 && $cat_top_id==6) {
  406. //普通商品:直接用财务提交的售价字段;
  407. //贵金属( 商品重量* 最新金价 + 工艺费(财务定价提交的)* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)=商品库商品直接下单的售价
  408. $value['sale_price'] = ($data['weight'] * $gold_price + $value['cost_fee'] * $data['weight'] + $value['package_fee'] + $value['mark_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['other_fee']);
  409. }
  410. $nakearry[] = $value;
  411. }
  412. }
  413. $proof =Db::name("good_proof")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  414. $data['proof'] = isset($proof)&&$proof!=false? $proof:[];
  415. $data["nakelist"]=$nakearry;
  416. //补充采购员字段
  417. //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  418. $temp_basic_info = Db::name('good_basic')
  419. ->field('id,createrid purchase_id,creater purchase')
  420. ->where(['spuCode'=>$data['spuCode'],'is_del'=>0])
  421. ->find();
  422. $data['purchase_id'] = $temp_basic_info['purchase_id'];
  423. $data['purchase'] = $temp_basic_info['purchase'];
  424. return app_show(0,"获取成功",$data);
  425. }
  426. public function SetWarn(){
  427. $condition=["is_del"=>0];
  428. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  429. if($wsm_code!=""){
  430. $condition["wsm_code"] = $wsm_code;
  431. }else{
  432. return error_show(1004,"参数wsm_code 不能为空");
  433. }
  434. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  435. if($type_code!=""){
  436. $condition["good_type_code"] = $type_code;
  437. }else{
  438. return error_show(1004,"参数type_code 不能为空");
  439. }
  440. $good= Db::name("good_stock")->where($condition)->find();
  441. if(empty($good)){
  442. return error_show(1005,"未找到数据");
  443. }
  444. $warn_stock = isset($this->post['warn_stock']) &&$this->post['warn_stock'] !=="" ? intval($this->post['warn_stock']):"";
  445. if($warn_stock===""){
  446. return error_show(1005,"参数warn_stock 不能为空");
  447. }
  448. $good['warn_stock'] = $warn_stock;
  449. $good['updatetime'] = date("Y-m-d H:i:s");
  450. $up= Db::name("good_stock")->save($good);
  451. if($up){
  452. //商品变动日志表,good_log_code字段存储仓库编码
  453. $data = ['good_log_code' => $wsm_code, "stock_id" => $good['id'], "type" => 1, 'stock' => $warn_stock, "stock_name" => "warn_stock"];
  454. GoodLog::LogAdd($this->post['token'],$data,'setwarn');
  455. return app_show(0,"预警库存更新成功");
  456. }else{
  457. return error_show(1005,"预警库存更新失败");
  458. }
  459. }
  460. public function SetStatus(){
  461. $id = isset($this->post['id']) &&$this->post['id'] !=="" ? intval($this->post['id']):"";
  462. if($id===""){
  463. return error_show(1005,"参数id 不能为空");
  464. }
  465. $good= Db::name("good_type")->where(["id"=>$id,"is_del"=>0])->find();
  466. if(empty($good)){
  467. return error_show(1005,"未找到数据");
  468. }
  469. $good['status'] = $good['status']==1?0 :1;
  470. $good['updatetime'] = date("Y-m-d H:i:s");
  471. $msg = $good['status']==1?"下架" :"上架";
  472. $up= Db::name("good_type")->save($good);
  473. return $up ? app_show(0,"商品{$msg}成功"): error_show(1005,"商品{$msg}失败");
  474. }
  475. public function GetStock(){
  476. $condition = [["a.is_del","=",0]];
  477. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  478. if($type_code!==""){
  479. $condition[]=["a.spuCode","=",$type_code];
  480. }
  481. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  482. :"";
  483. if($wsm_code!==""){
  484. //$condition["a.wsm_code"]=$wsm_code;
  485. $condition[]=["a.wsm_code","=",$type_code];
  486. }
  487. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  488. :"";
  489. if($suplierNo!==""){
  490. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  491. $condition[]=["a.wsm_code","in",$wsmcode];
  492. }
  493. $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")
  494. ->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.wait_out_stock+a.usable_stock) as total_stock,a.status,a.warn_stock")->select();
  495. if(empty($list)){
  496. return error_show(1004,"未找到数据");
  497. }
  498. return app_show(0,"获取成功",$list);
  499. }
  500. /**
  501. * @return \think\response\Json|void
  502. * @throws \think\db\exception\DataNotFoundException
  503. * @throws \think\db\exception\DbException
  504. * @throws \think\db\exception\ModelNotFoundException
  505. */
  506. public function GetStockBet(){
  507. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  508. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  509. $condition = [["is_del","=",0]];
  510. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  511. if($type_code!==""){
  512. $condition[]=["spuCode","like","%{$type_code}%"];
  513. }
  514. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  515. :"";
  516. if($wsm_code!==""){
  517. $condition[]=["wsm_code","=",$wsm_code];
  518. }
  519. $suplierNo = isset($this->post['suplierNo']) &&$this->post['suplierNo'] !=="" ? trim($this->post['suplierNo']):"";
  520. if($suplierNo!==""){
  521. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  522. $condition[]=["wsm_code","in",$wsmcode];
  523. }
  524. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  525. if ($companyNo !== "") {
  526. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  527. $condition[]=["wsm_code","in",$wsmcode];
  528. }
  529. $start = isset($this->post['start']) &&$this->post['start'] !=="" ? $this->post['start']:"";
  530. $end = isset($this->post['end']) &&$this->post['end'] !=="" ? $this->post['end']:"";
  531. if($start!=""){
  532. $condition[]=["addtime",">=",$start];
  533. }
  534. if($end!=""){
  535. $condition[]=["addtime","<=",$end];
  536. }
  537. $count = Db::name("good_stock")->where($condition)->count();
  538. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  539. $list = Db::name("good_stock")->where($condition)->page($page,$size)->order("addtime desc")->select();
  540. $data=[];
  541. foreach ($list as $key=>$value){
  542. $temp=[];
  543. if($value['wsm_code']!=""){
  544. $wsm = Db::name("warehouse_info")
  545. ->alias("a")
  546. ->leftJoin("supplier b","a.supplierNo=b.code")
  547. ->leftJoin("business bus","a.companyNo=bus.companyNo")
  548. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  549. ->field("a.name as wsm_name,wsm_code,a.supplierNo,b.name supplierName,a.companyNo,bus.company")
  550. ->find();
  551. }
  552. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  553. $temp['wsm_code']=$value['wsm_code'];
  554. $temp['supplier_code']=isset($wsm['supplierNo'])?$wsm['supplierNo']:"";
  555. $temp['supplier_name']=isset($wsm['supplierName'])?$wsm['supplierName']:"";
  556. $temp['company_no']=isset($wsm['companyNo'])?$wsm['companyNo']:"";
  557. $temp['company_name']=isset($wsm['company'])?$wsm['company']:"";
  558. if($value['spuCode']!=""){
  559. $good=Db::name("good")
  560. ->alias('g')
  561. ->field('g.*,b.brand_name,u.unit')
  562. ->where(["g.spuCode"=>$value['spuCode'],"g.is_del"=>0])
  563. ->leftJoin('brand b','b.id=g.brand_id')
  564. ->leftJoin('unit u','u.id=g.good_unit')
  565. ->find();
  566. if (empty($good)) {
  567. $good = Db::name("good_zixun")
  568. ->alias('g')
  569. ->field('g.*,b.brand_name,u.unit')
  570. ->where(["g.spuCode" => $value['spuCode'], "g.is_del" => 0])
  571. ->leftJoin('brand b', 'b.id=g.brand_id')
  572. ->leftJoin('unit u', 'u.id=g.good_unit')
  573. ->find();
  574. }
  575. //规格信息
  576. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  577. $speclist = [];
  578. if (!empty($spec)) {
  579. foreach ($spec as $val) {
  580. $tmp = [];
  581. $tmp['spec_id'] = $val['spec_id'];
  582. $tmp['spec_value_id'] = $val['spec_value_id'];
  583. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  584. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  585. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  586. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  587. $speclist[] = $tmp;
  588. }
  589. }
  590. $temp['specinfo'] = $speclist;
  591. }
  592. $temp['good_code']=isset($good['spuCode'])?$good['spuCode']:"";
  593. // $temp['type_code']=isset($good['type_code'])?$good['type_code']:"";
  594. $temp['good_name']=isset($good['good_name'])?$good['good_name']:"";
  595. $temp['unit']=isset($good['unit'])?$good['unit']:"";
  596. $temp['brand_name']=isset($good['brand_name'])?$good['brand_name']:"";
  597. // $temp['attribute']=isset($good['attribute'])?$good['attribute']:"";
  598. $temp['sort_f']=isset($good['cat_id'])?$good['cat_id']:"";
  599. $temp['cat_info']=isset($good['cat_id'])?made($good['cat_id']):"";
  600. $temp['usable_stock'] = $value['usable_stock'];
  601. $temp['wait_in_stock'] = $value['wait_in_stock'];
  602. $temp['wait_out_stock'] = $value['wait_out_stock'];
  603. $temp['intra_stock'] = $value['intra_stock'];
  604. $temp['total_stock'] = $value['wait_out_stock']+$value['usable_stock'];
  605. $temp['warn_stock'] = $value['warn_stock'];
  606. $temp['id'] = $value['id'];
  607. $temp['out_total'] =0;
  608. $temp['in_total'] = 0;
  609. $temp['addtime'] = $value['addtime'];
  610. $data[]=$temp;
  611. }
  612. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  613. }
  614. /**
  615. * @return \think\response\Json|void
  616. * @throws \think\db\exception\DataNotFoundException
  617. * @throws \think\db\exception\DbException
  618. * @throws \think\db\exception\ModelNotFoundException
  619. * @throws \think\exception\DbException
  620. */
  621. public function GetStockWsm(){
  622. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  623. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  624. $condition = [["gs.is_del","=",0]];
  625. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  626. if($wsm_code!==""){
  627. $condition[]=["gs.wsm_code","=",$wsm_code];
  628. }
  629. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  630. if($suplierNo!==""){
  631. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  632. $condition[]=["gs.wsm_code","in",$wsmcode];
  633. }
  634. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  635. if ($companyNo !== "") {
  636. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  637. $condition[]=["gs.wsm_code","in",$wsmcode];
  638. }
  639. $build= Db::name("good_stock")
  640. ->alias('gs')
  641. ->where($condition)
  642. ->where('whi.wsm_type','<>',2)//2表示虚拟仓,虚拟仓不参加统计
  643. ->leftJoin('warehouse_info whi','whi.wsm_code=gs.wsm_code AND whi.is_del=0')
  644. ->group("gs.wsm_code")
  645. ->field("gs.wsm_code")
  646. ->buildSql();
  647. $count = Db::table($build." a")->count();
  648. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  649. $list = Db::name("good_stock")
  650. ->alias('gs')
  651. ->where($condition)
  652. ->where('whi.wsm_type','<>',2)//2表示虚拟仓,虚拟仓不参加统计
  653. ->page($page,$size)
  654. ->leftJoin('warehouse_info whi','whi.wsm_code=gs.wsm_code AND whi.is_del=0')
  655. ->group("gs.wsm_code")
  656. ->field("gs.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(usable_stock+wait_out_stock) total_stock")
  657. ->select()
  658. ->toArray();
  659. $data=[];
  660. foreach ($list as $key=>$value){
  661. $temp=[];
  662. if($value['wsm_code']!=""){
  663. $wsm = Db::name("warehouse_info")
  664. ->alias("a")
  665. ->leftJoin("business bus", "bus.companyNo=a.companyNo")
  666. ->leftJoin("supplier b","a.supplierNo=b.code")
  667. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  668. ->field("a.name as wsm_name,wsm_code,a.supplierNo,b.name supplierName,a.companyNo,bus.company")
  669. ->find();
  670. $good = Db::name("good_stock")
  671. ->alias("a")
  672. ->leftJoin("good c","c.spuCode=a.spuCode")
  673. ->where(["a.wsm_code"=>$value['wsm_code'],"a.is_del"=>0,"c.is_del"=>0])
  674. ->select()
  675. ->toArray();
  676. //商品单位和品牌
  677. $good_unit_s = Db::name("unit")->whereIn('id', array_column($good, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
  678. $brands = Db::name("brand")->whereIn('id', array_column($good, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
  679. foreach ($good as &$item_good){
  680. //规格信息
  681. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $item_good['spuCode'], "is_del" => 0])->select()->toArray();
  682. $speclist = [];
  683. if (!empty($spec)) {
  684. foreach ($spec as $val) {
  685. $tmp = [];
  686. $tmp['spec_id'] = $val['spec_id'];
  687. $tmp['spec_value_id'] = $val['spec_value_id'];
  688. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  689. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  690. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  691. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  692. $speclist[] = $tmp;
  693. }
  694. }
  695. $item_good['specinfo'] = $speclist;
  696. $item_good['unit'] = $good_unit_s[$item_good['good_unit']]??'';
  697. $item_good['brand_name'] = $brands[$item_good['brand_id']]??'';
  698. $item_good['can'] = made($item_good['cat_id'],[]);
  699. $item_good['total_stock'] =$item_good['usable_stock']+$item_good['wait_out_stock'];
  700. }
  701. }
  702. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  703. $temp['wsm_code']=$value['wsm_code'];
  704. $temp['supplier_code']=isset($wsm['supplierNo'])?$wsm['supplierNo']:"";
  705. $temp['supplier_name']=isset($wsm['supplierName'])?$wsm['supplierName']:"";
  706. $temp['company_no']=isset($wsm['companyNo'])?$wsm['companyNo']:"";
  707. $temp['company_name']=isset($wsm['company'])?$wsm['company']:"";
  708. $temp['usable_stock'] = $value['usable_stock'];
  709. $temp['wait_in_stock'] = $value['wait_in_stock'];
  710. $temp['wait_out_stock'] = $value['wait_out_stock'];
  711. $temp['intra_stock'] = $value['intra_stock'];
  712. $temp['total_stock'] = $value['usable_stock']+$value['wait_out_stock'] ;
  713. $temp['child']=isset($good)&&!empty($good) ? $good:[];
  714. $data[]=$temp;
  715. }
  716. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  717. }
  718. public function GetStockGod(){
  719. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  720. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  721. $condition = [["b.is_del","=",0],["c.usable_stock",">",0],["a.wsm_type","<>",2]];
  722. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  723. if($type_code!==""){
  724. $condition[]=["b.spuCode","like","%{$type_code}%"];
  725. }
  726. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  727. if ($good_name !== "") {
  728. $condition[] = ["b.good_name", "like", "%{$good_name}%"];
  729. }
  730. $count = Db::name("good")->alias("b")
  731. ->join("good_stock c","c.spuCode = b.spuCode","left")
  732. ->leftJoin("warehouse_info a","a.wsm_code=c.wsm_code")
  733. ->where($condition)
  734. ->group("b.spuCode,b.good_name,b.good_unit,b.cat_id,b.craft_desc,b.addtime")
  735. ->count();
  736. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  737. $list = Db::name("good")
  738. ->alias("b")
  739. ->join("good_stock c","c.spuCode = b.spuCode","left")
  740. ->leftJoin("warehouse_info a","a.wsm_code=c.wsm_code")
  741. ->where($condition)
  742. ->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.usable_stock)+sum(c.wait_out_stock)) total_stock")
  743. ->page($page,$size)
  744. ->order("b.addtime desc")
  745. ->group("b.spuCode,b.good_name,b.good_unit,b.brand_id,b.cat_id,b.craft_desc,b.addtime")
  746. ->select()
  747. ->toArray();
  748. $data=[];
  749. if($list) {
  750. //商品单位和品牌
  751. $good_unit_s = Db::name("unit")->whereIn('id', array_column($list, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
  752. $brands = Db::name("brand")->whereIn('id', array_column($list, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
  753. foreach ($list as $key => $value) {
  754. $temp = [];
  755. if ($value['spuCode'] != "") {
  756. $child = Db::name("good_stock")
  757. ->alias("a")
  758. ->join("warehouse_info b", "a.wsm_code=b.wsm_code", "left")
  759. ->join("business bus", "bus.companyNo=b.companyNo", "left")
  760. ->join("supplier s", "s.code=b.supplierNo", "left")
  761. ->where(['a.spuCode' => $value['spuCode'], "a.is_del" => 0])
  762. ->where("b.wsm_type","<>",2)
  763. ->field("a.wsm_code,b.name wsm_name,a.wait_in_stock,a.wait_out_stock,a.usable_stock,a.intra_stock,(a.wait_out_stock+a.usable_stock) total_stock,a.warn_stock,b.supplierNo,s.name supplierName,b.companyNo,bus.company")
  764. ->select()
  765. ->toArray();
  766. // echo Db::name("good_stock")->getLastSql();
  767. }
  768. $temp['good_name'] = $value['good_name'];
  769. $temp['good_code'] = $value['spuCode'];
  770. $temp['type_code'] = '';
  771. // $unit = Db::name("unit")->where(['id' => $value['good_unit']])->find();
  772. $temp['unit'] =$good_unit_s[$value['good_unit']]??'';
  773. $temp['brand_name'] =$brands[$value['brand_id']]??'';
  774. $temp['sort_f'] = isset($value['cat_id']) ? made($value['cat_id']) : [];
  775. $temp['sort_f'] = implode('/', array_column($temp['sort_f'], 'name'));//由于这个字段原样在页面显示,所以在这里特意拼接成字符串
  776. $temp['attribute'] = $value['craft_desc'];
  777. $temp['addtime'] = $value['addtime'];
  778. $temp['usable_stock'] = isset($value['usable_stock']) ? $value['usable_stock'] : "";
  779. $temp['wait_in_stock'] = isset($value['wait_in_stock']) ? $value['wait_in_stock'] : "";
  780. $temp['wait_out_stock'] = isset($value['wait_out_stock']) ? $value['wait_out_stock'] : "";
  781. $temp['intra_stock'] = isset($value['intra_stock']) ? $value['intra_stock'] : "";
  782. $temp['total_stock'] = intval($value['wait_out_stock'])+intval($value['usable_stock']);
  783. // $temp['warn_stock'] = isset($value['warn_stock'])? $value['warn_stock']:"";
  784. $temp['child'] = isset($child) && !empty($child) ? $child : [];
  785. //规格信息
  786. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  787. $speclist = [];
  788. if (!empty($spec)) {
  789. foreach ($spec as $val) {
  790. $tmp = [];
  791. $tmp['spec_id'] = $val['spec_id'];
  792. $tmp['spec_value_id'] = $val['spec_value_id'];
  793. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  794. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  795. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  796. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  797. $speclist[] = $tmp;
  798. }
  799. }
  800. $temp['specinfo'] = $speclist;
  801. $data[] = $temp;
  802. }
  803. }
  804. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  805. }
  806. /**
  807. * @return \think\response\Json|void
  808. * @throws \think\db\exception\DataNotFoundException
  809. * @throws \think\db\exception\DbException
  810. * @throws \think\db\exception\ModelNotFoundException
  811. */
  812. public function Stat(){
  813. $condition =[["gs.is_del","=",0]];
  814. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  815. if($wsm_code!=""){
  816. //$condition["gs.wsm_code"] = $wsm_code;
  817. $condition[]=["gs.wsm_code","=",$wsm_code];
  818. }
  819. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  820. if($suplierNo!==""){
  821. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  822. $condition[]=["gs.wsm_code","in",$wsmcode];
  823. }
  824. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  825. if ($companyNo !== "") {
  826. // $where['khNo'] = $khNo;
  827. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  828. $condition[]=["gs.wsm_code","in",$wsmcode];
  829. }
  830. // $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  831. // if($type_code!=""){
  832. // $condition[] = ["gs.good_type_code","=",$type_code];
  833. // }
  834. $statlist = Db::name("good_stock")
  835. ->alias('gs')
  836. ->where($condition)
  837. ->where('whi.wsm_type','<>',2)//2表示虚拟仓,虚拟仓不参与
  838. ->leftJoin('warehouse_info whi','whi.wsm_code=gs.wsm_code AND whi.is_del=0')
  839. ->field("sum(gs.wait_in_stock) as wait_in_stock,sum(gs.wait_out_stock) as wait_out_stock ,sum(gs.usable_stock) as usable_stock,sum(gs.intra_stock) as intra_stock,sum(gs.usable_stock+gs.wait_out_stock) as total_stock,sum(gs.warn_stock) as warn_stock")
  840. ->find();
  841. return app_show(0,"获取成功",$statlist);
  842. }
  843. public function all(){
  844. $condtion=["a.is_del"=>0,"b.is_del"=>0];
  845. $wsmcode =isset($this->post['wsmcode']) &&$this->post['wsmcode'] !=="" ? trim($this->post['wsmcode']):"";
  846. if($wsmcode!=""){
  847. $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code");
  848. $condtion["b.type_code"] = $typecode;
  849. }
  850. $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  851. if($good_code!=""){
  852. $condtion['b.type_code'] = $good_code;
  853. }
  854. $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code'])
  855. :"";
  856. if($goodcode!=""){
  857. $condtion['a.good_code'] = $goodcode;
  858. }
  859. $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name'])
  860. :"";
  861. if($good_name!=""){
  862. $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'");
  863. }
  864. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  865. if($supplierNo!=""){
  866. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  867. if(empty($supplier)){
  868. return error_show(1004,"未找到供应商信息");
  869. }
  870. $condtion["a.gys_code"] = $supplierNo;
  871. }
  872. $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  873. ->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,
  874. 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")
  875. ->select();
  876. $data=[];
  877. foreach ($list as $key=>$value){
  878. $stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock");
  879. $value['usable_stock']=$stock;
  880. $supplier = Db::name("supplier")->where(["code"=>$value['gys_code']])->find();
  881. $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
  882. $data[]=$value;
  883. }
  884. return app_show(0,"获取成功",$data);
  885. }
  886. //库存概况
  887. public function loglist(){
  888. $page = isset($this->post['page']) && $this->post['page']!==""? intval($this->post['page']) :"1";
  889. $size = isset($this->post['size']) && $this->post['size']!==""? intval($this->post['size']) :"10";
  890. $where=[];
  891. $wsm_code= isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  892. if($wsm_code!=""){
  893. $where[]=['b.wsm_code',"like","%$wsm_code%"];
  894. }
  895. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  896. if($supplierNo!=""){
  897. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  898. if(empty($supplier)){
  899. return error_show(1004,"未找到供应商信息");
  900. }
  901. $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"supplierNo"=>$supplierNo])->column("wsm_code");
  902. $where[]=['b.wsm_code',"in",$wsmcode];
  903. }
  904. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  905. if ($companyNo !== "") {
  906. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  907. $where[]=["b.wsm_code","in",$wsmcode];
  908. }
  909. $count = Db::name("good_log")
  910. ->alias('a')
  911. ->join("good_stock b","b.id=a.id","left")
  912. ->where($where)
  913. ->count();
  914. $total = ceil($count/$size);
  915. $page = $total>=$page ? $page :$total;
  916. $list = Db::name("good_log")
  917. ->alias('a')
  918. ->join("good_stock b","b.id=a.stock_id","left")
  919. ->where($where)
  920. ->page($page,$size)
  921. ->order("a.addtime desc")
  922. ->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")
  923. ->select()
  924. ->toArray();
  925. $data=[];
  926. $action_uids = array_column($list, 'action_uid');
  927. $action_uids = array_unique($action_uids);
  928. $item = [];
  929. foreach ($action_uids as $action_uid) {
  930. $items = Db::name("depart_user")->where('uid', $action_uid)->column("itemid");
  931. foreach ($items as $it) {
  932. $item[$action_uid][] = implode('/', array_column(GetPart($it), 'name'));
  933. }
  934. }
  935. foreach ($list as $value){
  936. $wsm = Db::name("warehouse_info")
  937. ->alias("a")
  938. ->Join("supplier b","a.supplierNo=b.code","left")
  939. ->Join("business bus","bus.companyNo=a.companyNo","left")
  940. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  941. ->field("a.name as wsm_name,wsm_code,b.code,b.name,bus.company,bus.companyNo")
  942. ->find();
  943. $godd =Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  944. $value['good_name']=isset($godd['good_name'])? $godd['good_name']:"";
  945. $value['cat_id']=isset($godd['cat_id'])? $godd['cat_id']:"";
  946. $int = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  947. $value['wsm_name'] =$wsm['wsm_name'];
  948. $value['wsm_code'] =$wsm['wsm_code'];
  949. $value['code'] =$wsm['code'];
  950. $value['name'] =$wsm['name'];
  951. $value['action_type_cn'] =$this->acton[$value['action_type']];
  952. $value['item'] =$item[$value['action_uid']];
  953. $value['can'] =$int;
  954. $value['company'] =$wsm['company']??'';
  955. $value['companyNo'] =$wsm['companyNo']??'';
  956. $data[]=$value;
  957. }
  958. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  959. }
  960. public function goodlist()
  961. {
  962. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  963. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  964. $where = [["a.is_del", "=", 0], ["b.exam_status", "=", 6], ["b.is_del", "=", 0], ["c.is_del", "=", 0], ["c.status", "=", 1]];
  965. $paltcode = isset($this->post["platform_code"]) && $this->post["platform_code"] != "" ? trim($this->post["platform_code"]) : "";
  966. if ($paltcode != "") {
  967. $where[] = ["platform_code", "=", $paltcode];
  968. }
  969. $companyNo = isset($this->post["companyNo"]) && $this->post["companyNo"] != "" ? trim($this->post["companyNo"]) : "";
  970. if ($companyNo != "") {
  971. $where[] = ["companyNo", "like", "%$companyNo%"];
  972. }
  973. $cat_id = isset($this->post["cat_id"]) && $this->post["cat_id"] !== "" ? intval($this->post["cat_id"]) : "";
  974. if ($cat_id !== "") {
  975. //获取当前分类及所有子级
  976. $where[] = ["cat_id", "in", manger([$cat_id])];
  977. }
  978. $buy_num = isset($this->post["buy_num"]) && $this->post["buy_num"] !== "" ? intval($this->post["buy_num"]) : "";
  979. if ($buy_num !== "") {
  980. $where[] = ["c.min_num", "<=", $buy_num];
  981. }
  982. $price = isset($this->post["price"]) && $this->post["price"] !== "" ? floatval($this->post["price"]) : "";
  983. if ($price !== "") {
  984. $where[] = ["c.sale_price", "<=", $price];
  985. }
  986. $temp = Db::name('good_ladder')
  987. ->field('skuCode,MAX(min_num) min_num')
  988. ->where([
  989. ['min_num', '<=', $buy_num],
  990. ['sale_price', '<=', $price],
  991. ['is_del', '=', 0],
  992. ['status', '=', 1],
  993. ])->group('skuCode')
  994. ->order('skuCode', 'desc')->buildSql();
  995. $count = Db::name('good_ladder')
  996. ->alias('c')
  997. ->field('c.id,c.skuCode,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`')
  998. ->join($temp . ' temp', 'temp.skuCode = c.skuCode AND temp.min_num = c.min_num')
  999. ->leftJoin('good_platform b', 'b.skuCode=c.skuCode')
  1000. ->leftJoin('good a', 'a.spuCode = b.spuCode AND a.is_del=0')
  1001. ->where($where)
  1002. ->count();
  1003. $total = ceil($count / $size);
  1004. $page = $page >= $total ? $total : $page;
  1005. $list = Db::name('good_ladder')
  1006. ->alias('c')
  1007. ->field('c.id,c.skuCode,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`')
  1008. ->join($temp . ' temp', 'temp.skuCode = c.skuCode AND temp.min_num = c.min_num')
  1009. ->leftJoin('good_platform b', 'b.skuCode=c.skuCode')
  1010. ->leftJoin('good a', 'a.spuCode = b.spuCode AND a.is_del=0')
  1011. ->where($where)
  1012. ->page($page,$size)
  1013. ->select()
  1014. ->toArray();
  1015. // $list = Db::name('good')
  1016. // ->alias("a")
  1017. // ->leftJoin("good_platform b","a.spuCode=b.spuCode")
  1018. // ->leftJoin("good_ladder c","b.skuCode=c.skuCode")
  1019. // ->where($where)->fetchSql()
  1020. // ->where('a.spuCode','SKU2205251851017540')
  1021. // ->page($page,$size)
  1022. // ->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")
  1023. // ->order("b.addtime desc")
  1024. // ->select();halt($list);
  1025. // ->toArray();
  1026. $data = [];
  1027. foreach ($list as $value) {
  1028. $value['cat_info'] = made($value['cat_id'], []);
  1029. $platform = Db::name("platform")->where(["id" => $value['platform_code']])->find();
  1030. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name'] : "";
  1031. $value['platform_code_en'] = isset($platform['platform_code']) ? $platform['platform_code'] : "";
  1032. $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  1033. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name'] : "";
  1034. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  1035. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  1036. $unit = Db::name("unit")->where(["id" => $value['good_unit']])->find();
  1037. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : "";
  1038. $company = Db::name("business")->where(["companyNo" => $value['companyNo']])->find();
  1039. $value['company'] = isset($company['company']) ? $company['company'] : "";
  1040. $value['stock_total'] = Db::name("good_stock")->where(['spuCode' => $value['spuCode'], "is_del" => 0])->sum("usable_stock");
  1041. $value['status'] = $value['exam_status'];
  1042. $data[] = $value;
  1043. }
  1044. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  1045. }
  1046. //根据价格区间,筛选符合条件的商品列表
  1047. public function getGoodListByLadder()
  1048. {
  1049. //1.请求参数
  1050. $param = $this->request->only([
  1051. 'good_type' => '',
  1052. // 'start' => '',
  1053. // 'end' => '',
  1054. 'is_stock' => '',
  1055. 'cat_id' => 0,
  1056. 'brand_id' => 0,
  1057. 'min_price' => 0,
  1058. 'max_price' => 0,
  1059. 'moq' => 0,//最低起订量?
  1060. 'good_name' => '',
  1061. 'skucode' => '',
  1062. 'spucode' => '',
  1063. 'companyNo' => '',//业务企业编号
  1064. 'plat_code' => '',//平台商品编号
  1065. 'creater' => '',//创建人
  1066. 'platform_code' => '',
  1067. 'supplierNo' => '',
  1068. 'page' => 1,
  1069. 'size' => 15,
  1070. 'company_name'=>'',
  1071. ], 'post', 'trim');
  1072. $where = [["gl.is_del", "=", 0], ['gp.exam_status', '=', 6]];//exam_status==6已上线
  1073. if ($param['good_type']!='') $where[] = ['gb.good_type', '=', $param['good_type']];
  1074. // if (!empty($param['start'])) $where[] = ['gl.addtime', '>=', $param['start']];
  1075. // if (!empty($param['end'])) $where[] = ['gl.addtime', '<=', $param['end'] . ' 23:59:59'];
  1076. if ($param['is_stock']!='') $where[] = ['gb.is_stock', '=', $param['is_stock']];
  1077. if (!empty($param['cat_id'])) $where[] = ['gb.cat_id', '=', $param['cat_id']];
  1078. if (!empty($param['brand_id'])) $where[] = ['gb.brand_id', '=', $param['brand_id']];
  1079. if ($param['min_price']!='' && $param['max_price']!='') $where[] = ['gl.sale_price', 'between', [$param['min_price'], $param['max_price']]];
  1080. if (!empty($param['moq'])) $where[] = ['gl.min_num', '>=', $param['moq']];
  1081. if (!empty($param['good_name'])) $where[] = ['gb.good_name', 'like', '%' . $param['good_name'] . '%'];
  1082. if (!empty($param['skucode'])) $where[] = ['gl.skuCode', 'like', '%' . $param['skucode'] . '%'];
  1083. if (!empty($param['spucode'])) $where[] = ['gp.spuCode', 'like', '%' . $param['spucode'] . '%'];
  1084. if (!empty($param['companyNo'])) $where[] = ['gb.companyNo', 'like', '%' . $param['companyNo'], '%'];
  1085. if (!empty($param['plat_code'])) $where[] = ['gp.plat_code', 'like', '%' . $param['plat_code'], '%'];
  1086. if (!empty($param['creater'])) $where[] = ['gb.creater', 'like', '%' . $param['creater'], '%'];
  1087. if (!empty($param['platform_code'])) $where[] = ['gp.platform_code', 'like', '%' . $param['platform_code'], '%'];
  1088. if (!empty($param['company_name'])) $where[] = ['gb.createrid', 'in', get_company_item_user_by_name($param['company_name'])];
  1089. // if (!empty($param['supplierNo'])) $where[] = ['supplierNo', 'like', '%'.$param['supplierNo'],'%'];
  1090. //5.获取结果
  1091. $count = Db::name('good_ladder')
  1092. ->alias('gl')
  1093. //->field('gl.id,gl.skuCode,gp.spuCode,p.platform_name,gb.good_thumb_img,gb.good_name,gb.cat_id,gb.good_type,gb.is_stock,gb.brand_id,gp.plat_code,gl.min_num,gl.sale_price,gb.creater purchase,gb.creater,gb.companyNo,u.itemid')
  1094. ->leftJoin('good_platform gp', 'gp.skuCode=gl.skuCode AND gp.is_del=0')
  1095. ->leftJoin('platform p', 'p.id=gp.platform_code AND p.is_del=0')
  1096. ->leftJoin('good gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1097. ->leftJoin("depart_user u", "u.uid=gb.createrid AND u.is_del=0")
  1098. ->where($where)
  1099. ->count('gl.id');
  1100. $list = Db::name('good_ladder')
  1101. ->alias('gl')
  1102. ->field('gl.id,gl.skuCode,gp.spuCode,p.platform_name,gb.good_thumb_img,gb.good_name,gb.cat_id,gb.good_type,gb.is_stock,gb.brand_id,gp.plat_code,gl.min_num moq,gl.sale_price,gb.creater purchase,gb.creater,gb.companyNo,u.itemid')
  1103. ->leftJoin('good_platform gp', 'gp.skuCode=gl.skuCode AND gp.is_del=0')
  1104. ->leftJoin('platform p', 'p.id=gp.platform_code AND p.is_del=0')
  1105. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1106. ->leftJoin("depart_user u", "u.uid=gb.createrid AND u.is_del=0")
  1107. ->where($where)
  1108. ->page($param['page'], $param['size'])
  1109. ->order(['gl.skuCode' => 'asc', 'gl.addtime' => 'desc', 'gl.id' => 'desc'])
  1110. ->select()
  1111. ->toArray();
  1112. //6.补充数据,照搬list方法
  1113. $all_brand = Db::name('brand')
  1114. ->where('is_del', 0)
  1115. ->whereIn('id', array_column($list, 'brand_id'))
  1116. ->column('brand_name', 'id');
  1117. $all_company = Db::name('business')
  1118. ->where('is_del', 0)
  1119. ->whereIn('companyNo', array_column($list, 'companyNo'))
  1120. ->column('company', 'companyNo');
  1121. foreach ($list as &$value) {
  1122. $value['cat_info'] = made($value['cat_id'], []);
  1123. $value['brand_name'] = isset($all_brand[$value['brand_id']]) ? $all_brand[$value['brand_id']] : '';
  1124. $value['company'] = isset($all_company[$value['companyNo']]) ? $all_company[$value['companyNo']] : '';
  1125. $value['stock_total'] = Db::name("good_stock")
  1126. ->where(['spuCode' => $value['spuCode'], "is_del" => 0])
  1127. ->sum("usable_stock");
  1128. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  1129. }
  1130. return app_show(0, "获取成功", ['list' => $list, 'count' => $count]);
  1131. }
  1132. }