Good.php 53 KB

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