Good.php 66 KB

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