Good.php 52 KB

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