Plan.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. $params = $this->request->param();
  20. $user = $this->getUser();
  21. $list = (new BalancePlanModel)->getList();
  22. // 设置
  23. $settings = SettingModel::getItem('balance');
  24. // 是否开启支付宝支付
  25. $show_alipay = PayService::isAlipayOpen($params['pay_source'], $user['app_id']);
  26. return $this->renderSuccess('', compact('list', 'settings'));
  27. }
  28. /**
  29. * 充值套餐
  30. */
  31. public function submit($plan_id, $user_money)
  32. {
  33. $params = $this->request->param();
  34. // 用户信息
  35. $user = $this->getUser();
  36. // 生成等级订单
  37. $model = new BalanceOrderModel();
  38. $order_id = $model->createOrder($user, $plan_id, $user_money);
  39. if(!$order_id){
  40. return $this->renderError($model->getError() ?: '购买失败');
  41. }
  42. // 在线支付
  43. $payment = BalanceOrderModel::onOrderPayment($user, $model, OrderPayTypeEnum::WECHAT, $params['pay_source']);
  44. // 返回结算信息
  45. return $this->renderSuccess(['success' => '支付成功', 'error' => '订单未支付'], [
  46. 'order_id' => $order_id, // 订单id
  47. 'pay_type' => OrderPayTypeEnum::WECHAT, // 支付方式
  48. 'payment' => $payment, // 微信支付参数
  49. 'order_type' => OrderTypeEnum::BALANCE, //订单类型
  50. ]);
  51. }
  52. }