Parcourir la source

fix: 完善支付和充值

joe il y a 4 ans
Parent
commit
69576648b3

+ 51 - 3
app/api/controller/user/UserRechargeController.php

@@ -97,9 +97,57 @@ class UserRechargeController
                 try {
                     if ($from == 'weixinh5') {
                         $recharge = UserRecharge::wxH5Pay($rechargeOrder);
-                    } elseif ($from == 'weixinapp') {
+                    } else {    // weixin routine
+                        $recharge = UserRecharge::wxPay($rechargeOrder);
+                    }
+                } catch (\Exception $e) {
+                    return app('json')->fail($e->getMessage());
+                }
+                return app('json')->successful(['type' => $from, 'data' => $recharge]);
+                break;
+            case 1: //佣金转入余额
+                if (UserRecharge::importNowMoney($request->uid(), $price))
+                    return app('json')->successful('转入余额成功');
+                else
+                    return app('json')->fail(UserRecharge::getErrorInfo());
+                break;
+            default:
+                return app('json')->fail('缺少参数');
+                break;
+        }
+    }
+
+    /**
+     * app 充值
+     */
+    public function app(Request $request)
+    {
+        list($price, $recharId, $payType, $type) = UtilService::postMore([
+            [['price', 'f'], 0],
+            [['rechar_id', 'd'], 0],
+            ['payType', 'weixin'],  // weixin/alipay
+            ['type', 0]
+        ], $request, true);
+        if (!$price || $price <= 0) return app('json')->fail('参数错误');
+        $storeMinRecharge = sys_config('store_user_min_recharge');
+        if ($price < $storeMinRecharge) return app('json')->fail('充值金额不能低于' . $storeMinRecharge);
+        switch ((int)$type) {
+            case 0: //支付充值余额
+                $paid_price = 0;
+                if ($recharId) {
+                    $data = SystemGroupData::getDateValue($recharId);
+                    if ($data === false) {
+                        return app('json')->fail('您选择的充值方式已下架!');
+                    } else {
+                        $paid_price = $data['give_money'] ?? 0;
+                    }
+                }
+                $rechargeOrder = UserRecharge::addRecharge($request->uid(), $price, 'weixin', $paid_price);
+                if (!$rechargeOrder) return app('json')->fail('充值订单生成失败!');
+                try {
+                    if ($payType == 'weixin') {
                         $recharge = UserRecharge::wxAppPay($rechargeOrder);
-                    } elseif ($from == 'alipayapp') {
+                    } elseif ($payType == 'alipay') {
                         throw new \Exception('unsupported');
                     } else {    // weixin routine
                         $recharge = UserRecharge::wxPay($rechargeOrder);
@@ -107,7 +155,7 @@ class UserRechargeController
                 } catch (\Exception $e) {
                     return app('json')->fail($e->getMessage());
                 }
-                return app('json')->successful(['type' => $from, 'data' => $recharge]);
+                return app('json')->successful(['type' => $payType, 'data' => $recharge]);
                 break;
             case 1: //佣金转入余额
                 if (UserRecharge::importNowMoney($request->uid(), $price))

+ 1 - 1
app/models/store/StoreOrder.php

@@ -263,7 +263,7 @@ class StoreOrder extends BaseModel
      * @param int $seckill_id
      * @param int $bargain_id
      * @param bool $test
-     * @param int $isChannel 0, 1, 2 : routine, weixin, weixinh5
+     * @param int $isChannel 1, 0, 2 : routine, weixin, weixinh5
      * @param int $shipping_type
      * @param string $real_name
      * @param string $phone

+ 1 - 1
app/models/store/StoreOrderBatch.php

@@ -273,7 +273,7 @@ class StoreOrderBatch extends BaseModel {
      * @param int $seckill_id
      * @param int $bargain_id
      * @param bool $test
-     * @param int $isChannel 0, 1, 2 : routine, weixin, weixinh5
+     * @param int $isChannel 1, 0, 2 : routine, weixin, weixinh5
      * @param int $shipping_type
      * @param string $real_name
      * @param string $phone

+ 6 - 6
crmeb/repositories/OrderRepository.php

@@ -39,7 +39,7 @@ class OrderRepository
         $openid = WechatUser::getOpenId($orderInfo['uid']);
         $bodyContent = StoreOrder::getProductTitle($orderInfo['cart_id']);
         $site_name = sys_config('site_name');
-        if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
+        if (!$bodyContent && !$site_name) exception('缺少支付参数');
         return MiniProgramService::jsPay($openid, $orderInfo['order_id'], $orderInfo['pay_price'], 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
     }
 
@@ -66,7 +66,7 @@ class OrderRepository
         $openid = WechatUser::getOpenId($porderInfo['uid']);
         $bodyContent = StoreOrderBatch::getProductTitleBatch($subOrders);
         $site_name = sys_config('site_name');
-        if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
+        if (!$bodyContent && !$site_name) exception('缺少支付参数');
         return MiniProgramService::jsPay($openid, $porderInfo['porder_id'], $fieldValues['pay_price'], 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
     }
 
@@ -91,7 +91,7 @@ class OrderRepository
         $openid = WechatUser::uidToOpenid($orderInfo['uid'], 'openid');
         $bodyContent = StoreOrder::getProductTitle($orderInfo['cart_id']);
         $site_name = sys_config('site_name');
-        if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
+        if (!$bodyContent && !$site_name) exception('缺少支付参数');
         return WechatService::jsPay($openid, $orderInfo['porder_id'], $orderInfo['total_price'], 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
     }
 
@@ -119,7 +119,7 @@ class OrderRepository
         $openid = WechatUser::uidToOpenid($porderInfo['uid'], 'openid');
         $bodyContent = StoreOrderBatch::getProductTitleBatch($subOrders);
         $site_name = sys_config('site_name');
-        if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
+        if (!$bodyContent && !$site_name) exception('缺少支付参数');
         return WechatService::jsPay($openid, $porderInfo['porder_id'], $porderInfo['total_price'], 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
     }
 
@@ -156,7 +156,7 @@ class OrderRepository
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\exception\DbException
      */
-    public static function h5PayBatch($porderId, $field = 'order_id')
+    public static function h5PayBatch($porderId, $field = 'porder_id')
     {
         if (is_string($porderId))
             $porderInfo = StoreOrderBatch::where($field, $porderId)->find();
@@ -208,7 +208,7 @@ class OrderRepository
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\exception\DbException
      */
-    public static function wxAppPayBatch($porderId, $field = 'order_id')
+    public static function wxAppPayBatch($porderId, $field = 'porder_id')
     {
         if (is_string($porderId))
             $porderInfo = StoreOrderBatch::where($field, $porderId)->find();

+ 1 - 0
route/api/route.php

@@ -167,6 +167,7 @@ Route::group(function () {
     //充值类
     Route::post('recharge/routine', 'user.UserRechargeController/routine')->name('rechargeRoutine');//小程序充值
     Route::post('recharge/wechat', 'user.UserRechargeController/wechat')->name('rechargeWechat');//公众号充值
+    Route::post('recharge/app', 'user.UserRechargeController/app')->name('rechargeApp');//app充值
     Route::get('recharge/index','user.UserRechargeController/index')->name('rechargeQuota');//充值余额选择
     //会员等级类
     Route::get('menu/user', 'PublicController/menu_user')->name('menuUser');//个人中心菜单