select($select)->get(); } /** * 对指定对订单-标示为查单处理状态 * @param string yes $order_sn 订单号 * @param int no $is_admin_action 是否已查单处理: 0-没处理 1-已处理,(默认 值为 1) * @return bool */ public function setAdminAction($order_sn = '', $is_admin_action = 1) { $data = array( 'is_admin_action' => $is_admin_action ); if ($is_admin_action == 1) { $data['admin_action_at'] = date('Y-m-d H:i:s'); } $r = VipOrderModel::query() ->where('order_sn', $order_sn) ->update($data); if (!$r) { return false; } return true; } /** * 查询指定订单信息 * @param string yes $order_sn 订单号 * @return array */ public function getOrderInfo($order_sn = '') { $r = VipOrderModel::query() ->where('order_sn', $order_sn) ->first(); if (!$r) { return array(); } return $r; } /** * 查询指定订单信息 * @param string yes $order_sn 订单号 * @return array */ public function getCoinsOrderInfo($order_sn = '') { $r = CoinsOrderModel::query() ->where('order_sn', $order_sn) ->first(); if (!$r) { return array(); } return $r; } /** * 补单 * @param string yes $order_sn 订单号 * @param string no $trade_no 支付单号 * @param string no $repair_remark 补单备注 * @return bool * * 处理逻辑:vip_order 订单表标示已付款和付款日期; collections 表创建收款单记录, user表添加会员日期, * 成功之后,在mongodb中创建一个 补单记录。 * 备注: 不需要去内调回调接口,不要验签! * */ public function again($order_sn = '', $trade_no = '', $repair_remark = '') { $order_info = $this->getOrderInfo($order_sn); if (!$order_info) { return false; } $user_info = UserModel::query() ->where('id', $order_info['user_id']) ->first(); if (!$user_info) { return false; } $card_info = VipCardModel::query() ->where('id', $order_info['vip_id']) ->first(); if (!$card_info) { return false; } Db::beginTransaction(); try { // 标示订单已付款 $data = array( 'status' => 1, 'pay_time' => date('Y-m-d H:i:s'), 'trade_no' => $trade_no, 'repair_remark' => $repair_remark, ); $result = VipOrderModel::query() ->where('order_sn', $order_sn) ->update($data); if (!$result) { throw new ApiException('标示订单已付款失败'); } // 创建收款单记录 $insertData = array( 'user_id' => $user_info['id'], 'user_code' => $user_info['code'], 'order_sn' => $order_sn, 'trade_sn' => $trade_no, 'order_amount' => $order_info['order_amount'], 'real_amount' => $order_info['real_amount'], 'device_type' => $user_info['device_type'], 'type' => 1, //购买会员 ); $result = CollectionsModel::create($insertData); if (!$result) { throw new ApiException('创建收款单记录失败'); } // 对用户加会员天数 $userInfo = make(UserRepository::class) ->getUserInfoFromCache($user_info['code']); if ($userInfo['is_vip'] == 'y') { $vipTime = Carbon::parse($userInfo['vip_expired']) ->addDays($card_info['day']) ->toDateTimeString(); } else { $vipTime = Carbon::now() ->addDays($card_info['day']) ->toDateTimeString(); } $package = json_decode($order_info['package_info'], true); $houseCount = 0; $userCoins = 0; foreach ($package['jdata']['feature'] as $packVal) { switch ($packVal['type']) { case 'house': $houseCount = $packVal['count']; break; } } if ($package['send_type'] == 2) { $userCoins = $package['send_num']; } $houseCount = $userInfo['max_open_house'] + $houseCount; $coins = $userInfo['coins'] + $userCoins; $result = UserModel::query() ->where('id', $user_info['id']) ->update(['vip_expired' => $vipTime, 'vip_level' => $order_info['vip_id'], 'max_open_house' => $houseCount, 'coins' => $coins]); if (!$result) { throw new ApiException('对用户加会员天数失败'); } //创建一条mongo补单记录 $data = array( '_id' => md5($order_info['user_id'] . '_' . $order_sn), 'order_sn' => $order_sn, 'trade_no' => $trade_no, 'user_id' => $order_info['user_id'], 'vip_id' => $order_info['vip_id'], 'vip_days' => $order_info['vip_days'], 'repair_remark' => $repair_remark, 'created_at' => date('Y-m-d H:i:s') ); make(RepairOrderHistoryModel::class)->db()->insertOne($data); Db::commit(); //清除用户信息redis缓存 make(UserRepository::class)->delUserCache($user_info['code']); // 帐变记录 if ($userCoins > 0) { $changeData = [ 'user_uid' => $user_info['code'], 'currency_type' => ChangeLogConstant::CHANGE_COIN, 'amount' => $userCoins, 'way' => ChangeLogConstant::WAY_1, 'type' => ChangeLogConstant::TYPE_23, ]; make(QueueService::class)->saveChangeLogJob($changeData); } } catch (\Exception $e) { Db::rollBack(); } return true; } /** * 获取可用的自发通道 * * @param $payType * @return */ public function getPayChannel($payId) { $paymentData = PaymentModel::query() ->join('payment_type as pt', 'payment.uid', '=', 'pt.payment_uid') ->leftJoin('payment_attr as pa', 'pt.payment_attr_uid', '=', 'pa.uid') ->select( 'payment.pay_code', 'payment.partner_id', 'payment.uid', 'pa.code', 'pt.limit_type', 'pt.limit', 'pt.pay_type', 'pt.weights', 'pt.id', 'pt.name' ) ->where(['payment.status' => 1, 'pt.status' => 1, 'pt.id' => $payId]) ->first(); return $paymentData; } /** * 金币补单 * * @param $orderSn * @param $remark * @param $userId * @param $coins * @return string|void */ public function coinsAgain($orderSn, $remark, $userId, $coins) { $userInfo = UserModel::query() ->where('id', $userId) ->first(); if (!$userInfo) { return false; } Db::beginTransaction(); $coinsRes = CoinsOrderModel::query()->where('order_sn', $orderSn)->update(['remark' => $remark, 'status' => 1]); if (!$coinsRes) { Db::rollBack(); return false; } $userRes = UserModel::query()->where('id', $userId)->increment('coins', $coins); if (!$userRes) { Db::rollBack(); return false; } Db::commit(); //清除用户信息redis缓存 make(UserRepository::class)->delUserCache($userInfo['code']); // 帐变记录 $changeData = [ 'user_uid' => $userInfo['code'], 'currency_type' => ChangeLogConstant::CHANGE_COIN, 'amount' => $coins, 'way' => ChangeLogConstant::WAY_1, 'type' => ChangeLogConstant::TYPE_19, ]; make(QueueService::class)->saveChangeLogJob($changeData); return true; } }