Good.php 76 KB

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