Good.php 74 KB

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