SeckillEnd.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\common\command;
  20. use app\common\enum\ActivityEnum;
  21. use app\common\enum\SeckillEnum;
  22. use app\common\model\GoodsActivity;
  23. use app\common\model\SeckillActivity;
  24. use think\console\Command;
  25. use think\console\Input;
  26. use think\console\Output;
  27. class SeckillEnd extends Command
  28. {
  29. protected function configure()
  30. {
  31. $this->setName('seckill_end')
  32. ->setDescription('结束过期的秒杀活动');
  33. }
  34. protected function execute(Input $input, Output $output)
  35. {
  36. // 查找已过期的秒杀活动
  37. $ids = SeckillActivity::where([
  38. ['status', '=', SeckillEnum::SECKILL_STATUS_CONDUCT,],
  39. ['end_time', '<=', time()]
  40. ])->column('id');
  41. // 结束已过期的秒杀活动
  42. if (count($ids)) {
  43. SeckillActivity::update([ 'status' => SeckillEnum::SECKILL_STATUS_END ], [ [ 'id', 'in', $ids ] ]);
  44. }
  45. // 删除商品活动信息表的数据
  46. $goodsActivityIds = GoodsActivity::where([
  47. ['activity_type', '=', ActivityEnum::SECKILL],
  48. ['activity_id', 'in', $ids],
  49. ])->column('id');
  50. if (count($goodsActivityIds)) {
  51. GoodsActivity::destroy($goodsActivityIds);
  52. }
  53. }
  54. }