Good.php 65 KB

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