Browse Source

Merge branch 'master-new-wgg' of wugg/phpstock into master-new

wugg 8 months ago
parent
commit
abf9c20aab

+ 68 - 17
app/admin/controller/Activity.php

@@ -5,10 +5,13 @@ namespace app\admin\controller;
 use app\admin\common\Ocr;
 use app\admin\model\ActionLog;
 use app\admin\model\DataGroup as DataGroupModel;
+use app\admin\model\GoodTax;
+use app\admin\model\GoodZixun;
+use app\admin\model\OrderTax;
 use app\admin\model\ProcessOrder;
 use app\BaseController;
-use think\App;
-use think\facade\Db;
+use app\model\TaxCategory;use think\App;
+use think\facade\Db;use think\facade\Validate;
 
 class Activity extends Base
 {
@@ -191,19 +194,28 @@ class Activity extends Base
         if($relaComNo!="") $where[]=['a.supplierNo|a.companyNo','=', $relaComNo];
 		$orderSource= isset($this->post['order_source']) && $this->post['order_source']!='' ? $this->post['order_source']:[];
         if(!empty($orderSource)) $where[]=['a.order_source','in', $orderSource];
-
+        $tax_status= isset($this->post['tax_status']) && $this->post['tax_status']!=='' ? $this->post['tax_status']:'';
+        if($tax_status!==''){
+            $where[] = ['b.status', '=', $tax_status==0?null :$tax_status];
+        }
+        $orderCode= isset($this->post['orderCode']) && $this->post['orderCode']!='' ? $this->post['orderCode']:'';
+        if($orderCode!==''){
+            $where[]=['a.spuCode',"=",\app\admin\model\Sale::where('orderCode','=',$orderCode)->value('good_code','')];
+        }
         $count = Db::name('good_zixun')
             ->alias("a")
+            ->leftJoin("good_tax b","a.spuCode=b.spuCode")
             ->where($where)
             ->count();
         $total = ceil($count / $size);
         $page = $page >= $total ? $total : $page;
         $list = Db::name('good_zixun')
             ->alias("a")
-//            ->join("supplier b","b.code=a.supplierNo","left")
+             ->leftJoin('good_tax b','a.spuCode=b.spuCode')
             ->where($where)
             ->page($page,$size)
             ->order("a.addtime desc")
+            ->field("a.*,ifnull(b.status,0) tax_status")
             ->select()
             ->toArray();
 
@@ -221,13 +233,12 @@ class Activity extends Base
         $all_unit = Db::name('unit')
             ->where(['is_del'=>0,'id'=>$all_good_unit])
             ->column('unit','id');
+        $orderCoderArr=\app\admin\model\Sale::where('good_code','in',array_unique(array_column($list,'spuCode')))->column('orderCode','good_code');
 
         $all_code = array_merge(array_column($list,'supplierNo'),array_column($list,'companyNo'));
         $userCommon = \app\admin\common\User::getIns();
         $tmp = $userCommon->handle('getCodeAndName',['code'=>$all_code]);
         $depart = get_company_name_by_uid( array_unique(array_column($list,'order_createrid')));
-
-//halt($list);
         $data=[];
         //分类/规格/品牌 等字段取出对应文字
         $goodbasice = Db::name('good_basic')->where(['spuCode'=>array_column($list,"spuCode")])->column('status',"spuCode");
@@ -236,28 +247,19 @@ class Activity extends Base
             $value['cat_info']= made($value['cat_id'],[]);
             $value['is_basic']=$goodbasice[$value['spuCode']]??null;
             $value['order_creater_depart']=$depart[$value['order_createrid']]??'';
-            
             $value['is_online']=isset($good_online[$value['spuCode']])?1:0;
-
             $value['platform_name'] = $all_platform[$value['platform_id']]??'';//isset($platform['platform_name']) ? $platform['platform_name']:"";
             $value['platform_code_en'] = '';//isset($platform['platform_code_en']) ? $platform['platform_code_en']:"";
-
             $value['supplier_name'] = $tmp[$value['supplierNo']] ?? '';//isset($supplier['name']) ? $supplier['name']:"";
-
             $value["brand_name"]=$all_brand[$value['brand_id']]??'';//isset($brand['brand_name'])?$brand['brand_name']:"";
-
             $value['unit'] =$all_unit[$value['good_unit']]??'';//isset($unit['unit'])?$unit['unit']:"";
-//            $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
             $value['company'] = $tmp[$value['companyNo']]??'';//isset($company['company'])?$company['company']:"";
-//            $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['exclusive']=makeExcluse($value['is_exclusive']);
             $value['good_info_img']=$value['good_info_img'];
             $value['good_img']=$value['good_img'];
+            $value['orderCode']=$orderCoderArr[$value['spuCode']]??'';
             $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
             $speclist=[];
             if(!empty($spec)){
@@ -280,6 +282,55 @@ class Activity extends Base
         return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
     }
 
+    public function SetZixunTax(){
+        $param =$this->request->param(["spuCode"=>"","out_tax_id"=>"","out_tax"=>""],"post","trim");
+        $valid = Validate::rule( [
+            'spuCode' => 'require',
+            'out_tax_id' => 'require|number|gt:0',
+            'out_tax' => 'require',
+        ]);
+        if(!$valid->check($param))$this->error($valid->getError());
+        $goodinfo = GoodZixun::where(["spuCode"=>$param['spuCode']])->findOrEmpty();
+        if($goodinfo->isEmpty()){
+           $this->error('商品不存在');
+        }
+        $catgery=TaxCategory::where(["id"=>$param['out_tax_id']])->findOrEmpty();
+        $goodTax = GoodTax::where(["spuCode"=>$param['spuCode']])->findOrEmpty();
+        if($goodTax->isEmpty())$this->error("商品进项税目未设置");
+        $order= \app\admin\model\Sale::where(["good_code"=>$param['spuCode']])->findOrEmpty();
+        Db::startTrans();
+        try{
+                $goodTax->out_tax_id=$param['out_tax_id'];
+                $goodTax->out_tax=$param['out_tax'];
+                $goodTax->status=2;
+               if($goodTax->save()){
+                 if(!$order->isEmpty()){
+                   $orderTax=OrderTax::where(['code'=>$order->orderCode,'spuCode'=>$param['spuCode']])->findOrEmpty();
+                     $Tax=[
+                            'code'=>$order->orderCode,
+                            'spuCode'=>$param['spuCode'],
+                            'tax_code'=>$catgery->merge_code,
+                            'tax_name'=>$catgery->cat_name,
+                            'tax_short_name'=>$catgery->short_name,
+                            'inv_tax'=>str_replace("%","",$param['out_tax']),
+                            'inv_good_name'=>$goodTax->inv_good_name,
+                        ];
+                   if($orderTax->isEmpty()){
+                     OrderTax::create($Tax);
+                   }else {
+                      $orderTax->save($Tax);
+                   }
+                   $order->save(['updatetime'=>date("Y-m-d H:i:s")]);
+                };
+                 Db::commit();
+               } else throw new \Exception("设置失败");
+        }catch (\Exception $e){
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        return app_show(0,"设置成功");
+    }
+
     //创建活动
     public function create(){
         $activity_name = isset($this->post['activity_name'])&&$this->post['activity_name']!="" ? trim($this->post['activity_name']):"";
@@ -691,7 +742,7 @@ class Activity extends Base
       if($skuCode==""){
           return error_show(1004,"参数skuCode不能为空");
       }
-      $where=['a.is_del'=>0,"b.is_del"=>0,"a.status"=>3,"b.status"=>1,"b.skuCode"=>$skuCode];
+      $where=['a.is_del'=>0,"b.is_del"=>0,"a.status"=>6,"b.status"=>1,"b.skuCode"=>$skuCode];
       $condition=['a.skuCode' =>$skuCode,"a.is_del"=>0,'a.exam_status'=>3];
       $company =  isset($this->post['companyNo'])&&$this->post['companyNo']!=""?trim($this->post['companyNo']):"";
       if($company!=""){

+ 3 - 1
app/admin/controller/Channel.php

@@ -8,7 +8,9 @@ use think\App;
 use think\facade\Validate;
 use think\facade\Db;
 class Channel extends Base{
-	public function __construct(App $app) {parent::__construct($app);}
+	public function __construct(App $app) {
+	    parent::__construct($app);
+	}
 
 	public function add(){
 		$param =$this->request->only(["channel_name"=>"","companyNo"=>""],"post","trim");

+ 3 - 2
app/admin/controller/CombindStock.php

@@ -176,8 +176,9 @@ class CombindStock extends Base
 							"usable_stock"=>$row->stock_num,
 							"total_stock"=>$row->stock_num,
 							];
-						$id =$stock->insertGetId($wsm_stock);
-						if($id<=0) throw new \Exception('仓库库存数更新失败');
+						$info =$stock->create($wsm_stock);
+						if($info->id<=0) throw new \Exception('仓库库存数更新失败');
+						$id = $info->id;
 					}else{
 						$wsm_stock=[
 							'usable_stock'=>bcadd($stock->usable_stock,$row->stock_num),

+ 248 - 206
app/admin/controller/Consult.php

@@ -3,9 +3,9 @@
 namespace app\admin\controller;
 
 use app\admin\model\ActionLog;
-use app\admin\model\ConsultTemp;use app\admin\model\DataGroup as DataGroupModel;
-use app\admin\model\ProcessOrder;
-use think\App;
+use app\admin\model\ConsultBids;use app\admin\model\ConsultInfo;use app\admin\model\ConsultTemp;use app\admin\model\DataGroup as DataGroupModel;
+use app\admin\model\GoodTax;use app\admin\model\ProcessOrder;
+use app\model\TaxCategory;use think\App;
 use think\facade\Db;
 use think\facade\Validate;
 
@@ -457,7 +457,7 @@ class Consult extends Base
         if($is_custom===""){
             return error_show(1003,"参数is_custom不能为空");
         }
-        $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
+        $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"0";
         if($metal_id===""){
             return error_show(1003,"参数metal_id不能为空");
         }
@@ -561,21 +561,19 @@ class Consult extends Base
                     "action_remark" => '',//备注
                     "action_type" => "edit"//新建create,编辑edit,更改状态status
                 ], "ZXD", 1, $this->post);
-
-//                ProcessOrder::AddProcess($this->post['token'], [
-//                    "order_type" => 'ZXD',
-//                    "order_code" => $innew,//咨询单详情编号
-//                    "order_id" => 0,
-//                    "order_status" => 1
-//                ]);
 				if($isbids==1){
 					 $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select()->toArray();
-				                if (!empty($bidlist)){
+				          if (!empty($bidlist)){
 				                    foreach ($bidlist as $value){
 				                        unset($value['id']);
+				                        $bidno=$value['bidNo'];
 				                        $value['infoNo']=$innew;
 				                        $value['bidNo']=makeNo("BD");
-				                        $value['spuCode']=makeNo("SKU");
+				                        $value['spuCode']= $value['is_combind']==1?makeNo("SSU"):makeNo("SKU");
+				                        $value['tax_status']=-1;
+				                        $value['out_tax_id'] =0;
+				                        $value['out_tax'] ="";
+				                        $value["remark"]="";
 				                        $value['status'] =0;
 				                        $value['updatetime'] =date("Y-m-d H:i:s");
 				                        $in = Db::name("consult_bids")->insert($value);
@@ -586,6 +584,19 @@ class Consult extends Base
 				                            "action_remark" => '',//备注
 				                            "action_type" => "create"//新建create,编辑edit,更改状态status
 				                        ], "FKD", 1, $this->post);
+				                        if($value['is_combind']==1){
+				                            $combine = ConsultTemp::where(["bidNo"=>$bidno])->select();
+				                            if(!$combine->isEmpty()){
+				                                (new ConsultTemp)->saveAll(array_map(function($v)use($value){
+				                                    $v['id']=null;
+				                                    $v['bidNo']=$value['bidNo'];
+				                                    $v['spuCode']= substr(makeNo('SPU'), 0, -2) . round(10,99);
+				                                    $v['out_tax_id'] =0;
+				                                    $v['out_tax'] ="";
+				                                    return $v;
+				                                },$combine->toArray()));
+				                            }
+				                        }
 				                    }
 				                }
 				}
@@ -648,16 +659,14 @@ class Consult extends Base
         if($status===""){
             return error_show(1004,"参数status不能为空");
         }
-//        if($status==1&&$zxinfo['status']>1){
-//            $zxinfo['bargain_num']=+1;
-//        }
         $old_zxinfo_status = $zxinfo['status'];
         $zxinfo['status']=$status;
         $zxinfo['updatetime']=date("Y-m-d H:i:s");
         $up = Db::name("consult_info")->save($zxinfo);
         if($up){
-
-            //修改状态,添加待办
+            if($status==2 || $status==7){
+                Db::name("consult_bids")->where(["infoNo"=>$infoNo,"is_del"=>0])->update(["tax_status"=>0]);
+            }
             ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
                 "order_code" => $zxinfo['infoNo'],//咨询单详情编号
                 "status" => $old_zxinfo_status,//这里的status是之前的值
@@ -749,7 +758,7 @@ class Consult extends Base
         $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
         if($nake_fee===""  ){
             return error_show(1004,"参数nake_fee不能为空");
-            }
+        }
         $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
         $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
         $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
@@ -758,8 +767,8 @@ class Consult extends Base
             return error_show(1002,"参数delivery_place不能为空");
         }
 
-        $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != '' ? trim($this->post['relaComNo']) : "";
-        if ($relaComNo == '') return error_show(1004, '关联公司不能为空');
+//        $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != '' ? trim($this->post['relaComNo']) : "";
+//        if ($relaComNo == '') return error_show(1004, '关联公司不能为空');
         
         $createrid= $this->uid;//isset($user["data"]['id']) ?  $user["data"]['id'] : "";
         $creater= $this->uname;//isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
@@ -770,7 +779,20 @@ class Consult extends Base
 			 if(empty($goodBind))$this->error('组合商品商品明细不能为空');
 			 $spucode=makeNo('SSU');
 		}
-		
+		$tax_id = isset($this->post['tax_id'])&&$this->post['tax_id']!==''? intval($this->post['tax_id']):'0';
+		$cgd_tax_id = isset($this->post['cgd_tax_id'])&&$this->post['cgd_tax_id']!==''? intval($this->post['cgd_tax_id']):'0';
+		$cgd_tax = isset($this->post['cgd_tax'])&&$this->post['cgd_tax']!==''? trim($this->post['cgd_tax']):'';
+        $open_type= isset($this->post['open_type'])&&$this->post['open_type']!==''? intval($this->post['open_type']):1;
+        $inv_good_name = isset($this->post['inv_good_name'])&&$this->post['inv_good_name']!==''? trim($this->post['inv_good_name']):'';
+        if($open_type=='') return error_show(1004,'开票商品类型不能为空');
+        if($open_type==1){
+            if($tax_id=='') return error_show(1004,'商品税目id不能为空');
+            if($inv_good_name=='') return error_show(1004,'开票商品名称不能为空');
+            if($cgd_supplier_code!=""){
+                if($cgd_tax_id==0) return error_show(1004,'源头供应商开票税目不能为空');
+                if($cgd_tax==='') return error_show(1004,'源头供应商开票税率不能为空');
+            }
+        }
         //计算毛利率
         $budget = get_budget($zxinfo['cat_id'], $zx['companyNo'], $zx['platform_code']);
 		if($budget===false) $this->error('未找到业务公司有关的平台分类毛利信息');
@@ -896,6 +918,11 @@ class Consult extends Base
 	        'cgd_supplier_name'=>$cgd_supplier_name,//采购供应商编号
 	        'cgd_apply_id'=>$cgd_apply_id,//竞单人
 	        'cgd_apply_name'=>$cgd_apply_name,//竞单人
+	        "open_type"=>$open_type,
+	        "inv_good_name"=>$inv_good_name,//采购商品名称
+	        "tax_id"=>$tax_id,//税目id
+	        "cgd_tax"=>$cgd_tax,//税目
+	        "cgd_tax_id"=>$cgd_tax_id
         ];
         Db::startTrans();
         try{
@@ -1013,9 +1040,10 @@ class Consult extends Base
         $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
         $info['cat_info'] = made($info['cat_id'],[]);
         $info['noble_weight'] = $info['good_weight'];
+        $info['companyNo'] = $zx['companyNo'];
+        $info['companyName'] = $zx['companyName'];
         $user= \app\admin\common\User::getIns();
         $supplier =$user->handle("getCodeAndName",["code"=>$info['supplierNo']]);
-//        $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
         $info['supplierName'] = isset($supplier['data'][$info['supplierNo']])?$supplier['data'][$info['supplierNo']]:"";
         if($info['brand_id']!=0){
             $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
@@ -1024,9 +1052,8 @@ class Consult extends Base
             $info["brand_name"]="";
             $info["brand_id"]="";
         }
-//        $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
         $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
-//        $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
+
         $budget = get_budget($info['cat_id'], $zx['companyNo'], $zx['platform_code']);
         if($budget===false) $this->error('未找到业务公司有关的平台分类毛利信息');
         $god=[
@@ -1061,8 +1088,21 @@ class Consult extends Base
         $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
         $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
         $info['bargain'] =$bargain;
+        $info["info_status"]=$bidinfo['status'];
         $info['good_img'] = explode(',',$info['good_img']);
-
+        $tax = TaxCategory::where(['id'=>[$info['tax_id'],$info['out_tax_id'],$info['cgd_tax_id']]])->column("short_name,cat_name,cat_code,merge_code","id");
+        $info['in_info'] = $tax[$info['tax_id']]??[];
+        $info['out_info'] = $tax[$info['out_tax_id']]??[];
+        $info['cgd_info'] = $tax[$info['cgd_tax_id']]??[];
+        $info['child'] =[];
+        if($info['is_combind']==1){
+            $info['child'] =ConsultTemp::where(['bidNo'=>$bidNo])->select()->each(function(&$item){
+                $tax = TaxCategory::where(['id'=>[$item['tax_id'],$item['out_tax_id'],$item['cgd_tax_id']]])->column('short_name,cat_name,cat_code,merge_code','id');
+                $item['in_info'] = $tax[$item['tax_id']]??[];
+                $item['out_info'] = $tax[$item['out_tax_id']]??[];
+                $item['cgd_info'] = $tax[$item['cgd_tax_id']]??[];
+            });
+        }
         //添加商品创建人字段
         $good_info = Db::name('good_basic')
             ->field('id,createrid,creater')
@@ -1140,7 +1180,6 @@ class Consult extends Base
 	        $cgd_apply_id =  isset($this->post['cgd_apply_id'])&&$this->post['cgd_apply_id']!=''? trim($this->post['cgd_apply_id']):0;
 	        $cgd_apply_name =  isset($this->post['cgd_apply_name'])&&$this->post['cgd_apply_name']!=''? trim($this->post['cgd_apply_name']):'';
 	        $supplier_origin_price =  isset($this->post['supplier_origin_price'])&&$this->post['supplier_origin_price']!=''? floatval($this->post['supplier_origin_price']):0;
-	        $cgd_supplier_name='';
                 $user= \app\admin\common\User::getIns();
         $supplier =$user->handle("getCodeAndName",["code"=>[$supplierNo,$cgd_supplier_code]]);
 
@@ -1201,27 +1240,36 @@ class Consult extends Base
         $supplier_temp =$userCommon->handle("hqInfo",["code"=>$supplierNo]);
         if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,"供应商信息未找到");
 		$supplierArr=$supplier_temp['data']??[];
-//		$supplier=$supplierArr['child']??[];
 		$goodBind=  isset($this->post['goodBind']) && !empty($this->post['goodBind']) ? $this->post['goodBind'] :[];
-				if($is_combind==1){
-					 if(empty($goodBind))$this->error('组合商品商品明细不能为空');
-//					 $spucode=makeNo('SSU');
-				}
+        if($is_combind==1){
+             if(empty($goodBind))$this->error('组合商品商品明细不能为空');
+        }
         if ($supplierArr['relation_code'] != '') {
             if ($supplierArr['relation_code'] == $zx['companyNo']) return error_show(1004, "业务公司与供应商信息一致");
-
             //判断支付渠道中是否有相关供应商
             $is_select_pay_rate = Db::name('platform')
                 ->where(['is_del' => 0, 'id' => $zx['platform_code'],"status"=>1])
                 ->value('is_select_pay_rate', 0);
             if ($is_select_pay_rate == 1) {
                if(channel_is_company($zx['platform_code'],$supplierArr['relation_code'])) return  error_show(1004, "平台渠道包含当前供应商公司{$supplierNo}");
-//
             }
         }else{
         	if($is_combind==1)$this->error('当前供应商无对应业务公司,不可选择组合商品');
         }
-
+        $tax_id = isset($this->post['tax_id'])&&$this->post['tax_id']!==''? intval($this->post['tax_id']):'';
+        $open_type= isset($this->post['open_type'])&&$this->post['open_type']!==''? intval($this->post['open_type']):'';
+        $inv_good_name = isset($this->post['inv_good_name'])&&$this->post['inv_good_name']!==''? trim($this->post['inv_good_name']):'';
+        $cgd_tax_id = isset($this->post['cgd_tax_id'])&&$this->post['cgd_tax_id']!==''? intval($this->post['cgd_tax_id']):'0';
+		$cgd_tax = isset($this->post['cgd_tax'])&&$this->post['cgd_tax']!==''? trim($this->post['cgd_tax']):'';
+        if($open_type=='') return error_show(1004,'开票商品类型不能为空');
+        if($open_type==1){
+            if($tax_id=='') return error_show(1004,'商品税目id不能为空');
+            if($inv_good_name=='') return error_show(1004,'开票商品名称不能为空');
+            if($cgd_supplier_code!=''){
+                if($cgd_tax_id==0) return error_show(1004,'源头供应商开票税目不能为空');
+                if($cgd_tax==='') return error_show(1004,'源头供应商开票税率不能为空');
+            }
+        }
         Db::startTrans();
         try{
             $data=[
@@ -1272,6 +1320,11 @@ class Consult extends Base
 		        'cgd_supplier_name'=>$cgd_supplier_name,//采购供应商编号
 		        'cgd_apply_id'=>$cgd_apply_id,//竞单人
 		        'cgd_apply_name'=>$cgd_apply_name,//竞单人
+		        'open_type'=>$open_type,
+                'inv_good_name'=>$inv_good_name,//采购商品名称
+                'tax_id'=>$tax_id,//税目id
+                'cgd_tax'=>$cgd_tax,//税目
+	            'cgd_tax_id'=>$cgd_tax_id
             ];
             $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
             if($insert){
@@ -1515,64 +1568,124 @@ class Consult extends Base
         }
     }
 
-    //选择商品
     public function bids_check(){
-        $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
-        if($bidNo===""){
-            return error_show(1004,"参数bidNo不能为空");
-        }
-        $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
-        if($info==false){
-            return error_show(1004,"未找到商品数据");
+        $params = $this->request->param(["bidNo"=>"","status"=>"","remark"=>"","out_tax_id"=>"","out_tax"=>"","goodCombind"=>[]],"post");
+        $valid = Validate::rule([
+            "bidNo|反馈单编号"=>"require",
+            "status|状态"=>"require|number",
+            "remark|备注"=>"max:255",
+            "out_tax_id|税目id"=>"requireIf:status,1|number",
+            "out_tax|税目税率"=>"requireIf:status,1",
+            "goodCombind|组合商品信息"=>"array",
+        ]);
+        if(!$valid->check($params)){
+            return error_show(1004,$valid->getError());
         }
-        $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
-        if($infos==false){
+        $info =ConsultBids::where(['bidNo'=>$params['bidNo'],"is_del"=>0])->findOrEmpty();
+        if($info->isEmpty()){
             return error_show(1004,"未找到商品数据");
         }
-
-        if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
+        $consult_info =ConsultInfo::where(['infoNo'=>$info['infoNo'],"is_del"=>0])->findOrEmpty();
+        if($consult_info->isEmpty()) $this->error("未找到商品数据");
+        if($consult_info['status']!=2&&$consult_info['status']!=3&&$consult_info['status']!=7){
             return error_show(1004,"咨询单招标未结束或已确认商品");
         }
+        $goodCombind = $params['goodCombind'];
+        if($info->is_combind==1 && $params['status']==1){
+            if(empty($goodCombind)){
+                return error_show(1004,"组合商品信息不能为空");
+            }
+            $valids = Validate::rule(["out_tax_id|税目id"=>"require|number",'out_tax|税目税率'=>'require',"id|商品id"=>"require"]);
+            foreach ($goodCombind as $k=>$v){
+                if(!$valids->check($v)){
+                    return error_show(1004,$valids->getError());
+                }
+            }
+        }
         Db::startTrans();
         try {
-                $oldstattus=$info['status'];
-                $info['status']=6;
-                $info['updatetime']=date("Y-m-d H:i:s");
-                $bids = Db::name("consult_bids")->save($info);
-                if($bids){
-                    //修改状态,添加待办
-                    ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
-                        "order_code" =>$bidNo,//咨询单详情编号
-                        "status" => $oldstattus,//这里的status是之前的值
-                        "action_remark" => '',//备注
-                        "action_type" => "status"//新建create,编辑edit,更改状态status
-                    ], "FKD", $info['status'], $info);
-                    $old_infos_status = $infos['status'];
-                    $infos['status']=4;
-                    $infos['updatetime']=date("Y-m-d H:i:s");
-                    $se = Db::name("consult_info")->save($infos);
-                    if($se){
-
-                        //修改状态,添加待办
-                        ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
-                            "order_code" => $infos['infoNo'],//咨询单详情编号
-                            "status" => $old_infos_status,//这里的status是之前的值
-                            "action_remark" => '',//备注
-                            "action_type" => "status"//新建create,编辑edit,更改状态status
-                        ], "ZXD", $infos['status'], $infos);
-                        Db::name("bargain_order")->where(["bidsNo"=>$bidNo,"is_del"=>0,"status"=>[0,2,4,5,7]])
-                        ->update(['status'=>12,"remark"=>'已选择商品,取消议价',"updatetime"=>date("Y-m-d H:i:s")]);
-                        Db::commit();
-                        return app_show(0,"商品确定成功");
-                    }
+            $oldstattus=$info->status;
+            $info->tax_status=$params['status'];
+            $info->out_tax_id=$params['out_tax_id'];
+            $info->out_tax=$params['out_tax'];
+            $info->remark=$params['remark'];
+            $save=$info->save();
+            if($save){
+                ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
+                    'order_code' =>$params['bidNo'],//咨询单详情编号
+                    'status' => $oldstattus,//这里的status是之前的值
+                    'action_remark' => '',//备注
+                    'action_type' => 'status'//新建create,编辑edit,更改状态status
+                ], 'FKD', $params['status'], $info);
+                if(!empty($goodCombind)){
+                    (new ConsultTemp())->saveAll($goodCombind);
                 }
-            Db::rollback();
-            return error_show(1004,"商品确认失败");
+            }
+            Db::commit();
+            return app_show(0,'商品确定成功');
         }catch (\Exception $e){
             Db::rollback();
             return error_show(1004,$e->getMessage());
         }
