小说推广数据系统

JiaShuOrderList.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Log;
  4. use App\Models\Order;
  5. use App\Models\VpOrder;
  6. use App\RedisModel;
  7. use Illuminate\Console\Command;
  8. class JiaShuOrderList extends Command
  9. {
  10. protected $signature = 'JiaShuOrderList';
  11. protected $description = '嘉书订单数据处理';
  12. protected $start_id = 0;
  13. protected $channelList = array(
  14. '70327' => 'wx35a5e4175affaf71',
  15. '70085' => 'wx23630ed2f44c2f5e',
  16. '70337' => 'wx9610dca9398d58bc',
  17. '70104' => 'wxf6ac30e692cac6c8',
  18. '70326' => 'wx0d5ab4fa74e7924b',
  19. '70324' => 'wx03ae62e1695f04ff',
  20. '70109' => 'wx7fe3aebf2e55afdf',
  21. '70335' => 'wx4a7aec1334bda92c',
  22. '70336' => 'wxb560dbff83c78e6f',
  23. '70118' => 'wx74c4e96321ec757a',
  24. '70068' => 'wxef07de73d69c4adc',
  25. );
  26. public function handle()
  27. {
  28. \DB::connection()->disableQueryLog();
  29. $this->info(date('m-d H:i:s') . ' 开始整理');
  30. $beginTime = time();
  31. while(true){
  32. $this->saveOrder();
  33. if (time() - $beginTime > 600) {
  34. break;
  35. }
  36. }
  37. $this->info(date('m-d H:i:s') . ' 整理结束');
  38. }
  39. private function saveOrder()
  40. {
  41. try {
  42. $rdsKey = Order::JIA_SHU_ORDER_LIST_RDS;
  43. $orderInfoJson = RedisModel::rPop($rdsKey);
  44. if(empty($orderInfoJson)) {
  45. sleep(3);
  46. return false;
  47. }
  48. $orderInfo = json_decode($orderInfoJson, true);
  49. $platformId = 2;
  50. $orderId = isset($orderInfo['orderId']) ? $orderInfo['orderId'] : '';
  51. $appId = isset($this->channelList[$orderInfo['channel']]) ? $this->channelList[$orderInfo['channel']] : '';
  52. $this->info('订单ID:'.$orderId);
  53. $this->info('公众号AppId:'.$appId);
  54. if(empty($orderId) || empty($appId)) {
  55. Log::logError('嘉书订单数据异常', $orderInfo, 'JiaShuOrderList');
  56. return false;
  57. }
  58. $insertData = [
  59. 'pay_money' => $orderInfo['price'] * 10000,
  60. 'user_id' => isset($orderInfo['userId']) ? $orderInfo['userId'] : '',
  61. 'platform_created_at' => $orderInfo['createTs'],
  62. 'platform_updated_at' => isset($orderInfo['updateTs']) ? $orderInfo['updateTs'] : '',
  63. 'pay_status' => $orderInfo['status'],
  64. 'openid' => $orderInfo['openid'],
  65. 'user_register_time' => $orderInfo['userCreateTs'],
  66. 'mp_user_register_time' => $orderInfo['userCreateTs'],
  67. 'playlet_id' => $orderInfo['productId'],
  68. 'playlet_name' => $orderInfo['productName'],
  69. 'channel' => $orderInfo['channel'],
  70. 'app_id' => $appId,
  71. ];
  72. VpOrder::updateOrCreate(
  73. ['platform_id' => $platformId, 'order_id' => (string)$orderId], $insertData
  74. );
  75. } catch (\Exception $e) {
  76. Log::logError('嘉书订单数据写入过程发生异常', [
  77. 'line' => $e->getLine(),
  78. 'msg' => $e->getMessage(),
  79. ], 'JiaShuOrderList');
  80. $this->info('更新失败');
  81. return false;
  82. }
  83. $this->info('更新成功');
  84. return true;
  85. }
  86. }