Regiment.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Orders;
  4. use Illuminate\Console\Command;
  5. use App\Facades\Servers\Redis\RedisLock;
  6. use App\Facades\Servers\WechatWork\ExternalContact;
  7. use App\Models\RegimentActive as Model;
  8. use App\Models\Regiment as RegimentModel;
  9. use App\Models\RegimentRecord;
  10. class Regiment extends Command
  11. {
  12. /**
  13. * 任务名称
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'regiment';
  18. /**
  19. * 任务描述
  20. *
  21. * @var string
  22. */
  23. protected $description = '拼团活动时间到期';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return int
  37. */
  38. public function handle()
  39. {
  40. // 执行任务
  41. $this->run_task();
  42. return 0;
  43. }
  44. /**
  45. * 执行任务
  46. *
  47. * */
  48. public function run_task(){
  49. // 实例化
  50. $Model = New Model();
  51. $time = time();
  52. // 活动结束
  53. $activeList = $Model->query()->where([['end_time','<=',time()],['status','=',1]])->get();
  54. $activeList = array_column($activeList,null,'id');
  55. if ($activeList){
  56. $activeIds = array_column($activeList,'id');
  57. $regiment = RegimentModel::query()->where('status','=',1)->whereIn('id',$activeIds)->get();
  58. if ($regiment){
  59. foreach ($regiment as $v){
  60. //虚拟成团
  61. if ($activeList[$v['active_id']]['virtually'] == 2){
  62. //修改状态
  63. RegimentModel::query()->where('id','=',$v['id'])->update(['status'=>3]);
  64. RegimentRecord::query()->where('regiment_id','=',$v['id'])->update(['status'=>2]);
  65. //查询记录
  66. $regimentRecordList = regimentRecord::query()->where('regiment_id','=',$v['id'])->get();
  67. $regimentRecordListIds = array_column($regimentRecordList,'id');
  68. //修改订单
  69. $res = Orders::query()->whereIn('id',$regimentRecordListIds)->get();
  70. }else{
  71. RegimentModel::query()->where('id','=',$v['id'])->update(['status'=>2]);
  72. RegimentRecord::query()->where('regiment_id','=',$v['id'])->update(['status'=>3]);
  73. }
  74. }
  75. }
  76. }
  77. }
  78. }