123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?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);
- }
- }
|