+
     }
+    //选择商品
+//    public function bids_check(){
+//        $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
+//        if($bidNo===""){
+//            return error_show(1004,"参数bidNo不能为空");
+//        }
+//        $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
+//        if($info==false){
+//            return error_show(1004,"未找到商品数据");
+//        }
+//        $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
+//        if($infos==false){
+//            return error_show(1004,"未找到商品数据");
+//        }
+//
+//        if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
+//            return error_show(1004,"咨询单招标未结束或已确认商品");
+//        }
+//        Db::startTrans();
+//        try {
+//                $oldstattus=$info['status'];
+//                $info['status']=6;
+//                $info['updatetime']=date("Y-m-d H:i:s");
+//                $bids = Db::name("consult_bids")->save($info);
+//                if($bids){
+//                    //修改状态,添加待办
+//                    ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
+//                        "order_code" =>$bidNo,//咨询单详情编号
+//                        "status" => $oldstattus,//这里的status是之前的值
+//                        "action_remark" => '',//备注
+//                        "action_type" => "status"//新建create,编辑edit,更改状态status
+//                    ], "FKD", $info['status'], $info);
+//                    $old_infos_status = $infos['status'];
+//                    $infos['status']=4;
+//                    $infos['updatetime']=date("Y-m-d H:i:s");
+//                    $se = Db::name("consult_info")->save($infos);
+//                    if($se){
+//                        //修改状态,添加待办
+//                        ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
+//                            "order_code" => $infos['infoNo'],//咨询单详情编号
+//                            "status" => $old_infos_status,//这里的status是之前的值
+//                            "action_remark" => '',//备注
+//                            "action_type" => "status"//新建create,编辑edit,更改状态status
+//                        ], "ZXD", $infos['status'], $infos);
+//                        Db::name("bargain_order")->where(["bidsNo"=>$bidNo,"is_del"=>0,"status"=>[0,2,4,5,7]])
+//                        ->update(['status'=>12,"remark"=>'已选择商品,取消议价',"updatetime"=>date("Y-m-d H:i:s")]);
+//                        Db::commit();
+//                        return app_show(0,"商品确定成功");
+//                    }
+//                }
+//            Db::rollback();
+//            return error_show(1004,"商品确认失败");
+//        }catch (\Exception $e){
+//            Db::rollback();
+//            return error_show(1004,$e->getMessage());
+//        }
+//    }
 
     //议价审核
     /**
@@ -1705,7 +1818,7 @@ class Consult extends Base
             return error_show(1004,$e->getMessage());
         }
     }
-    public  function  bargain_info(){
+    public function bargain_info(){
         $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
         if($bargainNo===""){
             return error_show(1004,"参数bargainNo不能为空");
@@ -1810,9 +1923,7 @@ class Consult extends Base
         $info['supplierNo'] =$bidinfos['supplierNo'];
         $user= \app\admin\common\User::getIns();
         $supplier_temp =$user->handle("getCodeAndName",["code"=>$info['supplierNo']]);
-//        if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception('该供应商不存在');
 		$supplier=$supplier_temp['data']??[];
-//        $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
         $info['supplier_name'] = $supplier[$info['supplierNo']]??"";
         $info['pay_way'] =$bidinfos['pay_way'];
         $info['tax'] =$bidinfos['tax'];
@@ -1853,14 +1964,14 @@ class Consult extends Base
     public function bidlist(){
         $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=[['is_del',"=",0]];
+        $where=[['a.is_del',"=",0]];
         $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
         if ($zxNo !== "") {
-            $where[] = ['zxNo','like','%'.$zxNo.'%'];
+            $where[] = ['a.zxNo','like','%'.$zxNo.'%'];
         }
         $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
         if ($infoNo !== "") {
-            $where[] = ['infoNo','like','%'.$infoNo.'%'];
+            $where[] = ['a.infoNo','like','%'.$infoNo.'%'];
         }
         $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
         if ($bidNo !== "") {
@@ -1868,49 +1979,64 @@ class Consult extends Base
         }
         $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
         if ($pgNo !== "") {
-            $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
-            $where[] = ['infoNo','in',$bidinfo];
+            $where[] = ['c.pgNo','=',$pgNo];
         }
         $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
         if ($bargain_status !== "") {
-            $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
-            $where[] = ['infoNo','in',$bidinfo];
+            $where[] = ['bargain_status','=',$bargain_status];
+        }
+        $infoStatus = isset($this->post['info_status']) && !empty($this->post['info_status'])? $this->post['info_status'] : [];
+        if (!empty($infoStatus)) {
+            $where[] = ['c.status','in',$infoStatus];
         }
         $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
         if ($projectNo !== "") {
-            $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
-            ("zxNo");
-            $where[] = ['zxNo','in',$zxlist];
+            $where[] = ['b.projectNo','=',$projectNo];
         }
         $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
         if($is_own==1){
-//             $token = isset($this->post['token']) ? trim($this->post['token']) : "";
-//            if($token==""){
-//                return error_show(101,'token不能为空');
-//            }
-//            $apply_id =GetUserInfo($token);
-//            if(empty($apply_id)||$apply_id['code']!=0){
-//                return error_show(1002,"申请人数据不存在");
-//            }
             $rm= $this->uid;//isset($apply_id["data"]['id']) ?  $apply_id["data"]['id'] : "";
-            $where[]=['createrid',"=",$rm];
+            $where[]=['a.createrid',"=",$rm];
+        }
+        $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
+        if ($status !== "") {
+            $where[] = ['a.status','=',$status];
+        }
+        $tax_status = isset($this->post['tax_status']) && $this->post['tax_status'] !== "" ? intval($this->post['tax_status']) : "";
+        if ($tax_status !== "") {
+            $where[] = ['a.tax_status','=',$tax_status];
+        }
+        $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
+        if ($companyNo !== "") {
+            $where[] = ['companyNo','=',$companyNo];
+        }
+        $goodName = isset($this->post['goodName']) && $this->post['goodName'] !== "" ? trim($this->post['goodName']) : "";
+        if ($goodName !== "") {
+            $where[] = ['a.good_name','like','%'.$goodName.'%'];
         }
 
-        $count = Db::name('consult_bids')->where($where)->count();
+        $count = Db::name('consult_bids')->alias("a")
+        ->leftJoin('consult_info c','a.infoNo=c.infoNo')
+        ->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->count();
         $total = ceil($count / $size);
         $page = $page >= $total ? $total : $page;
-        $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
+        $list =Db::name('consult_bids')->alias('a')
+        ->leftJoin('consult_info c','a.infoNo=c.infoNo')
+        ->leftJoin('consult_order b','a.zxNo=b.zxNo')
+        ->where($where)
+        ->field("a.*,b.companyNo,b.companyName,platform_code,c.num info_num,c.bargain_status,c.status info_status")
+        ->order("a.id desc")
+        ->page($page,$size)
+        ->select()
+        ->toArray();
         $data=[];
         $user= \app\admin\common\User::getIns();
         $supplier_temp =$user->handle("getCodeAndName",["code"=>array_column($list,"supplierNo")]);
-//        if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception('该供应商不存在');
 		$supplier=$supplier_temp['data']??[];
         foreach ($list as $value){
-//            $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
             $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
             $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
             $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
-//            $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
             $value['supplierName'] = isset($supplier[$value['supplierNo']])?$supplier[$value['supplierNo']]:"";
             if($value['brand_id']!=0){
                 $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
@@ -1919,11 +2045,7 @@ class Consult extends Base
                 $value["brand_name"]="";
                 $value["brand_id"]="";
             }
-            $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
-            $zx = Db::name("consult_order")->where(["zxNo"=>$value["zxNo"]])->find();
-             $budget = get_budget($value['cat_id'],$zx['companyNo']??'',$zx['platform_code']??0);
-//             if($budget===false) $this->error('未找到业务公司有关的平台分类毛利信息');
-//            $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
+             $budget = get_budget($value['cat_id'],$value['companyNo']??'',$value['platform_code']??0);
                 $god=[
                     "metal_id"=>$value['metal_id'],
                     "weight"=>$value["good_weight"],
@@ -1934,10 +2056,8 @@ class Consult extends Base
                     "mark_fee"=>$value["mark_fee"],
                     "nake_fee"=>$value["nake_fee"],
                     "cert_fee"=>$value["cert_fee"],
-              //      "cost_fee"=>$value["cost_fee"],
-                   "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
-                    //暂时注掉,搞不清楚原因@吴广广
-                    "num"=>$bidinfo["num"],
+                    "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
+                    "num"=>$value["info_num"],
                 ];
 
             $top_cat = made($value['cat_id']);
@@ -1952,7 +2072,6 @@ class Consult extends Base
             $value['cost_fee'] =$value['origin_cost_fee'];
             $value['specinfo'] = json_decode($value['specinfo'],true);
             $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
-            $value['bargain_status']=$bidinfo['bargain_status'];
 
             //reject驳回原因,status==5表示驳回
             $value['reject']=[];
@@ -1974,15 +2093,10 @@ class Consult extends Base
                 list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['origin_place']);
             }
             $value['origin_addr']=GetAddr(json_encode($place));
-//            if($value['origin_place']!=''){
-//                $code = explode(",",$value['origin_place']);
-//                $temp=[];
-//                $temp['provice_code']=isset($code[0])?$code[0]:"";
-//                $temp['city_code']=isset($code[1])?$code[1]:"";
-//                $temp['area_code']=isset($code[2])?$code[2]:"";
-//                $addr= GetAddr(json_encode($temp));
-//                $value['origin_addr'] = $addr;
-//            }
+           $tax = TaxCategory::where(['id'=>[$value['tax_id'],$value['out_tax_id'],$value["cgd_tax_id"]]])->column('short_name,cat_name,cat_code,merge_code','id');
+            $value['in_info'] = $tax[$value['tax_id']]??[];
+            $value['out_info'] = $tax[$value['out_tax_id']]??[];
+            $value['cgd_info'] = $tax[$value['cgd_tax_id']]??[];
 		$good_info = Db::name('good_basic')
             ->field('id,createrid,creater')
             ->where('is_del',0)
@@ -2143,12 +2257,6 @@ class Consult extends Base
         $companyNo = trim($this->post['companyNo'] ?? '');
         if ($companyNo !== "") $where[] = ["b.companyNo", 'like', '%' . $companyNo . '%'];
 
-//        $role=$this->checkRole();
-//        if(!empty($role['write'])){
-//            $where[]=["bo.createrid","in",$role['write']];
-//        }
-//        $role = $this->checkDataShare();
-//        if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['bo.createrid', 'in', $role[DataGroupModel::$type_全部]];
         $role = $this->checkDataShare();
         $hand = resign_hand_user($this->uid, 0);
         if (!empty($role[DataGroupModel::$type_全部])) {
@@ -2201,51 +2309,23 @@ class Consult extends Base
         $data = [];
         foreach ($list as $value) {
             $value['companyName'] = $names['data'][$value['companyNo']] ?? '';
-//           $bidinfos =   Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
-            $bidinfos = $bidinfos_list[$value['bidsNo']];
+            $bidinfos = $bidinfos_list[$value['bidsNo']]??[];
             $value['spuCode'] = isset($bidinfos['spuCode']) ? $bidinfos['spuCode'] : "";
             $value['good_name'] = isset($bidinfos['good_name']) ? $bidinfos['good_name'] : "";
             $value['good_img'] = isset($bidinfos['good_img']) ? $bidinfos['good_img'] : "";
             $value['brand_id'] = isset($bidinfos['brand_id']) ? $bidinfos['brand_id'] : "";
-            if ($bidinfos['brand_id'] != 0) {
-                $value['brand_id'] = $bidinfos['brand_id'];
-//                $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
-                $value["brand_name"] = $brand[$value['brand_id']] ?? '';//isset($brand['brand_name'])?$brand['brand_name']:"";
-            } else {
-                $value["brand_name"] = "";
-                $value["brand_id"] = "";
-            }
-//            $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
+            $value['brand_id'] = $bidinfos['brand_id']??0;
+            $value['brand_name'] = $brand[$value['brand_id']] ?? '';
             $value['can'] = isset($bidinfos['cat_id']) && $bidinfos['cat_id'] != 0 ? made($bidinfos['cat_id']) : [];
-//            $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
-            $value['unit'] = $unit[$bidinfos['unit_id']] ?? '';//isset($unit['unit'])?$unit['unit']:'';
-//            $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
-//            $budget = $cat[$bidinfos['cat_id']] ?? 0;//isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
 
-            $budget = get_budget($bidinfos['cat_id'],$value['companyNo']??'',$value['platform_code']??0);
+            $value['unit'] = $unit[$bidinfos['unit_id']??0] ?? '';//isset($unit['unit'])?$unit['unit']:'';
+
+            $budget = get_budget($bidinfos['cat_id']??0,$value['companyNo']??'',$value['platform_code']??0);
             if($budget===false) $this->error('未找到业务公司有关的平台分类毛利信息');
             $value['budget'] = $budget;
-            $god = [
-                "metal_id" => $bidinfos['metal_id'],
-                "weight" => $bidinfos["good_weight"],
-                "demo_fee" => $bidinfos["demo_fee"],
-                "delivery_fee" => $bidinfos["delivery_fee"],
-                "open_fee" => $bidinfos["open_fee"],
-                "packing_fee" => $bidinfos["pakge_fee"],
-                "mark_fee" => $bidinfos["mark_fee"],
-                "nake_fee" => $bidinfos["nake_fee"],
-                "cert_fee" => $bidinfos["cert_fee"],
-                "cost_fee" => $bidinfos["cost_fee"],
-                "num" => $value["num"],
-            ];
-//            if($bidinfos['is_gold_price']==1){
-//                $price = GoldPrice($god, $budget/100);
-//            }else{
-//                $price = GoodPrice($god, $budget/100);
-//            }
             $value['metal_name'] = isset($bidinfos['metal_id']) && $bidinfos['metal_id'] != 0 ? $this->noble[$bidinfos['metal_id']] : "";
-            $value['sale_price'] = round($bidinfos['origin_price'], 2);
-            $value['cost_before_price'] = round($bidinfos['origin_cost_fee'], 2);
+            $value['sale_price'] = round($bidinfos['origin_price']??0, 2);
+            $value['cost_before_price'] = round($bidinfos['origin_cost_fee']??0, 2);
 
             $value['specinfo'] = isset($bidinfos['specinfo']) && $bidinfos['specinfo'] != "" ? json_decode($bidinfos['specinfo'], true) : [];
             $value['company_name'] = $item[$value['createrid']] ?? '';
@@ -2259,7 +2339,6 @@ class Consult extends Base
 
         return app_show(0, "获取成功", ["count" => $count, "list" => $data]);
     }
-
     //招标工作台
     public function  crontablist(){
         $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
@@ -2365,8 +2444,6 @@ class Consult extends Base
         }
         return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
     }
-
-
     //复制上面的bidlist方法,只更改排序方式
     public function bidlistCopy()
     {
@@ -2399,13 +2476,7 @@ class Consult extends Base
         }
         $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
         if ($is_own == 1) {
-//            $token = isset($this->post['token']) ? trim($this->post['token']) : "";
-//            if ($token == "") return error_show(101, 'token不能为空');
-
-//            $apply_id = GetUserInfo($token);
-//            if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "申请人数据不存在");
-
-            $rm = $this->uid;//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
+            $rm = $this->uid;
             $where[] = ['cb.createrid', "=", $rm];
         }
         $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
@@ -2413,10 +2484,6 @@ class Consult extends Base
 
         $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
         if ($good_name !== "") $where[] = ["cb.good_name", 'like', '%' . $good_name . '%'];
-
-//        $supplierName = isset($this->post['supplierName']) && $this->post['supplierName'] !== "" ? trim($this->post['supplierName']) : "";
-//        if ($supplierName !== "") $where[] = ["s.name", 'like', '%' . $supplierName . '%'];
-
         $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
         if ($supplierNo !== "") $where[] = ["cb.supplierNo", '=', $supplierNo];
 
@@ -2425,13 +2492,10 @@ class Consult extends Base
 
         $companyNo = $this->post['companyNo']??'';
         if($companyNo!='') $where[]=['d.companyNo','like','%' .$this->post['companyNo']. '%'];
-        //Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
-
         $count = Db::name('consult_bids')
             ->alias('cb')
             ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
             ->leftJoin("consult_order d", "d.zxNo=c.zxNo")
-//            ->leftJoin('supplier s', 's.code=cb.supplierNo')
             ->where($where)
             ->count();
 
@@ -2442,7 +2506,6 @@ class Consult extends Base
             ->field('cb.*,d.companyNo,d.platform_code,d.area')
             ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
             ->leftJoin("consult_order d", "d.zxNo=c.zxNo")
-//            ->leftJoin('supplier s', 's.code=cb.supplierNo')
             ->where($where)
             ->page($page, $size)
             ->order('cb.addtime', 'desc')
@@ -2451,7 +2514,6 @@ class Consult extends Base
         $data = [];
         $user= \app\admin\common\User::getIns();
         $supplier_temp =$user->handle("getCodeAndName",["code"=>array_unique(array_merge(array_column($list,"supplierNo"),array_column($list,"companyNo")))]);
-//        if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception('该供应商不存在');
 		$supplier=$supplier_temp['data']??[];
 
 		$unit=Db::name('unit')
@@ -2466,24 +2528,13 @@ class Consult extends Base
 
         foreach ($list as $value) {
             if(!isset($tmp_cat[$value['cat_id']])) $tmp_cat[$value['cat_id']] =made($value['cat_id']);
-//            $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
             $value['can'] = $tmp_cat[$value['cat_id']]??[];//isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
-//            $unit = Db::name("unit")->where(["id" => $value['unit_id']])->find();
             $value['unit'] = $unit[$value['unit_id']]??'';//isset($unit['unit']) ? $unit['unit'] : '';
-//            $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
             $value['supplierName'] = isset($supplier[$value['supplierNo']]) ? $supplier[$value['supplierNo']] : "";
             $value['companyName'] = $supplier[$value['companyNo']]??'';
-//            if ($value['brand_id'] != 0) {
-//                $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
             $value["brand_name"] = $brand[$value['brand_id']] ?? '';//isset($brand['brand_name']) ? $brand['brand_name'] : "";
-//            } else {
-//                $value["brand_name"] = "";
-//                $value["brand_id"] = "";
-//            }
             $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
-//            $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
             $budget = get_budget((int)$value['cat_id'], $value['companyNo'], (int)$value['platform_code']);
-//           if($budget===false) $this->error('未找到业务公司有关的平台分类毛利信息');
             $god = [
                 "metal_id" => $value['metal_id'],
                 "weight" => $value["good_weight"],
@@ -2526,15 +2577,6 @@ class Consult extends Base
                 list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
             }
             $value['origin_addr'] = GetAddr(json_encode($place));
-//            if($value['origin_place']!=''){
-//                $code = explode(",",$value['origin_place']);
-//                $temp=[];
-//                $temp['provice_code']=isset($code[0])?$code[0]:"";
-//                $temp['city_code']=isset($code[1])?$code[1]:"";
-//                $temp['area_code']=isset($code[2])?$code[2]:"";
-//                $addr= GetAddr(json_encode($temp));
-//                $value['origin_addr'] = $addr;
-//            }
             $value['company_name'] = $item[$value['createrid']]??'';
 
             $data[] = $value;

+ 26 - 6
app/admin/controller/Good.php

@@ -5,7 +5,7 @@ namespace app\admin\controller;
 
 use app\admin\model\DataGroup as DataGroupModel;
 use app\admin\model\GoodCombind;use app\admin\model\GoodLog;
-use app\admin\model\GoodStock;use app\txx\model\ActGoodurl;use app\txx\model\YzGood;
+use app\admin\model\GoodStock;use app\admin\model\GoodTax;use app\txx\model\ActGoodurl;use app\txx\model\YzGood;
 use think\App;
 use think\db\Raw;
 use think\facade\Db;
@@ -17,7 +17,6 @@ class Good extends Base
 
     private $acton=[];
     public $noble=[];
-  # public $white = ['*'];
     public function __construct(App $app)
     {
         parent::__construct($app);
@@ -302,7 +301,6 @@ class Good extends Base
         $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) {
@@ -343,7 +341,13 @@ class Good extends Base
             $value['specinfo'] = $speclist;
             $value['noble_name'] = isset($value['noble_metal']) && $value['noble_metal'] != 0 ? $this->noble[$value['noble_metal']] : "";
             $value['company_name'] = $item[$value['createrid']]??'';
-
+            $taxInfo=GoodTax::with(['tax'])->where(['spuCode'=>$value['spuCode']])->findOrEmpty();
+            $value['tax_id'] = $taxInfo['tax_id']??'';
+            $value['tax_name'] = $taxInfo['cat_name']??'';
+            $value['tax_short_name'] =$taxInfo['short_name']??'';
+            $value['tax_code'] =$taxInfo['merge_code']??'';
+            $value['tax']=$taxInfo['tax']??'';
+            $value['inv_good_name']=$taxInfo['inv_good_name']??'';
             //是否具有编辑权限
             $value['is_allow_update'] = 0;
 //            if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
@@ -394,15 +398,17 @@ class Good extends Base
         $supplier = $userCommon->handle('sInfo',['code'=>$data['supplierNo']]);
         $data['supplierName'] = $names['data'][$data['supplierNo']]??'';//isset($supplier['name'])?$supplier['name']:"";
         $data['company'] = $names['data'][$data['companyNo']]??'';//isset($company['company'])?$company['company']:"";
-
+        $data['tax_info']=GoodTax::with(['Tax','OutTax',"CgdTax"])->where(['spuCode'=>$good_platform['spuCode']])->findOrEmpty();
         $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
         $data['combind_list']=[];
         $data['wsm_list']=[];
         $data['is_combind_child']=true;
-		 if($data['is_combind']==1){
+		if($data['is_combind']==1){
         	$data['combind_list'] = (new GoodCombind())->where(['spuCode'=>$good_platform['spuCode'],'is_del'=>0])->select()->toArray();
         	foreach ($data['combind_list'] as &$item){
         		$item['stock'] =bcmul($item['child_num'],$data['usable_stock']);
+        		$taxInfo=GoodTax::with(['Tax','OutTax','CgdTax'])->where(['spuCode'=>$item['childCode']])->findOrEmpty();
+        		$item['tax_info'] = $taxInfo;
         	}
         	  $data['wsm_list']=(new GoodStock())->withJoin(['wsminfo'] , 'left')
 	                                           ->where(['spuCode'=>$good_platform['spuCode'] , 'wsm_type'=>[2 , 5]])
@@ -1358,6 +1364,20 @@ class Good extends Base
     public function getCombind(){
         $param= $this->request->param(['spuCode'=>'',"isZx"=>""],'post','trim');
 		$list = (new GoodCombind())->with([$param['isZx']==1?"goodZx":"goodBasic"])->where('spuCode',$param['spuCode'])->select();
+		foreach ($list as &$item){
+			    $taxInfo=GoodTax::with(['Tax','OutTax','CgdTax'])->where(['spuCode'=>$item['childCode']])->findOrEmpty();
+                $item['in_tax_name'] = $taxInfo->in_tax_name??'';
+                $item['in_tax_code'] = $taxInfo->in_tax_code??'';
+                $item['in_tax_short'] = $taxInfo->in_tax_short??'';
+                $item['in_tax_merge'] = $taxInfo->in_tax_merge??'';
+                $item['in_tax'] = $taxInfo->tax??'';
+                $item['out_tax_name'] = $taxInfo->out_tax_name??'';
+                $item['out_tax_code'] = $taxInfo->out_tax_code??'';
+                $item['out_tax_short'] = $taxInfo->out_tax_short??'';
+                $item['out_tax_merge'] = $taxInfo->out_tax_merge??'';
+                $item['out_tax'] = $taxInfo->out_tax??'';
+                $item['inv_good_name'] = $taxInfo->inv_good_name;
+		}
 		$this->success('获取成功',$list);
     }
 }

+ 113 - 29
app/admin/controller/Goodup.php

@@ -5,7 +5,7 @@ namespace app\admin\controller;
 use app\admin\model\ActionLog;
 use app\admin\model\ChangeLog;
 use app\admin\model\DataGroup as DataGroupModel;
-use app\admin\model\GoodBasic;use app\admin\model\GoodCombind;use app\admin\model\GoodStock;use app\admin\model\ProcessOrder;
+use app\admin\model\GoodBasic;use app\admin\model\GoodCombind;use app\admin\model\GoodStock;use app\admin\model\GoodTax;use app\admin\model\ProcessOrder;
 use app\youzan\model\PlatformYouzan;
 use think\App;
 use think\Exception;
@@ -492,12 +492,10 @@ class Goodup extends Base
 	        $cgd_supplier_code =  isset($this->post['cgd_supplier_code'])&&$this->post['cgd_supplier_code']!=''? trim($this->post['cgd_supplier_code']):'';
 	        $cgd_apply_id =  isset($this->post['cgd_apply_id'])&&$this->post['cgd_apply_id']!=''? trim($this->post['cgd_apply_id']):'';
 	        $cgd_apply_name =  isset($this->post['cgd_apply_name'])&&$this->post['cgd_apply_name']!=''? trim($this->post['cgd_apply_name']):'';
-//	        $supplier_origin_price =  isset($this->post['supplier_origin_price'])&&$this->post['supplier_origin_price']!=''? floatval($this->post['supplier_origin_price']):'';
-	        $cgd_supplier_name='';
+            $cgd_supplier_name='';
 	        if(isset($supplierArr['relation_code']) && $supplierArr['relation_code']!='' && $isCombind==0){
 	            if($cgd_supplier_code=="")return error_show(1004,'采购供应商信息不能为空');
 	            if($cgd_apply_id=="")return error_show(1004,'采购竞单人信息不能为空');
-//	            if($supplier_origin_price==="")return error_show(1004,'采购供应商信息采购成本不能为空');
 	              $cgd_supplier =$userCommon->handle('getCodeAndName',['code'=>$cgd_supplier_code]);
 		          $cgd_supplier_name= $cgd_supplier['data'][$cgd_supplier_code]??'';
 	        }
@@ -582,8 +580,7 @@ class Goodup extends Base
         if($is_stock===""){
             return error_show(1004,"参数is_stock不能为空");
         }
-        // $stock_moq=0 ;//库存品备库起订量; 如果是0 表示无限制;
-         $stock_moq = isset($this->post['stock_moq'])&&$this->post['stock_moq']!==""? intval($this->post['stock_moq']):"0";
+        $stock_moq = isset($this->post['stock_moq'])&&$this->post['stock_moq']!==""? intval($this->post['stock_moq']):"0";
         if($is_stock==1 && $stock_moq ==0){
             return error_show(1004,"库存品备库起订量不能为零");
         }
@@ -618,12 +615,24 @@ class Goodup extends Base
             return error_show(1004,"参数market_price不能为空");
         }
         $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"0";
-        
+        $cgd_tax_id = isset($this->post['cgd_tax_id'])&&$this->post['cgd_tax_id']!==''? intval($this->post['cgd_tax_id']):'0';
+        $cgd_tax = isset($this->post['cgd_tax'])&&$this->post['cgd_tax']!==''? trim($this->post['cgd_tax']):'';
         $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
         $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
         $is_support_barter = isset($this->post['is_support_barter']) && $this->post['is_support_barter'] !== "" ? intval($this->post['is_support_barter']) : 1;
         $combindList = $this->post["combind_list"]??[];
-		
+        $tax_id = isset($this->post['tax_id'])&&$this->post['tax_id']!==''? intval($this->post['tax_id']):'';
+        $open_type= isset($this->post['open_type'])&&$this->post['open_type']!==''? intval($this->post['open_type']):'';
+        $inv_good_name = isset($this->post['inv_good_name'])&&$this->post['inv_good_name']!==''? trim($this->post['inv_good_name']):'';
+        if($open_type=='') return error_show(1004,'开票商品类型不能为空');
+			if($open_type==1){
+				if($tax_id=='') return error_show(1004,'商品税目id不能为空');
+				if($inv_good_name=='') return error_show(1004,'开票商品名称不能为空');
+				if($cgd_supplier_code!=''){
+                    if($cgd_tax_id==0) return error_show(1004,'源头供应商开票税目不能为空');
+                    if($cgd_tax==='') return error_show(1004,'源头供应商开票税率不能为空');
+                }
+			}
         $createrid= $this->uid;
         $creater= $this->uname;
         $spucode=makeNo("SKU");
@@ -638,6 +647,7 @@ class Goodup extends Base
 				$value['good_name'] =$good_name;
 				$dchild[]=$value;
 			}
+
 		}
         Db::startTrans();
         try {
@@ -700,6 +710,7 @@ class Goodup extends Base
                 "is_step" => count($good_ladder) > 1 ? 1 : 0,//如果阶梯价个数大于1,说明启用阶梯价
                 "is_online"=>0,
                 "stock_moq"=>$stock_moq,
+                'open_type'=>$open_type,
                 "status"=>0,
                 "createrid"=>$createrid,
                 "creater"=>$creater,
@@ -791,6 +802,21 @@ class Goodup extends Base
 				if($isCombind==1 && !empty($dchild)){
 					 (new GoodCombind())->saveAll($dchild);
 				}
+				if($open_type==1||$tax_id>0){
+				    $data = [
+				        'spuCode'=>$spucode,
+				        'open_type'=>$open_type,
+				        "companyNo"=>$company_id,
+				        'tax_id'=>$tax_id,
+				        'inv_good_name'=>$inv_good_name,
+				        "cgd_tax_id"=>$cgd_tax_id,
+				        "cgd_tax"=>$cgd_tax,
+				        'tax'=>$tax,
+				        "creater"=>$creater,
+				        "createrid"=>$createrid,
+				    ];
+                    GoodTax::create($data);
+				}
                 //修改状态,添加待办
                 ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
                     "order_code" =>$spucode,//咨询单详情编号
@@ -919,9 +945,6 @@ class Goodup extends Base
             return error_show(1004,"参数is_auth不能为空");
         }
         $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
-//        if($auth_img==''){
-//            return error_show(1004,"商品不能为空");
-//        }
         $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
         if($after_sales==""){
             return error_show(1004,"参数after_sales不能为空");
@@ -1000,7 +1023,15 @@ class Goodup extends Base
         $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!=""? trim($this->post['proof_type']):"";
         $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!=""? trim($this->post['proof_url']):"";
         $combindList = $this->post['combind_list']??[];
-		 if($isCombind==1){
+        $tax_id = isset($this->post['tax_id'])&&$this->post['tax_id']!==''? intval($this->post['tax_id']):'';
+        $open_type= isset($this->post['open_type'])&&$this->post['open_type']!==''? intval($this->post['open_type']):'';
+        $inv_good_name = isset($this->post['inv_good_name'])&&$this->post['inv_good_name']!==''? trim($this->post['inv_good_name']):'';
+        if($open_type=='') return error_show(1004,'开票商品类型不能为空');
+        if($open_type==1){
+            if($tax_id=='') return error_show(1004,'商品税目id不能为空');
+            if($inv_good_name=='') return error_show(1004,'开票商品名称不能为空');
+        }
+        if($isCombind==1){
 			if(empty($combindList)) return error_show(1004,'组合商品子商品信息不能为空');
 			$dchild=[];
 			$valid = Validate::rule(['childCode|子商品成本编号'=>'require','child_name|子商品名称'=>'require','child_num|组合比例'=>'require|number|gt:0']);
@@ -1059,6 +1090,7 @@ class Goodup extends Base
                 "stock_moq" => $stock_moq,
                 "good_thumb_img"=>$good_thumb_img,
                 "good_info_img"=>$good_info_img,
+                 'open_type'=>$open_type,
                 "status"=>$count>0?2:1,
                 "updatetime" => date("Y-m-d H:i:s"),
                 'is_combind'=>$isCombind,
@@ -1113,6 +1145,18 @@ class Goodup extends Base
 			if($isCombind==1 && !empty($dchild)){
 					 (new GoodCombind())->saveAll($dchild);
 			}
+			if($open_type==1||$tax_id>0){
+			    $taxInfo = GoodTax::where('spuCode',$supcode)->findOrEmpty();
+			    $taxInfo->spuCode = $supcode;
+			    $taxInfo->companyNo = $company_id;
+			    $taxInfo->open_type = $open_type;
+			    $taxInfo->tax_id = $tax_id;
+			    $taxInfo->inv_good_name = $inv_good_name;
+			    $taxInfo->tax = $tax;
+			    $taxInfo->creater = $this->uname;
+			    $taxInfo->createrid =$this->uid;
+			    $taxInfo->save();
+			}
                 //修改状态,添加待办
                 ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
                     "order_code" =>$supcode,//咨询单详情编号
@@ -1306,7 +1350,13 @@ class Goodup extends Base
         if($token==''){
             return error_show(105,"参数token不能为空");
         }
+        $out_tax = isset($this->post['out_tax'])&&$this->post['out_tax']!=="" ? trim($this->post['out_tax']):"";
+        $out_tax_id = isset($this->post['out_tax_id'])&&$this->post['out_tax_id']!=="" ? trim($this->post['out_tax_id']):0;
+        if($out_tax_id>0){
+           $goodTax= GoodTax::where("spuCode","=",$supcode)->findOrEmpty();
+           if($goodTax->isEmpty()) $this->error("商品进项税目未设置");
 
+        }
         $createrid=$this->uid;
         $creater= $this->uname;
         Db::startTrans();
@@ -1344,18 +1394,17 @@ class Goodup extends Base
                 }
             }
 
-//            if ($status == 1) {
-//                //把同一个spuCode,且状态为1待完善成本,的记录更改状态为2待产品审核
-//                Db::name('good')
-//                    ->where(['is_del' => 0, 'status' => 1])
-//                    ->whereIn('spuCode', $supcode)
-//                    ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
-//            }
             $old_status = $data['status'];
             $data['status']=$status;
             $data['updatetime']=date("Y-m-d H:i:s");
             $up= Db::name("good_basic")->save($data);
             if($up){
+                if($out_tax_id>0){
+                    $goodTax->out_tax_id=$out_tax_id;
+                    $goodTax->out_tax=$out_tax;
+                    $goodTax->status=2;
+                    $goodTax->save();
+                }
                 //修改状态,添加待办
                 ActionLog::logAdd($this->post['token'], [
                     "order_code" =>$supcode,//咨询单详情编号
@@ -1430,8 +1479,7 @@ class Goodup extends Base
 	                                           ->where(['spuCode'=>$supcode , 'wsm_type'=>[2 , 5]])
 	                                           ->column('good_stock.id stock_id,name,good_stock.wsm_code,usable_stock');
         }
-       
-
+        $data['tax_info']=GoodTax::with(['Tax','OutTax',"CgdTax"])->where(['spuCode'=>$supcode])->findOrEmpty();
         $data['field_change'] = $data['field_change']!=''?json_decode($data['field_change']):"";
         if($data['brand_id']!=0){
             $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
@@ -2156,6 +2204,7 @@ class Goodup extends Base
         	    }
         	}
         }
+
         if(!empty($nake)){
             foreach ($nake as $value){
                     $tmp=[];
@@ -2237,6 +2286,16 @@ class Goodup extends Base
                         throw new \Exception("组合商子商品品信息复制失败");
                     }
                 }
+                if($data['open_type']==1){
+                    $taxinfo=GoodTax::where(["spuCode"=>$supcode])->findOrEmpty();
+                    if(!$taxinfo->isEmpty()){
+                        unset($taxinfo['id']);
+                        $taxinfo['spuCode']=$newCode;
+                        $taxinfo['creater_id']=$createrid;
+                        $taxinfo['creater']=$creater;
+                        GoodTax::create($taxinfo->toArray());
+                    }
+                }
                 Db::commit();
                 return app_show(0,"复制数据成功",["spuCode"=>$newCode]);
             }else{
@@ -2265,8 +2324,8 @@ class Goodup extends Base
         if($is_down!=false){
             return error_show(1004,"存在未下线商品数据");
         }
-        if ($data['status'] != 6 && $data['status'] != 7 && $data['status'] != 8) {
-            return error_show(1004,"商品状态有误");
+        if(!in_array($data['status'],[6,7,8,10])){
+           return error_show(1004,'商品状态有误');
         }
         $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
         if($good_name==""){
@@ -2305,10 +2364,6 @@ class Goodup extends Base
         if($is_exclusive===''){
             return error_show(1004,"参数is_exclusive不能为空");
         }
-//        $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
-//        if($customized===''){
-//            return error_show(1004,"参数customized不能为空");
-//        }
         $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
         if($tax===''){
             return error_show(1004,"参数tax不能为空");
@@ -2463,6 +2518,20 @@ class Goodup extends Base
 		$proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!=""? trim($this->post['proof_type']):"";
         $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!=""? trim($this->post['proof_url']):"";
 		$combindList = $this->post['combind_list']??[];
+		$tax_id = isset($this->post['tax_id'])&&$this->post['tax_id']!==''? intval($this->post['tax_id']):'';
+        $open_type= isset($this->post['open_type'])&&$this->post['open_type']!==''? intval($this->post['open_type']):'';
+        $inv_good_name = isset($this->post['inv_good_name'])&&$this->post['inv_good_name']!==''? trim($this->post['inv_good_name']):'';
+        $cgd_tax_id = isset($this->post['cgd_tax_id'])&&$this->post['cgd_tax_id']!==''? intval($this->post['cgd_tax_id']):'0';
+        $cgd_tax = isset($this->post['cgd_tax'])&&$this->post['cgd_tax']!==''? trim($this->post['cgd_tax']):'';
+        if($open_type=='') return error_show(1004,'开票商品类型不能为空');
+            if($open_type==1){
+                if($tax_id=='') return error_show(1004,'商品税目id不能为空');
+                if($inv_good_name=='') return error_show(1004,'开票商品名称不能为空');
+                if($cgd_supplier_code!=''){
+                    if($cgd_tax_id==0) return error_show(1004,'源头供应商开票税目不能为空');
+                    if($cgd_tax==='') return error_show(1004,'源头供应商开票税率不能为空');
+                }
+            }
 		 if($isCombind==1){
 			if(empty($combindList)) return error_show(1004,'组合商品子商品信息不能为空');
 			$dchild=[];
@@ -2536,13 +2605,14 @@ class Goodup extends Base
                 "cgd_gold_price"=>$cgd_gold_price,
                 "is_step" => count($good_ladder) > 1 ? 1 : 0,
                 "stock_moq"=>$stock_moq,
+                "open_type"=>$open_type,
                 "status"=>"0",
                 'is_combind'=>$isCombind,
                 "updatetime"=>date("Y-m-d H:i:s"),
                 'is_support_barter'=>$is_support_barter,
                 'chargerid' => $supplier['personid'] ?? $this->uid,
                 'charger' => $supplier['person'] ?? $this->uname,
-                 'cgd_supplier_code'=>$cgd_supplier_code,//采购供应商编号
+                'cgd_supplier_code'=>$cgd_supplier_code,//采购供应商编号
                 'cgd_supplier_name'=>$cgd_supplier_name,//采购供应商编号
                 'cgd_apply_id'=>$cgd_apply_id,//竞单人
                 'cgd_apply_name'=>$cgd_apply_name,//竞单人
@@ -2632,7 +2702,21 @@ class Goodup extends Base
                 }
 				if($isCombind==1 && !empty($dchild)){
 					 (new GoodCombind())->saveAll($dchild);
-			}
+			    }
+                if($open_type==1||$tax_id>0){
+                    $taxInfo = GoodTax::where('spuCode',$supcode)->findOrEmpty();
+                    $taxInfo->spuCode = $supcode;
+                    $taxInfo->companyNo = $company_id;
+                    $taxInfo->open_type = $open_type;
+                    $taxInfo->tax_id = $tax_id;
+                    $taxInfo->inv_good_name = $inv_good_name;
+				    $taxInfo->cgd_tax_id = $cgd_tax_id;
+                    $taxInfo->cgd_tax = $cgd_tax;
+                    $taxInfo->tax = $tax;
+                    $taxInfo->creater = $this->uname;
+                    $taxInfo->createrid =$this->uid;
+                    $taxInfo->save();
+                }
                 Db::commit();
                 return app_show(0,"更新成功");
             }else{

+ 0 - 5
app/admin/controller/OrderOutChild.php

@@ -161,16 +161,11 @@ class OrderOutChild extends Base
             ->where($condition)
             ->select()
             ->toArray();
-
-//        $all_apply_id = array_column($list, 'apply_id');
-//        $company_name = get_company_name_by_uid($all_apply_id);
-
         //校验是否开通了供应商账号
         $supp_account = checkHasAccountBySupplierNos(array_unique(array_column($list, 'supplierNo')));
 
         $data = [];
         foreach ($list as $value) {
-//            $value['company_name'] = $company_name[$value['apply_id']] ?? '';
             $value['has_account'] = (int)isset($supp_account[$value['supplierNo']]);
             $data[] = $value;
         }

+ 8 - 1
app/admin/controller/Purch.php

@@ -6,7 +6,7 @@ namespace app\admin\controller;
 
 use app\admin\model\ActionLog;
 use app\admin\model\CgdPrice;use app\admin\model\DataGroup as DataGroupModel;
-use app\admin\model\ProcessOrder;
+use app\admin\model\GoodTax;use app\admin\model\OrderTax;use app\admin\model\ProcessOrder;
 use think\App;
 use think\Exception;
 use think\facade\Db;
@@ -284,6 +284,13 @@ class Purch extends Base
         if (empty($goon)) {
             return error_show(1002, "未找到商品数据");
         } else {
+         $taxInfo=OrderTax::where(['code'=>$data['cgdNo']])->findOrEmpty();
+         $data['tax_name'] = $taxInfo['tax_name']??'';
+         $data['tax_code'] =$taxInfo['tax_code']??'';
+          $data['tax_short_name'] =$taxInfo['tax_short_name']??'';
+         $data['tax']=$taxInfo['inv_tax']??'';
+         $data['inv_good_name']=$taxInfo['inv_good_name']??'';
+
             $goon['exclusive'] = isset($goon['is_exclusive']) ? makeExcluse($goon['is_exclusive']) : "";
             $unit = Db::name("unit")->where(["id" => $goon['good_unit']])->find();
             $goon['unit'] = isset($unit['unit']) ? $unit['unit'] : '';

+ 18 - 5
app/admin/controller/Resign.php

@@ -8,7 +8,7 @@ namespace app\admin\controller;
 use app\admin\model\ActionLog;
 use app\admin\model\DataGroup as DataGroupModel;
 use app\admin\model\GoodLog;
-use app\admin\model\ProcessOrder;
+use app\admin\model\OrderTax;use app\admin\model\ProcessOrder;
 use think\facade\Cache;
 use think\facade\Config;
 use think\facade\Db;
@@ -915,7 +915,7 @@ class Resign extends Base
             $sale_price = $goodnake['nake_total'];
             $total_price = round($info['good_num']*$sale_price,2);
         }
-         $cgd_origin_price = $goodnake['supplier_origin_price']??0;
+       $cgd_origin_price = $goodnake['supplier_origin_price']??0;
         $cgdCode = makeNo("CG");
         $cg =["cgdNo"=>$cgdCode,
             "bkcode"=>$bk_code,
@@ -1048,12 +1048,25 @@ class Resign extends Base
                             ], JSON_UNESCAPED_UNICODE);
 //                            Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
 
-                            Db::commit();
-                            return app_show(0, "采购单新建成功", ["cgdNo" => $cgdCode]);
                         }
 
                     }
-//                    }
+                 $taxInfo = OrderTax::SpuCat($info['spuCode'],1,1);
+                if (!empty($taxInfo)) {
+                   (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($cgdCode){
+                        $temp=[];
+                        $temp['code']=$cgdCode;
+                        $temp['spuCode']=$item['spuCode'];
+                        $temp['tax_code']=$item['cat_code'];
+                        $temp['tax_name']=$item['cat_name'];
+                        $temp['tax_short_name']=$item['short_name'];
+                        $temp['inv_tax']=$item['tax'];
+                        $temp['inv_good_name']=$item['inv_good_name'];
+                        return $temp;
+                   },$taxInfo));
+                 }
+                   Db::commit();
+                 return app_show(0, '采购单新建成功', ['cgdNo' => $cgdCode]);
                 }
                 Db::rollback();
                 return error_show(1004,"采购单新建失败");

+ 188 - 89
app/admin/controller/Sale.php

@@ -2,17 +2,20 @@
 
 namespace app\admin\controller;
 
-use app\abutment\model\SupplierRelationUser;
-use app\abutment\model\SupplierUser;
-use app\admin\model\CgdPrice;use app\admin\model\ConsultTemp;use app\admin\model\DataGroup as DataGroupModel;
+use app\admin\model\ConsultTemp;
+use app\admin\model\DataGroup as DataGroupModel;
 use app\admin\model\GoodLog;
-use app\admin\model\GoodPlatform;use app\admin\model\GoodStockInfo;
-use app\admin\model\OrderOutChild;use app\admin\model\ProcessOrder;
-use app\admin\model\SaleCgdPrice;use app\admin\model\SaleInfo;
-use app\bbc\model\BbcFill;use Exception;
+use app\admin\model\GoodPlatform;
+use app\admin\model\GoodStockInfo;
+use app\admin\model\GoodTax;
+use app\admin\model\OrderOutChild;
+use app\admin\model\OrderTax;
+use app\admin\model\ProcessOrder;
+use app\admin\model\SaleCgdPrice;
+use app\bbc\model\BbcFill;
+use app\model\TaxCategory;
+use Exception;
 use think\App;
-use think\facade\Cache;
-use think\facade\Config;
 use think\facade\Db;
 use app\admin\model\ActionLog;
 use think\facade\Validate;
@@ -191,9 +194,10 @@ class Sale extends Base
             "createrid" =>$holder_id,
             "creater" =>$holder_name,
             'send_way' => 2,
+            "open_type"=>$ct['open_type'],
             'good_createrid' => $goodinfo['createrid'],
             'good_creater' => $goodinfo['creater'],//商品创建人
-             'supplier_origin_price'=>$cgd_origin_price,//供应商采购成本
+            'supplier_origin_price'=>$cgd_origin_price,//供应商采购成本
 	        'cgd_supplier_code'=>$goodinfo['cgd_supplier_code'],//采购供应商编号
 	        'cgd_supplier_name'=>$goodinfo['cgd_supplier_name'],//采购供应商编号
 	        'cgd_apply_id'=>$goodinfo['cgd_apply_id'],//竞单人
@@ -259,6 +263,8 @@ class Sale extends Base
                 'diff_weight' => 0,
                 'diff_fee' => 0,
                 "workNo" => $workNo,
+                "use_order"=>$this->post['useid']??0,
+                'open_type'=>$ct['open_type'],
                 "addtime" => date("Y-m-d H:i:s"),
                 "updatetime" => date("Y-m-d H:i:s"),
                 'total_price' => round($sale_price * $good_num, 2),
@@ -273,6 +279,21 @@ class Sale extends Base
             $paytime == "" ? "" : $data['paytime'] = $paytime;
             $datainfo = Db::name('sale')->insert($data, true);
             if ($datainfo > 0) {
+                $taxInfo = OrderTax::SpuCat($spuCode);
+                if (!empty($taxInfo)) {
+
+                   (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($orderCode){
+                        $temp=[];
+                        $temp['code']=$orderCode;
+                        $temp['spuCode']=$item['spuCode'];
+                        $temp['tax_code']=$item['cat_code'];
+                        $temp['tax_name']=$item['cat_name'];
+                        $temp['tax_short_name']=$item['short_name'];
+                        $temp['inv_tax']=$item['tax'];
+                        $temp['inv_good_name']=$item['inv_good_name'];
+                        return $temp;
+                   },$taxInfo));
+                 }
                 //修改状态,添加待办
                 ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
                     "order_code" => $orderCode,//销售单code
@@ -557,6 +578,7 @@ class Sale extends Base
             "status" => 0,//0初始化
             "lasttime" => date("Y-m-d H:i:s"),
             "is_del" => 0,
+            'open_type'=>$data['open_type'],
             "order_type" => $data['order_type'],
             "order_source" => $data['order_source'],
             "good_type" => $data['good_type'],
@@ -573,6 +595,20 @@ class Sale extends Base
         ];
         $up = Db::name("purchease_order")->insert($cg, true);
         if ($up) {
+             $taxInfo = OrderTax::SpuCat($data['spuCode'],1,1);
+                if (!empty($taxInfo)) {
+                   (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($cgdCode){
+                        $temp=[];
+                        $temp['code']=$cgdCode;
+                        $temp['spuCode']=$item['spuCode'];
+                        $temp['tax_code']=$item['cat_code'];
+                        $temp['tax_name']=$item['cat_name'];
+                        $temp['tax_short_name']=$item['short_name'];
+                        $temp['inv_tax']=$item['tax'];
+                        $temp['inv_good_name']=$item['inv_good_name'];
+                        return $temp;
+                   },$taxInfo));
+                 }
             //修改状态,添加待办
             ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
                 "order_code" => $cg['cgdNo'],//销售单code
@@ -673,16 +709,9 @@ class Sale extends Base
             return error_show(1004, "参数addrlist不能为空");
         }
 
-//        $userCommon = \app\admin\common\User::getIns();
         Db::startTrans();
         try {
-//            $GoodModel = Db::name("good");
-//            if (in_array($etid['order_type'], [3, 4])) {
-//                $GoodModel = Db::name("good_zixun");
-//            }
-//			$goodStock=$GoodModel->where(["spuCode"=>$etid['good_code']])->lock(true)->findOrEmpty();
             $i = 1;
-//        	$goodStock_num =$goodStock['usable_stock']??0;
             $total_num = array_sum(array_column($addrlist, "receipt_quantity"));
             $goodStock_num = Db::name('good_stock')->alias("a")
                         ->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")
@@ -878,6 +907,9 @@ class Sale extends Base
         $zxinfo = Db::name("consult_bids")->where(["bidNo" => $bidNo, "is_del" => 0])->find();
         if ($zxinfo == false) {
             return error_show(1003, "未找到咨询单商品信息");
+        }
+        if ($zxinfo['tax_status'] !=1) {
+            return error_show(1003, "咨询单商品财务未审核通过");
         }
 		$bargaininfo =Db::name("bargain_order")->where(["bidsNo" => $bidNo,"is_del"=>0,"status"=>0])->findOrEmpty();
         $zx = Db::name("consult_info")->where(["infoNo" => $zxinfo['infoNo'], "is_del" => 0])->find();
@@ -950,6 +982,7 @@ class Sale extends Base
             "createrid" =>$supplier_temp_info['personid'],
             "creater" =>$supplier_temp_info['person'],
             "good_type" => 1,
+            "open_type"=>$zxinfo["open_type"],
             "weight" => $zxinfo['good_weight'],
             "gold_price" => $zxinfo['gold_price'],
             "is_diff" => $zxinfo['is_diff'],
@@ -1058,7 +1091,9 @@ class Sale extends Base
                 'gold_price' => $zxinfo['gold_price'],
                 'cost_price' => $zxinfo['sale_cost_fee'],
                 'diff_weight' => 0,
+                'open_type'=>$zxinfo['open_type'],
                 'diff_fee' => 0,
+                'use_order'=>$this->post['useid']??0,
                 "addtime" => date("Y-m-d H:i:s"),
                 "updatetime" => date("Y-m-d H:i:s"),
                 'total_price' => round($sale_price * $good_num, 2),
@@ -1072,7 +1107,6 @@ class Sale extends Base
             ];
             $datainfo = Db::name('sale')->insert($data, true);
             if ($datainfo > 0) {
-
                 $standing_book_data = [
                     'sale_id' => $datainfo,
                     'infoNo' => $zxinfo['infoNo'],
@@ -1110,11 +1144,6 @@ class Sale extends Base
                     ], "ZXD", 5, $zx);
 
                 }
-                $bol = $this->createCgd($cgd, $standing_book_data);
-                if ($bol == false) {
-                    Db::rollback();
-                    return error_show(1002, "咨询订单创建失败");
-                }
                 $limt = [
                     "spuCode" => $zxinfo['spuCode'],
                     "good_name" => $zxinfo['good_name'],
@@ -1148,8 +1177,10 @@ class Sale extends Base
                     "send_way" => $zxinfo['send_way'],
                     "companyNo" => $companyNo,
                     "companyName" =>$companyinfo['data'][$companyNo]??"",
+                    'sale_price' => $sale_price,
                     "status" => 1,
                     "is_combind" => $zxinfo['is_combind'],
+                    "open_type"=>$zxinfo['open_type'],
                     "is_del" => 0,
                     'order_type' => 3,
                     'order_source' => 2,
@@ -1175,11 +1206,11 @@ class Sale extends Base
                 		'order_type' => 3,
                 		 'order_source' => 2,
                 		 'good_type' => 0,
-                            'moq' => 1,
-                            'good_thumb_img' => '',
+                        'moq' => 1,
+                        'good_thumb_img' => '',
 	                    'good_info_img' => '',
-		                    "is_auth" => 0,
-		                    'good_remark' => '',
+                        "is_auth" => 0,
+                        'good_remark' => '',
                 		 'createrid' => $zxinfo['createrid'],
 	                    'creater' => $zxinfo['creater'],
 	                    'order_createrid' => $this->uid,
@@ -1190,6 +1221,42 @@ class Sale extends Base
                 		];
                 	(new ConsultTemp())->CreateGood($zxinfo['bidNo'],$marage);
                 }
+                if($zxinfo['open_type']==1|| $zxinfo['tax_id']>0){
+                     $data = [
+				        'spuCode'=>$zxinfo['spuCode'],
+				        'companyNo'=>$companyNo,
+				        'tax_id'=>$zxinfo['tax_id'],
+				        'inv_good_name'=>$zxinfo['inv_good_name'],
+				        'open_type'=>$zxinfo['open_type'],
+				        'tax'=>$zxinfo['tax'],
+				        "out_tax_id"=>$zxinfo['out_tax_id'],
+				        'out_tax'=>$zxinfo['out_tax'],
+				        'cgd_tax_id'=>$zxinfo['cgd_tax_id'],
+                        'cgd_tax'=>$zxinfo['cgd_tax'],
+				        'createrid' => $zxinfo['createrid'],
+	                    'creater' => $zxinfo['creater'],
+				    ];
+                    GoodTax::create($data);
+                }
+               $taxInfo = OrderTax::SpuCat($spuCode);
+                if (!empty($taxInfo)) {
+                   (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($orderCode){
+                        $temp=[];
+                        $temp['code']=$orderCode;
+                        $temp['spuCode']=$item['spuCode'];
+                        $temp['tax_code']=$item['cat_code'];
+                        $temp['tax_name']=$item['cat_name'];
+                        $temp['tax_short_name']=$item['short_name'];
+                        $temp['inv_tax']=$item['tax'];
+                        $temp['inv_good_name']=$item['inv_good_name'];
+                        return $temp;
+                   },$taxInfo));
+                 }
+                $bol = $this->createCgd($cgd, $standing_book_data);
+                if ($bol == false) {
+                    Db::rollback();
+                    return error_show(1002, '咨询订单创建失败');
+                }
                 if (!empty($va)) {
                     $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
                         ->find();
@@ -1399,6 +1466,7 @@ class Sale extends Base
                 $good['arrtime'] = $arrtime;
                 $good['rm'] = $rm;
                 $good['ri'] = $ri;
+                $good['use_order']=$this->post['useid']??0;
                 $good['manager'] = $manager;
                 $good['managerid'] = $managerid;
                 $good['send_num'] = 0;
@@ -1532,6 +1600,9 @@ class Sale extends Base
         $goodinfo = Db::name("consult_bids")->where(["spuCode" => $data['spuCode'], "is_del" => 0])->find();
         if ($goodinfo == false) {
            throw new Exception("咨询商品未找到");
+        }
+         if ($goodinfo['status'] !=7) {
+           throw new Exception('咨询单商品财务未审核');
         }
         $bargaininfo =Db::name("bargain_order")->where(["bidsNo" => $goodinfo["bidNo"],"is_del"=>0,"status"=>0])
         ->findOrEmpty();
@@ -1573,6 +1644,7 @@ class Sale extends Base
             "creater" =>$holder_name,
             "weight" => $goodinfo['good_weight'],
             "gold_price" => $goodinfo['gold_price'],
+            'open_type'=>$goodinfo['open_type'],
             "good_type" => 1,
             "order_type" => 3,//3咨询商品
             "order_source" => 3,//项目
@@ -1613,6 +1685,7 @@ class Sale extends Base
             "zxNo" => $data["pgNo"],
             "platform_order" => "",
             "platform_id" => $data['platform_id'],
+             'open_type'=>$goodinfo['open_type'],
             "remark" => "",
             "is_stock" => 0,
             "is_activity" => 0,
@@ -1620,6 +1693,7 @@ class Sale extends Base
             "proof_id" => 0,
             "order_type" => 3,//咨询商品
             "order_source" => 3,//项目
+            'use_order'=>$data['useid']??0,
             'good_weight' => $goodinfo['good_weight'],
             'gold_price' => $goodinfo['gold_price'],
             'cost_price' => $goodinfo['sale_cost_fee'],
@@ -1656,10 +1730,6 @@ class Sale extends Base
                 "before_status" => 0,
                 'holder_id' => $datas['apply_id']
             ]);
-            $bol = $this->createCgd($cgd, $standing_book_data);
-            if ($bol == false) {
-                throw new Exception("采购单生成失败");
-            }
             $bidstatus = $goodinfo['status'];
             $goodinfo['status'] = 6;
             $goodinfo['updatetime'] = date("Y-m-d H:i:s");
@@ -1721,6 +1791,8 @@ class Sale extends Base
                 "supply_area" => $goodinfo['supply_area'],
                 "pay_way" => $goodinfo['pay_way'],
                 "send_way" => $goodinfo['send_way'],
+                'sale_price' => $data['sale_price'],
+                 'open_type'=>$goodinfo['open_type'],
                 "status" => 1,
                 "is_del" => 0,
                 "order_type" => 3,
@@ -1741,21 +1813,54 @@ class Sale extends Base
                 		'parent_code'=>$goodinfo['spuCode'],
                 		'parent_name'=>$goodinfo['good_name'],
                 		'order_type' => 3,
-                		 'order_source' =>3,
-                		 'good_type' => 0,
-                            'moq' => 1,
-                            'good_thumb_img' => '',
-	                    '   good_info_img' => '',
-		                    'is_auth' => 0,
-		                    'good_remark' => '',
-                		 'createrid' => $goodinfo['createrid'],
+                		'order_source' =>3,
+                		'good_type' => 0,
+                        'moq' => 1,
+                        'good_thumb_img' => '',
+	                    'good_info_img' => '',
+                        'is_auth' => 0,
+                        'good_remark' => '',
+                		'createrid' => $goodinfo['createrid'],
 	                    'creater' => $goodinfo['creater'],
-	                     'order_createrid' => $data['rm'],
+	                    'order_createrid' => $data['rm'],
                         'order_creater' => $data['ri'],
-	                     'platform_id' => $zxorder['platform_id'],
+	                    'platform_id' => $zxorder['platform_id'],
                 		];
                 	(new ConsultTemp())->CreateGood($goodinfo['bidNo'],$marage);
                 }
+            if($goodinfo['open_type']==1|| $goodinfo['tax_id']>0){
+                                 $data = [
+            				        'spuCode'=>$goodinfo['spuCode'],
+            				        'companyNo'=>$data['companyNo'],
+            				        'tax_id'=>$goodinfo['tax_id'],
+            				         'open_type'=>$goodinfo['open_type'],
+            				        'inv_good_name'=>$goodinfo['inv_good_name'],
+            				        'tax'=>$goodinfo['tax'],
+            				        'out_tax_id'=>$goodinfo['out_tax_id'],
+				                    'out_tax'=>$goodinfo['out_tax'],
+            				        'createrid' => $goodinfo['createrid'],
+            	                    'creater' => $goodinfo['creater'],
+            				    ];
+                                GoodTax::create($data);
+                            }
+           $taxInfo = OrderTax::SpuCat( $data['spuCode']);
+           if (!empty($taxInfo)) {
+              (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($orderCode){
+                   $temp=[];
+                   $temp['code']=$orderCode;
+                   $temp['spuCode']=$item['spuCode'];
+                   $temp['tax_code']=$item['cat_code'];
+                   $temp['tax_name']=$item['cat_name'];
+                    $temp['tax_short_name']=$item['short_name'];
+                   $temp['inv_tax']=$item['tax'];
+                   $temp['inv_good_name']=$item['inv_good_name'];
+                   return $temp;
+              },$taxInfo));
+            }
+            $bol = $this->createCgd($cgd, $standing_book_data);
+            if ($bol == false) {
+                throw new Exception('采购单生成失败');
+            }
             if ($data['sendtype'] == 1 && !empty($data['addrlist'])) {
                 $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])
                     ->find();
@@ -1939,12 +2044,14 @@ class Sale extends Base
             "supplierName" => $data['companyName'],
             "supName" => $good['supplierName'],
             "supNo" => $good['supplierNo'],
+            'use_order'=>$data['useid']??0,
             "is_del" => 0,
             "zxNo" => $data["pgNo"],
             "platform_order" => "",
             "platform_id" => $data['platform_id'],
             "remark" => "",
             "is_stock" => $good['is_stock'],
+            'open_type'=>$good['open_type'],
             "is_activity" => 0,
             "activity_code" => '',
             "proof_id" => 0,
@@ -2011,6 +2118,7 @@ class Sale extends Base
                 "createrid" => $supplier_temp_info['personid']??0,
                 "creater" => $supplier_temp_info['person']??"",
                 "order_type" => $good['is_stock'] == 1 ? 1 : 2,
+                'open_type'=>$good['open_type'],
                 'order_source' => 3,//3项目
                 'send_way' => 2,
                 'good_createrid' => $good['createrid'],
@@ -2021,6 +2129,21 @@ class Sale extends Base
 		        'cgd_apply_id'=>$good['cgd_apply_id'],//竞单人
 		        'cgd_apply_name'=>$good['cgd_apply_name'],//竞单人
             ];
+            $taxInfo = OrderTax::SpuCat( $data['spuCode']);
+           if (!empty($taxInfo)) {
+              (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($orderCode){
+                   $temp=[];
+                   $temp['code']=$orderCode;
+                   $temp['spuCode']=$item['spuCode'];
+                   $temp['tax_code']=$item['cat_code'];
+                   $temp['tax_name']=$item['cat_name'];
+                    $temp['tax_short_name']=$item['short_name'];
+                   $temp['inv_tax']=$item['tax'];
+                   $temp['inv_good_name']=$item['inv_good_name'];
+                   return $temp;
+              },$taxInfo));
+            }
+
             if ($good['is_stock'] == 0) {
                 $bol = $this->createCgd($cgd, $standing_book_data);
                 if ($bol == false) {
@@ -2476,6 +2599,12 @@ class Sale extends Base
         if ($goon == false) {
             return error_show(1003, "未找到商品数据");
         } else {
+            $taxInfo=OrderTax::where(['code'=>$einfo['orderCode']])->findOrEmpty();
+            $einfo['tax_name'] = $taxInfo['tax_name']??'';
+            $einfo['tax_short_name'] =$taxInfo['tax_short_name']??'';
+            $einfo['tax_code'] =$taxInfo['tax_code']??'';
+            $einfo['tax']=$taxInfo['inv_tax']??'';
+            $einfo['inv_good_name']=$taxInfo['inv_good_name']??'';
             $goon['exclusive'] = isset($goon['is_exclusive']) ? makeExcluse($goon['is_exclusive']) : "";
             $unit = Db::name("unit")->where(["id" => $goon['good_unit']])->find();
             $goon['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
@@ -2527,13 +2656,9 @@ class Sale extends Base
                 $einfo['supplierNo']
             ]]);
 
-
-//            $supplier = Db::name("supplier")->where(["code" => $goon['supplierNo']])->find();
             $goon['supplierName'] = $names['data'][$goon['supplierNo']]??'';//isset($supplier['name']) ? $supplier['name'] : "";
             $goon['noble_name'] = isset($goon['noble_metal']) && $goon['noble_metal'] != 0 ? $this->noble[$goon['noble_metal']] : "";
-//            if (isset($goon['companyNo']) && $goon['companyNo'] != "") {
-//                $company = Db::name("business")->where(["companyNo" => $goon['companyNo']])->find();
-//            }
+
             $goon['company'] = $names['data'][$goon['companyNo']]??'';//isset($company['company']) ? $company['company'] : "";
         }
         $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
@@ -2541,35 +2666,12 @@ class Sale extends Base
 //        $in = Db::name('customer_info')->where(['companyNo' => $einfo['customer_code']])->field('companyName')->find();
         $einfo['supplierName'] = '';
         if ($einfo['supplierNo'] != "") {
-//            $supplier = Db::name("business")->where(["companyNo" => $einfo['supplierNo']])->find();
             $einfo['supplierName'] = $names['data'][$einfo['supplierNo']]??'';//isset($supplier['company']) ? $supplier['company'] : "";
         }
         $addr_sum = Db::name('order_addr')->where(['orderCode' => $einfo['orderCode'],"is_del"=>0])->sum('receipt_quantity');
         $einfo['addr_sum']=$addr_sum;
-//        $fo = Db::name('order_addr')->alias("a")->leftJoin("order_out b", "a.id=b.addrid and b.is_del=0")
-//            ->where(['a.orderCode' => $einfo['orderCode'], 'a.is_del' => 0])->field("a.*,b.post_name,b.post_code,
-//            b.post_fee,b.sendtime,b.send_num,b.check_num,b.error_num,b.wsm_code,b.order_type,b.status as send_status,b.outCode")
-//            ->select();
         $addrs = [];
-//        if (!empty($fo)) {
-//            foreach ($fo as $value) {
-//                $value['addr_info'] = "";
-//                $value['send_num'] = 0;
-//                if ($value['addr_code'] != "" && !empty($value['addr_code'])) {
-//                    $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
-//                    list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['addr_code']);
-//                    $addr = GetAddr(json_encode($place));
-//                    $value['addr_info'] = $addr;
-//                }
-//                $value['wsm_name'] = "";
-//                if (isset($value['wsm_code']) && $value['wsm_code'] != "") {
-//                    $wsmcode = Db::name("warehouse_info")->where(["wsm_code" => $value['wsm_code']])->find();
-//                    $value['wsm_name'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
-//                }
-//                $value['sendtime'] = $value['send_status'] < 2 ? '' : $value['sendtime'];
-//                $addrs[] = $value;
-//            }
-//        }
+
         $einfo['useage'] = "";
         if ($einfo['use_order'] != 0) {
             $use = Db::name("order_use")->where(["id" => $einfo['use_order']])->find();
@@ -4642,10 +4744,10 @@ class Sale extends Base
             $price = Db::name("gold_price1")->where(["type" => $order['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
 
         }
-			$depart = get_company_name_by_uid($order['order_createrid']);
+        $order['tax_info']=GoodTax::with(['Tax','OutTax',"CgdTax"])->where(['spuCode'=>$orderCode])->findOrEmpty();
+		$depart = get_company_name_by_uid($order['order_createrid']);
         $userCommon = \app\admin\common\User::getIns();
         $supplier = $userCommon->handle('sInfo',['code'=>$order['supplierNo']]);
-//        $supplier = Db::name("supplier")->where(["code" => $order['supplierNo']])->find();
         $order['supplier_name'] = isset($supplier['data']['name']) ? $supplier['data']['name'] : "";
         $order['cgder'] = isset($supplier['data']['person']) ? $supplier['data']['person'] : "";
         $order['cgderid'] = isset($supplier['data']['personid']) ? $supplier['data']['personid'] : "";
@@ -4655,10 +4757,8 @@ class Sale extends Base
         $value['is_basic']= Db::name('good_basic')->where(['spuCode'=>$order['spuCode']])->value("status",null);
         $palt = Db::name("platform")->where(["id" => $order['platform_id']])->find();
         $order['platform_name'] = isset($palt['platform_name']) ? $palt['platform_name'] : "";
-
         $names = $userCommon->handle('getCodeAndName',['code'=>$order['companyNo']]);
-//        $company = Db::name("business")->where(["companyNo" => $order['companyNo']])->find();
-        $order['company'] = $names['data'][$order['companyNo']]??'';//isset($company['company']) ? $company['company'] : "";
+        $order['company'] = $names['data'][$order['companyNo']]??'';
         $order["gold_price"] = isset($price['price']) ? $price['price'] : 0;
         $order["noble_weight"] = isset($order['weight']) ? $order['weight'] : 0;
         return app_show(0, "获取成功", $order);
@@ -4681,14 +4781,6 @@ class Sale extends Base
 
         if (empty($order)) return error_show(1003, "数据未找到");
 
-//        $orderCode= isset($this->post['spuCode'])&&$this->post['spuCode']!=''?trim($this->post['spuCode']):"";
-//        if($orderCode==""){
-//            return error_show(1003,"参数spuCode不能为空");
-//        }
-//        $order= Db::name("good_zixun")->where(["spuCode"=>$orderCode,"is_del"=>0])->find();
-//        if(empty($order)){
-//            return error_show(1003,"订单数据未找到");
-//        }
         $unit = Db::name("unit")->where(["id" => $order['unit_id']])->find();
         if ($order['brand_id'] != 0) {
             $brand = Db::name("brand")->where(["id" => $order['brand_id']])->find();
@@ -4707,15 +4799,22 @@ class Sale extends Base
         }
         $userCommon = \app\admin\common\User::getIns();
         $supplier_temp = $userCommon->handle('getCodeAndName', ['code' => $order['supplierNo']]);
-//            $supplier =Db::name("supplier")->where(['code'=>$supplierNo])->find();
-//		 if($supplier_temp['code']!=0 || empty($supplier_temp['data']) )   return error_show(1004,"未找到供应商信息");
-//        $supplier = Db::name("supplier")->where(["code" => $order['supplierNo']])->find();
         $order['supplier_name'] = $supplier_temp['data'][$order['supplierNo']]??"";
-//        $palt =Db::name("platform")->where(["id"=>$order['platform_id']])->find();
-//        $order['platform_name']=isset($palt['platform_name']) ? $palt['platform_name']:"";
         $order["gold_price"] = isset($price['price']) ? $price['price'] : 0;
         $order["noble_weight"] = isset($order['weight']) ? $order['weight'] : 0;
-
+        $tax = TaxCategory::where(['id'=>[$order['tax_id'],$order['out_tax_id'],$order['cgd_tax_id']]])->column('short_name,cat_name,cat_code,merge_code','id');
+        $order['in_info'] = $tax[$order['tax_id']]??[];
+        $order['out_info'] = $tax[$order['out_tax_id']]??[];
+        $order['cgd_info'] = $tax[$order['cgd_tax_id']]??[];
+        $order['child'] =[];
+        if($order['is_combind']==1){
+            $order['child'] =ConsultTemp::where(['bidNo'=>$order['bidNo']])->select()->each(function(&$item){
+                $tax = TaxCategory::where(['id'=>[$item['tax_id'],$item['out_tax_id'],$item['cgd_tax_id']]])->column('short_name,cat_name,cat_code,merge_code','id');
+                $item['in_info'] = $tax[$item['tax_id']]??[];
+                $item['out_info'] = $tax[$item['out_tax_id']]??[];
+                $item['cgd_info'] = $tax[$item['cgd_tax_id']]??[];
+            });
+        }
         $good_info = Db::name('good_basic')
             ->field('id,createrid,creater')
             ->where('is_del',0)

+ 3 - 38
app/admin/controller/User.php

@@ -41,6 +41,7 @@ class User extends Base
                 break;
 
             case 2:
+            case 3:
                 //获取默认公司
                 $default = array_column($rs['data']['company_relaton'], 'companyNo', 'is_main');
                 if (!isset($default) || !isset($default[1])) return json_show(1004, '没有默认公司,无法登录');
@@ -54,47 +55,11 @@ class User extends Base
 
                 if (empty($role)) return json_show(1004, '没有默认角色,无法登录,请联系管理员');
                 break;
-
-            case 3:
-                //供应商端
-                $role = [
-                    'role_name' => '',
-                    'role_level' => $rs['data']['level'],
-                    'role_id' => env('default_supplier_addcount_role_id',90),//指定一个默认角色id
-                ];
-                break;
+                default:
+                    return json_show(1004, '没有默认角色,无法登录,请联系管理员');
 
         }
 
-
-
-//        if ($rs['data']['level'] == 2) {
-//
-//            $role = Db::name('user_role')
-//                ->alias('a')
-//                ->field('a.roleid,b.role_name,b.role_level')
-//                ->leftJoin('role b', 'b.id=a.roleid')
-//                ->where(['a.uid' => $rs['data']['id'], 'a.is_main' => 1, 'a.is_del' => 0])
-//                ->findOrEmpty();
-//
-//            if (empty($role)) return json_show(1004, '没有默认角色,无法登录,请联系管理员');
-//
-//            //数据合并
-//            $data = array_merge($rs['data'], [
-//                'role_name' => $role['role_name'],
-//                'role_level' => $role['role_level'],
-//                'role_id' => $role['roleid'],
-//            ]);
-//
-//        } else {
-//            //超管 or 供应商
-//            $data = array_merge($rs['data'], [
-//                'role_name' => '',
-//                'role_level' => $rs['data']['level'],
-//                'role_id' => '',
-//            ]);
-//        }
-
         $data = array_merge($rs['data'], [
             'role_name' => $role['role_name'],
             'role_level' => $role['role_level'],

+ 2 - 1
app/admin/model/CgdCaixiao.php

@@ -11,6 +11,7 @@ use think\Model;
 class CgdCaixiao extends Model
 {
     public function OriginCgd(){
-    	return $this->belongsTo(OriginCgd::class,"cgdNo","newCode")->bind(["mainCode"=>"oldCode"]);
+    	return $this->belongsTo(OriginCgd::class,"cgdNo","newCode")->bind(["mainCode"=>"oldCode","is_child"]);
     }
+
 }

+ 1 - 2
app/admin/model/CombindStockInfo.php

@@ -10,7 +10,6 @@ use think\Model;
  */
 class CombindStockInfo extends Model
 {
- protected $createTime="addtime";
- 
+  protected $createTime="addtime";
 
 }

