Order.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace App\Jobs;
  3. use App\Facade\TableName;
  4. use App\Game\Services\OuroGameService;
  5. use App\Models\AccountsInfo;
  6. use App\Models\PrivateMail;
  7. use App\Services\Custom;
  8. use App\Services\FirstPayStatService;
  9. use App\Services\OrderServices;
  10. use App\Game\Services\FacebookEventService;
  11. use Illuminate\Bus\Queueable;
  12. use Illuminate\Contracts\Queue\ShouldQueue;
  13. use Illuminate\Foundation\Bus\Dispatchable;
  14. use Illuminate\Queue\InteractsWithQueue;
  15. use Illuminate\Queue\SerializesModels;
  16. use Illuminate\Support\Facades\DB;
  17. use Illuminate\Support\Facades\Log;
  18. use Illuminate\Support\Facades\Redis;
  19. class Order implements ShouldQueue
  20. {
  21. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  22. protected $data = [];
  23. public $tries = 5; // 增加最大尝试次数
  24. public $timeout = 300; // 设置最大执行时间为 300 秒
  25. /**
  26. * Create a new job instance.
  27. *
  28. * @return void
  29. */
  30. public function __construct($data = [])
  31. {
  32. $this->data = $data;
  33. }
  34. /**
  35. * Execute the job.
  36. *
  37. * @return void
  38. */
  39. public function handle()
  40. {
  41. if (empty($this->data)) return;
  42. // 接收数据
  43. [$user_id, $payAmt,$Score,$favorable_price,$GiftsID,$order_sn] = $this->data;
  44. try {
  45. //Log::info('接收数据'.\GuzzleHttp\json_encode($this->data));
  46. // 获取支付金额
  47. $service = new OrderServices();
  48. // [$give, $favorable_price, $Recharge, $czReason, $cjReason] = $service->getPayInfo($GiftsID, $user_id, $payAmt);
  49. // 发送邮件给玩家
  50. //PrivateMail::paySendMail($user_id, $order_sn, $favorable_price,$payAmt);
  51. // 增加充值记录
  52. //[$Score] = $service->addRecord($user_id,$payAmt,$favorable_price,$order_sn,$GiftsID,$Recharge,$czReason,$give,$cjReason);
  53. // 执行支付后存储过程
  54. $service->storedProcedure($user_id, $payAmt, $favorable_price, $Score, $GiftsID);
  55. // 发送通知邮件
  56. PrivateMail::paySendMail($user_id, $order_sn, $favorable_price, $payAmt);
  57. // 首次付费统计
  58. $service = new FirstPayStatService();
  59. $isfirst = $service->stat($order_sn);
  60. }catch (\Exception $e) {
  61. Log::error('订单处理失败:' . $e->getMessage());
  62. }
  63. try {
  64. $user = DB::connection('write')->table(TableName::QPAccountsDB() . 'AccountsInfo')
  65. ->where('UserID', $user_id)->select("Channel","RegisterDate")->first();
  66. // if($user->Channel>121&&$user->Channel<200) {
  67. //apk/checkpay用来统计
  68. // if($order->Channel>121&&$order->Channel<180) {
  69. // //记录redisevent,24小时
  70. // Redis::set("user_pay_first_".$order->user_id, json_encode(['order_sn' => $order_sn]));
  71. // }
  72. $item=[
  73. 'regtime'=>strtotime($user->RegisterDate),
  74. // 'isd0'=>date("Ymd",strtotime($user->RegisterDate))==date("Ymd"),
  75. 'isd0' => (time()-strtotime($user->RegisterDate)<86400),
  76. 'first' => $isfirst?1:0,
  77. 'golds' => $payAmt,
  78. 'udid' => $user_id,
  79. 'order_sn' => $order_sn
  80. ];
  81. //通知24680
  82. OuroGameService::notifyWebHall($user_id,"","pay_finish",["Golds"=>$Score,"PayNum"=>$favorable_price,"event"=>"pay","params"=>$item]);
  83. try {
  84. FacebookEventService::trackPayEvent(
  85. $user_id,
  86. $order_sn,
  87. $payAmt,
  88. 'USD',
  89. $isfirst?1:0,
  90. (time()-strtotime($user->RegisterDate)<86400),
  91. $user->Channel
  92. );
  93. }catch (\Exception $e){
  94. }
  95. // OuroGameService::notifyWebHall($user_id,"",'call_client',["type"=>"track","event"=>"pay","params"=>$item]);
  96. $data = [];
  97. if (Redis::exists("user_pay_order_$user_id")) {
  98. $data = json_decode(Redis::get("user_pay_order_$user_id"), true);
  99. }
  100. array_push($data, $item);
  101. Log::info('订单记录成功user_pay_order_:' . json_encode($data));
  102. //记录redisevent,24小时
  103. Redis::set("user_pay_order_$user_id", json_encode($data));
  104. Redis::expire("user_pay_order_$user_id", 86400);
  105. // }
  106. //新的邀请系统生效了
  107. // $callback = DB::table(TableName::agent() . 'UserCallBack')->where('UserID', $user_id)->first();
  108. // if($callback){
  109. // if($callback->call_state != 2){
  110. // $update = [
  111. // 'call_state' => 2,
  112. // //'CallbackDate' => date('Y-m-d H:i:s')
  113. // ];
  114. // DB::table(TableName::agent() . 'UserCallBack')->where('UserID', $user_id)->update($update);
  115. // Custom::updateAdminBonus($callback->admin_id,30,2);
  116. // }
  117. //
  118. //
  119. // }
  120. }catch (\Exception $e){
  121. }
  122. }
  123. }