123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- namespace App\Console\Commands;
- use App\Http\Services\YouMenGApiService;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- class MessageInquiry extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'message:inquiry';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- const MESSAGE_STENCIL = [
- 'softText' => 6,//软文
- 'report' => 7,//报表
- 'inquiry' => 8,//8询盘
- ];
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- * 任务计划
- * @return mixed
- */
- public function handle()
- {
- $messageStatus = DB::table('message_status');
- $softTextNoticeList = DB::table('articles_notice')->get()->toArray();
- //软文推送任务表
- foreach ($softTextNoticeList as $key => $value) {
- $messageStencil = DB::table('message')->where('id', self::MESSAGE_STENCIL['softText'])->first();
- $info = [
- 'type' => $messageStencil->type,
- 'site_id' => $value->site_id,
- 'title' => $messageStencil->title ?? '',
- 'message' => $messageStencil->message ?? '',
- 'message_id' => $messageStencil->id,
- 'url' => $messageStencil->url ?? '',
- 'img' => $messageStencil->img ?? '',
- 'date' => strtotime(date('Y-m 00:00:00')),
- ];
- $messageStatus->insert($info);
- $deleteCondition = [
- ['site_id', '=', $value->site_id],
- ];
- DB::table('articles_notice')->where($deleteCondition)->delete();
- }
- $reportNoticeList = DB::table('report_notice')->get()->toArray();
- foreach ($reportNoticeList as $key => $value) {
- //报表推送任务表
- $messageStencil = DB::table('message')->where('id', self::MESSAGE_STENCIL['report'])->first();
- $info = [
- 'type' => $messageStencil->type,
- 'site_id' => $value->site_id,
- 'title' => $messageStencil->title ?? '',
- 'message' => $messageStencil->message ?? '',
- 'message_id' => $messageStencil->id,
- 'url' => $messageStencil->url ?? '',
- 'img' => $messageStencil->img ?? '',
- 'date' => strtotime(date('Y-m 00:00:00')),
- ];
- $messageStatus->insert($info);
- $deleteCondition = [
- ['site_id', '=', $value->site_id],
- ];
- DB::table('report_notice')->where($deleteCondition)->delete();
- }
- $inquiryNoticeList = DB::table('inquiry_notice')->get()->toArray();
- foreach ($inquiryNoticeList as $key => $value) {
- //询盘推送任务表
- $siteId = DB::table('sites')->where('database', $value->website)->value('id');
- if (!empty($siteId)) {
- $messageStencil = DB::table('message')->where('id', self::MESSAGE_STENCIL['inquiry'])->first();
- $info = [
- 'type' => $messageStencil->type,
- 'site_id' => $siteId,
- 'title' => $messageStencil->title ?? '',
- 'message' => $messageStencil->message ?? '',
- 'message_id' => $messageStencil->id,
- 'url' => $messageStencil->url ?? '',
- 'img' => $messageStencil->img ?? '',
- 'date' => strtotime(date('Y-m 00:00:00')),
- ];
- $messageStatus->insert($info);
- $deleteCondition = [
- ['website', '=', $value->website],
- ];
- DB::table('inquiry_notice')->where($deleteCondition)->delete();
- }
- }
- $messageList = DB::table('message_status')
- ->where('status', 0)
- ->whereIn('type', [6, 7, 8])
- ->get()->toArray();
- $youMenGApiService = new YouMenGApiService();
- foreach ($messageList as $key => $value) {
- $message = [
- 'title' => $value->title,
- 'subtitle' => $value->message,
- 'body' => ''
- ];
- $youMenGApiService->pushIosDevice($value->site_id, $message);
- $youMenGApiService->pushAndroidDevice($value->site_id, $message);
- DB::table('message_status')->where('id', $value->id)->update(['push_time' => date('Y-m-d H:i:s'), 'status' => 1]);
- }
- }
- }
|