Good.php 63 KB

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