ProductDelist.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Facades\Servers\Redis\RedisLock;
  5. use App\Facades\Servers\WechatWork\ExternalContact;
  6. use App\Models\Product as Model;
  7. class ProductDelist extends Command
  8. {
  9. /**
  10. * 任务名称
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'product_delist';
  15. /**
  16. * 任务描述
  17. *
  18. * @var string
  19. */
  20. protected $description = '产品自动上下架';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return int
  34. */
  35. public function handle()
  36. {
  37. // 执行任务
  38. $this->run_task();
  39. return 0;
  40. }
  41. /**
  42. * 执行任务
  43. *
  44. * */
  45. public function run_task(){
  46. // 实例化
  47. $Model = New Model();
  48. // 限购自动下架
  49. $Model->query()->where([['quota_end','>',0],['quota_end','<=',time()],['status','=',0]])->update(['status'=>1,'update_time'=>time()]);
  50. // 预上架的产品自动上架
  51. $Model->query()->where([['puton_time','>',0],['puton_time','<=',time()],['status','=',2]])->update(['status'=>0,'update_time'=>time()]);
  52. // 已上架并且需要自动下架的产品,自动下架
  53. $Model->query()->where([['putoff_time','>',0],['putoff_time','<=',time()],['status','=',0]])->update(['status'=>4,'update_time'=>time()]);
  54. }
  55. }