Good.php 64 KB

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