Good.php 55 KB

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