Good.php 55 KB

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