Good.php 66 KB

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