123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App\Console\Commands;
- use App\Log;
- use App\Models\Order;
- use App\Models\VpOrder;
- use App\RedisModel;
- use Illuminate\Console\Command;
- class JiaShuOrderList extends Command
- {
- protected $signature = 'JiaShuOrderList';
- protected $description = '嘉书订单数据处理';
- protected $start_id = 0;
- protected $channelList = array(
- '70327' => 'wx35a5e4175affaf71',
- '70085' => 'wx23630ed2f44c2f5e',
- '70337' => 'wx9610dca9398d58bc',
- '70104' => 'wxf6ac30e692cac6c8',
- '70326' => 'wx0d5ab4fa74e7924b',
- '70324' => 'wx03ae62e1695f04ff',
- '70109' => 'wx7fe3aebf2e55afdf',
- '70335' => 'wx4a7aec1334bda92c',
- '70336' => 'wxb560dbff83c78e6f',
- '70118' => 'wx74c4e96321ec757a',
- '70068' => 'wxef07de73d69c4adc',
- );
- public function handle()
- {
- \DB::connection()->disableQueryLog();
- $this->info(date('m-d H:i:s') . ' 开始整理');
- $beginTime = time();
- while(true){
- $this->saveOrder();
- if (time() - $beginTime > 600) {
- break;
- }
- }
- $this->info(date('m-d H:i:s') . ' 整理结束');
- }
- private function saveOrder()
- {
- try {
- $rdsKey = Order::JIA_SHU_ORDER_LIST_RDS;
- $orderInfoJson = RedisModel::rPop($rdsKey);
- if(empty($orderInfoJson)) {
- sleep(3);
- return false;
- }
- $orderInfo = json_decode($orderInfoJson, true);
- $platformId = 2;
- $orderId = isset($orderInfo['orderId']) ? $orderInfo['orderId'] : '';
- $appId = isset($this->channelList[$orderInfo['channel']]) ? $this->channelList[$orderInfo['channel']] : '';
- $this->info('订单ID:'.$orderId);
- $this->info('公众号AppId:'.$appId);
- if(empty($orderId) || empty($appId)) {
- Log::logError('嘉书订单数据异常', $orderInfo, 'JiaShuOrderList');
- return false;
- }
- $insertData = [
- 'pay_money' => $orderInfo['price'] * 10000,
- 'user_id' => isset($orderInfo['userId']) ? $orderInfo['userId'] : '',
- 'platform_created_at' => $orderInfo['createTs'],
- 'platform_updated_at' => isset($orderInfo['updateTs']) ? $orderInfo['updateTs'] : '',
- 'pay_status' => $orderInfo['status'],
- 'openid' => $orderInfo['openid'],
- 'user_register_time' => $orderInfo['userCreateTs'],
- 'mp_user_register_time' => $orderInfo['userCreateTs'],
- 'playlet_id' => $orderInfo['productId'],
- 'playlet_name' => $orderInfo['productName'],
- 'channel' => $orderInfo['channel'],
- 'app_id' => $appId,
- ];
- VpOrder::updateOrCreate(
- ['platform_id' => $platformId, 'order_id' => (string)$orderId], $insertData
- );
- } catch (\Exception $e) {
- Log::logError('嘉书订单数据写入过程发生异常', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage(),
- ], 'JiaShuOrderList');
- $this->info('更新失败');
- return false;
- }
- $this->info('更新成功');
- return true;
- }
- }
|