Send.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * 发送
  4. * User: qissen
  5. * Date: 2017/11/26
  6. * Time: 11:26a
  7. */
  8. namespace app\crontab\command;
  9. use app\core\model\HongbaoPlan;
  10. use app\core\service\SMS;
  11. use think\console\Command;
  12. use think\console\Input;
  13. use think\console\Output;
  14. use think\Log;
  15. use tool\Common;
  16. class Send extends Command
  17. {
  18. protected function configure()
  19. {
  20. $this->setName('Send')->setDescription('Send开始');
  21. }
  22. protected function execute(Input $input, Output $output)
  23. {
  24. //在这里我们进行结算
  25. Log::info('Send:'.Common::timetodate(THINK_START_TIME));
  26. $this->sendSMS();
  27. $this->hongbaoPlan();
  28. $output->writeln("Send结束");
  29. }
  30. /**
  31. * 红包派送计划 - 定时发送
  32. */
  33. private function hongbaoPlan() {
  34. (new HongbaoPlan())->sendUserOnTiming();
  35. }
  36. /**
  37. * 短信发送
  38. */
  39. private function sendSMS() {
  40. \app\core\model\Sms::where([
  41. 'status'=>0,
  42. 'sendTime'=>['lt', THINK_START_TIME]
  43. ])->chunk(100, function($list) {
  44. foreach ($list as $item) {
  45. SMS::sendSMS($item['mobile'], $item['message']);
  46. $item->status = 1;
  47. $item->save();
  48. }
  49. });
  50. }
  51. }