Good.php 52 KB

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