Good.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  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. {
  460. //1.接收参数
  461. $data = $this->request->only(['page' => 1, 'size' => 10, 'type_code' => ''], 'post', 'trim');
  462. //2.组织查询条件
  463. $condition = [["b.is_del", "=", 0], ["c.usable_stock", ">", 0]];
  464. if ($data['type_code']) $condition[] = ["b.spuCode", "like", "%{$data['type_code']}%"];
  465. //3.总数
  466. $count = Db::name("good")
  467. ->alias("b")
  468. ->join("good_stock c", "c.spuCode = b.spuCode", "left")
  469. ->where($condition)
  470. ->group("b.spuCode,b.good_name,b.good_unit,b.cat_id,b.craft_desc,b.addtime")
  471. ->count('b.id');
  472. //4.查询列表
  473. $last_page = ceil($count / $data['size']);
  474. $page = $data['page'] >= $last_page ? $last_page : $data['page'];
  475. $list = Db::name("good")
  476. ->alias("b")
  477. ->join("good_stock c", "c.spuCode = b.spuCode", "left")
  478. ->where($condition)
  479. ->field("b.spuCode,b.good_name,b.good_unit,b.cat_id,b.brand_id,b.craft_desc,b.addtime,sum(c.wait_in_stock) wait_in_stock,sum(c.wait_out_stock) wait_out_stock,sum(c.usable_stock) usable_stock,sum(c.intra_stock) intra_stock,sum(c.warn_stock) warn_stock,sum(c.total_stock) total_stock")
  480. ->page($page, $data['size'])
  481. ->order("b.addtime desc")
  482. ->group("b.spuCode,b.good_name,b.good_unit,b.cat_id,b.craft_desc,b.brand_id,b.addtime")
  483. ->select()
  484. ->toArray();
  485. //5.组织其他数据
  486. if ($list) {
  487. //仓库
  488. $child = Db::name("good_stock")
  489. ->alias("a")
  490. ->join("warehouse_info b", "a.wsm_code=b.wsm_code", "left")
  491. ->join("business bus", "bus.companyNo=b.companyNo", "left")
  492. ->join("supplier s", "s.code=b.supplierNo", "left")
  493. ->where(["b.wsm_type" => 1, "a.is_del" => 0])
  494. ->whereIn('a.spuCode', array_column($list, 'spuCode'))
  495. ->column("a.wsm_code,b.name wsm_name,a.wait_in_stock,a.wait_out_stock,a.usable_stock,a.intra_stock,a.total_stock,a.warn_stock,b.supplierNo,s.name supplierName,b.companyNo,bus.company", 'a.spuCode');
  496. //商品单位和品牌
  497. $good_unit_s = Db::name("unit")->whereIn('id', array_column($list, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
  498. $brands = Db::name("brand")->whereIn('id', array_column($list, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
  499. $data = [];
  500. foreach ($list as $key => $value) {
  501. $temp = [];
  502. $temp['good_name'] = $value['good_name'];
  503. $temp['good_code'] = $value['spuCode'];
  504. $temp['type_code'] = '';
  505. $temp['unit'] = $good_unit_s[$value['good_unit']] ?? '';
  506. $temp['sort_f'] = isset($value['cat_id']) ? made($value['cat_id']) : [];
  507. $temp['sort_f'] = implode('/', array_column($temp['sort_f'], 'name'));//由于这个字段原样在页面显示,所以在这里特意拼接成字符串
  508. $temp['attribute'] = $value['craft_desc'];
  509. $temp['addtime'] = $value['addtime'];
  510. $temp['usable_stock'] = isset($value['usable_stock']) ? $value['usable_stock'] : "";
  511. $temp['wait_in_stock'] = isset($value['wait_in_stock']) ? $value['wait_in_stock'] : "";
  512. $temp['wait_out_stock'] = isset($value['wait_out_stock']) ? $value['wait_out_stock'] : "";
  513. $temp['intra_stock'] = isset($value['intra_stock']) ? $value['intra_stock'] : "";
  514. $temp['total_stock'] = isset($value['total_stock']) ? $value['total_stock'] : "";
  515. // $temp['warn_stock'] = isset($value['warn_stock'])? $value['warn_stock']:"";
  516. $temp['child'] = $child[$value['spuCode']] ?? [];
  517. $temp['brand_name'] = $brands[$value['brand_id']] ?? '';
  518. //规格信息
  519. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  520. $speclist = [];
  521. if (!empty($spec)) {
  522. foreach ($spec as $val) {
  523. $tmp = [];
  524. $tmp['spec_id'] = $val['spec_id'];
  525. $tmp['spec_value_id'] = $val['spec_value_id'];
  526. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  527. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  528. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  529. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  530. $speclist[] = $tmp;
  531. }
  532. }
  533. $temp['specinfo'] = $speclist;
  534. $data[] = $temp;
  535. }
  536. }
  537. return app_show(0, "获取成功", ["list" => $data, "count" => $count]);
  538. }
  539. /**
  540. * @return \think\response\Json|void
  541. * @throws \think\db\exception\DataNotFoundException
  542. * @throws \think\db\exception\DbException
  543. * @throws \think\db\exception\ModelNotFoundException
  544. */
  545. public function Stat(){
  546. $condition =[["is_del","=",0]];
  547. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  548. if($wsm_code!=""){
  549. //$condition["wsm_code"] = $wsm_code;
  550. $condition[]=["wsm_code","=",$wsm_code];
  551. }
  552. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  553. if($suplierNo!==""){
  554. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  555. $condition[]=["wsm_code","in",$wsmcode];
  556. }
  557. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  558. if ($companyNo !== "") {
  559. // $where['khNo'] = $khNo;
  560. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  561. $condition[]=["wsm_code","in",$wsmcode];
  562. }
  563. // $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  564. // if($type_code!=""){
  565. // $condition[] = ["good_type_code","=",$type_code];
  566. // }
  567. $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();
  568. return app_show(0,"获取成功",$statlist);
  569. }
  570. public function all(){
  571. $condtion=["a.is_del"=>0,"b.is_del"=>0];
  572. $wsmcode =isset($this->post['wsmcode']) &&$this->post['wsmcode'] !=="" ? trim($this->post['wsmcode']):"";
  573. if($wsmcode!=""){
  574. $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code");
  575. $condtion["b.type_code"] = $typecode;
  576. }
  577. $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  578. if($good_code!=""){
  579. $condtion['b.type_code'] = $good_code;
  580. }
  581. $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code'])
  582. :"";
  583. if($goodcode!=""){
  584. $condtion['a.good_code'] = $goodcode;
  585. }
  586. $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name'])
  587. :"";
  588. if($good_name!=""){
  589. $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'");
  590. }
  591. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  592. if($supplierNo!=""){
  593. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  594. if(empty($supplier)){
  595. return error_show(1004,"未找到供应商信息");
  596. }
  597. $condtion["a.gys_code"] = $supplierNo;
  598. }
  599. $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  600. ->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,
  601. 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")
  602. ->select();
  603. $data=[];
  604. foreach ($list as $key=>$value){
  605. $stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock");
  606. $value['usable_stock']=$stock;
  607. $supplier = Db::name("supplier")->where(["code"=>$value['gys_code']])->find();
  608. $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
  609. $data[]=$value;
  610. }
  611. return app_show(0,"获取成功",$data);
  612. }
  613. public function loglist(){
  614. $page = isset($this->post['page']) && $this->post['page']!==""? intval($this->post['page']) :"1";
  615. $size = isset($this->post['size']) && $this->post['size']!==""? intval($this->post['size']) :"10";
  616. $where=[];
  617. $wsm_code= isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  618. if($wsm_code!=""){
  619. $where[]=['b.wsm_code',"like","%$wsm_code%"];
  620. }
  621. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  622. if($supplierNo!=""){
  623. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  624. if(empty($supplier)){
  625. return error_show(1004,"未找到供应商信息");
  626. }
  627. $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"supplierNo"=>$supplierNo])->column("wsm_code");
  628. $where[]=['b.wsm_code',"in",$wsmcode];
  629. }
  630. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  631. if ($companyNo !== "") {
  632. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  633. $condition[]=["b.wsm_code","in",$wsmcode];
  634. }
  635. $count = Db::name("good_log")->alias('a')
  636. ->join("good_stock b","b.id=a.id","left")->where($where)->count();
  637. $total = ceil($count/$size);
  638. $page = $total>=$page ? $page :$total;
  639. $list = Db::name("good_log")->alias('a')
  640. ->join("good_stock b","b.id=a.stock_id","left")
  641. ->where($where)->page($page,$size)->order("a.addtime desc")
  642. ->field("a.action_name,a.type,a.stock_name,a.stock,a.action_type,b.spuCode,a.addtime,a.action_uid,b.wsm_code")
  643. ->select()
  644. ->toArray();
  645. $data=[];
  646. foreach ($list as $value){
  647. $db = Db::name("depart_user")->where(['uid'=>$value['action_uid']])->column("itemid");
  648. $item = Db::name("company_item")->where(['id'=>$db])->column("id,name");
  649. $wsm = Db::name("warehouse_info")
  650. ->alias("a")
  651. ->Join("supplier b","a.supplierNo=b.code","left")
  652. ->Join("business bus","bus.companyNo=a.companyNo","left")
  653. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  654. ->field("a.name as wsm_name,wsm_code,b.code,b.name,bus.company,bus.companyNo")
  655. ->find();
  656. $godd =Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  657. $value['good_name']=isset($godd['good_name'])? $godd['good_name']:"";
  658. $value['cat_id']=isset($godd['cat_id'])? $godd['cat_id']:"";
  659. $int = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  660. $value['wsm_name'] =$wsm['wsm_name'];
  661. $value['wsm_code'] =$wsm['wsm_code'];
  662. $value['code'] =$wsm['code'];
  663. $value['name'] =$wsm['name'];
  664. $value['action_type_cn'] =$this->acton[$value['action_type']];
  665. $value['item'] =$item;
  666. $value['can'] =$int;
  667. $value['company'] =$wsm['company']??'';
  668. $value['companyNo'] =$wsm['companyNo']??'';
  669. $data[]=$value;
  670. }
  671. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  672. }
  673. public function goodlist(){
  674. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  675. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  676. $where =[["a.is_del","=",0],["b.exam_status","=",6],["b.is_del","=",0],["c.is_del","=",0],["c.status","=",1]];
  677. $paltcode = isset($this->post["platform_code"])&& $this->post["platform_code"]!=""? trim($this->post["platform_code"]):"";
  678. if($paltcode!=""){
  679. $where[]=["platform_code","=",$paltcode];
  680. }
  681. $companyNo = isset($this->post["companyNo"])&& $this->post["companyNo"]!=""? trim($this->post["companyNo"])
  682. :"";
  683. if($companyNo!=""){
  684. $where[]=["companyNo","like","%$companyNo%"];
  685. }
  686. $cat_id = isset($this->post["cat_id"])&& $this->post["cat_id"]!==""? intval($this->post["cat_id"]):"";
  687. if($cat_id!==""){
  688. $where[]=["cat_id","=",$cat_id];
  689. }
  690. $buy_num = isset($this->post["buy_num"])&& $this->post["buy_num"]!==""? intval($this->post["buy_num"]):"";
  691. if($buy_num!==""){
  692. $where[]=["min_num","<=",$buy_num];
  693. }
  694. $price = isset($this->post["price"])&& $this->post["price"]!==""? floatval($this->post["price"]):"";
  695. if($buy_num!==""){
  696. $where[]=["sale_price","<=",$price];
  697. }
  698. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->leftJoin("good_ladder c","b.skuCode=c.skuCode")
  699. ->where($where)->count();
  700. $total = ceil($count / $size);
  701. $page = $page >= $total ? $total : $page;
  702. $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
  703. ($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")
  704. ->order("b.addtime desc")
  705. ->select();
  706. $data=[];
  707. foreach ($list as $value){
  708. $value['cat_info']= made($value['cat_id'],[]);
  709. $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
  710. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
  711. $value['platform_code_en'] = isset($platform['platform_code']) ? $platform['platform_code']:"";
  712. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  713. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  714. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  715. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  716. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  717. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  718. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  719. $value['company'] = isset($company['company'])?$company['company']:"";
  720. $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
  721. $value['status']=$value['exam_status'];
  722. $data[]=$value;
  723. }
  724. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  725. }
  726. }