Ver código fonte

多层级bug修改

jun 4 meses atrás
pai
commit
cdc84e8bf8

+ 27 - 0
app/Http/Controllers/Admin/AdminUser.php

@@ -49,6 +49,33 @@ class AdminUser extends Auth{
 			if (in_array($value['uid'],explode(',',config('administrator')))) $group[] = '超管';
 			// 切成字符串
 			$value['title']		= implode('、', $group);
+            //获取用户角色
+            $rule               = DB::table('admin_rule')->where('admin_uid',$value['uid'])->first();
+            $rule_title         =   '';
+            if ($rule){
+                switch ($rule['menu_type']){
+                    case 1:
+                        $rule_title         =  '商户';
+                        break;
+                    case 2:
+                        $rule_title         =  '店铺';
+                        break;
+                }
+                if ($rule['menu_type'] == 1){
+                    if ($rule['data_type'] == 1){
+                        $rule_title     =   '商户普通员工';
+                    }elseif ($rule['data_type'] == 2){
+                        $rule_title     =   '商户代表';
+                    }
+                }elseif ($rule['menu_type'] == 2){
+                    if ($rule['data_type'] == 1){
+                        $rule_title     =   '店铺普通员工';
+                    }elseif ($rule['data_type'] == 2){
+                        $rule_title     =   '店铺推广员';
+                    }
+                }
+            }
+            $value['rule_title']    =   $rule_title;
 			// 重组
 			$list[$key]			= $value;
 		}

+ 31 - 8
app/Http/Controllers/Admin/Business.php

@@ -6,6 +6,8 @@ use App\Models\AdminUser;
 use App\Models\City;
 use App\Models\AuthRule;
 use App\Models\AdminRule;
+use App\Models\Company;
+use App\Models\AdminHistory;
 use Illuminate\Support\Carbon;
 use Illuminate\Support\Facades\DB;
 
