wugg hai 7 meses
pai
achega
f718ea7264

+ 4 - 1
app/admin/model/GoodBasic.php

@@ -95,6 +95,9 @@ class GoodBasic extends Base
     }
 
     public function GoodTax(){
-        return $this->hasOne('GoodTax',"spuCode",'spuCode')->bind(["cgd_inv_tax"=>"tax","tax_id","cgd_inv_good_name"=>"inv_good_name"]);
+        return $this->hasOne('GoodTax',"spuCode",'spuCode')
+        ->bind(["cgd_inv_tax"=>"tax","cgd_inv_cat_name"=>"in_tax_short_name","cgd_inv_cat_code"=>"in_tax_merge_code",
+        "cgd_inv_good_name"=>"inv_good_name","inv_good_name","inv_tax"=>"out_tax","inv_cat_name"=>"out_tax_short_name",
+        "inv_cat_code"=>"out_tax_merge_code","addtax","sumitem"]);
     }
 }

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

@@ -1,7 +1,7 @@
 <?php
 namespace app\admin\model;
 
-use think\model\concern\SoftDelete;
+use app\user\model\TaxCategory;use think\model\concern\SoftDelete;
 class GoodTax extends Base
 {
     use SoftDelete;
@@ -14,6 +14,9 @@ class GoodTax extends Base
         'companyNo'  =>'varchar',//业务公司
         'open_type'  =>'tinyint',//开票类型
         'inv_good_name'  =>'varchar',//开票商品名称
+        "out_tax"=>"varchar",
+        "out_tax_id"=>"int",
+        "status"=>"int",
         'createrid'  =>'int',//
         'creater'  =>'varchar',//
         'createTime'  =>'datetime',//
@@ -23,4 +26,14 @@ class GoodTax extends Base
     protected $createTime='createTime';
     protected $updateTime='updateTime';
     protected $deleteTime='delete_time';
+
+    public function outCategory(){
+        return $this->hasOne(TaxCategory::class,'out_tax_id','id')
+        ->bind(["out_tax_name"=>"cat_name","out_tax_short_name"=>"short_name","out_tax_merge_code"=>"merge_code","out_tax_cat_code"=>"cat_code","out_bind_tax"=>"tax"]);
+    }
+
+    public function inCategory(){
+        return $this->hasOne(TaxCategory::class,'tax_id','id')
+        ->bind(["in_tax_name"=>"cat_name","in_tax_short_name"=>"short_name","in_tax_merge_code"=>"merge_code","in_tax_cat_code"=>"cat_code","in_bind_tax"=>"tax","addtax","sumitem"]);
+    }
 }

+ 4 - 1
app/admin/model/GoodZixun.php

@@ -72,6 +72,9 @@ class GoodZixun extends Base
         return $this->hasOne('Unit','good_unit','id')->bind(["unit_name"]);
     }
     public function GoodTax(){
-        return $this->hasOne('GoodTax',"spuCode",'spuCode')->bind(["cgd_inv_tax"=>"tax","tax_id","cgd_inv_good_name"=>"inv_good_name"]);
+         return $this->hasOne('GoodTax','spuCode','spuCode')
+        ->bind(['cgd_inv_tax'=>'tax','cgd_inv_cat_name'=>'in_tax_short_name','cgd_inv_cat_code'=>'in_tax_merge_code',
+        'cgd_inv_good_name'=>'inv_good_name','inv_good_name','inv_tax'=>'out_tax','inv_cat_name'=>'out_tax_short_name',
+        'inv_cat_code'=>'out_tax_merge_code','addtax','sumitem']);
     }
 }

+ 139 - 0
app/command/sysGood.php

