12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\DataGroup as DataGroupModel;
- use app\admin\model\GoodLog;
- 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];
- }
- $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];
- }
- // $role=$this->checkRole();
- // if(!empty($role['write']) ){
- // $where[]=["a.createrid","in",$role['write']];
- // }
- // $role = $this->checkDataShare();
- // $hand = resign_hand_user($this->uid,0);
- // if (!empty($role[DataGroupModel::$type_全部])) {
- // $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
- // $where[] = ['b.createrid', 'in',$arr];
- // }
- $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")
- ->leftJoin("good_platform b","a.spuCode=b.spuCode")
- // ->leftJoin("supplier s","a.supplierNo=s.code")
- // ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
- ->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,
- a.good_info_img,a.good_thumb_img,b.createrid,a.is_exclusive,a.brand_id,a.supplierNo,a.supplierName,
- 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取个别名
- ->leftJoin("good_platform b","a.spuCode=b.spuCode")
- // ->leftJoin("supplier s","a.supplierNo=s.code")
- // ->leftJoin("good_basic gb","gb.spuCode=a.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]];
- 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']];
- // $role = $this->checkRole();
- // if (!empty($role['write'])) $where[] = ["a.createrid", "in", $role['write']];
- $role = $this->checkDataShare();
- $hand = resign_hand_user($this->uid,0);
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
- $where[] = ['b.createrid', 'in',$arr];
- }
- if ($param['company_name'] !== '') $where[] = ["a.createrid", 'in', get_company_item_user_by_name($param['company_name'])];
- // $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
- 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")
- // ->leftJoin("depart_user u", "u.uid=a.createrid AND u.is_del=0")
- ->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,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'] : "";
- // $company = Db::name("business")->field('id,company')->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'];
- $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;
- //补充商品详情链接字段
- $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['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']]);
- // $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
- $data['supplierName'] = $names['data'][$data['supplierNo']]??'';//isset($supplier['name'])?$supplier['name']:"";
- // $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
- $data['company'] = $names['data'][$data['companyNo']]??'';//isset($company['company'])?$company['company']:"";
- $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
- 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;
- //补充采购员字段
- //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给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]];
- $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","=",$type_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,c.code,c.name,a.wait_in_stock,a.wait_out_stock,a.usable_stock,a.intra_stock,(a.wait_out_stock+a.usable_stock) as total_stock,a.status,a.warn_stock")->select();
- 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")
- ->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();
- }
- //规格信息
- $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'] = 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];
- }
- // $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[]=["gs.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[]=["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,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")
- // ->leftJoin("business bus", "bus.companyNo=a.companyNo")
- // ->leftJoin("supplier b","a.supplierNo=b.code")
- ->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.wsm_code');
- // ->find();
- // $userCommon = \app\admin\common\User::getIns();
- // $names = $userCommon->handle('getCodeAndName', ['code'=>array_unique(array_merge(array_column($warehouse_info, 'supplierNo'), array_column($warehouse_info, 'companyNo')))]);
- $data=[];
- foreach ($list as $key=>$value){
- $temp=[];
- if($value['wsm_code']!=""){
- // $wsm = Db::name("warehouse_info")
- // ->alias("a")
- //// ->leftJoin("business bus", "bus.companyNo=a.companyNo")
- //// ->leftJoin("supplier b","a.supplierNo=b.code")
- // ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
- // ->field("a.name as wsm_name,wsm_code,a.supplierNo,a.companyNo")
- // ->find();
- // $good = Db::name("good_stock")
- // ->alias("a")
- // ->leftJoin("good c","c.spuCode=a.spuCode")
- // ->where(["a.wsm_code"=>$value['wsm_code'],"a.is_del"=>0,"c.is_del"=>0])
- // ->select()
- // ->toArray();
- // $names = $userCommon->handle('getCodeAndName', [$wsm['supplierNo'], $wsm['companyNo']]);
- // $warehouse_info[$value['wsm_code']]['supplierName'] = $names['data'][$warehouse_info[$value['wsm_code']]['supplierNo']] ?? '';
- // $warehouse_info[$value['wsm_code']]['company'] = $names['data'][$warehouse_info[$value['wsm_code']]['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'] = 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'];
- //
- // }
- }
- $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['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 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'] = 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],["c.usable_stock",">",0],["a.wsm_type","<>",2]];
- $condition = [["b.is_del", "=", 0], ["a.wsm_type", "<>", 2]];//库存为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];
- $count = Db::name("good")
- ->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")
- ->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")
- // ->join("business bus", "bus.companyNo=b.companyNo", "left")
- // ->join("supplier s", "s.code=b.supplierNo", "left")
- ->where(['a.spuCode' => $value['spuCode'], "a.is_del" => 0])
- ->where("b.wsm_type","<>",2)
- ->field("a.wsm_code,b.name wsm_name,a.wait_in_stock,a.wait_out_stock,a.usable_stock,a.intra_stock,(a.wait_out_stock+a.usable_stock) total_stock,a.warn_stock,b.supplierNo,b.companyNo")
- ->select()
- ->toArray();
- foreach ($child as &$vvv){
- $names = $userCommon->handle('getCodeAndName',['code'=>[$vvv['supplierNo'],$vvv['companyNo']]]);
- $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'] = 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 (!empty($param['start'])) $where[] = ['gl.addtime', '>=', $param['start']];
- // if (!empty($param['end'])) $where[] = ['gl.addtime', '<=', $param['end'] . ' 23:59:59'];
- 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 (!empty($param['supplierNo'])) $where[] = ['supplierNo', 'like', '%'.$param['supplierNo'],'%'];
- if ($param['relaComNo'] != '') $where[] = ['gb.companyNo|gb.supplierNo', '=', $param['relaComNo']];
- //5.获取结果
- $count = 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,gl.sale_price,gb.creater purchase,gb.creater,gb.companyNo,u.itemid')
- ->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')
- // ->leftJoin("depart_user u", "u.uid=gb.createrid AND u.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]);
- }
- }
|