Good.php 75 KB

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