7 changed files with 441 additions and 7 deletions
@ -0,0 +1,155 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|||
// +---------------------------------------------------------------------- |
|||
// | 官方网址:https://www.niucloud.com |
|||
// +---------------------------------------------------------------------- |
|||
// | niucloud团队 版权所有 开源版本可自由商用 |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: Niucloud Team |
|||
// +---------------------------------------------------------------------- |
|||
|
|||
namespace app\api\controller\apiController; |
|||
|
|||
use app\dict\member\MemberLoginTypeDict; |
|||
use app\Request; |
|||
use app\service\api\apiService\PersonnelService; |
|||
use app\service\api\captcha\CaptchaService; |
|||
use app\service\api\login\ConfigService; |
|||
use app\service\api\login\LoginService; |
|||
use core\base\BaseApiService; |
|||
use Exception; |
|||
use think\Response; |
|||
|
|||
/** |
|||
* 员工端相关接口 |
|||
* Class Personnel |
|||
* @package app\api\controller\apiController |
|||
*/ |
|||
class Personnel extends BaseApiService |
|||
{ |
|||
|
|||
//员工详情 |
|||
public function info(Request $request){ |
|||
//获取员工信息 |
|||
$where = [ |
|||
'id'=>$this->member_id, |
|||
]; |
|||
$res = (new PersonnelService())->info($where); |
|||
if(!$res){ |
|||
return fail('账户信息有误'); |
|||
} |
|||
return success($result); |
|||
} |
|||
|
|||
/** |
|||
* 登录 |
|||
* @return Response |
|||
*/ |
|||
public function login() |
|||
{ |
|||
$data = $this->request->params([ |
|||
['username', ''], |
|||
['password', ''], |
|||
]); |
|||
//校验登录注册配置 |
|||
(new ConfigService())->checkLoginConfig(MemberLoginTypeDict::USERNAME); |
|||
//参数验证 |
|||
//验证码验证 |
|||
$result = (new LoginService())->account($data['username'], $data['password']); |
|||
if (!$result) { |
|||
//账号密码错误, 重置验证码 |
|||
return fail('ACCOUNT_OR_PASSWORD_ERROR'); |
|||
} |
|||
return success($result); |
|||
} |
|||
|
|||
/** |
|||
* 登出 |
|||
* @return Response |
|||
*/ |
|||
public function logout() |
|||
{ |
|||
(new LoginService)->logout(); |
|||
return success('MEMBER_LOGOUT'); |
|||
} |
|||
|
|||
/** |
|||
* 创建验证码 |
|||
* @return Response |
|||
*/ |
|||
public function captcha() |
|||
{ |
|||
return success((new CaptchaService())->create()); |
|||
} |
|||
|
|||
/** |
|||
* 发送手机验证码 |
|||
* @param $type |
|||
* @return Response |
|||
* @throws Exception |
|||
*/ |
|||
public function sendMobileCode($type) |
|||
{ |
|||
$data = $this->request->params([ |
|||
['mobile', ''], |
|||
]); |
|||
return success((new LoginService())->sendMobileCode($data['mobile'], $type)); |
|||
} |
|||
|
|||
/** |
|||
* 手机号登录 |
|||
* @return Response |
|||
*/ |
|||
public function mobile() |
|||
{ |
|||
$data = $this->request->params([ |
|||
['mobile', ''], |
|||
['nickname', ''], |
|||
['headimg', ''], |
|||
['mobile', ''] |
|||
]); |
|||
//校验登录注册配置 |
|||
(new ConfigService())->checkLoginConfig(MemberLoginTypeDict::MOBILE); |
|||
return success((new LoginService())->mobile($data)); |
|||
} |
|||
|
|||
/** |
|||
* 重置密码 |
|||
* @return Response |
|||
*/ |
|||
public function resetPassword() |
|||
{ |
|||
$data = $this->request->params([ |
|||
['mobile', ''], |
|||
['password', ''] |
|||
]); |
|||
//参数验证 |
|||
$this->validate($data, 'app\validate\member\Member.reset_password'); |
|||
(new LoginService())->resetPassword($data['mobile'], $data['password']); |
|||
return success('PASSWORD_RESET_SUCCESS'); |
|||
} |
|||
|
|||
//销售教师人员登陆 |
|||
public function personnelLogin() |
|||
{ |
|||
$data = $this->request->params([ |
|||
['phone', ''], |
|||
['password', ''], |
|||
['login_type', ''],//登陆类型|1=教练,2=销售 |
|||
]); |
|||
//验证码验证 |
|||
$result = (new LoginService())->loginByPersonnel($data); |
|||
|
|||
if(!$result['user_type']){ |
|||
if($data['login_type'] == 1){ |
|||
$msg = '暂无教练权限'; |
|||
}else{ |
|||
$msg = '暂无销售权限'; |
|||
} |
|||
return fail($msg);//code|0错误 |
|||
} |
|||
|
|||
return success($result);//code|1正确 |
|||
} |
|||
} |
|||
@ -0,0 +1,58 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|||
// +---------------------------------------------------------------------- |
|||
// | 官方网址:https://www.niucloud.com |
|||
// +---------------------------------------------------------------------- |
|||
// | niucloud团队 版权所有 开源版本可自由商用 |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: Niucloud Team |
|||
// +---------------------------------------------------------------------- |
|||
|
|||
namespace app\api\middleware; |
|||
|
|||
use app\dict\sys\AppTypeDict; |
|||
use app\Request; |
|||
use app\service\api\login\AuthService; |
|||
use app\service\api\login\LoginService; |
|||
use Closure; |
|||
use Exception; |
|||
use core\exception\AuthException; |
|||
|
|||
|
|||
/** |
|||
* 员工端登录token验证 |
|||
* Class ApiCheckToken |
|||
* @package app\api\middleware |
|||
*/ |
|||
class ApiPersonnelCheckToken |
|||
{ |
|||
/** |
|||
* @param Request $request |
|||
* @param Closure $next |
|||
* @param bool $is_throw_exception 是否把错误抛出 |
|||
* @return mixed |
|||
* @throws Exception |
|||
*/ |
|||
public function handle(Request $request, Closure $next, bool $is_throw_exception = false) |
|||
{ |
|||
$request->appType(AppTypeDict::PERSONNEL); |
|||
// 校验渠道 |
|||
( new AuthService() )->checkChannel($request); |
|||
//通过配置来设置系统header参数 |
|||
try { |
|||
$token = $request->apiToken(); |
|||
$token_info = ( new LoginService() )->parsePersonnelToken($token); |
|||
if (!empty($token_info)) { |
|||
$request->memberId($token_info[ 'member_id' ]); |
|||
} |
|||
//校验会员和站点 |
|||
$a= ( new AuthService() )->checkPersonnelMember($request); |
|||
} catch (AuthException $e) { |
|||
//是否将登录错误抛出 |
|||
if ($is_throw_exception) |
|||
return fail($e->getMessage(), [], $e->getCode()); |
|||
} |
|||
return $next($request); |
|||
} |
|||
} |
|||
@ -0,0 +1,91 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|||
// +---------------------------------------------------------------------- |
|||
// | 官方网址:https://www.niucloud.com |
|||
// +---------------------------------------------------------------------- |
|||
// | niucloud团队 版权所有 开源版本可自由商用 |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: Niucloud Team |
|||
// +---------------------------------------------------------------------- |
|||
|
|||
namespace app\service\api\apiService; |
|||
|
|||
use app\model\campus_person_role\CampusPersonRole; |
|||
use app\model\member\Member; |
|||
use app\model\personnel\Personnel; |
|||
use app\service\core\member\CoreMemberService; |
|||
use core\base\BaseApiService; |
|||
use core\exception\ApiException; |
|||
use core\util\Barcode; |
|||
use think\Model; |
|||
|
|||
/** |
|||
* 员工服务层 |
|||
* Class MemberService |
|||
* @package app\service\api\member |
|||
*/ |
|||
class PersonnelService extends BaseApiService |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
$this->model = new Personnel(); |
|||
} |
|||
|
|||
//获取员工信息 |
|||
public function info(array $where,string $field = '*'){ |
|||
$model = $this->model; |
|||
if(!empty($where['id'])){ |
|||
$model = $model->where('id',$where['id']); |
|||
} |
|||
$res = $model->field($field)->find();//员工信息 |
|||
|
|||
//查询部门信息 |
|||
$campus_person_role = CampusPersonRole::where('person_id',$where['id'])->select()->toArray(); |
|||
$role_id = array_column($campus_person_role, 'role_id'); |
|||
$dept_id = array_column($campus_person_role, 'dept_id'); |
|||
|
|||
|
|||
if($res){ |
|||
$res = $res->toArray(); |
|||
}else{ |
|||
$res = []; |
|||
return $res; |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取会员的模型对象(todo 慎用!!! 现主要用于登录) |
|||
* @param array $data |
|||
* @return Member|array|mixed|Model !!! 仔细看,返回值是模型对象 如果想要判断是否为空 请用 $member->isEmpty() |
|||
*/ |
|||
public function findMemberInfo(array $data){ |
|||
//会员账号 |
|||
if(!empty($data['username'])) |
|||
$where[] = ['username', '=', $data['username']]; |
|||
//会员手机号 |
|||
if(!empty($data['mobile'])) |
|||
$where[] = ['mobile', '=', $data['mobile']]; |
|||
//会员id |
|||
if(!empty($data['id'])) |
|||
$where[] = ['id', '=', $data['id']]; |
|||
//微信公众号openid |
|||
if(!empty($data['wx_openid'])) |
|||
$where[] = ['wx_openid', '=', $data['wx_openid']]; |
|||
//微信小程序openid |
|||
if(!empty($data['weapp_openid'])) |
|||
$where[] = ['weapp_openid', '=', $data['weapp_openid']]; |
|||
// 微信unionid |
|||
if(!empty($data['wx_unionid'])) |
|||
$where[] = ['wx_unionid', '=', $data['wx_unionid']]; |
|||
if(!empty($data['username|mobile'])) |
|||
$where[] = ['username|mobile', '=', $data['username|mobile']]; |
|||
if(empty($where)){ |
|||
$where[] = ['member_id', '=', -1]; |
|||
} |
|||
return $this->model->where($where)->findOrEmpty(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue