12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use App\Facades\Servers\Aliyun\Sms;
- use App\Models\CustomCoupon as Model;
- class CouponNotice extends Command
- {
- /**
- * 任务名称
- *
- * @var string
- */
- protected $signature = 'coupon_notice';
- /**
- * 任务描述
- *
- * @var string
- */
- protected $description = '优惠券到期提醒';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
- {
- // 执行任务
- $this->run_task();
- return 0;
- }
- /**
- * 执行任务
- *
- * */
- public function run_task(){
- // 实例化模型
- $Model = new Model();
- // 获取三天后到期的优惠券->addDays(3)
- $phoneList = $Model->query()
- ->join('custom','custom_coupon.custom_uid','=','custom.uid')
- ->where([['custom_coupon.status','=',0],['custom_coupon.exp_time','>',now()->endOfDay()->getTimestamp()],['custom_coupon.exp_time','<',now()->addDays(2)->endOfDay()->getTimestamp()]])
- ->groupBy('custom.phone')
- ->limit(1000)
- ->pluck('custom.phone')
- ->toArray();
- // 组合数据
- $phoneList = implode(',',$phoneList);
- // 给这些手机号发送一条阿里云短信
- $result = Sms::sendSms($phoneList,'开邻智数','SMS_478125029');
- // 返回结果
- return $result;
- }
- }
|