+ 19 - 0
app/admin/model/ConsultTemp.php

@@ -66,6 +66,7 @@ class ConsultTemp extends Model
       if($list->isEmpty()==false){
       	    $addGood=[];
       	    $combind =[];
+      	    $goodTax=[];
             foreach ($list as $item){
             	$item['good_unit'] = $item['unit_id'];
             	$item['specinfo'] = json_encode($item['specinfo'],JSON_UNESCAPED_UNICODE);
@@ -84,9 +85,27 @@ class ConsultTemp extends Model
                 	"child_name"=>$item["good_name"],
                 	"child_num"=>$item["good_num"],
                 	];
+                if($item['open_type']==1){
+                   $goodTax[]=[
+                	'spuCode'=>$item['spuCode'],
+                    'companyNo'=>$item['companyNo'],
+                    'tax_id'=>$item['tax_id'],
+                    "open_type"=>$item['open_type'],
+                    'inv_good_name'=>$item['inv_good_name'],
+                    'tax'=>$item['tax'],
+                    'out_tax_id'=>$item['out_tax_id'],
+				    'out_tax'=>$item['out_tax'],
+                    "cgd_tax_id"=>$item['cgd_tax_id'],
+                    "cgd_tax"=>$item['cgd_tax'],
+                    'createrid' => $marage['createrid'],
+                    'creater' => $marage['creater'],
+                    ];
+                }
+
             }
             if(empty($addGood)==false)(new GoodZixun())->strict(false)->insertAll($addGood);
             if(empty($combind)==false)(new GoodCombind())->insertAll($combind);