@@ -38,27 +40,48 @@ class Business extends Auth{
 		// 查询条件
 		$map 					= [];
 		// 编码ID
-		if( $id )				$map[] = ['id','=',$id];
-		if( $phone )			$map[] = ['phone','=',$phone];
-		if( $startTime )		$map[] = ['insert_time','>=',Carbon::createFromFormat('Y-m-d',$startTime)->startOfDay()->getTimestamp()];
-		if( $startTime )		$map[] = ['insert_time','<=',Carbon::createFromFormat('Y-m-d',$startTime)->endOfDay()->getTimestamp()];
-		if( !is_null($status) )	$map[] = ['status','=',$status];
+		if( $id )				$map[] = ['business.id','=',$id];
+		if( $phone )			$map[] = ['business.phone','=',$phone];
+		if( $startTime )		$map[] = ['business.insert_time','>=',Carbon::createFromFormat('Y-m-d',$startTime)->startOfDay()->getTimestamp()];
+		if( $startTime )		$map[] = ['business.insert_time','<=',Carbon::createFromFormat('Y-m-d',$startTime)->endOfDay()->getTimestamp()];
+		if( !is_null($status) )	$map[] = ['business.status','=',$status];
         $session                = session('userRule');
         if ($session){
             $map[] = ['company_id','=',$session['company_id']];
             if ($session['business_id']){
-                $map[] = ['id','=',$session['business_id']];
+                $map[] = ['business.id','=',$session['business_id']];
             }
             if ($session['menu_type'] == 1 && $session['data_type'] == 2){
-                $map[] = ['leader_uid','=',$session['admin_uid']];
+                $map[] = ['business.leader_uid','=',$session['admin_uid']];
             }
         }
 		// 查询数据
-		$list					= $Model->query()->where($map)->orderByDesc('id')->paginate(config('page_num',10));
+		$list					= $Model->query()
+            ->join('company','company.id','=','business.company_id')
+            ->join('admin','admin.uid','=','business.admin_uid')
+            ->where($map)
+            ->orderByDesc('business.id')
+            ->select('business.*','company.name as company_name', 'admin.username as username','admin.phone as admin_phone')
+            ->paginate(config('page_num',10));
 		// 循环处理数据
 		foreach ($list as $key => $value) {
 			// id转编号
 			$value['business_code'] = $Model->idToCode($value['id']);
+            $value['logopic']		= $value['logopic'] ? path_compat($value['logopic']) : '';
+            $addHistory             = AdminHistory::query()
+                ->join('admin','admin.uid','=','admin_history.admin_uid')
+                ->where(['admin_history.primary_id'=>$value['id'],'admin_history.notes_type'=>1,'admin_history.table_name'=>$Model->getTable()])
+                ->select('admin_history.insert_time','admin.username as username')
+                ->first();
+            $editHistory            = AdminHistory::query()
+                ->join('admin','admin.uid','=','admin_history.admin_uid')
+                ->where(['admin_history.primary_id'=>$value['id'],'admin_history.notes_type'=>2,'admin_history.table_name'=>$Model->getTable()])
+                ->select('admin_history.update_time','admin.username as username')
+                ->orderByDesc('id')->first();
+            $value['add_history_username']  = $addHistory   ? $addHistory->username : '';
+            $value['add_history_time']      = $addHistory   ? $addHistory->insert_time : 0;
+            $value['edit_history_username'] = $editHistory  ? $editHistory->username : '';
+            $value['edit_history_time']     = $editHistory  ? $editHistory->update_time : 0;
 			// 重组
 			$list[$key]			= $value;
             if( $value['city_ids'] ) {

+ 37 - 37
app/Http/Controllers/Admin/Login.php

@@ -7,52 +7,52 @@ use Illuminate\Support\Facades\DB;
 
 /**
  * 管理后台登录控制器
- * 
+ *
  * @author 刘相欣
- * 
+ *
  * */
 class Login extends Admin {
 
 	/**
 	 * 登录方法
-	 * 
+	 *
 	 * */
-	public function index(AdminUser $AdminUser,AdminRule $AdminRule){
-		if( request()->isMethod('post') ){
-			// 接收数据
-			$username						= request('username','');
-			// 接收数据
-			$code							= request('code','');
-			// 验证
-			if( !$username || !$code )		return json_send(['code'=>'error','msg'=>'用户名验证码必填']);
-			// 查询用户
-			$uid							= $AdminUser->orWhere('username',$username)->orWhere('phone',$username)->value('uid');
-			// 获取数据
-			$admin							= $AdminUser->getOne($uid);
-			$adminRule						= $AdminRule::query()->where('admin_uid',$uid)->first();
-			// 用户不存在
-			if( !$admin || $admin['status'] ) return json_send(['code'=>'error','msg'=>'用户名不存在或已被停用']);
-			// 比对密码
-			if( md5($code) != $admin['password'] ) return json_send(['code'=>'error','msg'=>'密码错误或账号不存在']);
-			// 查询用户的组别
-			$group							= DB::table('auth_group_access')->where(['user_uid'=>$admin['uid']])->pluck('group_id')->toArray();
-			// 权限小组
-			$admin['group_id']				= $group;
-			// 删除敏感数据-密码
-			unset($admin['password']);
-			// 存储登录状态
-			session(['userAuth'=>$admin]);
-			session(['userRule'=>$adminRule]);
-			// 表单令牌
-			return							json_send(['code'=>'success','msg'=>'登录成功','path'=>url('admin')]);
-		}
-		// 加载模板
-		return								$this->fetch();
-	}
+    public function index(AdminUser $AdminUser,AdminRule $AdminRule){
+        if( request()->isMethod('post') ){
+            // 接收数据
+            $username						= request('username','');
+            // 接收数据
+            $code							= request('code','');
+            // 验证
+            if( !$username || !$code )		return json_send(['code'=>'error','msg'=>'用户名验证码必填']);
+            // 查询用户
+            $admin							= $AdminUser->orWhere('username',$username)->orWhere('phone',$username)->first(['uid','username','phone','status','password','insert_time','update_time']);
+            // 用户不存在
+            if( !$admin || $admin['status'] ) return json_send(['code'=>'error','msg'=>'用户名不存在或已被停用']);
+            // 比对密码
+            if( md5($code) != $admin['password'] ) return json_send(['code'=>'error','msg'=>'密码错误或账号不存在']);
+            $admin                          =   $admin->toArray();
+            // 获取数据
+            $adminRule						= $AdminRule::query()->where('admin_uid',$admin['uid'])->first();
+            // 查询用户的组别
+            $group							= DB::table('auth_group_access')->where(['user_uid'=>$admin['uid']])->pluck('group_id')->toArray();
+            // 权限小组
+            $admin['group_id']				= $group;
+            // 删除敏感数据-密码
+            unset($admin['password']);
+            // 存储登录状态
+            session(['userAuth'=>$admin]);
+            session(['userRule'=>$adminRule]);
+            // 表单令牌
+            return							json_send(['code'=>'success','msg'=>'登录成功','path'=>url('admin')]);
+        }
+        // 加载模板
+        return								$this->fetch();
+    }
 
 	/**
 	 * 退出登录方法
-	 * 
+	 *
 	 * */
 	public function out(){
 		// 清除
@@ -63,7 +63,7 @@ class Login extends Admin {
 
 	/**
 	 * 发送验证码
-	 * 
+	 *
 	 * */
 	public function send_code(Sms $Sms){
 		if( request()->isMethod('post') ){

+ 162 - 0
app/Models/Company.php

@@ -0,0 +1,162 @@
+<?php namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * 商业公司模型
+ * 
+ */
+class Company extends Model
+{
+    use HasFactory;
+
+    // 与模型关联的表名
+    protected $table = 'company';
+    // 是否主动维护时间戳
+    public $timestamps = false;
+    // 定义时间戳字段名
+    // const CREATED_AT = 'insert_time';
+    // const UPDATED_AT = 'update_time';
+
+    /**
+     * 添加数据
+     * 
+     */
+    public function add($data)
+    {
+        // 时间
+        $data['insert_time']				= time();
+        $data['update_time']				= time();
+        // 写入数据表
+        $id						            = $this->query()->insertGetId($data);
+        // 如果操作失败
+        if( !$id )                          return $id;
+        // 更新缓存
+        $this->getList(true);
+        // 返回结果
+        return                              $id;
+    }
+
+    /**
+     * 添加数据
+     * 
+     */
+    public function edit($id,$data)
+    {
+        // 更新时间
+        $data['update_time']                = time();
+        // 写入数据表
+        $result						        = $this->query()->where(['id'=>$id])->update($data);
+        // 如果操作失败
+        if( !$result )                      return $result;
+        // 更新缓存
+        $this->getList(true);
+        // 返回结果
+        return                              $result;
+    }
+
+    /**
+     * 获取列表
+     * @param   Bool    $force  是否强制更新
+     * 
+     */
+    public function getList($force = false)
+    {
+        // 结果数据
+        //$list                  = $force ? [] : cache('admin:business:list');
+        $list                   =   [];
+        // 不存在数据
+        if ( !$list ) {
+            $session           = session('userRule');
+            $map                =   [];
+            $map[] = ['status','=',0];
+            if ($session){
+                $map[] = ['company_id','=',$session['company_id']];
+                if ($session['business_id']){
+                    $map[] = ['id','=',$session['business_id']];
+                }
+                if ($session['menu_type'] == 1 && $session['data_type'] == 2){
+                    $map[] = ['leader_uid','=',$session['admin_uid']];
+                }
+            }
+            // 从数据库获取数据
+            $data              = $this->query()->where($map)->get();
+            // 是否有数据
+            $data              = $data ? $data->toArray() : [];
+            // 循环处理数据
+            $list              = [];
+            // 进行更新
+            foreach ($data as $value) {
+                // 重组数据
+                $list[$value['id']] = $value;
+            }
+            // 存起来
+            cache(['admin:business:list'=>$list]);
+        }
+        // 返回结果
+        return                  $list;
+    }
+
+    /**
+     * 获取配置平台对应的应用数据
+     * 
+     * @param   Array      用户ID
+     * @param   String     指定字段
+     * 
+     */
+    public function getOne($id,$field='')
+    {
+        // 获取列表数据
+        $list                   = $this->getList();
+        // 获取数据
+        $one                    = isset($list[$id]) ? $list[$id] : [];
+        // 返回值
+        return                  empty($field) ? $one : ( isset($one[$field]) ? $one[$field] : null);
+    }
+
+
+    /**
+     * 获取配置平台对应的应用数据
+     * 
+     * @param   Array      用户ID
+     * @param   String     指定字段
+     * 
+     */
+    public function getIdByName($name)
+    {
+        // 获取列表数据
+        $list                               = $this->getList();
+        // 获取数据
+        foreach ($list as $value) {
+            // 如果有名称
+            if( $name == $value['name'] )   return $value['id'];
+        }
+        // 写入数据表
+        $id						            = $this->add(['name'=>$name]);
+        // 返回结果
+        return                              $id;
+    }
+
+
+    /**
+     * 编码转id
+     * 
+     * @param  string $code 编码
+     * 
+     */
+    public function codeToId($code){
+        return intval(str_ireplace('klsj','',$code));
+    }
+ 
+    /**
+     * id转编码
+     * 
+     * @param  int  $id 编码
+     * 
+     */
+    public function idToCode($id){
+         return 'klsj'. str_pad($id, 9, '0', STR_PAD_LEFT);
+    }
+
+}

+ 6 - 1
resources/views/admin/admin_user/add.blade.php

@@ -25,7 +25,12 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 			</label>
 			<label class="checkbox-inline">
 				<input type="radio" value="2" name="data_type">
-				代表
+				@if(session('userRule.business_id'))
+					推广员
+				@else
+					代表
+				@endif
+
 			</label>
 		</div>
 	</div>

+ 5 - 1
resources/views/admin/admin_user/edit.blade.php

@@ -25,7 +25,11 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 			</label>
 			<label class="checkbox-inline">
 				<input type="checkbox" value="2" name="data_type">
-				代表
+				@if(session('userRule.business_id'))
+					推广员
+				@else
+					代表
+				@endif
 			</label>
 		</div>
 	</div>

+ 2 - 0
resources/views/admin/admin_user/index.blade.php

@@ -22,6 +22,7 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 					<tr>
 						<th>序号</th>
 						<th>用户账号</th>
+						<th>用户角色</th>
 						<th>用户权限</th>
 						<th>创建时间</th>
 						<th>操作</th>									
@@ -33,6 +34,7 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 						<tr>
 							<th>{{$a['uid']}}</th>
 							<td>{{$a['username']}}</td>
+							<td>{{$a['rule_title']}}</td>
 							<td>{{$a['title']}}</td>
 							<td> {{date('Y/m/d H:i:s',$a['insert_time'])}}</td>
 							<td>

+ 24 - 8
resources/views/admin/business/index.blade.php

@@ -38,14 +38,18 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 				<thead>
 					<tr>
 						<th>编码</th>
-						<th>状态</th>
 						<th>商业公司</th>
+						<th>图片</th>
+						<th>状态</th>
 						<th>联系方式</th>
 						<th>城市</th>
 						<th>详细地址</th>
 						<th>上级代表</th>
-						<th>简介说明</th>
-						<th>创建时间</th>
+						<th>管理员登录账号</th>
+						<th>管理员手机号</th>
+						<th>所属平台</th>
+						<th>最后修改人员/时间</th>
+						<th>创建人员/时间</th>
 						<th>操作</th>									
 					</tr>
 				</thead>
@@ -54,23 +58,35 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 						@foreach ($list as $a)
 						<tr>
 							<th>{{$a['business_code']}}</th>
-							<td>{{$a['status']?'禁用':'正常'}}</td>
 							<td>{{$a['name']}}</td>
+							<td> <img src="{{$a['logopic']}}" alt="" height="50"> </td>
+							<td>{{$a['status']?'停用':'启用'}}</td>
 							<td>{{$a['phone']}}</td>
 							<td>{{$a['city_ids']}}</td>
 							<td>{{$a['address']}}</td>
 							<td>{{$a['leader_uid']}}</td>
-							<td>{{$a['desc']}}</td>
-							<td> {{date('Y/m/d H:i:s',$a['insert_time'])}}</td>
+							<td>{{$a['username']}}</td>
+							<td>{{$a['admin_phone']}}</td>
+							<td>{{$a['company_name']}}</td>
+							<td>
+								@if($a['edit_history_time'])
+									{{$a['edit_history_username']}}<br/> {{date('Y/m/d H:i:s',$a['edit_history_time'])}}
+								@endif
+							</td>
+							<td>
+								@if($a['add_history_time'])
+									{{$a['add_history_username']}}<br/> {{date('Y/m/d H:i:s',$a['add_history_time'])}}
+								@endif
+							</td>
 							<td>
 								@if(check_auth('admin/business/edit'))
 								<a href="{{url('admin/business/edit?'.http_build_query(['id'=>$a['id']]))}}" class="btn btn-sm btn-warning" >编辑</a>
 								@endif
 								@if(check_auth('admin/business/set_status'))
 									@if($a['status'])
-									<a data-url="{{url('admin/business/set_status?'.http_build_query(['id'=>$a['id'],'status'=>0]))}}" class="set_status btn btn-sm btn-success" >取消拉黑</a>
+									<a data-url="{{url('admin/business/set_status?'.http_build_query(['id'=>$a['id'],'status'=>0]))}}" class="set_status btn btn-sm btn-success" >启用</a>
 									@else
-									<a data-url="{{url('admin/business/set_status?'.http_build_query(['id'=>$a['id'],'status'=>1]))}}" class="set_status btn btn-sm btn-danger" >拉黑</a>
+									<a data-url="{{url('admin/business/set_status?'.http_build_query(['id'=>$a['id'],'status'=>1]))}}" class="set_status btn btn-sm btn-danger" >停用</a>
 									@endif
 								@endif
 							</td>