Good.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\GoodLog;
  4. use think\App;
  5. use think\facade\Db;
  6. use think\facade\Validate;
  7. //线上商品
  8. class Good extends Base
  9. {
  10. private $acton=[
  11. "allotsend"=>'调拨发货',
  12. "allotin"=>'调拨入库',
  13. "allotincheck"=>'调拨验货',
  14. 'CGD'=>'采购单',
  15. 'BHD'=>'备库单',
  16. 'FKD'=>'备库反馈单',
  17. 'RKD'=>'入库单',
  18. 'ZXQRD'=>'咨询单',
  19. 'XSQRD'=>'销售单',
  20. 'PDD'=>'盘点单',
  21. 'DBD'=>'调拨单',
  22. 'CKD'=>'出库单',
  23. 'CGTHD'=>'采购退货单',
  24. 'XSTHD'=>'销售退货单',
  25. 'CGGCD'=>'采购工差单',
  26. 'ZXGCD'=>'咨询工差单'
  27. ];
  28. public $noble=[];
  29. public function __construct(App $app)
  30. {
  31. parent::__construct($app);
  32. $this->noble=\think\facade\Config::get("noble");
  33. }
  34. public function list(){
  35. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  36. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  37. $where =[["a.is_del","=",0]];
  38. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? trim($this->post['cat_id']):"";
  39. if($cat_id!==""){
  40. $where[]=['a.cat_id',"=",$cat_id];
  41. }
  42. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  43. if($good_name!==""){
  44. $where[]=['a.good_name',"like","%$good_name%"];
  45. }
  46. $skucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode'])
  47. :"";
  48. if($skucode!==""){
  49. $where [] = ['b.skucode',"like","%$skucode%"];
  50. }
  51. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  52. if($start!==""){
  53. $where[]=['a.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  54. }
  55. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  56. if($end!==""){
  57. $where[]=['a.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  58. }
  59. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !=="" ? intval($this->post['is_stock'])
  60. :"";
  61. if($is_stock!==""){
  62. $where[]=['is_stock',"=",$is_stock];
  63. }
  64. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? intval($this->post['good_type'])
  65. :"";
  66. if($good_type!==""){
  67. $where[]=['good_type',"=",$good_type];
  68. }
  69. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  70. :"";
  71. if($supplierNo!==""){
  72. $where[]=['a.supplierNo',"=",$supplierNo];
  73. }
  74. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :"";
  75. if($companyNo!==""){
  76. $where[]=['a.companyNo',"like","%$companyNo%"];
  77. }
  78. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  79. if($creater!==""){
  80. $where[]=['a.creater',"like","%$creater%"];
  81. }
  82. $createrid = isset($this->post['createrid']) && $this->post['createrid'] !=="" ? intval($this->post['createrid']):"";
  83. if($createrid!==""){
  84. $where[]=['a.createrid',"=",$createrid];
  85. }
  86. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
  87. :"";
  88. if($status!==""){
  89. $where[]=['a.status',"=",$status];
  90. }
  91. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code'])
  92. :"";
  93. if($platform_code!==""){
  94. //$platform = Db::name("good_platform")->where(["platform_code"=>$platform_code,"is_del"=>0])->column
  95. //("spuCode");
  96. $where[]=["platform_code","=",$platform_code];
  97. }
  98. $plat_code = isset($this->post['plat_code']) && $this->post['plat_code'] !=="" ? trim($this->post['plat_code'])
  99. :"";
  100. if($plat_code!==""){
  101. $where[]=["b.plat_code","like","%$plat_code%"];
  102. }
  103. $exam_status = isset($this->post['exam_status']) && $this->post['exam_status'] !=="" ? intval($this->post['exam_status'])
  104. :"";
  105. if($exam_status!==""){
  106. $where[]=['b.exam_status',"=",$exam_status];
  107. }
  108. $brand_id = isset($this->post['brand_id']) && $this->post['brand_id'] !=="" ? intval($this->post['brand_id'])
  109. :"";
  110. if($brand_id!==""){
  111. $where[]=['a.brand_id',"=",$brand_id];
  112. }
  113. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where($where)
  114. ->count();
  115. $total = ceil($count / $size);
  116. $page = $page >= $total ? $total : $page;
  117. $list = Db::name('good')
  118. ->alias("a")
  119. ->field("b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.*,b.addtime,b.updatetime,b.exam_status,gb.createrid purchase_id,gb.creater purchase")//成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  120. ->leftJoin("good_platform b","a.spuCode=b.spuCode")
  121. ->leftJoin("good_basic gb","gb.spuCode=a.spuCode")
  122. ->where($where)
  123. ->page($page,$size)
  124. ->order("b.addtime desc")
  125. ->select();
  126. $data=[];
  127. foreach ($list as $value){
  128. $value['cat_info']= made($value['cat_id'],[]);
  129. $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
  130. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
  131. $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en']:"";
  132. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  133. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  134. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  135. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  136. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  137. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  138. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  139. $value['company'] = isset($company['company'])?$company['company']:"";
  140. $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
  141. $value['status']=$value['exam_status'];
  142. $value['exclusive']=makeExcluse($value['is_exclusive']);
  143. $value['good_info_img']=$value['good_info_img'];
  144. $value['good_img']=$value['good_img'];
  145. $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
  146. $speclist=[];
  147. if(!empty($spec)){
  148. foreach ($spec as $val){
  149. $temp=[];
  150. $temp['spec_id']=$val['spec_id'];
  151. $temp['spec_value_id']=$val['spec_value_id'];
  152. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  153. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  154. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  155. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  156. $speclist[]=$temp;
  157. }
  158. }
  159. $value['specinfo']=$speclist;
  160. $value['noble_name']=isset($value['noble_metal'])&&$value['noble_metal']!=0?$this->noble[$value['noble_metal']] :"";
  161. $data[]=$value;
  162. }
  163. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  164. }
  165. public function info(){
  166. $skucode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
  167. if($skucode==""){
  168. return error_show(1005,"参数skuCode不能为空");
  169. }
  170. $good_platform = Db::name("good_platform")->where(['skuCode'=>$skucode,"is_del"=>0])->find();
  171. if($good_platform==false){
  172. return error_show(1004,"未找到商品数据");
  173. }
  174. $data = Db::name("good")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->find();
  175. if($data==false){
  176. return error_show(1004,"未找到商品数据");
  177. }
  178. $plat =Db::name("platform")->where(["id"=>$good_platform['platform_code']])->find();
  179. $data['skuCode']=$good_platform['skuCode'];
  180. $data['platform_code']=$good_platform['id'];
  181. $data['platform_code_en']=isset($plat['platform_code'])?$plat['platform_code']:"";
  182. $data['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  183. $data['online_reason']=$good_platform['online_reason'];
  184. $data['online_time']=$good_platform['online_time'];
  185. $data['online_remark']=$good_platform['online_remark'];
  186. $data['exam_status']=$good_platform['exam_status'];
  187. $data['is_online']=$good_platform['is_online'];
  188. $data['plat_code']=$good_platform['plat_code'];
  189. $data['exclusive']=makeExcluse($data['is_exclusive']);
  190. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  191. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  192. $data['cat_info'] = made($data['cat_id'],[]);
  193. $spec = Db::name("good_spec")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
  194. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  195. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  196. $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
  197. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  198. $data['company'] = isset($company['company'])?$company['company']:"";
  199. if($data['brand_id']!=0){
  200. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  201. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  202. }else{
  203. $data["brand_name"]="";
  204. $data["brand_id"]="";
  205. }
  206. $data['origin_place_cn']="";
  207. $data['delivery_place_cn']="";
  208. if($data['delivery_place']!==""){
  209. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  210. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['delivery_place']);
  211. $data['delivery_place_cn']=GetAddr(json_encode($place));
  212. }
  213. if($data['origin_place']!==""){
  214. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  215. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['origin_place']);
  216. $data['origin_place_cn']=GetAddr(json_encode($place));
  217. }
  218. $excluse = makeExcluse($data['is_exclusive']);
  219. $data['exclusive']=$excluse;
  220. $data["good_info_img"]=$data['good_info_img']!=""? $data['good_info_img']:[];
  221. $data["good_img"]=$data['good_img']!=""? $data['good_img']:[];
  222. $speclist=[];
  223. if(!empty($spec)){
  224. foreach ($spec as $value){
  225. $temp=[];
  226. $temp['id']=$value['id'];
  227. $temp['spuCode']=$value['spuCode'];
  228. $temp['spec_id']=$value['spec_id'];
  229. $temp['spec_value_id']=$value['spec_value_id'];
  230. $temp['is_del']=$value['is_del'];
  231. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  232. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  233. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  234. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  235. $speclist[]=$temp;
  236. }
  237. }
  238. $data["speclist"]=empty($speclist)?[]:$speclist;
  239. $ladder = Db::name("good_ladder")->where(['skuCode'=>$skucode,"is_del"=>0])->select()->toArray();
  240. $data["ladderlist"]=!empty($ladder)?$ladder:[];
  241. $nakelist = Db::name("good_nake")->where(['spuCode'=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
  242. $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  243. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  244. $nakearry=[];
  245. if(!empty($nakelist)){
  246. foreach ($nakelist as $value){
  247. $value['sale_price'] =$value['nake_total'];
  248. $nakearry[]=$value;
  249. }
  250. }
  251. $proof =Db::name("good_proof")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  252. $data['proof'] = isset($proof)&&$proof!=false? $proof:[];
  253. $data["nakelist"]=$nakearry;
  254. return app_show(0,"获取成功",$data);
  255. }
  256. public function SetWarn(){
  257. $condition=["is_del"=>0];
  258. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  259. if($wsm_code!=""){
  260. $condition["wsm_code"] = $wsm_code;
  261. }else{
  262. return error_show(1004,"参数wsm_code 不能为空");
  263. }
  264. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  265. if($type_code!=""){
  266. $condition["good_type_code"] = $type_code;
  267. }else{
  268. return error_show(1004,"参数type_code 不能为空");
  269. }
  270. $good= Db::name("good_stock")->where($condition)->find();
  271. if(empty($good)){
  272. return error_show(1005,"未找到数据");
  273. }
  274. $warn_stock = isset($this->post['warn_stock']) &&$this->post['warn_stock'] !=="" ? intval($this->post['warn_stock']):"";
  275. if($warn_stock===""){
  276. return error_show(1005,"参数warn_stock 不能为空");
  277. }
  278. $good['warn_stock'] = $warn_stock;
  279. $good['updatetime'] = date("Y-m-d H:i:s");
  280. $up= Db::name("good_stock")->save($good);
  281. if($up){
  282. //商品变动日志表,good_log_code字段存储仓库编码
  283. $data = ['good_log_code' => $wsm_code, "stock_id" => $good['id'], "type" => 1, 'stock' => $warn_stock, "stock_name" => "warn_stock"];
  284. GoodLog::LogAdd($this->post['token'],$data,'setwarn');
  285. return app_show(0,"预警库存更新成功");
  286. }else{
  287. return error_show(1005,"预警库存更新失败");
  288. }
  289. }
  290. public function SetStatus(){
  291. $id = isset($this->post['id']) &&$this->post['id'] !=="" ? intval($this->post['id']):"";
  292. if($id===""){
  293. return error_show(1005,"参数id 不能为空");
  294. }
  295. $good= Db::name("good_type")->where(["id"=>$id,"is_del"=>0])->find();
  296. if(empty($good)){
  297. return error_show(1005,"未找到数据");
  298. }
  299. $good['status'] = $good['status']==1?0 :1;
  300. $good['updatetime'] = date("Y-m-d H:i:s");
  301. $msg = $good['status']==1?"下架" :"上架";
  302. $up= Db::name("good_type")->save($good);
  303. return $up ? app_show(0,"商品{$msg}成功"): error_show(1005,"商品{$msg}失败");
  304. }
  305. public function GetStock(){
  306. $condition = [["a.is_del","=",0]];
  307. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  308. if($type_code!==""){
  309. $condition[]=["a.spuCode","=",$type_code];
  310. }
  311. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  312. :"";
  313. if($wsm_code!==""){
  314. //$condition["a.wsm_code"]=$wsm_code;
  315. $condition[]=["a.wsm_code","=",$type_code];
  316. }
  317. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  318. :"";
  319. if($suplierNo!==""){
  320. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  321. $condition[]=["a.wsm_code","in",$wsmcode];
  322. }
  323. $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")
  324. ->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.total_stock,a.status,a.warn_stock")->select();
  325. if(empty($list)){
  326. return error_show(1004,"未找到数据");
  327. }
  328. return app_show(0,"获取成功",$list);
  329. }
  330. /**
  331. * @return \think\response\Json|void
  332. * @throws \think\db\exception\DataNotFoundException
  333. * @throws \think\db\exception\DbException
  334. * @throws \think\db\exception\ModelNotFoundException
  335. */
  336. public function GetStockBet(){
  337. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  338. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  339. $condition = [["is_del","=",0]];
  340. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  341. if($type_code!==""){
  342. $condition[]=["spuCode","like","%{$type_code}%"];
  343. }
  344. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  345. :"";
  346. if($wsm_code!==""){
  347. $condition[]=["wsm_code","=",$wsm_code];
  348. }
  349. $suplierNo = isset($this->post['suplierNo']) &&$this->post['suplierNo'] !=="" ? trim($this->post['suplierNo']):"";
  350. if($suplierNo!==""){
  351. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  352. $condition[]=["wsm_code","in",$wsmcode];
  353. }
  354. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  355. if ($companyNo !== "") {
  356. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  357. $condition[]=["wsm_code","in",$wsmcode];
  358. }
  359. $start = isset($this->post['start']) &&$this->post['start'] !=="" ? $this->post['start']:"";
  360. $end = isset($this->post['end']) &&$this->post['end'] !=="" ? $this->post['end']:"";
  361. if($start!=""){
  362. $condition[]=["addtime",">=",$start];
  363. }
  364. if($end!=""){
  365. $condition[]=["addtime","<=",$end];
  366. }
  367. $count = Db::name("good_stock")->where($condition)->count();
  368. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  369. $list = Db::name("good_stock")->where($condition)->page($page,$size)->order("addtime desc")->select();
  370. $data=[];
  371. foreach ($list as $key=>$value){
  372. $temp=[];
  373. if($value['wsm_code']!=""){
  374. $wsm = Db::name("warehouse_info")
  375. ->alias("a")
  376. ->leftJoin("supplier b","a.supplierNo=b.code")
  377. ->leftJoin("business bus","a.companyNo=bus.companyNo")
  378. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  379. ->field("a.name as wsm_name,wsm_code,a.supplierNo,b.name supplierName,a.companyNo,bus.company")
  380. ->find();
  381. }
  382. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  383. $temp['wsm_code']=$value['wsm_code'];
  384. $temp['supplier_code']=isset($wsm['supplierNo'])?$wsm['supplierNo']:"";
  385. $temp['supplier_name']=isset($wsm['supplierName'])?$wsm['supplierName']:"";
  386. $temp['company_no']=isset($wsm['companyNo'])?$wsm['companyNo']:"";
  387. $temp['company_name']=isset($wsm['company'])?$wsm['company']:"";
  388. if($value['spuCode']!=""){
  389. $good=Db::name("good")
  390. ->alias('g')
  391. ->field('g.*,b.brand_name,u.unit')
  392. ->where(["g.spuCode"=>$value['spuCode'],"g.is_del"=>0])
  393. ->leftJoin('brand b','b.id=g.brand_id')
  394. ->leftJoin('unit u','u.id=g.good_unit')
  395. ->find();
  396. //规格信息
  397. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  398. $speclist = [];
  399. if (!empty($spec)) {
  400. foreach ($spec as $val) {
  401. $tmp = [];
  402. $tmp['spec_id'] = $val['spec_id'];
  403. $tmp['spec_value_id'] = $val['spec_value_id'];
  404. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  405. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  406. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  407. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  408. $speclist[] = $tmp;
  409. }
  410. }
  411. $temp['specinfo'] = $speclist;
  412. }
  413. $temp['good_code']=isset($good['spuCode'])?$good['spuCode']:"";
  414. // $temp['type_code']=isset($good['type_code'])?$good['type_code']:"";
  415. $temp['good_name']=isset($good['good_name'])?$good['good_name']:"";
  416. $temp['unit']=isset($good['unit'])?$good['unit']:"";
  417. $temp['brand_name']=isset($good['brand_name'])?$good['brand_name']:"";
  418. // $temp['attribute']=isset($good['attribute'])?$good['attribute']:"";
  419. $temp['sort_f']=isset($good['cat_id'])?$good['cat_id']:"";
  420. $temp['cat_info']=isset($good['cat_id'])?made($good['cat_id']):"";
  421. $temp['usable_stock'] = $value['usable_stock'];
  422. $temp['wait_in_stock'] = $value['wait_in_stock'];
  423. $temp['wait_out_stock'] = $value['wait_out_stock'];
  424. $temp['intra_stock'] = $value['intra_stock'];
  425. $temp['total_stock'] = $value['total_stock'];
  426. $temp['warn_stock'] = $value['warn_stock'];
  427. $temp['id'] = $value['id'];
  428. $temp['out_total'] =0;
  429. $temp['in_total'] = 0;
  430. $temp['addtime'] = $value['addtime'];
  431. $data[]=$temp;
  432. }
  433. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  434. }
  435. /**
  436. * @return \think\response\Json|void
  437. * @throws \think\db\exception\DataNotFoundException
  438. * @throws \think\db\exception\DbException
  439. * @throws \think\db\exception\ModelNotFoundException
  440. * @throws \think\exception\DbException
  441. */
  442. public function GetStockWsm(){
  443. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  444. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  445. $condition = [["is_del","=",0]];
  446. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  447. if($wsm_code!==""){
  448. $condition[]=["wsm_code","=",$wsm_code];
  449. }
  450. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  451. if($suplierNo!==""){
  452. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  453. $condition[]=["wsm_code","in",$wsmcode];
  454. }
  455. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  456. if ($companyNo !== "") {
  457. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  458. $condition[]=["wsm_code","in",$wsmcode];
  459. }
  460. $build= Db::name("good_stock")->where($condition)->group("wsm_code")->field("wsm_code")->buildSql();
  461. $count = Db::table($build." a")->count();
  462. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  463. $list = Db::name("good_stock")
  464. ->where($condition)
  465. ->page($page,$size)
  466. ->group("wsm_code")
  467. ->field("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(total_stock) total_stock")
  468. ->select()
  469. ->toArray();
  470. $data=[];
  471. foreach ($list as $key=>$value){
  472. $temp=[];
  473. if($value['wsm_code']!=""){
  474. $wsm = Db::name("warehouse_info")
  475. ->alias("a")
  476. ->leftJoin("business bus", "bus.companyNo=a.companyNo")
  477. ->leftJoin("supplier b","a.supplierNo=b.code")
  478. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  479. ->field("a.name as wsm_name,wsm_code,a.supplierNo,b.name supplierName,a.companyNo,bus.company")
  480. ->find();
  481. $good = Db::name("good_stock")
  482. ->alias("a")
  483. ->leftJoin("good c","c.spuCode=a.spuCode")
  484. ->where(["a.wsm_code"=>$value['wsm_code'],"a.is_del"=>0,"c.is_del"=>0])
  485. ->select()
  486. ->toArray();
  487. //商品单位和品牌
  488. $good_unit_s = Db::name("unit")->whereIn('id', array_column($good, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
  489. $brands = Db::name("brand")->whereIn('id', array_column($good, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
  490. foreach ($good as &$item_good){
  491. //规格信息
  492. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $item_good['spuCode'], "is_del" => 0])->select()->toArray();
  493. $speclist = [];
  494. if (!empty($spec)) {
  495. foreach ($spec as $val) {
  496. $tmp = [];
  497. $tmp['spec_id'] = $val['spec_id'];
  498. $tmp['spec_value_id'] = $val['spec_value_id'];
  499. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  500. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  501. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  502. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  503. $speclist[] = $tmp;
  504. }
  505. }
  506. $item_good['specinfo'] = $speclist;
  507. $item_good['unit'] = $good_unit_s[$item_good['good_unit']]??'';
  508. $item_good['brand_name'] = $brands[$item_good['brand_id']]??'';
  509. $item_good['can'] = made($item_good['cat_id'],[]);
  510. }
  511. }
  512. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  513. $temp['wsm_code']=$value['wsm_code'];
  514. $temp['supplier_code']=isset($wsm['supplierNo'])?$wsm['supplierNo']:"";
  515. $temp['supplier_name']=isset($wsm['supplierName'])?$wsm['supplierName']:"";
  516. $temp['company_no']=isset($wsm['companyNo'])?$wsm['companyNo']:"";
  517. $temp['company_name']=isset($wsm['company'])?$wsm['company']:"";
  518. $temp['usable_stock'] = $value['usable_stock'];
  519. $temp['wait_in_stock'] = $value['wait_in_stock'];
  520. $temp['wait_out_stock'] = $value['wait_out_stock'];
  521. $temp['intra_stock'] = $value['intra_stock'];
  522. $temp['total_stock'] = $value['total_stock'];
  523. // $temp['warn_stock'] = $value['warn_stock'];
  524. $temp['child']=isset($good)&&!empty($good) ? $good:[];
  525. $data[]=$temp;
  526. }
  527. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  528. }
  529. public function GetStockGod(){
  530. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  531. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  532. $condition = [["b.is_del","=",0],["c.usable_stock",">",0]];
  533. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  534. if($type_code!==""){
  535. $condition[]=["b.spuCode","like","%{$type_code}%"];
  536. }
  537. $count = Db::name("good")->alias("b")
  538. ->join("good_stock c","c.spuCode = b.spuCode","left")
  539. ->where($condition)
  540. ->group("b.spuCode,b.good_name,b.good_unit,b.cat_id,b.craft_desc,b.addtime")
  541. ->count();
  542. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  543. $list = Db::name("good")
  544. ->alias("b")
  545. ->join("good_stock c","c.spuCode = b.spuCode","left")
  546. ->where($condition)
  547. ->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.total_stock) total_stock")
  548. ->page($page,$size)
  549. ->order("b.addtime desc")
  550. ->group("b.spuCode,b.good_name,b.good_unit,b.brand_id,b.cat_id,b.craft_desc,b.addtime")
  551. ->select()
  552. ->toArray();
  553. // echo Db::name("good_type")->getLastSql();
  554. $data=[];
  555. if($list) {
  556. //商品单位和品牌
  557. $good_unit_s = Db::name("unit")->whereIn('id', array_column($list, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
  558. $brands = Db::name("brand")->whereIn('id', array_column($list, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
  559. foreach ($list as $key => $value) {
  560. $temp = [];
  561. if ($value['spuCode'] != "") {
  562. $child = Db::name("good_stock")
  563. ->alias("a")
  564. ->join("warehouse_info b", "a.wsm_code=b.wsm_code", "left")
  565. ->join("business bus", "bus.companyNo=b.companyNo", "left")
  566. ->join("supplier s", "s.code=b.supplierNo", "left")
  567. ->where(['a.spuCode' => $value['spuCode'], "b.wsm_type" => 1, "a.is_del" => 0])
  568. ->field("a.wsm_code,b.name wsm_name,a.wait_in_stock,a.wait_out_stock,a.usable_stock,a.intra_stock,a.total_stock,a.warn_stock,b.supplierNo,s.name supplierName,b.companyNo,bus.company")
  569. ->select()
  570. ->toArray();
  571. }
  572. $temp['good_name'] = $value['good_name'];
  573. $temp['good_code'] = $value['spuCode'];
  574. $temp['type_code'] = '';
  575. // $unit = Db::name("unit")->where(['id' => $value['good_unit']])->find();
  576. $temp['unit'] =$good_unit_s[$value['spuCode']]??'';
  577. $temp['brand_name'] =$brands[$value['brand_id']]??'';
  578. $temp['sort_f'] = isset($value['cat_id']) ? made($value['cat_id']) : [];
  579. $temp['sort_f'] = implode('/', array_column($temp['sort_f'], 'name'));//由于这个字段原样在页面显示,所以在这里特意拼接成字符串
  580. $temp['attribute'] = $value['craft_desc'];
  581. $temp['addtime'] = $value['addtime'];
  582. $temp['usable_stock'] = isset($value['usable_stock']) ? $value['usable_stock'] : "";
  583. $temp['wait_in_stock'] = isset($value['wait_in_stock']) ? $value['wait_in_stock'] : "";
  584. $temp['wait_out_stock'] = isset($value['wait_out_stock']) ? $value['wait_out_stock'] : "";
  585. $temp['intra_stock'] = isset($value['intra_stock']) ? $value['intra_stock'] : "";
  586. $temp['total_stock'] = isset($value['total_stock']) ? $value['total_stock'] : "";
  587. // $temp['warn_stock'] = isset($value['warn_stock'])? $value['warn_stock']:"";
  588. $temp['child'] = isset($child) && !empty($child) ? $child : [];
  589. //规格信息
  590. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  591. $speclist = [];
  592. if (!empty($spec)) {
  593. foreach ($spec as $val) {
  594. $tmp = [];
  595. $tmp['spec_id'] = $val['spec_id'];
  596. $tmp['spec_value_id'] = $val['spec_value_id'];
  597. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  598. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  599. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  600. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  601. $speclist[] = $tmp;
  602. }
  603. }
  604. $temp['specinfo'] = $speclist;
  605. $data[] = $temp;
  606. }
  607. }
  608. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  609. }
  610. /**
  611. * @return \think\response\Json|void
  612. * @throws \think\db\exception\DataNotFoundException
  613. * @throws \think\db\exception\DbException
  614. * @throws \think\db\exception\ModelNotFoundException
  615. */
  616. public function Stat(){
  617. $condition =[["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["wsm_code"] = $wsm_code;
  621. $condition[]=["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[]=["wsm_code","in",$wsmcode];
  627. }
  628. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  629. if ($companyNo !== "") {
  630. // $where['khNo'] = $khNo;
  631. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  632. $condition[]=["wsm_code","in",$wsmcode];
  633. }
  634. // $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  635. // if($type_code!=""){
  636. // $condition[] = ["good_type_code","=",$type_code];
  637. // }
  638. $statlist = Db::name("good_stock")->where($condition)->field("sum(wait_in_stock) as wait_in_stock,sum(wait_out_stock) as wait_out_stock ,sum(usable_stock) as usable_stock,sum(intra_stock) as intra_stock,sum(total_stock) as total_stock,sum(warn_stock) as warn_stock")->find();
  639. return app_show(0,"获取成功",$statlist);
  640. }
  641. public function all(){
  642. $condtion=["a.is_del"=>0,"b.is_del"=>0];
  643. $wsmcode =isset($this->post['wsmcode']) &&$this->post['wsmcode'] !=="" ? trim($this->post['wsmcode']):"";
  644. if($wsmcode!=""){
  645. $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code");
  646. $condtion["b.type_code"] = $typecode;
  647. }
  648. $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  649. if($good_code!=""){
  650. $condtion['b.type_code'] = $good_code;
  651. }
  652. $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code'])
  653. :"";
  654. if($goodcode!=""){
  655. $condtion['a.good_code'] = $goodcode;
  656. }
  657. $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name'])
  658. :"";
  659. if($good_name!=""){
  660. $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'");
  661. }
  662. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  663. if($supplierNo!=""){
  664. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  665. if(empty($supplier)){
  666. return error_show(1004,"未找到供应商信息");
  667. }
  668. $condtion["a.gys_code"] = $supplierNo;
  669. }
  670. $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  671. ->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,
  672. 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")
  673. ->select();
  674. $data=[];
  675. foreach ($list as $key=>$value){
  676. $stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock");
  677. $value['usable_stock']=$stock;
  678. $supplier = Db::name("supplier")->where(["code"=>$value['gys_code']])->find();
  679. $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
  680. $data[]=$value;
  681. }
  682. return app_show(0,"获取成功",$data);
  683. }
  684. public function loglist(){
  685. $page = isset($this->post['page']) && $this->post['page']!==""? intval($this->post['page']) :"1";
  686. $size = isset($this->post['size']) && $this->post['size']!==""? intval($this->post['size']) :"10";
  687. $where=[];
  688. $wsm_code= isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  689. if($wsm_code!=""){
  690. $where[]=['b.wsm_code',"like","%$wsm_code%"];
  691. }
  692. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  693. if($supplierNo!=""){
  694. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  695. if(empty($supplier)){
  696. return error_show(1004,"未找到供应商信息");
  697. }
  698. $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"supplierNo"=>$supplierNo])->column("wsm_code");
  699. $where[]=['b.wsm_code',"in",$wsmcode];
  700. }
  701. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  702. if ($companyNo !== "") {
  703. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  704. $condition[]=["b.wsm_code","in",$wsmcode];
  705. }
  706. $count = Db::name("good_log")
  707. ->alias('a')
  708. ->join("good_stock b","b.id=a.id","left")
  709. ->where($where)
  710. ->count();
  711. $total = ceil($count/$size);
  712. $page = $total>=$page ? $page :$total;
  713. $list = Db::name("good_log")
  714. ->alias('a')
  715. ->join("good_stock b","b.id=a.stock_id","left")
  716. ->where($where)
  717. ->page($page,$size)
  718. ->order("a.addtime desc")
  719. ->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")
  720. ->select()
  721. ->toArray();
  722. $data=[];
  723. $action_uids = array_column($list, 'action_uid');
  724. $action_uids = array_unique($action_uids);
  725. $item = [];
  726. foreach ($action_uids as $action_uid) {
  727. $items = Db::name("depart_user")->where('uid', $action_uid)->column("itemid");
  728. foreach ($items as $it) {
  729. $item[$action_uid][] = implode('/', array_column(GetPart($it), 'name'));
  730. }
  731. }
  732. foreach ($list as $value){
  733. $wsm = Db::name("warehouse_info")
  734. ->alias("a")
  735. ->Join("supplier b","a.supplierNo=b.code","left")
  736. ->Join("business bus","bus.companyNo=a.companyNo","left")
  737. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  738. ->field("a.name as wsm_name,wsm_code,b.code,b.name,bus.company,bus.companyNo")
  739. ->find();
  740. $godd =Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  741. $value['good_name']=isset($godd['good_name'])? $godd['good_name']:"";
  742. $value['cat_id']=isset($godd['cat_id'])? $godd['cat_id']:"";
  743. $int = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  744. $value['wsm_name'] =$wsm['wsm_name'];
  745. $value['wsm_code'] =$wsm['wsm_code'];
  746. $value['code'] =$wsm['code'];
  747. $value['name'] =$wsm['name'];
  748. $value['action_type_cn'] =$this->acton[$value['action_type']];
  749. $value['item'] =$item[$value['action_uid']];
  750. $value['can'] =$int;
  751. $value['company'] =$wsm['company']??'';
  752. $value['companyNo'] =$wsm['companyNo']??'';
  753. $data[]=$value;
  754. }
  755. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  756. }
  757. public function goodlist(){
  758. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  759. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  760. $where =[["a.is_del","=",0],["b.exam_status","=",6],["b.is_del","=",0],["c.is_del","=",0],["c.status","=",1]];
  761. $paltcode = isset($this->post["platform_code"])&& $this->post["platform_code"]!=""? trim($this->post["platform_code"]):"";
  762. if($paltcode!=""){
  763. $where[]=["platform_code","=",$paltcode];
  764. }
  765. $companyNo = isset($this->post["companyNo"])&& $this->post["companyNo"]!=""? trim($this->post["companyNo"])
  766. :"";
  767. if($companyNo!=""){
  768. $where[]=["companyNo","like","%$companyNo%"];
  769. }
  770. $cat_id = isset($this->post["cat_id"])&& $this->post["cat_id"]!==""? intval($this->post["cat_id"]):"";
  771. if($cat_id!==""){
  772. $where[]=["cat_id","=",$cat_id];
  773. }
  774. $buy_num = isset($this->post["buy_num"])&& $this->post["buy_num"]!==""? intval($this->post["buy_num"]):"";
  775. if($buy_num!==""){
  776. $where[]=["min_num","<=",$buy_num];
  777. }
  778. $price = isset($this->post["price"])&& $this->post["price"]!==""? floatval($this->post["price"]):"";
  779. if($buy_num!==""){
  780. $where[]=["sale_price","<=",$price];
  781. }
  782. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->leftJoin("good_ladder c","b.skuCode=c.skuCode")
  783. ->where($where)->count();
  784. $total = ceil($count / $size);
  785. $page = $page >= $total ? $total : $page;
  786. $list = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->leftJoin("good_ladder c","b.skuCode=c.skuCode")->where($where)->page
  787. ($page,$size)->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")
  788. ->order("b.addtime desc")
  789. ->select();
  790. $data=[];
  791. foreach ($list as $value){
  792. $value['cat_info']= made($value['cat_id'],[]);
  793. $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
  794. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
  795. $value['platform_code_en'] = isset($platform['platform_code']) ? $platform['platform_code']:"";
  796. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  797. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  798. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  799. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  800. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  801. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  802. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  803. $value['company'] = isset($company['company'])?$company['company']:"";
  804. $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
  805. $value['status']=$value['exam_status'];
  806. $data[]=$value;
  807. }
  808. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  809. }
  810. //根据价格区间,筛选符合条件的商品列表
  811. public function getGoodListByLadder()
  812. {
  813. //1.请求参数
  814. $param=$this->request->only(['min_price','max_price','page'=>1,'size'=>15],'post','trim');
  815. //2.参数校验
  816. $val=Validate::rule([
  817. 'min_price'=>'require|float|elt:max_price',
  818. 'max_price'=>'require|float|egt:min_price',
  819. 'page'=>'require|number|gt:0',
  820. 'size'=>'require|number|gt:0',
  821. ]);
  822. if(!$val->check($param)) return error_show(1004,$val->getError());
  823. //3.组织SQL语句
  824. $skuCodes = Db::name('good_ladder')
  825. ->field('skuCode')
  826. ->whereBetween('sale_price', [$param['min_price'], $param['max_price']])
  827. ->where(['is_del' => 0, 'status' => 1])
  828. ->group('skuCode')
  829. ->buildSql();
  830. //4.查询列表并补充相关信息(从list方法照搬)
  831. $list = Db::name('good')
  832. ->alias("a")
  833. ->field("b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.*,b.addtime,b.updatetime,b.exam_status,gb.createrid purchase_id,gb.creater purchase,gl.min_num,gl.max_num")//成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  834. ->leftJoin("good_platform b", "a.spuCode=b.spuCode")
  835. ->leftJoin("good_basic gb", "gb.spuCode=a.spuCode")
  836. ->leftJoin("good_ladder gl", "gl.skuCode=b.skuCode")
  837. ->where('b.skuCode in ' . $skuCodes)
  838. ->page($param['page'], $param['size'])
  839. ->order("b.addtime desc")
  840. ->select();
  841. $data = [];
  842. foreach ($list as $value) {
  843. $value['cat_info'] = made($value['cat_id'], []);
  844. $platform = Db::name("platform")->where(["id" => $value['platform_code']])->find();
  845. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name'] : "";
  846. $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en'] : "";
  847. $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  848. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name'] : "";
  849. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  850. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  851. $unit = Db::name("unit")->where(["id" => $value['good_unit']])->find();
  852. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : "";
  853. $company = Db::name("business")->where(["companyNo" => $value['companyNo']])->find();
  854. $value['company'] = isset($company['company']) ? $company['company'] : "";
  855. $value['stock_total'] = Db::name("good_stock")->where(['spuCode' => $value['spuCode'], "is_del" => 0])->sum("usable_stock");
  856. $value['status'] = $value['exam_status'];
  857. $value['exclusive'] = makeExcluse($value['is_exclusive']);
  858. $value['good_info_img'] = $value['good_info_img'];
  859. $value['good_img'] = $value['good_img'];
  860. $spec = Db::name("good_spec")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  861. $speclist = [];
  862. if (!empty($spec)) {
  863. foreach ($spec as $val) {
  864. $temp = [];
  865. $temp['spec_id'] = $val['spec_id'];
  866. $temp['spec_value_id'] = $val['spec_value_id'];
  867. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  868. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  869. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  870. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  871. $speclist[] = $temp;
  872. }
  873. }
  874. $value['specinfo'] = $speclist;
  875. $value['noble_name'] = isset($value['noble_metal']) && $value['noble_metal'] != 0 ? $this->noble[$value['noble_metal']] : "";
  876. $data[] = $value;
  877. }
  878. return app_show(0, '请求成功', $data);
  879. }
  880. }