添加:获取用户身份信息

This commit is contained in:
wuhui_zzw 2024-02-20 11:55:12 +08:00
parent a322bf68df
commit e5b093449f
5 changed files with 90 additions and 18 deletions

View File

@ -79,7 +79,7 @@ class AgentDao extends BaseDao{
},
])
->order('create_time DESC,id DESC')
->append(['only_key','mer_id_list','children_count']);
->append(['only_key','mer_id_list','children_count','agent_type_text']);
}

View File

@ -59,6 +59,31 @@ class Agent extends BaseModel{
}
return 0;
}
/**
* Common: 获取角色类型
* Author: wu-hui
* Time: 2024/02/20 10:44
* @return string
*/
public function getAgentTypeTextAttr():string{
// 类型1=总部发起人,2=省公司发起人,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商,9=总部外勤,10=总部内勤
$agentType = $this->agent_type ?? -1;
switch($agentType){
case 1: return '总部发起人';break;
case 2: return '省公司发起人';break;
case 3: return '省公司外勤';break;
case 4: return '省公司内勤';break;
case 5: return '区县运营商';break;
case 6: return '区县合伙人';break;
case 7: return '餐厅';break;
case 8: return '配送商';break;
case 9: return '总部外勤';break;
case 10: return '总部内勤';break;
}
return '';
}
public function user(){
return $this->hasOne(User::class, 'uid', 'uid');
@ -66,9 +91,6 @@ class Agent extends BaseModel{
public function parent(){
return $this->hasOne(self::class, 'id', 'pid');
}
public function province(){
return $this->hasOne(CityArea::class, 'id', 'province_id');
}

View File

@ -96,6 +96,41 @@ class AgentRepository extends BaseRepository{
throw new ValidateException('小程序码生成失败!');
}
/**
* Common: 获取用户指定身份列表
* Author: wu-hui
* Time: 2024/02/19 17:47
* @param int $uid
* @param string $type
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getIdentityList(int $uid,string $type = 'headquarters'):array{
// 根据身份类型,获取代理中心角色类型数组headquarters=总部province=省公司county=区县
// 类型1=总部发起人,2=省公司发起人,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商,9=总部外勤,10=总部内勤
switch($type){
case 'headquarters':
$agentType = [1,9,10];
break;
case 'province':
$agentType = [2,3,4];
break;
case 'county':
$agentType = [5,6,7,8];
break;
default:
throw new ValidateException('身份查询失败!');
}
// 获取对应的角色身份列表
return $this->dao->searchList(['uid'=>$uid])
->whereIn('agent_type', $agentType)
->whereNotIn('agent_type', [4,7,8,10])// 忽略无管理菜单的角色
->field(['id','uid','agent_type','province_id','city_id','area_id','street_id','address','mer_id','contact_name'])
->select()
->toArray();
}
/**
@ -212,7 +247,7 @@ class AgentRepository extends BaseRepository{
$delIds = array_diff($allIds,$updateIds);
// 处理结果 进行对应的操作;必须按照先删除、在修改、最后添加的顺序进行
if(count($delIds) > 0) Agent::whereIn('id',$delIds)->where('agent_type','<>',8)->update(['is_del'=>1]);
if(count($delIds) > 0) Agent::whereIn('id',$delIds)->update(['is_del'=>1]);
if(count($updateData) > 0) Agent::batchUpdate(array_values($updateData));
if(count($insertData) > 0) $this->dao->insertAll($insertData);
if(count($merUpdateData) > 0) {

View File

@ -23,16 +23,14 @@ class Agent extends BaseController{
* Common: 获取代理列表
* Author: wu-hui
* Time: 2024/01/29 16:00
* @return mixed
*/
public function agentList(){
// 参数处理
[$page, $limit] = $this->getPage();
$params = $this->request->params(['is_get_self','not_page','pid']);
if((int)$params['is_get_self'] > 0) $params['uid'] = $this->request->uid();
$params = $this->request->params(['uid','not_page','pid', 'id']);
// 信息列表获取
if((int)$params['not_page'] > 0) $data = app()->make(AgentRepository::class)->getAllList((array)$params);
else $data = app()->make(AgentRepository::class)->getList((array)$params,(int)$page,(int)$limit);
if((int)$params['not_page'] > 0) $data = $this->repository->getAllList((array)$params);
else $data = $this->repository->getList((array)$params,(int)$page,(int)$limit);
return app('json')->success($data);
}
@ -68,7 +66,7 @@ class Agent extends BaseController{
* @return mixed
*/
public function getConfig(){
$config = app()->make(AgentRepository::class)->getConfig();
$config = $this->repository->getConfig();
return app('json')->success($config);
}
@ -214,6 +212,28 @@ class Agent extends BaseController{
return app('json')->success($data);
}
/**
* Common: 获取用户身份信息列表
* Author: wu-hui
* Time: 2024/02/19 17:47
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getIdentityList(){
$uid = $this->request->uid();
// headquarters=总部province=省公司county=区县
$headquartersList = (array)$this->repository->getIdentityList($uid);
$provinceList = (array)$this->repository->getIdentityList($uid,'province');
$countyList = (array)$this->repository->getIdentityList($uid,'county');
return app('json')->success([
'headquarters_list' => $headquartersList,
'province_list' => $provinceList,
'county_list' => $countyList,
]);
}
}

View File

@ -395,6 +395,8 @@ Route::group('api/', function () {
Route::post('apply_record', 'applyRecord');// 申请记录
Route::get('apply_info', 'applyInfo');// 申请信息
Route::get('commission_list', 'commissionList');// 佣金明细
Route::get('identity_list', 'getIdentityList');// 某个身份是否有效
})->prefix('api.Agent/');
@ -403,16 +405,9 @@ Route::group('api/', function () {
Route::post('apply', 'applyJoin');// 申请成为供应商
Route::post('apply_record', 'applyRecord');// 申请记录
Route::get('apply_info', 'applyInfo');// 申请信息详情
})->prefix('api.Supplier/');
})->middleware(UserTokenMiddleware::class, true);
//非强制登录
Route::group(function () {