Plan.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\api\controller\balance;
  3. use app\api\controller\Controller;
  4. use app\api\model\settings\Setting as SettingModel;
  5. use app\api\model\user\BalancePlan as BalancePlanModel;
  6. use app\api\model\user\BalanceOrder as BalanceOrderModel;
  7. use app\api\service\pay\PayService;
  8. use app\common\enum\order\OrderPayTypeEnum;
  9. use app\common\enum\order\OrderTypeEnum;
  10. /**
  11. * 充值套餐
  12. */
  13. class Plan extends Controller
  14. {
  15. /**
  16. * 余额首页
  17. */
  18. public function index()
  19. {
  20. $params = $this->request->param();
  21. $user = $this->getUser();
  22. $list = (new BalancePlanModel)->getList();
  23. // 设置
  24. $settings = SettingModel::getItem('balance');
  25. // 是否开启支付宝支付
  26. $show_alipay = PayService::isAlipayOpen($params['pay_source'], $user['app_id']);
  27. return $this->renderSuccess('', compact('list', 'settings', 'show_alipay'));
  28. }
  29. /**
  30. * 充值套餐
  31. */
  32. public function submit($plan_id, $user_money)
  33. {
  34. $params = $this->request->param();
  35. // 用户信息
  36. $user = $this->getUser();
  37. // 生成等级订单
  38. $model = new BalanceOrderModel();
  39. $order_id = $model->createOrder($user, $plan_id, $user_money);
  40. if (!$order_id) {
  41. return $this->renderError($model->getError() ?: '购买失败');
  42. }
  43. // 在线支付
  44. $payment = BalanceOrderModel::onOrderPayment($user, $model, OrderPayTypeEnum::WECHAT, $params['pay_source']);
  45. // 返回结算信息
  46. return $this->renderSuccess(['success' => '支付成功', 'error' => '订单未支付'], [
  47. 'order_id' => $order_id, // 订单id
  48. 'pay_type' => OrderPayTypeEnum::WECHAT, // 支付方式
  49. 'payment' => $payment, // 微信支付参数
  50. 'order_type' => OrderTypeEnum::BALANCE, //订单类型
  51. ]);
  52. }
  53. }