wugg vor 4 Monaten
Ursprung
Commit
80df49e901

+ 112 - 8
app/admin/controller/GoodZx.php

@@ -4,32 +4,136 @@
 namespace app\admin\controller;
 
 
+use app\admin\model\GoodBasic;
+use app\admin\model\GoodPlatform;
+use app\admin\model\GoodTax;
+use app\admin\model\OrderTax;
+use app\cxinv\model\OrderCategory;
+use app\user\model\AccountItem;
 use think\App;
 class GoodZx extends Base{
     public function __construct(App $app)
     {
-        $this->noLogin=['list'];
         parent::__construct($app);
         $this->model=new \app\admin\model\GoodZixun();
     }
     public function list(){
         $param = $this->request->param(["spuCode"=>"","status"=>"","tax_status"=>"","order_source"=>"","orderCode"=>"",
-        "start"=>"","end"=>"","relaComNo"=>"","good_name"=>"","supplierNo"=>"","name"=>"","page"=>"","size"=>""],"post","trim");
+        "start"=>"","end"=>"","relaComNo"=>"","good_name"=>"","supplierNo"=>"","name"=>"","page"=>"1","size"=>"10"],"post","trim");
         $where =[['is_del','=',0]] ;
-        if($param['spuCode']!="") $where[]=['spuCode','like',"%".$param['spuCode']."%"];
+        if($param['spuCode']!="") $where[]=['good_zixun.spuCode','like',"%".$param['spuCode']."%"];
         if($param['status']!="") $where[]=['good_zixun.status','=',$param['status']];
         if($param['tax_status']!="") $where[]=['good_tax.status','=',$param['tax_status']==0?null:$param['tax_status']];
         if($param['order_source']!="") $where[]=['order_source','=',$param['order_source']];
-        if($param['orderCode']!="") $where[]=['spuCode','in',\app\admin\model\Sale::where("orderCode","=",$param['orderCode'])->column("good_code")];
-        if($param['relaComNo']!="") $where[]=['companyNo|supplierNo','like',"%".$param['relaComNo']."%"];
+        if($param['orderCode']!="") $where[]=['good_zixun.spuCode','in',\app\admin\model\Sale::where("orderCode","=",$param['orderCode'])->column("good_code")];
+        if($param['relaComNo']!="") $where[]=['good_zixun.companyNo|supplierNo','like',"%".$param['relaComNo']."%"];
         if($param['good_name']!="") $where[]=['good_name','like',"%".$param['good_name']."%"];
         if($param['supplierNo']!="") $where[]=['supplierNo','like',"%".$param['supplierNo']."%"];
         if($param['name']!="") $where[]=['supplierName','like',"%".$param['name']."%"];
-        $list = $this->model->with(["brand","unit","cat","GoodTax"])->withJoin("good_tax","left")
+        $list = $this->model->with(["brand","unit","cat","Platform","GoodTax"=>["outCategory","inCategory","cgdCategory"]])->withJoin("good_tax","left")
         ->where($where)->order('id desc')
-        ->paginate(['page'=>$param['page'],'list_rows'=>$param['size']]);
+        ->paginate(['page'=>$param['page'],'list_rows'=>$param['size']])
+        ->each(function(&$item){
+                $item['cat_info'] = explode("_",$item->search);
+                $item['is_basic'] =GoodBasic::where("spuCode","=",$item['spuCode'])->value("status");
+                $item['is_online'] = GoodPlatform::where("spuCode","=",$item['spuCode'])->findOrEmpty()->isEmpty()?0:1;
+                $item["orderCode"] = \app\admin\model\Sale::where("good_code","=",$item['spuCode'])->value("orderCode");
+                $account = AccountItem::with(["ItemName"])->where("account_id","=",$item['order_createrid'])->findOrEmpty();
+                $item["order_creater_depart"] = $account["depart_name"]??"";
+        });
+        $list->hidden(["brand","unit","cat","good_tax","GoodTax","Platform"]);
         return success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
