12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace App\Console\Commands;
- use App\Log;
- use App\Models\jiashuData;
- use App\RedisModel;
- use Illuminate\Console\Command;
- class JiaShuOrderToRds extends Command
- {
- protected $signature = 'JiaShuOrderToRds';
- protected $description = '嘉书订单信息入队列供小说数据看板消耗';
- protected $startId = 0;
- protected $limit = 500;
- const JIA_SHU_ORDER_LIST = 'Novel:JiaShuOrderList';
- protected $platform_id = '3a8vJ2t0K5XkH5Wl';
- public function handle()
- {
- \DB::connection()->disableQueryLog();
- $this->info(date('m-d H:i:s') . ' 开始整理');
- $this->saveToRds();
- $this->info(date('m-d H:i:s') . ' 整理结束');
- }
- private function saveToRds()
- {
- try {
- do{
- # 查询嘉书订单数据
- $orderList = jiashuData::select(['data', 'id'])->where('platform_id', $this->platform_id)
- ->where('id', '>', $this->startId)->orderBy('id')
- ->limit($this->limit)
- ->get();
- $count = $orderList->count();
- $this->info('起始ID:'.$this->startId);
- $this->info('本次获取的订单条数为:'.$count);
- $this->startId = $orderList->max('id');
- foreach ($orderList as $order) {
- $orderInfo = isset($order->data) ? $order->data : '';
- if(empty($orderInfo)) {
- Log::logError('嘉书订单数据异常', $order, 'JiaShuOrderToRds');
- continue;
- }
- RedisModel::lPush(JiaShuOrderToRds::JIA_SHU_ORDER_LIST, $orderInfo);
- }
- } while ($count == $this->limit);
- } catch (\Exception $e) {
- Log::logError('嘉书订单信息入队列发生异常', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage(),
- ], 'JiaShuOrderToRds');
- }
- }
- }
|