Pārlūkot izejas kodu

feat #1243 多个会员组

magicblack 3 mēneši atpakaļ
vecāks
revīzija
17ac297c71

+ 25 - 10
application/admin/controller/User.php

@@ -36,7 +36,14 @@ class User extends Base
 
         $group_list = model('Group')->getCache('group_list');
         foreach($res['list'] as $k=>$v){
-            $res['list'][$k]['group_name'] = $group_list[$v['group_id']]['group_name'];
+            $group_ids = explode(',', $v['group_id']);
+            $names = [];
+            foreach($group_ids as $gid){
+                if(isset($group_list[$gid])){
+                    $names[] = $group_list[$gid]['group_name'];
+                }
+            }
+            $res['list'][$k]['group_name'] = implode(',', $names);
         }
 
         $this->assign('list',$res['list']);
@@ -139,6 +146,9 @@ class User extends Base
     {
         if (Request()->isPost()) {
             $param = input('post.');
+            if(isset($param['group_id']) && is_array($param['group_id'])) {
+                $param['group_id'] = implode(',', $param['group_id']);
+            }
             $res = model('User')->saveData($param);
             if($res['code']>1){
                 return $this->error($res['msg']);
@@ -146,19 +156,24 @@ class User extends Base
             return $this->success($res['msg']);
         }
 
-        $id = input('id');
+        $id = input('id/d');
         $where=[];
         $where['user_id'] = ['eq',$id];
         $res = model('User')->infoData($where);
+        $info = $res['info'];
 
-        $this->assign('info',$res['info']);
-
-        $order='group_id asc';
-        $where=[];
-        $res = model('Group')->listData($where,$order);
-        $this->assign('group_list',$res['list']);
-
-        $this->assign('title',lang('admin/user/title'));
+        $group_list = model('Group')->getCache('group_list');
+        $group_ids = isset($info['group_id']) ? explode(',', $info['group_id']) : [];
+        $has_vip_group = false;
+        foreach($group_ids as $gid){
+            if(intval($gid) > 2){
+                $has_vip_group = true;
+                break;
+            }
+        }
+        $this->assign('info', $info);
+        $this->assign('group_list', $group_list);
+        $this->assign('has_vip_group', $has_vip_group);
         return $this->fetch('admin@user/info');
     }
 

+ 7 - 3
application/admin/view_new/user/index.html

@@ -47,7 +47,7 @@
                     <th width="25"><input type="checkbox" lay-skin="primary" lay-filter="allChoose"></th>
                     <th width="100">{:lang('id')}</th>
                     <th>{:lang('name')}</th>
-                    <th width="100">{:lang('group')}</th>
+                    <th width="80">{:lang('group')}</th>
                     <th width="80">{:lang('status')}</th>
                     <th width="80">{:lang('points')}</th>
                     <th width="130">{:lang('last_login_time')}</th>
@@ -63,8 +63,12 @@
                 <td><input type="checkbox" name="ids[]" value="{$vo.user_id}" class="layui-checkbox checkbox-ids"
                         lay-skin="primary"></td>
                 <td>{$vo.user_id}</td>
-                <td>{$vo.user_name|htmlspecialchars}</td>
-                <td>{$vo.group_name|htmlspecialchars}</td>
+                <td>{$vo.user_name}</td>
+                <td>
+                    {volist name=":explode(',',$vo.group_id)" id="gid"}
+                    {$group_list[$gid]['group_name']}{if !$i.last},{/if}
+                    {/volist}
+                </td>
                 <td>
                     <input type="checkbox" name="status" {if condition="$vo['user_status'] eq 1" }checked{/if}
                         value="{$vo['user_status']}" lay-skin="switch" lay-filter="switchStatus"

+ 23 - 16
application/admin/view_new/user/info.html

@@ -26,14 +26,12 @@
         </div>
 
 
-        <div class="layui-form-item ">
+        <div class="layui-form-item">
             <label class="layui-form-label">{:lang('group')}:</label>
-            <div class="layui-input-inline">
-                <select name="group_id" lay-filter="group_id">
-                    {volist name="group_list" id="vo"}
-                    <option value="{$vo.group_id}" {if condition="$info['group_id'] eq $vo['group_id']"}selected {/if}>{$vo.group_name}</option>
-                    {/volist}
-                </select>
+            <div class="layui-input-block">
+                {volist name="group_list" id="vo"}
+                <input type="checkbox" name="group_id[]" value="{$vo.group_id}" title="{$vo.group_name}" lay-filter="group_id" {if condition="in_array($vo.group_id,explode(',',$info.group_id))"}checked{/if}>
+                {/volist}
             </div>
         </div>
         {if condition="$info.user_id neq ''"}
@@ -55,8 +53,7 @@
             </div>
         </div>
 
-        <div class="layui-form-item rowTime" {if condition="$info.group_id elt 2"} style="display:none;" {/if}>
-
+        <div class="layui-form-item rowTime" {if condition="!$has_vip_group"} style="display:none;" {/if}>
             <label class="layui-form-label">{:lang('admin/user/time_end')}:</label>
             <div class="layui-input-inline">
                 <input type="text" class="layui-input" name="user_end_time" id="user_end_time" value="{$info.user_end_time|date='Y-m-d H:i:s',###}" placeholder="yyyy-MM-dd HH:mm:ss">
@@ -140,22 +137,32 @@
         //日期范围
         laydate.render({
             elem: '#user_end_time',
-            type: 'datetime'
+            type: 'datetime',
+            trigger: 'click'
         });
         laydate.render({
             elem: '#user_start_time',
-            type: 'datetime'
+            type: 'datetime',
+            trigger: 'click'
         });
 
-        form.on('select(group_id)', function(data) {
-            $('.rowTime').hide();
-            if(data.value >2 ){
+        form.on('checkbox(group_id)', function(data) {
+            var checkedBoxes = $('input[name="group_id[]"]:checked');
+            var hasHighLevelGroup = false;
+            checkedBoxes.each(function() {
+                var groupId = parseInt($(this).val());
+                if (groupId > 2) {
+                    hasHighLevelGroup = true;
+                    return false;
+                }
+            });
+            if (hasHighLevelGroup) {
                 $('.rowTime').show();
+            } else {
+                $('.rowTime').hide();
             }
         });
 
-
-
         upload.render({
             elem: '.layui-upload'
             ,url: "{:url('upload/upload')}?flag=user&user_id={$info.user_id}"

+ 41 - 14
application/common/model/User.php

@@ -51,7 +51,13 @@ class User extends Base
 
         //用户组
         $group_list = model('Group')->getCache('group_list');
-        $info['group'] = $group_list[$info['group_id']];
+        $group_ids = explode(',', $info['group_id']);
+        $info['group'] = [];
+        foreach($group_ids as $gid){
+            if(isset($group_list[$gid])){
+                $info['group'][] = $group_list[$gid];
+            }
+        }
 
 
         $info['user_pwd'] = '';
@@ -383,12 +389,18 @@ class User extends Base
 
         //用户组
         $group_list = model('Group')->getCache('group_list');
-        $group = $group_list[$row['group_id']];
+        $group_ids = explode(',', $row['group_id']);
+        $group = [];
+        foreach($group_ids as $gid){
+            if(isset($group_list[$gid])){
+                $group[] = $group_list[$gid];
+            }
+        }
 
         cookie('user_id', $row['user_id'],['expire'=>2592000] );
         cookie('user_name', $row['user_name'],['expire'=>2592000] );
-        cookie('group_id', $group['group_id'],['expire'=>2592000] );
-        cookie('group_name', $group['group_name'],['expire'=>2592000] );
+        cookie('group_id', $group[0]['group_id'],['expire'=>2592000] );
+        cookie('group_name', $group[0]['group_name'],['expire'=>2592000] );
         cookie('user_check', md5($random . '-' .$row['user_name'] . '-' . $row['user_id'] .'-' ),['expire'=>2592000] );
         cookie('user_portrait', mac_get_user_portrait($row['user_id']),['expire'=>2592000] );
 
@@ -398,11 +410,10 @@ class User extends Base
     public function expire()
     {
         $where=[];
-        $where['group_id'] = ['gt',2];
         $where['user_end_time'] = ['elt',time()];
 
         $update=[];
-        $update['group_id'] = 2;
+        $update['group_id'] = '2';
 
         $res = $this->where($where)->update($update);
         if ($res === false) {
@@ -452,7 +463,13 @@ class User extends Base
         }
 
         $group_list = model('Group')->getCache('group_list');
-        $info['group'] = $group_list[$info['group_id']];
+        $group_ids = explode(',', $info['group_id']);
+        $info['group'] = [];
+        foreach($group_ids as $gid){
+            if(isset($group_list[$gid])){
+                $info['group'][] = $group_list[$gid];
+            }
+        }
 
         //会员截止日期
         if ($info['group_id'] > 2 && $info['user_end_time'] < time()) {
@@ -528,13 +545,20 @@ class User extends Base
 
     }
 
-    public function popedom($type_id, $popedom, $group_id = 1)
+    public function popedom($type_id, $popedom, $group_ids = 1)
     {
         $group_list = model('Group')->getCache();
-        $group_info = $group_list[$group_id];
-
-        if (strpos(',' . $group_info['group_type'], ',' . $type_id . ',') !== false && !empty($group_info['group_popedom'][$type_id][$popedom]) !== false) {
-            return true;
+        $group_ids = explode(',', $group_ids);
+        
+        foreach($group_ids as $group_id) {
+            if(!isset($group_list[$group_id])) {
+                continue;
+            }
+            $group_info = $group_list[$group_id];
+            
+            if (strpos(',' . $group_info['group_type'], ',' . $type_id . ',') !== false && !empty($group_info['group_popedom'][$type_id][$popedom]) !== false) {
+                return true;
+            }
         }
         return false;
     }
@@ -576,11 +600,14 @@ class User extends Base
 
         $where = [];
         $where['user_id'] = $GLOBALS['user']['user_id'];
-
+        $old_group_ids = explode(',', $GLOBALS['user']['group_id']);
+        if(!in_array($group_id, $old_group_ids)){
+            $old_group_ids[] = $group_id;
+        }
         $data = [];
         $data['user_points'] = $GLOBALS['user']['user_points'] - $point;
         $data['user_end_time'] = $end_time;
-        $data['group_id'] = $group_id;
+        $data['group_id'] = implode(',', array_unique($old_group_ids));
 
         $res = $this->where($where)->update($data);
         if($res===false){

+ 4 - 1
application/data/update/database.php

@@ -108,4 +108,7 @@ if (version_compare(config('version.code'), '2024.1000.4043', '>=')) {
         $config['collect']['vod']['inrule_first_change']= true;
         $res = mac_arr2file($file, $config);
     }
-}
+}
+// 修改group_id字段为varchar(255)
+$sql = "ALTER TABLE `mac_user` MODIFY COLUMN `group_id` varchar(255) NOT NULL DEFAULT '0' COMMENT '会员组ID,多个用逗号分隔';";
+$sql .= "\r";

+ 66 - 16
application/index/controller/Base.php

@@ -92,12 +92,21 @@ class Base extends All
     protected function check_user_popedom($type_id,$popedom,$param=[],$flag='',$info=[],$trysee=0)
     {
         $user = $GLOBALS['user'];
-        $group = $GLOBALS['user']['group'];
-
+        $group_ids = explode(',', $user['group_id']);
+        $group_list = model('Group')->getCache();
+        
         $res = false;
-        if(strpos(','.$group['group_type'],','.$type_id.',')!==false && !empty($group['group_popedom'][$type_id][$popedom])!==false){
-            $res = true;
+        foreach($group_ids as $group_id) {
+            if(!isset($group_list[$group_id])) {
+                continue;
+            }
+            $group = $group_list[$group_id];
+            if(strpos(','.$group['group_type'],','.$type_id.',')!==false && !empty($group['group_popedom'][$type_id][$popedom])!==false){
+                $res = true;
+                break;
+            }
         }
+        
         $pre = $flag;
         $col = 'detail';
         if($flag=='play' || $flag=='down'){
@@ -116,11 +125,25 @@ class Base extends All
 
         }
         elseif($popedom==2 && in_array($pre,['art','actor','website'])){
+            $has_permission = false;
+            $has_trysee = false;
+            foreach($group_ids as $group_id) {
+                if(!isset($group_list[$group_id])) {
+                    continue;
+                }
+                $group = $group_list[$group_id];
+                if(!empty($group['group_popedom'][$type_id][2])) {
+                    $has_permission = true;
+                }
+                if($trysee > 0) {
+                    $has_trysee = true;
+                }
+            }
 
-            if($res===false && (empty($group['group_popedom'][$type_id][2]) || $trysee==0)){
+            if($res===false && (!$has_permission || !$has_trysee)){
                 return ['code'=>3001,'msg'=>lang('controller/no_popedom'),'trysee'=>0];
             }
-            elseif($group['group_id']<3 && $points>0  ){
+            elseif(max($group_ids)<3 && $points>0){
                 $mid = mac_get_mid($pre);
                 $where=[];
                 $where['ulog_mid'] = $mid;
@@ -141,13 +164,25 @@ class Base extends All
             }
         }
         elseif($popedom==3){
-            if($res===false && (empty($group['group_popedom'][$type_id][5]) || $trysee==0)){
-                return ['code'=>3001,'msg'=>lang('controller/no_popedom'),'trysee'=>0];
+            $has_permission = false;
+            $has_trysee = false;
+            foreach($group_ids as $group_id) {
+                if(!isset($group_list[$group_id])) {
+                    continue;
+                }
+                $group = $group_list[$group_id];
+                if(!empty($group['group_popedom'][$type_id][5])) {
+                    $has_permission = true;
+                }
+                if($trysee > 0) {
+                    $has_trysee = true;
+                }
             }
-            elseif($group['group_id']<3 && empty($group['group_popedom'][$type_id][3]) && !empty($group['group_popedom'][$type_id][5]) && $trysee>0){
-                return ['code'=>3002,'msg'=>lang('controller/in_try_see'),'trysee'=>$trysee];
+
+            if($res===false && (!$has_permission || !$has_trysee)){
+                return ['code'=>3001,'msg'=>lang('controller/no_popedom'),'trysee'=>0];
             }
-            elseif($group['group_id']<3 && $points>0  ){
+            elseif(max($group_ids)<3 && $points>0){
                 $where=[];
                 $where['ulog_mid'] = 1;
                 $where['ulog_type'] = $flag=='play' ? 4 : 5;
@@ -172,10 +207,10 @@ class Base extends All
                 return ['code'=>1001,'msg'=>lang('controller/no_popedom')];
             }
             if($popedom == 4){
-                if( $group['group_id'] ==1 && $points>0){
+                if(max($group_ids)==1 && $points>0){
                     return ['code'=>4001,'msg'=>lang('controller/charge_data'),'trysee'=>0];
                 }
-                elseif($group['group_id'] ==2 && $points>0){
+                elseif(max($group_ids)==2 && $points>0){
                     $where=[];
                     $where['ulog_mid'] = 1;
                     $where['ulog_type'] = $flag=='play' ? 4 : 5;
@@ -196,7 +231,22 @@ class Base extends All
                 }
             }
             elseif($popedom==5){
-                if(empty($group['group_popedom'][$type_id][3]) && !empty($group['group_popedom'][$type_id][5])){
+                $has_permission = false;
+                $has_trysee = false;
+                foreach($group_ids as $group_id) {
+                    if(!isset($group_list[$group_id])) {
+                        continue;
+                    }
+                    $group = $group_list[$group_id];
+                    if(!empty($group['group_popedom'][$type_id][3])) {
+                        $has_permission = true;
+                    }
+                    if(!empty($group['group_popedom'][$type_id][5])) {
+                        $has_trysee = true;
+                    }
+                }
+
+                if(!$has_permission && $has_trysee){
                     $where=[];
                     $where['ulog_mid'] = 1;
                     $where['ulog_type'] = $flag=='play' ? 4 : 5;
@@ -217,10 +267,10 @@ class Base extends All
                     elseif($points>0 && $res['code'] == 1) {
 
                     }
-                    elseif( $group['group_id'] <=2 && $points <= intval($user['user_points']) ){
+                    elseif(max($group_ids)<=2 && $points <= intval($user['user_points'])){
                         return ['code'=>5001,'msg'=>lang('controller/try_see_end',[$points, $user['user_points']]),'trysee'=>$trysee];
                     }
-                    elseif( $group['group_id'] <3 && $points > intval($user['user_points']) ){
+                    elseif(max($group_ids)<3 && $points > intval($user['user_points'])){
                         return ['code'=>5002,'msg'=>lang('controller/not_enough_points',[$points,$user['user_points'] ]),'trysee'=>$trysee];
                     }
                 }

+ 1 - 1
application/install/sql/install.sql

@@ -629,7 +629,7 @@ CREATE TABLE `mac_ulog` (
 DROP TABLE IF EXISTS `mac_user`;
 CREATE TABLE `mac_user` (
   `user_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
-  `group_id` smallint(6) unsigned NOT NULL DEFAULT '0' ,
+  `group_id` varchar(255) NOT NULL DEFAULT '0' COMMENT '会员组ID,多个用逗号分隔',
   `user_name` varchar(30) NOT NULL DEFAULT '' ,
   `user_pwd` varchar(32) NOT NULL DEFAULT '' ,
   `user_nick_name` varchar(30) NOT NULL DEFAULT '' ,