CouponNotice.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Facades\Servers\Aliyun\Sms;
  5. use App\Models\CustomCoupon as Model;
  6. class CouponNotice extends Command
  7. {
  8. /**
  9. * 任务名称
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'coupon_notice';
  14. /**
  15. * 任务描述
  16. *
  17. * @var string
  18. */
  19. protected $description = '优惠券到期提醒';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return int
  33. */
  34. public function handle()
  35. {
  36. // 执行任务
  37. $this->run_task();
  38. return 0;
  39. }
  40. /**
  41. * 执行任务
  42. *
  43. * */
  44. public function run_task(){
  45. // 实例化模型
  46. $Model = new Model();
  47. // 获取三天后到期的优惠券->addDays(3)
  48. $phoneList = $Model->query()
  49. ->join('custom','custom_coupon.custom_uid','=','custom.uid')
  50. ->where([['custom_coupon.status','=',0],['custom_coupon.exp_time','>',now()->endOfDay()->getTimestamp()],['custom_coupon.exp_time','<',now()->addDays(2)->endOfDay()->getTimestamp()]])
  51. ->groupBy('custom.phone')
  52. ->limit(1000)
  53. ->pluck('custom.phone')
  54. ->toArray();
  55. // 组合数据
  56. $phoneList = implode(',',$phoneList);
  57. // 给这些手机号发送一条阿里云短信
  58. $result = $phoneList ? Sms::sendSms($phoneList,'开邻智数','SMS_478125029') : [];
  59. // 返回结果
  60. return $result;
  61. }
  62. }