MakeSeal.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\cxinv\command;
  4. use app\cxinv\model\ProductFz;use app\cxinv\model\ProductOnlog;use app\cxinv\model\ProductSeal;use think\console\Command;
  5. use think\console\Input;
  6. use think\console\input\Argument;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. class MakeSeal extends Command
  10. {
  11. protected function configure()
  12. {
  13. // 指令配置
  14. $this->setName('makeseal')
  15. ->setDescription('the makeseal command');
  16. }
  17. protected function execute(Input $input, Output $output)
  18. {
  19. $list = $this->GetInfo();
  20. while ( $list->valid()){
  21. $item = $list->current();
  22. $this->makeSeal($item);
  23. $list->next();
  24. }
  25. }
  26. public function GetInfo()
  27. {
  28. $info = ProductFz::where([['status','=',1]])->order("fz_date asc")->cursor();
  29. foreach ($info as $item){
  30. yield $item->toArray();
  31. }
  32. }
  33. public function makeSeal($item){
  34. $lastMonth = date('Ym',strtotime('-1 month',strtotime($item['fz_date'])));
  35. $ist = ProductFz::where([['fz_date','=',$lastMonth],['status','=',2],['company_code','=',$item['company_code']]])->findOrEmpty();
  36. if($ist->isEmpty()){
  37. $item['status']=3;
  38. $item['remark']=$lastMonth.'未封账';
  39. (new ProductFz)->save($item);
  40. };
  41. (new ProductSeal)->saveAll($this->getProductLog($item,$ist->id));
  42. }
  43. public function getProductLog($item,$lastId){
  44. $pastLog= ProductOnlog::withJoin(['Product'],'left')
  45. ->where([['fz_date','=',$item['fz_date']],['company_code','=',$item['company_code']]])
  46. ->field('type,product_id,skuCode,goodName,spec,unit,unit_price,num')->cursor();
  47. $list=[];
  48. $balance = ProductSeal::where([['fz_id','=',$lastId],['balance_num','>',0]])->column('balance_num','product_id');
  49. foreach ($pastLog as $item){
  50. if(!isset($list[$item['product_id']])){
  51. $list[$item['product_id']] = [
  52. 'product_id'=>$item['product_id'],
  53. 'skuCode'=>$item['skuCode'],
  54. 'goodName'=>$item['goodName'],
  55. 'spec'=>$item['spec'],
  56. 'unit'=>$item['unit'],
  57. 'unit_price'=>$item['unit_price'],
  58. 'begin_num'=>$balance[$item['product_id']]??"0",
  59. 'in_num'=>"0",
  60. 'out_num'=>"0",
  61. 'balance_num'=>$balance[$item['product_id']]??"0",
  62. 'fz_id'=>$item['fz_id'],
  63. ];
  64. }
  65. if($item['type']==3|| $item['type']==1){
  66. $list[$item['product_id']]['balance_num']=bcadd($list[$item['product_id']]['balance_num'],$item['num'],8);
  67. $list[$item['product_id']]['in_num']=bcadd($list[$item['product_id']]['in_num'],$item['num'],8);
  68. }
  69. if($item['type']==4|| $item['type']==2){
  70. $list[$item['product_id']]['balance_num']=bcsub($list[$item['product_id']]['balance_num'],$item['num'],8);
  71. $list[$item['product_id']]['out_num']=bcadd($list[$item['product_id']]['out_num'],$item['num'],8);
  72. }
  73. }
  74. return array_values($list);
  75. }
  76. }