123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\DataGroup as DataGroupModel;
- use app\admin\model\GoodCombind;use app\admin\model\GoodLog;
- use app\admin\model\GoodStock;use app\admin\model\GoodTax;use app\txx\model\ActGoodurl;use app\txx\model\YzGood;
- use think\App;
- use think\db\Raw;
- use think\facade\Db;
- use think\facade\Validate;
- //线上商品
- class Good extends Base
- {
- private $acton=[];
- public $noble=[];
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->noble=\think\facade\Config::get("noble");
- $order=\think\facade\Config::get("order");
- $this->acton=$order['order_type'];
- }
- public function list(){
- $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
- $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
- $where =[["a.is_del","=",0]];
- $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? trim($this->post['cat_id']):"";
- if($cat_id!==""){
- $where[]=['a.cat_id',"=",$cat_id];
- }
- $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
- if($good_name!==""){
- $where[]=['a.good_name',"like","%$good_name%"];
- }
- $skucode = isset($this->post['skucode']) && $this->post['skucode'] !=="" ? trim($this->post['skucode']):"";
- if($skucode!==""){
- $where [] = ['b.skucode',"like","%$skucode%"];
- }
- $spucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode']):"";
- if($spucode!==""){
- $where [] = ['b.spucode',"like","%$spucode%"];
- }
- $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
- if($start!==""){
- $where[]=['b.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
- }
- $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
- if($end!==""){
- $where[]=['b.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
- }
- $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !=="" ? intval($this->post['is_stock']) :"";
- if($is_stock!==""){
- $where[]=['a.is_stock',"=",$is_stock];
- }
- $create_source = isset($this->post['create_source']) && $this->post['create_source'] !=='' ? intval($this->post['create_source']) :'';
- if($create_source!==''){
- $where[]=['a.create_source','=',$create_source];
- }
- $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? intval($this->post['good_type']) :"";
- if($good_type!==""){
- $where[]=['a.good_type',"=",$good_type];
- }
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
- if($supplierNo!==""){
- $where[]=['a.supplierNo',"like","%$supplierNo%"];
- }
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :"";
- if($companyNo!==""){
- $where[]=['a.companyNo',"like","%$companyNo%"];
- }
- $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
- if($creater!==""){
- $where[]=['a.creater',"like","%$creater%"];
- }
- $online_creater = isset($this->post['online_creater']) && $this->post['online_creater'] !=="" ? trim($this->post['online_creater'])
- :"";
- if($online_creater!==""){
- $where[]=['b.creater',"like","%$online_creater%"];
- }
- $createrid = isset($this->post['createrid']) && $this->post['createrid'] !=="" ? intval($this->post['createrid']):"";
- if($createrid!==""){
- $where[]=['a.createrid',"=",$createrid];
- }
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
- if($status!==""){
- $where[]=['a.status',"=",$status];
- }
- $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :"";
- if($platform_code!==""){
- //$platform = Db::name("good_platform")->where(["platform_code"=>$platform_code,"is_del"=>0])->column
- //("spuCode");
- $where[]=["b.platform_code","=",$platform_code];
- }
- $plat_code = isset($this->post['plat_code']) && $this->post['plat_code'] !=="" ? trim($this->post['plat_code']) :"";
- if($plat_code!==""){
- $where[]=["b.plat_code","like","%$plat_code%"];
- }
- $exam_status = isset($this->post['exam_status']) && $this->post['exam_status'] !=="" ? intval($this->post['exam_status']) :"";
- if($exam_status!==""){
- $where[]=['b.exam_status',"=",$exam_status];
- }
- $brand_id = isset($this->post['brand_id']) && $this->post['brand_id'] !=="" ? intval($this->post['brand_id']) :"";
- if($brand_id!==""){
- $where[]=['a.brand_id',"=",$brand_id];
- }
- $is_compliance = isset($this->post['is_compliance']) && $this->post['is_compliance'] !=="" ? intval($this->post['is_compliance']) :"";
- if($is_compliance!==""){
- $where[]=['b.is_compliance',"=",$is_compliance];
- }
- $supplier = isset($this->post['supplier_name']) && $this->post['supplier_name'] !=="" ? trim($this->post['supplier_name']) :"";
- if($supplier!==""){
- $where[]=['a.supplierName',"like","%$supplier%"];
- }
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
- if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
- $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != "" ? trim($this->post['relaComNo']) : "";
- if ($relaComNo != "") $where[] = ['a.companyNo|a.supplierNo', '=', $relaComNo];
- $count = Db::name('good')
- ->alias("a")
- ->rightJoin("good_platform b","a.spuCode=b.spuCode")
- ->leftJoin("platform p","p.id=b.platform_code")
- ->where('p.platform_type',0)//只筛选非对接平台的商品
- ->where($where)
- ->count('a.id');
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('good')
- ->alias("a")
- ->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,
- a.good_info_img,a.good_thumb_img,b.createrid,a.is_exclusive,a.brand_id,a.supplierNo,a.supplierName,a.create_source,
- a.good_unit,a.noble_metal,a.companyNo,a.companyName,a.spuCode,a.good_type,b.creater,b.addtime,b.updatetime,
- b.exam_status,a.createrid purchase_id,a.creater purchase,a.is_stock,p.platform_name,b.is_compliance,b.compliance_remark")
- //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
- ->rightJoin("good_platform b","a.spuCode=b.spuCode")
- ->leftJoin("platform p","p.id=b.platform_code")
- ->where('p.platform_type',0)//只筛选非对接平台的商品
- ->where($where)
- ->page($page,$size)
- ->order("b.addtime desc")
- ->select()
- ->toArray();
- $all_createrid = array_column($list,'createrid');
- $item = get_company_name_by_uid($all_createrid);
- $brand=Db::name('brand')
- ->where(['id'=>array_column($list,'brand_id')])
- ->column('brand_name','id');
- $unit = Db::name('unit')
- ->where(['id'=>array_column($list,'good_unit')])
- ->column('unit','id');
- // $userCommon = \app\admin\common\User::getIns();
- // $names = $userCommon->handle('getCodeAndName',['code'=>array_merge(array_column($list,'companyNo'),
- // array_column($list,'supplierNo'))]);
- $data=[];
- foreach ($list as $value){
- $value['cat_info']= made($value['cat_id']);
- // $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
- // $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
- // $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en']:"";
- // $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
- // $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
- // $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
- $value["brand_name"]=$brand[$value['brand_id']]??'';//isset($brand['brand_name'])?$brand['brand_name']:"";
- // $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
- $value['unit'] =$unit[$value['good_unit']]??'';//isset($unit['unit'])?$unit['unit']:"";
- // $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
- $value['company'] = $value['companyName'];//$names['data'][$value['companyNo']]??'';//isset($company['company'])?$company['company']:"";
- // $value['supplierName'] = $names['data'][$value['supplierNo']]??'';//isset($company['company'])//?$company['company']:"";
- $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
- $value['status']=$value['exam_status'];
- $value['exclusive']=makeExcluse($value['is_exclusive']);
- // $value['good_info_img']=$value['good_info_img'];
- // $value['good_img']=$value['good_img'];
- $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
- $speclist=[];
- if(!empty($spec)){
- foreach ($spec as $val){
- $temp=[];
- $temp['spec_id']=$val['spec_id'];
- $temp['spec_value_id']=$val['spec_value_id'];
- $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
- $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
- $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
- $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
- $speclist[]=$temp;
- }
- }
- $value['specinfo']=$speclist;
- $value['noble_name']=isset($value['noble_metal'])&&$value['noble_metal']!=0?$this->noble[$value['noble_metal']] :"";
- $value['company_name'] = $item[$value['createrid']]??'';
- //是否具有编辑权限
- // $value['is_allow_update'] = 0;
- // if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
- $data[]=$value;
- }
- return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
- }
- //获取跟有赞对接的平台所属的商品上线信息
- public function listByYz()
- {
- $param = $this->request->only([
- 'page' => 1,
- 'size' => 15,
- 'cat_id' => '',
- 'good_name' => '',
- 'skucode' => '',
- 'spucode' => '',
- 'start' => '',
- 'end' => '',
- 'is_stock' => '',
- 'good_type' => '',
- 'supplierNo' => '',
- 'companyNo' => '',
- 'creater' => '',
- 'online_creater' => '',
- 'createrid' => '',
- 'status' => '',
- 'platform_code' => '',
- 'plat_code' => '',
- 'exam_status' => '',
- 'brand_id' => '',
- 'company_name' => '',
- 'relaComNo' => '',
- ], 'post', 'trim');
- $where = [["b.is_del", "=", 0],['a.is_del', '=', 0]];
- if ($param['cat_id'] !== "") $where[] = ['a.cat_id', "=", $param['cat_id']];
- if ($param['good_name'] !== "") $where[] = ['a.good_name', 'like', '%' . $param['good_name'] . '%'];
- if ($param['skucode'] !== '') $where [] = ['b.skucode', 'like', '%' . $param['skucode'] . '%'];
- if ($param['spucode'] !== '') $where [] = ['b.spucode', 'like', '%' . $param['spucode'] . '%'];
- if ($param['start'] !== '') $where[] = ['b.addtime', '>=', date('Y-m-d H:i:s', strtotime($param['start']))];
- if ($param['end'] !== "") $where[] = ['b.addtime', "<", date('Y-m-d H:i:s', strtotime($param['end']) + 24 * 3600)];
- if ($param['is_stock'] !== "") $where[] = ['a.is_stock', "=", $param['is_stock']];
- if ($param['good_type'] !== "") $where[] = ['a.good_type', "=", $param['good_type']];
- if ($param['supplierNo'] !== "") $where[] = ['a.supplierNo', "=", $param['supplierNo']];
- if ($param['companyNo'] !== "") $where[] = ['a.companyNo', "like", '%' . $param['companyNo'] . '%'];
- if ($param['online_creater'] !== '') $where[] = ['b.creater', "like", '%' . $param['online_creater'] . '%'];
- if ($param['creater'] !== '') $where[] = ['a.creater', "like", '%' . $param['creater'] . '%'];
- if ($param['createrid'] !== '') $where[] = ['a.createrid', "=", $param['createrid']];
- if ($param['status'] !== '') $where[] = ['a.status', '=', $param['status']];
- if ($param['platform_code'] !== "") $where[] = ["b.platform_id", '=', $param['platform_code']];
- if ($param['plat_code'] !== '') $where[] = ["b.plat_code", "like", '%' . $param['plat_code'] . '%'];
- if ($param['exam_status'] !== '') $where[] = ['b.exam_status', "=", $param['exam_status']];
- if ($param['brand_id'] !== "") $where[] = ['a.brand_id', "=", $param['brand_id']];
- if ($param['company_name'] !== '') $where[] = ["a.createrid", 'in', get_company_item_user_by_name($param['company_name'])];
- if($param['relaComNo'] !== '') $where[]=['a.companyNo|a.supplierNo','=', $param['relaComNo']];
- $count = Db::name('platform_youzan')
- ->alias("b")
- ->leftJoin("good_basic a", "a.spuCode=b.spuCode")
- ->where($where)
- ->count();
- $total = ceil($count / $param['size']);
- $param['page'] = $param['page'] >= $total ? $total : $param['page'];
- $list = Db::name('platform_youzan')
- ->alias("b")
- ->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取个别名
- ->leftJoin("good_basic a", "a.spuCode=b.spuCode")
- ->where($where)
- ->page($param['page'], $param['size'])
- ->order("b.addtime desc")
- ->select()
- ->toArray();
- $all_createrid = array_column($list,'createrid');
- $item = get_company_name_by_uid($all_createrid);
- //取回所有的详情链接字段
- $all_skuCode = array_column($list,'skuCode');
- $detail_url_skuCode = YzGood::where(['item_no'=>$all_skuCode,'is_del'=>0])
- ->column('detail_url','item_no');
- $brand = Db::name('brand')
- ->where(['id'=>array_column($list,'brand_id')])
- ->column('brand_name','id');
- $unit = Db::name('unit')
- ->where(['id'=>array_column($list,'good_unit')])
- ->column('unit','id');
- $platform = Db::name('platform')
- ->where(['id'=>array_column($list,'platform_code')])
- ->column('platform_name','id');
- $userCommon = \app\admin\common\User::getIns();
- $names = $userCommon->handle('getCodeAndName',['code'=>array_merge(array_column($list,'companyNo'),array_column($list,'supplierNo'))]);
- $data = [];
- $tmp_cat = [];
- foreach ($list as $value) {
- if(!isset($tmp_cat[$value['cat_id']])) $tmp_cat[$value['cat_id']] = made($value['cat_id'], []);
- $value['cat_info'] = $tmp_cat[$value['cat_id']];
- // $platform = Db::name("platform")->field('id,platform_name')->where(["id" => $value['platform_code']])->find();
- $value['platform_name'] = $platform[$value['platform_code']]??'';//isset($platform['platform_name']) ? $platform['platform_name'] : "";
- $value['platform_code_en'] = "";
- // $supplier = Db::name("supplier")->field('id,name')->where(["code" => $value['supplierNo']])->find();
- $value['supplier_name'] = $names['data'][$value['supplierNo']]??'';//isset($supplier['name']) ? $supplier['name'] : "";
- // $brand = Db::name("brand")->field('id,brand_name')->where(["id" => $value['brand_id']])->find();
- $value["brand_name"] = $brand[$value['brand_id']]??'';//isset($brand['brand_name']) ? $brand['brand_name'] : "";
- // $unit = Db::name("unit")->field('id,unit')->where(["id" => $value['good_unit']])->find();
- $value['unit'] = $unit[$value['good_unit']]??'';//isset($unit['unit']) ? $unit['unit'] : "";
- $value['company'] = $names['data'][$value['companyNo']]??'';//isset($company['company']) ? $company['company'] : "";
- $value['stock_total'] = Db::name("good_stock")->where(['spuCode' => $value['spuCode'], "is_del" => 0])->sum("usable_stock");
- $value['status'] = $value['exam_status'];
- $value['exclusive'] = makeExcluse($value['is_exclusive']);
- $value['is_act_url'] =ActGoodurl::where(["act_good_id"=>$value["platform_youzan_id"],"is_del"=>0])->value("act_good_url",'');
- $spec = Db::name("good_spec")
- ->where(["spuCode" => $value['spuCode'], "is_del" => 0])
- ->select()
- ->toArray();
- $speclist = [];
- if (!empty($spec)) {
- foreach ($spec as $val) {
- $temp = [];
- $temp['spec_id'] = $val['spec_id'];
- $temp['spec_value_id'] = $val['spec_value_id'];
- $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
- $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
- $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
- $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
- $speclist[] = $temp;
- }
- }
- $value['specinfo'] = $speclist;
- $value['noble_name'] = isset($value['noble_metal']) && $value['noble_metal'] != 0 ? $this->noble[$value['noble_metal']] : "";
- $value['company_name'] = $item[$value['createrid']]??'';
- $taxInfo=GoodTax::with(['tax'])->where(['spuCode'=>$value['spuCode']])->findOrEmpty();
- $value['tax_id'] = $taxInfo['tax_id']??'';
- $value['tax_name'] = $taxInfo['cat_name']??'';
- $value['tax_short_name'] =$taxInfo['short_name']??'';
- $value['tax_code'] =$taxInfo['merge_code']??'';
- $value['tax']=$taxInfo['tax']??'';
- $value['inv_good_name']=$taxInfo['inv_good_name']??'';
- //是否具有编辑权限
- $value['is_allow_update'] = 0;
- // if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
- //补充商品详情链接字段
- $value['detail_url'] = $detail_url_skuCode[$value['skuCode']]??'';
- $data[] = $value;
- }
- return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
- }
- public function info(){
- $skucode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
- if($skucode==""){
- return error_show(1005,"参数skuCode不能为空");
- }
- $good_platform = Db::name("good_platform")->where(['skuCode'=>$skucode,"is_del"=>0])->find();
- if($good_platform==false){
- return error_show(1004,"未找到商品数据");
- }
- $data = Db::name("good")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->find();
- if($data==false){
- return error_show(1004,"未找到商品数据");
- }
- $plat =Db::name("platform")->where(["id"=>$good_platform['platform_code']])->find();
- $data['skuCode']=$good_platform['skuCode'];
- $data['market_url']=$good_platform['market_url'];
- $data['is_fixed']=$good_platform['is_fixed'];
- $data['platform_id']=$good_platform['platform_code'];
- $data['platform_code_en']=isset($plat['platform_code'])?$plat['platform_code']:"";
- $data['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
- $data['online_reason']=$good_platform['online_reason'];
- $data['online_time']=$good_platform['online_time'];
- $data['online_remark']=$good_platform['online_remark'];
- $data['exam_status']=$good_platform['exam_status'];
- $data['is_online']=$good_platform['is_online'];
- $data['plat_code']=$good_platform['plat_code'];
- $data['createrid']=$good_platform['createrid']??'';
- $data['creater']=$good_platform['creater']??'';
- $data['exclusive']=makeExcluse($data['is_exclusive']);
- $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
- $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
- $data['cat_info'] = made($data['cat_id'],[]);
- $spec = Db::name("good_spec")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
- $userCommon = \app\admin\common\User::getIns();
- $names = $userCommon->handle('getCodeAndName',['code'=>[$data['supplierNo'],$data['companyNo']]]);
- $supplier = $userCommon->handle('sInfo',['code'=>$data['supplierNo']]);
- $data['supplierName'] = $names['data'][$data['supplierNo']]??'';//isset($supplier['name'])?$supplier['name']:"";
- $data['company'] = $names['data'][$data['companyNo']]??'';//isset($company['company'])?$company['company']:"";
- $data['tax_info']=GoodTax::with(['Tax','OutTax',"CgdTax"])->where(['spuCode'=>$good_platform['spuCode']])->findOrEmpty();
- $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
- $data['combind_list']=[];
- $data['wsm_list']=[];
- $data['is_combind_child']=true;
- if($data['is_combind']==1){
- $data['combind_list'] = (new GoodCombind())->where(['spuCode'=>$good_platform['spuCode'],'is_del'=>0])->select()->toArray();
- foreach ($data['combind_list'] as &$item){
- $item['stock'] =bcmul($item['child_num'],$data['usable_stock']);
- $taxInfo=GoodTax::with(['Tax','OutTax','CgdTax'])->where(['spuCode'=>$item['childCode']])->findOrEmpty();
- $item['tax_info'] = $taxInfo;
- }
- $data['wsm_list']=(new GoodStock())->withJoin(['wsminfo'] , 'left')
- ->where(['spuCode'=>$good_platform['spuCode'] , 'wsm_type'=>[2 , 5]])
- ->column('good_stock.id stock_id,name,good_stock.wsm_code,usable_stock');
- }else{
- $isCombind= (new GoodCombind())->where(['childCode'=>$good_platform['spuCode'],'is_del'=>0])->findOrEmpty();
- $data['is_combind_child']=$isCombind->isEmpty();
- }
-
- if($data['brand_id']!=0){
- $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
- $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
- }else{
- $data["brand_name"]="";
- $data["brand_id"]="";
- }
- $data['origin_place_cn']="";
- $data['delivery_place_cn']="";
- if($data['delivery_place']!==""){
- $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
- list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['delivery_place']);
- $data['delivery_place_cn']=GetAddr(json_encode($place));
- }
- if($data['origin_place']!==""){
- $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
- list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$data['origin_place']);
- $data['origin_place_cn']=GetAddr(json_encode($place));
- }
- $excluse = makeExcluse($data['is_exclusive']);
- $data['exclusive']=$excluse;
- $data["good_info_img"]=$data['good_info_img']!=""? $data['good_info_img']:[];
- $data["good_img"]=$data['good_img']!=""? $data['good_img']:[];
- $speclist=[];
- if(!empty($spec)){
- foreach ($spec as $value){
- $temp=[];
- $temp['id']=$value['id'];
- $temp['spuCode']=$value['spuCode'];
- $temp['spec_id']=$value['spec_id'];
- $temp['spec_value_id']=$value['spec_value_id'];
- $temp['is_del']=$value['is_del'];
- $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
- $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
- $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
- $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
- $speclist[]=$temp;
- }
- }
- $data["speclist"]=empty($speclist)?[]:$speclist;
- $ladder = Db::name("good_ladder")->where(['skuCode'=>$skucode,"is_del"=>0])->select()->toArray();
- $data["ladderlist"]=!empty($ladder)?$ladder:[];
- $nakelist = Db::name("good_nake")->where(['spuCode'=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
- // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
- $cat_top_list = $data['cat_info'];
- $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
- // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
- $gold_price=0;
- if ($data['is_gold_price']==1 && $cat_top_id==6) {
- $gold_price = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->value('price', 0);
- }
- $data['gold_price'] =$gold_price;
- $nakearry=[];
- if(!empty($nakelist)){
- //实时金价
- foreach ($nakelist as $value){
- $value['sale_price'] =$value['nake_total'];
- //计算最终售价
- if ($data['is_gold_price']==1 && $cat_top_id==6) {
- //普通商品:直接用财务提交的售价字段;
- //贵金属( 商品重量* 最新金价 + 工艺费(财务定价提交的)* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)=商品库商品直接下单的售价
- $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']);
- }
- $nakearry[] = $value;
- }
- }
- $proof =Db::name("good_proof")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
- $data['proof'] = isset($proof)&&$proof!=false? $proof:[];
- $data["nakelist"]=$nakearry;
- $data['sale_price'] = 0;
- if($data['create_source']==1){
- $data['sale_price'] = Db::name('sale')->where(['good_code'=>$good_platform['spuCode'],'order_type'=>3])
- ->value('sale_price',0);
- }
- //补充采购员字段
- //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
- $temp_basic_info = Db::name('good_basic')
- ->field('id,createrid purchase_id,creater purchase')
- ->where(['spuCode' => $data['spuCode'], 'is_del' => 0])
- ->find();
- $data['good_createrid'] = $data['purchase_id'] = $temp_basic_info['purchase_id'] ?? 0;
- $data['good_creater'] = $data['purchase'] = $temp_basic_info['purchase'] ?? '';
- $data['cgderid'] = $supplier['data']['personid'] ?? 0;
- $data['cgder'] = $supplier['data']['person'] ?? '';
- return app_show(0, "获取成功", $data);
- }
- public function SetWarn(){
- $condition=["is_del"=>0];
- $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
- if($wsm_code!=""){
- $condition["wsm_code"] = $wsm_code;
- }else{
- return error_show(1004,"参数wsm_code 不能为空");
- }
- // $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
- // if($type_code!=""){
- // $condition["good_type_code"] = $type_code;
- // }else{
- // return error_show(1004,"参数type_code 不能为空");
- // }
- $good= Db::name("good_stock")->where($condition)->find();
- if(empty($good)){
- return error_show(1005,"未找到数据");
- }
- $warn_stock = isset($this->post['warn_stock']) &&$this->post['warn_stock'] !=="" ? intval($this->post['warn_stock']):"";
- if($warn_stock===""){
- return error_show(1005,"参数warn_stock 不能为空");
- }
- $good['warn_stock'] = $warn_stock;
- $good['updatetime'] = date("Y-m-d H:i:s");
- $up= Db::name("good_stock")->save($good);
- if($up){
- //商品变动日志表,good_log_code字段存储仓库编码
- $data = ['good_log_code' => $wsm_code, "stock_id" => $good['id'], "type" => 1, 'stock' => $warn_stock, "stock_name" => "warn_stock"];
- GoodLog::LogAdd($this->post['token'],$data,'setwarn');
- return app_show(0,"预警库存更新成功");
- }else{
- return error_show(1005,"预警库存更新失败");
- }
- }
- public function SetStatus(){
- $id = isset($this->post['id']) &&$this->post['id'] !=="" ? intval($this->post['id']):"";
- if($id===""){
- return error_show(1005,"参数id 不能为空");
- }
- $good= Db::name("good_type")->where(["id"=>$id,"is_del"=>0])->find();
- if(empty($good)){
- return error_show(1005,"未找到数据");
- }
- $good['status'] = $good['status']==1?0 :1;
- $good['updatetime'] = date("Y-m-d H:i:s");
- $msg = $good['status']==1?"下架" :"上架";
- $up= Db::name("good_type")->save($good);
- return $up ? app_show(0,"商品{$msg}成功"): error_show(1005,"商品{$msg}失败");
- }
- public function GetStock(){
- $condition = [["a.is_del","=",0],['a.is_stock','=',1]];
- $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
- if($type_code!==""){
- $condition[]=["a.spuCode","=",$type_code];
- }
- $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
- :"";
- if($wsm_code!==""){
- //$condition["a.wsm_code"]=$wsm_code;
- $condition[]=["a.wsm_code","=",$wsm_code];
- }
- $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
- :"";
- if($suplierNo!==""){
- $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
- $condition[]=["a.wsm_code","in",$wsmcode];
- }
- $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")
- ->where($condition)
- ->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();
- if(empty($list)){
- return error_show(1004,"未找到数据");
- }
- return app_show(0,"获取成功",$list);
- }
- //库存统计 区间统计
- public function GetStockBet(){
- $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
- $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
- $condition = [["is_del","=",0]];
- $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
- if($type_code!==""){
- $condition[]=["spuCode","like","%{$type_code}%"];
- }
- $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
- :"";
- if($wsm_code!==""){
- $condition[]=["wsm_code","=",$wsm_code];
- }
- $suplierNo = isset($this->post['suplierNo']) &&$this->post['suplierNo'] !=="" ? trim($this->post['suplierNo']):"";
- if($suplierNo!==""){
- $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
- $condition[]=["wsm_code","in",$wsmcode];
- }
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
- if ($companyNo !== "") {
- $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
- $condition[]=["wsm_code","in",$wsmcode];
- }
- $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
- if($relaComNo!=""){
- $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$relaComNo,"is_del"=>0])->column("wsm_code");
- $condition[]=["wsm_code","in",$wsmcode];
- }
- $start = isset($this->post['start']) &&$this->post['start'] !=="" ? $this->post['start']:"";
- $end = isset($this->post['end']) &&$this->post['end'] !=="" ? $this->post['end']:"";
- if($start!=""){
- $condition[]=["addtime",">=",$start];
- }
- if($end!=""){
- $condition[]=["addtime","<=",$end];
- }
- $count = Db::name("good_stock")->where($condition)->count();
- $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
- $list = Db::name("good_stock")->where($condition)->page($page,$size)->order("addtime desc")->select();
- $data=[];
- $userCommon = \app\admin\common\User::getIns();
- foreach ($list as $key=>$value){
- $temp=[];
- if($value['wsm_code']!=""){
- $wsm = Db::name("warehouse_info")
- ->alias("a")
- // ->leftJoin("supplier b","a.supplierNo=b.code")
- // ->leftJoin("business bus","a.companyNo=bus.companyNo")
- ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
- ->field("a.name as wsm_name,wsm_code,a.supplierNo,a.companyNo")
- ->find();
- $names = $userCommon->handle('getCodeAndName',['code'=>[$wsm['supplierNo'],$wsm['companyNo']]]);
- $wsm['supplierName'] = $names['data'][$wsm['supplierNo']]??'';
- $wsm['company'] = $names['data'][$wsm['companyNo']]??'';
- }
- $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
- $temp['wsm_code']=$value['wsm_code'];
- $temp['supplier_code']=isset($wsm['supplierNo'])?$wsm['supplierNo']:"";
- $temp['supplier_name']=isset($wsm['supplierName'])?$wsm['supplierName']:"";
- $temp['company_no']=isset($wsm['companyNo'])?$wsm['companyNo']:"";
- $temp['company_name']=isset($wsm['company'])?$wsm['company']:"";
- if($value['spuCode']!=""){
- $good=Db::name("good_basic")
- ->alias('g')
- ->field('g.*,b.brand_name,u.unit')
- ->where(["g.spuCode"=>$value['spuCode'],"g.is_del"=>0])
- ->leftJoin('brand b','b.id=g.brand_id')
- ->leftJoin('unit u','u.id=g.good_unit')
- ->find();
- if (empty($good)) {
- $good = Db::name("good_zixun")
- ->alias('g')
- ->field('g.*,b.brand_name,u.unit')
- ->where(["g.spuCode" => $value['spuCode'], "g.is_del" => 0])
- ->leftJoin('brand b', 'b.id=g.brand_id')
- ->leftJoin('unit u', 'u.id=g.good_unit')
- ->find();
- $speclist =json_decode($good['specinfo'],true);
- }else{
- //规格信息
- $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
- $speclist = [];
- if (!empty($spec)) {
- foreach ($spec as $val) {
- $tmp = [];
- $tmp['spec_id'] = $val['spec_id'];
- $tmp['spec_value_id'] = $val['spec_value_id'];
- $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
- $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
- $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
- $tmp['spec_value_name'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
- $speclist[] = $tmp;
- }
- }
- }
- $temp['specinfo'] = $speclist;
- }
- $temp['good_code']=isset($good['spuCode'])?$good['spuCode']:"";
- // $temp['type_code']=isset($good['type_code'])?$good['type_code']:"";
- $temp['good_name']=isset($good['good_name'])?$good['good_name']:"";
- $temp['unit']=isset($good['unit'])?$good['unit']:"";
- $temp['brand_name']=isset($good['brand_name'])?$good['brand_name']:"";
- // $temp['attribute']=isset($good['attribute'])?$good['attribute']:"";
- $temp['sort_f']=isset($good['cat_id'])?$good['cat_id']:"";
- $temp['cat_info']=isset($good['cat_id'])?made($good['cat_id']):"";
- $temp['usable_stock'] = $value['usable_stock'];
- $temp['wait_in_stock'] = $value['wait_in_stock'];
- $temp['wait_out_stock'] = $value['wait_out_stock'];
- $temp['intra_stock'] = $value['intra_stock'];
- $temp['total_stock'] = $value['wait_out_stock']+$value['usable_stock'];
- $temp['warn_stock'] = $value['warn_stock'];
- $temp['id'] = $value['id'];
- $temp['out_total'] =0;
- $temp['in_total'] = 0;
- $temp['addtime'] = $value['addtime'];
- $data[]=$temp;
- }
- return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
- }
- //库存统计 仓库维度
- public function GetStockWsm(){
- $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
- $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
- $condition = [["gs.is_del","=",0]];
- $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
- if($wsm_code!==""){
- $condition[]=["gs.wsm_code","=",$wsm_code];
- }
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
- if ($companyNo !== "") {
- $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
- $condition[]=["gs.wsm_code","in",$wsmcode];
- }
- $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
- if($relaComNo!=""){
- $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$relaComNo,"is_del"=>0])->column("wsm_code");
- $condition[]=["gs.wsm_code","in",$wsmcode];
- }
- $build= Db::name("good_stock")
- ->alias('gs')
- ->where($condition)
- ->where('whi.wsm_type','<>',2)//2表示虚拟仓,虚拟仓不参加统计
- ->leftJoin('warehouse_info whi','whi.wsm_code=gs.wsm_code AND whi.is_del=0')
- ->group("gs.wsm_code")
- ->field("gs.wsm_code")
- ->buildSql();
- $count = Db::table($build." a")->count();
- $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
- $list = Db::name("good_stock")
- ->alias('gs')
- ->where($condition)
- ->where('whi.wsm_type','<>',2)//2表示虚拟仓,虚拟仓不参加统计
- ->page($page,$size)
- ->leftJoin('warehouse_info whi','whi.wsm_code=gs.wsm_code AND whi.is_del=0')
- ->group("gs.wsm_code")
- ->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")
- ->select()
- ->toArray();
- $warehouse_info = Db::name("warehouse_info")
- ->alias("a")
- ->where(['a.wsm_code'=>array_column($list,'wsm_code'),"a.is_del"=>0])
- ->column("a.name as wsm_name,wsm_code,a.supplierNo,a.supplierName,a.companyNo,a.companyName,a
- .contactor_name",'a.wsm_code');
- // ->find();
- $persionArr = get_personid_by_supplierNo(array_unique(array_column($warehouse_info,'supplierNo')),'person');
- $data=[];
- foreach ($list as $key=>$value){
- $temp=[];
- $temp['wsm_name'] = isset($warehouse_info[$value['wsm_code']]['wsm_name'])?$warehouse_info[$value['wsm_code']]['wsm_name']:"";
- $temp['wsm_code']=$value['wsm_code'];
- $temp['supplier_code']=isset($warehouse_info[$value['wsm_code']]['supplierNo'])?$warehouse_info[$value['wsm_code']]['supplierNo']:"";
- $temp['supplier_name']=isset($warehouse_info[$value['wsm_code']]['supplierName'])?$warehouse_info[$value['wsm_code']]['supplierName']:"";
- $temp['company_no']=isset($warehouse_info[$value['wsm_code']]['companyNo'])?$warehouse_info[$value['wsm_code']]['companyNo']:"";
- $temp['company_name']=isset($warehouse_info[$value['wsm_code']]['companyName'])?$warehouse_info[$value['wsm_code']]['companyName']:"";
- $temp['contactor_name']=isset($warehouse_info[$value['wsm_code']]['contactor_name'])?$warehouse_info[$value['wsm_code']]['contactor_name']:"";
- $temp['person']=$persionArr[$warehouse_info[$value['wsm_code']]['supplierNo']]??"";
- $temp['usable_stock'] = $value['usable_stock'];
- $temp['wait_in_stock'] = $value['wait_in_stock'];
- $temp['wait_out_stock'] = $value['wait_out_stock'];
- $temp['intra_stock'] = $value['intra_stock'];
- $temp['total_stock'] = $value['usable_stock']+$value['wait_out_stock'] ;
- // $temp['child']=isset($good)&&!empty($good) ? $good:[];
- $data[]=$temp;
- }
- return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
- }
- //库存统计 仓库维度 明细
- public function GetStockWsmChild()
- {
- $wsm_code = $this->request->post('wsm_code', '', 'trim');
- $good = Db::name("good_stock")
- ->alias("a")
- ->leftJoin("good_basic c", "c.spuCode=a.spuCode")
- ->where(["a.wsm_code" => $wsm_code, "a.is_del" => 0, "c.is_del" => 0])
- ->select()
- ->toArray();
- // $names = $userCommon->handle('getCodeAndName', [$wsm['supplierNo'], $wsm['companyNo']]);
- // $wsm['supplierName'] = $names['data'][$wsm['supplierNo']] ?? '';
- // $wsm['company'] = $names['data'][$wsm['companyNo']] ?? '';
- //商品单位和品牌
- $good_unit_s = Db::name("unit")
- ->whereIn('id', array_column($good, 'good_unit'))
- ->where('is_del', 0)
- ->column('unit', 'id');
- $brands = Db::name("brand")
- ->whereIn('id', array_column($good, 'brand_id'))
- ->where('is_del', 0)
- ->column('brand_name', 'id');
- foreach ($good as &$item_good) {
- //规格信息
- $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $item_good['spuCode'], "is_del" => 0])->select()->toArray();
- $speclist = [];
- if (!empty($spec)) {
- foreach ($spec as $val) {
- $tmp = [];
- $tmp['spec_id'] = $val['spec_id'];
- $tmp['spec_value_id'] = $val['spec_value_id'];
- $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
- $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
- $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
- $tmp['spec_value_name'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
- $speclist[] = $tmp;
- }
- }
- $item_good['specinfo'] = $speclist;
- $item_good['unit'] = $good_unit_s[$item_good['good_unit']] ?? '';
- $item_good['brand_name'] = $brands[$item_good['brand_id']] ?? '';
- $item_good['can'] = made($item_good['cat_id'], []);
- $item_good['total_stock'] = $item_good['usable_stock'] + $item_good['wait_out_stock'];
- }
- return json_show(0, '获取成功', $good);
- }
- //库存统计 商品维度
- public function GetStockGod(){
- $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
- $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
- $condition = [["b.is_del", "=", 0], ["a.wsm_type", "<>", 2],['b.is_stock','=',1]];//库存为0的也要显示出来
- $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
- if($type_code!==""){
- $condition[]=["b.spuCode","like","%{$type_code}%"];
- }
- $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
- if ($good_name !== "") {
- $condition[] = ["b.good_name", "like", "%{$good_name}%"];
- }
- $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
- if($relaComNo!="") $condition[]=['b.companyNo','=', $relaComNo];
-
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo']!="" ? trim($this->post['supplierNo']):"";
- if($supplierNo!=="") $condition[]=['b.supplierNo','=', $supplierNo];
- $isZero=isset($this->post['isZero']) && $this->post['isZero']!='' ? intval($this->post['isZero']):0;
- if($isZero!==0) $condition[]=['c.wait_in_stock|c.wait_out_stock|c.usable_stock|c.intra_stock','<>',
- 0];
- $count = Db::name("good_basic")
- ->alias("b")
- ->join("good_stock c","c.spuCode = b.spuCode","left")
- ->leftJoin("warehouse_info a","a.wsm_code=c.wsm_code")
- ->where($condition)
- ->group("b.spuCode,b.good_name,b.good_unit,b.cat_id,b.craft_desc,b.addtime")
- ->count();
- $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
- $list = Db::name("good_basic")
- ->alias("b")
- ->join("good_stock c","c.spuCode = b.spuCode","left")
- ->leftJoin("warehouse_info a","a.wsm_code=c.wsm_code")
- ->where($condition)
- ->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")
- ->page($page,$size)
- ->order("b.addtime desc")
- ->group("b.spuCode,b.good_name,b.good_unit,b.brand_id,b.cat_id,b.craft_desc,b.addtime")
- ->select()
- ->toArray();
- $data=[];
- if($list) {
- //商品单位和品牌
- $good_unit_s = Db::name("unit")->whereIn('id', array_column($list, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
- $brands = Db::name("brand")->whereIn('id', array_column($list, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
- $userCommon = \app\admin\common\User::getIns();
- foreach ($list as $key => $value) {
- $temp = [];
- if ($value['spuCode'] != "") {
- $child = Db::name("good_stock")
- ->alias("a")
- ->join("warehouse_info b", "a.wsm_code=b.wsm_code", "left")
- ->where(['a.spuCode' => $value['spuCode'], "a.is_del" => 0])
- ->where("b.wsm_type","<>",2)
- ->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")
- ->select()
- ->toArray();
- foreach ($child as &$vvv){
- $names = $userCommon->handle('getCodeAndName',['code'=>[$vvv['supplierNo'],$vvv['companyNo']]]);
- $person = get_personid_by_supplierNo([$vvv['supplierNo']],'person');
- $vvv['person'] =$person[$vvv['supplierNo']]??"";
- $vvv['supplierName'] = $names['data'][$vvv['supplierNo']]??'';
- $vvv['company'] = $names['data'][$vvv['companyNo']]??'';
- }
- // echo Db::name("good_stock")->getLastSql();
- }
- $temp['good_name'] = $value['good_name'];
- $temp['good_code'] = $value['spuCode'];
- $temp['type_code'] = '';
- // $unit = Db::name("unit")->where(['id' => $value['good_unit']])->find();
- $temp['unit'] =$good_unit_s[$value['good_unit']]??'';
- $temp['brand_name'] =$brands[$value['brand_id']]??'';
- $temp['sort_f'] = isset($value['cat_id']) ? made($value['cat_id']) : [];
- $temp['sort_f'] = implode('/', array_column($temp['sort_f'], 'name'));//由于这个字段原样在页面显示,所以在这里特意拼接成字符串
- $temp['attribute'] = $value['craft_desc'];
- $temp['addtime'] = $value['addtime'];
- $temp['usable_stock'] = isset($value['usable_stock']) ? $value['usable_stock'] : "";
- $temp['wait_in_stock'] = isset($value['wait_in_stock']) ? $value['wait_in_stock'] : "";
- $temp['wait_out_stock'] = isset($value['wait_out_stock']) ? $value['wait_out_stock'] : "";
- $temp['intra_stock'] = isset($value['intra_stock']) ? $value['intra_stock'] : "";
- $temp['total_stock'] = intval($value['wait_out_stock'])+intval($value['usable_stock']);
- // $temp['warn_stock'] = isset($value['warn_stock'])? $value['warn_stock']:"";
- $temp['child'] = isset($child) && !empty($child) ? $child : [];
- //规格信息
- $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
- $speclist = [];
- if (!empty($spec)) {
- foreach ($spec as $val) {
- $tmp = [];
- $tmp['spec_id'] = $val['spec_id'];
- $tmp['spec_value_id'] = $val['spec_value_id'];
- $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
- $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
- $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
- $tmp['spec_value_name'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
- $speclist[] = $tmp;
- }
- }
- $temp['specinfo'] = $speclist;
- $data[] = $temp;
- }
- }
- return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function Stat(){
- $condition =[["gs.is_del","=",0]];
- $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
- if($wsm_code!=""){
- //$condition["gs.wsm_code"] = $wsm_code;
- $condition[]=["gs.wsm_code","=",$wsm_code];
- }
- $supplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
- if($supplierNo!=="") $condition[]=["whi.supplierNo","=",$supplierNo];
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
- if ($companyNo !== "") {
- // $where['khNo'] = $khNo;
- $wsmcode = Db::name("warehouse_info")->where(['companyNo' => $companyNo, "is_del" => 0])->column("wsm_code");
- $condition[] = ["gs.wsm_code", "in", $wsmcode];
- }
- $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
- if($relaComNo!="") {
- $wsmcode = Db::name("warehouse_info")
- ->where(['companyNo'=>$relaComNo,"is_del"=>0])
- ->column("wsm_code");
- $condition[]=["gs.wsm_code","in",$wsmcode];
- }
- $good_name = trim($this->post['good_name'] ?? '');
- if ($good_name !== '') $condition[] = ['c.good_name', 'like', '%' . $good_name . '%'];
- $spuCode = trim($this->post['spuCode'] ?? '');
- if ($spuCode !== '') $condition[] = ['gs.spuCode', 'like', '%' . $spuCode . '%'];
- $is_stock = trim($this->post['is_stock'] ?? '');
- if ($is_stock !== '') $condition[] = ['c.is_stock', '=', $is_stock];
- // $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
- // if($type_code!=""){
- // $condition[] = ["gs.good_type_code","=",$type_code];
- // }
- $statlist = Db::name("good_stock")
- ->alias('gs')
- ->where($condition)
- ->where('whi.wsm_type','<>',2)//2表示虚拟仓,虚拟仓不参与
- ->leftJoin('warehouse_info whi','whi.wsm_code=gs.wsm_code AND whi.is_del=0')
- ->leftJoin('good_basic c','c.spuCode=gs.spuCode AND c.is_del=0')
- ->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")
- ->findOrEmpty();
- return app_show(0,"获取成功",$statlist);
- }
- //废弃接口
- public function all(){
- $condtion=["a.is_del"=>0,"b.is_del"=>0];
- $wsmcode =isset($this->post['wsmcode']) &&$this->post['wsmcode'] !=="" ? trim($this->post['wsmcode']):"";
- if($wsmcode!=""){
- $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code");
- $condtion["b.type_code"] = $typecode;
- }
- $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
- if($good_code!=""){
- $condtion['b.type_code'] = $good_code;
- }
- $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code'])
- :"";
- if($goodcode!=""){
- $condtion['a.good_code'] = $goodcode;
- }
- $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name'])
- :"";
- if($good_name!=""){
- $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'");
- }
- $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
- if($supplierNo!=""){
- // $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
- // if(empty($supplier)){
- // return error_show(1004,"未找到供应商信息");
- // }
- $condtion["a.gys_code"] = $supplierNo;
- }
- $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
- ->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,
- 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")
- ->select();
- $data=[];
- foreach ($list as $key=>$value){
- $stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock");
- $value['usable_stock']=$stock;
- //废弃
- $supplier = Db::name("supplier")->where(["code"=>$value['gys_code']])->find();//废弃
- $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
- $data[]=$value;
- }
- return app_show(0,"获取成功",$data);
- }
- //库存概况
- public function loglist(){
- $param = $this->request->filter('trim')->only(['wsm_code'=>'','supplierNo'=>'','companyNo'=>'','is_stock'=>'','good_name'=>'','spuCode'=>'','page'=>1,'size'=>10,'relaComNo'=>''],'post');
- $where=[];
- if($param['wsm_code']!="") $where[]=['b.wsm_code',"like","%".$param['wsm_code']."%"];
- // $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
- if($param['supplierNo']!=""){
- $where[]=['c.supplierNo',"=",$param['supplierNo']];
- }
- // $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
- if ($param['companyNo'] !== "") {
- $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$param['companyNo'],"is_del"=>0])->column("wsm_code");
- $where[]=["b.wsm_code","in",$wsmcode];
- }
- if ($param['relaComNo'] != '') {
- $wsmcode = Db::name("warehouse_info")
- ->where(['companyNo' => $param['relaComNo'], "is_del" => 0])
- ->column("wsm_code");
- $where[] = ["b.wsm_code", "in", $wsmcode];
- }
- if($param['is_stock']!="") $where[]=['c.is_stock','=',$param['is_stock']];
- if($param['good_name']!="") $where[]=['c.good_name','like','%'.$param['good_name'].'%'];
- if($param['spuCode']!="") $where[]=['b.spuCode','like','%'.$param['spuCode'].'%'];
- $count = Db::name("good_log")
- ->alias('a')
- ->leftJoin("good_stock b","b.id=a.stock_id")
- ->leftJoin('good c','c.spuCode=b.spuCode')
- ->where($where)
- ->count();
- $total = ceil($count/$param['size']);
- $page = $total>=$param['page'] ? $param['page'] :$total;
- $list = Db::name("good_log")
- ->alias('a')
- ->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")
- ->leftJoin('good_stock b','b.id=a.stock_id')
- ->leftJoin('good c','c.spuCode=b.spuCode')
- ->where($where)
- ->page($page,$param['size'])
- ->order("a.addtime desc")
- ->select()
- ->toArray();
- // $data=[];
- $action_uids = array_column($list, 'action_uid');
- $action_uids = array_unique($action_uids);
- $item = get_company_name_by_uid($action_uids);
- // $item = [];
- // foreach ($action_uids as $action_uid) {
- // $items = Db::name("depart_user")->where('uid', $action_uid)->column("itemid");
- // foreach ($items as $it) {
- // $item[$action_uid][] = implode('/', array_column(GetPart($it), 'name'));
- // }
- // }
- $userCommon = \app\admin\common\User::getIns();
- $wsmcode = Db::name("warehouse_info")
- ->alias("a")
- ->where(['a.wsm_code'=>array_column($list,"wsm_code"),"a.is_del"=>0])
- ->column("a.name as wsm_name","wsm_code");
- $names = $userCommon->handle('getCodeAndName', ['code' =>array_merge(array_column($list,"companyNo"),array_column($list,"supplierNo"))]);
- foreach ($list as &$value){
- $value['supplierName'] = $names['data'][$value['supplierNo']] ?? '';
- $value['company'] = $names['data'][$value['companyNo']] ?? '';
- $int = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
- $value['wsm_name'] =$wsmcode[$value['wsm_code']]??"";
- $value['action_type_cn'] =$this->acton[$value['action_type']];
- $value['item'] = $item[$value['action_uid']] ?? '';
- $value['can'] =$int;
- }
- return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
- }
- public function goodlist()
- {
- $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
- $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
- $where = [["a.is_del", "=", 0], ["b.exam_status", "=", 3], ["b.is_del", "=", 0], ["c.is_del", "=", 0], ["c.status", "=", 1]];
- $paltcode = isset($this->post["platform_code"]) && $this->post["platform_code"] != "" ? trim($this->post["platform_code"]) : "";
- if ($paltcode != "") {
- $where[] = ["platform_code", "=", $paltcode];
- }
- $companyNo = isset($this->post["companyNo"]) && $this->post["companyNo"] != "" ? trim($this->post["companyNo"]) : "";
- if ($companyNo != "") {
- $where[] = ["companyNo", "like", "%$companyNo%"];
- }
- $cat_id = isset($this->post["cat_id"]) && $this->post["cat_id"] !== "" ? intval($this->post["cat_id"]) : "";
- if ($cat_id !== "") {
- //获取当前分类及所有子级
- $where[] = ["cat_id", "in", manger([$cat_id])];
- }
- $buy_num = isset($this->post["buy_num"]) && $this->post["buy_num"] !== "" ? intval($this->post["buy_num"]) : "";
- if ($buy_num !== "") {
- $where[] = ["c.min_num", "<=", $buy_num];
- }
- $price = isset($this->post["price"]) && $this->post["price"] !== "" ? floatval($this->post["price"]) : "";
- if ($price !== "") {
- $where[] = ["c.sale_price", "<=", $price];
- }
- $temp = Db::name('good_ladder')
- ->field('skuCode,MAX(min_num) min_num')
- ->where([
- ['min_num', '<=', $buy_num],
- ['sale_price', '<=', $price],
- ['is_del', '=', 0],
- ['status', '=', 1],
- ])->group('skuCode')
- ->order('skuCode', 'desc')->buildSql();
- $count = Db::name('good_ladder')
- ->alias('c')
- ->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`')
- ->join($temp . ' temp', 'temp.skuCode = c.skuCode AND temp.min_num = c.min_num')
- ->leftJoin('good_platform b', 'b.skuCode=c.skuCode')
- ->leftJoin('good a', 'a.spuCode = b.spuCode AND a.is_del=0')
- ->where($where)
- ->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('good_ladder')
- ->alias('c')
- ->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`')
- ->join($temp . ' temp', 'temp.skuCode = c.skuCode AND temp.min_num = c.min_num')
- ->leftJoin('good_platform b', 'b.skuCode=c.skuCode')
- ->leftJoin('good a', 'a.spuCode = b.spuCode AND a.is_del=0')
- ->where($where)
- ->page($page,$size)
- ->select()
- ->toArray();
- // $list = Db::name('good')
- // ->alias("a")
- // ->leftJoin("good_platform b","a.spuCode=b.spuCode")
- // ->leftJoin("good_ladder c","b.skuCode=c.skuCode")
- // ->where($where)->fetchSql()
- // ->where('a.spuCode','SKU2205251851017540')
- // ->page($page,$size)
- // ->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")
- // ->order("b.addtime desc")
- // ->select();halt($list);
- // ->toArray();
- $data = [];
- $platform = Db::name('platform')
- ->whereIn('id',array_column($list,'platform_code'))
- ->column('platform_name,platform_code','id');
- $brand = Db::name('brand')
- ->whereIn('id',array_column($list,'brand_id'))
- ->column('brand_name','id');
- $unit = Db::name('unit')
- ->whereIn('id',array_column($list,'good_unit'))
- ->column('unit','id');
- $userCommon =\app\admin\common\User::getIns();
- $names = $userCommon->handle('getCodeAndName',['code'=>array_merge(array_column($list,'supplierNo'),array_column($list,'companyNo'))]);
- foreach ($list as $value) {
- $value['cat_info'] = made($value['cat_id'], []);
- // $platform = Db::name("platform")->where(["id" => $value['platform_code']])->find();
- $value['platform_name'] = $platform[$value['platform_code']]['platform_name']??'';//isset($platform['platform_name']) ? $platform['platform_name'] : "";
- $value['platform_code_en'] = $platform[$value['platform_code']]['platform_code']??'';//isset($platform['platform_code']) ? $platform['platform_code'] : "";
- // $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
- $value['supplier_name'] = $names['data'][$value['supplierNo']]??'';//isset($supplier['name']) ? $supplier['name'] : "";
- // $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
- $value["brand_name"] = $brand[$value['brand_id']]??'';//isset($brand['brand_name']) ? $brand['brand_name'] : "";
- // $unit = Db::name("unit")->where(["id" => $value['good_unit']])->find();
- $value['unit'] = $unit[$value['good_unit']]??'';//isset($unit['unit']) ? $unit['unit'] : "";
- // $company = Db::name("business")->where(["companyNo" => $value['companyNo']])->find();
- $value['company'] = $names['data'][$value['companyNo']]??'';//isset($company['company']) ? $company['company'] : "";
- $value['stock_total'] = Db::name("good_stock")->where(['spuCode' => $value['spuCode'], "is_del" => 0])->sum("usable_stock");
- $value['status'] = $value['exam_status'];
- $data[] = $value;
- }
- return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
- }
- //根据价格区间,筛选符合条件的商品列表
- public function getGoodListByLadder()
- {
- //1.请求参数
- $param = $this->request->only([
- 'good_type' => '',
- // 'start' => '',
- // 'end' => '',
- 'is_stock' => '',
- 'cat_id' => 0,
- 'brand_id' => 0,
- 'min_price' => 0,
- 'max_price' => 0,
- 'moq' => 0,//最低起订量?
- 'good_name' => '',
- 'skucode' => '',
- 'spucode' => '',
- 'companyNo' => '',//业务企业编号
- 'plat_code' => '',//平台商品编号
- 'creater' => '',//创建人
- 'platform_code' => '',
- 'supplierNo' => '',
- 'page' => 1,
- 'size' => 15,
- 'company_name'=>'',
- 'relaComNo'=>'',
- ], 'post', 'trim');
- $where = [["gl.is_del", "=", 0], ['gp.exam_status', '=', 3]];//exam_status==6已上线
- if ($param['good_type']!='') $where[] = ['gb.good_type', '=', $param['good_type']];
- if ($param['is_stock']!='') $where[] = ['gb.is_stock', '=', $param['is_stock']];
- if (!empty($param['cat_id'])) $where[] = ['gb.cat_id', '=', $param['cat_id']];
- if (!empty($param['brand_id'])) $where[] = ['gb.brand_id', '=', $param['brand_id']];
- if ($param['min_price']!='' && $param['max_price']!='') $where[] = ['gl.sale_price', 'between', [$param['min_price'], $param['max_price']]];
- if (!empty($param['moq'])) $where[] = ['gl.min_num', '>=', $param['moq']];
- if (!empty($param['good_name'])) $where[] = ['gb.good_name', 'like', '%' . $param['good_name'] . '%'];
- if (!empty($param['skucode'])) $where[] = ['gl.skuCode', 'like', '%' . $param['skucode'] . '%'];
- if (!empty($param['spucode'])) $where[] = ['gp.spuCode', 'like', '%' . $param['spucode'] . '%'];
- if (!empty($param['companyNo'])) $where[] = ['gb.companyNo', 'like', '%' . $param['companyNo'], '%'];
- if (!empty($param['plat_code'])) $where[] = ['gp.plat_code', 'like', '%' . $param['plat_code'], '%'];
- if (!empty($param['creater'])) $where[] = ['gb.creater', 'like', '%' . $param['creater'], '%'];
- if (!empty($param['platform_code'])) $where[] = ['gp.platform_code', 'like', '%' . $param['platform_code'], '%'];
- if (!empty($param['company_name'])) $where[] = ['gb.createrid', 'in', get_company_item_user_by_name($param['company_name'])];
- if ($param['relaComNo'] != '') $where[] = ['gb.companyNo|gb.supplierNo', '=', $param['relaComNo']];
- //5.获取结果
- $count = Db::name('good_ladder')
- ->alias('gl')
- ->leftJoin('good_platform gp', 'gp.skuCode=gl.skuCode AND gp.is_del=0')
- ->leftJoin('platform p', 'p.id=gp.platform_code AND p.is_del=0')
- ->leftJoin('good gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
- ->where($where)
- ->count('gl.id');
- $list = Db::name('good_ladder')
- ->alias('gl')
- ->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')
- ->leftJoin('good_platform gp', 'gp.skuCode=gl.skuCode AND gp.is_del=0')
- ->leftJoin('platform p', 'p.id=gp.platform_code AND p.is_del=0')
- ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
- ->where($where)
- ->page($param['page'], $param['size'])
- ->order(['gl.skuCode' => 'asc', 'gl.addtime' => 'desc', 'gl.id' => 'desc'])
- ->select()
- ->toArray();
- $all_createrid = array_column($list,'createrid');
- $item = get_company_name_by_uid($all_createrid);
- //6.补充数据,照搬list方法
- $all_brand = Db::name('brand')
- ->where('is_del', 0)
- ->whereIn('id', array_column($list, 'brand_id'))
- ->column('brand_name', 'id');
- $userCommon = \app\admin\common\User::getIns();
- $temp = $userCommon->handle('sGetList',['more_code'=>array_column($list,'supplierNo')]);
- $person = array_column($temp['data']['list'],'person','code');
- // $names = $userCommon->handle('getCodeAndName', ['code' => array_column($list, 'companyNo')]);
- // $all_company = $names['data'];
- // $all_company = Db::name('business')
- // ->where('is_del', 0)
- // ->whereIn('companyNo', array_column($list, 'companyNo'))
- // ->column('company', 'companyNo');
- foreach ($list as &$value) {
- $value['cat_info'] = made($value['cat_id'], []);
- $value['brand_name'] = isset($all_brand[$value['brand_id']]) ? $all_brand[$value['brand_id']] : '';
- // $value['company'] = isset($all_company[$value['companyNo']]) ? $all_company[$value['companyNo']] : '';
- $value['stock_total'] = Db::name("good_stock")
- ->where(['spuCode' => $value['spuCode'], "is_del" => 0])
- ->sum("usable_stock");
- $value['company_name'] = $item[$value['createrid']]??'';
- $value['purchase'] = $person[$value['supplierNo']] ?? '';//供应商负责人
- }
- return app_show(0, "获取成功", ['list' => $list, 'count' => $count]);
- }
- public function getCombind(){
- $param= $this->request->param(['spuCode'=>'',"isZx"=>""],'post','trim');
- $list = (new GoodCombind())->with([$param['isZx']==1?"goodZx":"goodBasic"])->where('spuCode',$param['spuCode'])->select();
- foreach ($list as &$item){
- $taxInfo=GoodTax::with(['Tax','OutTax','CgdTax'])->where(['spuCode'=>$item['childCode']])->findOrEmpty();
- $item['in_tax_name'] = $taxInfo->in_tax_name??'';
- $item['in_tax_code'] = $taxInfo->in_tax_code??'';
- $item['in_tax_short'] = $taxInfo->in_tax_short??'';
- $item['in_tax_merge'] = $taxInfo->in_tax_merge??'';
- $item['in_tax'] = $taxInfo->tax??'';
- $item['out_tax_name'] = $taxInfo->out_tax_name??'';
- $item['out_tax_code'] = $taxInfo->out_tax_code??'';
- $item['out_tax_short'] = $taxInfo->out_tax_short??'';
- $item['out_tax_merge'] = $taxInfo->out_tax_merge??'';
- $item['out_tax'] = $taxInfo->out_tax??'';
- $item['inv_good_name'] = $taxInfo->inv_good_name;
- }
- $this->success('获取成功',$list);
- }
- }
|