Good.php 66 KB

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