Good.php 38 KB

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