wugg 3 ماه پیش
والد
کامیت
3a1f0d8763

+ 84 - 0
app/cxinv/command/MakeSeal.php

@@ -0,0 +1,84 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\cxinv\command;
+
+use app\cxinv\model\ProductFz;use app\cxinv\model\ProductOnlog;use app\cxinv\model\ProductSeal;use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;
+
+class MakeSeal extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('makeseal')
+            ->setDescription('the makeseal command');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        $list = $this->GetInfo();
+        while ( $list->valid()){
+            $item = $list->current();
+            $this->makeSeal($item);
+            $list->next();
+        }
+    }
+
+    public function GetInfo()
+    {
+        $info = ProductFz::where([['status','=',1]])->order("fz_date asc")->cursor();
+        foreach ($info as $item){
+            yield $item->toArray();
+        }
+    }
+
+    public function makeSeal($item){
+        $lastMonth = date('Ym',strtotime('-1 month',strtotime($item['fz_date'])));
+        $ist = ProductFz::where([['fz_date','=',$lastMonth],['status','=',2],['company_code','=',$item['company_code']]])->findOrEmpty();
+        if($ist->isEmpty()){
+            $item['status']=3;
+            $item['remark']=$lastMonth.'未封账';
+            (new ProductFz)->save($item);
+        };
+        (new ProductSeal)->saveAll($this->getProductLog($item,$ist->id));
+    }
+
+    public function getProductLog($item,$lastId){
+      $pastLog= ProductOnlog::withJoin(['Product'],'left')
+       ->where([['fz_date','=',$item['fz_date']],['company_code','=',$item['company_code']]])
+       ->field('type,product_id,skuCode,goodName,spec,unit,unit_price,num')->cursor();
+      $list=[];
+      $balance = ProductSeal::where([['fz_id','=',$lastId],['balance_num','>',0]])->column('balance_num','product_id');
+      foreach ($pastLog as $item){
+          if(!isset($list[$item['product_id']])){
+              $list[$item['product_id']] = [
+                  'product_id'=>$item['product_id'],
+                  'skuCode'=>$item['skuCode'],
+                  'goodName'=>$item['goodName'],
+                  'spec'=>$item['spec'],
+                  'unit'=>$item['unit'],
+                  'unit_price'=>$item['unit_price'],
+                  'begin_num'=>$balance[$item['product_id']]??"0",
+                  'in_num'=>"0",
+                  'out_num'=>"0",
+                  'balance_num'=>$balance[$item['product_id']]??"0",
+                   'fz_id'=>$item['fz_id'],
+              ];
+          }
+          if($item['type']==3|| $item['type']==1){
+              $list[$item['product_id']]['balance_num']=bcadd($list[$item['product_id']]['balance_num'],$item['num'],8);
+              $list[$item['product_id']]['in_num']=bcadd($list[$item['product_id']]['in_num'],$item['num'],8);
+          }
+          if($item['type']==4|| $item['type']==2){
+              $list[$item['product_id']]['balance_num']=bcsub($list[$item['product_id']]['balance_num'],$item['num'],8);
+              $list[$item['product_id']]['out_num']=bcadd($list[$item['product_id']]['out_num'],$item['num'],8);
+          }
+       }
+      return array_values($list);
+    }
+
+}

+ 1 - 1
app/cxinv/controller/FinancialProducts.php

@@ -293,7 +293,7 @@ class FinancialProducts extends Base{
              if($use->isEmpty()) throw new \think\Exception("新增盘点单失败");
         }catch (\Exception $e){
             $this->model->rollback();
-            return error($e->getMessage());
+            return error($e->getTrace());
         }
         $this->model->commit();
       return success('盘点单创建成功');

+ 20 - 0
app/cxinv/model/ProductFz.php

@@ -0,0 +1,20 @@
+<?php
+namespace app\cxinv\model;
+
+class ProductFz extends Base
+{
+//设置字段信息
+    protected $schema = [
+        'id'  =>'bigint',//
+        'fzCode'  =>'varchar',//封账编号
+        'company_code'  =>'varchar',//业务公司编号
+        'company_name'  =>'varchar',//业务公司名称
+        'fz_date'  =>'varchar',//封账月份
+        'status'  =>'tinyint',//
+        'apply_id'  =>'int',//
+        'apply_name'  =>'varchar',//
+        'update_name'  =>'varchar',//
+        'create_time'  =>'datetime',//
+        'update_time'  =>'datetime',//
+       ];
+}

+ 1 - 0
app/cxinv/model/ProductOnlog.php

@@ -11,6 +11,7 @@ class ProductOnlog extends Base
         'product_id'  =>'bigint',//商品id
         'first_on_time'  =>'datetime',//第一次入账
         'on_time'  =>'datetime',//入账时间
+        "fz_date"=>'varchar',
         'num'  =>'decimal',//入账数量
         'unit_price'  =>'decimal',//单价
         'rate'  =>'varchar',//税率

+ 46 - 0
app/cxinv/model/ProductSeal.php

@@ -0,0 +1,46 @@
+<?php
+namespace app\cxinv\model;
+
+use think\model\concern\SoftDelete;
+class ProductSeal extends Base
+{
+    use SoftDelete;
+//设置字段信息
+    protected $schema = [
+        'id'  =>'bigint',//
+        'product_id'  =>'bigint',//商品id
+        'skuCode'  =>'varchar',//商品编号
+        'goodName'  =>'varchar',//商品名称
+        'spec'  =>'varchar',//规格
+        'unit'  =>'varchar',//单位
+        'unit_price'  =>'decimal',//单价
+        'begin_num'  =>'decimal',//期初数据
+        'in_num'  =>'decimal',//收入数据
+        'out_num'  =>'decimal',//发出数据
+        'balance_num'  =>'decimal',//结存数据
+        'fz_id'  =>'bigint',//封账id
+        'create_time'  =>'datetime',//
+        'update_time'  =>'datetime',//
+        'delete_time'  =>'datetime',//
+       ];
+    protected $createTime = 'create_time';
+    protected $updateTime = 'update_time';
+    protected $deleteTime = 'delete_time';
+    protected $append=['begin_total_price','in_total_price','out_total_price','balance_total_price'];
+    public function PorductFz(){
+        return $this->belongsTo(ProductFz::class,'fz_id','id');
+    }
+    public function getBeginTotalPriceAttr($value,$data){
+        return bcmul($data['begin_num'],$data['unit_price'],8);
+    }
+
+    public function getInTotalPriceAttr($value,$data){
+        return bcmul($data['in_num'],$data['unit_price'],8);
+    }
+    public function getOutTotalPriceAttr($value,$data){
+        return bcmul($data['out_num'],$data['unit_price'],8);
+    }
+    public function getBalanceTotalPriceAttr($value,$data){
+        return bcmul($data['balance_num'],$data['unit_price'],8);
+    }
+}