| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- // +----------------------------------------------------------------------
- // | 商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.thinkphp.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: thinkphp <admin@yiovo.com>
- // +----------------------------------------------------------------------
- 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;
- }
- }
|