+            if(empty($goodTax)==false)(new GoodTax())->insertAll($goodTax);
       }
     }
 }

+ 6 - 1
app/admin/model/GoodCombind.php

@@ -33,7 +33,7 @@ class GoodCombind extends Model
 		                 ->where(['spuCode'=>$row['childCode'] , 'wsm_type'=>[2 , 5]])
 		                 ->sum('usable_stock');
 	}
-	
+
 	public function  AddStock($spuCode='',$num="0"){
 		$comblist = $this->where(['spuCode'=>$spuCode,'is_del'=>0])->select()->toArray();
 		if(empty($comblist))throw new \Exception("未找到对应子商品信息");
@@ -82,4 +82,9 @@ class GoodCombind extends Model
 		}
 		return true;
 	}
+
+	public function goodTax(){
+		return $this->belongsTo(GoodTax::class,"childCode","spuCode")
+		->bind(['short_name','merge_code',"tax","inv_good_name","tax_id","companyNo"]);
+	}
 }

+ 1 - 0
app/admin/model/GoodStock.php

@@ -10,6 +10,7 @@ use think\Model;
  */
 class GoodStock extends Model
 {
+    protected $autoWriteTimestamp = true;
     protected $createTime="addtime";
     protected $updateTime="updatetime";
     

+ 76 - 0
app/admin/model/GoodTax.php

@@ -0,0 +1,76 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use app\model\TaxCategory;
+use app\model\TaxRelation;use think\Model;
+use think\model\concern\SoftDelete;use function Symfony\Component\String\b;
+
+/**
+ * @mixin \think\Model
+ */
+class GoodTax extends Model
+{
+    use SoftDelete;
+    protected $createTime = 'createTime';
+    protected $updateTime = 'updateTime';
+    protected $deleteTime = 'delete_time';
+    protected $autoWriteTimestamp = 'datetime';
+
+    public function Tax(){
+        return $this->belongsTo(TaxCategory::class,'tax_id','id')
+        ->bind(["in_tax_name"=>'cat_name',"in_tax_code"=>'cat_code',"in_tax_short"=>'short_name',"in_tax_merge"=>'merge_code']);
+    }
+    public function OutTax(){
+        return $this->belongsTo(TaxCategory::class,'out_tax_id','id')
+        ->bind(["out_tax_name"=>'cat_name',"out_tax_code"=>'cat_code',"out_tax_short"=>'short_name',"out_tax_merge"=>'merge_code']);
+    }
+    public function CgdTax(){
+        return $this->belongsTo(TaxCategory::class,'cgd_tax_id','id')
+        ->bind(['cgd_tax_name'=>'cat_name','cgd_tax_code'=>'cat_code','cgd_tax_short'=>'short_name','cgd_tax_merge'=>'merge_code']);
+    }
+    /**
+    * @param $spuCode
+    * @param int $type 1 进项票 2 销项票
+     * @return array
+     */
+    public static function getInfobySpuCode($spuCode,$type=1){
+        $item = (new GoodTax)->with(['Tax',"OutTax","CgdTax"])->where(['spuCode'=>$spuCode])->findOrEmpty();
+        if($item->isEmpty()) return [];
+        $temp=[];
+        switch ($type){
+            case 1:
+                 $temp['spuCode']=$item->spuCode;
+                 $temp['cat_code']=$item->in_tax_code;
+                 $temp['cat_name']=$item->in_tax_name;
+                 $temp['short_name']=$item->in_tax_short;
+                 $temp['merge_code']=$item->in_tax_merge;
+                 $temp['tax']= str_replace('%','',$item->tax);
+                 $temp['inv_good_name']=$item->inv_good_name;
+              break;
+            case 2:
+                 $temp['spuCode']=$item->spuCode;
+                 $temp['cat_code']=$item->out_tax_code??'';
+                 $temp['cat_name']=$item->out_tax_name??'';
+                 $temp['short_name']=$item->out_tax_short??'';
+                 $temp['merge_code']=$item->out_tax_merge;
+                 $temp['tax']= str_replace('%','',$item->out_tax);
+                 $temp['inv_good_name']=$item->inv_good_name;
+                 break;
+            case 3:
+                 $temp['spuCode']=$item->spuCode;
+                 $temp['cat_code']=$item->cgd_tax_code??'';
+                 $temp['cat_name']=$item->cgd_tax_name??'';
+                 $temp['short_name']=$item->cgd_tax_short??'';
+                 $temp['merge_code']=$item->cgd_tax_merge;
+                 $temp['tax']= str_replace('%','',$item->cgd_tax);
+                 $temp['inv_good_name']=$item->inv_good_name;
+                 break;
+            default:
+                break;
+        }
+
+        return $temp;
+    }
+}

+ 33 - 0
app/admin/model/OrderTax.php

@@ -0,0 +1,33 @@
+<?php
+
+
+namespace app\admin\model;
+
+
+use think\Model;
+class OrderTax extends Model {
+    protected $createTime = 'createTime';
+    /**
+     * @param $spuCode
+     * @param int $open_type 1 原商品开票 2 子商品开票
+     * @param int $order_type 1 进项 2 销项
+     * @return array
+     */
+    public static function SpuCat($spuCode,$open_type=1,$order_type=2){
+        $result=[];
+         if($open_type==2){
+              $goods= GoodCombind::where('spuCode',$spuCode)->select();
+              if(!$goods->isEmpty()){
+                  foreach ($goods as $item){
+                     $temp = GoodTax::getInfobySpuCode($item->childCode,$order_type);
+                     if(empty($temp)) continue;
+                     $result[]=$temp;
+                  }
+              }
+         }
+         $temp = GoodTax::getInfobySpuCode($spuCode,$order_type);
+         if(empty($temp)) return $result;
+         $result[]=$temp;
+        return $result;
+    }
+}

+ 1 - 2
app/admin/route/app.php

@@ -423,6 +423,7 @@ Route::rule('goodproof', 'admin/Goodup/prooflist');
 Route::rule('activitylist', 'admin/Activity/list');
 Route::rule('activitylinst', 'admin/Activity/linst');
 Route::rule("zixunlist", 'admin/Activity/zilist');
+Route::rule("setzxtax", 'admin/Activity/SetZixunTax');
 Route::rule("actquery", 'admin/Activity/query');
 Route::rule("actstock", 'admin/Activity/editStock');
 
@@ -461,10 +462,8 @@ Route::rule('titlestatus', 'admin/Title/status');
 
 Route::rule('ocrquery', 'admin/Ocrlicense/query');
 Route::rule('consultlists', 'admin/Consult/conlist');
-//Route::rule('consultinfo', 'admin/Consult/info');
 Route::rule('consultdel', 'admin/Consult/delete');
 Route::rule('consultcreate', 'admin/Consult/create');
-//Route::rule('consultzxadd', 'admin/Consult/zxadd');
 Route::rule('consultzxinfo', 'admin/Consult/zxinfo');
 Route::rule('consultbar', 'admin/Consult/bargain');
 Route::rule('consultfeed', 'admin/Consult/feadback');

+ 31 - 3
app/command/ImportOrderFromCHandleData.php

@@ -8,7 +8,7 @@ use app\admin\model\GoodLog;
 use app\admin\model\GoodStockInfo;
 use app\admin\model\OrderImportFromC as OIFCModel;
 use app\admin\model\OrderOutChild;
-use app\admin\model\ProcessOrder;
+use app\admin\model\OrderTax;use app\admin\model\ProcessOrder;
 use app\admin\model\SaleCgdPrice;use app\admin\model\Test1;
 use think\console\Command;
 use think\console\Input;
@@ -320,6 +320,20 @@ class ImportOrderFromCHandleData extends Command
                         }
 					SaleCgdPrice::GetPrice($datainfo);
                     }