@@ -0,0 +1,139 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\command;
+
+use app\admin\model\GoodBasic;
+use app\admin\model\GoodZixun;
+use app\user\model\TaxRelation;
+use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;
+use think\facade\Cache;
+
+class sysGood extends Command
+{
+    protected $date;
+
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('sysgood')
+            ->setDescription('the sysgood command');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        $this->date = date('Y-m-d H:i:s', time() - 3600);
+
+        try {
+            $this->processGoods('goodBasic');
+            $this->processGoods('goodZx');
+        } catch (\Exception $e) {
+            $output->writeln('【' . date('Y-m-d H:i:s') . '】' . $e->getMessage());
+        }
+    }
+
+    protected function processGoods($method)
+    {
+        $goods = call_user_func([$this, $method]);
+
+        if (empty($goods)) {
+            return;
+        }
+
+        $this->addGood($goods);
+    }
+
+    protected function goodBasic()
+    {
+        return $this->processGood(GoodBasic::class, 0);
+    }
+
+    protected function goodZx()
+    {
+        return $this->processGood(GoodZixun::class, 1);
+    }
+
+    protected function processGood($modelClass, $isZx)
+    {
+        $with = ["unit", "cat", "goodTax"=>["outCategory", "inCategory"]];
+
+        $fields = "spuCode,good_name,craft_desc,supplierNo,companyNo,supplierName,companyName,good_img,
+         good_info_img,good_thumb_img,creater,createrid,{$isZx} as isZx,is_combind,cgd_supplier_code cgd_supplierNo,
+         cgd_supplier_name cgd_supplierName,isChild,addtime,updatetime";
+      if ($isZx == 0) {
+            $fields .=",after_sales,is_stock";
+        }else{
+            $fields .=",'' after_sales, 0 is_stock";
+        }
+
+      return   $modelClass::with($with)
+            ->field($fields)
+            ->where('updatetime', '>=', $this->date)
+            ->where('status', '=', 1)
+            ->where('is_del', 0)
+            ->select()
+            ->each(function (&$item){
+                $this->populateItem($item);
+            });
+    }
+
+    protected function populateItem(&$item)
+    {
+        $item['tax_id'] = $item['tax_id'] ?? 0;
+        $item['cgd_inv_good_name'] = $item['cgd_inv_good_name'] ?? '';
+        $item['inv_cat_name'] = '';
+        $item['inv_cat_code'] = '';
+        $item['inv_tax'] = '';
+        $item['inv_good_name'] = $item['cgd_inv_good_name'] ?? '';
+        $item['cgd_inv_cat_code'] = '';
+        $item['cgd_inv_cat_name'] = '';
+        $item['cgd_inv_tax'] = isset($item['cgd_inv_tax'])?(str_replace('%','',$item['cgd_inv_tax'])/100):"";
+        $item['cat_diff'] = 0;
+        $item['tax_diff'] = 0;
+
+        if (!is_null($item['tax_id']) && $item['tax_id'] != 0) {
+            $taxInfo = TaxRelation::with(["incomeTax", "outputTax"])
+                ->where(['income_tax_id' => $item['tax_id'], "companyNo" => $item['companyNo']])
+                ->findOrEmpty();
+
+            if (!$taxInfo->isEmpty()) {
+                $item['inv_cat_name'] = $taxInfo['output_short_name'];
+                $item['inv_cat_code'] = $taxInfo['output_merge_code'];
+                $item['inv_tax'] =  str_replace("%",'',$taxInfo['output_bind_tax'])/100;
+                $item['cgd_inv_cat_code'] = $taxInfo['income_merge_code'];
+                $item['cgd_inv_cat_name']= $taxInfo['income_short_name'];
+                $item['cat_diff'] = $taxInfo['output_merge_code']===$taxInfo['income_merge_code']?1:2;
+                $item['tax_diff'] = $taxInfo['output_bind_tax']===$item['cgd_inv_tax']?1:2;
+            }
+        }
+
+        $item['status'] = ($item['inv_cat_code'] != '' && $item['cgd_inv_cat_code'] != '') ? 2 : (($item['inv_cat_code'] != '' || $item['cgd_inv_cat_code'] != '') ? 1 : 0);
+    }
+     protected function addGood($goods)
+    {
+        $spuCode = array_column($goods->toArray(), 'spuCode');
+        $idsArr = (new \app\cxinv\model\Good())
+            ->whereIn('spuCode', $spuCode)
+            ->column('id,status,updatetime', 'spuCode');
+        $saveAll = [];
+        foreach ($goods as $item) {
+            if (!isset($idsArr[$item['spuCode']]) ||
+                ($idsArr[$item['spuCode']]['updatetime'] != $item['updatetime'])) {
+                $item['id'] = $idsArr[$item['spuCode']]['id'] ?? null;
+                $saveAll[] = $item->toArray();
+            }
+        }
+
+        if (!empty($saveAll)) {
+            try {
+                (new \app\cxinv\model\Good())->saveAll($saveAll);
+            } catch (\Exception $e) {
+                throw new \Exception($e->getMessage());
+            }
+        }
+    }
+}