Good.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\GoodLog;
  4. use think\App;
  5. use think\facade\Db;
  6. //线上商品
  7. class Good extends Base
  8. {
  9. private $acton=[
  10. "allotsend"=>'调拨发货',
  11. "allotin"=>'调拨入库',
  12. "allotincheck"=>'调拨验货',
  13. 'CGD'=>'采购单',
  14. 'BHD'=>'备库单',
  15. 'FKD'=>'备库反馈单',
  16. 'RKD'=>'入库单',
  17. 'ZXQRD'=>'咨询单',
  18. 'XSQRD'=>'销售单',
  19. 'PDD'=>'盘点单',
  20. 'DBD'=>'调拨单',
  21. 'CKD'=>'出库单',
  22. 'CGTHD'=>'采购退货单',
  23. 'XSTHD'=>'销售退货单',
  24. 'CGGCD'=>'采购工差单',
  25. 'ZXGCD'=>'咨询工差单'
  26. ];
  27. public $noble=[];
  28. public function __construct(App $app)
  29. {
  30. parent::__construct($app);
  31. $this->noble=\think\facade\Config::get("noble");
  32. }
  33. public function list(){
  34. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  35. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  36. $where =[["a.is_del","=",0]];
  37. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? trim($this->post['cat_id']):"";
  38. if($cat_id!==""){
  39. $where[]=['a.cat_id',"=",$cat_id];
  40. }
  41. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  42. if($good_name!==""){
  43. $where[]=['a.good_name',"like","%$good_name%"];
  44. }
  45. $skucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode'])
  46. :"";
  47. if($skucode!==""){
  48. $where [] = ['b.skucode',"like","%$skucode%"];
  49. }
  50. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  51. if($start!==""){
  52. $where[]=['a.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  53. }
  54. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  55. if($end!==""){
  56. $where[]=['a.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  57. }
  58. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !=="" ? intval($this->post['is_stock'])
  59. :"";
  60. if($is_stock!==""){
  61. $where[]=['is_stock',"=",$is_stock];
  62. }
  63. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? intval($this->post['good_type'])
  64. :"";
  65. if($good_type!==""){
  66. $where[]=['good_type',"=",$good_type];
  67. }
  68. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  69. :"";
  70. if($supplierNo!==""){
  71. $where[]=['a.supplierNo',"=",$supplierNo];
  72. }
  73. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :"";
  74. if($companyNo!==""){
  75. $where[]=['a.companyNo',"like","%$companyNo%"];
  76. }
  77. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  78. if($creater!==""){
  79. $where[]=['a.creater',"like","%$creater%"];
  80. }
  81. $createrid = isset($this->post['createrid']) && $this->post['createrid'] !=="" ? intval($this->post['createrid']):"";
  82. if($createrid!==""){
  83. $where[]=['a.createrid',"=",$createrid];
  84. }
  85. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
  86. :"";
  87. if($status!==""){
  88. $where[]=['a.status',"=",$status];
  89. }
  90. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code'])
  91. :"";
  92. if($platform_code!==""){
  93. //$platform = Db::name("good_platform")->where(["platform_code"=>$platform_code,"is_del"=>0])->column
  94. //("spuCode");
  95. $where[]=["platform_code","=",$platform_code];
  96. }
  97. $plat_code = isset($this->post['plat_code']) && $this->post['plat_code'] !=="" ? trim($this->post['plat_code'])
  98. :"";
  99. if($plat_code!==""){
  100. $where[]=["b.plat_code","like","%$plat_code%"];
  101. }
  102. $exam_status = isset($this->post['exam_status']) && $this->post['exam_status'] !=="" ? intval($this->post['exam_status'])
  103. :"";
  104. if($exam_status!==""){
  105. $where[]=['b.exam_status',"=",$exam_status];
  106. }
  107. $brand_id = isset($this->post['brand_id']) && $this->post['brand_id'] !=="" ? intval($this->post['brand_id'])
  108. :"";
  109. if($brand_id!==""){
  110. $where[]=['a.brand_id',"=",$brand_id];
  111. }
  112. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where($where)
  113. ->count();
  114. $total = ceil($count / $size);
  115. $page = $page >= $total ? $total : $page;
  116. $list = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where($where)->page
  117. ($page,$size)->field("b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.*,b.addtime,b.updatetime,b.exam_status")
  118. ->order("b.addtime desc")
  119. ->select();
  120. $data=[];
  121. foreach ($list as $value){
  122. $value['cat_info']= made($value['cat_id'],[]);
  123. $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
  124. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
  125. $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en']:"";
  126. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  127. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  128. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  129. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  130. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  131. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  132. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  133. $value['company'] = isset($company['company'])?$company['company']:"";
  134. $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
  135. $value['status']=$value['exam_status'];
  136. $value['exclusive']=makeExcluse($value['is_exclusive']);
  137. $value['good_info_img']=$value['good_info_img'];
  138. $value['good_img']=$value['good_img'];
  139. $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
  140. $speclist=[];
  141. if(!empty($spec)){
  142. foreach ($spec as $val){
  143. $temp=[];
  144. $temp['spec_id']=$val['spec_id'];
  145. $temp['spec_value_id']=$val['spec_value_id'];
  146. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  147. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  148. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  149. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  150. $speclist[]=$temp;
  151. }
  152. }
  153. $value['specinfo']=$speclist;
  154. $value['noble_name']=isset($value['noble_metal'])&&$value['noble_metal']!=0?$this->noble[$value['noble_metal']] :"";
  155. $data[]=$value;
  156. }
  157. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  158. }
  159. public function info(){
  160. $skucode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
  161. if($skucode==""){
  162. return error_show(1005,"参数skuCode不能为空");
  163. }
  164. $good_platform = Db::name("good_platform")->where(['skuCode'=>$skucode,"is_del"=>0])->find();
  165. if($good_platform==false){
  166. return error_show(1004,"未找到商品数据");
  167. }
  168. $data = Db::name("good")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->find();
  169. if($data==false){
  170. return error_show(1004,"未找到商品数据");
  171. }
  172. $plat =Db::name("platform")->where(["id"=>$good_platform['platform_code']])->find();
  173. $data['skuCode']=$good_platform['skuCode'];
  174. $data['platform_code']=$good_platform['id'];
  175. $data['platform_code_en']=isset($plat['platform_code'])?$plat['platform_code']:"";
  176. $data['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  177. $data['online_reason']=$good_platform['online_reason'];
  178. $data['online_time']=$good_platform['online_time'];
  179. $data['online_remark']=$good_platform['online_remark'];
  180. $data['exam_status']=$good_platform['exam_status'];
  181. $data['is_online']=$good_platform['is_online'];
  182. $data['plat_code']=$good_platform['plat_code'];
  183. $data['exclusive']=makeExcluse($data['is_exclusive']);
  184. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  185. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  186. $data['cat_info'] = made($data['cat_id'],[]);
  187. $spec = Db::name("good_spec")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
  188. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  189. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  190. $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
  191. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  192. $data['company'] = isset($company['company'])?$company['company']:"";
  193. if($data['brand_id']!=0){
  194. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  195. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  196. }else{
  197. $data["brand_name"]="";
  198. $data["brand_id"]="";
  199. }
  200. $data['origin_place_cn']="";
  201. $data['delivery_place_cn']="";
  202. if($data['delivery_place']!==""){
  203. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  204. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['delivery_place']);
  205. $data['delivery_place_cn']=GetAddr(json_encode($place));
  206. }
  207. if($data['origin_place']!==""){
  208. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  209. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['origin_place']);
  210. $data['origin_place_cn']=GetAddr(json_encode($place));
  211. }
  212. $excluse = makeExcluse($data['is_exclusive']);
  213. $data['exclusive']=$excluse;
  214. $data["good_info_img"]=$data['good_info_img']!=""? $data['good_info_img']:[];
  215. $data["good_img"]=$data['good_img']!=""? $data['good_img']:[];
  216. $speclist=[];
  217. if(!empty($spec)){
  218. foreach ($spec as $value){
  219. $temp=[];
  220. $temp['id']=$value['id'];
  221. $temp['spuCode']=$value['spuCode'];
  222. $temp['spec_id']=$value['spec_id'];
  223. $temp['spec_value_id']=$value['spec_value_id'];
  224. $temp['is_del']=$value['is_del'];
  225. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  226. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  227. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  228. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  229. $speclist[]=$temp;
  230. }
  231. }
  232. $data["speclist"]=empty($speclist)?[]:$speclist;
  233. $ladder = Db::name("good_ladder")->where(['skuCode'=>$skucode,"is_del"=>0])->select()->toArray();
  234. $data["ladderlist"]=!empty($ladder)?$ladder:[];
  235. $nakelist = Db::name("good_nake")->where(['spuCode'=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
  236. $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  237. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  238. $nakearry=[];
  239. if(!empty($nakelist)){
  240. foreach ($nakelist as $value){
  241. $value['sale_price'] =$value['nake_total'];
  242. $nakearry[]=$value;
  243. }
  244. }
  245. $proof =Db::name("good_proof")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  246. $data['proof'] = isset($proof)&&$proof!=false? $proof:[];
  247. $data["nakelist"]=$nakearry;
  248. return app_show(0,"获取成功",$data);
  249. }
  250. public function SetWarn(){
  251. $condition=["is_del"=>0];
  252. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  253. if($wsm_code!=""){
  254. $condition["wsm_code"] = $wsm_code;
  255. }else{
  256. return error_show(1004,"参数wsm_code 不能为空");
  257. }
  258. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  259. if($type_code!=""){
  260. $condition["good_type_code"] = $type_code;
  261. }else{
  262. return error_show(1004,"参数type_code 不能为空");
  263. }
  264. $good= Db::name("good_stock")->where($condition)->find();
  265. if(empty($good)){
  266. return error_show(1005,"未找到数据");
  267. }
  268. $warn_stock = isset($this->post['warn_stock']) &&$this->post['warn_stock'] !=="" ? intval($this->post['warn_stock']):"";
  269. if($warn_stock===""){
  270. return error_show(1005,"参数warn_stock 不能为空");
  271. }
  272. $good['warn_stock'] = $warn_stock;
  273. $good['updatetime'] = date("Y-m-d H:i:s");
  274. $up= Db::name("good_stock")->save($good);
  275. if($up){
  276. $data=["stock_id"=>$good['id'],"type"=>1,'stock'=>$warn_stock,"stock_name"=>"warn_stock"];
  277. GoodLog::LogAdd($this->post['token'],$data,'setwarn');
  278. return app_show(0,"预警库存更新成功");
  279. }else{
  280. return error_show(1005,"预警库存更新失败");
  281. }
  282. }
  283. public function SetStatus(){
  284. $id = isset($this->post['id']) &&$this->post['id'] !=="" ? intval($this->post['id']):"";
  285. if($id===""){
  286. return error_show(1005,"参数id 不能为空");
  287. }
  288. $good= Db::name("good_type")->where(["id"=>$id,"is_del"=>0])->find();
  289. if(empty($good)){
  290. return error_show(1005,"未找到数据");
  291. }
  292. $good['status'] = $good['status']==1?0 :1;
  293. $good['updatetime'] = date("Y-m-d H:i:s");
  294. $msg = $good['status']==1?"下架" :"上架";
  295. $up= Db::name("good_type")->save($good);
  296. return $up ? app_show(0,"商品{$msg}成功"): error_show(1005,"商品{$msg}失败");
  297. }
  298. public function GetStock(){
  299. $condition = [["a.is_del","=",0]];
  300. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  301. if($type_code!==""){
  302. $condition[]=["a.spuCode","=",$type_code];
  303. }
  304. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  305. :"";
  306. if($wsm_code!==""){
  307. //$condition["a.wsm_code"]=$wsm_code;
  308. $condition[]=["a.wsm_code","=",$type_code];
  309. }
  310. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  311. :"";
  312. if($suplierNo!==""){
  313. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  314. $condition[]=["a.wsm_code","in",$wsmcode];
  315. }
  316. $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")
  317. ->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();
  318. if(empty($list)){
  319. return error_show(1004,"未找到数据");
  320. }
  321. return app_show(0,"获取成功",$list);
  322. }
  323. /**
  324. * @return \think\response\Json|void
  325. * @throws \think\db\exception\DataNotFoundException
  326. * @throws \think\db\exception\DbException
  327. * @throws \think\db\exception\ModelNotFoundException
  328. */
  329. public function GetStockBet(){
  330. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  331. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  332. $condition = [["is_del","=",0]];
  333. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  334. if($type_code!==""){
  335. $condition[]=["spuCode","like","%{$type_code}%"];
  336. }
  337. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  338. :"";
  339. if($wsm_code!==""){
  340. $condition[]=["wsm_code","=",$wsm_code];
  341. }
  342. $suplierNo = isset($this->post['suplierNo']) &&$this->post['suplierNo'] !=="" ? trim($this->post['suplierNo'])
  343. :"";
  344. if($suplierNo!==""){
  345. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  346. $condition[]=["wsm_code","in",$wsmcode];
  347. }
  348. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  349. if ($companyNo !== "") {
  350. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  351. $condition[]=["wsm_code","in",$wsmcode];
  352. }
  353. $start = isset($this->post['start']) &&$this->post['start'] !=="" ? $this->post['start']:"";
  354. $end = isset($this->post['end']) &&$this->post['end'] !=="" ? $this->post['end']:"";
  355. if($start!=""){
  356. $condition[]=["addtime",">=",$start];
  357. }
  358. if($end!=""){
  359. $condition[]=["addtime","<=",$end];
  360. }
  361. $count = Db::name("good_stock")->where($condition)->count();
  362. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  363. $list = Db::name("good_stock")->where($condition)->page($page,$size)->order("addtime desc")->select();
  364. $data=[];
  365. foreach ($list as $key=>$value){
  366. $temp=[];
  367. if($value['wsm_code']!=""){
  368. $wsm = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")->where
  369. (['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])->field("a.name as wsm_name,wsm_code,b.code,b.name")
  370. ->find();
  371. }
  372. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  373. $temp['wsm_code']=$value['wsm_code'];
  374. $temp['supplier_code']=isset($wsm['code'])?$wsm['code']:"";
  375. $temp['supplier_name']=isset($wsm['name'])?$wsm['name']:"";
  376. if($value['spuCode']!=""){
  377. $good=Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  378. }
  379. $temp['good_code']=isset($good['spuCode'])?$good['spuCode']:"";
  380. // $temp['type_code']=isset($good['type_code'])?$good['type_code']:"";
  381. $temp['good_name']=isset($good['good_name'])?$good['good_name']:"";
  382. $temp['unit']=isset($good['unit'])?$good['unit']:"";
  383. // $temp['attribute']=isset($good['attribute'])?$good['attribute']:"";
  384. $temp['sort_f']=isset($good['cat_id'])?$good['cat_id']:"";
  385. $temp['cat_info']=isset($good['cat_id'])?made($good['cat_id']):"";
  386. $temp['usable_stock'] = $value['usable_stock'];
  387. $temp['wait_in_stock'] = $value['wait_in_stock'];
  388. $temp['wait_out_stock'] = $value['wait_out_stock'];
  389. $temp['intra_stock'] = $value['intra_stock'];
  390. $temp['total_stock'] = $value['total_stock'];
  391. $temp['warn_stock'] = $value['warn_stock'];
  392. $temp['id'] = $value['id'];
  393. $temp['out_total'] =0;
  394. $temp['in_total'] = 0;
  395. $temp['addtime'] = $value['addtime'];
  396. $data[]=$temp;
  397. }
  398. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  399. }
  400. /**
  401. * @return \think\response\Json|void
  402. * @throws \think\db\exception\DataNotFoundException
  403. * @throws \think\db\exception\DbException
  404. * @throws \think\db\exception\ModelNotFoundException
  405. * @throws \think\exception\DbException
  406. */
  407. public function GetStockWsm(){
  408. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  409. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  410. $condition = [["is_del","=",0]];
  411. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  412. :"";
  413. if($wsm_code!==""){
  414. $condition[]=["wsm_code","=",$wsm_code];
  415. }
  416. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  417. :"";
  418. if($suplierNo!==""){
  419. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  420. $condition[]=["wsm_code","in",$wsmcode];
  421. }
  422. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  423. if ($companyNo !== "") {
  424. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  425. $condition[]=["wsm_code","in",$wsmcode];
  426. }
  427. $build= Db::name("good_stock")->where($condition)->group("wsm_code")->field("wsm_code")->buildSql();
  428. $count = Db::table($build." a")->count();
  429. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  430. $list = Db::name("good_stock")->where($condition)->page($page,$size)->group("wsm_code")
  431. ->field("wsm_code,sum(wait_in_stock) wait_in_stock,sum(wait_out_stock) wait_out_stock,sum(usable_stock) usable_stock,
  432. sum(intra_stock) intra_stock,sum(warn_stock) warn_stock,sum(total_stock) total_stock")->select();
  433. $data=[];
  434. foreach ($list as $key=>$value){
  435. $temp=[];
  436. if($value['wsm_code']!=""){
  437. $wsm = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")->where
  438. (['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])->field("a.name as wsm_name,wsm_code,b.code,b.name")
  439. ->find();
  440. $good = Db::name("good_stock")->alias("a")
  441. ->join("good c","c.spuCode=a.spuCode","left")->where(["a.wsm_code"=>$value['wsm_code'],"a.is_del"=>0,"c.is_del"=>0])->select();
  442. }
  443. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  444. $temp['wsm_code']=$value['wsm_code'];
  445. $temp['supplier_code']=isset($wsm['code'])?$wsm['code']:"";
  446. $temp['supplier_name']=isset($wsm['name'])?$wsm['name']:"";
  447. $temp['usable_stock'] = $value['usable_stock'];
  448. $temp['wait_in_stock'] = $value['wait_in_stock'];
  449. $temp['wait_out_stock'] = $value['wait_out_stock'];
  450. $temp['intra_stock'] = $value['intra_stock'];
  451. $temp['total_stock'] = $value['total_stock'];
  452. // $temp['warn_stock'] = $value['warn_stock'];
  453. $temp['child']=isset($good)&&!empty($good) ? $good:[];
  454. $data[]=$temp;
  455. }
  456. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  457. }
  458. public function GetStockGod(){
  459. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  460. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  461. $condition = [["b.is_del","=",0],["c.usable_stock",">",0]];
  462. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code'])
  463. :"";
  464. if($type_code!==""){
  465. $condition[]=["b.spuCode","like","%{$type_code}%"];
  466. }
  467. $count = Db::name("good")->alias("b")
  468. ->join("good_stock c","c.spuCode = b.spuCode","left")
  469. ->where($condition)->group("b.spuCode,b.good_name,b.good_unit,b.cat_id,b.craft_desc,b.addtime")
  470. ->count();
  471. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  472. $list = Db::name("good")->alias("b")
  473. ->join("good_stock c","c.spuCode = b.spuCode","left")
  474. ->where($condition)->field("b.spuCode,b.good_name,b.good_unit,b.cat_id,b.craft_desc,b.addtime,sum(c.wait_in_stock) wait_in_stock,
  475. 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")
  476. ->page($page,$size)->order("b.addtime desc")->group("b.spuCode,b.good_name,b.good_unit,b.cat_id,b.craft_desc,b.addtime")->select();
  477. // echo Db::name("good_type")->getLastSql();
  478. $data=[];
  479. foreach ($list as $key=>$value){
  480. $temp=[];
  481. if($value['spuCode']!=""){
  482. $child = Db::name("good_stock")->alias("a")->join("warehouse_info b","a.wsm_code=b.wsm_code","left")
  483. ->where(['a.spuCode'=>$value['spuCode'],"b.wsm_type"=>1,"a.is_del"=>0])->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")->select();
  484. }
  485. $temp['good_name'] = $value['good_name'];
  486. $temp['good_code'] = $value['spuCode'];
  487. $temp['type_code'] ='';
  488. $unit = Db::name("unit")->where(['id'=>$value['good_unit']])->find();
  489. $temp['unit'] = isset($unit['unit'])?$unit['unit']:"";
  490. $temp['sort_f']=isset($value['cat_id'])?made($value['cat_id']):[];
  491. $temp['sort_f']=implode('/',array_column($temp['sort_f'],'name'));//由于这个字段原样在页面显示,所以在这里特意拼接成字符串
  492. $temp['attribute']=$value['craft_desc'];
  493. $temp['addtime']=$value['addtime'];
  494. $temp['usable_stock'] = isset($value['usable_stock'])? $value['usable_stock']:"";
  495. $temp['wait_in_stock'] = isset($value['wait_in_stock'])? $value['wait_in_stock']:"";
  496. $temp['wait_out_stock'] = isset($value['wait_out_stock'])? $value['wait_out_stock']:"";
  497. $temp['intra_stock'] = isset($value['intra_stock'])? $value['intra_stock']:"";
  498. $temp['total_stock'] = isset($value['total_stock'])? $value['total_stock']:"";
  499. // $temp['warn_stock'] = isset($value['warn_stock'])? $value['warn_stock']:"";
  500. $temp['child']=isset($child)&&!empty($child) ? $child:[];
  501. $data[]=$temp;
  502. }
  503. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  504. }
  505. /**
  506. * @return \think\response\Json|void
  507. * @throws \think\db\exception\DataNotFoundException
  508. * @throws \think\db\exception\DbException
  509. * @throws \think\db\exception\ModelNotFoundException
  510. */
  511. public function Stat(){
  512. $condition =[["is_del","=",0]];
  513. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  514. if($wsm_code!=""){
  515. //$condition["wsm_code"] = $wsm_code;
  516. $condition[]=["wsm_code","=",$wsm_code];
  517. }
  518. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  519. if($suplierNo!==""){
  520. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  521. $condition[]=["wsm_code","in",$wsmcode];
  522. }
  523. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  524. if ($companyNo !== "") {
  525. // $where['khNo'] = $khNo;
  526. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  527. $condition[]=["wsm_code","in",$wsmcode];
  528. }
  529. // $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  530. // if($type_code!=""){
  531. // $condition[] = ["good_type_code","=",$type_code];
  532. // }
  533. $statlist = Db::name("good_stock")->where($condition)->field("sum(wait_in_stock) as wait_in_stock,sum(wait_out_stock) as wait_out_stock ,sum(usable_stock) as usable_stock,sum(intra_stock) as intra_stock,sum(total_stock) as total_stock,sum(warn_stock) as warn_stock")->find();
  534. return app_show(0,"获取成功",$statlist);
  535. }
  536. public function all(){
  537. $condtion=["a.is_del"=>0,"b.is_del"=>0];
  538. $wsmcode =isset($this->post['wsmcode']) &&$this->post['wsmcode'] !=="" ? trim($this->post['wsmcode']):"";
  539. if($wsmcode!=""){
  540. $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code");
  541. $condtion["b.type_code"] = $typecode;
  542. }
  543. $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  544. if($good_code!=""){
  545. $condtion['b.type_code'] = $good_code;
  546. }
  547. $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code'])
  548. :"";
  549. if($goodcode!=""){
  550. $condtion['a.good_code'] = $goodcode;
  551. }
  552. $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name'])
  553. :"";
  554. if($good_name!=""){
  555. $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'");
  556. }
  557. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  558. if($supplierNo!=""){
  559. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  560. if(empty($supplier)){
  561. return error_show(1004,"未找到供应商信息");
  562. }
  563. $condtion["a.gys_code"] = $supplierNo;
  564. }
  565. $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  566. ->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,
  567. 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")
  568. ->select();
  569. $data=[];
  570. foreach ($list as $key=>$value){
  571. $stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock");
  572. $value['usable_stock']=$stock;
  573. $supplier = Db::name("supplier")->where(["code"=>$value['gys_code']])->find();
  574. $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
  575. $data[]=$value;
  576. }
  577. return app_show(0,"获取成功",$data);
  578. }
  579. public function loglist(){
  580. $page = isset($this->post['page']) && $this->post['page']!==""? intval($this->post['page']) :"1";
  581. $size = isset($this->post['size']) && $this->post['size']!==""? intval($this->post['size']) :"10";
  582. $where=[];
  583. $wsm_code= isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  584. if($wsm_code!=""){
  585. $where[]=['b.wsm_code',"like","%$wsm_code%"];
  586. }
  587. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  588. if($supplierNo!=""){
  589. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  590. if(empty($supplier)){
  591. return error_show(1004,"未找到供应商信息");
  592. }
  593. $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"supplierNo"=>$supplierNo])->column("wsm_code");
  594. $where[]=['b.wsm_code',"in",$wsmcode];
  595. }
  596. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  597. if ($companyNo !== "") {
  598. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  599. $condition[]=["b.wsm_code","in",$wsmcode];
  600. }
  601. $count = Db::name("good_log")->alias('a')
  602. ->join("good_stock b","b.id=a.id","left")->where($where)->count();
  603. $total = ceil($count/$size);
  604. $page = $total>=$page ? $page :$total;
  605. $list = Db::name("good_log")->alias('a')
  606. ->join("good_stock b","b.id=a.stock_id","left")
  607. ->where($where)->page($page,$size)->order("a.addtime desc")
  608. ->field("a.action_name,a.type,a.stock_name,a.stock,a.action_type,b.spuCode,
  609. a.addtime,a.action_uid,b.wsm_code")->select();
  610. $data=[];
  611. foreach ($list as $value){
  612. $db = Db::name("depart_user")->where(['uid'=>$value['action_uid']])->column("itemid");
  613. $item = Db::name("company_item")->where(['id'=>$db])->column("id,name");
  614. $wsm = Db::name("warehouse_info")->alias("a")->Join("supplier b","a.supplierNo=b.code","left")->where
  615. (['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])->field("a.name as wsm_name,wsm_code,b.code,b.name")->find();
  616. $godd =Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  617. $value['good_name']=isset($godd['good_name'])? $godd['good_name']:"";
  618. $value['cat_id']=isset($godd['cat_id'])? $godd['cat_id']:"";
  619. $int = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  620. $value['wsm_name'] =$wsm['wsm_name'];
  621. $value['wsm_code'] =$wsm['wsm_code'];
  622. $value['code'] =$wsm['code'];
  623. $value['name'] =$wsm['name'];
  624. $value['action_type_cn'] =$this->acton[$value['action_type']];
  625. $value['item'] =$item;
  626. $value['can'] =$int;
  627. $data[]=$value;
  628. }
  629. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  630. }
  631. public function goodlist(){
  632. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  633. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  634. $where =[["a.is_del","=",0],["b.exam_status","=",6],["b.is_del","=",0],["c.is_del","=",0],["c.status","=",1]];
  635. $paltcode = isset($this->post["platform_code"])&& $this->post["platform_code"]!=""? trim($this->post["platform_code"]):"";
  636. if($paltcode!=""){
  637. $where[]=["platform_code","=",$paltcode];
  638. }
  639. $companyNo = isset($this->post["companyNo"])&& $this->post["companyNo"]!=""? trim($this->post["companyNo"])
  640. :"";
  641. if($companyNo!=""){
  642. $where[]=["companyNo","like","%$companyNo%"];
  643. }
  644. $cat_id = isset($this->post["cat_id"])&& $this->post["cat_id"]!==""? intval($this->post["cat_id"]):"";
  645. if($cat_id!==""){
  646. $where[]=["cat_id","=",$cat_id];
  647. }
  648. $buy_num = isset($this->post["buy_num"])&& $this->post["buy_num"]!==""? intval($this->post["buy_num"]):"";
  649. if($buy_num!==""){
  650. $where[]=["min_num","<=",$buy_num];
  651. }
  652. $price = isset($this->post["price"])&& $this->post["price"]!==""? floatval($this->post["price"]):"";
  653. if($buy_num!==""){
  654. $where[]=["sale_price","<=",$price];
  655. }
  656. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->leftJoin("good_ladder c","b.skuCode=c.skuCode")
  657. ->where($where)->count();
  658. $total = ceil($count / $size);
  659. $page = $page >= $total ? $total : $page;
  660. $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
  661. ($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")
  662. ->order("b.addtime desc")
  663. ->select();
  664. $data=[];
  665. foreach ($list as $value){
  666. $value['cat_info']= made($value['cat_id'],[]);
  667. $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
  668. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
  669. $value['platform_code_en'] = isset($platform['platform_code']) ? $platform['platform_code']:"";
  670. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  671. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  672. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  673. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  674. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  675. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  676. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  677. $value['company'] = isset($company['company'])?$company['company']:"";
  678. $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
  679. $value['status']=$value['exam_status'];
  680. $data[]=$value;
  681. }
  682. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  683. }
  684. }