// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\api\model\locked; use app\api\model\Setting as SettingModel; use app\api\model\User; use app\api\service\User as UserService; use app\common\enum\locked\order\PayType; use app\common\library\helper; use app\common\model\UnlockOrder as OrderModel; use app\common\service\Order as OrderService; use app\common\enum\locked\order\PayStatus as PayStatusEnum; use app\common\exception\BaseException; /** * 用户解锁订单模型 * Class Order * @package app\api\model\locked */ class Order extends OrderModel { /** * 隐藏字段 * @var array */ protected $hidden = [ 'transaction_id', 'create_time', 'update_time', ]; /** * 获取订单列表 * @return \think\Paginator * @throws BaseException * @throws \think\db\exception\DbException */ public function getList() { // 当前用户ID $userId = UserService::getCurrentLoginUserId(); // 获取列表数据 return $this->where('user_id', '=', $userId) ->where('status', '>=', PayStatusEnum::PENDING) ->order(['create_time' => 'desc']) ->paginate(15); } /** * 获取订单详情(待付款状态) * @param $orderNo * @return array|null|static */ public static function getPayDetail(string $orderNo) { return self::detail(['order_no' => $orderNo, 'status' => PayStatusEnum::PENDING]); } /** * 创建充值订单 * @param int|null $planId * @param float $customMoney * @return bool|int * @throws BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function createOrder(?int $planId = null, float $customMoney = 0.00) { } /** * 保存订单记录 * @param $data * @return bool|false|int */ private function saveOrder(array $data) { return true; } /** * 生成订单 * @param int $payType 支付方式 * @return array|array[]|bool * @throws BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ private function getOrderData(int $payType, float $price) { // 订单信息 $data = [ 'order' => [ 'user_id' => UserService::getCurrentLoginUserId(), 'order_no' => 'RC' . OrderService::createOrderNo(), 'recharge_type' => $payType, 'price' => 0.00, 'store_id' => self::$storeId, ], 'users' => [] // 解锁用户 ]; // 实际到账金额 $data['order']['total_money'] = 0; return $data; } /** * 创建套餐充值订单数据 * @param array $order * @param int $planId * @return array * @throws BaseException */ private function createDataByUsers(array $order, int $userId) { // 获取用户详情 $info = User::detail($userId); if (empty($info)) { throwError('解锁用户不存在'); } $order['info'] = $info; return $order; } /** * 表单验证 * @param int $payType * @param float $price * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ private function validateForm(int $payType, float $price) { if ($price <= 0) { $this->error = '请先后台设置解锁费用'; return false; } return true; } /** * 表单验证 [自定义充值] * @param float $customMoney 充值金额 * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ private function validateFormCustom(float $customMoney) { // 充值设置 $setting = SettingModel::getItem('recharge'); if ($setting['is_custom'] == false) { $this->error = '很抱歉,当前不允许充值自定义金额'; return false; } if ($customMoney <= 0) { $this->error = '请输入正确的充值金额'; return false; } // 验证最低充值金额 if (helper::bccomp($customMoney, $setting['lowest_money']) === -1) { $this->error = "很抱歉,当前最低充值金额不能低于{$setting['lowest_money']}元"; return false; } return true; } }