Good.php 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\GoodLog;
  4. use think\App;
  5. use think\db\Raw;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. //线上商品
  9. class Good extends Base
  10. {
  11. private $acton=[
  12. "allotsend"=>'调拨发货',
  13. "allotin"=>'调拨入库',
  14. "allotincheck"=>'调拨验货',
  15. 'CGD'=>'采购单',
  16. 'BHD'=>'备库单',
  17. 'FKD'=>'备库反馈单',
  18. 'RKD'=>'入库单',
  19. 'ZXQRD'=>'咨询单',
  20. 'XSQRD'=>'销售单',
  21. 'PDD'=>'盘点单',
  22. 'DBD'=>'调拨单',
  23. 'CKD'=>'出库单',
  24. 'CGTHD'=>'采购退货单',
  25. 'XSTHD'=>'销售退货单',
  26. 'CGGCD'=>'采购工差单',
  27. 'ZXGCD'=>'咨询工差单'
  28. ];
  29. public $noble=[];
  30. public function __construct(App $app)
  31. {
  32. parent::__construct($app);
  33. $this->noble=\think\facade\Config::get("noble");
  34. }
  35. public function list(){
  36. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  37. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  38. $where =[["a.is_del","=",0]];
  39. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? trim($this->post['cat_id']):"";
  40. if($cat_id!==""){
  41. $where[]=['a.cat_id',"=",$cat_id];
  42. }
  43. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  44. if($good_name!==""){
  45. $where[]=['a.good_name',"like","%$good_name%"];
  46. }
  47. $skucode = isset($this->post['skucode']) && $this->post['skucode'] !=="" ? trim($this->post['skucode']):"";
  48. if($skucode!==""){
  49. $where [] = ['b.skucode',"like","%$skucode%"];
  50. }
  51. $spucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode']):"";
  52. if($spucode!==""){
  53. $where [] = ['b.spucode',"like","%$spucode%"];
  54. }
  55. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  56. if($start!==""){
  57. $where[]=['a.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  58. }
  59. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  60. if($end!==""){
  61. $where[]=['a.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  62. }
  63. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !=="" ? intval($this->post['is_stock'])
  64. :"";
  65. if($is_stock!==""){
  66. $where[]=['a.is_stock',"=",$is_stock];
  67. }
  68. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? intval($this->post['good_type'])
  69. :"";
  70. if($good_type!==""){
  71. $where[]=['a.good_type',"=",$good_type];
  72. }
  73. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  74. :"";
  75. if($supplierNo!==""){
  76. $where[]=['a.supplierNo',"=",$supplierNo];
  77. }
  78. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :"";
  79. if($companyNo!==""){
  80. $where[]=['a.companyNo',"like","%$companyNo%"];
  81. }
  82. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  83. if($creater!==""){
  84. $where[]=['a.creater',"like","%$creater%"];
  85. }
  86. $createrid = isset($this->post['createrid']) && $this->post['createrid'] !=="" ? intval($this->post['createrid']):"";
  87. if($createrid!==""){
  88. $where[]=['a.createrid',"=",$createrid];
  89. }
  90. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
  91. :"";
  92. if($status!==""){
  93. $where[]=['a.status',"=",$status];
  94. }
  95. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code'])
  96. :"";
  97. if($platform_code!==""){
  98. //$platform = Db::name("good_platform")->where(["platform_code"=>$platform_code,"is_del"=>0])->column
  99. //("spuCode");
  100. $where[]=["platform_code","=",$platform_code];
  101. }
  102. $plat_code = isset($this->post['plat_code']) && $this->post['plat_code'] !=="" ? trim($this->post['plat_code'])
  103. :"";
  104. if($plat_code!==""){
  105. $where[]=["b.plat_code","like","%$plat_code%"];
  106. }
  107. $exam_status = isset($this->post['exam_status']) && $this->post['exam_status'] !=="" ? intval($this->post['exam_status'])
  108. :"";
  109. if($exam_status!==""){
  110. $where[]=['b.exam_status',"=",$exam_status];
  111. }
  112. $brand_id = isset($this->post['brand_id']) && $this->post['brand_id'] !=="" ? intval($this->post['brand_id'])
  113. :"";
  114. if($brand_id!==""){
  115. $where[]=['a.brand_id',"=",$brand_id];
  116. }
  117. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where($where)
  118. ->count();
  119. $total = ceil($count / $size);
  120. $page = $page >= $total ? $total : $page;
  121. $list = Db::name('good')
  122. ->alias("a")
  123. ->field("b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.*,b.addtime,b.updatetime,b.exam_status,gb.createrid purchase_id,gb.creater purchase")//成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  124. ->leftJoin("good_platform b","a.spuCode=b.spuCode")
  125. ->leftJoin("good_basic gb","gb.spuCode=a.spuCode")
  126. ->where($where)
  127. ->page($page,$size)
  128. ->order("b.addtime desc")
  129. ->select()
  130. ->toArray();
  131. $data=[];
  132. foreach ($list as $value){
  133. $value['cat_info']= made($value['cat_id'],[]);
  134. $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
  135. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
  136. $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en']:"";
  137. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  138. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  139. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  140. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  141. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  142. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  143. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  144. $value['company'] = isset($company['company'])?$company['company']:"";
  145. $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
  146. $value['status']=$value['exam_status'];
  147. $value['exclusive']=makeExcluse($value['is_exclusive']);
  148. $value['good_info_img']=$value['good_info_img'];
  149. $value['good_img']=$value['good_img'];
  150. $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
  151. $speclist=[];
  152. if(!empty($spec)){
  153. foreach ($spec as $val){
  154. $temp=[];
  155. $temp['spec_id']=$val['spec_id'];
  156. $temp['spec_value_id']=$val['spec_value_id'];
  157. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  158. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  159. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  160. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  161. $speclist[]=$temp;
  162. }
  163. }
  164. $value['specinfo']=$speclist;
  165. $value['noble_name']=isset($value['noble_metal'])&&$value['noble_metal']!=0?$this->noble[$value['noble_metal']] :"";
  166. $data[]=$value;
  167. }
  168. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  169. }
  170. public function info(){
  171. $skucode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
  172. if($skucode==""){
  173. return error_show(1005,"参数skuCode不能为空");
  174. }
  175. $good_platform = Db::name("good_platform")->where(['skuCode'=>$skucode,"is_del"=>0])->find();
  176. if($good_platform==false){
  177. return error_show(1004,"未找到商品数据");
  178. }
  179. $data = Db::name("good")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->find();
  180. if($data==false){
  181. return error_show(1004,"未找到商品数据");
  182. }
  183. $plat =Db::name("platform")->where(["id"=>$good_platform['platform_code']])->find();
  184. $data['skuCode']=$good_platform['skuCode'];
  185. $data['platform_code']=$good_platform['id'];
  186. $data['platform_code_en']=isset($plat['platform_code'])?$plat['platform_code']:"";
  187. $data['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  188. $data['online_reason']=$good_platform['online_reason'];
  189. $data['online_time']=$good_platform['online_time'];
  190. $data['online_remark']=$good_platform['online_remark'];
  191. $data['exam_status']=$good_platform['exam_status'];
  192. $data['is_online']=$good_platform['is_online'];
  193. $data['plat_code']=$good_platform['plat_code'];
  194. $data['exclusive']=makeExcluse($data['is_exclusive']);
  195. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  196. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  197. $data['cat_info'] = made($data['cat_id'],[]);
  198. $spec = Db::name("good_spec")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
  199. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  200. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  201. $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
  202. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  203. $data['company'] = isset($company['company'])?$company['company']:"";
  204. if($data['brand_id']!=0){
  205. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  206. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  207. }else{
  208. $data["brand_name"]="";
  209. $data["brand_id"]="";
  210. }
  211. $data['origin_place_cn']="";
  212. $data['delivery_place_cn']="";
  213. if($data['delivery_place']!==""){
  214. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  215. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['delivery_place']);
  216. $data['delivery_place_cn']=GetAddr(json_encode($place));
  217. }
  218. if($data['origin_place']!==""){
  219. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  220. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['origin_place']);
  221. $data['origin_place_cn']=GetAddr(json_encode($place));
  222. }
  223. $excluse = makeExcluse($data['is_exclusive']);
  224. $data['exclusive']=$excluse;
  225. $data["good_info_img"]=$data['good_info_img']!=""? $data['good_info_img']:[];
  226. $data["good_img"]=$data['good_img']!=""? $data['good_img']:[];
  227. $speclist=[];
  228. if(!empty($spec)){
  229. foreach ($spec as $value){
  230. $temp=[];
  231. $temp['id']=$value['id'];
  232. $temp['spuCode']=$value['spuCode'];
  233. $temp['spec_id']=$value['spec_id'];
  234. $temp['spec_value_id']=$value['spec_value_id'];
  235. $temp['is_del']=$value['is_del'];
  236. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  237. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  238. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  239. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  240. $speclist[]=$temp;
  241. }
  242. }
  243. $data["speclist"]=empty($speclist)?[]:$speclist;
  244. $ladder = Db::name("good_ladder")->where(['skuCode'=>$skucode,"is_del"=>0])->select()->toArray();
  245. $data["ladderlist"]=!empty($ladder)?$ladder:[];
  246. $nakelist = Db::name("good_nake")->where(['spuCode'=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
  247. // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  248. $cat_top_list = made($data['cat_id']);
  249. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  250. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  251. $nakearry=[];
  252. if(!empty($nakelist)){
  253. //实时金价
  254. $gold_price = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->value('price', 0);
  255. foreach ($nakelist as $value){
  256. $value['sale_price'] =$value['nake_total'];
  257. //计算最终售价
  258. if ($data['is_gold_price']==1 && $cat_top_id==6) {
  259. //普通商品:直接用财务提交的售价字段;
  260. //贵金属( 商品重量* 最新金价 + 工艺费(财务定价提交的)* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)=商品库商品直接下单的售价
  261. $value['sale_price'] = ($data['weight'] * $gold_price + $value['cost_fee'] * $data['weight'] + $value['package_fee'] + $value['mark_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['other_fee']);
  262. }
  263. $nakearry[] = $value;
  264. }
  265. }
  266. $proof =Db::name("good_proof")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  267. $data['proof'] = isset($proof)&&$proof!=false? $proof:[];
  268. $data["nakelist"]=$nakearry;
  269. //补充采购员字段
  270. //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  271. $temp_basic_info = Db::name('good_basic')
  272. ->field('id,createrid purchase_id,creater purchase')
  273. ->where(['spuCode'=>$data['spuCode'],'is_del'=>0])
  274. ->find();
  275. $data['purchase_id'] = $temp_basic_info['purchase_id'];
  276. $data['purchase'] = $temp_basic_info['purchase'];
  277. return app_show(0,"获取成功",$data);
  278. }
  279. public function SetWarn(){
  280. $condition=["is_del"=>0];
  281. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  282. if($wsm_code!=""){
  283. $condition["wsm_code"] = $wsm_code;
  284. }else{
  285. return error_show(1004,"参数wsm_code 不能为空");
  286. }
  287. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  288. if($type_code!=""){
  289. $condition["good_type_code"] = $type_code;
  290. }else{
  291. return error_show(1004,"参数type_code 不能为空");
  292. }
  293. $good= Db::name("good_stock")->where($condition)->find();
  294. if(empty($good)){
  295. return error_show(1005,"未找到数据");
  296. }
  297. $warn_stock = isset($this->post['warn_stock']) &&$this->post['warn_stock'] !=="" ? intval($this->post['warn_stock']):"";
  298. if($warn_stock===""){
  299. return error_show(1005,"参数warn_stock 不能为空");
  300. }
  301. $good['warn_stock'] = $warn_stock;
  302. $good['updatetime'] = date("Y-m-d H:i:s");
  303. $up= Db::name("good_stock")->save($good);
  304. if($up){
  305. //商品变动日志表,good_log_code字段存储仓库编码
  306. $data = ['good_log_code' => $wsm_code, "stock_id" => $good['id'], "type" => 1, 'stock' => $warn_stock, "stock_name" => "warn_stock"];
  307. GoodLog::LogAdd($this->post['token'],$data,'setwarn');
  308. return app_show(0,"预警库存更新成功");
  309. }else{
  310. return error_show(1005,"预警库存更新失败");
  311. }
  312. }
  313. public function SetStatus(){
  314. $id = isset($this->post['id']) &&$this->post['id'] !=="" ? intval($this->post['id']):"";
  315. if($id===""){
  316. return error_show(1005,"参数id 不能为空");
  317. }
  318. $good= Db::name("good_type")->where(["id"=>$id,"is_del"=>0])->find();
  319. if(empty($good)){
  320. return error_show(1005,"未找到数据");
  321. }
  322. $good['status'] = $good['status']==1?0 :1;
  323. $good['updatetime'] = date("Y-m-d H:i:s");
  324. $msg = $good['status']==1?"下架" :"上架";
  325. $up= Db::name("good_type")->save($good);
  326. return $up ? app_show(0,"商品{$msg}成功"): error_show(1005,"商品{$msg}失败");
  327. }
  328. public function GetStock(){
  329. $condition = [["a.is_del","=",0]];
  330. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  331. if($type_code!==""){
  332. $condition[]=["a.spuCode","=",$type_code];
  333. }
  334. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  335. :"";
  336. if($wsm_code!==""){
  337. //$condition["a.wsm_code"]=$wsm_code;
  338. $condition[]=["a.wsm_code","=",$type_code];
  339. }
  340. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  341. :"";
  342. if($suplierNo!==""){
  343. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  344. $condition[]=["a.wsm_code","in",$wsmcode];
  345. }
  346. $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")
  347. ->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();
  348. if(empty($list)){
  349. return error_show(1004,"未找到数据");
  350. }
  351. return app_show(0,"获取成功",$list);
  352. }
  353. /**
  354. * @return \think\response\Json|void
  355. * @throws \think\db\exception\DataNotFoundException
  356. * @throws \think\db\exception\DbException
  357. * @throws \think\db\exception\ModelNotFoundException
  358. */
  359. public function GetStockBet(){
  360. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  361. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  362. $condition = [["is_del","=",0]];
  363. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  364. if($type_code!==""){
  365. $condition[]=["spuCode","like","%{$type_code}%"];
  366. }
  367. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
  368. :"";
  369. if($wsm_code!==""){
  370. $condition[]=["wsm_code","=",$wsm_code];
  371. }
  372. $suplierNo = isset($this->post['suplierNo']) &&$this->post['suplierNo'] !=="" ? trim($this->post['suplierNo']):"";
  373. if($suplierNo!==""){
  374. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  375. $condition[]=["wsm_code","in",$wsmcode];
  376. }
  377. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  378. if ($companyNo !== "") {
  379. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  380. $condition[]=["wsm_code","in",$wsmcode];
  381. }
  382. $start = isset($this->post['start']) &&$this->post['start'] !=="" ? $this->post['start']:"";
  383. $end = isset($this->post['end']) &&$this->post['end'] !=="" ? $this->post['end']:"";
  384. if($start!=""){
  385. $condition[]=["addtime",">=",$start];
  386. }
  387. if($end!=""){
  388. $condition[]=["addtime","<=",$end];
  389. }
  390. $count = Db::name("good_stock")->where($condition)->count();
  391. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  392. $list = Db::name("good_stock")->where($condition)->page($page,$size)->order("addtime desc")->select();
  393. $data=[];
  394. foreach ($list as $key=>$value){
  395. $temp=[];
  396. if($value['wsm_code']!=""){
  397. $wsm = Db::name("warehouse_info")
  398. ->alias("a")
  399. ->leftJoin("supplier b","a.supplierNo=b.code")
  400. ->leftJoin("business bus","a.companyNo=bus.companyNo")
  401. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  402. ->field("a.name as wsm_name,wsm_code,a.supplierNo,b.name supplierName,a.companyNo,bus.company")
  403. ->find();
  404. }
  405. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  406. $temp['wsm_code']=$value['wsm_code'];
  407. $temp['supplier_code']=isset($wsm['supplierNo'])?$wsm['supplierNo']:"";
  408. $temp['supplier_name']=isset($wsm['supplierName'])?$wsm['supplierName']:"";
  409. $temp['company_no']=isset($wsm['companyNo'])?$wsm['companyNo']:"";
  410. $temp['company_name']=isset($wsm['company'])?$wsm['company']:"";
  411. if($value['spuCode']!=""){
  412. $good=Db::name("good")
  413. ->alias('g')
  414. ->field('g.*,b.brand_name,u.unit')
  415. ->where(["g.spuCode"=>$value['spuCode'],"g.is_del"=>0])
  416. ->leftJoin('brand b','b.id=g.brand_id')
  417. ->leftJoin('unit u','u.id=g.good_unit')
  418. ->find();
  419. //规格信息
  420. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  421. $speclist = [];
  422. if (!empty($spec)) {
  423. foreach ($spec as $val) {
  424. $tmp = [];
  425. $tmp['spec_id'] = $val['spec_id'];
  426. $tmp['spec_value_id'] = $val['spec_value_id'];
  427. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  428. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  429. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  430. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  431. $speclist[] = $tmp;
  432. }
  433. }
  434. $temp['specinfo'] = $speclist;
  435. }
  436. $temp['good_code']=isset($good['spuCode'])?$good['spuCode']:"";
  437. // $temp['type_code']=isset($good['type_code'])?$good['type_code']:"";
  438. $temp['good_name']=isset($good['good_name'])?$good['good_name']:"";
  439. $temp['unit']=isset($good['unit'])?$good['unit']:"";
  440. $temp['brand_name']=isset($good['brand_name'])?$good['brand_name']:"";
  441. // $temp['attribute']=isset($good['attribute'])?$good['attribute']:"";
  442. $temp['sort_f']=isset($good['cat_id'])?$good['cat_id']:"";
  443. $temp['cat_info']=isset($good['cat_id'])?made($good['cat_id']):"";
  444. $temp['usable_stock'] = $value['usable_stock'];
  445. $temp['wait_in_stock'] = $value['wait_in_stock'];
  446. $temp['wait_out_stock'] = $value['wait_out_stock'];
  447. $temp['intra_stock'] = $value['intra_stock'];
  448. $temp['total_stock'] = $value['total_stock'];
  449. $temp['warn_stock'] = $value['warn_stock'];
  450. $temp['id'] = $value['id'];
  451. $temp['out_total'] =0;
  452. $temp['in_total'] = 0;
  453. $temp['addtime'] = $value['addtime'];
  454. $data[]=$temp;
  455. }
  456. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  457. }
  458. /**
  459. * @return \think\response\Json|void
  460. * @throws \think\db\exception\DataNotFoundException
  461. * @throws \think\db\exception\DbException
  462. * @throws \think\db\exception\ModelNotFoundException
  463. * @throws \think\exception\DbException
  464. */
  465. public function GetStockWsm(){
  466. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  467. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  468. $condition = [["gs.is_del","=",0]];
  469. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  470. if($wsm_code!==""){
  471. $condition[]=["gs.wsm_code","=",$wsm_code];
  472. }
  473. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  474. if($suplierNo!==""){
  475. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  476. $condition[]=["gs.wsm_code","in",$wsmcode];
  477. }
  478. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  479. if ($companyNo !== "") {
  480. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  481. $condition[]=["gs.wsm_code","in",$wsmcode];
  482. }
  483. $build= Db::name("good_stock")
  484. ->alias('gs')
  485. ->where($condition)
  486. ->where('whi.wsm_type','<>',2)//2表示虚拟仓,虚拟仓不参加统计
  487. ->leftJoin('warehouse_info whi','whi.wsm_code=gs.wsm_code AND whi.is_del=0')
  488. ->group("gs.wsm_code")
  489. ->field("gs.wsm_code")
  490. ->buildSql();
  491. $count = Db::table($build." a")->count();
  492. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  493. $list = Db::name("good_stock")
  494. ->alias('gs')
  495. ->where($condition)
  496. ->where('whi.wsm_type','<>',2)//2表示虚拟仓,虚拟仓不参加统计
  497. ->page($page,$size)
  498. ->leftJoin('warehouse_info whi','whi.wsm_code=gs.wsm_code AND whi.is_del=0')
  499. ->group("gs.wsm_code")
  500. ->field("gs.wsm_code,sum(wait_in_stock) wait_in_stock,sum(wait_out_stock) wait_out_stock,sum(usable_stock) usable_stock,sum(intra_stock) intra_stock,sum(warn_stock) warn_stock,sum(total_stock) total_stock")
  501. ->select()
  502. ->toArray();
  503. $data=[];
  504. foreach ($list as $key=>$value){
  505. $temp=[];
  506. if($value['wsm_code']!=""){
  507. $wsm = Db::name("warehouse_info")
  508. ->alias("a")
  509. ->leftJoin("business bus", "bus.companyNo=a.companyNo")
  510. ->leftJoin("supplier b","a.supplierNo=b.code")
  511. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  512. ->field("a.name as wsm_name,wsm_code,a.supplierNo,b.name supplierName,a.companyNo,bus.company")
  513. ->find();
  514. $good = Db::name("good_stock")
  515. ->alias("a")
  516. ->leftJoin("good c","c.spuCode=a.spuCode")
  517. ->where(["a.wsm_code"=>$value['wsm_code'],"a.is_del"=>0,"c.is_del"=>0])
  518. ->select()
  519. ->toArray();
  520. //商品单位和品牌
  521. $good_unit_s = Db::name("unit")->whereIn('id', array_column($good, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
  522. $brands = Db::name("brand")->whereIn('id', array_column($good, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
  523. foreach ($good as &$item_good){
  524. //规格信息
  525. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $item_good['spuCode'], "is_del" => 0])->select()->toArray();
  526. $speclist = [];
  527. if (!empty($spec)) {
  528. foreach ($spec as $val) {
  529. $tmp = [];
  530. $tmp['spec_id'] = $val['spec_id'];
  531. $tmp['spec_value_id'] = $val['spec_value_id'];
  532. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  533. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  534. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  535. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  536. $speclist[] = $tmp;
  537. }
  538. }
  539. $item_good['specinfo'] = $speclist;
  540. $item_good['unit'] = $good_unit_s[$item_good['good_unit']]??'';
  541. $item_good['brand_name'] = $brands[$item_good['brand_id']]??'';
  542. $item_good['can'] = made($item_good['cat_id'],[]);
  543. }
  544. }
  545. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  546. $temp['wsm_code']=$value['wsm_code'];
  547. $temp['supplier_code']=isset($wsm['supplierNo'])?$wsm['supplierNo']:"";
  548. $temp['supplier_name']=isset($wsm['supplierName'])?$wsm['supplierName']:"";
  549. $temp['company_no']=isset($wsm['companyNo'])?$wsm['companyNo']:"";
  550. $temp['company_name']=isset($wsm['company'])?$wsm['company']:"";
  551. $temp['usable_stock'] = $value['usable_stock'];
  552. $temp['wait_in_stock'] = $value['wait_in_stock'];
  553. $temp['wait_out_stock'] = $value['wait_out_stock'];
  554. $temp['intra_stock'] = $value['intra_stock'];
  555. $temp['total_stock'] = $value['total_stock'];
  556. // $temp['warn_stock'] = $value['warn_stock'];
  557. $temp['child']=isset($good)&&!empty($good) ? $good:[];
  558. $data[]=$temp;
  559. }
  560. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  561. }
  562. public function GetStockGod(){
  563. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  564. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  565. $condition = [["b.is_del","=",0],["c.usable_stock",">",0]];
  566. $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  567. if($type_code!==""){
  568. $condition[]=["b.spuCode","like","%{$type_code}%"];
  569. }
  570. $count = Db::name("good")->alias("b")
  571. ->join("good_stock c","c.spuCode = b.spuCode","left")
  572. ->where($condition)
  573. ->group("b.spuCode,b.good_name,b.good_unit,b.cat_id,b.craft_desc,b.addtime")
  574. ->count();
  575. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  576. $list = Db::name("good")
  577. ->alias("b")
  578. ->join("good_stock c","c.spuCode = b.spuCode","left")
  579. ->where($condition)
  580. ->field("b.spuCode,b.good_name,b.good_unit,b.brand_id,b.cat_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")
  581. ->page($page,$size)
  582. ->order("b.addtime desc")
  583. ->group("b.spuCode,b.good_name,b.good_unit,b.brand_id,b.cat_id,b.craft_desc,b.addtime")
  584. ->select()
  585. ->toArray();
  586. // echo Db::name("good_type")->getLastSql();
  587. $data=[];
  588. if($list) {
  589. //商品单位和品牌
  590. $good_unit_s = Db::name("unit")->whereIn('id', array_column($list, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
  591. $brands = Db::name("brand")->whereIn('id', array_column($list, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
  592. foreach ($list as $key => $value) {
  593. $temp = [];
  594. if ($value['spuCode'] != "") {
  595. $child = Db::name("good_stock")
  596. ->alias("a")
  597. ->join("warehouse_info b", "a.wsm_code=b.wsm_code", "left")
  598. ->join("business bus", "bus.companyNo=b.companyNo", "left")
  599. ->join("supplier s", "s.code=b.supplierNo", "left")
  600. ->where(['a.spuCode' => $value['spuCode'], "b.wsm_type" => 1, "a.is_del" => 0])
  601. ->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,b.supplierNo,s.name supplierName,b.companyNo,bus.company")
  602. ->select()
  603. ->toArray();
  604. }
  605. $temp['good_name'] = $value['good_name'];
  606. $temp['good_code'] = $value['spuCode'];
  607. $temp['type_code'] = '';
  608. // $unit = Db::name("unit")->where(['id' => $value['good_unit']])->find();
  609. $temp['unit'] =$good_unit_s[$value['spuCode']]??'';
  610. $temp['brand_name'] =$brands[$value['brand_id']]??'';
  611. $temp['sort_f'] = isset($value['cat_id']) ? made($value['cat_id']) : [];
  612. $temp['sort_f'] = implode('/', array_column($temp['sort_f'], 'name'));//由于这个字段原样在页面显示,所以在这里特意拼接成字符串
  613. $temp['attribute'] = $value['craft_desc'];
  614. $temp['addtime'] = $value['addtime'];
  615. $temp['usable_stock'] = isset($value['usable_stock']) ? $value['usable_stock'] : "";
  616. $temp['wait_in_stock'] = isset($value['wait_in_stock']) ? $value['wait_in_stock'] : "";
  617. $temp['wait_out_stock'] = isset($value['wait_out_stock']) ? $value['wait_out_stock'] : "";
  618. $temp['intra_stock'] = isset($value['intra_stock']) ? $value['intra_stock'] : "";
  619. $temp['total_stock'] = isset($value['total_stock']) ? $value['total_stock'] : "";
  620. // $temp['warn_stock'] = isset($value['warn_stock'])? $value['warn_stock']:"";
  621. $temp['child'] = isset($child) && !empty($child) ? $child : [];
  622. //规格信息
  623. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  624. $speclist = [];
  625. if (!empty($spec)) {
  626. foreach ($spec as $val) {
  627. $tmp = [];
  628. $tmp['spec_id'] = $val['spec_id'];
  629. $tmp['spec_value_id'] = $val['spec_value_id'];
  630. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  631. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  632. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  633. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  634. $speclist[] = $tmp;
  635. }
  636. }
  637. $temp['specinfo'] = $speclist;
  638. $data[] = $temp;
  639. }
  640. }
  641. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  642. }
  643. /**
  644. * @return \think\response\Json|void
  645. * @throws \think\db\exception\DataNotFoundException
  646. * @throws \think\db\exception\DbException
  647. * @throws \think\db\exception\ModelNotFoundException
  648. */
  649. public function Stat(){
  650. $condition =[["gs.is_del","=",0]];
  651. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  652. if($wsm_code!=""){
  653. //$condition["gs.wsm_code"] = $wsm_code;
  654. $condition[]=["gs.wsm_code","=",$wsm_code];
  655. }
  656. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  657. if($suplierNo!==""){
  658. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  659. $condition[]=["gs.wsm_code","in",$wsmcode];
  660. }
  661. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  662. if ($companyNo !== "") {
  663. // $where['khNo'] = $khNo;
  664. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  665. $condition[]=["gs.wsm_code","in",$wsmcode];
  666. }
  667. // $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  668. // if($type_code!=""){
  669. // $condition[] = ["gs.good_type_code","=",$type_code];
  670. // }
  671. $statlist = Db::name("good_stock")
  672. ->alias('gs')
  673. ->where($condition)
  674. ->where('whi.wsm_type','<>',2)//2表示虚拟仓,虚拟仓不参与
  675. ->leftJoin('warehouse_info whi','whi.wsm_code=gs.wsm_code AND whi.is_del=0')
  676. ->field("sum(gs.wait_in_stock) as wait_in_stock,sum(gs.wait_out_stock) as wait_out_stock ,sum(gs.usable_stock) as usable_stock,sum(gs.intra_stock) as intra_stock,sum(gs.usable_stock+gs.wait_out_stock) as total_stock,sum(gs.warn_stock) as warn_stock")
  677. ->find();
  678. return app_show(0,"获取成功",$statlist);
  679. }
  680. public function all(){
  681. $condtion=["a.is_del"=>0,"b.is_del"=>0];
  682. $wsmcode =isset($this->post['wsmcode']) &&$this->post['wsmcode'] !=="" ? trim($this->post['wsmcode']):"";
  683. if($wsmcode!=""){
  684. $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code");
  685. $condtion["b.type_code"] = $typecode;
  686. }
  687. $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  688. if($good_code!=""){
  689. $condtion['b.type_code'] = $good_code;
  690. }
  691. $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code'])
  692. :"";
  693. if($goodcode!=""){
  694. $condtion['a.good_code'] = $goodcode;
  695. }
  696. $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name'])
  697. :"";
  698. if($good_name!=""){
  699. $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'");
  700. }
  701. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  702. if($supplierNo!=""){
  703. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  704. if(empty($supplier)){
  705. return error_show(1004,"未找到供应商信息");
  706. }
  707. $condtion["a.gys_code"] = $supplierNo;
  708. }
  709. $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  710. ->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,
  711. 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")
  712. ->select();
  713. $data=[];
  714. foreach ($list as $key=>$value){
  715. $stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock");
  716. $value['usable_stock']=$stock;
  717. $supplier = Db::name("supplier")->where(["code"=>$value['gys_code']])->find();
  718. $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
  719. $data[]=$value;
  720. }
  721. return app_show(0,"获取成功",$data);
  722. }
  723. public function loglist(){
  724. $page = isset($this->post['page']) && $this->post['page']!==""? intval($this->post['page']) :"1";
  725. $size = isset($this->post['size']) && $this->post['size']!==""? intval($this->post['size']) :"10";
  726. $where=[];
  727. $wsm_code= isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  728. if($wsm_code!=""){
  729. $where[]=['b.wsm_code',"like","%$wsm_code%"];
  730. }
  731. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  732. if($supplierNo!=""){
  733. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  734. if(empty($supplier)){
  735. return error_show(1004,"未找到供应商信息");
  736. }
  737. $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"supplierNo"=>$supplierNo])->column("wsm_code");
  738. $where[]=['b.wsm_code',"in",$wsmcode];
  739. }
  740. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  741. if ($companyNo !== "") {
  742. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  743. $condition[]=["b.wsm_code","in",$wsmcode];
  744. }
  745. $count = Db::name("good_log")
  746. ->alias('a')
  747. ->join("good_stock b","b.id=a.id","left")
  748. ->where($where)
  749. ->count();
  750. $total = ceil($count/$size);
  751. $page = $total>=$page ? $page :$total;
  752. $list = Db::name("good_log")
  753. ->alias('a')
  754. ->join("good_stock b","b.id=a.stock_id","left")
  755. ->where($where)
  756. ->page($page,$size)
  757. ->order("a.addtime desc")
  758. ->field("a.good_log_code,a.action_name,a.type,a.stock_name,a.stock,a.action_type,b.spuCode,a.addtime,a.action_uid,b.wsm_code")
  759. ->select()
  760. ->toArray();
  761. $data=[];
  762. $action_uids = array_column($list, 'action_uid');
  763. $action_uids = array_unique($action_uids);
  764. $item = [];
  765. foreach ($action_uids as $action_uid) {
  766. $items = Db::name("depart_user")->where('uid', $action_uid)->column("itemid");
  767. foreach ($items as $it) {
  768. $item[$action_uid][] = implode('/', array_column(GetPart($it), 'name'));
  769. }
  770. }
  771. foreach ($list as $value){
  772. $wsm = Db::name("warehouse_info")
  773. ->alias("a")
  774. ->Join("supplier b","a.supplierNo=b.code","left")
  775. ->Join("business bus","bus.companyNo=a.companyNo","left")
  776. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  777. ->field("a.name as wsm_name,wsm_code,b.code,b.name,bus.company,bus.companyNo")
  778. ->find();
  779. $godd =Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  780. $value['good_name']=isset($godd['good_name'])? $godd['good_name']:"";
  781. $value['cat_id']=isset($godd['cat_id'])? $godd['cat_id']:"";
  782. $int = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  783. $value['wsm_name'] =$wsm['wsm_name'];
  784. $value['wsm_code'] =$wsm['wsm_code'];
  785. $value['code'] =$wsm['code'];
  786. $value['name'] =$wsm['name'];
  787. $value['action_type_cn'] =$this->acton[$value['action_type']];
  788. $value['item'] =$item[$value['action_uid']];
  789. $value['can'] =$int;
  790. $value['company'] =$wsm['company']??'';
  791. $value['companyNo'] =$wsm['companyNo']??'';
  792. $data[]=$value;
  793. }
  794. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  795. }
  796. public function goodlist(){
  797. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  798. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  799. $where =[["a.is_del","=",0],["b.exam_status","=",6],["b.is_del","=",0],["c.is_del","=",0],["c.status","=",1]];
  800. $paltcode = isset($this->post["platform_code"])&& $this->post["platform_code"]!=""? trim($this->post["platform_code"]):"";
  801. if($paltcode!=""){
  802. $where[]=["platform_code","=",$paltcode];
  803. }
  804. $companyNo = isset($this->post["companyNo"])&& $this->post["companyNo"]!=""? trim($this->post["companyNo"])
  805. :"";
  806. if($companyNo!=""){
  807. $where[]=["companyNo","like","%$companyNo%"];
  808. }
  809. $cat_id = isset($this->post["cat_id"])&& $this->post["cat_id"]!==""? intval($this->post["cat_id"]):"";
  810. if($cat_id!==""){
  811. $where[]=["cat_id","=",$cat_id];
  812. }
  813. $buy_num = isset($this->post["buy_num"])&& $this->post["buy_num"]!==""? intval($this->post["buy_num"]):"";
  814. if($buy_num!==""){
  815. $where[]=["min_num","<=",$buy_num];
  816. }
  817. $price = isset($this->post["price"])&& $this->post["price"]!==""? floatval($this->post["price"]):"";
  818. if($buy_num!==""){
  819. $where[]=["sale_price","<=",$price];
  820. }
  821. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->leftJoin("good_ladder c","b.skuCode=c.skuCode")
  822. ->where($where)->count();
  823. $total = ceil($count / $size);
  824. $page = $page >= $total ? $total : $page;
  825. $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
  826. ($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")
  827. ->order("b.addtime desc")
  828. ->select();
  829. $data=[];
  830. foreach ($list as $value){
  831. $value['cat_info']= made($value['cat_id'],[]);
  832. $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
  833. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
  834. $value['platform_code_en'] = isset($platform['platform_code']) ? $platform['platform_code']:"";
  835. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  836. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  837. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  838. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  839. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  840. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  841. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  842. $value['company'] = isset($company['company'])?$company['company']:"";
  843. $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
  844. $value['status']=$value['exam_status'];
  845. $data[]=$value;
  846. }
  847. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  848. }
  849. //根据价格区间,筛选符合条件的商品列表
  850. public function getGoodListByLadder()
  851. {
  852. //1.请求参数
  853. $param = $this->request->only([
  854. 'is_stock' => '',
  855. 'min_price' => 0,
  856. 'max_price' => 0,
  857. 'moq' => 0,
  858. 'cat_id' => 0,
  859. 'good_name' => '',
  860. 'skucode' => '',
  861. 'spucode' => '',
  862. 'start' => '',
  863. 'end' => '',
  864. 'good_type' => '',
  865. 'supplierNo' => '',
  866. 'companyNo' => '',
  867. 'creater' => '',
  868. 'createrid' => '',
  869. 'status' => '',
  870. 'platform_code' => '',
  871. 'plat_code' => '',
  872. 'exam_status' => '',
  873. 'brand_id' => 0,
  874. 'page' => 1,
  875. 'size' => 15
  876. ], 'post', 'trim');
  877. $where = $ladder_where = [];
  878. if ($param['min_price'] && $param['max_price']) {
  879. $skuCodes = Db::name('good_ladder')
  880. ->whereBetween('sale_price', [$param['min_price'], $param['max_price']])
  881. ->where(['is_del' => 0, 'status' => 1])
  882. ->group('skuCode')
  883. ->column('skuCode');
  884. $where[] = ['b.skuCode', 'in', $skuCodes];
  885. $ladder_where[] = ['sale_price', 'between', [$param['min_price'], $param['max_price']]];
  886. }
  887. if ($param['is_stock'] != '') $where[] = ['a.is_stock', '=', $param['is_stock']];
  888. if ($param['moq']) $where[] = ['a.moq', '>=', $param['moq']];
  889. if ($param['cat_id']) $where[] = ['a.cat_id', '=', $param['cat_id']];
  890. if ($param['good_name']) $where[] = ['a.good_name', 'like', '%' . $param['good_name'] . '%'];
  891. if ($param['skucode']) $where[] = ['b.skucode', 'like', '%' . $param['skucode'] . '%'];
  892. if ($param['spucode']) $where[] = ['b.spucode', 'like', '%' . $param['spucode'] . '%'];
  893. if ($param['start']) $where[] = ['a.addtime', '>=', date('Y-m-d H:i:s', strtotime($param['start']))];
  894. if ($param['end']) $where[] = ['a.addtime', '<', date('Y-m-d H:i:s', strtotime($param['end'] + 24 * 3600))];
  895. if ($param['good_type']!='') $where[] = ['a.good_type', '=', $param['good_type']];
  896. if ($param['supplierNo']) $where[] = ['a.supplierNo', '=', $param['supplierNo']];
  897. if ($param['companyNo']) $where[] = ['a.companyNo', 'like', '%' . $param['companyNo'] . '%'];
  898. if ($param['creater']) $where[] = ['a.creater', 'like', '%' . $param['creater'] . '%'];
  899. if ($param['createrid']) $where[] = ['a.createrid', '=', $param['createrid']];
  900. if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
  901. if ($param['platform_code']) $where[] = ['platform_code', '=', $param['platform_code']];
  902. if ($param['plat_code']) $where[] = ['b.plat_code', 'like', '%' . $param['plat_code'] . '%'];
  903. if ($param['exam_status'] != '') $where[] = ['b.exam_status', '=', $param['exam_status']];
  904. if ($param['brand_id']) $where[] = ['a.brand_id', '=', $param['brand_id']];
  905. //5.获取结果
  906. $count = Db::name('good')
  907. ->alias("a")
  908. // ->field("b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.*,b.addtime,b.updatetime,b.exam_status,gb.createrid purchase_id,gb.creater purchase,gl.min_num,gl.max_num")//成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  909. ->leftJoin("good_platform b", "a.spuCode=b.spuCode")
  910. ->leftJoin("good_basic gb", "gb.spuCode=a.spuCode")
  911. // ->leftJoin("good_ladder gl", "gl.skuCode=b.skuCode")
  912. ->where($where)
  913. ->where('b.exam_status', '=', 6)//6表示上线成功
  914. ->order("b.addtime desc")
  915. ->count('a.id');
  916. $list = Db::name('good')
  917. ->alias("a")
  918. ->field("b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.*,b.addtime,b.updatetime,b.exam_status,gb.createrid purchase_id,gb.creater purchase")//成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  919. ->leftJoin("good_platform b", "a.spuCode=b.spuCode")
  920. ->leftJoin("good_basic gb", "gb.spuCode=a.spuCode")
  921. // ->leftJoin("good_ladder gl", "gl.skuCode=b.skuCode")
  922. ->page($param['page'], $param['size'])
  923. ->where($where)
  924. ->where('b.exam_status', '=', 6)//6表示上线成功
  925. ->order("b.addtime desc")
  926. // ->fetchSql()
  927. ->select()
  928. ->toArray();
  929. // halt($list);
  930. //6.补充数据,照搬list方法
  931. $data = [];
  932. foreach ($list as $value) {
  933. $value['cat_info'] = made($value['cat_id'], []);
  934. $platform = Db::name("platform")->where(["id" => $value['platform_code']])->find();
  935. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name'] : "";
  936. $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en'] : "";
  937. $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  938. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name'] : "";
  939. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  940. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  941. $unit = Db::name("unit")->where(["id" => $value['good_unit']])->find();
  942. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : "";
  943. $company = Db::name("business")->where(["companyNo" => $value['companyNo']])->find();
  944. $value['company'] = isset($company['company']) ? $company['company'] : "";
  945. $value['stock_total'] = Db::name("good_stock")->where(['spuCode' => $value['spuCode'], "is_del" => 0])->sum("usable_stock");
  946. $value['status'] = $value['exam_status'];
  947. $value['exclusive'] = makeExcluse($value['is_exclusive']);
  948. $value['good_info_img'] = $value['good_info_img'];
  949. $value['good_img'] = $value['good_img'];
  950. $spec = Db::name("good_spec")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  951. $speclist = [];
  952. if (!empty($spec)) {
  953. foreach ($spec as $val) {
  954. $temp = [];
  955. $temp['spec_id'] = $val['spec_id'];
  956. $temp['spec_value_id'] = $val['spec_value_id'];
  957. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  958. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  959. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  960. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  961. $speclist[] = $temp;
  962. }
  963. }
  964. $value['specinfo'] = $speclist;
  965. $value['noble_name'] = isset($value['noble_metal']) && $value['noble_metal'] != 0 ? $this->noble[$value['noble_metal']] : "";
  966. //补充阶梯数据
  967. $ladder_info = Db::name('good_ladder')
  968. ->field('min_num,max_num,sale_price')
  969. ->where(['skuCode' => $value['skuCode']])
  970. ->where($ladder_where)
  971. ->order('min_num', 'asc')
  972. ->find();
  973. $value['min_num'] = isset($ladder_info['min_num']) ? $ladder_info['min_num'] : 0;
  974. $value['max_num'] = isset($ladder_info['max_num']) ? $ladder_info['max_num'] : 0;
  975. $value['sale_price'] = isset($ladder_info['sale_price']) ? $ladder_info['sale_price'] : 0;
  976. $data[] = $value;
  977. }
  978. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  979. }
  980. }