wugg 7 місяців тому
батько
коміт
87059a0b44

+ 7 - 8
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\GoodTax;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,13 +284,12 @@ class Purch extends Base
         if (empty($goon)) {
             return error_show(1002, "未找到商品数据");
         } else {
-            $taxInfo=GoodTax::with(['tax'])->where(['spuCode'=>$data['spuCode']])->findOrEmpty();
-            $data['tax_id'] = $taxInfo['tax_id']??'';
-            $data['tax_name'] = $taxInfo['cat_name']??'';
-            $data['tax_short_name'] =$taxInfo['short_name']??'';
-            $data['tax_code'] =$taxInfo['merge_code']??'';
-            $data['tax']=$taxInfo['tax']??'';
-            $data['inv_good_name']=$taxInfo['inv_good_name']??'';
+         $taxInfo=OrderTax::where(['code'=>$data['cgdNo']])->findOrEmpty();
+         $data['tax_name'] = $taxInfo['tax_name']??'';
+         $data['tax_code'] =$taxInfo['tax_code']??'';
+         $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'] : '';

+ 80 - 17
app/admin/controller/Sale.php

@@ -7,7 +7,7 @@ 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\GoodLog;
 use app\admin\model\GoodPlatform;use app\admin\model\GoodStockInfo;
-use app\admin\model\GoodTax;use app\admin\model\OrderOutChild;use app\admin\model\ProcessOrder;
+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\admin\model\SaleInfo;
 use app\bbc\model\BbcFill;use app\model\TaxCategory;use app\model\TaxRelation;use Exception;
 use think\App;
@@ -275,6 +275,19 @@ class Sale extends Base
             $paytime == "" ? "" : $data['paytime'] = $paytime;
             $datainfo = Db::name('sale')->insert($data, true);
             if ($datainfo > 0) {
+                $taxInfo = OrderTax::SpuCat($spuCode,1,2);
+                if (!empty($taxInfo)) {
+                   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['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
@@ -576,6 +589,19 @@ class Sale extends Base
         ];
         $up = Db::name("purchease_order")->insert($cg, true);
         if ($up) {
+             $taxInfo = OrderTax::SpuCat($data['spuCode'],1,1);
+                if (!empty($taxInfo)) {
+                   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['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
@@ -1077,7 +1103,6 @@ class Sale extends Base
             ];
             $datainfo = Db::name('sale')->insert($data, true);
             if ($datainfo > 0) {
-
                 $standing_book_data = [
                     'sale_id' => $datainfo,
                     'infoNo' => $zxinfo['infoNo'],
@@ -1115,11 +1140,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'],
@@ -1210,6 +1230,24 @@ class Sale extends Base
 				    ];
                     GoodTax::create($data);
                 }
+               $taxInfo = OrderTax::SpuCat($spuCode,1,2);
+                if (!empty($taxInfo)) {
+                   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['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();
@@ -1678,10 +1716,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");
@@ -1793,6 +1827,23 @@ class Sale extends Base
             				    ];
                                 GoodTax::create($data);
                             }
+           $taxInfo = OrderTax::SpuCat( $data['spuCode'],1,2);
+           if (!empty($taxInfo)) {
+              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['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();
@@ -2060,6 +2111,20 @@ class Sale extends Base
 		        'cgd_apply_id'=>$good['cgd_apply_id'],//竞单人
 		        'cgd_apply_name'=>$good['cgd_apply_name'],//竞单人
             ];
+            $taxInfo = OrderTax::SpuCat( $data['spuCode'],1,2);
+           if (!empty($taxInfo)) {
+              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['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) {
@@ -2515,12 +2580,10 @@ class Sale extends Base
         if ($goon == false) {
             return error_show(1003, "未找到商品数据");
         } else {
-            $taxInfo=GoodTax::with(['tax'])->where(['spuCode'=>$einfo['good_code']])->findOrEmpty();
-            $einfo['tax_id'] = $taxInfo['tax_id']??'';
-            $einfo['tax_name'] = $taxInfo['cat_name']??'';
-            $einfo['tax_short_name'] =$taxInfo['short_name']??'';
-            $einfo['tax_code'] =$taxInfo['merge_code']??'';
-            $einfo['tax']=$taxInfo['tax']??'';
+            $taxInfo=OrderTax::where(['code'=>$einfo['orderCode']])->findOrEmpty();
+            $einfo['tax_name'] = $taxInfo['tax_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();

+ 5 - 1
app/admin/model/GoodTax.php

@@ -21,7 +21,11 @@ class GoodTax extends Model
     public function Tax(){
         return $this->belongsTo(TaxCategory::class,'tax_id','id')->bind(['cat_name','cat_code','short_name','merge_code']);
     }
-
+    /**
+    * @param $spuCode
+    * @param int $type 1 进项票 2 销项票
+     * @return array
+     */
     public static function getInfobySpuCode($spuCode,$type=1){
         $item = (new GoodTax)->with(['Tax'])->where(['spuCode'=>$spuCode])->findOrEmpty();
         if($item->isEmpty()) return [];

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

@@ -0,0 +1,32 @@
+<?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()) return $result;
+              foreach ($goods as $item){
+               $temp = GoodTax::getInfobySpuCode($item->spuCode,$order_type);
+               if(empty($temp)) continue;
+               $result[]=$temp;
+              }
+         }else{
+            $temp = GoodTax::getInfobySpuCode($spuCode,$order_type);
+            $result[]=$temp;
+         }
+        return $result;
+    }
+}

+ 29 - 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,19 @@ class ImportOrderFromCHandleData extends Command
                         }
 					SaleCgdPrice::GetPrice($datainfo);
                     }
+            $taxInfo = OrderTax::SpuCat( $spuCode,$goodinfo['open_type'],2);
+           if (!empty($taxInfo)) {
+              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['inv_tax']=$item['tax'];
+                   $temp['inv_good_name']=$item['inv_good_name'];
+                   return $temp;
+              },$taxInfo));
+            }
                     if ($sendtype == 1) {
                         $temp = [
                             'orderCode' => $orderCode,
@@ -557,6 +570,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 +587,20 @@ class ImportOrderFromCHandleData extends Command
         ];
         $up = Db::name("purchease_order")->insert($cg, true);
         if ($up) {
-
-            //修改状态,添加待办
+            $taxInfo = OrderTax::SpuCat( $data['spuCode'],$data['open_type'],1);
+           if (!empty($taxInfo)) {
+              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['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是之前的值

+ 30 - 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,19 @@ class handleYzOrderData extends Command
 	                        }
 					SaleCgdPrice::GetPrice($datainfo);
                     }
+           $taxInfo = OrderTax::SpuCat( $spuCode,$goodinfo['open_type'],2);
+           if (!empty($taxInfo)) {
+              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['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 +573,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 +589,19 @@ class handleYzOrderData extends Command
         ];
         $up = Db::name("purchease_order")->insert($cg, true);
         if ($up) {
-
+            $taxInfo = OrderTax::SpuCat( $data['spuCode'],$data['open_type'],1);
+           if (!empty($taxInfo)) {
+              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['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