LatestCustomerMsg.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 = 'Command description';
  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() - 10 * 3600 - 3 * 86400))
  46. ->where('send_time', '<=', date('Y-m-d H:i:s', time() - 10 * 3600))
  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. ) {
  59. continue;
  60. }
  61. $bid = null;
  62. if (strpos('/reader', $url_info['path']) !== false) {
  63. parse_str($url_info['query'], $param);
  64. if (!isset($param['bid'])) {
  65. continue;
  66. }
  67. if ($param['bid'] == 'undefined') continue;
  68. $bid_info = Hashids::decode($param['bid']);
  69. $bid = isset($bid_info[0]) ? $bid_info[0] : 0;
  70. }
  71. /*if (strpos('/detail',$url_info['path']) !== false) {
  72. parse_str($url_info['query'],$param);
  73. if (!isset($param['id'])) {
  74. continue;
  75. }
  76. if($param['id'] == 'undefined') continue;
  77. $bid_info = \Hashids::decode($param['id']);
  78. $bid = isset($bid_info[0])?$bid_info[0]:0;
  79. }
  80. if (strpos($url_info['path'],'/yun/') !== false) {
  81. $send_order_id = str_replace('/yun/','',$url_info['path']);
  82. $send_order_info = \App\Modules\SendOrder\Services\SendOrderService::getById($send_order_id);
  83. if($send_order_info){
  84. $bid = $send_order_info->book_id;
  85. }
  86. }*/
  87. if (!$bid) continue;
  88. Redis::hset('latestcustomerinfo', $item->id, json_encode([
  89. 'bid' => $bid,
  90. 'send_time' => $item->send_time
  91. ]));
  92. }
  93. }
  94. }
  95. }