+            $taxInfo = OrderTax::SpuCat( $spuCode);
+           if (!empty($taxInfo)) {
+              (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($orderCode){
+                   $temp=[];
+                   $temp['code']=$orderCode;
+                   $temp['spuCode']=$item['spuCode'];
+                   $temp['tax_code']=$item['cat_code'];
+                   $temp['tax_name']=$item['cat_name'];
+                    $temp['tax_short_name']=$item['short_name'];
+                   $temp['inv_tax']=$item['tax'];
+                   $temp['inv_good_name']=$item['inv_good_name'];
+                   return $temp;
+              },$taxInfo));
+            }
                     if ($sendtype == 1) {
                         $temp = [
                             'orderCode' => $orderCode,
@@ -557,6 +571,7 @@ class ImportOrderFromCHandleData extends Command
             "status" => 0,//0初始化
             "lasttime" => date("Y-m-d H:i:s"),
             "is_del" => 0,
+            "open_type" => $data['open_type'],
             "order_type" => $data['order_type'],
             "order_source" => $data['order_source'],
             "good_type" => $data['good_type'],
@@ -573,8 +588,21 @@ class ImportOrderFromCHandleData extends Command
         ];
         $up = Db::name("purchease_order")->insert($cg, true);
         if ($up) {
-
-            //修改状态,添加待办
+            $taxInfo = OrderTax::SpuCat( $data['spuCode'],1,1);
+           if (!empty($taxInfo)) {
+              (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($cgdCode){
+                   $temp=[];
+                   $temp['code']=$cgdCode;
+                   $temp['spuCode']=$item['spuCode'];
+                   $temp['tax_code']=$item['cat_code'];
+                   $temp['tax_name']=$item['cat_name'];
+                    $temp['tax_short_name']=$item['short_name'];
+                   $temp['inv_tax']=$item['tax'];
+                   $temp['inv_good_name']=$item['inv_good_name'];
+                   return $temp;
+              },$taxInfo));
+            }
+            //修改状   态,添加待办
             ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
                 "order_code" => $cg['cgdNo'],//销售单code
                 "status" => 0,//这里的status是之前的值

+ 8 - 7
app/command/SplitSale.php

@@ -28,9 +28,6 @@ class SplitSale extends Command
 
     protected function execute(Input $input, Output $output)
     {
-
-        try {
-
             $key = 'split_sale_';
 
             $rs = Cache::store('redis')->inc($key);
@@ -38,6 +35,7 @@ class SplitSale extends Command
             	Cache::store('redis')->dec($key);
 	            return true;
             }
+        try {
 			$this->comOrder=new ComonOrder();
             Db::startTrans();
 			
@@ -207,12 +205,10 @@ class SplitSale extends Command
                 $output->writeln('事务回滚:' . $e->getMessage() . '||' . $e->getFile() . '||' . $e->getLine());
             }
 
-           Cache::store('redis')->dec($key);
-
         } catch (\Exception $exception) {
             $output->writeln('脚本执行出错,' . $exception->getMessage() . '||' . $exception->getFile() . '||' . $exception->getLine());
         }
-
+          Cache::store('redis')->dec($key);
     }
 
     //构建销售单
