Good.php 76 KB

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