model = OrderModel::getPayDetail($orderNo); $this->wxappId = $this->model['wxapp_id']; // 获取用户信息 $this->user = UserModel::detail($this->model['user_id']); } /** * 获取订单详情 * @return OrderModel|null */ public function getOrderInfo() { return $this->model; } /** * 订单支付成功业务处理 * @param int $payType 支付类型 * @param array $payData 支付回调数据 * @return bool */ public function onPaySuccess($payType, $payData) { return $this->model->transaction(function () use ($payType, $payData) { // 更新订单状态 $this->model->save([ 'pay_status' => PayStatusEnum::SUCCESS, 'pay_time' => time(), 'transaction_id' => $payData['transaction_id'] ]); // 累积用户余额 $this->user->setInc('balance', $this->model['actual_money']); // 用户余额变动明细 BalanceLogModel::add(SceneEnum::RECHARGE, [ 'user_id' => $this->user['user_id'], 'money' => $this->model['actual_money'], 'wxapp_id' => $this->wxappId, ], ['order_no' => $this->model['order_no']]); // 更新prepay_id记录 if ($payType == PayTypeEnum::WECHAT) { // WxappPrepayIdModel::updatePayStatus($this->model['order_id'], OrderTypeEnum::RECHARGE); } return true; }); } }