-        
+    }
+    //添加或修改商品税目
+    public function changeTax(){
+        $param = $this->request->param([
+            "spuCode"=>"",
+            "isToSale"=>0, //是否同步结算销售单
+            "isToCgd"=>0, //是否同步结算采购单
+            "isToGood"=>0, //是否同步结算商品库
+            "tax_id"=>"",
+            "tax"=>"",
+            "inv_good_name"=>"",
+            "out_tax_id"=>"",
+            "out_tax"=>"",
+            "cgd_tax_id"=>"",
+            "cgd_tax"=>"",
+            ],"post","trim");
+        $validate = $this->validate($param,[
+            "spuCode|商品编码"=>"require",
+            "isToSale|是否同步结算销售单"=>"number|in:0,1",
+            "isToCgd|是否同步结算采购单"=>"number|in:0,1",
+            "isToGood|是否同步结算商品库"=>"number|in:0,1",
+            "tax_id|进项税目"=>"require",
+            "tax|进项税率"=>"number",
+            "inv_good_name|开票商品名称"=>"require",
+            "out_tax_id|销项税目"=>"require",
+            "out_tax|销项税率"=>"number",
+            "cgd_tax_id|源头税目"=>"require",
+            "cgd_tax|源头税率"=>"number",
+        ]);
+        if($validate!==true) return error($validate);
+        $good= $this->model->where("spuCode","=",$param['spuCode'])->findOrEmpty();
+        if($good->isEmpty()) return error("咨询商品不存在");
+        $good_tax = GoodTax::where("spuCode","=",$param['spuCode'])->findOrEmpty();
+        $good_tax->open_type=$good->open_type;
+        $good_tax->companyNo = $good->companyNo;
+        $good_tax->tax_id = $param['tax_id'];
+        $good_tax->tax = $param['tax'];
+        $good_tax->inv_good_name = $param['inv_good_name'];
+        $good_tax->out_tax_id = $param['out_tax_id'];
+        $good_tax->out_tax = $param['out_tax'];
+        $good_tax->cgd_tax_id = $param['cgd_tax_id'];
+        $good_tax->cgd_tax = $param['cgd_tax'];
+        $good_tax->createrid=$this->uid;
+        $good_tax->creater=$this->uname;
+        $this->model->startTrans();
+        try{
+            $save=$good_tax->save();
+            if($save==false) throw new \Exception("添加失败");
+            if($param['isToSale']==1){
+                $sale = \app\admin\model\Sale::where("good_code","=",$param['spuCode'])->findOrEmpty();
+                if($sale->isEmpty()) return error("咨询销售单不存在");
+                $sale->updatetime=date('Y-m-d H:i:s');
+                $sale->save();
+                if($sale->save()==false) throw new \Exception("同步销售单失败");
+                OrderTax::where(["spuCode"=>$param['spuCode'],"code"=>$sale->orderCode])->delete();
+                OrderCategory::where(["spuCode"=>$param['spuCode']])->whereNotLike("code","CG%")
+                ->save(["cat_code"=>"","cat_name"=>"","merge_code"=>"","tax"=>"","short_name"=>"","inv_good_name"=>""]);
+            }
+            if($param['isToCgd']==1){
+                $cgd = \app\admin\model\PurcheaseOrder::where("spuCode","=",$param['spuCode'])->findOrEmpty();
+                if($cgd->isEmpty()) return error("咨询采购单不存在");
+                $cgd->updatetime=date('Y-m-d H:i:s');
+                if($cgd->save()==false) throw new \Exception("同步采购单失败");
+                OrderTax::where(['spuCode'=>$param['spuCode'],'code'=>$cgd->cgdNo])->delete();
+                OrderCategory::where(["spuCode"=>$param['spuCode'],'code'=>$cgd->cgdNo])->save(["cat_code"=>"","cat_name"=>"","merge_code"=>"","tax"=>"","short_name"=>"","inv_good_name"=>""]);
+            }
+            if($param['isToGood']==1){
+                $good->updatetime=date('Y-m-d H:i:s');
+                $sa=$good->save();
+                if($sa==false) throw new \Exception("同步商品库失败");
+            }
+            $this->model->commit();
+        }catch (\Exception $e){
+            $this->model->rollback();
+            return error("添加失败");
+        }
+        return success("添加成功");
+    }
+
+    public function info(){
+        $id = $this->request->post("id","", "int");
+        $info = $this->model->with(["brand","unit","cat","Platform","GoodTax"=>["outCategory","inCategory","cgdCategory"]])
+        ->where("id","=",$id)->findOrEmpty();
+        if($info->isEmpty()) return error("咨询商品不存在");
+        $info['cat_info'] = explode("_",$info->search);
+        $info['is_basic'] =GoodBasic::where("spuCode","=",$info['spuCode'])->value("status");
+        $info['is_online'] = GoodPlatform::where("spuCode","=",$info['spuCode'])->findOrEmpty()->isEmpty()?0:1;
+        $info["orderCode"] = \app\admin\model\Sale::where("good_code","=",$info['spuCode'])->value("orderCode");
+        $account = AccountItem::with(["ItemName"])->where("account_id","=",$info['order_createrid'])->findOrEmpty();
+        $info["order_creater_depart"] = $account["depart_name"]??"";
+        return  success("获取成功",$info);
     }
 
 }

