Good.php 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  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. public $noble=[];
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. $this->noble=\think\facade\Config::get("noble");
  17. $order=\think\facade\Config::get("order");
  18. $this->acton=$order['order_type'];
  19. }
  20. public function list(){
  21. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  22. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  23. $where =[["a.is_del","=",0]];
  24. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? trim($this->post['cat_id']):"";
  25. if($cat_id!==""){
  26. $where[]=['a.cat_id',"=",$cat_id];
  27. }
  28. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  29. if($good_name!==""){
  30. $where[]=['a.good_name',"like","%$good_name%"];
  31. }
  32. $skucode = isset($this->post['skucode']) && $this->post['skucode'] !=="" ? trim($this->post['skucode']):"";
  33. if($skucode!==""){
  34. $where [] = ['b.skucode',"like","%$skucode%"];
  35. }
  36. $spucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode']):"";
  37. if($spucode!==""){
  38. $where [] = ['b.spucode',"like","%$spucode%"];
  39. }
  40. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  41. if($start!==""){
  42. $where[]=['a.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  43. }
  44. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  45. if($end!==""){
  46. $where[]=['a.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  47. }
  48. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !=="" ? intval($this->post['is_stock'])
  49. :"";
  50. if($is_stock!==""){
  51. $where[]=['a.is_stock',"=",$is_stock];
  52. }
  53. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? intval($this->post['good_type'])
  54. :"";
  55. if($good_type!==""){
  56. $where[]=['a.good_type',"=",$good_type];
  57. }
  58. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  59. :"";
  60. if($supplierNo!==""){
  61. $where[]=['a.supplierNo',"=",$supplierNo];
  62. }
  63. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :"";
  64. if($companyNo!==""){
  65. $where[]=['a.companyNo',"like","%$companyNo%"];
  66. }
  67. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  68. if($creater!==""){
  69. $where[]=['a.creater',"like","%$creater%"];
  70. }
  71. $createrid = isset($this->post['createrid']) && $this->post['createrid'] !=="" ? intval($this->post['createrid']):"";
  72. if($createrid!==""){
  73. $where[]=['a.createrid',"=",$createrid];
  74. }
  75. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
  76. :"";
  77. if($status!==""){
  78. $where[]=['a.status',"=",$status];
  79. }
  80. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code'])
  81. :"";
  82. if($platform_code!==""){
  83. //$platform = Db::name("good_platform")->where(["platform_code"=>$platform_code,"is_del"=>0])->column
  84. //("spuCode");
  85. $where[]=["platform_code","=",$platform_code];
  86. }
  87. $plat_code = isset($this->post['plat_code']) && $this->post['plat_code'] !=="" ? trim($this->post['plat_code'])
  88. :"";
  89. if($plat_code!==""){
  90. $where[]=["b.plat_code","like","%$plat_code%"];
  91. }
  92. $exam_status = isset($this->post['exam_status']) && $this->post['exam_status'] !=="" ? intval($this->post['exam_status'])
  93. :"";
  94. if($exam_status!==""){
  95. $where[]=['b.exam_status',"=",$exam_status];
  96. }
  97. $brand_id = isset($this->post['brand_id']) && $this->post['brand_id'] !=="" ? intval($this->post['brand_id'])
  98. :"";
  99. if($brand_id!==""){
  100. $where[]=['a.brand_id',"=",$brand_id];
  101. }
  102. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where($where)
  103. ->count();
  104. $total = ceil($count / $size);
  105. $page = $page >= $total ? $total : $page;
  106. $list = Db::name('good')
  107. ->alias("a")
  108. ->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取个别名
  109. ->leftJoin("good_platform b","a.spuCode=b.spuCode")
  110. ->leftJoin("good_basic gb","gb.spuCode=a.spuCode")
  111. ->where($where)
  112. ->page($page,$size)
  113. ->order("b.addtime desc")
  114. ->select()
  115. ->toArray();
  116. $data=[];
  117. foreach ($list as $value){
  118. $value['cat_info']= made($value['cat_id'],[]);
  119. $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
  120. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
  121. $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en']:"";
  122. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  123. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  124. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  125. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  126. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  127. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  128. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  129. $value['company'] = isset($company['company'])?$company['company']:"";
  130. $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
  131. $value['status']=$value['exam_status'];
  132. $value['exclusive']=makeExcluse($value['is_exclusive']);
  133. $value['good_info_img']=$value['good_info_img'];
  134. $value['good_img']=$value['good_img'];
  135. $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
  136. $speclist=[];
  137. if(!empty($spec)){
  138. foreach ($spec as $val){
  139. $temp=[];
  140. $temp['spec_id']=$val['spec_id'];
  141. $temp['spec_value_id']=$val['spec_value_id'];
  142. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  143. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  144. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  145. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  146. $speclist[]=$temp;
  147. }
  148. }
  149. $value['specinfo']=$speclist;
  150. $value['noble_name']=isset($value['noble_metal'])&&$value['noble_metal']!=0?$this->noble[$value['noble_metal']] :"";
  151. $data[]=$value;
  152. }
  153. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  154. }
  155. public function info(){
  156. $skucode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
  157. if($skucode==""){
  158. return error_show(1005,"参数skuCode不能为空");
  159. }
  160. $good_platform = Db::name("good_platform")->where(['skuCode'=>$skucode,"is_del"=>0])->find();
  161. if($good_platform==false){
  162. return error_show(1004,"未找到商品数据");
  163. }
  164. $data = Db::name("good")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->find();
  165. if($data==false){
  166. return error_show(1004,"未找到商品数据");
  167. }
  168. $plat =Db::name("platform")->where(["id"=>$good_platform['platform_code']])->find();
  169. $data['skuCode']=$good_platform['skuCode'];
  170. $data['platform_code']=$good_platform['id'];
  171. $data['platform_code_en']=isset($plat['platform_code'])?$plat['platform_code']:"";
  172. $data['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  173. $data['online_reason']=$good_platform['online_reason'];
  174. $data['online_time']=$good_platform['online_time'];
  175. $data['online_remark']=$good_platform['online_remark'];
  176. $data['exam_status']=$good_platform['exam_status'];
  177. $data['is_online']=$good_platform['is_online'];
  178. $data['plat_code']=$good_platform['plat_code'];
  179. $data['exclusive']=makeExcluse($data['is_exclusive']);
  180. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  181. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  182. $data['cat_info'] = made($data['cat_id'],[]);
  183. $spec = Db::name("good_spec")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
  184. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  185. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  186. $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
  187. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  188. $data['company'] = isset($company['company'])?$company['company']:"";
  189. if($data['brand_id']!=0){
  190. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  191. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  192. }else{
  193. $data["brand_name"]="";
  194. $data["brand_id"]="";
  195. }
  196. $data['origin_place_cn']="";
  197. $data['delivery_place_cn']="";
  198. if($data['delivery_place']!==""){
  199. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  200. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['delivery_place']);
  201. $data['delivery_place_cn']=GetAddr(json_encode($place));
  202. }
  203. if($data['origin_place']!==""){
  204. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  205. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['origin_place']);
  206. $data['origin_place_cn']=GetAddr(json_encode($place));
  207. }
  208. $excluse = makeExcluse($data['is_exclusive']);
  209. $data['exclusive']=$excluse;
  210. $data["good_info_img"]=$data['good_info_img']!=""? $data['good_info_img']:[];
  211. $data["good_img"]=$data['good_img']!=""? $data['good_img']:[];
  212. $speclist=[];
  213. if(!empty($spec)){
  214. foreach ($spec as $value){
  215. $temp=[];
  216. $temp['id']=$value['id'];
  217. $temp['spuCode']=$value['spuCode'];
  218. $temp['spec_id']=$value['spec_id'];
  219. $temp['spec_value_id']=$value['spec_value_id'];
  220. $temp['is_del']=$value['is_del'];
  221. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  222. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  223. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  224. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  225. $speclist[]=$temp;
  226. }
  227. }
  228. $data["speclist"]=empty($speclist)?[]:$speclist;
  229. $ladder = Db::name("good_ladder")->where(['skuCode'=>$skucode,"is_del"=>0])->select()->toArray();
  230. $data["ladderlist"]=!empty($ladder)?$ladder:[];
  231. $nakelist = Db::name("good_nake")->where(['spuCode'=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
  232. // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  233. $cat_top_list = $data['cat_info'];
  234. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  235. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  236. $gold_price=0;
  237. if ($data['is_gold_price']==1 && $cat_top_id==6) {
  238. $gold_price = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->value('price', 0);
  239. }
  240. $data['gold_price'] =$gold_price;
  241. $nakearry=[];
  242. if(!empty($nakelist)){
  243. //实时金价
  244. foreach ($nakelist as $value){
  245. $value['sale_price'] =$value['nake_total'];
  246. //计算最终售价
  247. if ($data['is_gold_price']==1 && $cat_top_id==6) {
  248. //普通商品:直接用财务提交的售价字段;
  249. //贵金属( 商品重量* 最新金价 + 工艺费(财务定价提交的)* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)=商品库商品直接下单的售价
  250. $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']);
  251. }
  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.wait_out_stock+a.usable_stock) as 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['wait_out_stock']+$value['usable_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(usable_stock+wait_out_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. $item_good['total_stock'] =$item_good['usable_stock']+$item_good['wait_out_stock'];
  533. }
  534. }
  535. $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
  536. $temp['wsm_code']=$value['wsm_code'];
  537. $temp['supplier_code']=isset($wsm['supplierNo'])?$wsm['supplierNo']:"";
  538. $temp['supplier_name']=isset($wsm['supplierName'])?$wsm['supplierName']:"";
  539. $temp['company_no']=isset($wsm['companyNo'])?$wsm['companyNo']:"";
  540. $temp['company_name']=isset($wsm['company'])?$wsm['company']:"";
  541. $temp['usable_stock'] = $value['usable_stock'];
  542. $temp['wait_in_stock'] = $value['wait_in_stock'];
  543. $temp['wait_out_stock'] = $value['wait_out_stock'];
  544. $temp['intra_stock'] = $value['intra_stock'];
  545. $temp['total_stock'] = $value['usable_stock']+$value['wait_out_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],["a.wsm_type","<>",2]];
  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. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  560. if ($good_name !== "") {
  561. $condition[] = ["b.good_name", "like", "%{$good_name}%"];
  562. }
  563. $count = Db::name("good")->alias("b")
  564. ->join("good_stock c","c.spuCode = b.spuCode","left")
  565. ->leftJoin("warehouse_info a","a.wsm_code=c.wsm_code")
  566. ->where($condition)
  567. ->group("b.spuCode,b.good_name,b.good_unit,b.cat_id,b.craft_desc,b.addtime")
  568. ->count();
  569. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  570. $list = Db::name("good")
  571. ->alias("b")
  572. ->join("good_stock c","c.spuCode = b.spuCode","left")
  573. ->leftJoin("warehouse_info a","a.wsm_code=c.wsm_code")
  574. ->where($condition)
  575. ->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")
  576. ->page($page,$size)
  577. ->order("b.addtime desc")
  578. ->group("b.spuCode,b.good_name,b.good_unit,b.brand_id,b.cat_id,b.craft_desc,b.addtime")
  579. ->select()
  580. ->toArray();
  581. $data=[];
  582. if($list) {
  583. //商品单位和品牌
  584. $good_unit_s = Db::name("unit")->whereIn('id', array_column($list, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
  585. $brands = Db::name("brand")->whereIn('id', array_column($list, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
  586. foreach ($list as $key => $value) {
  587. $temp = [];
  588. if ($value['spuCode'] != "") {
  589. $child = Db::name("good_stock")
  590. ->alias("a")
  591. ->join("warehouse_info b", "a.wsm_code=b.wsm_code", "left")
  592. ->join("business bus", "bus.companyNo=b.companyNo", "left")
  593. ->join("supplier s", "s.code=b.supplierNo", "left")
  594. ->where(['a.spuCode' => $value['spuCode'], "a.is_del" => 0])
  595. ->where("b.wsm_type","<>",2)
  596. ->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")
  597. ->select()
  598. ->toArray();
  599. // echo Db::name("good_stock")->getLastSql();
  600. }
  601. $temp['good_name'] = $value['good_name'];
  602. $temp['good_code'] = $value['spuCode'];
  603. $temp['type_code'] = '';
  604. // $unit = Db::name("unit")->where(['id' => $value['good_unit']])->find();
  605. $temp['unit'] =$good_unit_s[$value['good_unit']]??'';
  606. $temp['brand_name'] =$brands[$value['brand_id']]??'';
  607. $temp['sort_f'] = isset($value['cat_id']) ? made($value['cat_id']) : [];
  608. $temp['sort_f'] = implode('/', array_column($temp['sort_f'], 'name'));//由于这个字段原样在页面显示,所以在这里特意拼接成字符串
  609. $temp['attribute'] = $value['craft_desc'];
  610. $temp['addtime'] = $value['addtime'];
  611. $temp['usable_stock'] = isset($value['usable_stock']) ? $value['usable_stock'] : "";
  612. $temp['wait_in_stock'] = isset($value['wait_in_stock']) ? $value['wait_in_stock'] : "";
  613. $temp['wait_out_stock'] = isset($value['wait_out_stock']) ? $value['wait_out_stock'] : "";
  614. $temp['intra_stock'] = isset($value['intra_stock']) ? $value['intra_stock'] : "";
  615. $temp['total_stock'] = intval($value['wait_out_stock'])+intval($value['usable_stock']);
  616. // $temp['warn_stock'] = isset($value['warn_stock'])? $value['warn_stock']:"";
  617. $temp['child'] = isset($child) && !empty($child) ? $child : [];
  618. //规格信息
  619. $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  620. $speclist = [];
  621. if (!empty($spec)) {
  622. foreach ($spec as $val) {
  623. $tmp = [];
  624. $tmp['spec_id'] = $val['spec_id'];
  625. $tmp['spec_value_id'] = $val['spec_value_id'];
  626. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  627. $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  628. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  629. $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  630. $speclist[] = $tmp;
  631. }
  632. }
  633. $temp['specinfo'] = $speclist;
  634. $data[] = $temp;
  635. }
  636. }
  637. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  638. }
  639. /**
  640. * @return \think\response\Json|void
  641. * @throws \think\db\exception\DataNotFoundException
  642. * @throws \think\db\exception\DbException
  643. * @throws \think\db\exception\ModelNotFoundException
  644. */
  645. public function Stat(){
  646. $condition =[["gs.is_del","=",0]];
  647. $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  648. if($wsm_code!=""){
  649. //$condition["gs.wsm_code"] = $wsm_code;
  650. $condition[]=["gs.wsm_code","=",$wsm_code];
  651. }
  652. $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  653. if($suplierNo!==""){
  654. $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
  655. $condition[]=["gs.wsm_code","in",$wsmcode];
  656. }
  657. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  658. if ($companyNo !== "") {
  659. // $where['khNo'] = $khNo;
  660. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  661. $condition[]=["gs.wsm_code","in",$wsmcode];
  662. }
  663. // $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  664. // if($type_code!=""){
  665. // $condition[] = ["gs.good_type_code","=",$type_code];
  666. // }
  667. $statlist = Db::name("good_stock")
  668. ->alias('gs')
  669. ->where($condition)
  670. ->where('whi.wsm_type','<>',2)//2表示虚拟仓,虚拟仓不参与
  671. ->leftJoin('warehouse_info whi','whi.wsm_code=gs.wsm_code AND whi.is_del=0')
  672. ->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")
  673. ->find();
  674. return app_show(0,"获取成功",$statlist);
  675. }
  676. public function all(){
  677. $condtion=["a.is_del"=>0,"b.is_del"=>0];
  678. $wsmcode =isset($this->post['wsmcode']) &&$this->post['wsmcode'] !=="" ? trim($this->post['wsmcode']):"";
  679. if($wsmcode!=""){
  680. $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code");
  681. $condtion["b.type_code"] = $typecode;
  682. }
  683. $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  684. if($good_code!=""){
  685. $condtion['b.type_code'] = $good_code;
  686. }
  687. $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code'])
  688. :"";
  689. if($goodcode!=""){
  690. $condtion['a.good_code'] = $goodcode;
  691. }
  692. $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name'])
  693. :"";
  694. if($good_name!=""){
  695. $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'");
  696. }
  697. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  698. if($supplierNo!=""){
  699. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  700. if(empty($supplier)){
  701. return error_show(1004,"未找到供应商信息");
  702. }
  703. $condtion["a.gys_code"] = $supplierNo;
  704. }
  705. $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  706. ->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,
  707. 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")
  708. ->select();
  709. $data=[];
  710. foreach ($list as $key=>$value){
  711. $stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock");
  712. $value['usable_stock']=$stock;
  713. $supplier = Db::name("supplier")->where(["code"=>$value['gys_code']])->find();
  714. $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
  715. $data[]=$value;
  716. }
  717. return app_show(0,"获取成功",$data);
  718. }
  719. public function loglist(){
  720. $page = isset($this->post['page']) && $this->post['page']!==""? intval($this->post['page']) :"1";
  721. $size = isset($this->post['size']) && $this->post['size']!==""? intval($this->post['size']) :"10";
  722. $where=[];
  723. $wsm_code= isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  724. if($wsm_code!=""){
  725. $where[]=['b.wsm_code',"like","%$wsm_code%"];
  726. }
  727. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  728. if($supplierNo!=""){
  729. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  730. if(empty($supplier)){
  731. return error_show(1004,"未找到供应商信息");
  732. }
  733. $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"supplierNo"=>$supplierNo])->column("wsm_code");
  734. $where[]=['b.wsm_code',"in",$wsmcode];
  735. }
  736. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  737. if ($companyNo !== "") {
  738. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  739. $condition[]=["b.wsm_code","in",$wsmcode];
  740. }
  741. $count = Db::name("good_log")
  742. ->alias('a')
  743. ->join("good_stock b","b.id=a.id","left")
  744. ->where($where)
  745. ->count();
  746. $total = ceil($count/$size);
  747. $page = $total>=$page ? $page :$total;
  748. $list = Db::name("good_log")
  749. ->alias('a')
  750. ->join("good_stock b","b.id=a.stock_id","left")
  751. ->where($where)
  752. ->page($page,$size)
  753. ->order("a.addtime desc")
  754. ->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")
  755. ->select()
  756. ->toArray();
  757. $data=[];
  758. $action_uids = array_column($list, 'action_uid');
  759. $action_uids = array_unique($action_uids);
  760. $item = [];
  761. foreach ($action_uids as $action_uid) {
  762. $items = Db::name("depart_user")->where('uid', $action_uid)->column("itemid");
  763. foreach ($items as $it) {
  764. $item[$action_uid][] = implode('/', array_column(GetPart($it), 'name'));
  765. }
  766. }
  767. foreach ($list as $value){
  768. $wsm = Db::name("warehouse_info")
  769. ->alias("a")
  770. ->Join("supplier b","a.supplierNo=b.code","left")
  771. ->Join("business bus","bus.companyNo=a.companyNo","left")
  772. ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
  773. ->field("a.name as wsm_name,wsm_code,b.code,b.name,bus.company,bus.companyNo")
  774. ->find();
  775. $godd =Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  776. $value['good_name']=isset($godd['good_name'])? $godd['good_name']:"";
  777. $value['cat_id']=isset($godd['cat_id'])? $godd['cat_id']:"";
  778. $int = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  779. $value['wsm_name'] =$wsm['wsm_name'];
  780. $value['wsm_code'] =$wsm['wsm_code'];
  781. $value['code'] =$wsm['code'];
  782. $value['name'] =$wsm['name'];
  783. $value['action_type_cn'] =$this->acton[$value['action_type']];
  784. $value['item'] =$item[$value['action_uid']];
  785. $value['can'] =$int;
  786. $value['company'] =$wsm['company']??'';
  787. $value['companyNo'] =$wsm['companyNo']??'';
  788. $data[]=$value;
  789. }
  790. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  791. }
  792. public function goodlist(){
  793. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  794. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  795. $where =[["a.is_del","=",0],["b.exam_status","=",6],["b.is_del","=",0],["c.is_del","=",0],["c.status","=",1]];
  796. $paltcode = isset($this->post["platform_code"])&& $this->post["platform_code"]!=""? trim($this->post["platform_code"]):"";
  797. if($paltcode!=""){
  798. $where[]=["platform_code","=",$paltcode];
  799. }
  800. $companyNo = isset($this->post["companyNo"])&& $this->post["companyNo"]!=""? trim($this->post["companyNo"])
  801. :"";
  802. if($companyNo!=""){
  803. $where[]=["companyNo","like","%$companyNo%"];
  804. }
  805. $cat_id = isset($this->post["cat_id"])&& $this->post["cat_id"]!==""? intval($this->post["cat_id"]):"";
  806. if($cat_id!==""){
  807. $where[]=["cat_id","=",$cat_id];
  808. }
  809. $buy_num = isset($this->post["buy_num"])&& $this->post["buy_num"]!==""? intval($this->post["buy_num"]):"";
  810. if($buy_num!==""){
  811. $where[]=["min_num","<=",$buy_num];
  812. }
  813. $price = isset($this->post["price"])&& $this->post["price"]!==""? floatval($this->post["price"]):"";
  814. if($buy_num!==""){
  815. $where[]=["sale_price","<=",$price];
  816. }
  817. $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->leftJoin("good_ladder c","b.skuCode=c.skuCode")
  818. ->where($where)->count();
  819. $total = ceil($count / $size);
  820. $page = $page >= $total ? $total : $page;
  821. $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
  822. ($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")
  823. ->order("b.addtime desc")
  824. ->select();
  825. $data=[];
  826. foreach ($list as $value){
  827. $value['cat_info']= made($value['cat_id'],[]);
  828. $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
  829. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
  830. $value['platform_code_en'] = isset($platform['platform_code']) ? $platform['platform_code']:"";
  831. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  832. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  833. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  834. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  835. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  836. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  837. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  838. $value['company'] = isset($company['company'])?$company['company']:"";
  839. $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
  840. $value['status']=$value['exam_status'];
  841. $data[]=$value;
  842. }
  843. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  844. }
  845. //根据价格区间,筛选符合条件的商品列表
  846. public function getGoodListByLadder()
  847. {
  848. //1.请求参数
  849. $param = $this->request->only([
  850. 'good_type' => '',
  851. 'start' => '',
  852. 'end' => '',
  853. 'is_stock' => '',
  854. 'cat_id' => 0,
  855. 'brand_id' => 0,
  856. 'min_price' => 0,
  857. 'max_price' => 0,
  858. 'moq' => 0,//最低起订量?
  859. 'good_name' => '',
  860. 'skucode' => '',
  861. 'spucode' => '',
  862. 'companyNo' => '',//业务企业编号
  863. 'plat_code' => '',//平台商品编号
  864. 'creater' => '',//创建人
  865. 'platform_code' => '',
  866. 'supplierNo' => '',
  867. 'page' => 1,
  868. 'size' => 15
  869. ], 'post', 'trim');
  870. $where = [];
  871. if (!empty($param['good_type'])) $where[] = ['gb.good_type', '=', $param['good_type']];
  872. if (!empty($param['start'])) $where[] = ['gl.addtime', '>=', $param['start']];
  873. if (!empty($param['end'])) $where[] = ['gl.addtime', '<=', $param['end'] . ' 23:59:59'];
  874. if (!empty($param['is_stock'])) $where[] = ['gb.is_stock', '=', $param['is_stock']];
  875. if (!empty($param['cat_id'])) $where[] = ['gb.cat_id', '=', $param['cat_id']];
  876. if (!empty($param['brand_id'])) $where[] = ['gb.brand_id', '=', $param['brand_id']];
  877. if (!empty($param['min_price']) && !empty($param['max_price'])) $where[] = ['gl.sale_price', 'between', [$param['min_price'], $param['max_price']]];
  878. if (!empty($param['moq'])) $where[] = ['gl.min_num', '>=', $param['moq']];
  879. if (!empty($param['good_name'])) $where[] = ['gb.good_name', 'like', '%' . $param['good_name'] . '%'];
  880. if (!empty($param['skucode'])) $where[] = ['gl.skuCode', 'like', '%' . $param['skucode'] . '%'];
  881. if (!empty($param['spucode'])) $where[] = ['gp.spuCode', 'like', '%' . $param['spucode'] . '%'];
  882. if (!empty($param['companyNo'])) $where[] = ['gb.companyNo', 'like', '%' . $param['companyNo'], '%'];
  883. if (!empty($param['plat_code'])) $where[] = ['gp.plat_code', 'like', '%' . $param['plat_code'], '%'];
  884. if (!empty($param['creater'])) $where[] = ['gb.creater', 'like', '%' . $param['creater'], '%'];
  885. if (!empty($param['platform_code'])) $where[] = ['gp.platform_code', 'like', '%' . $param['platform_code'], '%'];
  886. // if (!empty($param['supplierNo'])) $where[] = ['supplierNo', 'like', '%'.$param['supplierNo'],'%'];
  887. //5.获取结果
  888. $count = Db::name('good_ladder')
  889. ->alias('gl')
  890. ->field('gl.id,gl.skuCode,gp.spuCode,p.platform_name,gb.good_thumb_img,gb.good_name,gb.cat_id,gb.good_type,gb.is_stock,gb.brand_id,gp.plat_code,gl.min_num,gl.sale_price,gb.creater purchase,gb.creater,gb.companyNo')
  891. ->leftJoin('good_platform gp', 'gp.skuCode=gl.skuCode AND gp.is_del=0')
  892. ->leftJoin('platform p', 'p.id=gp.platform_code AND p.is_del=0')
  893. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  894. ->where($where)
  895. ->count('gl.id');
  896. $list = Db::name('good_ladder')
  897. ->alias('gl')
  898. ->field('gl.id,gl.skuCode,gp.spuCode,p.platform_name,gb.good_thumb_img,gb.good_name,gb.cat_id,gb.good_type,gb.is_stock,gb.brand_id,gp.plat_code,gl.min_num moq,gl.sale_price,gb.creater purchase,gb.creater,gb.companyNo')
  899. ->leftJoin('good_platform gp', 'gp.skuCode=gl.skuCode AND gp.is_del=0')
  900. ->leftJoin('platform p', 'p.id=gp.platform_code AND p.is_del=0')
  901. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  902. ->where($where)
  903. ->page($param['page'], $param['size'])
  904. ->order(['gl.skuCode' => 'asc', 'gl.addtime' => 'desc', 'gl.id' => 'desc'])
  905. ->select()
  906. ->toArray();
  907. //6.补充数据,照搬list方法
  908. $all_brand = Db::name('brand')
  909. ->where('is_del', 0)
  910. ->whereIn('id', array_column($list, 'brand_id'))
  911. ->column('brand_name', 'id');
  912. $all_company = Db::name('business')
  913. ->where('is_del', 0)
  914. ->whereIn('companyNo', array_column($list, 'companyNo'))
  915. ->column('company', 'companyNo');
  916. foreach ($list as &$value) {
  917. $value['cat_info'] = made($value['cat_id'], []);
  918. $value['brand_name'] = isset($all_brand[$value['brand_id']]) ? $all_brand[$value['brand_id']] : '';
  919. $value['company'] = isset($all_company[$value['companyNo']]) ? $all_company[$value['companyNo']] : '';
  920. $value['stock_total'] = Db::name("good_stock")
  921. ->where(['spuCode' => $value['spuCode'], "is_del" => 0])
  922. ->sum("usable_stock");
  923. }
  924. return app_show(0, "获取成功", ['list' => $list, 'count' => $count]);
  925. }
  926. }