Good.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\GoodLog;
  4. use think\App;
  5. use think\facade\Db;
  6. class Good extends \app\BaseController
  7. {
  8. public $post="";
  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. private $exclusive=["非专属","泰康"];
  28. public function __construct(App $app)
  29. {
  30. parent::__construct($app);
  31. $this->post = $this->request->post();
  32. // $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  33. // if($token==""){
  34. // return error_show(101,'token不能为空');
  35. // }0
  36. // $effetc = VerifyTokens($token);
  37. // if(!empty($effetc) && $effetc['code']!=0){
  38. // return error_show($effetc['code'],$effetc['message']);
  39. // }
  40. }
  41. public function list(){
  42. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  43. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  44. $where =[["a.is_del","=",0]];
  45. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? trim($this->post['cat_id']):"";
  46. if($cat_id!==""){
  47. $where[]=['a.cat_id',"=",$cat_id];
  48. }
  49. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  50. if($good_name!==""){
  51. $where[]=['a.good_name',"like","%$good_name%"];
  52. }
  53. $spucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode'])
  54. :"";
  55. if($spucode!==""){
  56. $where [] = ['a.spuCode',"like","%$spucode%"];
  57. }
  58. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  59. if($start!==""){
  60. $where[]=['a.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  61. }
  62. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  63. if($end!==""){
  64. $where[]=['a.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  65. }
  66. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !=="" ? intval($this->post['is_stock'])
  67. :"";
  68. if($is_stock!==""){
  69. $where[]=['is_stock',"=",$is_stock];
  70. }
  71. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? intval($this->post['good_type'])
  72. :"";
  73. if($good_type!==""){
  74. $where[]=['good_type',"=",$good_type];
  75. }
  76. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  77. :"";
  78. if($supplierNo!==""){
  79. $where[]=['a.supplierNo',"=",$supplierNo];
  80. }
  81. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :"";
  82. if($companyNo!==""){
  83. $where[]=['a.companyNo',"like","%$companyNo%"];
  84. }
  85. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  86. if($creater!==""){
  87. $where[]=['a.creater',"like","%$creater%"];
  88. }
  89. $createrid = isset($this->post['createrid']) && $this->post['createrid'] !=="" ? intval($this->post['createrid']):"";
  90. if($createrid!==""){
  91. $where[]=['a.createrid',"=",$createrid];
  92. }
  93. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
  94. :"";
  95. if($status!==""){
  96. $where[]=['a.status',"=",$status];
  97. }
  98. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code'])
  99. :"";
  100. if($platform_code!==""){
  101. //$platform = Db::name("good_platform")->where(["platform_code"=>$platform_code,"is_del"=>0])->column
  102. //("spuCode");
  103. $where[]=["platform_code","=",$platform_code];
  104. }
  105. $plat_code = isset($this->post['plat_code']) && $this->post['plat_code'] !=="" ? trim($this->post['plat_code'])
  106. :"";
  107. if($plat_code!==""){
  108. $where[]=["b.plat_code","like","%$plat_code%"];
  109. }
  110. $exam_status = isset($this->post['exam_status']) && $this->post['exam_status'] !=="" ? intval($this->post['exam_status'])
  111. :"";
  112. if($exam_status!==""){
  113. $where[]=['b.exam_status',"=",$exam_status];
  114. }
  115. $brand_id = isset($this->post['brand_id']) && $this->post['brand_id'] !=="" ? intval($this->post['brand_id'])
  116. :"";
  117. if($brand_id!==""){
  118. $where[]=['a.brand_id',"=",$brand_id];
  119. }
  120. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where($where)
  121. ->count();
  122. $total = ceil($count / $size);
  123. $page = $page >= $total ? $total : $page;
  124. $list = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where($where)->page
  125. ($page,$size)->field("b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.*,b.addtime,b.updatetime,b.exam_status")
  126. ->order("b.addtime desc")
  127. ->select();
  128. $data=[];
  129. foreach ($list as $value){
  130. $value['cat_info']= made($value['cat_id'],[]);
  131. $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
  132. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
  133. $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en']:"";
  134. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  135. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  136. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  137. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  138. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  139. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  140. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  141. $value['company'] = isset($company['company'])?$company['company']:"";
  142. $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
  143. $value['status']=$value['exam_status'];
  144. $data[]=$value;
  145. }
  146. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  147. }
  148. public function info(){
  149. $skucode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
  150. if($skucode==""){
  151. return error_show(1005,"参数skuCode不能为空");
  152. }
  153. $good_platform = Db::name("good_platform")->where(['skuCode'=>$skucode,"is_del"=>0])->find();
  154. if($good_platform==false){
  155. return error_show(1004,"未找到商品数据");
  156. }
  157. $data = Db::name("good")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->find();
  158. if($data==false){
  159. return error_show(1004,"未找到商品数据");
  160. }
  161. $plat =Db::name("platform")->where(["id"=>$good_platform['platform_code']])->find();
  162. $data['skuCode']=$good_platform['skuCode'];
  163. $data['platform_code']=$good_platform['id'];
  164. $data['platform_code_en']=isset($plat['platform_code'])?$plat['platform_code']:"";
  165. $data['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  166. $data['online_reason']=$good_platform['online_reason'];
  167. $data['online_time']=$good_platform['online_time'];
  168. $data['online_remark']=$good_platform['online_remark'];
  169. $data['exam_status']=$good_platform['exam_status'];
  170. $data['is_online']=$good_platform['is_online'];
  171. $data['plat_code']=$good_platform['plat_code'];
  172. $data['exclusive']=$this->exclusive[$data['is_exclusive' ]];
  173. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  174. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  175. $data['cat_info'] = made($data['cat_id'],[]);
  176. $spec = Db::name("good_spec")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
  177. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  178. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  179. // $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  180. // $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  181. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  182. $data['company'] = isset($company['company'])?$company['company']:"";
  183. if($data['brand_id']!=0){
  184. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  185. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  186. }else{
  187. $data["brand_name"]="";
  188. $data["brand_id"]="";
  189. }
  190. $data['origin_place_cn']="";
  191. $data['delivery_place_cn']="";
  192. if($data['delivery_place']!==""){
  193. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  194. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['delivery_place']);
  195. $data['delivery_place_cn']=GetAddr(json_encode($place));
  196. }
  197. if($data['origin_place']!==""){
  198. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  199. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['origin_place']);
  200. $data['origin_place_cn']=GetAddr(json_encode($place));
  201. }
  202. $data["good_info_img"]=$data['good_info_img']!=""? json_decode($data['good_info_img'],true):[];
  203. $speclist=[];
  204. if(!empty($spec)){
  205. foreach ($spec as $value){
  206. $temp=[];
  207. $temp['id']=$value['id'];
  208. $temp['spuCode']=$value['spuCode'];
  209. $temp['spec_id']=$value['spec_id'];
  210. $temp['spec_value_id']=$value['spec_value_id'];
  211. $temp['is_del']=$value['is_del'];
  212. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  213. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  214. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  215. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  216. $speclist[]=$temp;
  217. }
  218. }
  219. $data["speclist"]=empty($speclist)?[]:$speclist;
  220. // $nake=[];
  221. $ladder = Db::name("good_ladder")->where(['skuCode'=>$skucode,"is_del"=>0])->select()->toArray();
  222. $data["ladderlist"]=!empty($ladder)?$ladder:[];
  223. $nakelist = Db::name("good_nake")->where(['spuCode'=>$good_platform['spuCode'],"is_del"=>0])->select()
  224. ->toArray();
  225. $data["nakelist"]=!empty($nakelist)?$nakelist:[];
  226. return app_show(0,"获取成功",$data);
  227. }
  228. public function SetWarn(){
  229. $condition=["is_del"=>0];
  230. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  231. if($wsm_code!=""){
  232. $condition["wsm_code"] = $wsm_code;
  233. }else{
  234. return error_show(1004,"参数wsm_code 不能为空");
  235. }
  236. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  237. if($type_code!=""){
  238. $condition["good_type_code"] = $type_code;
  239. }else{
  240. return error_show(1004,"参数type_code 不能为空");
  241. }
  242. $good= Db::name("good_stock")->where($condition)->find();
  243. if(empty($good)){
  244. return error_show(1005,"未找到数据");
  245. }
  246. $warn_stock = isset($this->post['warn_stock']) &&$this->post['warn_stock'] !=="" ? intval($this->post['warn_stock']):"";
  247. if($warn_stock===""){
  248. return error_show(1005,"参数warn_stock 不能为空");
  249. }
  250. $good['warn_stock'] = $warn_stock;
  251. $good['updatetime'] = date("Y-m-d H:i:s");
  252. $up= Db::name("good_stock")->save($good);
  253. if($up){
  254. $data=["stock_id"=>$good['id'],"type"=>1,'stock'=>$warn_stock,"stock_name"=>"warn_stock"];
  255. GoodLog::LogAdd($this->post['token'],$data,'setwarn');
  256. return app_show(0,"预警库存更新成功");
  257. }else{
  258. return error_show(1005,"预警库存更新失败");
  259. }
  260. }
  261. public function SetStatus(){
  262. $id = isset($this->post['id']) &&$this->post['id'] !=="" ? intval($this->post['id']):"";
  263. if($id===""){
  264. return error_show(1005,"参数id 不能为空");
  265. }
  266. $good= Db::name("good_type")->where(["id"=>$id,"is_del"=>0])->find();
  267. if(empty($good)){
  268. return error_show(1005,"未找到数据");
  269. }
  270. $good['status'] = $good['status']==1?0 :1;
  271. $good['updatetime'] = date("Y-m-d H:i:s");
  272. $msg = $good['status']==1?"下架" :"上架";
  273. $up= Db::name("good_type")->save($good);
  274. return $up ? app_show(0,"商品{$msg}成功"): error_show(1005,"商品{$msg}失败");
  275. }
  276. public function GetStock(){
  277. $condition = [["a.is_del","=",0]];
  278. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  279. if($type_code!==""){
  280. $condition[]=["a.good_type_code","=",$type_code];
  281. }
  282. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  283. :"";
  284. if($wsm_code!==""){
  285. //$condition["a.wsm_code"]=$wsm_code;
  286. $condition[]=["a.wsm_code","=",$type_code];
  287. }
  288. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  289. :"";
  290. if($suplierNo!==""){
  291. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"wsm_type"=>1,"is_del"=>0])->column("wsm_code");
  292. $condition[]=["a.wsm_code","in",$wsmcode];
  293. }
  294. $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")
  295. ->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();
  296. if(empty($list)){
  297. return error_show(1004,"未找到数据");
  298. }
  299. return app_show(0,"获取成功",$list);
  300. }
  301. /**
  302. * @return \think\response\Json|void
  303. * @throws \think\db\exception\DataNotFoundException
  304. * @throws \think\db\exception\DbException
  305. * @throws \think\db\exception\ModelNotFoundException
  306. */
  307. public function GetStockBet(){
  308. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  309. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  310. $condition = [["is_del","=",0]];
  311. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  312. if($type_code!==""){
  313. $condition[]=["good_type_code","like","%{$type_code}%"];
  314. }
  315. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  316. :"";
  317. if($wsm_code!==""){
  318. $condition[]=["wsm_code","=",$wsm_code];
  319. }
  320. $suplierNo = isset($this->post['suplierNo']) &&$this->post['suplierNo'] !=="" ? trim($this->post['suplierNo'])
  321. :"";
  322. if($suplierNo!==""){
  323. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"wsm_type"=>1,"is_del"=>0])->column("wsm_code");
  324. $condition[]=["wsm_code","in",$wsmcode];
  325. }
  326. $start = isset($this->post['start']) &&$this->post['start'] !=="" ? $this->post['start']:"";
  327. $end = isset($this->post['end']) &&$this->post['end'] !=="" ? $this->post['end']:"";
  328. if($start!=""){
  329. $condition[]=["addtime",">=",$start];
  330. }
  331. if($end!=""){
  332. $condition[]=["addtime","<=",$end];
  333. }
  334. $count = Db::name("good_stock")->where($condition)->count();
  335. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  336. $list = Db::name("good_stock")->where($condition)->page($page,$size)->order("addtime desc")->select();
  337. $data=[];
  338. foreach ($list as $key=>$value){
  339. $temp=[];
  340. if($value['wsm_code']!=""){
  341. $wsm = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")->where
  342. (['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])->field("a.name as wsm_name,wsm_code,b.code,b.name")
  343. ->find();
  344. }
  345. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  346. $temp['wsm_code']=$value['wsm_code'];
  347. $temp['supplier_code']=isset($wsm['code'])?$wsm['code']:"";
  348. $temp['supplier_name']=isset($wsm['name'])?$wsm['name']:"";
  349. if($value['good_type_code']!=""){
  350. $good=Db::name("good_type")->alias("a")->join("good b","a.good_code=b.good_code","left")->where(["a.type_code"=>$value['good_type_code'],"a.is_del"=>0,"b.is_del"=>0])
  351. ->field("a.good_code,a.type_code,b.good_name,b.unit,a.attribute,b.sort_f")->find();
  352. }
  353. $temp['good_code']=isset($good['good_code'])?$good['good_code']:"";
  354. $temp['type_code']=isset($good['type_code'])?$good['type_code']:"";
  355. $temp['good_name']=isset($good['good_name'])?$good['good_name']:"";
  356. $temp['unit']=isset($good['unit'])?$good['unit']:"";
  357. $temp['attribute']=isset($good['attribute'])?$good['attribute']:"";
  358. $temp['sort_f']=isset($good['sort_f'])?$good['sort_f']:"";
  359. $temp['usable_stock'] = $value['usable_stock'];
  360. $temp['wait_in_stock'] = $value['wait_in_stock'];
  361. $temp['wait_out_stock'] = $value['wait_out_stock'];
  362. $temp['intra_stock'] = $value['intra_stock'];
  363. $temp['total_stock'] = $value['total_stock'];
  364. $temp['warn_stock'] = $value['warn_stock'];
  365. $temp['id'] = $value['id'];
  366. $temp['out_total'] =0;
  367. $temp['in_total'] = 0;
  368. $temp['addtime'] = $value['addtime'];
  369. $data[]=$temp;
  370. }
  371. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  372. }
  373. /**
  374. * @return \think\response\Json|void
  375. * @throws \think\db\exception\DataNotFoundException
  376. * @throws \think\db\exception\DbException
  377. * @throws \think\db\exception\ModelNotFoundException
  378. * @throws \think\exception\DbException
  379. */
  380. public function GetStockWsm(){
  381. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  382. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  383. $condition = [["is_del","=",0]];
  384. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  385. :"";
  386. if($wsm_code!==""){
  387. $condition[]=["wsm_code","=",$wsm_code];
  388. }
  389. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  390. :"";
  391. if($suplierNo!==""){
  392. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"wsm_type"=>1,"is_del"=>0])->column("wsm_code");
  393. $condition[]=["wsm_code","in",$wsmcode];
  394. }
  395. $build= Db::name("good_stock")->where($condition)->group("wsm_code")->field("wsm_code")->buildSql();
  396. $count = Db::table($build." a")->count();
  397. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  398. $list = Db::name("good_stock")->where($condition)->page($page,$size)->group("wsm_code")
  399. ->field("wsm_code,sum(wait_in_stock) wait_in_stock,sum(wait_out_stock) wait_out_stock,sum(usable_stock) usable_stock,
  400. sum(intra_stock) intra_stock,sum(warn_stock) warn_stock,sum(total_stock) total_stock")->select();
  401. $data=[];
  402. foreach ($list as $key=>$value){
  403. $temp=[];
  404. if($value['wsm_code']!=""){
  405. $wsm = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")->where
  406. (['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])->field("a.name as wsm_name,wsm_code,b.code,b.name")
  407. ->find();
  408. $good = Db::name("good_stock")->alias("a")->join("good_type b","a.good_type_code=b.type_code","left")
  409. ->join("good c","c.good_code=b.good_code","left")->where(["a.wsm_code"=>$value['wsm_code'],"a.is_del"=>0,"b.is_del"=>0,"c.is_del"=>0])
  410. ->field("c.good_code,a.good_type_code,c.good_name,b.attribute,c.sort_f,c.unit,a.usable_stock,a.wait_in_stock,a.wait_out_stock,a.intra_stock,a.total_stock,a.warn_stock")
  411. ->select();
  412. }
  413. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  414. $temp['wsm_code']=$value['wsm_code'];
  415. $temp['supplier_code']=isset($wsm['code'])?$wsm['code']:"";
  416. $temp['supplier_name']=isset($wsm['name'])?$wsm['name']:"";
  417. $temp['usable_stock'] = $value['usable_stock'];
  418. $temp['wait_in_stock'] = $value['wait_in_stock'];
  419. $temp['wait_out_stock'] = $value['wait_out_stock'];
  420. $temp['intra_stock'] = $value['intra_stock'];
  421. $temp['total_stock'] = $value['total_stock'];
  422. // $temp['warn_stock'] = $value['warn_stock'];
  423. $temp['child']=isset($good)&&!empty($good) ? $good:[];
  424. $data[]=$temp;
  425. }
  426. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  427. }
  428. public function GetStockGod(){
  429. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  430. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  431. $condition = [["a.is_del","=",0],["b.is_del","=",0],["c.usable_stock",">",0]];
  432. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code'])
  433. :"";
  434. if($type_code!==""){
  435. $condition[]=["b.type_code","like","%{$type_code}%"];
  436. }
  437. $count = Db::name("good_type")->alias("b")
  438. ->join("good a","a.good_code = b.good_code","left")
  439. ->join("good_stock c","c.good_type_code = b.type_code","left")
  440. ->where($condition)->group("a.good_code,a.good_name,a.unit,a.sort_f,b.type_code,b.attribute,a.addtime")->count();
  441. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  442. $list = Db::name("good_type")->alias("b")
  443. ->join("good a","a.good_code = b.good_code","left")
  444. ->join("good_stock c","c.good_type_code = b.type_code","left")
  445. ->where($condition)->field("a.good_code,a.good_name,a.unit,a.sort_f,b.type_code,b.attribute,a.addtime,sum(c.wait_in_stock) wait_in_stock,
  446. 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")
  447. ->page($page,$size)->order("a.addtime desc")->group("a.good_code,a.good_name,a.unit,a.sort_f,b.type_code,b.attribute,a.addtime")->select();
  448. // echo Db::name("good_type")->getLastSql();
  449. $data=[];
  450. foreach ($list as $key=>$value){
  451. $temp=[];
  452. if($value['type_code']!=""){
  453. $child = Db::name("good_stock")->alias("a")->join("warehouse_info b","a.wsm_code=b.wsm_code","left")
  454. ->where(['a.good_type_code'=>$value['type_code'],"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();
  455. }
  456. $temp['good_name'] = $value['good_name'];
  457. $temp['good_code'] = $value['good_code'];
  458. $temp['type_code'] = $value['type_code'];
  459. $temp['unit'] = $value['unit'];
  460. $temp['sort_f']=$value['sort_f'];
  461. $temp['attribute']=$value['attribute'];
  462. $temp['addtime']=$value['addtime'];
  463. $temp['usable_stock'] = isset($value['usable_stock'])? $value['usable_stock']:"";
  464. $temp['wait_in_stock'] = isset($value['wait_in_stock'])? $value['wait_in_stock']:"";
  465. $temp['wait_out_stock'] = isset($value['wait_out_stock'])? $value['wait_out_stock']:"";
  466. $temp['intra_stock'] = isset($value['intra_stock'])? $value['intra_stock']:"";
  467. $temp['total_stock'] = isset($value['total_stock'])? $value['total_stock']:"";
  468. // $temp['warn_stock'] = isset($value['warn_stock'])? $value['warn_stock']:"";
  469. $temp['child']=isset($child)&&!empty($child) ? $child:[];
  470. $data[]=$temp;
  471. }
  472. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  473. }
  474. /**
  475. * @return \think\response\Json|void
  476. * @throws \think\db\exception\DataNotFoundException
  477. * @throws \think\db\exception\DbException
  478. * @throws \think\db\exception\ModelNotFoundException
  479. */
  480. public function Stat(){
  481. $condition =[["is_del","=",0]];
  482. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  483. if($wsm_code!=""){
  484. //$condition["wsm_code"] = $wsm_code;
  485. $condition[]=["wsm_code","=",$wsm_code];
  486. }
  487. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  488. if($suplierNo!==""){
  489. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"wsm_type"=>1,"is_del"=>0])->column("wsm_code");
  490. $condition[]=["wsm_code","in",$wsmcode];
  491. }
  492. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  493. if($type_code!=""){
  494. $condition[] = ["good_type_code","=",$type_code];
  495. }
  496. $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();
  497. return app_show(0,"获取成功",$statlist);
  498. }
  499. public function all(){
  500. $condtion=["a.is_del"=>0,"b.is_del"=>0];
  501. $wsmcode =isset($this->post['wsmcode']) &&$this->post['wsmcode'] !=="" ? trim($this->post['wsmcode']):"";
  502. if($wsmcode!=""){
  503. $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code");
  504. $condtion["b.type_code"] = $typecode;
  505. }
  506. $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  507. if($good_code!=""){
  508. $condtion['b.type_code'] = $good_code;
  509. }
  510. $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code'])
  511. :"";
  512. if($goodcode!=""){
  513. $condtion['a.good_code'] = $goodcode;
  514. }
  515. $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name'])
  516. :"";
  517. if($good_name!=""){
  518. $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'");
  519. }
  520. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  521. if($supplierNo!=""){
  522. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  523. if(empty($supplier)){
  524. return error_show(1004,"未找到供应商信息");
  525. }
  526. $condtion["a.gys_code"] = $supplierNo;
  527. }
  528. $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  529. ->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,
  530. 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")
  531. ->select();
  532. $data=[];
  533. foreach ($list as $key=>$value){
  534. $stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock");
  535. $value['usable_stock']=$stock;
  536. $supplier = Db::name("supplier")->where(["code"=>$value['gys_code']])->find();
  537. $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
  538. $data[]=$value;
  539. }
  540. return app_show(0,"获取成功",$data);
  541. }
  542. public function loglist(){
  543. $page = isset($this->post['page']) && $this->post['page']!==""? intval($this->post['page']) :"1";
  544. $size = isset($this->post['size']) && $this->post['size']!==""? intval($this->post['size']) :"10";
  545. $where=[];
  546. $wsm_code= isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  547. if($wsm_code!=""){
  548. $where[]=['b.wsm_code',"like","%$wsm_code%"];
  549. }
  550. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  551. if($supplierNo!=""){
  552. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  553. if(empty($supplier)){
  554. return error_show(1004,"未找到供应商信息");
  555. }
  556. $wsmcode = Db::name("warehouse_info")->where([
  557. "is_del"=>0,"wsm_type"=>1,"supplierNo"=>$supplierNo])->column("wsm_code");
  558. $where[]=['b.wsm_code',"in",$wsmcode];
  559. }
  560. $count = Db::name("good_log")->alias('a')
  561. ->join("good_stock b","b.id=a.id","left")->where($where)
  562. ->join("good_type c","c.type_code=b.good_type_code","left")
  563. ->join("good v","v.good_code=c.good_code","left")->count();
  564. $total = ceil($count/$size);
  565. $page = $total>=$page ? $page :$total;
  566. $list = Db::name("good_log")->alias('a')
  567. ->join("good_stock b","b.id=a.stock_id","left")
  568. ->join("good_type c","c.type_code=b.good_type_code","left")
  569. ->join("good v","v.good_code=c.good_code","left")
  570. ->where($where)->page($page,$size)->order("a.addtime desc")
  571. ->field("a.action_name,a.type,a.stock_name,a.stock,a.action_type,
  572. a.addtime,a.action_uid,b.wsm_code,v.good_code,v.good_name,v.cat_id")->select();
  573. $data=[];
  574. foreach ($list as $value){
  575. $db = Db::name("depart_user")->where(['uid'=>$value['action_uid']])->column("itemid");
  576. $item = Db::name("company_item")->where(['id'=>$db])->column("id,name");
  577. $wsm = Db::name("warehouse_info")->alias("a")->Join("supplier b","a.supplierNo=b.code","left")->where
  578. (['a.wsm_code'=>$value['wsm_code'],"a.wsm_type"=>1,"a.is_del"=>0])->field("a.name as wsm_name,wsm_code,b.code,b.name")->find();
  579. $int = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  580. $value['wsm_name'] =$wsm['wsm_name'];
  581. $value['wsm_code'] =$wsm['wsm_code'];
  582. $value['code'] =$wsm['code'];
  583. $value['name'] =$wsm['name'];
  584. $value['action_type_cn'] =$this->acton[$value['action_type']];
  585. $value['item'] =$item;
  586. $value['can'] =$int;
  587. $data[]=$value;
  588. }
  589. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  590. }
  591. }