| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace app\api\controller\balance;
- use app\api\controller\Controller;
- use app\api\model\settings\Setting as SettingModel;
- use app\api\model\user\BalancePlan as BalancePlanModel;
- use app\api\model\user\BalanceOrder as BalanceOrderModel;
- use app\api\service\pay\PayService;
- use app\common\enum\order\OrderPayTypeEnum;
- use app\common\enum\order\OrderTypeEnum;
- /**
- * 充值套餐
- */
- class Plan extends Controller
- {
- /**
- * 余额首页
- */
- public function index()
- {
- $params = $this->request->param();
- $user = $this->getUser();
- $list = (new BalancePlanModel)->getList();
- // 设置
- $settings = SettingModel::getItem('balance');
- // 是否开启支付宝支付
- $show_alipay = PayService::isAlipayOpen($params['pay_source'], $user['app_id']);
- return $this->renderSuccess('', compact('list', 'settings', 'show_alipay'));
- }
- /**
- * 充值套餐
- */
- public function submit($plan_id, $user_money)
- {
- $params = $this->request->param();
- // 用户信息
- $user = $this->getUser();
- // 生成等级订单
- $model = new BalanceOrderModel();
- $order_id = $model->createOrder($user, $plan_id, $user_money);
- if (!$order_id) {
- return $this->renderError($model->getError() ?: '购买失败');
- }
- // 在线支付
- $payment = BalanceOrderModel::onOrderPayment($user, $model, OrderPayTypeEnum::WECHAT, $params['pay_source']);
- // 返回结算信息
- return $this->renderSuccess(['success' => '支付成功', 'error' => '订单未支付'], [
- 'order_id' => $order_id, // 订单id
- 'pay_type' => OrderPayTypeEnum::WECHAT, // 支付方式
- 'payment' => $payment, // 微信支付参数
- 'order_type' => OrderTypeEnum::BALANCE, //订单类型
- ]);
- }
- }
|