order = $order; } /** * 支付成功入口 */ public function success() { try { DB::beginTransaction(); $this->setOrderSuccess(); $this->handlePayProcess(); $job = new QappTikTokUserCharge($this->order->uid, $this->order->price, $this->order->created_at); dispatch($job->onConnection('rabbitmq')->onQueue('qapp_tiktok_user_charge_queue')); DB::commit(); return true; } catch (Exception $e) { DB::rollback(); Log::error('pay.success: ' . $e->getTraceAsString()); } } /** * 设置order成功 */ protected function setOrderSuccess() { $this->order->pay_type = $this->getChargeTimes(); $this->order->status = 'PAID'; $this->order->pay_end_at = date('Y-m-d H:i:s'); $this->order->save(); } /** * 获取用户第几次充值 * @param $uid * @return int */ private function getChargeTimes() { $count = Order::where('uid', $this->order->uid)->where('status', 'PAID')->count('id'); return $count + 1; } }