Good.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  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. //补充采购员字段
  255. //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  256. $temp_basic_info = Db::name('good_basic')
  257. ->field('id,createrid purchase_id,creater purchase')
  258. ->where(['spuCode'=>$data['spuCode'],'is_del'=>0])
  259. ->find();
  260. $data['purchase_id'] = $temp_basic_info['purchase_id'];
  261. $data['purchase'] = $temp_basic_info['purchase'];
  262. return app_show(0,"获取成功",$data);
  263. }
  264. public function SetWarn(){
  265. $condition=["is_del"=>0];
  266. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  267. if($wsm_code!=""){
  268. $condition["wsm_code"] = $wsm_code;
  269. }else{
  270. return error_show(1004,"参数wsm_code 不能为空");
  271. }
  272. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  273. if($type_code!=""){
  274. $condition["good_type_code"] = $type_code;
  275. }else{
  276. return error_show(1004,"参数type_code 不能为空");
  277. }
  278. $good= Db::name("good_stock")->where($condition)->find();
  279. if(empty($good)){
  280. return error_show(1005,"未找到数据");
  281. }
  282. $warn_stock = isset($this->post['warn_stock']) &&$this->post['warn_stock'] !=="" ? intval($this->post['warn_stock']):"";
  283. if($warn_stock===""){
  284. return error_show(1005,"参数warn_stock 不能为空");
  285. }
  286. $good['warn_stock'] = $warn_stock;
  287. $good['updatetime'] = date("Y-m-d H:i:s");
  288. $up= Db::name("good_stock")->save($good);
  289. if($up){
  290. //商品变动日志表,good_log_code字段存储仓库编码
  291. $data = ['good_log_code' => $wsm_code, "stock_id" => $good['id'], "type" => 1, 'stock' => $warn_stock, "stock_name" => "warn_stock"];
  292. GoodLog::LogAdd($this->post['token'],$data,'setwarn');
  293. return app_show(0,"预警库存更新成功");
  294. }else{
  295. return error_show(1005,"预警库存更新失败");
  296. }
  297. }
  298. public function SetStatus(){
  299. $id = isset($this->post['id']) &&$this->post['id'] !=="" ? intval($this->post['id']):"";
  300. if($id===""){
  301. return error_show(1005,"参数id 不能为空");
  302. }
  303. $good= Db::name("good_type")->where(["id"=>$id,"is_del"=>0])->find();
  304. if(empty($good)){
  305. return error_show(1005,"未找到数据");
  306. }
  307. $good['status'] = $good['status']==1?0 :1;
  308. $good['updatetime'] = date("Y-m-d H:i:s");
  309. $msg = $good['status']==1?"下架" :"上架";
  310. $up= Db::name("good_type")->save($good);
  311. return $up ? app_show(0,"商品{$msg}成功"): error_show(1005,"商品{$msg}失败");
  312. }
  313. public function GetStock(){
  314. $condition = [["a.is_del","=",0]];
  315. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  316. if($type_code!==""){
  317. $condition[]=["a.spuCode","=",$type_code];
  318. }
  319. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  320. :"";
  321. if($wsm_code!==""){
  322. //$condition["a.wsm_code"]=$wsm_code;
  323. $condition[]=["a.wsm_code","=",$type_code];
  324. }
  325. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  326. :"";
  327. if($suplierNo!==""){
  328. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  329. $condition[]=["a.wsm_code","in",$wsmcode];
  330. }
  331. $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")
  332. ->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();
  333. if(empty($list)){
  334. return error_show(1004,"未找到数据");
  335. }
  336. return app_show(0,"获取成功",$list);
  337. }
  338. /**
  339. * @return \think\response\Json|void
  340. * @throws \think\db\exception\DataNotFoundException
  341. * @throws \think\db\exception\DbException
  342. * @throws \think\db\exception\ModelNotFoundException
  343. */
  344. public function GetStockBet(){
  345. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  346. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  347. $condition = [["is_del","=",0]];
  348. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  349. if($type_code!==""){
  350. $condition[]=["spuCode","like","%{$type_code}%"];
  351. }
  352. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  353. :"";
  354. if($wsm_code!==""){
  355. $condition[]=["wsm_code","=",$wsm_code];
  356. }
  357. $suplierNo = isset($this->post['suplierNo']) &&$this->post['suplierNo'] !=="" ? trim($this->post['suplierNo']):"";
  358. if($suplierNo!==""){
  359. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  360. $condition[]=["wsm_code","in",$wsmcode];
  361. }
  362. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  363. if ($companyNo !== "") {
  364. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  365. $condition[]=["wsm_code","in",$wsmcode];
  366. }
  367. $start = isset($this->post['start']) &&$this->post['start'] !=="" ? $this->post['start']:"";
  368. $end = isset($this->post['end']) &&$this->post['end'] !=="" ? $this->post['end']:"";
  369. if($start!=""){
  370. $condition[]=["addtime",">=",$start];
  371. }
  372. if($end!=""){
  373. $condition[]=["addtime","<=",$end];
  374. }
  375. $count = Db::name("good_stock")->where($condition)->count();
  376. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  377. $list = Db::name("good_stock")->where($condition)->page($page,$size)->order("addtime desc")->select();
  378. $data=[];
  379. foreach ($list as $key=>$value){
  380. $temp=[];
  381. if($value['wsm_code']!=""){
  382. $wsm = Db::name("warehouse_info")
  383. ->alias("a")
  384. ->leftJoin("supplier b","a.supplierNo=b.code")
  385. ->leftJoin("business bus","a.companyNo=bus.companyNo")
  386. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  387. ->field("a.name as wsm_name,wsm_code,a.supplierNo,b.name supplierName,a.companyNo,bus.company")
  388. ->find();
  389. }
  390. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  391. $temp['wsm_code']=$value['wsm_code'];
  392. $temp['supplier_code']=isset($wsm['supplierNo'])?$wsm['supplierNo']:"";
  393. $temp['supplier_name']=isset($wsm['supplierName'])?$wsm['supplierName']:"";
  394. $temp['company_no']=isset($wsm['companyNo'])?$wsm['companyNo']:"";
  395. $temp['company_name']=isset($wsm['company'])?$wsm['company']:"";
  396. if($value['spuCode']!=""){
  397. $good=Db::name("good")
  398. ->alias('g')
  399. ->field('g.*,b.brand_name,u.unit')
  400. ->where(["g.spuCode"=>$value['spuCode'],"g.is_del"=>0])
  401. ->leftJoin('brand b','b.id=g.brand_id')
  402. ->leftJoin('unit u','u.id=g.good_unit')
  403. ->find();
  404. //规格信息
  405. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  406. $speclist = [];
  407. if (!empty($spec)) {
  408. foreach ($spec as $val) {
  409. $tmp = [];
  410. $tmp['spec_id'] = $val['spec_id'];
  411. $tmp['spec_value_id'] = $val['spec_value_id'];
  412. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  413. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  414. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  415. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  416. $speclist[] = $tmp;
  417. }
  418. }
  419. $temp['specinfo'] = $speclist;
  420. }
  421. $temp['good_code']=isset($good['spuCode'])?$good['spuCode']:"";
  422. // $temp['type_code']=isset($good['type_code'])?$good['type_code']:"";
  423. $temp['good_name']=isset($good['good_name'])?$good['good_name']:"";
  424. $temp['unit']=isset($good['unit'])?$good['unit']:"";
  425. $temp['brand_name']=isset($good['brand_name'])?$good['brand_name']:"";
  426. // $temp['attribute']=isset($good['attribute'])?$good['attribute']:"";
  427. $temp['sort_f']=isset($good['cat_id'])?$good['cat_id']:"";
  428. $temp['cat_info']=isset($good['cat_id'])?made($good['cat_id']):"";
  429. $temp['usable_stock'] = $value['usable_stock'];
  430. $temp['wait_in_stock'] = $value['wait_in_stock'];
  431. $temp['wait_out_stock'] = $value['wait_out_stock'];
  432. $temp['intra_stock'] = $value['intra_stock'];
  433. $temp['total_stock'] = $value['total_stock'];
  434. $temp['warn_stock'] = $value['warn_stock'];
  435. $temp['id'] = $value['id'];
  436. $temp['out_total'] =0;
  437. $temp['in_total'] = 0;
  438. $temp['addtime'] = $value['addtime'];
  439. $data[]=$temp;
  440. }
  441. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  442. }
  443. /**
  444. * @return \think\response\Json|void
  445. * @throws \think\db\exception\DataNotFoundException
  446. * @throws \think\db\exception\DbException
  447. * @throws \think\db\exception\ModelNotFoundException
  448. * @throws \think\exception\DbException
  449. */
  450. public function GetStockWsm(){
  451. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  452. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  453. $condition = [["gs.is_del","=",0]];
  454. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  455. if($wsm_code!==""){
  456. $condition[]=["gs.wsm_code","=",$wsm_code];
  457. }
  458. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  459. if($suplierNo!==""){
  460. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  461. $condition[]=["gs.wsm_code","in",$wsmcode];
  462. }
  463. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  464. if ($companyNo !== "") {
  465. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  466. $condition[]=["gs.wsm_code","in",$wsmcode];
  467. }
  468. $build= Db::name("good_stock")
  469. ->alias('gs')
  470. ->where($condition)
  471. ->where('whi.wsm_type','<>',2)//2表示虚拟仓,虚拟仓不参加统计
  472. ->leftJoin('warehouse_info whi','whi.wsm_code=gs.wsm_code AND whi.is_del=0')
  473. ->group("gs.wsm_code")
  474. ->field("gs.wsm_code")
  475. ->buildSql();
  476. $count = Db::table($build." a")->count();
  477. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  478. $list = Db::name("good_stock")
  479. ->alias('gs')
  480. ->where($condition)
  481. ->where('whi.wsm_type','<>',2)//2表示虚拟仓,虚拟仓不参加统计
  482. ->page($page,$size)
  483. ->leftJoin('warehouse_info whi','whi.wsm_code=gs.wsm_code AND whi.is_del=0')
  484. ->group("gs.wsm_code")
  485. ->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(total_stock) total_stock")
  486. ->select()
  487. ->toArray();
  488. $data=[];
  489. foreach ($list as $key=>$value){
  490. $temp=[];
  491. if($value['wsm_code']!=""){
  492. $wsm = Db::name("warehouse_info")
  493. ->alias("a")
  494. ->leftJoin("business bus", "bus.companyNo=a.companyNo")
  495. ->leftJoin("supplier b","a.supplierNo=b.code")
  496. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  497. ->field("a.name as wsm_name,wsm_code,a.supplierNo,b.name supplierName,a.companyNo,bus.company")
  498. ->find();
  499. $good = Db::name("good_stock")
  500. ->alias("a")
  501. ->leftJoin("good c","c.spuCode=a.spuCode")
  502. ->where(["a.wsm_code"=>$value['wsm_code'],"a.is_del"=>0,"c.is_del"=>0])
  503. ->select()
  504. ->toArray();
  505. //商品单位和品牌
  506. $good_unit_s = Db::name("unit")->whereIn('id', array_column($good, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
  507. $brands = Db::name("brand")->whereIn('id', array_column($good, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
  508. foreach ($good as &$item_good){
  509. //规格信息
  510. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $item_good['spuCode'], "is_del" => 0])->select()->toArray();
  511. $speclist = [];
  512. if (!empty($spec)) {
  513. foreach ($spec as $val) {
  514. $tmp = [];
  515. $tmp['spec_id'] = $val['spec_id'];
  516. $tmp['spec_value_id'] = $val['spec_value_id'];
  517. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  518. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  519. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  520. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  521. $speclist[] = $tmp;
  522. }
  523. }
  524. $item_good['specinfo'] = $speclist;
  525. $item_good['unit'] = $good_unit_s[$item_good['good_unit']]??'';
  526. $item_good['brand_name'] = $brands[$item_good['brand_id']]??'';
  527. $item_good['can'] = made($item_good['cat_id'],[]);
  528. }
  529. }
  530. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  531. $temp['wsm_code']=$value['wsm_code'];
  532. $temp['supplier_code']=isset($wsm['supplierNo'])?$wsm['supplierNo']:"";
  533. $temp['supplier_name']=isset($wsm['supplierName'])?$wsm['supplierName']:"";
  534. $temp['company_no']=isset($wsm['companyNo'])?$wsm['companyNo']:"";
  535. $temp['company_name']=isset($wsm['company'])?$wsm['company']:"";
  536. $temp['usable_stock'] = $value['usable_stock'];
  537. $temp['wait_in_stock'] = $value['wait_in_stock'];
  538. $temp['wait_out_stock'] = $value['wait_out_stock'];
  539. $temp['intra_stock'] = $value['intra_stock'];
  540. $temp['total_stock'] = $value['total_stock'];
  541. // $temp['warn_stock'] = $value['warn_stock'];
  542. $temp['child']=isset($good)&&!empty($good) ? $good:[];
  543. $data[]=$temp;
  544. }
  545. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  546. }
  547. public function GetStockGod(){
  548. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  549. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  550. $condition = [["b.is_del","=",0],["c.usable_stock",">",0]];
  551. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  552. if($type_code!==""){
  553. $condition[]=["b.spuCode","like","%{$type_code}%"];
  554. }
  555. $count = Db::name("good")->alias("b")
  556. ->join("good_stock c","c.spuCode = b.spuCode","left")
  557. ->where($condition)
  558. ->group("b.spuCode,b.good_name,b.good_unit,b.cat_id,b.craft_desc,b.addtime")
  559. ->count();
  560. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  561. $list = Db::name("good")
  562. ->alias("b")
  563. ->join("good_stock c","c.spuCode = b.spuCode","left")
  564. ->where($condition)
  565. ->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")
  566. ->page($page,$size)
  567. ->order("b.addtime desc")
  568. ->group("b.spuCode,b.good_name,b.good_unit,b.brand_id,b.cat_id,b.craft_desc,b.addtime")
  569. ->select()
  570. ->toArray();
  571. // echo Db::name("good_type")->getLastSql();
  572. $data=[];
  573. if($list) {
  574. //商品单位和品牌
  575. $good_unit_s = Db::name("unit")->whereIn('id', array_column($list, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
  576. $brands = Db::name("brand")->whereIn('id', array_column($list, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
  577. foreach ($list as $key => $value) {
  578. $temp = [];
  579. if ($value['spuCode'] != "") {
  580. $child = Db::name("good_stock")
  581. ->alias("a")
  582. ->join("warehouse_info b", "a.wsm_code=b.wsm_code", "left")
  583. ->join("business bus", "bus.companyNo=b.companyNo", "left")
  584. ->join("supplier s", "s.code=b.supplierNo", "left")
  585. ->where(['a.spuCode' => $value['spuCode'], "b.wsm_type" => 1, "a.is_del" => 0])
  586. ->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")
  587. ->select()
  588. ->toArray();
  589. }
  590. $temp['good_name'] = $value['good_name'];
  591. $temp['good_code'] = $value['spuCode'];
  592. $temp['type_code'] = '';
  593. // $unit = Db::name("unit")->where(['id' => $value['good_unit']])->find();
  594. $temp['unit'] =$good_unit_s[$value['spuCode']]??'';
  595. $temp['brand_name'] =$brands[$value['brand_id']]??'';
  596. $temp['sort_f'] = isset($value['cat_id']) ? made($value['cat_id']) : [];
  597. $temp['sort_f'] = implode('/', array_column($temp['sort_f'], 'name'));//由于这个字段原样在页面显示,所以在这里特意拼接成字符串
  598. $temp['attribute'] = $value['craft_desc'];
  599. $temp['addtime'] = $value['addtime'];
  600. $temp['usable_stock'] = isset($value['usable_stock']) ? $value['usable_stock'] : "";
  601. $temp['wait_in_stock'] = isset($value['wait_in_stock']) ? $value['wait_in_stock'] : "";
  602. $temp['wait_out_stock'] = isset($value['wait_out_stock']) ? $value['wait_out_stock'] : "";
  603. $temp['intra_stock'] = isset($value['intra_stock']) ? $value['intra_stock'] : "";
  604. $temp['total_stock'] = isset($value['total_stock']) ? $value['total_stock'] : "";
  605. // $temp['warn_stock'] = isset($value['warn_stock'])? $value['warn_stock']:"";
  606. $temp['child'] = isset($child) && !empty($child) ? $child : [];
  607. //规格信息
  608. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  609. $speclist = [];
  610. if (!empty($spec)) {
  611. foreach ($spec as $val) {
  612. $tmp = [];
  613. $tmp['spec_id'] = $val['spec_id'];
  614. $tmp['spec_value_id'] = $val['spec_value_id'];
  615. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  616. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  617. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  618. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  619. $speclist[] = $tmp;
  620. }
  621. }
  622. $temp['specinfo'] = $speclist;
  623. $data[] = $temp;
  624. }
  625. }
  626. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  627. }
  628. /**
  629. * @return \think\response\Json|void
  630. * @throws \think\db\exception\DataNotFoundException
  631. * @throws \think\db\exception\DbException
  632. * @throws \think\db\exception\ModelNotFoundException
  633. */
  634. public function Stat(){
  635. $condition =[["gs.is_del","=",0]];
  636. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  637. if($wsm_code!=""){
  638. //$condition["gs.wsm_code"] = $wsm_code;
  639. $condition[]=["gs.wsm_code","=",$wsm_code];
  640. }
  641. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  642. if($suplierNo!==""){
  643. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  644. $condition[]=["gs.wsm_code","in",$wsmcode];
  645. }
  646. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  647. if ($companyNo !== "") {
  648. // $where['khNo'] = $khNo;
  649. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  650. $condition[]=["gs.wsm_code","in",$wsmcode];
  651. }
  652. // $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  653. // if($type_code!=""){
  654. // $condition[] = ["gs.good_type_code","=",$type_code];
  655. // }
  656. $statlist = Db::name("good_stock")
  657. ->alias('gs')
  658. ->where($condition)
  659. ->where('whi.wsm_type','<>',2)//2表示虚拟仓,虚拟仓不参与
  660. ->leftJoin('warehouse_info whi','whi.wsm_code=gs.wsm_code AND whi.is_del=0')
  661. ->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.total_stock) as total_stock,sum(gs.warn_stock) as warn_stock")
  662. ->find();
  663. return app_show(0,"获取成功",$statlist);
  664. }
  665. public function all(){
  666. $condtion=["a.is_del"=>0,"b.is_del"=>0];
  667. $wsmcode =isset($this->post['wsmcode']) &&$this->post['wsmcode'] !=="" ? trim($this->post['wsmcode']):"";
  668. if($wsmcode!=""){
  669. $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code");
  670. $condtion["b.type_code"] = $typecode;
  671. }
  672. $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  673. if($good_code!=""){
  674. $condtion['b.type_code'] = $good_code;
  675. }
  676. $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code'])
  677. :"";
  678. if($goodcode!=""){
  679. $condtion['a.good_code'] = $goodcode;
  680. }
  681. $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name'])
  682. :"";
  683. if($good_name!=""){
  684. $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'");
  685. }
  686. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  687. if($supplierNo!=""){
  688. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  689. if(empty($supplier)){
  690. return error_show(1004,"未找到供应商信息");
  691. }
  692. $condtion["a.gys_code"] = $supplierNo;
  693. }
  694. $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  695. ->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,
  696. 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")
  697. ->select();
  698. $data=[];
  699. foreach ($list as $key=>$value){
  700. $stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock");
  701. $value['usable_stock']=$stock;
  702. $supplier = Db::name("supplier")->where(["code"=>$value['gys_code']])->find();
  703. $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
  704. $data[]=$value;
  705. }
  706. return app_show(0,"获取成功",$data);
  707. }
  708. public function loglist(){
  709. $page = isset($this->post['page']) && $this->post['page']!==""? intval($this->post['page']) :"1";
  710. $size = isset($this->post['size']) && $this->post['size']!==""? intval($this->post['size']) :"10";
  711. $where=[];
  712. $wsm_code= isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  713. if($wsm_code!=""){
  714. $where[]=['b.wsm_code',"like","%$wsm_code%"];
  715. }
  716. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  717. if($supplierNo!=""){
  718. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  719. if(empty($supplier)){
  720. return error_show(1004,"未找到供应商信息");
  721. }
  722. $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"supplierNo"=>$supplierNo])->column("wsm_code");
  723. $where[]=['b.wsm_code',"in",$wsmcode];
  724. }
  725. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  726. if ($companyNo !== "") {
  727. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  728. $condition[]=["b.wsm_code","in",$wsmcode];
  729. }
  730. $count = Db::name("good_log")
  731. ->alias('a')
  732. ->join("good_stock b","b.id=a.id","left")
  733. ->where($where)
  734. ->count();
  735. $total = ceil($count/$size);
  736. $page = $total>=$page ? $page :$total;
  737. $list = Db::name("good_log")
  738. ->alias('a')
  739. ->join("good_stock b","b.id=a.stock_id","left")
  740. ->where($where)
  741. ->page($page,$size)
  742. ->order("a.addtime desc")
  743. ->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")
  744. ->select()
  745. ->toArray();
  746. $data=[];
  747. $action_uids = array_column($list, 'action_uid');
  748. $action_uids = array_unique($action_uids);
  749. $item = [];
  750. foreach ($action_uids as $action_uid) {
  751. $items = Db::name("depart_user")->where('uid', $action_uid)->column("itemid");
  752. foreach ($items as $it) {
  753. $item[$action_uid][] = implode('/', array_column(GetPart($it), 'name'));
  754. }
  755. }
  756. foreach ($list as $value){
  757. $wsm = Db::name("warehouse_info")
  758. ->alias("a")
  759. ->Join("supplier b","a.supplierNo=b.code","left")
  760. ->Join("business bus","bus.companyNo=a.companyNo","left")
  761. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  762. ->field("a.name as wsm_name,wsm_code,b.code,b.name,bus.company,bus.companyNo")
  763. ->find();
  764. $godd =Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  765. $value['good_name']=isset($godd['good_name'])? $godd['good_name']:"";
  766. $value['cat_id']=isset($godd['cat_id'])? $godd['cat_id']:"";
  767. $int = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  768. $value['wsm_name'] =$wsm['wsm_name'];
  769. $value['wsm_code'] =$wsm['wsm_code'];
  770. $value['code'] =$wsm['code'];
  771. $value['name'] =$wsm['name'];
  772. $value['action_type_cn'] =$this->acton[$value['action_type']];
  773. $value['item'] =$item[$value['action_uid']];
  774. $value['can'] =$int;
  775. $value['company'] =$wsm['company']??'';
  776. $value['companyNo'] =$wsm['companyNo']??'';
  777. $data[]=$value;
  778. }
  779. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  780. }
  781. public function goodlist(){
  782. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  783. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  784. $where =[["a.is_del","=",0],["b.exam_status","=",6],["b.is_del","=",0],["c.is_del","=",0],["c.status","=",1]];
  785. $paltcode = isset($this->post["platform_code"])&& $this->post["platform_code"]!=""? trim($this->post["platform_code"]):"";
  786. if($paltcode!=""){
  787. $where[]=["platform_code","=",$paltcode];
  788. }
  789. $companyNo = isset($this->post["companyNo"])&& $this->post["companyNo"]!=""? trim($this->post["companyNo"])
  790. :"";
  791. if($companyNo!=""){
  792. $where[]=["companyNo","like","%$companyNo%"];
  793. }
  794. $cat_id = isset($this->post["cat_id"])&& $this->post["cat_id"]!==""? intval($this->post["cat_id"]):"";
  795. if($cat_id!==""){
  796. $where[]=["cat_id","=",$cat_id];
  797. }
  798. $buy_num = isset($this->post["buy_num"])&& $this->post["buy_num"]!==""? intval($this->post["buy_num"]):"";
  799. if($buy_num!==""){
  800. $where[]=["min_num","<=",$buy_num];
  801. }
  802. $price = isset($this->post["price"])&& $this->post["price"]!==""? floatval($this->post["price"]):"";
  803. if($buy_num!==""){
  804. $where[]=["sale_price","<=",$price];
  805. }
  806. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->leftJoin("good_ladder c","b.skuCode=c.skuCode")
  807. ->where($where)->count();
  808. $total = ceil($count / $size);
  809. $page = $page >= $total ? $total : $page;
  810. $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
  811. ($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")
  812. ->order("b.addtime desc")
  813. ->select();
  814. $data=[];
  815. foreach ($list as $value){
  816. $value['cat_info']= made($value['cat_id'],[]);
  817. $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
  818. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
  819. $value['platform_code_en'] = isset($platform['platform_code']) ? $platform['platform_code']:"";
  820. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  821. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  822. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  823. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  824. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  825. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  826. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  827. $value['company'] = isset($company['company'])?$company['company']:"";
  828. $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
  829. $value['status']=$value['exam_status'];
  830. $data[]=$value;
  831. }
  832. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  833. }
  834. //根据价格区间,筛选符合条件的商品列表
  835. public function getGoodListByLadder()
  836. {
  837. //1.请求参数
  838. $param=$this->request->only(['min_price','max_price','page'=>1,'size'=>15],'post','trim');
  839. //2.参数校验
  840. $val=Validate::rule([
  841. 'min_price'=>'require|float|elt:max_price',
  842. 'max_price'=>'require|float|egt:min_price',
  843. 'page'=>'require|number|gt:0',
  844. 'size'=>'require|number|gt:0',
  845. ]);
  846. if(!$val->check($param)) return error_show(1004,$val->getError());
  847. //3.组织SQL语句
  848. $skuCodes = Db::name('good_ladder')
  849. ->field('skuCode')
  850. ->whereBetween('sale_price', [$param['min_price'], $param['max_price']])
  851. ->where(['is_del' => 0, 'status' => 1])
  852. ->group('skuCode')
  853. ->buildSql();
  854. //4.查询列表并补充相关信息(从list方法照搬)
  855. $list = Db::name('good')
  856. ->alias("a")
  857. ->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取个别名
  858. ->leftJoin("good_platform b", "a.spuCode=b.spuCode")
  859. ->leftJoin("good_basic gb", "gb.spuCode=a.spuCode")
  860. ->leftJoin("good_ladder gl", "gl.skuCode=b.skuCode")
  861. ->where('b.skuCode in ' . $skuCodes)
  862. ->page($param['page'], $param['size'])
  863. ->order("b.addtime desc")
  864. ->select();
  865. $data = [];
  866. foreach ($list as $value) {
  867. $value['cat_info'] = made($value['cat_id'], []);
  868. $platform = Db::name("platform")->where(["id" => $value['platform_code']])->find();
  869. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name'] : "";
  870. $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en'] : "";
  871. $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  872. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name'] : "";
  873. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  874. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  875. $unit = Db::name("unit")->where(["id" => $value['good_unit']])->find();
  876. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : "";
  877. $company = Db::name("business")->where(["companyNo" => $value['companyNo']])->find();
  878. $value['company'] = isset($company['company']) ? $company['company'] : "";
  879. $value['stock_total'] = Db::name("good_stock")->where(['spuCode' => $value['spuCode'], "is_del" => 0])->sum("usable_stock");
  880. $value['status'] = $value['exam_status'];
  881. $value['exclusive'] = makeExcluse($value['is_exclusive']);
  882. $value['good_info_img'] = $value['good_info_img'];
  883. $value['good_img'] = $value['good_img'];
  884. $spec = Db::name("good_spec")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  885. $speclist = [];
  886. if (!empty($spec)) {
  887. foreach ($spec as $val) {
  888. $temp = [];
  889. $temp['spec_id'] = $val['spec_id'];
  890. $temp['spec_value_id'] = $val['spec_value_id'];
  891. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  892. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  893. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  894. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  895. $speclist[] = $temp;
  896. }
  897. }
  898. $value['specinfo'] = $speclist;
  899. $value['noble_name'] = isset($value['noble_metal']) && $value['noble_metal'] != 0 ? $this->noble[$value['noble_metal']] : "";
  900. $data[] = $value;
  901. }
  902. return app_show(0, '请求成功', $data);
  903. }
  904. }