updateAct.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\txx\command;
  4. 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;use think\facade\Cache;
  9. class updateAct extends Command
  10. {
  11. protected function configure()
  12. {
  13. // 指令配置
  14. $this->setName('updateact')
  15. ->setDescription('the updateact command');
  16. }
  17. protected function execute(Input $input, Output $output)
  18. {
  19. // 指令输出
  20. if(Cache::get('createPro2')==1) return;
  21. Cache::set('createPro2',1,60);
  22. $actGood=new \app\txx\model\ActGood();//同步券码
  23. $actGood->startTrans();
  24. try{
  25. $info = $actGood->with(['act','promocode'])
  26. ->where(['version'=>'2.0','status'=>2,'is_del'=>0])->order("updatetime asc")->findOrEmpty();
  27. if(!$info->isEmpty()){
  28. if($info->promocode_status==0){
  29. $info->updatetime=date("Y-m-d H:i:s");
  30. $info->save();
  31. }elseif($info->promocode_status==1){
  32. $info->status=3;
  33. $info->save();
  34. }else{
  35. $info->status=5;
  36. $info->remark=$info->promocode_remark;
  37. $info->save();
  38. }
  39. }
  40. $actGood->commit();
  41. }catch (\Exception $e){
  42. $actGood->rollback();
  43. $output->writeln('<error>'.$e->getMessage().'</error>');
  44. }
  45. Cache::set('createPro2',0);
  46. }
  47. }