@@ -243,6 +239,7 @@ class SplitSale extends Command
             'gold_price' => $sale['gold_price'] ?? 0,
             'cost_price' => $sale['cost_price'] ?? 0,
             'status' => $sale['status'] ?? 0,
+             'open_type'=>$sale['open_type'],
             'updatetime' => $sale['updatetime'],
             'delivery_day' => $sale['delivery_day'] ?? 0,
             'th_fee' => round(bcmul($sale_price, $sale['th_num'] ?? 0, 3), 2),
@@ -271,8 +268,9 @@ class SplitSale extends Command
                 'apply_name' => $sale['apply_name'] ?? '',
                 'order_type' => $sale['order_type'] ?? 0,
                 'order_source' => $this->order_source,
-                'platform_id' => $sale['platform_name'] ?? '',
+                'platform_id' => $sale['platform_id'] ?? '',
                 'platform_type' => $sale['use_type'] ?? '',
+                "platform_name"=>$sale['platform_name']??"",
                 'good_code' => $sale['good_code'] ?? '',
                 'cat_id' => $sale['cat_id'] ?? 0,
                 'cat_name' => json_encode($this->_get_cat_list($sale['cat_id']), JSON_UNESCAPED_UNICODE),
@@ -346,6 +344,7 @@ class SplitSale extends Command
             'last_time' => $cgd['last_time'] ?? '',
             'send_type' => $sale['send_type'] ?? '',
             'send_status' => $sale['send_status'] ?? '',