+ 6 - 0
app/admin/model/Base.php

@@ -12,5 +12,11 @@ class Base extends Model
 {
     public static $statusCn = ["禁用","启用"];
     public static $deleteCn = ["已删除","正常"];
+    public static $NobleMetalCn =[
+                    '0'=>'',
+                    '1'=>'18K',
+                    '2'=>'24K',
+                    '3'=>'白银',
+                ];
 }
 

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

@@ -60,16 +60,30 @@ class GoodZixun extends Base
         'order_type'       =>'tinyint',//商品类型
         'order_createrid'       =>'int',//订单创建人
         'order_creater'       =>'varchar',//订单创建人
+        "open_type"=>"tinyint"
     ];
 
     public function Brand(){
-        return $this->hasOne('Brand','brand_id','id')->bind(["brand_name"]);
+        return $this->hasOne('Brand','id','brand_id')->bind(["brand_name"]);
     }
     public function Cat(){
-        return $this->hasOne('Cat','cat_id','id')->bind(["cat_name"]);
+        return $this->hasOne('Cat','id','cat_id')->bind(["search"]);
     }
     public function Unit(){
-        return $this->hasOne('Unit','good_unit','id')->bind(["unit_name"]);
+        return $this->hasOne('Unit','id','good_unit')->bind(["unit_name"=>"unit"]);
+    }
+
+    public function Platform(){
+        return $this->hasOne('Platform','id','platform_id')->bind(["platform_name"]);
+    }
+    public function getSpecinfoAttr($argv){
+        return json_decode($argv,true);
+    }
+     public function getNobleMetalAttr($argv){
+        return parent::$NobleMetalCn[$argv]??"";
+    }
+    public function setSpecinfoAttr($argv){
+        return json_encode($argv,JSON_UNESCAPED_UNICODE);
     }
     public function GoodTax(){
          return $this->hasOne('GoodTax','spuCode','spuCode')
@@ -91,7 +105,8 @@ class GoodZixun extends Base
                 "cgd_tax_name",
                 "cgd_tax_cat_code",
                 "addTax",
-                "sumitem"
+                "sumitem",
+                "tax_status"=>"status"
                 ]);
     }
 }

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

@@ -0,0 +1,19 @@
+<?php
+
+
+namespace app\admin\model;
+
+
+class OrderTax extends Base{
+    protected $schema = [
+        'id'  =>'bigint',//
+        'code'  =>'varchar',//
+        'spuCode'  =>'varchar',//
+        'tax_code'  =>'varchar',//
+        'tax_name'  =>'varchar',//
+        'tax_short_name'  =>'varchar',//
+        'inv_tax'  =>'varchar',//
+        'inv_good_name'  =>'varchar',//
+        'createTime'  =>'datetime',//
+       ];
+}

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

@@ -11,6 +11,5 @@ class OrgItem extends Base
         'is_del'       =>'int',//是否删除
         'addtime'       =>'datetime',//
         'updatetime'       =>'datetime',//
-
     ];
 }