Good.php 56 KB

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