+            "open_type"=>$sale['open_type'],
             'th_num' => $sale['th_num'] ?? 0,
             'th_fee' => round(bcmul($good_price, $sale['th_num'] ?? 0, 3), 2),
             'updatetime' => $sale['updatetime'],
@@ -374,6 +373,8 @@ class SplitSale extends Command
                 'cgder_id' => $sale['cgderid'] ?? 0,
                 'depart' => isset($sale['cgderid']) ? get_company_name_by_uid($sale['cgderid']) : '',
                  'qrdNo' => $orderCode,
+                'platform_id' => $sale['platform_id'] ?? '',
+                'platform_name'=>$sale['platform_name']??'',
                 'spuCode' => $cgd['spuCode'] ?? $sale['good_code'],
                 'good_name' => $sale['good_name'],
                 'skuCode' => $cgd['skuCode'] ?? '',

+ 16 - 1
app/command/caixiao.php

@@ -3,7 +3,17 @@ declare (strict_types = 1);
 
 namespace app\command;
 
-use app\admin\model\CgdCaixiao;use app\admin\model\Platform;use app\admin\model\SaleCaixiao;use think\console\Command;use think\console\Input;use think\console\Output;use think\facade\Cache;use think\facade\Db;
+use app\admin\model\CgdCaixiao;
+use app\admin\model\GoodCombind;
+use app\admin\model\GoodTax;
+use app\admin\model\OrderTax;use app\admin\model\Platform;
+use app\admin\model\SaleCaixiao;
+use app\model\TaxRelation;
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+use think\facade\Cache;
+use think\facade\Db;
 
 class caixiao extends Command
 {
@@ -21,6 +31,8 @@ class caixiao extends Command
     		$unique = md5($item->cgdNo.$item->updatetime);
            $temp=['order_type'=>2,'uniqkey'=>$unique,'status'=>1,'addtime'=>date('Y-m:d H:i:s')];
            if($this->isInCfp($unique)){
+               $order_type= is_null($item->mainCode)?($item->order_source!=8?1:2):3;
+            $item['inv_cat_info'] =  OrderTax::spuCat($item->spuCode,2,$order_type);
            	$item['cat_name'] = json_decode($item->cat_name);
             $temp['data']= json_encode($item,JSON_UNESCAPED_UNICODE);
             $cgdArr[]=$temp;
@@ -66,6 +78,7 @@ class caixiao extends Command
            echo date('Y-m:d H:i:s').'|'.$item->orderCode."\r\n";
            $temp=["order_type"=>1,"uniqkey"=>$unique,"status"=>1,"addtime"=>date('Y-m:d H:i:s')];
            if($this->isInCfp($unique)){
+            $item['inv_cat_info'] = OrderTax::spuCat($item->good_code,2);
            	$item['cat_name'] = json_decode($item->cat_name);
             $temp["data"]= json_encode($item,JSON_UNESCAPED_UNICODE);
             $qrd[]=$temp;
@@ -78,4 +91,6 @@ class caixiao extends Command
         $ist = $this->contect->name("caixiao_data")->where("uniqkey",$unique)->findOrEmpty();
         return empty($ist);
     }
+
+
 }

+ 32 - 2
app/command/handleYzOrderData.php

@@ -7,7 +7,7 @@ use app\admin\model\ActionLog;
 use app\admin\model\GoodLog;
 use app\admin\model\GoodStockInfo;
 use app\admin\model\OrderOutChild;
-use app\admin\model\ProcessOrder;
+use app\admin\model\OrderTax;use app\admin\model\ProcessOrder;
 use app\admin\model\SaleCgdPrice;use think\console\Command;
 use think\console\Input;
 use think\console\Output;
@@ -179,6 +179,7 @@ class handleYzOrderData extends Command
                     'activity_code' => $is_activity==1 ? $act['activity_code'] : ($is_activity==2?"txx":""),
                     "order_type" => $order_type,
                     "order_source" => $order_source,
+                    'open_type'=>$goodinfo['open_type'],
                     'good_weight' => $ct['weight'],
                     'gold_price' => $ct['cgd_gold_price'],
                     'cost_price' => $ct['cost_fee'],
@@ -247,6 +248,7 @@ class handleYzOrderData extends Command
                             "delivery_fee" => isset($origin['delivery_fee']) ? $origin['delivery_fee'] : 0,
                             "good_num" => $good_num,
                             "good_type" => $goodtype,
+                            "open_type"=>$goodinfo['open_type'],
                             "order_type" => $order_type,
                             "order_source" => $order_source,
                             "createrid" =>$supplier_temp_info['personid']??'',
@@ -279,6 +281,20 @@ class handleYzOrderData extends Command
 	                        }
 					SaleCgdPrice::GetPrice($datainfo);
                     }
