Ver código fonte

格式化代碼

joe 4 anos atrás
pai
commit
0afa921e5b

+ 15 - 5
app/api/controller/wechat/AuthController.php

@@ -46,8 +46,16 @@ class AuthController
             return app('json')->fail('授权失败,参数有误');
         if ($code && !$session_key) {
             try {
-                $userInfoCong = MiniProgramService::getUserInfo($code);
-                $session_key = $userInfoCong['session_key'];
+                /**
+                 * 属性	类型	说明
+                    openid	string	用户唯一标识
+                    session_key	string	会话密钥
+                    unionid	string	用户在开放平台的唯一标识符,若当前小程序已绑定到微信开放平台帐号下会返回,详见 UnionID 机制说明。
+                    errcode	number	错误码
+                    errmsg	string	错误信息
+                 */
+                $userInfoWx = MiniProgramService::getUserInfo($code);
+                $session_key = $userInfoWx['session_key'];
                 $cache_key = md5(time() . $code);
                 Cache::set('eb_api_code_' . $cache_key, $session_key, 86400);
             } catch (\Exception $e) {
@@ -67,9 +75,11 @@ class AuthController
         } catch (\Exception $e) {
             if ($e->getCode() == '-41003') return app('json')->fail('获取会话密匙失败');
         }
-        if (!isset($userInfoCong['openid'])) return app('json')->fail('openid获取失败');
-        if (!isset($userInfo['unionId'])) $userInfo['unionId'] = '';
-        $userInfo['openId'] = $userInfoCong['openid'];
+        if (!isset($userInfoWx['openid'])) return app('json')->fail('openid获取失败');
+        if (!isset($userInfo['unionId'])) {
+            $userInfo['unionId'] = '';
+        }
+        $userInfo['openId'] = $userInfoWx['openid'];
         $userInfo['spid'] = $data['spread_spid'];
         $userInfo['code'] = $data['spread_code'];
         $userInfo['session_key'] = $session_key;

+ 7 - 3
app/common.php

@@ -29,6 +29,10 @@ define('REFUNDED', 2);
 define('SHIPPING_EXPRESS', 1);
 define('SHIPPING_SELF_COLLECT', 2);
 
+// 分銷方式
+define('DISTRIBUTE_SPECIFIED', 1);  // 指定分銷
+define('DISTRIBUTE_EVERYONE', 2);   // 人人分銷
+
 
 if (!function_exists('exception')) {
     /**
@@ -515,11 +519,11 @@ if (!function_exists('is_brokerage_statu')) {
      */
     function is_brokerage_statu(float $price)
     {
-        $storeBrokerageStatus = sys_config('store_brokerage_statu', 1);
-        if ($storeBrokerageStatus == 1) {
+        $storeBrokerageStatus = sys_config('store_brokerage_statu', DISTRIBUTE_SPECIFIED);
+        if ($storeBrokerageStatus == DISTRIBUTE_SPECIFIED) {
             return false;
         } else {
-            $storeBrokeragePrice = sys_config('store_brokerage_price', 0);
+            $storeBrokeragePrice = sys_config('store_brokerage_price', 0);  // 滿足金額
             return $price >= $storeBrokeragePrice;
         }
     }

+ 14 - 8
app/models/user/User.php

@@ -103,24 +103,26 @@ class User extends BaseModel
         $userInfo = self::where('uid', $uid)->find();
         if (!$userInfo) return;
         //增加成为分销权限
+        $becomingPromoter = false;
         if (!$userInfo->is_promoter) {
+            // 獲得有效訂單總金額
             $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $uid])->sum('pay_price');
-            $status = is_brokerage_statu($price);
+            $becomingPromoter = is_brokerage_statu($price);
         } else {
-            $status = false;
+            $becomingPromoter = false;
         }
         if ($userInfo->spread_uid) {
             return self::edit([
                 'nickname' => $wechatUser['nickname'] ?: '',
                 'avatar' => $wechatUser['headimgurl'] ?: '',
-                'is_promoter' => $status ? 1 : $userInfo->is_promoter,
+                'is_promoter' => $becomingPromoter ? 1 : $userInfo->is_promoter,
                 'login_type' => isset($wechatUser['login_type']) ? $wechatUser['login_type'] : $userInfo->login_type,
             ], $uid, 'uid');
         } else {
             $data = [
                 'nickname' => $wechatUser['nickname'] ?: '',
                 'avatar' => $wechatUser['headimgurl'] ?: '',
-                'is_promoter' => $status ? 1 : $userInfo->is_promoter,
+                'is_promoter' => $becomingPromoter ? 1 : $userInfo->is_promoter,
                 'login_type' => isset($wechatUser['login_type']) ? $wechatUser['login_type'] : $userInfo->login_type,
                 'spread_uid' => 0,
                 'spread_time' => 0,
@@ -129,9 +131,11 @@ class User extends BaseModel
             ];
             //TODO 获取后台分销类型
             $storeBrokerageStatus = sys_config('store_brokerage_statu');
-            $storeBrokerageStatus = $storeBrokerageStatus ? $storeBrokerageStatus : 1;
-            if (isset($wechatUser['code']) && $wechatUser['code'] && $wechatUser['code'] != $uid && $uid != self::where('uid', $wechatUser['code'])->value('spread_uid')) {
-                if ($storeBrokerageStatus == 1) {
+            $storeBrokerageStatus = $storeBrokerageStatus ? $storeBrokerageStatus : DISTRIBUTE_SPECIFIED;
+            if (isset($wechatUser['code']) && $wechatUser['code'] 
+                && $wechatUser['code'] != $uid 
+                && $uid != self::where('uid', $wechatUser['code'])->value('spread_uid')) {
+                if ($storeBrokerageStatus == DISTRIBUTE_SPECIFIED) {
                     $spreadCount = self::where('uid', $wechatUser['code'])->count();
                     if ($spreadCount) {
                         $spreadInfo = self::where('uid', $wechatUser['code'])->find();
@@ -196,7 +200,9 @@ class User extends BaseModel
     {
         self::beginTrans();
         $res1 = true;
-        if ($spread_uid) $res1 = self::where('uid', $spread_uid)->inc('spread_count', 1)->update();
+        if ($spread_uid) {
+            $res1 = self::where('uid', $spread_uid)->inc('spread_count', 1)->update();
+        }
 //        $storeBrokerageStatu = sys_config('store_brokerage_statu') ? : 1;//获取后台分销类型
         $res2 = self::create([
             'account' => 'rt' . $routineUser['uid'] . time(),

+ 7 - 3
app/models/user/WechatUser.php

@@ -98,10 +98,12 @@ class WechatUser extends BaseModel
             if ($info = RoutineQrcode::getRoutineQrcodeFindType($routine['code'])) {
                 $spid = $info['third_id'];
                 $isCOde = true;
-            } else
+            } else {
                 $spid = $routine['spid'];
-        } else if ($routine['spid'])
+            }
+        } else if ($routine['spid']) {
             $spid = $routine['spid'];
+        }
 
         //  判断unionid  存在根据unionid判断
         if ($routineInfo['unionid'] != '' && ($uid = self::where(['unionid' => $routineInfo['unionid']])->where('user_type', '<>', 'h5')->value('uid'))) {
@@ -114,7 +116,9 @@ class WechatUser extends BaseModel
             self::edit($routineInfo, $uid, 'uid');
             $routineInfo['code'] = $spid;
             $routineInfo['isPromoter'] = $isCOde;
-            if ($routine['login_type']) $routineInfo['login_type'] = $routine['login_type'];
+            if ($routine['login_type']) {
+                $routineInfo['login_type'] = $routine['login_type'];
+            }
             User::updateWechatUser($routineInfo, $uid);
         } else {
             $routineInfo['add_time'] = time();//用户添加时间