diff --git a/niucloud/app/adminapi/controller/member/Config.php b/niucloud/app/adminapi/controller/member/Config.php index fdd691a3..9c3de521 100644 --- a/niucloud/app/adminapi/controller/member/Config.php +++ b/niucloud/app/adminapi/controller/member/Config.php @@ -93,7 +93,8 @@ class Config extends BaseAdminController { $data = $this->request->params([ [ 'prefix', '' ], - [ 'length', 10 ] + [ 'length', 10 ], + [ 'member_headimg', ''] ]); $this->validate($data, 'app\validate\member\MemberConfig.set'); ( new MemberConfigService() )->setMemberConfig($data); diff --git a/niucloud/app/adminapi/controller/personnel/Personnel.php b/niucloud/app/adminapi/controller/personnel/Personnel.php new file mode 100644 index 00000000..9b1f9fc9 --- /dev/null +++ b/niucloud/app/adminapi/controller/personnel/Personnel.php @@ -0,0 +1,116 @@ +request->params([ + ["name",""], + ["gender",""], + ["phone",""], + ["address",""], + ["education",""], + ["employee_number",""], + ["status",""], + ["create_time",""] + ]); + return success((new PersonnelService())->getPage($data)); + } + + /** + * 人力资源-人员详情 + * @param int $id + * @return \think\Response + */ + public function info(int $id){ + return success((new PersonnelService())->getInfo($id)); + } + + /** + * 添加人力资源-人员 + * @return \think\Response + */ + public function add(){ + $data = $this->request->params([ + ["name",""], + ["gender",0], + ["phone",""], + ["head_img",""], + ["address",""], + ["native_place",""], + ["education",""], + ["profile",""], + ["emergency_contact_phone",""], + ["id_card_front",""], + ["id_card_back",""], + ["status",0], + ["is_sys_user",0], + + ]); + $this->validate($data, 'app\validate\personnel\Personnel.add'); + $id = (new PersonnelService())->add($data); + return success('ADD_SUCCESS', ['id' => $id]); + } + + /** + * 人力资源-人员编辑 + * @param $id 人力资源-人员id + * @return \think\Response + */ + public function edit(int $id){ + $data = $this->request->params([ + ["name",""], + ["gender",0], + ["phone",""], + ["head_img",""], + ["address",""], + ["native_place",""], + ["education",""], + ["profile",""], + ["emergency_contact_phone",""], + ["id_card_front",""], + ["id_card_back",""], + ["status",0], + ["is_sys_user",0], + + ]); + $this->validate($data, 'app\validate\personnel\Personnel.edit'); + (new PersonnelService())->edit($id, $data); + return success('EDIT_SUCCESS'); + } + + /** + * 人力资源-人员删除 + * @param $id 人力资源-人员id + * @return \think\Response + */ + public function del(int $id){ + (new PersonnelService())->del($id); + return success('DELETE_SUCCESS'); + } + + +} diff --git a/niucloud/app/adminapi/route/class.php b/niucloud/app/adminapi/route/class.php index c44ddf61..a03b7b55 100644 --- a/niucloud/app/adminapi/route/class.php +++ b/niucloud/app/adminapi/route/class.php @@ -14,24 +14,26 @@ use think\facade\Route; use app\adminapi\middleware\AdminCheckRole; use app\adminapi\middleware\AdminCheckToken; use app\adminapi\middleware\AdminLog; -// USER_CODE_BEGIN -- class -Route::group('class', function () { - //班级列表 - Route::get('class', 'class.Class/lists'); - //班级详情 - Route::get('class/:id', 'class.Class/info'); - //添加班级 - Route::post('class', 'class.Class/add'); - //编辑班级 - Route::put('class/:id', 'class.Class/edit'); - //删除班级 - Route::delete('class/:id', 'class.Class/del'); +// USER_CODE_BEGIN -- campus + +Route::group('campus', function () { + + //校区列表 + Route::get('campus', 'campus.Campus/lists'); + //校区详情 + Route::get('campus/:id', 'campus.Campus/info'); + //添加校区 + Route::post('campus', 'campus.Campus/add'); + //编辑校区 + Route::put('campus/:id', 'campus.Campus/edit'); + //删除校区 + Route::delete('campus/:id', 'campus.Campus/del'); })->middleware([ AdminCheckToken::class, AdminCheckRole::class, AdminLog::class ]); -// USER_CODE_END -- class +// USER_CODE_END -- campus diff --git a/niucloud/app/adminapi/route/personnel.php b/niucloud/app/adminapi/route/personnel.php new file mode 100644 index 00000000..d1458304 --- /dev/null +++ b/niucloud/app/adminapi/route/personnel.php @@ -0,0 +1,37 @@ +middleware([ + AdminCheckToken::class, + AdminCheckRole::class, + AdminLog::class +]); +// USER_CODE_END -- personnel diff --git a/niucloud/app/api/controller/login/Login.php b/niucloud/app/api/controller/login/Login.php index ccd00e6d..a454d941 100644 --- a/niucloud/app/api/controller/login/Login.php +++ b/niucloud/app/api/controller/login/Login.php @@ -28,14 +28,14 @@ class Login extends BaseController public function login() { $data = $this->request->params([ - [ 'username', '' ], - [ 'password', '' ], + ['username', ''], + ['password', ''], ]); //校验登录注册配置 - ( new ConfigService() )->checkLoginConfig(MemberLoginTypeDict::USERNAME); + (new ConfigService())->checkLoginConfig(MemberLoginTypeDict::USERNAME); //参数验证 //验证码验证 - $result = ( new LoginService() )->account($data[ 'username' ], $data[ 'password' ]); + $result = (new LoginService())->account($data['username'], $data['password']); if (!$result) { //账号密码错误, 重置验证码 return fail('ACCOUNT_OR_PASSWORD_ERROR'); @@ -49,7 +49,7 @@ class Login extends BaseController */ public function logout() { - ( new LoginService )->logout(); + (new LoginService)->logout(); return success('MEMBER_LOGOUT'); } @@ -59,7 +59,7 @@ class Login extends BaseController */ public function captcha() { - return success(( new CaptchaService() )->create()); + return success((new CaptchaService())->create()); } /** @@ -71,9 +71,9 @@ class Login extends BaseController public function sendMobileCode($type) { $data = $this->request->params([ - [ 'mobile', '' ], + ['mobile', ''], ]); - return success(( new LoginService() )->sendMobileCode($data[ 'mobile' ], $type)); + return success((new LoginService())->sendMobileCode($data['mobile'], $type)); } /** @@ -83,14 +83,14 @@ class Login extends BaseController public function mobile() { $data = $this->request->params([ - [ 'mobile', '' ], - [ 'nickname', '' ], - [ 'headimg', '' ], - [ 'mobile', '' ] + ['mobile', ''], + ['nickname', ''], + ['headimg', ''], + ['mobile', ''] ]); //校验登录注册配置 - ( new ConfigService() )->checkLoginConfig(MemberLoginTypeDict::MOBILE); - return success(( new LoginService() )->mobile($data)); + (new ConfigService())->checkLoginConfig(MemberLoginTypeDict::MOBILE); + return success((new LoginService())->mobile($data)); } /** @@ -100,12 +100,23 @@ class Login extends BaseController public function resetPassword() { $data = $this->request->params([ - [ 'mobile', '' ], - [ 'password', '' ] + ['mobile', ''], + ['password', ''] ]); //参数验证 $this->validate($data, 'app\validate\member\Member.reset_password'); - ( new LoginService() )->resetPassword($data[ 'mobile' ], $data[ 'password' ]); + (new LoginService())->resetPassword($data['mobile'], $data['password']); return success('PASSWORD_RESET_SUCCESS'); } + + public function personnelLogin() + { + $data = $this->request->params([ + ['phone', ''], + ['password', ''], + ]); + //验证码验证 + $result = (new LoginService())->loginByPersonnel($data); + return success($result); + } } diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index bbbbccb8..217081ae 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -74,6 +74,9 @@ Route::group(function() { //登录 Route::get('login', 'login.Login/login'); + //员工登录 + Route::post('personnelLogin', 'login.Login/personnelLogin'); + //第三方绑定 Route::post('bind', BindDispatch::class); //密码重置 diff --git a/niucloud/app/dict/sys/AppTypeDict.php b/niucloud/app/dict/sys/AppTypeDict.php index 0b45e1ae..14f81390 100644 --- a/niucloud/app/dict/sys/AppTypeDict.php +++ b/niucloud/app/dict/sys/AppTypeDict.php @@ -18,6 +18,8 @@ class AppTypeDict public const API = 'api';//手机网页端 + public const PERSONNEL = 'personnel';//员工端 + /** * 附件类型 * @return array @@ -27,6 +29,7 @@ class AppTypeDict return [ self::ADMIN => get_lang('dict_app.type_admin'),//平台管理端 self::API => get_lang('dict_app.type_api'),//客户端 + self::PERSONNEL => get_lang('dict_app.type_personnel'),//员工端 ]; } diff --git a/niucloud/app/model/attendance/Attendance.php b/niucloud/app/model/attendance/Attendance.php index 53e9425e..0f5e48e3 100644 --- a/niucloud/app/model/attendance/Attendance.php +++ b/niucloud/app/model/attendance/Attendance.php @@ -9,7 +9,7 @@ // | Author: Niucloud Team // +---------------------------------------------------------------------- -namespace app\model\attendance; +namespace app\model\campus; use core\base\BaseModel; use think\model\concern\SoftDelete; @@ -17,14 +17,14 @@ use think\model\relation\HasMany; use think\model\relation\HasOne; /** - * 考勤模型 - * Class Attendance - * @package app\model\attendance + * 校区模型 + * Class Campus + * @package app\model\campus */ -class Attendance extends BaseModel +class Campus extends BaseModel { - + use SoftDelete; /** * 数据表主键 @@ -36,141 +36,53 @@ class Attendance extends BaseModel * 模型名称 * @var string */ - protected $name = 'attendance'; - - - - + protected $name = 'campus'; /** - * 搜索器:考勤考勤编号 - * @param $value - * @param $data - */ - public function searchIdAttr($query, $value, $data) - { - if ($value) { - $query->where("id", $value); - } - } - - /** - * 搜索器:考勤校区ID - * @param $value - * @param $data - */ - public function searchCampusIdAttr($query, $value, $data) - { - if ($value) { - $query->where("campus_id", $value); - } - } - - /** - * 搜索器:考勤人员ID - * @param $value - * @param $data - */ - public function searchStaffIdAttr($query, $value, $data) - { - if ($value) { - $query->where("staff_id", $value); - } - } - - /** - * 搜索器:考勤考勤日期 - * @param $value - * @param $data - */ - public function searchAttendanceDateAttr($query, $value, $data) - { - if ($value) { - $query->where("attendance_date", $value); - } - } - - /** - * 搜索器:考勤签到时间 - * @param $value - * @param $data - */ - public function searchCheckInTimeAttr($query, $value, $data) - { - if ($value) { - $query->where("check_in_time", $value); - } - } - - /** - * 搜索器:考勤签退时间 - * @param $value - * @param $data - */ - public function searchCheckOutTimeAttr($query, $value, $data) - { - if ($value) { - $query->where("check_out_time", $value); - } - } - - /** - * 搜索器:考勤考勤状态 - * @param $value - * @param $data - */ - public function searchStatusAttr($query, $value, $data) - { - if ($value) { - $query->where("status", $value); - } - } - + * 定义软删除标记字段. + * @var string + */ + protected $deleteTime = 'delete_time'; + /** - * 搜索器:考勤备注 - * @param $value - * @param $data - */ - public function searchRemarksAttr($query, $value, $data) - { - if ($value) { - $query->where("remarks", $value); - } - } - + * 定义软删除字段的默认值. + * @var int + */ + protected $defaultSoftDelete = 0; + /** - * 搜索器:考勤创建时间 + * 搜索器:校区校区名称 * @param $value * @param $data */ - public function searchCreatedAtAttr($query, $value, $data) + public function searchCampusNameAttr($query, $value, $data) { if ($value) { - $query->where("created_at", $value); + $query->where("campus_name", "like", "%".$value."%"); } } /** - * 搜索器:考勤修改时间 + * 搜索器:校区校区地址 * @param $value * @param $data */ - public function searchUpdatedAtAttr($query, $value, $data) + public function searchCampusAddressAttr($query, $value, $data) { if ($value) { - $query->where("updated_at", $value); + $query->where("campus_address", $value); } } /** - * 搜索器:考勤坐标 + * 搜索器:校区校区状态 * @param $value * @param $data */ - public function searchCoordinateAttr($query, $value, $data) + public function searchCampusStatusAttr($query, $value, $data) { if ($value) { - $query->where("coordinate", $value); + $query->where("campus_status", $value); } } diff --git a/niucloud/app/model/personnel/Personnel.php b/niucloud/app/model/personnel/Personnel.php new file mode 100644 index 00000000..d7ae5c60 --- /dev/null +++ b/niucloud/app/model/personnel/Personnel.php @@ -0,0 +1,159 @@ +where("name", "like", "%".$value."%"); + } + } + + /** + * 搜索器:人力资源-人员性别 + * @param $value + * @param $data + */ + public function searchGenderAttr($query, $value, $data) + { + if ($value) { + $query->where("gender", $value); + } + } + + /** + * 搜索器:人力资源-人员电话 + * @param $value + * @param $data + */ + public function searchPhoneAttr($query, $value, $data) + { + if ($value) { + $query->where("phone", $value); + } + } + + /** + * 搜索器:人力资源-人员家庭住址 + * @param $value + * @param $data + */ + public function searchAddressAttr($query, $value, $data) + { + if ($value) { + $query->where("address", $value); + } + } + + /** + * 搜索器:人力资源-人员学历 + * @param $value + * @param $data + */ + public function searchEducationAttr($query, $value, $data) + { + if ($value) { + $query->where("education", $value); + } + } + + /** + * 搜索器:人力资源-人员员工编号 + * @param $value + * @param $data + */ + public function searchEmployeeNumberAttr($query, $value, $data) + { + if ($value) { + $query->where("employee_number", $value); + } + } + + /** + * 搜索器:人力资源-人员员工状态 + * @param $value + * @param $data + */ + public function searchStatusAttr($query, $value, $data) + { + if ($value) { + $query->where("status", $value); + } + } + + /** + * 搜索器:人力资源-人员创建时间 + * @param $value + * @param $data + */ + public function searchCreateTimeAttr($query, $value, $data) + { + if ($value) { + $query->where("create_time", $value); + } + } + + + + public function sys_user() + { + return $this->hasOne(\app\model\sys\SysUser::class, 'uid', 'sys_user_id'); + } + + + + +} diff --git a/niucloud/app/service/admin/personnel/PersonnelService.php b/niucloud/app/service/admin/personnel/PersonnelService.php new file mode 100644 index 00000000..3ec8d320 --- /dev/null +++ b/niucloud/app/service/admin/personnel/PersonnelService.php @@ -0,0 +1,151 @@ +model = new Personnel(); + } + + /** + * 获取人力资源-人员列表 + * @param array $where + * @return array + */ + public function getPage(array $where = []) + { + $field = 'id,name,head_img,gender,birthday,phone,address,native_place,education,profile,emergency_contact_phone,id_card_front,id_card_back,employee_number,status,is_sys_user,sys_user_id,create_time,update_time,delete_time'; + $order = 'create_time desc'; + + $search_model = $this->model->withSearch(["name", "gender", "phone", "address", "education", "employee_number", "status", "create_time"], $where)->field($field)->order($order); + $list = $this->pageQuery($search_model); + return $list; + } + + /** + * 获取人力资源-人员信息 + * @param int $id + * @return array + */ + public function getInfo(int $id) + { + $field = 'id,name,gender,head_img,birthday,phone,address,native_place,education,profile,emergency_contact_phone,id_card_front,id_card_back,employee_number,status,is_sys_user,sys_user_id,create_time,update_time,delete_time'; + + $info = $this->model->field($field)->where([['id', "=", $id]])->findOrEmpty()->toArray(); + $info['gender'] = strval($info['gender']); + $info['status'] = strval($info['status']); + $info['is_sys_user'] = strval($info['is_sys_user']); + return $info; + } + + /** + * 添加人力资源-人员 + * @param array $data + * @return mixed + */ + public function add(array $data) + { + $status = $this->model->where('phone', $data['phone'])->value('id'); + if ($status) { + throw new \Exception('手机号已存在'); + } + try { + Db::startTrans(); + if ($data['is_sys_user'] === '1') { + $uid = (new UserService())->addUser([ + 'username' => $data['phone'], + 'password' => $data['phone'], + 'real_name' => $data['name'], + 'head_img' => $data['head_img'], + 'status' => UserDict::ON, + 'role_ids' => [] + ]); + $data['sys_user_id'] = $uid; + } + $res = $this->model->create($data); + Db::commit(); + return $res->id; + } catch (\Exception $e) { + Db::rollback(); + throw new \Exception($e->getMessage()); + } + } + + /** + * 人力资源-人员编辑 + * @param int $id + * @param array $data + * @return bool + */ + public function edit(int $id, array $data) + { + + $status = $this->model->where('phone', $data['phone'])->value('id'); + if ($status && $status != $id) { + throw new \Exception('手机号已存在'); + } + try { + Db::startTrans(); + if ($data['is_sys_user'] === '1') { + $uid = (new SysUser())->where(['username' => $data['phone']])->value('uid'); + if (!$uid) { + $uid = (new UserService())->addUser([ + 'username' => $data['phone'], + 'password' => $data['phone'], + 'real_name' => $data['name'], + 'head_img' => $data['head_img'], + 'status' => UserDict::ON, + 'role_ids' => [] + ]); + $data['sys_user_id'] = $uid; + } + } + $this->model->where([['id', '=', $id]])->update($data); + Db::commit(); + } catch (\Exception $e) { + Db::rollback(); + throw new \Exception($e->getMessage()); + } + return true; + } + + /** + * 删除人力资源-人员 + * @param int $id + * @return bool + */ + public function del(int $id) + { + $model = $this->model->where([['id', '=', $id]])->find(); + $res = $model->delete(); + return $res; + } + + +} diff --git a/niucloud/app/service/admin/student_courses/StudentCoursesService.php b/niucloud/app/service/admin/student_courses/StudentCoursesService.php index 1ff88ead..2d67b47f 100644 --- a/niucloud/app/service/admin/student_courses/StudentCoursesService.php +++ b/niucloud/app/service/admin/student_courses/StudentCoursesService.php @@ -9,56 +9,57 @@ // | Author: Niucloud Team // +---------------------------------------------------------------------- -namespace app\service\admin\student_courses; +namespace app\service\admin\campus; -use app\model\student_courses\StudentCourses; +use app\model\campus\Campus; use core\base\BaseAdminService; /** - * 学员课程服务层 - * Class StudentCoursesService - * @package app\service\admin\student_courses + * 校区服务层 + * Class CampusService + * @package app\service\admin\campus */ -class StudentCoursesService extends BaseAdminService +class CampusService extends BaseAdminService { public function __construct() { parent::__construct(); - $this->model = new StudentCourses(); + $this->model = new Campus(); } /** - * 获取学员课程列表 + * 获取校区列表 * @param array $where * @return array */ public function getPage(array $where = []) { - $field = 'id,student_id,course_id,total_hours,gift_hours,start_date,end_date,created_at,updated_at'; - $order = 'id desc'; + $field = 'id,campus_name,campus_address,campus_preview_image,campus_coordinates,campus_introduction,campus_status,create_time,update_time,delete_time'; + $order = ''; - $search_model = $this->model->withSearch(["id","student_id","course_id","total_hours","gift_hours","start_date","end_date"], $where)->field($field)->order($order); + $search_model = $this->model->withSearch(["campus_name","campus_address","campus_status"], $where)->field($field)->order($order); $list = $this->pageQuery($search_model); return $list; } /** - * 获取学员课程信息 + * 获取校区信息 * @param int $id * @return array */ public function getInfo(int $id) { - $field = 'id,student_id,course_id,total_hours,gift_hours,start_date,end_date,created_at,updated_at'; + $field = 'id,campus_name,campus_address,campus_preview_image,campus_coordinates,campus_introduction,campus_status,create_time,update_time,delete_time'; $info = $this->model->field($field)->where([['id', "=", $id]])->findOrEmpty()->toArray(); + $info['campus_status'] = strval($info['campus_status']); return $info; } /** - * 添加学员课程 + * 添加校区 * @param array $data * @return mixed */ @@ -70,7 +71,7 @@ class StudentCoursesService extends BaseAdminService } /** - * 学员课程编辑 + * 校区编辑 * @param int $id * @param array $data * @return bool @@ -83,7 +84,7 @@ class StudentCoursesService extends BaseAdminService } /** - * 删除学员课程 + * 删除校区 * @param int $id * @return bool */ diff --git a/niucloud/app/service/api/login/LoginService.php b/niucloud/app/service/api/login/LoginService.php index 450c2247..b556f2a0 100644 --- a/niucloud/app/service/api/login/LoginService.php +++ b/niucloud/app/service/api/login/LoginService.php @@ -16,6 +16,8 @@ use app\dict\member\MemberRegisterTypeDict; use app\dict\sys\AppTypeDict; use app\dict\sys\SmsDict; use app\model\member\Member; +use app\model\personnel\Personnel; +use app\model\sys\SysUser; use app\service\api\captcha\CaptchaService; use app\service\api\member\MemberConfigService; use app\service\api\member\MemberService; @@ -75,8 +77,8 @@ class LoginService extends BaseApiService $token_info = $this->createToken($member_info); event("MemberLogin", $member_info); return [ - 'token' => $token_info[ 'token' ], - 'expires_time' => $token_info[ 'params' ][ 'exp' ], + 'token' => $token_info['token'], + 'expires_time' => $token_info['params']['exp'], 'mobile' => $member_info->mobile ]; } @@ -90,7 +92,7 @@ class LoginService extends BaseApiService public function account(string $username, string $password) { $member_service = new MemberService(); - $member_info = $member_service->findMemberInfo([ 'username|mobile' => $username ]); + $member_info = $member_service->findMemberInfo(['username|mobile' => $username]); if ($member_info->isEmpty()) throw new AuthException('MEMBER_NOT_EXIST');//账号不存在 if (!check_password($password, $member_info->password)) return false;//密码与账号不匹配 return $this->login($member_info, MemberLoginTypeDict::USERNAME); @@ -104,23 +106,23 @@ class LoginService extends BaseApiService public function mobile($params) { //校验手机验证码 - $this->checkMobileCode($params[ 'mobile' ]); + $this->checkMobileCode($params['mobile']); //登录注册配置 - $config = ( new MemberConfigService() )->getLoginConfig(); - $is_mobile = $config[ 'is_mobile' ]; - $is_bind_mobile = $config[ 'is_bind_mobile' ]; + $config = (new MemberConfigService())->getLoginConfig(); + $is_mobile = $config['is_mobile']; + $is_bind_mobile = $config['is_bind_mobile']; if ($is_mobile != 1 && $is_bind_mobile != 1) throw new AuthException('MOBILE_LOGIN_UNOPENED'); $member_service = new MemberService(); - $member_info = $member_service->findMemberInfo([ 'mobile' => $params[ 'mobile' ] ]); + $member_info = $member_service->findMemberInfo(['mobile' => $params['mobile']]); if ($member_info->isEmpty()) { //开启强制绑定手机号,登录会自动注册并绑定手机号 if ($is_bind_mobile == 1) { $data = array( - 'mobile' => $params[ 'mobile' ], - 'nickname' => $params[ 'nickname' ], - 'headimg' => $params[ 'headimg' ] + 'mobile' => $params['mobile'], + 'nickname' => $params['nickname'], + 'headimg' => $params['headimg'] ); - return ( new RegisterService() )->register($params[ 'mobile' ], $data, MemberRegisterTypeDict::MOBILE, false); + return (new RegisterService())->register($params['mobile'], $data, MemberRegisterTypeDict::MOBILE, false); } else { throw new AuthException('MEMBER_NOT_EXIST');//账号不存在 } @@ -133,16 +135,16 @@ class LoginService extends BaseApiService * @param $member_info * @return array|null */ - public function createToken($member_info) : ?array + public function createToken($member_info): ?array { $expire_time = env('system.api_token_expire_time') ?? 3600;//todo 不一定和管理端合用这个token时限 - return TokenAuth::createToken($member_info->member_id, AppTypeDict::API, [ 'member_id' => $member_info->member_id, 'username' => $member_info->username ], $expire_time); + return TokenAuth::createToken($member_info->member_id, AppTypeDict::API, ['member_id' => $member_info->member_id, 'username' => $member_info->username], $expire_time); } /** * 登陆退出(当前账户) */ - public function logout() : ?bool + public function logout(): ?bool { self::clearToken($this->member_id, $this->request->apiToken()); return true; @@ -154,7 +156,7 @@ class LoginService extends BaseApiService * @param string|null $token * @return bool|null */ - public static function clearToken(int $member_id, ?string $token = '') : ?bool + public static function clearToken(int $member_id, ?string $token = ''): ?bool { TokenAuth::clearToken($member_id, AppTypeDict::API, $token); return true; @@ -197,18 +199,18 @@ class LoginService extends BaseApiService */ public function sendMobileCode($mobile, string $type = '') { - ( new CaptchaService() )->check(); + (new CaptchaService())->check(); if (empty($mobile)) throw new AuthException('MOBILE_NEEDED'); //发送 if (!in_array($type, SmsDict::SCENE_TYPE)) throw new AuthException('MEMBER_MOBILE_CAPTCHA_ERROR'); $code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT);// 生成4位随机数,左侧补0 - ( new NoticeService() )->send('member_verify_code', [ 'code' => $code, 'mobile' => $mobile ]); + (new NoticeService())->send('member_verify_code', ['code' => $code, 'mobile' => $mobile]); //将验证码存入缓存 $key = md5(uniqid('', true)); $cache_tag_name = "mobile_key" . $mobile . $type; $this->clearMobileCode($mobile, $type); - Cache::tag($cache_tag_name)->set($key, [ 'mobile' => $mobile, 'code' => $code, 'type' => $type ], 600); - return [ 'key' => $key ]; + Cache::tag($cache_tag_name)->set($key, ['mobile' => $mobile, 'code' => $code, 'type' => $type], 600); + return ['key' => $key]; } public function getMobileCodeCacheName() @@ -235,9 +237,9 @@ class LoginService extends BaseApiService if (empty($mobile_key) || empty($mobile_code)) throw new AuthException('MOBILE_CAPTCHA_ERROR'); $cache = Cache::get($mobile_key); if (empty($cache)) throw new AuthException('MOBILE_CAPTCHA_ERROR'); - $temp_mobile = $cache[ 'mobile' ]; - $temp_code = $cache[ 'code' ]; - $temp_type = $cache[ 'type' ]; + $temp_mobile = $cache['mobile']; + $temp_code = $cache['code']; + $temp_type = $cache['type']; if ($temp_mobile != $mobile || $temp_code != $mobile_code) throw new AuthException('MOBILE_CAPTCHA_ERROR'); $this->clearMobileCode($temp_mobile, $temp_type); return true; @@ -255,8 +257,8 @@ class LoginService extends BaseApiService if (!empty($open_id)) { Log::write('channel_1' . $this->channel); if (!empty($this->channel)) { - $openid_field = match($this->channel){ - 'wechat' => 'wx_openid', + $openid_field = match ($this->channel) { + 'wechat' => 'wx_openid', 'weapp' => 'weapp_openid', default => '' }; @@ -291,7 +293,7 @@ class LoginService extends BaseApiService $member_service = new MemberService(); //校验手机验证码 $this->checkMobileCode($mobile); - $member_info = $member_service->findMemberInfo([ 'mobile' => $mobile ]); + $member_info = $member_service->findMemberInfo(['mobile' => $mobile]); if ($member_info->isEmpty()) throw new AuthException('MOBILE_NOT_EXIST_MEMBER');//账号不存在 //todo 需要考虑一下,新的密码和原密码一样能否通过验证 $password_hash = create_password($password); @@ -299,7 +301,7 @@ class LoginService extends BaseApiService 'password' => $password_hash, ); $member_service->editByFind($member_info, $data); - self::clearToken($member_info[ 'member_id' ], $this->request->apiToken()); + self::clearToken($member_info['member_id'], $this->request->apiToken()); return true; } @@ -318,4 +320,25 @@ class LoginService extends BaseApiService } + public function loginByPersonnel($params) + { + $member_info = (new Personnel())->where('phone', $params['phone'])->find(); + + if ($member_info->status != 2) throw new ApiException('账号状态异常禁止登录'); + $user = (new SysUser())->where('username', $params['phone'])->find(); + if (!check_password($params['password'], $user->password)) throw new ApiException('账号或密码错误'); + $user->login_time = time(); + $user->last_ip = $this->request->ip(); + $user->login_type = 'mini'; + $user->login_count++; + $user->last_time = time(); + $user->save(); + $expire_time = env('system.api_token_expire_time') ?? 3600; + $token_info = TokenAuth::createToken($member_info->id, AppTypeDict::PERSONNEL, ['id' => $member_info->id, 'phone' => $member_info->phone], $expire_time);; + event("PersonnelLogin", $member_info); + return [ + 'token' => $token_info['token'], + 'expires_time' => $token_info['params']['exp'] + ]; + } } diff --git a/niucloud/app/service/core/member/CoreMemberConfigService.php b/niucloud/app/service/core/member/CoreMemberConfigService.php index 39bfaba3..5d8f9cff 100644 --- a/niucloud/app/service/core/member/CoreMemberConfigService.php +++ b/niucloud/app/service/core/member/CoreMemberConfigService.php @@ -72,6 +72,7 @@ class CoreMemberConfigService extends BaseCoreService { $info = ( new CoreConfigService() )->getConfig('MEMBER')[ 'value' ] ?? []; return [ + 'member_headimg' => $info[ 'member_headimg' ] ?? '',// 会员默认头像 'prefix' => $info[ 'prefix' ] ?? '',// 会员编码前缀 'length' => $info[ 'length' ] ?? 4, // 会员编码长度 ]; @@ -85,6 +86,7 @@ class CoreMemberConfigService extends BaseCoreService public function setMemberConfig(array $data) { $config = [ + 'member_headimg' => $data[ 'member_headimg' ] ?? '',// 会员默认头像 'prefix' => $data[ 'prefix' ] ?? '',// 会员编码前缀 'length' => $data[ 'length' ] ?? 4,// 会员编码长度 ]; @@ -174,4 +176,33 @@ class CoreMemberConfigService extends BaseCoreService } + /** + * 获取员工设置 + * @return array + */ + public function getPersonnelConfig() + { + $info = ( new CoreConfigService() )->getConfig('Personnel')[ 'value' ] ?? []; + return [ + 'head_img' => $info[ 'head_img' ] ?? '',// 员工默认头像 + 'prefix' => $info[ 'prefix' ] ?? '',// 员工编码前缀 + 'length' => $info[ 'length' ] ?? 4, // 员工编码长度 + ]; + } + + /** + * 员工设置 + * @param array $data + * @return true + */ + public function setPersonnelConfig(array $data) + { + $config = [ + 'head_img' => $info[ 'head_img' ] ?? '',// 会员默认头像 + 'prefix' => $data[ 'prefix' ] ?? '',// 会员编码前缀 + 'length' => $data[ 'length' ] ?? 4,// 会员编码长度 + ]; + ( new CoreConfigService() )->setConfig('Personnel', $config); + return true; + } } diff --git a/niucloud/app/validate/personnel/Personnel.php b/niucloud/app/validate/personnel/Personnel.php new file mode 100644 index 00000000..401c40b9 --- /dev/null +++ b/niucloud/app/validate/personnel/Personnel.php @@ -0,0 +1,44 @@ + 'require', + 'phone' => 'require|mobile', + 'emergency_contact_phone' => 'mobile', + 'status' => 'require', + 'is_sys_user' => 'require', + ]; + + protected $message = [ + 'name.require' => ['common_validate.require', ['name']], + 'phone.require' => ['common_validate.require', ['phone']], + 'phone.mobile' => ['common_validate.mobile', ['phone']], + 'emergency_contact_phone.mobile' => ['common_validate.mobile', ['emergency_contact_phone']], + 'status.require' => ['common_validate.require', ['status']], + 'is_sys_user.require' => ['common_validate.require', ['is_sys_user']], + ]; + + protected $scene = [ + "add" => ['name', 'gender', 'phone', 'address', 'native_place', 'education', 'profile', 'emergency_contact_phone', 'id_card_front', 'id_card_back', 'status', 'is_sys_user'], + "edit" => ['name', 'gender', 'phone', 'address', 'native_place', 'education', 'profile', 'emergency_contact_phone', 'id_card_front', 'id_card_back', 'status', 'is_sys_user'] + ]; + +} diff --git a/niucloud/app/validate/resource_sharing/ResourceSharing.php b/niucloud/app/validate/resource_sharing/ResourceSharing.php index 180c9f42..33316c20 100644 --- a/niucloud/app/validate/resource_sharing/ResourceSharing.php +++ b/niucloud/app/validate/resource_sharing/ResourceSharing.php @@ -9,29 +9,27 @@ // | Author: Niucloud Team // +---------------------------------------------------------------------- -namespace app\validate\resource_sharing; +namespace app\validate\campus; use core\base\BaseValidate; /** - * 资源共享验证器 - * Class ResourceSharing - * @package addon\app\validate\resource_sharing + * 校区验证器 + * Class Campus + * @package addon\app\validate\campus */ -class ResourceSharing extends BaseValidate +class Campus extends BaseValidate { protected $rule = [ - 'resource_id' => 'require', - 'shared_by' => 'require', + 'campus_name' => 'require', ]; protected $message = [ - 'resource_id.require' => ['common_validate.require', ['resource_id']], - 'shared_by.require' => ['common_validate.require', ['shared_by']], + 'campus_name.require' => ['common_validate.require', ['campus_name']], ]; protected $scene = [ - "add" => ['resource_id', 'user_id', 'role_id', 'shared_by', 'shared_at'], - "edit" => ['resource_id', 'user_id', 'role_id', 'shared_by', 'shared_at'] + "add" => ['campus_name', 'campus_address', 'campus_preview_image', 'campus_coordinates', 'campus_introduction', 'campus_status'], + "edit" => ['campus_name', 'campus_address', 'campus_preview_image', 'campus_coordinates', 'campus_introduction', 'campus_status'] ]; }