Good.php 54 KB

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