| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace app\api\controller;
- use app\common\model\UnlockOrder;
- use app\api\service\Payment as PaymentService;
- use app\api\service\User as UserService;
- use app\common\enum\OrderType as OrderTypeEnum;
- use app\common\enum\book\order\PayType as OrderPayTypeEnum;
- /**
- * 解锁用户控制器
- * Class Locked
- * @package app\api\controller
- */
- class Locked extends Controller
- {
- /**
- * 解锁单个用户
- * @return \think\response\Json
- */
- public function submit()
- {
- if (getPlatform() !== 'MP-WEIXIN') {
- return $this->renderError('很抱歉,解锁功能暂时仅支持微信小程序端');
- }
- // 生成订单
- $model = new UnlockOrder();
- if (!$order = $model->createOrder($this->request->param(), 1)) {
- return $this->renderError($model->getError() ?: '解锁提交失败');
- }
- $payment = PaymentService::wechat(
- $order['order_id'],
- $order['order_no'],
- $order['total_price'],
- OrderTypeEnum::LOCKED
- );
- // 充值状态提醒
- $order = ['order_id'=> $order['order_id'],'type'=>'普通解锁订单','message' => '解锁提交成功'];
- return $this->renderSuccess(compact('payment','order'));
- }
- /**
- * 全解
- * @return \think\response\Json
- */
- public function submitAll()
- {
- if (getPlatform() !== 'MP-WEIXIN') {
- return $this->renderError('很抱歉,解锁功能暂时仅支持微信小程序端');
- }
- // 生成订单
- $model = new UnlockOrder();
- if (!$order = $model->createOrder($this->request->param(), 2)) {
- return $this->renderError($model->getError() ?: '解锁提交失败');
- }
- $payment = PaymentService::wechat(
- $order['order_id'],
- $order['order_no'],
- $order['total_price'],
- OrderTypeEnum::LOCKED
- );
- // 充值状态提醒
- $order = ['order_id'=> $order['order_id'],'type'=>'普通解锁订单','message' => '解锁提交成功'];
- return $this->renderSuccess(compact('payment','order'));
- }
- /**
- * 解锁订单支付
- * @param int $order_id
- * @return \think\response\Json
- * @throws \app\common\exception\BaseException
- * @throws \cores\exception\BaseException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function pay(int $order_id)
- {
- // 订单信息
- $model = new UnlockOrder();
- $model = $model::getUserOrderDetail($order_id);
- if (!$model) {
- return $this->renderError($model->getError() ?: '报名订单不存在');
- }
- // 验证
- if(!$model->checkPay($model))
- {
- return $this->renderError($model->getError() ?: '订单支付失败');
- }
- $pilOrder = false;
- $userInfo = UserService::getCurrentLoginUser(true);
- $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
- if($userId != $model['user_id'])
- {
- return $this->renderError('无权操作');
- }
- // 构建微信支付
- try {
- $payment = PaymentService::wechat(
- $model['order_id'],
- $model['order_no'],
- $model['total_price'],
- OrderTypeEnum::LOCKED
- );
- } catch (\Exception $exception) {
- $data = ['order_no'=> 'LC'.\app\common\service\Order::createOrderNo()];
- $model->save($data);
- $payment = PaymentService::wechat(
- $model['order_id'],
- $model['order_no'],
- $model['total_price'],
- OrderTypeEnum::LOCKED
- );
- }
- //
- $message = ['success' => '解锁成功', 'error' => '订单支付中'];
- return $this->renderSuccess(compact('payment', 'message'));
- }
- }
|