updateAct.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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=6; //同步中
  33. $info->remark='';
  34. $info->save();
  35. }else{
  36. $info->status=5;
  37. $info->remark=$info->promocode_remark;
  38. $info->save();
  39. }
  40. }
  41. $actGood->commit();
  42. }catch (\Exception $e){
  43. $actGood->rollback();
  44. $output->writeln('<error>'.$e->getMessage().'</error>');
  45. }
  46. Cache::set('createPro2',0);
  47. }
  48. }