MessageInquiry.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Http\Services\YouMenGApiService;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\DB;
  6. class MessageInquiry extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'message:inquiry';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command description';
  20. const MESSAGE_STENCIL = [
  21. 'softText' => 6,//软文
  22. 'report' => 7,//报表
  23. 'inquiry' => 8,//8询盘
  24. ];
  25. /**
  26. * Create a new command instance.
  27. *
  28. * @return void
  29. */
  30. public function __construct()
  31. {
  32. parent::__construct();
  33. }
  34. /**
  35. * Execute the console command.
  36. * 任务计划
  37. * @return mixed
  38. */
  39. public function handle()
  40. {
  41. $messageStatus = DB::table('message_status');
  42. $softTextNoticeList = DB::table('articles_notice')->get()->toArray();
  43. //软文推送任务表
  44. foreach ($softTextNoticeList as $key => $value) {
  45. $messageStencil = DB::table('message')->where('id', self::MESSAGE_STENCIL['softText'])->first();
  46. $info = [
  47. 'type' => $messageStencil->type,
  48. 'site_id' => $value->site_id,
  49. 'title' => $messageStencil->title ?? '',
  50. 'message' => $messageStencil->message ?? '',
  51. 'message_id' => $messageStencil->id,
  52. 'url' => $messageStencil->url ?? '',
  53. 'img' => $messageStencil->img ?? '',
  54. 'date' => strtotime(date('Y-m 00:00:00')),
  55. ];
  56. $messageStatus->insert($info);
  57. $deleteCondition = [
  58. ['site_id', '=', $value->site_id],
  59. ];
  60. DB::table('articles_notice')->where($deleteCondition)->delete();
  61. }
  62. $reportNoticeList = DB::table('report_notice')->get()->toArray();
  63. foreach ($reportNoticeList as $key => $value) {
  64. //报表推送任务表
  65. $messageStencil = DB::table('message')->where('id', self::MESSAGE_STENCIL['report'])->first();
  66. $info = [
  67. 'type' => $messageStencil->type,
  68. 'site_id' => $value->site_id,
  69. 'title' => $messageStencil->title ?? '',
  70. 'message' => $messageStencil->message ?? '',
  71. 'message_id' => $messageStencil->id,
  72. 'url' => $messageStencil->url ?? '',
  73. 'img' => $messageStencil->img ?? '',
  74. 'date' => strtotime(date('Y-m 00:00:00')),
  75. ];
  76. $messageStatus->insert($info);
  77. $deleteCondition = [
  78. ['site_id', '=', $value->site_id],
  79. ];
  80. DB::table('report_notice')->where($deleteCondition)->delete();
  81. }
  82. $inquiryNoticeList = DB::table('inquiry_notice')->get()->toArray();
  83. foreach ($inquiryNoticeList as $key => $value) {
  84. //询盘推送任务表
  85. $siteId = DB::table('sites')->where('database', $value->website)->value('id');
  86. if (!empty($siteId)) {
  87. $messageStencil = DB::table('message')->where('id', self::MESSAGE_STENCIL['inquiry'])->first();
  88. $info = [
  89. 'type' => $messageStencil->type,
  90. 'site_id' => $siteId,
  91. 'title' => $messageStencil->title ?? '',
  92. 'message' => $messageStencil->message ?? '',
  93. 'message_id' => $messageStencil->id,
  94. 'url' => $messageStencil->url ?? '',
  95. 'img' => $messageStencil->img ?? '',
  96. 'date' => strtotime(date('Y-m 00:00:00')),
  97. ];
  98. $messageStatus->insert($info);
  99. $deleteCondition = [
  100. ['website', '=', $value->website],
  101. ];
  102. DB::table('inquiry_notice')->where($deleteCondition)->delete();
  103. }
  104. }
  105. $messageList = DB::table('message_status')
  106. ->where('status', 0)
  107. ->whereIn('type', [6, 7, 8])
  108. ->get()->toArray();
  109. $youMenGApiService = new YouMenGApiService();
  110. foreach ($messageList as $key => $value) {
  111. $message = [
  112. 'title' => $value->title,
  113. 'subtitle' => $value->message,
  114. 'body' => ''
  115. ];
  116. $youMenGApiService->pushIosDevice($value->site_id, $message);
  117. $youMenGApiService->pushAndroidDevice($value->site_id, $message);
  118. DB::table('message_status')->where('id', $value->id)->update(['push_time' => date('Y-m-d H:i:s'), 'status' => 1]);
  119. }
  120. }
  121. }