123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\GoodLog;
- use think\App;
- use think\facade\Db;
- class Good extends \app\BaseController
- {
- public $post="";
- private $acton=[
- "allotsend"=>'调拨发货',
- "allotin"=>'调拨入库',
- "allotincheck"=>'调拨验货',
- 'CGD'=>'采购单',
- 'BHD'=>'备库单',
- 'FKD'=>'备库反馈单',
- 'RKD'=>'入库单',
- 'ZXQRD'=>'咨询单',
- 'XSQRD'=>'销售单',
- 'PDD'=>'盘点单',
- 'DBD'=>'调拨单',
- 'CKD'=>'出库单',
- 'CGTHD'=>'采购退货单',
- 'XSTHD'=>'销售退货单',
- 'CGGCD'=>'采购工差单',
- 'ZXGCD'=>'咨询工差单'
- ];
- private $exclusive=["非专属","泰康"];
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post = $this->request->post();
- // $token = isset($this->post['token']) ? trim($this->post['token']) : "";
- // if($token==""){
- // return error_show(101,'token不能为空');
- // }0
- // $effetc = VerifyTokens($token);
- // if(!empty($effetc) && $effetc['code']!=0){
- // return error_show($effetc['code'],$effetc['message']);
- // }
- }
- 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['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode'])
- :"";
- if($skucode!==""){
- $where [] = ['b.skucode',"like","%$skucode%"];
- }
- $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
- if($start!==""){
- $where[]=['a.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
- }
- $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
- if($end!==""){
- $where[]=['a.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[]=['is_stock',"=",$is_stock];
- }
- $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? intval($this->post['good_type'])
- :"";
- if($good_type!==""){
- $where[]=['good_type',"=",$good_type];
- }
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
- :"";
- if($supplierNo!==""){
- $where[]=['a.supplierNo',"=",$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%"];
- }
- $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[]=["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];
- }
- $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where($where)
- ->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where($where)->page
- ($page,$size)->field("b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.*,b.addtime,b.updatetime,b.exam_status")
- ->order("b.addtime desc")
- ->select();
- $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"]=isset($brand['brand_name'])?$brand['brand_name']:"";
- $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
- $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
- $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
- $value['company'] = 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['good_info_img']=json_decode($value['good_info_img'],true);
- $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;
- $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_code']=$good_platform['id'];
- $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['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();
- $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
- $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
- // $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
- // $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
- $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
- $data['company'] = isset($company['company'])?$company['company']:"";
- 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']!=""? json_decode($data['good_info_img'],true):[];
- $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();
- $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
- $nakearry=[];
- if(!empty($nakelist)){
- foreach ($nakelist as $value){
- if($data['is_gold_price']==1){
- $gold = Db::name("gold_price1")->where(["type"=>$data['noble_metal'],"is_del"=>0,"status"=>1])->order("addtime desc")
- ->find();
- // $total_fee = $data['open_fee']/$value['min_num'] + $data['weight']*$gold["price"] + $data['cost_fee']/(1-$budget)*
- // $data['noble_weight']+$data['mark_fee']+$data['packing_fee']+$data['cert_fee']+$value['nake_fee'];
- $saleprice = $data['open_fee']/$value['min_num'] + $data['weight']*$gold["price"] + $data['cost_fee']*
- $data['noble_weight']+$data['mark_fee']+$data['packing_fee']+$data['cert_fee']+$value['nake_fee'];
- }else{
- // $total_fee = $data['open_fee']/$value['min_num']+
- // $data['cost_fee']*$data['weight']+$data['mark_fee']+$data['packing_fee']+$data['cert_fee']+$value['nake_fee'];
- $saleprice = $data['open_fee']/$value['min_num'] + $data['cost_fee']*
- $data['noble_weight']+$data['mark_fee']+$data['packing_fee']+$data['cert_fee']+$value['nake_fee']/(1-$budget);
- }
- $value['sale_price'] =round($saleprice,2) ;
- $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;
- 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){
- $data=["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.good_type_code","=",$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,"wsm_type"=>1,"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.total_stock,a.status,a.warn_stock")->select();
- if(empty($list)){
- return error_show(1004,"未找到数据");
- }
- return app_show(0,"获取成功",$list);
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- 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[]=["good_type_code","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,"wsm_type"=>1,"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=[];
- foreach ($list as $key=>$value){
- $temp=[];
- if($value['wsm_code']!=""){
- $wsm = Db::name("warehouse_info")->alias("a")->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,b.code,b.name")
- ->find();
- }
- $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
- $temp['wsm_code']=$value['wsm_code'];
- $temp['supplier_code']=isset($wsm['code'])?$wsm['code']:"";
- $temp['supplier_name']=isset($wsm['name'])?$wsm['name']:"";
- if($value['good_type_code']!=""){
- $good=Db::name("good_type")->alias("a")->join("good b","a.good_code=b.good_code","left")->where(["a.type_code"=>$value['good_type_code'],"a.is_del"=>0,"b.is_del"=>0])
- ->field("a.good_code,a.type_code,b.good_name,b.unit,a.attribute,b.sort_f")->find();
- }
- $temp['good_code']=isset($good['good_code'])?$good['good_code']:"";
- $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['attribute']=isset($good['attribute'])?$good['attribute']:"";
- $temp['sort_f']=isset($good['sort_f'])?$good['sort_f']:"";
- $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['total_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]);
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- 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 = [["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];
- }
- $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
- :"";
- if($suplierNo!==""){
- $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"wsm_type"=>1,"is_del"=>0])->column("wsm_code");
- $condition[]=["wsm_code","in",$wsmcode];
- }
- $build= Db::name("good_stock")->where($condition)->group("wsm_code")->field("wsm_code")->buildSql();
- $count = Db::table($build." a")->count();
- $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
- $list = Db::name("good_stock")->where($condition)->page($page,$size)->group("wsm_code")
- ->field("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(total_stock) total_stock")->select();
- $data=[];
- foreach ($list as $key=>$value){
- $temp=[];
- if($value['wsm_code']!=""){
- $wsm = Db::name("warehouse_info")->alias("a")->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,b.code,b.name")
- ->find();
- $good = Db::name("good_stock")->alias("a")->join("good_type b","a.good_type_code=b.type_code","left")
- ->join("good c","c.good_code=b.good_code","left")->where(["a.wsm_code"=>$value['wsm_code'],"a.is_del"=>0,"b.is_del"=>0,"c.is_del"=>0])
- ->field("c.good_code,a.good_type_code,c.good_name,b.attribute,c.sort_f,c.unit,a.usable_stock,a.wait_in_stock,a.wait_out_stock,a.intra_stock,a.total_stock,a.warn_stock")
- ->select();
- }
- $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
- $temp['wsm_code']=$value['wsm_code'];
- $temp['supplier_code']=isset($wsm['code'])?$wsm['code']:"";
- $temp['supplier_name']=isset($wsm['name'])?$wsm['name']:"";
- $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['total_stock'];
- // $temp['warn_stock'] = $value['warn_stock'];
- $temp['child']=isset($good)&&!empty($good) ? $good:[];
- $data[]=$temp;
- }
- return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
- }
- 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 = [["a.is_del","=",0],["b.is_del","=",0],["c.usable_stock",">",0]];
- $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code'])
- :"";
- if($type_code!==""){
- $condition[]=["b.type_code","like","%{$type_code}%"];
- }
- $count = Db::name("good_type")->alias("b")
- ->join("good a","a.good_code = b.good_code","left")
- ->join("good_stock c","c.good_type_code = b.type_code","left")
- ->where($condition)->group("a.good_code,a.good_name,a.unit,a.sort_f,b.type_code,b.attribute,a.addtime")->count();
- $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
- $list = Db::name("good_type")->alias("b")
- ->join("good a","a.good_code = b.good_code","left")
- ->join("good_stock c","c.good_type_code = b.type_code","left")
- ->where($condition)->field("a.good_code,a.good_name,a.unit,a.sort_f,b.type_code,b.attribute,a.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.total_stock) total_stock")
- ->page($page,$size)->order("a.addtime desc")->group("a.good_code,a.good_name,a.unit,a.sort_f,b.type_code,b.attribute,a.addtime")->select();
- // echo Db::name("good_type")->getLastSql();
- $data=[];
- foreach ($list as $key=>$value){
- $temp=[];
- if($value['type_code']!=""){
- $child = Db::name("good_stock")->alias("a")->join("warehouse_info b","a.wsm_code=b.wsm_code","left")
- ->where(['a.good_type_code'=>$value['type_code'],"b.wsm_type"=>1,"a.is_del"=>0])->field("a.wsm_code,b.name wsm_name,a.wait_in_stock,a.wait_out_stock,a.usable_stock,a.intra_stock,a.total_stock,a.warn_stock")->select();
- }
- $temp['good_name'] = $value['good_name'];
- $temp['good_code'] = $value['good_code'];
- $temp['type_code'] = $value['type_code'];
- $temp['unit'] = $value['unit'];
- $temp['sort_f']=$value['sort_f'];
- $temp['attribute']=$value['attribute'];
- $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'] = isset($value['total_stock'])? $value['total_stock']:"";
- // $temp['warn_stock'] = isset($value['warn_stock'])? $value['warn_stock']:"";
- $temp['child']=isset($child)&&!empty($child) ? $child:[];
- $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 =[["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;
- $condition[]=["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,"wsm_type"=>1,"is_del"=>0])->column("wsm_code");
- $condition[]=["wsm_code","in",$wsmcode];
- }
- $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];
- }
- $statlist = Db::name("good_stock")->where($condition)->field("sum(wait_in_stock) as wait_in_stock,sum(wait_out_stock) as wait_out_stock ,sum(usable_stock) as usable_stock,sum(intra_stock) as intra_stock,sum(total_stock) as total_stock,sum(warn_stock) as warn_stock")->find();
- 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(){
- $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=[];
- $wsm_code= isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
- if($wsm_code!=""){
- $where[]=['b.wsm_code',"like","%$wsm_code%"];
- }
- $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,"未找到供应商信息");
- }
- $wsmcode = Db::name("warehouse_info")->where([
- "is_del"=>0,"wsm_type"=>1,"supplierNo"=>$supplierNo])->column("wsm_code");
- $where[]=['b.wsm_code',"in",$wsmcode];
- }
- $count = Db::name("good_log")->alias('a')
- ->join("good_stock b","b.id=a.id","left")->where($where)
- ->join("good_type c","c.type_code=b.good_type_code","left")
- ->join("good v","v.good_code=c.good_code","left")->count();
- $total = ceil($count/$size);
- $page = $total>=$page ? $page :$total;
- $list = Db::name("good_log")->alias('a')
- ->join("good_stock b","b.id=a.stock_id","left")
- ->join("good_type c","c.type_code=b.good_type_code","left")
- ->join("good v","v.good_code=c.good_code","left")
- ->where($where)->page($page,$size)->order("a.addtime desc")
- ->field("a.action_name,a.type,a.stock_name,a.stock,a.action_type,
- a.addtime,a.action_uid,b.wsm_code,v.good_code,v.good_name,v.cat_id")->select();
- $data=[];
- foreach ($list as $value){
- $db = Db::name("depart_user")->where(['uid'=>$value['action_uid']])->column("itemid");
- $item = Db::name("company_item")->where(['id'=>$db])->column("id,name");
- $wsm = Db::name("warehouse_info")->alias("a")->Join("supplier b","a.supplierNo=b.code","left")->where
- (['a.wsm_code'=>$value['wsm_code'],"a.wsm_type"=>1,"a.is_del"=>0])->field("a.name as wsm_name,wsm_code,b.code,b.name")->find();
- $int = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
- $value['wsm_name'] =$wsm['wsm_name'];
- $value['wsm_code'] =$wsm['wsm_code'];
- $value['code'] =$wsm['code'];
- $value['name'] =$wsm['name'];
- $value['action_type_cn'] =$this->acton[$value['action_type']];
- $value['item'] =$item;
- $value['can'] =$int;
- $data[]=$value;
- }
- return app_show(0,"获取成功",['list'=>$data,'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","=",6],["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","=",$cat_id];
- }
- $buy_num = isset($this->post["buy_num"])&& $this->post["buy_num"]!==""? intval($this->post["buy_num"]):"";
- if($buy_num!==""){
- $where[]=["min_num","<=",$buy_num];
- }
- $price = isset($this->post["price"])&& $this->post["price"]!==""? floatval($this->post["price"]):"";
- if($buy_num!==""){
- $where[]=["sale_price","<=",$price];
- }
- $count = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->leftJoin("good_ladder c","b.skuCode=c.skuCode")
- ->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->leftJoin("good_ladder c","b.skuCode=c.skuCode")->where($where)->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();
- $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']) ? $platform['platform_code']:"";
- $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"]=isset($brand['brand_name'])?$brand['brand_name']:"";
- $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
- $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
- $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
- $value['company'] = 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]);
- }
- }
|