Parcourir la source

Wesmiler 2021-0115第4期分销功能新增

wesmiler il y a 5 ans
Parent
commit
a9c5021c6a
2 fichiers modifiés avec 12 ajouts et 7 suppressions
  1. 7 2
      app/api/controller/MarketController.php
  2. 5 5
      app/weixin/model/Wechat.php

+ 7 - 2
app/api/controller/MarketController.php

@@ -90,8 +90,13 @@ class MarketController extends MarketBaseController
                 $qrcode = Wechat::makeNormalQrcode($inviteUrl);
                 $memberInfo['team_qrcode'] = $qrcode ? $qrcode : '';
 
-                // 会员邀请二维码
-                $qrcodeData = Wechat::makeQrcode($userId, $userId);
+                // 会员邀请二维码,2000以内永久
+                $randCount = Member::where(['user_type'=> 2, 'agent_type'=> 1, 'agent_status'=> 1])->where('id','<=', $userId)->count('id');
+                if($randCount>2000){
+                    $qrcodeData = Wechat::makeQrcode($userId, $userId);
+                }else{
+                    $qrcodeData = Wechat::makeQrcode($userId, $userId, 'qrcode','QR_LIMIT_STR_SCENE', 0);
+                }
                 $memberInfo['qrcode'] = isset($qrcodeData['qrcode']) ? $qrcodeData['qrcode'] : '';
             }
         }

+ 5 - 5
app/weixin/model/Wechat.php

@@ -1004,7 +1004,7 @@ class Wechat
      * @param $sceneStr 场景参数字符串或ID
      * @param $scene 场景标识:qrcode-用户二维码
      * @param string $qrType 二维码生成类型:QR_SCENE, QR_STR_SCENE, QR_LIMIT_SCENE, QR_LIMIT_STR_SCENE
-     * @param int $expire 有效期,配合场景类型使用,临时二维码最长30天有效期
+     * @param int $expire 有效期,配合场景类型使用,临时二维码最长30天有效期,0-永久
      * @return array|bool
      * @throws \think\Exception
      * @throws \think\db\exception\DataNotFoundException
@@ -1012,9 +1012,9 @@ class Wechat
      * @throws \think\exception\DbException
      * @throws \think\exception\PDOException
      */
-    public static function makeQrcode($sourceId = 0, $sceneStr = '', $scene = 'qrcode', $qrType = 'QR_STR_SCENE', $expire = 0)
+    public static function makeQrcode($sourceId = 0, $sceneStr = '', $scene = 'qrcode', $qrType = 'QR_STR_SCENE', $expire = -1)
     {
-        $expire = $expire ? $expire : 24 * 3600 * 20;
+        $expire = $expire>=0 ? $expire : 24 * 3600 * 20;
         $tokenData = Wechat::getAccessToken('', 'accessToken');
         $token = isset($tokenData['token']) ? trim($tokenData['token']) : '';
 
@@ -1024,7 +1024,7 @@ class Wechat
             ->find();
         $qrcodeId = isset($qrData['id']) ? $qrData['id'] : 0;
         $qrcodeExpire = isset($qrData['expire_at']) ? strtotime($qrData['expire_at']) : 0;
-        if ($qrcodeExpire > time() && $qrcodeId) {
+        if (($expire==0 && $qrcodeId) || $qrcodeExpire > time() && $qrcodeId) {
             $ticket = isset($qrData['ticket']) ? $qrData['ticket'] : '';
             $qrcode = sprintf(self::$apiUrl['getQrcodeByTicket'], $ticket);
             $qrData['qrcode'] = Wechat::loadImage($qrcode, 'qrcode');
@@ -1064,7 +1064,7 @@ class Wechat
                 'scene' => $scene,
                 'scene_str' => $sceneStr,
                 'ticket' => $ticket,
-                'expire_at' => date('Y-m-d H:i:s', time() + $expire),
+                'expire_at' => $expire>0? date('Y-m-d H:i:s', time() + $expire) : null,
                 'url' => isset($result['url']) ? $result['url'] : '',
             ];