wugg 8 ヶ月 前
コミット
401867ff34
1 ファイル変更34 行追加7 行削除
  1. 34 7
      app/admin/controller/Activity.php

+ 34 - 7
app/admin/controller/Activity.php

@@ -5,9 +5,12 @@ 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\ProcessOrder;
+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 app\model\TaxCategory;use think\App;
 use think\facade\Db;use think\facade\Validate;
 
 class Activity extends Base
@@ -193,7 +196,7 @@ class Activity extends Base
         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];
+            $where[] = ['b.status', '=', $tax_status==0?null :$tax_status];
         }
 
         $count = Db::name('good_zixun')
@@ -295,12 +298,36 @@ class Activity extends Base
         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("商品进项税目未设置");
-        $goodTax->out_tax_id=$param['out_tax_id'];
-        $goodTax->out_tax=$param['out_tax'];
-        $goodTax->status=2;
-        $goodTax->save();
+        $order= \app\admin\model\Sale::where(["spuCode"=>$param['spuCode']])->findOrEmpty();
+        Db::startTrans();
+        try{
+                if(!$order->isEmpty()){
+                   $orderTax=OrderTax::where(['code'=>$order->orderCode,'spuCode'=>$param['spuCode']])->findOrEmpty();
+                   if($orderTax->isEmpty()){
+                       $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'=>$param['out_tax'],
+                           'inv_good_name'=>$goodTax->inv_good_name,
+                       ];
+                     OrderTax::create($Tax);
+                   }
+                };
+                $goodTax->out_tax_id=$param['out_tax_id'];
+                $goodTax->out_tax=$param['out_tax'];
+                $goodTax->status=2;
+                $goodTax->save();
+                Db::commit();
+        }catch (\Exception $e){
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
         return app_show(0,"设置成功");
     }