12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace App\Console\Commands\CustomMsg;
- use App\Modules\OfficialAccount\Services\CustomMsgService;
- use App\Modules\OfficialAccount\Models\CustomMsgStrategy;
- use Illuminate\Console\Command;
- use DB;
- class CustomMsgStrategyAutoSend extends Command
- {
-
- protected $signature = 'auth_send_custom_msg_by_strategy';
-
- protected $description = '根据客服消息策略生成客服消息';
-
- public function __construct()
- {
- parent::__construct();
- }
-
- public function handle()
- {
-
- $hour_begin = date('H:00:00');
- $hour_end = date('H:59:59');
- $strategies = CustomMsgStrategy::whereNull('deleted_at')
- ->where('status',1)
- ->where(function ($query) {
- $query->where('last_send_date','<',date('Y-m-d 00:00:00'))
- ->orWhereNull('last_send_date');
- })
- ->whereBetween('send_time',[$hour_begin,$hour_end])
- ->select([
- 'id',
- 'appid',
- 'name',
- 'send_time',
- 'content',
- 'description',
- 'book_name',
- 'chapter_name',
- 'redirect_url',
- 'subscribe_time',
- 'sex',
- 'balance',
- 'order_type',
- 'category_id',
- 'is_full_send',
- 'distribution_channel_id',
- 'status',
- 'batch_order_sn',
- 'custom_type',
- ])
- ->get()
- ;
- $strategies = json_decode(json_encode($strategies), true);
- foreach ($strategies as $strategy){
- $strategy['status']=1;
- $strategy_id = $strategy['id'];
- unset($strategy['id']);
- $strategy['send_time']=date('Y-m-d ').$strategy['send_time'];
-
- $isSendCustomer = CustomMsgService::isSendCustomerAtSameTime($strategy);
- if (!empty($isSendCustomer)) {
- \Log::info('isSendCustomerAtSameTime:' . $strategy['distribution_channel_id']);
- } else {
- CustomMsgStrategy::where('id',$strategy_id)->update(['last_send_date' => date('Y-m-d H:i:s')]);
- $customMsgService = CustomMsgService::addCustomSendMsgs($strategy);
- }
- }
- }
- }
|