Good.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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. $skucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode'])
  54. :"";
  55. if($skucode!==""){
  56. $where [] = ['b.skucode',"like","%$skucode%"];
  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. $value['good_info_img']=json_decode($value['good_info_img'],true);
  145. $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
  146. $speclist=[];
  147. if(!empty($spec)){
  148. foreach ($spec as $val){
  149. $temp=[];
  150. $temp['spec_id']=$val['spec_id'];
  151. $temp['spec_value_id']=$val['spec_value_id'];
  152. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  153. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  154. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  155. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  156. $speclist[]=$temp;
  157. }
  158. }
  159. $value['specinfo']=$speclist;
  160. $data[]=$value;
  161. }
  162. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  163. }
  164. public function info(){
  165. $skucode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
  166. if($skucode==""){
  167. return error_show(1005,"参数skuCode不能为空");
  168. }
  169. $good_platform = Db::name("good_platform")->where(['skuCode'=>$skucode,"is_del"=>0])->find();
  170. if($good_platform==false){
  171. return error_show(1004,"未找到商品数据");
  172. }
  173. $data = Db::name("good")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->find();
  174. if($data==false){
  175. return error_show(1004,"未找到商品数据");
  176. }
  177. $plat =Db::name("platform")->where(["id"=>$good_platform['platform_code']])->find();
  178. $data['skuCode']=$good_platform['skuCode'];
  179. $data['platform_code']=$good_platform['id'];
  180. $data['platform_code_en']=isset($plat['platform_code'])?$plat['platform_code']:"";
  181. $data['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  182. $data['online_reason']=$good_platform['online_reason'];
  183. $data['online_time']=$good_platform['online_time'];
  184. $data['online_remark']=$good_platform['online_remark'];
  185. $data['exam_status']=$good_platform['exam_status'];
  186. $data['is_online']=$good_platform['is_online'];
  187. $data['plat_code']=$good_platform['plat_code'];
  188. $data['exclusive']=makeExcluse($data['is_exclusive']);
  189. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  190. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  191. $data['cat_info'] = made($data['cat_id'],[]);
  192. $spec = Db::name("good_spec")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
  193. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  194. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  195. // $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  196. // $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  197. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  198. $data['company'] = isset($company['company'])?$company['company']:"";
  199. if($data['brand_id']!=0){
  200. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  201. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  202. }else{
  203. $data["brand_name"]="";
  204. $data["brand_id"]="";
  205. }
  206. $data['origin_place_cn']="";
  207. $data['delivery_place_cn']="";
  208. if($data['delivery_place']!==""){
  209. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  210. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['delivery_place']);
  211. $data['delivery_place_cn']=GetAddr(json_encode($place));
  212. }
  213. if($data['origin_place']!==""){
  214. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  215. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['origin_place']);
  216. $data['origin_place_cn']=GetAddr(json_encode($place));
  217. }
  218. $excluse = makeExcluse($data['is_exclusive']);
  219. $data['exclusive']=$excluse;
  220. $data["good_info_img"]=$data['good_info_img']!=""? json_decode($data['good_info_img'],true):[];
  221. $speclist=[];
  222. if(!empty($spec)){
  223. foreach ($spec as $value){
  224. $temp=[];
  225. $temp['id']=$value['id'];
  226. $temp['spuCode']=$value['spuCode'];
  227. $temp['spec_id']=$value['spec_id'];
  228. $temp['spec_value_id']=$value['spec_value_id'];
  229. $temp['is_del']=$value['is_del'];
  230. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  231. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  232. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  233. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  234. $speclist[]=$temp;
  235. }
  236. }
  237. $data["speclist"]=empty($speclist)?[]:$speclist;
  238. $ladder = Db::name("good_ladder")->where(['skuCode'=>$skucode,"is_del"=>0])->select()->toArray();
  239. $data["ladderlist"]=!empty($ladder)?$ladder:[];
  240. $nakelist = Db::name("good_nake")->where(['spuCode'=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
  241. $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  242. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  243. $nakearry=[];
  244. if(!empty($nakelist)){
  245. foreach ($nakelist as $value){
  246. if($data['is_gold_price']==1){
  247. $gold = Db::name("gold_price1")->where(["type"=>$data['noble_metal'],"is_del"=>0,"status"=>1])->order("addtime desc")
  248. ->find();
  249. // $total_fee = $data['open_fee']/$value['min_num'] + $data['weight']*$gold["price"] + $data['cost_fee']/(1-$budget)*
  250. // $data['noble_weight']+$data['mark_fee']+$data['packing_fee']+$data['cert_fee']+$value['nake_fee'];
  251. $saleprice = $data['open_fee']/$value['min_num'] + $data['weight']*$gold["price"] + $data['cost_fee']*
  252. $data['noble_weight']+$data['mark_fee']+$data['packing_fee']+$data['cert_fee']+$value['nake_fee'];
  253. }else{
  254. // $total_fee = $data['open_fee']/$value['min_num']+
  255. // $data['cost_fee']*$data['weight']+$data['mark_fee']+$data['packing_fee']+$data['cert_fee']+$value['nake_fee'];
  256. $saleprice = $data['open_fee']/$value['min_num'] + $data['cost_fee']*
  257. $data['noble_weight']+$data['mark_fee']+$data['packing_fee']+$data['cert_fee']+$value['nake_fee']/(1-$budget);
  258. }
  259. $value['sale_price'] =round($saleprice,2) ;
  260. $nakearry[]=$value;
  261. }
  262. }
  263. $proof =Db::name("good_proof")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  264. $data['proof'] = isset($proof)&&$proof!=false? $proof:[];
  265. $data["nakelist"]=$nakearry;
  266. return app_show(0,"获取成功",$data);
  267. }
  268. public function SetWarn(){
  269. $condition=["is_del"=>0];
  270. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  271. if($wsm_code!=""){
  272. $condition["wsm_code"] = $wsm_code;
  273. }else{
  274. return error_show(1004,"参数wsm_code 不能为空");
  275. }
  276. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  277. if($type_code!=""){
  278. $condition["good_type_code"] = $type_code;
  279. }else{
  280. return error_show(1004,"参数type_code 不能为空");
  281. }
  282. $good= Db::name("good_stock")->where($condition)->find();
  283. if(empty($good)){
  284. return error_show(1005,"未找到数据");
  285. }
  286. $warn_stock = isset($this->post['warn_stock']) &&$this->post['warn_stock'] !=="" ? intval($this->post['warn_stock']):"";
  287. if($warn_stock===""){
  288. return error_show(1005,"参数warn_stock 不能为空");
  289. }
  290. $good['warn_stock'] = $warn_stock;
  291. $good['updatetime'] = date("Y-m-d H:i:s");
  292. $up= Db::name("good_stock")->save($good);
  293. if($up){
  294. $data=["stock_id"=>$good['id'],"type"=>1,'stock'=>$warn_stock,"stock_name"=>"warn_stock"];
  295. GoodLog::LogAdd($this->post['token'],$data,'setwarn');
  296. return app_show(0,"预警库存更新成功");
  297. }else{
  298. return error_show(1005,"预警库存更新失败");
  299. }
  300. }
  301. public function SetStatus(){
  302. $id = isset($this->post['id']) &&$this->post['id'] !=="" ? intval($this->post['id']):"";
  303. if($id===""){
  304. return error_show(1005,"参数id 不能为空");
  305. }
  306. $good= Db::name("good_type")->where(["id"=>$id,"is_del"=>0])->find();
  307. if(empty($good)){
  308. return error_show(1005,"未找到数据");
  309. }
  310. $good['status'] = $good['status']==1?0 :1;
  311. $good['updatetime'] = date("Y-m-d H:i:s");
  312. $msg = $good['status']==1?"下架" :"上架";
  313. $up= Db::name("good_type")->save($good);
  314. return $up ? app_show(0,"商品{$msg}成功"): error_show(1005,"商品{$msg}失败");
  315. }
  316. public function GetStock(){
  317. $condition = [["a.is_del","=",0]];
  318. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  319. if($type_code!==""){
  320. $condition[]=["a.good_type_code","=",$type_code];
  321. }
  322. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  323. :"";
  324. if($wsm_code!==""){
  325. //$condition["a.wsm_code"]=$wsm_code;
  326. $condition[]=["a.wsm_code","=",$type_code];
  327. }
  328. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  329. :"";
  330. if($suplierNo!==""){
  331. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"wsm_type"=>1,"is_del"=>0])->column("wsm_code");
  332. $condition[]=["a.wsm_code","in",$wsmcode];
  333. }
  334. $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")
  335. ->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();
  336. if(empty($list)){
  337. return error_show(1004,"未找到数据");
  338. }
  339. return app_show(0,"获取成功",$list);
  340. }
  341. /**
  342. * @return \think\response\Json|void
  343. * @throws \think\db\exception\DataNotFoundException
  344. * @throws \think\db\exception\DbException
  345. * @throws \think\db\exception\ModelNotFoundException
  346. */
  347. public function GetStockBet(){
  348. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  349. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  350. $condition = [["is_del","=",0]];
  351. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  352. if($type_code!==""){
  353. $condition[]=["good_type_code","like","%{$type_code}%"];
  354. }
  355. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  356. :"";
  357. if($wsm_code!==""){
  358. $condition[]=["wsm_code","=",$wsm_code];
  359. }
  360. $suplierNo = isset($this->post['suplierNo']) &&$this->post['suplierNo'] !=="" ? trim($this->post['suplierNo'])
  361. :"";
  362. if($suplierNo!==""){
  363. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"wsm_type"=>1,"is_del"=>0])->column("wsm_code");
  364. $condition[]=["wsm_code","in",$wsmcode];
  365. }
  366. $start = isset($this->post['start']) &&$this->post['start'] !=="" ? $this->post['start']:"";
  367. $end = isset($this->post['end']) &&$this->post['end'] !=="" ? $this->post['end']:"";
  368. if($start!=""){
  369. $condition[]=["addtime",">=",$start];
  370. }
  371. if($end!=""){
  372. $condition[]=["addtime","<=",$end];
  373. }
  374. $count = Db::name("good_stock")->where($condition)->count();
  375. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  376. $list = Db::name("good_stock")->where($condition)->page($page,$size)->order("addtime desc")->select();
  377. $data=[];
  378. foreach ($list as $key=>$value){
  379. $temp=[];
  380. if($value['wsm_code']!=""){
  381. $wsm = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")->where
  382. (['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])->field("a.name as wsm_name,wsm_code,b.code,b.name")
  383. ->find();
  384. }
  385. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  386. $temp['wsm_code']=$value['wsm_code'];
  387. $temp['supplier_code']=isset($wsm['code'])?$wsm['code']:"";
  388. $temp['supplier_name']=isset($wsm['name'])?$wsm['name']:"";
  389. if($value['good_type_code']!=""){
  390. $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])
  391. ->field("a.good_code,a.type_code,b.good_name,b.unit,a.attribute,b.sort_f")->find();
  392. }
  393. $temp['good_code']=isset($good['good_code'])?$good['good_code']:"";
  394. $temp['type_code']=isset($good['type_code'])?$good['type_code']:"";
  395. $temp['good_name']=isset($good['good_name'])?$good['good_name']:"";
  396. $temp['unit']=isset($good['unit'])?$good['unit']:"";
  397. $temp['attribute']=isset($good['attribute'])?$good['attribute']:"";
  398. $temp['sort_f']=isset($good['sort_f'])?$good['sort_f']:"";
  399. $temp['usable_stock'] = $value['usable_stock'];
  400. $temp['wait_in_stock'] = $value['wait_in_stock'];
  401. $temp['wait_out_stock'] = $value['wait_out_stock'];
  402. $temp['intra_stock'] = $value['intra_stock'];
  403. $temp['total_stock'] = $value['total_stock'];
  404. $temp['warn_stock'] = $value['warn_stock'];
  405. $temp['id'] = $value['id'];
  406. $temp['out_total'] =0;
  407. $temp['in_total'] = 0;
  408. $temp['addtime'] = $value['addtime'];
  409. $data[]=$temp;
  410. }
  411. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  412. }
  413. /**
  414. * @return \think\response\Json|void
  415. * @throws \think\db\exception\DataNotFoundException
  416. * @throws \think\db\exception\DbException
  417. * @throws \think\db\exception\ModelNotFoundException
  418. * @throws \think\exception\DbException
  419. */
  420. public function GetStockWsm(){
  421. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  422. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  423. $condition = [["is_del","=",0]];
  424. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  425. :"";
  426. if($wsm_code!==""){
  427. $condition[]=["wsm_code","=",$wsm_code];
  428. }
  429. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  430. :"";
  431. if($suplierNo!==""){
  432. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"wsm_type"=>1,"is_del"=>0])->column("wsm_code");
  433. $condition[]=["wsm_code","in",$wsmcode];
  434. }
  435. $build= Db::name("good_stock")->where($condition)->group("wsm_code")->field("wsm_code")->buildSql();
  436. $count = Db::table($build." a")->count();
  437. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  438. $list = Db::name("good_stock")->where($condition)->page($page,$size)->group("wsm_code")
  439. ->field("wsm_code,sum(wait_in_stock) wait_in_stock,sum(wait_out_stock) wait_out_stock,sum(usable_stock) usable_stock,
  440. sum(intra_stock) intra_stock,sum(warn_stock) warn_stock,sum(total_stock) total_stock")->select();
  441. $data=[];
  442. foreach ($list as $key=>$value){
  443. $temp=[];
  444. if($value['wsm_code']!=""){
  445. $wsm = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")->where
  446. (['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])->field("a.name as wsm_name,wsm_code,b.code,b.name")
  447. ->find();
  448. $good = Db::name("good_stock")->alias("a")->join("good_type b","a.good_type_code=b.type_code","left")
  449. ->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])
  450. ->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")
  451. ->select();
  452. }
  453. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  454. $temp['wsm_code']=$value['wsm_code'];
  455. $temp['supplier_code']=isset($wsm['code'])?$wsm['code']:"";
  456. $temp['supplier_name']=isset($wsm['name'])?$wsm['name']:"";
  457. $temp['usable_stock'] = $value['usable_stock'];
  458. $temp['wait_in_stock'] = $value['wait_in_stock'];
  459. $temp['wait_out_stock'] = $value['wait_out_stock'];
  460. $temp['intra_stock'] = $value['intra_stock'];
  461. $temp['total_stock'] = $value['total_stock'];
  462. // $temp['warn_stock'] = $value['warn_stock'];
  463. $temp['child']=isset($good)&&!empty($good) ? $good:[];
  464. $data[]=$temp;
  465. }
  466. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  467. }
  468. public function GetStockGod(){
  469. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  470. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  471. $condition = [["a.is_del","=",0],["b.is_del","=",0],["c.usable_stock",">",0]];
  472. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code'])
  473. :"";
  474. if($type_code!==""){
  475. $condition[]=["b.type_code","like","%{$type_code}%"];
  476. }
  477. $count = Db::name("good_type")->alias("b")
  478. ->join("good a","a.good_code = b.good_code","left")
  479. ->join("good_stock c","c.good_type_code = b.type_code","left")
  480. ->where($condition)->group("a.good_code,a.good_name,a.unit,a.sort_f,b.type_code,b.attribute,a.addtime")->count();
  481. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  482. $list = Db::name("good_type")->alias("b")
  483. ->join("good a","a.good_code = b.good_code","left")
  484. ->join("good_stock c","c.good_type_code = b.type_code","left")
  485. ->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,
  486. 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")
  487. ->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();
  488. // echo Db::name("good_type")->getLastSql();
  489. $data=[];
  490. foreach ($list as $key=>$value){
  491. $temp=[];
  492. if($value['type_code']!=""){
  493. $child = Db::name("good_stock")->alias("a")->join("warehouse_info b","a.wsm_code=b.wsm_code","left")
  494. ->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();
  495. }
  496. $temp['good_name'] = $value['good_name'];
  497. $temp['good_code'] = $value['good_code'];
  498. $temp['type_code'] = $value['type_code'];
  499. $temp['unit'] = $value['unit'];
  500. $temp['sort_f']=$value['sort_f'];
  501. $temp['attribute']=$value['attribute'];
  502. $temp['addtime']=$value['addtime'];
  503. $temp['usable_stock'] = isset($value['usable_stock'])? $value['usable_stock']:"";
  504. $temp['wait_in_stock'] = isset($value['wait_in_stock'])? $value['wait_in_stock']:"";
  505. $temp['wait_out_stock'] = isset($value['wait_out_stock'])? $value['wait_out_stock']:"";
  506. $temp['intra_stock'] = isset($value['intra_stock'])? $value['intra_stock']:"";
  507. $temp['total_stock'] = isset($value['total_stock'])? $value['total_stock']:"";
  508. // $temp['warn_stock'] = isset($value['warn_stock'])? $value['warn_stock']:"";
  509. $temp['child']=isset($child)&&!empty($child) ? $child:[];
  510. $data[]=$temp;
  511. }
  512. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  513. }
  514. /**
  515. * @return \think\response\Json|void
  516. * @throws \think\db\exception\DataNotFoundException
  517. * @throws \think\db\exception\DbException
  518. * @throws \think\db\exception\ModelNotFoundException
  519. */
  520. public function Stat(){
  521. $condition =[["is_del","=",0]];
  522. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  523. if($wsm_code!=""){
  524. //$condition["wsm_code"] = $wsm_code;
  525. $condition[]=["wsm_code","=",$wsm_code];
  526. }
  527. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  528. if($suplierNo!==""){
  529. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"wsm_type"=>1,"is_del"=>0])->column("wsm_code");
  530. $condition[]=["wsm_code","in",$wsmcode];
  531. }
  532. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  533. if($type_code!=""){
  534. $condition[] = ["good_type_code","=",$type_code];
  535. }
  536. $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();
  537. return app_show(0,"获取成功",$statlist);
  538. }
  539. public function all(){
  540. $condtion=["a.is_del"=>0,"b.is_del"=>0];
  541. $wsmcode =isset($this->post['wsmcode']) &&$this->post['wsmcode'] !=="" ? trim($this->post['wsmcode']):"";
  542. if($wsmcode!=""){
  543. $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code");
  544. $condtion["b.type_code"] = $typecode;
  545. }
  546. $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  547. if($good_code!=""){
  548. $condtion['b.type_code'] = $good_code;
  549. }
  550. $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code'])
  551. :"";
  552. if($goodcode!=""){
  553. $condtion['a.good_code'] = $goodcode;
  554. }
  555. $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name'])
  556. :"";
  557. if($good_name!=""){
  558. $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'");
  559. }
  560. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  561. if($supplierNo!=""){
  562. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  563. if(empty($supplier)){
  564. return error_show(1004,"未找到供应商信息");
  565. }
  566. $condtion["a.gys_code"] = $supplierNo;
  567. }
  568. $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  569. ->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,
  570. 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")
  571. ->select();
  572. $data=[];
  573. foreach ($list as $key=>$value){
  574. $stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock");
  575. $value['usable_stock']=$stock;
  576. $supplier = Db::name("supplier")->where(["code"=>$value['gys_code']])->find();
  577. $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
  578. $data[]=$value;
  579. }
  580. return app_show(0,"获取成功",$data);
  581. }
  582. public function loglist(){
  583. $page = isset($this->post['page']) && $this->post['page']!==""? intval($this->post['page']) :"1";
  584. $size = isset($this->post['size']) && $this->post['size']!==""? intval($this->post['size']) :"10";
  585. $where=[];
  586. $wsm_code= isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  587. if($wsm_code!=""){
  588. $where[]=['b.wsm_code',"like","%$wsm_code%"];
  589. }
  590. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  591. if($supplierNo!=""){
  592. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  593. if(empty($supplier)){
  594. return error_show(1004,"未找到供应商信息");
  595. }
  596. $wsmcode = Db::name("warehouse_info")->where([
  597. "is_del"=>0,"wsm_type"=>1,"supplierNo"=>$supplierNo])->column("wsm_code");
  598. $where[]=['b.wsm_code',"in",$wsmcode];
  599. }
  600. $count = Db::name("good_log")->alias('a')
  601. ->join("good_stock b","b.id=a.id","left")->where($where)
  602. ->join("good_type c","c.type_code=b.good_type_code","left")
  603. ->join("good v","v.good_code=c.good_code","left")->count();
  604. $total = ceil($count/$size);
  605. $page = $total>=$page ? $page :$total;
  606. $list = Db::name("good_log")->alias('a')
  607. ->join("good_stock b","b.id=a.stock_id","left")
  608. ->join("good_type c","c.type_code=b.good_type_code","left")
  609. ->join("good v","v.good_code=c.good_code","left")
  610. ->where($where)->page($page,$size)->order("a.addtime desc")
  611. ->field("a.action_name,a.type,a.stock_name,a.stock,a.action_type,
  612. a.addtime,a.action_uid,b.wsm_code,v.good_code,v.good_name,v.cat_id")->select();
  613. $data=[];
  614. foreach ($list as $value){
  615. $db = Db::name("depart_user")->where(['uid'=>$value['action_uid']])->column("itemid");
  616. $item = Db::name("company_item")->where(['id'=>$db])->column("id,name");
  617. $wsm = Db::name("warehouse_info")->alias("a")->Join("supplier b","a.supplierNo=b.code","left")->where
  618. (['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();
  619. $int = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  620. $value['wsm_name'] =$wsm['wsm_name'];
  621. $value['wsm_code'] =$wsm['wsm_code'];
  622. $value['code'] =$wsm['code'];
  623. $value['name'] =$wsm['name'];
  624. $value['action_type_cn'] =$this->acton[$value['action_type']];
  625. $value['item'] =$item;
  626. $value['can'] =$int;
  627. $data[]=$value;
  628. }
  629. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  630. }
  631. public function goodlist(){
  632. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  633. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  634. $where =[["a.is_del","=",0],["b.exam_status","=",6],["b.is_del","=",0],["c.is_del","=",0],["c.status","=",1]];
  635. $paltcode = isset($this->post["platform_code"])&& $this->post["platform_code"]!=""? trim($this->post["platform_code"]):"";
  636. if($paltcode!=""){
  637. $where[]=["platform_code","=",$paltcode];
  638. }
  639. $companyNo = isset($this->post["companyNo"])&& $this->post["companyNo"]!=""? trim($this->post["companyNo"])
  640. :"";
  641. if($companyNo!=""){
  642. $where[]=["companyNo","like","%$companyNo%"];
  643. }
  644. $cat_id = isset($this->post["cat_id"])&& $this->post["cat_id"]!==""? intval($this->post["cat_id"]):"";
  645. if($cat_id!==""){
  646. $where[]=["cat_id","=",$cat_id];
  647. }
  648. $buy_num = isset($this->post["buy_num"])&& $this->post["buy_num"]!==""? intval($this->post["buy_num"]):"";
  649. if($buy_num!==""){
  650. $where[]=["min_num","<=",$buy_num];
  651. }
  652. $price = isset($this->post["price"])&& $this->post["price"]!==""? floatval($this->post["price"]):"";
  653. if($buy_num!==""){
  654. $where[]=["sale_price","<=",$price];
  655. }
  656. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->leftJoin("good_ladder c","b.skuCode=c.skuCode")
  657. ->where($where)->count();
  658. $total = ceil($count / $size);
  659. $page = $page >= $total ? $total : $page;
  660. $list = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->leftJoin("good_ladder c","b.skuCode=c.skuCode")->where($where)->page
  661. ($page,$size)->field("c.id,c.min_num,c.sale_price,.a.good_name,a.spuCode,a.cat_id,a.brand_id,a.companyNo,a.supplierNo,a.good_unit,b.skuCode,b.platform_code,b.plat_code,b.id as good_id,b.addtime,b.updatetime,b.exam_status")
  662. ->order("b.addtime desc")
  663. ->select();
  664. $data=[];
  665. foreach ($list as $value){
  666. $value['cat_info']= made($value['cat_id'],[]);
  667. $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
  668. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
  669. $value['platform_code_en'] = isset($platform['platform_code']) ? $platform['platform_code']:"";
  670. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  671. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  672. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  673. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  674. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  675. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  676. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  677. $value['company'] = isset($company['company'])?$company['company']:"";
  678. $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
  679. $value['status']=$value['exam_status'];
  680. $data[]=$value;
  681. }
  682. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  683. }
  684. }