LatestCustomerMsg.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Redis;
  5. use DB;
  6. use Hashids;
  7. class LatestCustomerMsg extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'LatestCustomerMsg';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'latest three days customer msg';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. $this->start();
  38. }
  39. private function start()
  40. {
  41. Redis::del('latestcustomerinfo');
  42. $sites = redisEnv('CUSTOM_CHAPTER_ORDER_SITES', '');
  43. if (!$sites) return;
  44. $sites = explode(',', $sites);
  45. $result = \App\Modules\OfficialAccount\Models\CustomSendMsgs::where('send_time', '>=', date('Y-m-d H:i:s', time() - 15 * 60 - 3 * 86400))
  46. ->where('send_time', '<=', date('Y-m-d H:i:s'))
  47. ->whereIn('distribution_channel_id', $sites)
  48. ->select('id', 'redirect_url', 'send_time')
  49. ->get();
  50. if ($result->isEmpty()) return;
  51. foreach ($result as $item) {
  52. if (!$item->redirect_url) continue;
  53. $url_info = parse_url($item->redirect_url);
  54. if (isset($url_info['path']) && isset($url_info['query'])) {
  55. if (strpos('/reader', $url_info['path']) === false &&
  56. strpos('/yun', $url_info['path']) === false &&
  57. strpos('/detail', $url_info['path']) === false &&
  58. strpos('/custom_msgs_page', $url_info['path']) === false
  59. ) {
  60. continue;
  61. }
  62. $bid = null;
  63. if (strpos('/reader', $url_info['path']) !== false) {
  64. parse_str($url_info['query'], $param);
  65. if (!isset($param['bid'])) {
  66. continue;
  67. }
  68. if ($param['bid'] == 'undefined') continue;
  69. $bid_info = Hashids::decode($param['bid']);
  70. $bid = isset($bid_info[0]) ? $bid_info[0] : 0;
  71. }
  72. if (strpos('/custom_msgs_page', $url_info['path']) !== false) {
  73. $temp = urldecode($url_info['query']);
  74. $temp_info = parse_url($temp);
  75. parse_str($temp_info['query'], $param);
  76. if (!isset($param['bid'])) {
  77. continue;
  78. }
  79. if ($param['bid'] == 'undefined') continue;
  80. $bid_info = Hashids::decode($param['bid']);
  81. $bid = isset($bid_info[0]) ? $bid_info[0] : 0;
  82. }
  83. /*if (strpos('/detail',$url_info['path']) !== false) {
  84. parse_str($url_info['query'],$param);
  85. if (!isset($param['id'])) {
  86. continue;
  87. }
  88. if($param['id'] == 'undefined') continue;
  89. $bid_info = \Hashids::decode($param['id']);
  90. $bid = isset($bid_info[0])?$bid_info[0]:0;
  91. }
  92. if (strpos($url_info['path'],'/yun/') !== false) {
  93. $send_order_id = str_replace('/yun/','',$url_info['path']);
  94. $send_order_info = \App\Modules\SendOrder\Services\SendOrderService::getById($send_order_id);
  95. if($send_order_info){
  96. $bid = $send_order_info->book_id;
  97. }
  98. }*/
  99. if (!$bid) continue;
  100. Redis::hset('latestcustomerinfo', $item->id, json_encode([
  101. 'bid' => $bid,
  102. 'send_time' => $item->send_time
  103. ]));
  104. }
  105. }
  106. }
  107. }