+           $taxInfo = OrderTax::SpuCat( $spuCode);
+           if (!empty($taxInfo)) {
+              (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($orderCode){
+                   $temp=[];
+                   $temp['code']=$orderCode;
+                   $temp['spuCode']=$item['spuCode'];
+                   $temp['tax_code']=$item['cat_code'];
+                   $temp['tax_name']=$item['cat_name'];
+                   $temp['tax_short_name']=$item['short_name'];
+                   $temp['inv_tax']=$item['tax'];
+                   $temp['inv_good_name']=$item['inv_good_name'];
+                   return $temp;
+              },$taxInfo));
+            }
                     if ($sendtype == 1) {
 
 //                        $p_c_a = get_address($c_data['delivery_province'] . $c_data['delivery_city'] . $c_data['delivery_district']);
@@ -558,6 +574,7 @@ class handleYzOrderData extends Command
             "lasttime" => date("Y-m-d H:i:s"),
             "is_del" => 0,
             "order_type" => $data['order_type'],
+            "open_type"=>$data['open_type'],
             "order_source" => $data['order_source'],
             "good_type" => $data['good_type'],
             "addtime" => date("Y-m-d H:i:s"),
@@ -573,7 +590,20 @@ class handleYzOrderData extends Command
         ];
         $up = Db::name("purchease_order")->insert($cg, true);
         if ($up) {
-
+            $taxInfo = OrderTax::SpuCat( $data['spuCode'],1,1);
+           if (!empty($taxInfo)) {
+              (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($cgdCode){
+                   $temp=[];
+                   $temp['code']=$cgdCode;
+                   $temp['spuCode']=$item['spuCode'];
+                   $temp['tax_code']=$item['cat_code'];
+                   $temp['tax_name']=$item['cat_name'];
+                   $temp['tax_short_name']=$item['short_name'];
+                   $temp['inv_tax']=$item['tax'];
+                   $temp['inv_good_name']=$item['inv_good_name'];
+                   return $temp;
+              },$taxInfo));
+            }
             //修改状态,添加待办
             ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
                 "order_code" => $cg['cgdNo'],//销售单code

+ 1 - 0
app/event.php

@@ -16,6 +16,7 @@ return [
         'GoodOff' => [\app\bbc\listener\GoodOffine::class],
         'thdata' => [\app\admin\listener\ThData::class],
         'CgdCreate' => [\app\admin\listener\Cgdmake::class],
+         "WxPush"=>[app\txx\listener\WxPush::class]
     ],
 
     'subscribe' => [

+ 1 - 1
app/model/ComonOrder.php

@@ -10,7 +10,7 @@ use think\Model;
  */
 class ComonOrder extends Model
 {
-	protected $connection='mysql_cxinv';
+    protected $connection='mysql_cxinv';
    protected $createTime="addtime";
    protected $updateTime="updatetime";
    

+ 14 - 0
app/model/TaxCategory.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class TaxCategory extends Base
+{
+
+}

+ 0 - 2
app/txx/controller/Act.php

@@ -9,8 +9,6 @@ use think\App;
 
 class Act extends Base
 {
-	protected $uid=0;
-	protected $uname='';
 	protected $model;
 	protected static $ActStatusCn=["无状态",'活动未开始','活动进行中',"活动已结束"];
     public function __construct(App $app) {

+ 3 - 2
app/txx/controller/Base.php

@@ -3,12 +3,13 @@ declare (strict_types = 1);
 
 namespace app\txx\controller;
 
-use app\BaseController;use think\App;
+use app\BaseController;
+use think\App;
 use think\exception\HttpResponseException;
 use think\Response;
 
 
-class Base extends BaseController
+class Base extends \app\admin\controller\Base
 {
 	public $white=[];
 	public function __construct(App $app) {

+ 3 - 3
app/txx/controller/Good.php

@@ -6,7 +6,7 @@ namespace app\txx\controller;
 use app\BaseController;
 use app\txx\model\Act;
 use app\txx\model\ActGood;
-use app\txx\model\YzGood;
+use app\txx\model\ActGoodurl;use app\txx\model\YzGood;
 use app\txx\model\PlatformYouzan;
 use think\App;
 use think\Exception;
@@ -516,16 +516,16 @@ class Good extends BaseController
 		    $unit = Db::name("unit")->where(["id" => array_column($list, 'good_unit')])->column('unit', 'id');
 		    if($this->request->isCx==1){
 			    $all_platform =Db::name("platform")->field('id,platform_name')->where(["id" =>array_column($list, 'platform_code')])->column('platform_name', 'id');
-//			    $all_supplier = Db::name("supplier")->where(["code" =>array_column($list, 'supplierNo')])->column("name","code");
 			    $itemid_all =Db::connect("mysql_sys")->name("account_item")->where(["account_id"=>array_column($list,
 				    'purchase_id')])->column("itemid",'account_id');
 		    }
+		    $actUrl = ActGoodurl::where(["is_del"=>0,"act_good_id"=>array_column($list, 'platform_youzan_id')])->column("act_good_url","act_good_id");
         foreach ($list as $value) {
             $value["brand_name"] = $all_brand[$value['brand_id']]??"";
             $value['unit'] = $unit[$value['good_unit']]??"";
-//		    $value['exam_status'] = $value['exam_status']==6?1:0;
             $value['origin_price'] =isset($yzadd[$value['skuCode']])? $yzadd[$value['skuCode']]['origin']??"":"";
             $value['good_url'] =isset($yzadd[$value['skuCode']])? $yzadd[$value['skuCode']]['detail_url']??"":"";
+            $value['act_good_url']= $actUrl[$value['platform_youzan_id']]??"";
 
             $spec = Db::name("good_spec")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
             $speclist = [];

+ 52 - 0
app/txx/listener/WxPush.php

@@ -0,0 +1,52 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\txx\listener;
+
+use app\txx\model\Act;use think\facade\Cache;
+class WxPush
+{
+    protected $appid;
+    protected $appsecret;
+    protected $wechat;
+    /**
+     * 事件监听处理
+     *
+     * @return mixed
+     */
+    public function __construct()
+    {
+         $this->appid = env('WECHAT.APPID');
+        $this->appsecret = env('WECHAT.APPSECRET');
+        $this->wechat = new \Wechat(['appid' => $this->appid, 'appsecret' => $this->appsecret]);
+    }
+    public function handle($event)
+    {
+        if($event==null)return;
+        if($event['status']==3){
+            $act = Act::where(['actCode'=>$event['actCode']])->findOrEmpty();
+            if(!$act->isEmpty()){
+               $this->push($act->toArray());
+            }
+        }
+    }
+    public function push($data){
+        $temps=[
+                'code'=>$data['actCode'],
+                'belong'=>1,
+                'openId'=>'oOpc26OhvWzdO0JlL9Q37rXyu69I',
+                'template_id'=>'oUFsqOfVNgavlzQKs9bT1as1miFNJ5-Q-h68eFiiQ0Q',
+                'template_name'=>'系统单据处理通知',
+                'action_name'=>'泰行销活动审批推送',
+                'template_data'=>['thing8' => ['value' => '泰行销直播'],
+                                    'thing4' => ['value' => $data['actCode']],
+                                    'thing5' =>['value' => Act::$statusCn[$data['status']]??'未知'],
+                                    'thing17' =>['value' => $data['contactor']],
+                                    'thing20' =>['value' => $data['depart']]
+                                    ],
+                'uid'=>106,
+                'uname'=>'魏莉',
+            ];
+        Cache::store('redis')->handler()->lPush('wxpush_queue',json_encode($temps));
+    }
+}

+ 4 - 1
app/txx/model/ActGood.php

@@ -41,7 +41,10 @@ class ActGood extends Model
                     $act = \app\txx\model\Act::where(['actCode'=>$actCode])->findOrEmpty();
                     if(!$act->isEmpty()){
                         $act->status=$actStatus[$goodStatus];
-                        $act->save();
+                        $save=$act->save();
+                        if($save&&$goodStatus==3){
+                            event("wxPush",$act->toArray());
+                        }
                     }
                }
      }

+ 2 - 5
app/youzan/logic/Goodup.php

@@ -4,6 +4,7 @@ namespace app\youzan\logic;
 
 use app\admin\common\User;
 use app\admin\model\ActionLog;
+use app\admin\model\GoodTax;
 use app\admin\model\ProcessOrder;
 use app\txx\model\YzGood;
 use app\youzan\model\PlatformYouzan;
@@ -587,11 +588,7 @@ class Goodup
         $ladder = Db::name("good_ladder")->where(['skuCode' => $data['skuCode'], "is_del" => 0])->select()->toArray();
         $data["ladderlist"] = !empty($ladder) ? $ladder : [];
         $nakelist = Db::name("good_nake")->where(['spuCode' => $data['spuCode'], "is_del" => 0])->select()->toArray();
-//        $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
-
-//        $cat_top_list = $data['yz_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;
+        $data['tax_info']=GoodTax::with(['Tax','OutTax'])->where(['spuCode'=>$data['spuCode']])->findOrEmpty();
         $gold_price = 0;
         if ($data['is_gold_price'] == 1 && $data['cost_fee'] != 0 && $data['good_price'] == 0) {
             $gold_price = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->value('price', 0);