企微短剧业务系统

JiaShuOrderToRds.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Log;
  4. use App\Models\jiashuData;
  5. use App\RedisModel;
  6. use Illuminate\Console\Command;
  7. class JiaShuOrderToRds extends Command
  8. {
  9. protected $signature = 'JiaShuOrderToRds';
  10. protected $description = '嘉书订单信息入队列供小说数据看板消耗';
  11. protected $startId = 0;
  12. protected $limit = 500;
  13. const JIA_SHU_ORDER_LIST = 'Novel:JiaShuOrderList';
  14. protected $platform_id = '3a8vJ2t0K5XkH5Wl';
  15. public function handle()
  16. {
  17. \DB::connection()->disableQueryLog();
  18. $this->info(date('m-d H:i:s') . ' 开始整理');
  19. $this->saveToRds();
  20. $this->info(date('m-d H:i:s') . ' 整理结束');
  21. }
  22. private function saveToRds()
  23. {
  24. try {
  25. do{
  26. # 查询嘉书订单数据
  27. $orderList = jiashuData::select(['data', 'id'])->where('platform_id', $this->platform_id)
  28. ->where('id', '>', $this->startId)->orderBy('id')
  29. ->limit($this->limit)
  30. ->get();
  31. $count = $orderList->count();
  32. $this->info('起始ID:'.$this->startId);
  33. $this->info('本次获取的订单条数为:'.$count);
  34. $this->startId = $orderList->max('id');
  35. foreach ($orderList as $order) {
  36. $orderInfo = isset($order->data) ? $order->data : '';
  37. if(empty($orderInfo)) {
  38. Log::logError('嘉书订单数据异常', $order, 'JiaShuOrderToRds');
  39. continue;
  40. }
  41. RedisModel::lPush(JiaShuOrderToRds::JIA_SHU_ORDER_LIST, $orderInfo);
  42. }
  43. } while ($count == $this->limit);
  44. } catch (\Exception $e) {
  45. Log::logError('嘉书订单信息入队列发生异常', [
  46. 'line' => $e->getLine(),
  47. 'msg' => $e->getMessage(),
  48. ], 'JiaShuOrderToRds');
  49. }
  50. }
  51. }