Good.php 56 KB

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