123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Exception;
- use think\Model;
- class User extends Model
- {
- public $sex = [
- "未知",
- "男",
- "女"
- ];
- protected function setPasswordAttr($value){
- if(trim($value)){
- return password_hash($value, PASSWORD_DEFAULT);
- }
- return '';
- }
- public function addUser(){
- $data = [
- 'id' => input('id/d',0),
- 'account' => input('account','','trim'),
- 'real_name' => input('real_name','','trim'),
- 'mobile' => input('mobile','','trim'),
- 'password' => input('password','','trim'),
- 'depId' => input('depId/d',0),
- 'rolesId' => input('rolesId/d',0),
- 'enable' => input('enable/d',1),
- 'addr_id' => input('addr_id/d',0),
- 'sort'=>input('sort',0,'trim'),
- 'type_id' => input('type_id/d', 0),
- 'sex' => input('sex/d', 0),
- ];
- $orgId = cur_org_id();
- $result = validate('User')->check($data,[],'add');
- if(true !== $result){
- $this->error = validate('User')->getError();
- return false;
- }
- Db::startTrans();
- try{
- $id = $data['id'];
- unset($data['id']);
- $depId = $data['depId'];
- $rolesId = $data['rolesId'];
- unset($data['depId']);
- unset($data['rolesId']);
- $role = Db::name('roles')
- ->where('id',$rolesId)
- ->find();
- if($rolesId!=7 && $role['parent_id']!=7){
- unset($data['type_id']);
- }
- if($id > 0){
- if(!$data['password']){
- unset($data['password']);
- }
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- if(!$ret){
- \exception('操作失败');
- }
- $ud = Db::name('user_dep')->where('user_id',$id)->find();
- if(!$ud){
- Db::name('user_dep')->insert(['user_id'=>$id,'dep_id'=>$depId]);
- }else{
- Db::name('user_dep')->where('user_id',$id)->setField('dep_id',$depId);
- }
- $ur = Db::name('user_roles')->where('user_id',$id)->find();
- if(!$ur){
- Db::name('user_roles')->insert(['user_id'=>$id,'roles_id'=>$rolesId]);
- }else{
- Db::name('user_roles')->where('user_id',$id)->setField('roles_id',$rolesId);
- }
- $rolesParentId = Db::name('roles')
- ->where('id',$rolesId)
- ->value('parent_id');
- if($rolesParentId==11){
- $check = Db::name('worker')
- ->where('user_id',$id)->find();
- if(empty($check)){
- $a = [
- 'user_id'=>$id
- ];
- $res = Db::name('worker')
- ->insertGetId($a);
- if(!$res){
- \exception('护工保存失败');
- }
- }
- }
- }else{
- $data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
- $data['create_time'] = date('Y-m-d H:i:s');
- $data['ip'] = request()->ip();
- $ret = $this->insertGetId($data);
- $ids = $ret;
- if(!$ret){
- \exception('操作失败');
- }
- Db::name('user_org')->insert(['user_id'=>$ids,'org_id'=>$orgId]);
- Db::name('user_dep')->insert(['user_id'=>$ids,'dep_id'=>$depId]);
- Db::name('user_roles')->insert(['user_id'=>$ids,'roles_id'=>$rolesId]);
- $rolesParentId = Db::name('roles')
- ->where('id',$rolesId)
- ->value('parent_id');
- if($rolesParentId==11){
- Db::name('worker')
- ->where('user_id',$ids)
- ->delete();
- $a = [
- 'user_id'=>$ids
- ];
- $res = Db::name('worker')
- ->insertGetId($a);
- if(!$res){
- \exception('护工保存失败');
- }
- }
- }
- Db::commit();
- return true;
- }catch (Exception $e){
- Db::rollback();
- $this->error = $e->getMessage();
- return false;
- }
- }
- public function wxaddUser(){
- $data = [
- 'id' => input('id/d',0),
- 'real_name' => input('real_name','','trim'),
- 'enable' => input('enable/d',1),
- ];
- $result = validate('User')->check($data,[],'wxedit');
- if(true !== $result){
- $this->error = validate('User')->getError();
- return false;
- }
- Db::startTrans();
- try{
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- if(!$ret){
- \exception('操作失败');
- }
- }else{
- }
- Db::commit();
- return true;
- }catch (Exception $e){
- Db::rollback();
- $this->error = $e->getMessage();
- return false;
- }
- }
- public function addCompany(){
- $data = [
- 'id' => input('id/d',0),
- 'account' => input('account','','trim'),
- 'real_name' => input('real_name','','trim'),
- 'mobile' => input('mobile','','trim'),
- 'password' => input('password','','trim'),
- 'orgs' => input('orgs','','trim'),
- 'rolesId' => input('rolesId/d',0),
- 'enable' => input('enable/d',1),
- 'type' => 1
- ];
- $result = validate('User')->check($data,[],'addCompany');
- if(true !== $result){
- $this->error = validate('User')->getError();
- return false;
- }
- Db::startTrans();
- try{
- $id = $data['id'];
- unset($data['id']);
- $rolesId = $data['rolesId'];
- unset($data['rolesId']);
- if($rolesId == 1){ //超级管理员
- $data['orgs'] = '';
- }
- if($id > 0){
- if(!$data['password']){
- unset($data['password']);
- }
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- if(!$ret){
- \exception('操作失败');
- }
- Db::name('user_roles')->where('user_id',$id)->setField('roles_id',$rolesId);
- }else{
- $data['create_time'] = date('Y-m-d H:i:s');
- $data['ip'] = request()->ip();
- $ret = $this->allowField(true)->save($data);
- if(!$ret){
- \exception('操作失败');
- }
- Db::name('user_roles')->insert(['user_id'=>$this->id,'roles_id'=>$rolesId]);
- }
- Db::commit();
- return true;
- }catch (Exception $e){
- Db::rollback();
- $this->error = $e->getMessage();
- return false;
- }
- }
- // 修改密码
- public function modifyPass($data){
- $result = validate('User')->check($data,[],'modifyPass');
- if(true !== $result){
- $this->error = validate('User')->getError();
- return false;
- }
- $info = Db::name('user')->where('id',$data['id'])->where('del',0)->find();
- if(!$info){
- $this->error = '用户不存在';
- return false;
- }
- if (!password_verify($data['oldpass'], $info['password'])) {
- $this->error = "旧密码错误";
- return false;
- }
- $data['update_time'] = date('Y-m-d H:i:s');
- $sdata = [
- 'update_time' => date('Y-m-d H:i:s'),
- 'password' => $data['pass'],
- 'login' => 1
- ];
- $ret = $this->allowField(true)->save($sdata,['id'=>$data['id']]);
- if(!$ret){
- $this->error = "密码修改失败";
- return false;
- }
- return true;
- }
- //app登录
- public function login($accountName,$password){
- // 登录限流
- $ret = (new \app\common\util\ThrottlesUtil(config('app.login_throttles')))->tooManyAttempts($accountName);
- if($ret){
- $this->error ='账号已被锁定,请稍后重试';
- return false;
- }
- // 登录是根据账号和手机号组成,先查账号再查手机号
- $user = Db::name('user')
- ->where('account',$accountName)
- ->where('del',0)
- ->find();
- if(empty($user)){
- $user = Db::name('user')
- ->where('mobile',$accountName)
- ->where('del',0)
- ->find();
- }
- if(empty($user)){
- $this->error = '账号或密码错误';
- return false;
- }
- $pass = aes_decrypt($password);
- if(!password_verify($pass, $user['password'])){
- $this->error = '账号或密码错误';
- return false;
- }
- $token = $this->authLogin($user['id']);
- if(!$token){
- $this->error = '登录失败';
- return false;
- }
- // 登录成功,重置限流
- (new \app\common\util\ThrottlesUtil(config('app.login_throttles')))->resetAttempts($accountName);
- return ['user_id' => $user['id'],'token' => $token];
- }
- private function authLogin($userId,$openid=''){
- Db::startTrans();
- try{
- $res = Db::name('user')->where('id',$userId)->update([
- 'last_login_time' => date('Y-m-d H:i:s')
- ]);
- if(!$res){
- \exception('登录失败');
- }
- $token = model('Token')->updateToken($userId);
- if(!$token){
- \exception(model('Token')->getError());
- }
- if($openid){
- $ret = Db::name('user_oauth')->insert([
- 'user_id' => $userId,
- 'openid' => $openid,
- 'type' => 1,
- 'create_time' => date('Y-m-d H:i:s')
- ]);
- if (!$ret) {
- \exception('事务失败');
- }
- }
- Db::commit();
- return $token;
- }catch (Exception $e){
- Db::rollback();
- $this->error = $e->getMessage();
- return false;
- }
- }
- // 小程序手机号登录
- public function wxpLogin($phone,$orgId){
- // 1.检查用户是否存在,存在登录,不存在告诉用户进行下一步
- $user = Db::name('user')->where('mobile',$phone)->where('del',0)->find();
- if(!$user){ // 不存在注册
- HelpHander::error('用户不存在',2,['phone'=>$phone]); // 用户进行下一步
- Db::startTrans();
- try{
- $data = [
- 'account' => md5($phone.$orgId.get_unique_id().time()),
- 'real_name' => $phone,
- 'mobile' => $phone,
- 'password' => $phone,
- 'enable' => 1,
- 'type' => 2,
- 'last_login_time' => date('Y-m-d H:i:s'),
- ];
- $data['create_time'] = date('Y-m-d H:i:s');
- $data['ip'] = request()->ip();
- $ret = $this->allowField(true)->save($data);
- if(!$ret){
- \exception('操作失败');
- }
- $userId = $this->id;
- $token = model('Token')->updateToken($userId);
- if(!$token){
- \exception(model('Token')->getError());
- }
- Db::name('user_org')->insert([
- 'user_id' => $userId,
- 'org_id' => $orgId
- ]);
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- $this->error = $e->getMessage();
- return false;
- }
- return ['user_id' => $userId,'token' => $token,'org_id' => $orgId];
- }else{
- if($user['enable'] != 1){
- HelpHander::error('用户被禁用,请联系管理员');
- }
- // 获取用户组织
- $uo = Db::name('user_org')->where('user_id',$user['id'])->find();
- if(!$uo){
- Db::name('user_org')->insert([
- 'user_id' => $user['id'],
- 'org_id' => $orgId
- ]);
- $curOrgId = $orgId;
- }else{
- $curOrgId = $uo['org_id'];
- }
- $org = Db::name('org')->where('id',$curOrgId)->where('del',0)->where('enable',1)->where('type',2)->find();
- if(!$org){
- $this->error = "项目不存在或已禁用";
- return false;
- }
- Db::startTrans();
- try{
- $data = [
- 'last_login_time' => date('Y-m-d H:i:s'),
- ];
- $ret = Db::name('user')->where('id',$user['id'])->update($data);
- if(!$ret){
- \exception('操作失败');
- }
- $token = model('Token')->updateToken($user['id']);
- if(!$token){
- \exception(model('Token')->getError());
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- $this->error = $e->getMessage();
- return false;
- }
- return ['user_id' => $user['id'],'token' => $token,'org_id' => $curOrgId];
- }
- }
- // 小程序登录
- public function wxLogin($openid,$nickname,$avatar,$orgId){
- $oauth = Db::name('user_oauth')
- ->where('openid',$openid)
- ->where('type',1)
- ->find();
- if($oauth){
- return $this->wxPreLogin($openid,$orgId);
- }
- $org = Db::name('org')->where('id',$orgId)->where('del',0)->where('enable',1)->where('type',2)->find();
- if(!$org){
- $this->error = "项目不存在";
- return false;
- }
- Db::startTrans();
- try{
- $data = [
- 'account' => $orgId.'_'.$openid,
- 'real_name' => $nickname,
- 'head_image' => $avatar,
- 'mobile' => '',
- 'password' => $openid,
- 'enable' => 1,
- 'type' => 2,
- 'last_login_time' => date('Y-m-d H:i:s'),
- ];
- $data['create_time'] = date('Y-m-d H:i:s');
- $data['ip'] = request()->ip();
- $ret = $this->allowField(true)->save($data);
- if(!$ret){
- \exception('操作失败');
- }
- $userId = $this->id;
- $token = model('Token')->updateToken($userId);
- if(!$token){
- \exception(model('Token')->getError());
- }
- if($openid){
- $ret = Db::name('user_oauth')->insert([
- 'user_id' => $userId,
- 'openid' => $openid,
- 'type' => 1,
- 'create_time' => date('Y-m-d H:i:s')
- ]);
- if (!$ret) {
- \exception('事务失败');
- }
- }
- Db::name('user_org')->insert([
- 'user_id' => $userId,
- 'org_id' => $orgId
- ]);
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- $this->error = $e->getMessage();
- return false;
- }
- return ['user_id' => $userId,'token' => $token];
- }
- // 微信小程序预登陆
- public function wxPreLogin($openid,$orgId){
- $org = Db::name('org')->where('id',$orgId)->where('del',0)->where('enable',1)->where('type',2)->find();
- if(!$org){
- $this->error = "项目不存在";
- return false;
- }
- $oauth = Db::name('user_oauth')
- ->where('openid',$openid)
- ->where('type',1)
- ->find();
- if(empty($oauth)){ // 账号不存在注册一个
- $data = [
- 'account' => $orgId.'_'.$openid,
- 'real_name' => "",
- 'mobile' => '',
- 'password' => $openid,
- 'head_image' => "",
- 'enable' => 1,
- 'type' => 2,
- ];
- $data['create_time'] = date('Y-m-d H:i:s');
- $data['ip'] = request()->ip();
- $ret = $this->allowField(true)->save($data);
- if(!$ret){
- \exception('操作失败');
- }
- $userId = $this->id;
- $uoData = [
- 'openid'=>$openid,
- 'user_id'=>$userId,
- 'create_time'=>date('Y-m-d H:i:s'),
- 'type'=>1
- ];
- $uo = Db::name('user_oauth')->insert($uoData);
- if(!$uo){
- $this->error = '登录失败';
- return false;
- }
- }else{
- $userId = $oauth['user_id'];
- }
- $user = Db::name('user')
- ->where('id',$userId)
- ->where('del',0)
- ->find();
- if(empty($user)){
- $this->error = '账号不存在';
- return false;
- }
- $uo = Db::name('user_org')->where('user_id',$user['id'])->where('org_id',$orgId)->find();
- if(!$uo){
- Db::name('user_org')->insert([
- 'user_id' => $user['id'],
- 'org_id' => $orgId
- ]);
- }
- $token = $this->authLogin($user['id'],'',$orgId);
- if(!$token){
- $this->error = '登录失败';
- return false;
- }
- return ['user_id' => $user['id'],'token' => $token,'org_name' => $org['name']];
- }
- /**
- * 专项保洁获取人员
- *
- * @author wst
- * @date 2021/9/6 10:45
- */
- public function getCleanWorker(){
- $list = (new WorkTypeMode())->getRolesUser(14,cur_org_id());
- $arr = [];
- foreach ($list as $k=>$v){
- if(!empty($v['user'])){
- foreach ($v['user'] as $k1=>$v1){
- $arr[] = [
- 'id'=>$v1['id'],
- 'title'=>$v1['real_name'],
- ];
- }
- }
- }
- return $arr;
- }
- /**
- * 设备台账获取人员
- *
- * @author wst
- * @date 2021/9/8 14:59
- * @return array
- */
- public function getDeviceWorker(){
- $list = (new WorkTypeMode())->getRolesUser(10,cur_org_id());
- $arr = [];
- foreach ($list as $k=>$v){
- if(!empty($v['user'])){
- foreach ($v['user'] as $k1=>$v1){
- $arr[] = [
- 'id'=>$v1['id'],
- 'title'=>$v1['real_name'],
- ];
- }
- }
- }
- return $arr;
- }
- /**
- * 巡更模块获取人员
- *
- * @author wst
- * @date 2021/9/8 15:00
- * @return array
- */
- public function getPatrolWorker($id){
- $list = (new WorkTypeMode())->getRolesUser($id,cur_org_id());
- $arr = [];
- foreach ($list as $k=>$v){
- if(!empty($v['user'])){
- foreach ($v['user'] as $k1=>$v1){
- $arr[] = [
- 'id'=>$v1['id'],
- 'title'=>$v1['real_name'],
- ];
- }
- }
- }
- return $arr;
- }
- /**
- * 医废获取人员
- *
- * @author wst
- * @date 2021/9/8 15:01
- * @param string $test
- * @return bool
- */
- public function getWasteWorker(){
- $list = (new WorkTypeMode())->getRolesUser(11,cur_org_id());
- $arr = [];
- foreach ($list as $k=>$v){
- if(!empty($v['user'])){
- foreach ($v['user'] as $k1=>$v1){
- $arr[] = [
- 'id'=>$v1['id'],
- 'title'=>$v1['real_name'],
- ];
- }
- }
- }
- return $arr;
- }
- /**
- * 获取医废未转运提示人员
- *
- * @author wst
- * @date 2021/9/8 15:01
- * @param string $test
- * @return bool
- */
- public function getWasteWorkerList(){
- $user = Db::name('user')
- ->alias('u')
- ->field('u.id,u.real_name as title')
- ->join('user_org uo','uo.user_id=u.id')
- ->where([
- 'uo.org_id'=>cur_org_id(),
- 'u.del'=>0,
- 'u.enable'=>1,
- ])
- ->select();
- return $user;
- }
- /**
- * 获取用户消息
- * @param $userId
- */
- public function info($userId,$orgId=0){
- $user = Db::name('user')
- ->where('id',$userId)
- ->where('del',0)
- ->where('enable',1)
- ->field('id,real_name,mobile,type,head_image,work,station,addr_id,device_sn,login')
- ->find();
- if(!$user){
- $this->error = '用户不存在或被禁用';
- return false;
- }
- $dep = Db::name('user_dep')
- ->alias('ud')
- ->join('dep d','d.id = ud.dep_id')
- ->field('d.id,d.title')
- ->where('ud.user_id',$userId)
- ->find();
- $user['dep_id'] = $dep?$dep['id']:0;
- $user['dep_name'] = $dep?$dep['title']:'';
- $addrTitle = Db::name('address')
- ->where('id',$user['addr_id'])
- ->value('title');
- $user['addr_title'] = $user['addr_id']>0?$addrTitle:'';
- $roles = Db::name('user_roles')
- ->alias('ur')
- ->join('roles r','r.id = ur.roles_id')
- ->field('r.id,r.name,r.parent_id')
- ->where('ur.user_id',$userId)
- ->find();
- $user['roles_id'] = $roles?$roles['id']:0;
- $user['roles_name'] = $roles?$roles['name']:'';
- $parentId = $roles?$roles['parent_id']:0;
- $user['userType'] = $parentId==3?1:2;//2其它1客户
- $user['workTypeMode'] = '';
- $user['isTwoDispatch'] = 2;
- if($user['roles_id'] >0){
- $rolesInfo = Db::name('roles')
- ->where('id',$user['roles_id'])
- ->find();
- $user['workTypeMode'] = $rolesInfo['work_type_mode'];
- $user['isTwoDispatch'] = $rolesInfo['level'];
- }
- return $user;
- }
- /*
- * 获取某组织下全部人员
- * @param $orgId
- */
- public function gerUserAll($orgId = 0){
- $user = Db::name('user')
- ->alias('u')
- ->field('u.id,u.real_name as title')
- ->join('user_org uo','u.id=uo.user_id')
- ->where('uo.org_id',$orgId)
- ->where('enable',1)
- ->where('del',0)
- ->select();
- return $user;
- }
- //获取二级调度角色下用户、
- public function get_two_dispatch_user($rolesId){
- $user = Db::name('user_roles')
- ->alias('a')
- ->join('user u','a.user_id=u.id')
- ->where('a.roles_id',$rolesId)
- ->where('u.del',0)
- ->where('u.enable',1)
- ->where('u.type',0)
- ->select();
- return $user;
- }
- //后台获取所有二级调度角色
- public function get_two_dispatch_role($orgId,$type){
- $map[] = ['enable','=',1];
- $map[] = ['level','=',2];
- $map[] = ['del','=',0];
- $map[] = ['parent_id','=',9];
- $map[] = ['org_id','=',$orgId];
- $map[] = ['','exp',Db::raw("FIND_IN_SET(".$type.",work_type_mode)")];
- $role = Db::name('roles')
- ->field('id,name as title')
- ->where($map)
- ->select();
- return $role;
- }
- //api获取所有二级调度角色
- public function get_two_dispatch_role1($orgId,$type){
- $map[] = ['enable','=',1];
- $map[] = ['level','=',2];
- $map[] = ['del','=',0];
- $map[] = ['parent_id','=',9];
- $map[] = ['org_id','=',$orgId];
- $map[] = ['','exp',Db::raw("FIND_IN_SET(".$type.",work_type_mode)")];
- $role = Db::name('roles')
- ->field('id,name as realName')
- ->where($map)
- ->select();
- return $role;
- }
- // 根据id获取用户信息
- public function getUserInfo($id){
- $info = Db::name('user')
- ->where('id',$id)
- ->where('del',0)
- ->find();
- return $info;
- }
- //获取所有调度
- public function get_dispatch_user($orgId){
- $roles = Db::name('roles')
- ->where('parent_id',9)
- ->where('org_id',$orgId)
- ->where('del',0)
- ->where('enable',1)
- ->column('id');
- if(empty($roles)){
- return [];
- }
- $user = Db::name('user')
- ->alias('a')
- ->join('user_roles u','a.id=u.user_id')
- ->where('u.roles_id','in',$roles)
- ->where('a.del',0)
- ->where('a.enable',1)
- ->where('a.type',0)
- ->select();
- return $user;
- }
- /**
- * 获取拥有陪护模块权限的人
- * @param $orgId
- */
- public function get_ph_dispatch_user($orgId){
- $appId = Db::name('app_icon')->where('mode',25)->value('id');
- if(!$appId){
- return [];
- }
- $map[] = ['org_id','=',$orgId];
- $map[] = ['del','=',0];
- $map[] = ['enable','=',1];
- $map[] = ['','exp',Db::raw("FIND_IN_SET('appauths','".$appId."')")];
- $roles = Db::name('roles')->where($map)->column('id');
- if(empty($roles)){
- return [];
- }
- $user = Db::name('user')
- ->alias('a')
- ->join('user_roles u','a.id=u.user_id')
- ->where('u.roles_id','in',$roles)
- ->where('a.del',0)
- ->where('a.enable',1)
- ->where('a.type',0)
- ->select();
- return $user;
- }
- /**
- * 运送获取人员
- *
- * @author wst
- * @date 2021/9/8 14:59
- * @return array
- */
- public function getConveyWorker(){
- $list = (new WorkTypeMode())->getRolesUser(6,cur_org_id());
- $arr = [];
- foreach ($list as $k=>$v){
- if(!empty($v['user'])){
- foreach ($v['user'] as $k1=>$v1){
- $arr[] = [
- 'id'=>$v1['id'],
- 'title'=>$v1['real_name'],
- ];
- }
- }
- }
- return $arr;
- }
- public function wxRegister($post){
- $post['id'] = 0;
- $result = validate('User')->check($post,[],'wxadd');
- if(true !== $result){
- $this->error = validate('User')->getError();
- return false;
- }
- $data = [
- 'mobile' => $post['mobile'],
- 'real_name' => $post['real_name'],
- 'password' => $post['password'],
- ];
- Db::startTrans();
- try{
- $data['account'] = md5($data['mobile'].$data['password'].get_unique_id().time());
- $data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
- $data['create_time'] = date('Y-m-d H:i:s');
- $data['ip'] = request()->ip();
- $data['update_time'] = date('Y-m-d H:i:s');
- $data['last_login_time'] = date('Y-m-d H:i:s');
- $data['type'] = 2;
- $data['enable'] = 1;
- $data['del'] = 0;
- $uid = Db::name('user')->insertGetId($data);
- if(!$uid){
- \exception('操作失败');
- }
- Db::name('user_org')->insert(['user_id'=>$uid,'org_id'=>$post['orgId']]);
- if($post['depId'] > 0){
- Db::name('user_dep')->insert(['user_id'=>$uid,'dep_id'=>$post['depId']]);
- }
- $token = model('Token')->updateToken($uid);
- if(!$token){
- \exception(model('Token')->getError());
- }
- Db::commit();
- return ['user_id' => $uid,'token' => $token,'org_id' => $post['orgId']];
- }catch (Exception $e){
- Db::rollback();
- $this->error = $e->getMessage();
- return false;
- }
- }
- /**
- * 绿化养护获取人员
- *
- * @author wst
- * @date 2021/9/6 10:45
- */
- public function getGreenWorker() {
- $list = (new WorkTypeMode())->getRolesUser(19, cur_org_id());
- $arr = [];
- foreach ($list as $k => $v) {
- if (!empty($v['user'])) {
- foreach ($v['user'] as $k1 => $v1) {
- $arr[] = [
- 'id' => $v1['id'],
- 'title' => $v1['real_name'],
- ];
- }
- }
- }
- return $arr;
- }
- public function getYsUser($orgId,$work=0){
- $list = (new WorkTypeMode())->getRolesUser(3,$orgId,1);
- $arr = [];
- foreach ($list as $k=>$v){
- if(!empty($v['user'])){
- foreach ($v['user'] as $k1=>$v1){
- $arr[] = [
- 'id'=>$v1['id'],
- 'real_name'=>$v1['real_name'],
- ];
- }
- }
- }
- return $arr;
- }
- public function getWorkTypeModeUser($id,$orgId,$work=0){
- $list = (new WorkTypeMode())->getRolesUser($id,$orgId,$work);
- $arr = [];
- foreach ($list as $k=>$v){
- if(!empty($v['user'])){
- foreach ($v['user'] as $k1=>$v1){
- $arr[] = [
- 'id'=>$v1['id'],
- 'title'=>$v1['real_name'],
- ];
- }
- }
- }
- return $arr;
- }
- }
|