Good.php 68 KB

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