User.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\BaseController;
  5. use think\facade\Db;
  6. use app\admin\model\ActionLog;
  7. //用户
  8. class User extends BaseController
  9. {
  10. /**
  11. * 显示资源列表
  12. *
  13. * @return \think\Response
  14. */
  15. public function list()
  16. {
  17. $post =$this->request->post();
  18. $token = isset($post['token']) ? trim($post['token']) : "";
  19. if($token==""){
  20. return error_show(101,'token不能为空');
  21. }
  22. $effetc =VerifyTokens($token);
  23. if(!empty($effetc) && $effetc['code']!=0){
  24. return error_show($effetc['code'],$effetc['message']);
  25. }
  26. if(isset($post['status'])&&$post['status']!==''){
  27. $uid =Db::name("user_role")->where(["status"=>1,"is_del"=>0])->column("uid");
  28. if($post['status']==1){
  29. $post['uid']=$uid;
  30. }else{
  31. $post['nouid']=$uid;
  32. unset($post['status']);
  33. }
  34. }
  35. $data = Getlist($token,$post);
  36. if(!empty($data) && $data['code']!=0){
  37. return error_show($data['code'],$data['message']);
  38. }
  39. $list=[];
  40. foreach($data['data']['list'] as $key=>$value){
  41. $role = Db::name("user_role")->alias('a')->leftJoin('role b',"a.roleid = b.id")->where("a.uid","=",$value['id'])
  42. ->field("roleid,role_name,a.status")->find();
  43. $value['roleid'] = isset($role['roleid']) ? $role['roleid'] :"";
  44. $value['role_name'] = isset($role['role_name']) ? $role['role_name'] :"";
  45. $depart = Db::name("depart_user")->where([["uid","=",$value['id']],["is_del","=",0]])->column("itemid");
  46. $value['depart']="";
  47. $value['status']=$value['status']==1?($role['status']??"0"):'0';
  48. if(!empty($depart)){
  49. $deparname = Db::name("company_item")->where(["id"=>$depart,"is_del"=>0])->column("id,name,depart_link");
  50. $value['depart_code'] = [];
  51. if(!empty($deparname)){
  52. foreach ($deparname as $item) {
  53. $value['depart_code'][] = array_filter(explode("-",$item['depart_link'])) ;
  54. $value['depart_info'][] = Db::name("company_item")->where(["id"=>array_filter(explode("-",
  55. $item['depart_link'])),"is_del"=>0])->column("name");
  56. }
  57. }
  58. $value['depart'] = $deparname;
  59. }
  60. $list[]=$value;
  61. }
  62. $data['data']['list'] = $list;
  63. return app_show($data['code'],$data['message'],$data['data']);
  64. }
  65. /**
  66. * @param token
  67. * @return \think\response\Json
  68. * @throws \think\exception\DbException
  69. */
  70. public function userInfo(){
  71. $post =$this->request->post();
  72. $token = isset($post['token']) ? trim($post['token']) : "";
  73. if($token==""){
  74. return app_show(101,'token不能为空');
  75. }
  76. $effetc = VerifyTokens($token);
  77. if(!empty($effetc) && $effetc['code']!=0){
  78. return app_show($effetc['code'],$effetc['message']);
  79. }
  80. $userinfo=GetUserInfo($token);
  81. if(empty($userinfo)||$userinfo['code']!=0){
  82. return app_show(102,"员工信息不存在");
  83. }
  84. $id = isset($post['id']) && $post['id'] !==""? trim($post['id']):"";
  85. if($id ==""){
  86. return error_show(1004,"id不能为空");
  87. }
  88. $to= GetInfoById($token,['id'=>$id]);
  89. if(empty($to)||$to['code']!=0){
  90. return app_show(1002,"员工信息不存在");
  91. }
  92. // $nickname = isset($to['data']['nickname']) &&$to['data']['nickname']!="" ? $to['data']['nickname'] :"" ;
  93. $data = $to['data'];
  94. $role = Db::name("user_role")->alias('a')->leftJoin('role b',"a.roleid = b.id")->where("a.uid","=",$data['id'])
  95. ->field("roleid,role_name,business_all,uid,a.status")->find();
  96. $data['role_name']=isset($role['role_name']) ? $role['role_name'] :"";
  97. $data['roleid']=isset($role['roleid']) ? $role['roleid'] :"";
  98. $data['status']= $data['status']==1? ($role['status']??'0'):"0";
  99. $st = Db::name('user_business')->where(['userid'=>$role['uid'],"is_del"=>0])->field('businessid,is_main')->select()->toArray();
  100. $val=[];
  101. if (!empty($st)){
  102. foreach ($st as $itom){
  103. $tep=[];
  104. $business= Db::name('business')->where(['id'=>$itom['businessid'],"is_del"=>0])->field("company,companyNo")->find();
  105. $tep['company']=isset($business['company'])?$business['company']:"";
  106. $tep['companyNo']=isset($business['companyNo'])?$business['companyNo']:"";
  107. $tep['businessid']=$itom['businessid'];
  108. $tep['is_main']=$itom['is_main'];
  109. $val[]=$tep;
  110. }
  111. }
  112. $data['business'] =$val;
  113. $info=[];
  114. $stn = Db::name('user_platform')->where(['uid'=>$role['uid']])->find();
  115. if($stn!=false){
  116. $plat =isset($stn['platform'])?explode(",",$stn['platform']):"";
  117. if($plat!=""){
  118. $platform = Db::name('platform')->where(['id'=>$plat,'is_del'=>0])->column("id,platform_name,platform_code");
  119. $info=$platform;
  120. }
  121. }
  122. $depart = Db::name("depart_user")->where([["uid","=",$data['id']],["is_del","=",0]])->column("itemid");
  123. $data['depart']="";
  124. if(!empty($depart)){
  125. $deparname = Db::name("company_item")->where(["id"=>$depart,"is_del"=>0])->field("id,name,depart_link")->select()->toArray();
  126. if(!empty($deparname)){
  127. foreach ($deparname as $ky=> $item) {
  128. $deparname[$ky]['depart_code']= array_filter(explode("-",$item['depart_link'])) ;
  129. }
  130. }
  131. $data['depart'] = $deparname;
  132. }
  133. $data['platform']=$info;
  134. return app_show(0,"获取成功",$data);
  135. }
  136. /**
  137. * @param token
  138. * @param passwd
  139. * @return \think\response\Json
  140. * @throws \think\exception\DbException
  141. */
  142. public function resetPwd(){
  143. $post =$this->request->post();
  144. $token = isset($post['token']) ? trim($post['token']) : "";
  145. if($token==""){
  146. return error_show(101,'token不能为空');
  147. }
  148. $effetc = VerifyTokens($token);
  149. if(!empty($effetc) && $effetc['code']!=0){
  150. return error_show($effetc['code'],$effetc['message']);
  151. }
  152. $newPwd= isset($post['newpwd']) ? trim($post['newpwd']) : "";
  153. if($newPwd==""){
  154. return error_show(1001,'新密码不能为空');
  155. }
  156. $oldpwd = isset($post['oldpwd'])?trim($post['oldpwd']):"";
  157. if($oldpwd==""){
  158. return error_show(1002,"原密码不能为空");
  159. }
  160. $data = resetpasswd($token,['newpwd'=>$newPwd,'oldpwd'=>$oldpwd]);
  161. if(empty($userinfo)||$userinfo['code']!=0){
  162. return error_show($userinfo['code'],$userinfo['message']);
  163. }else{
  164. return app_show(0,"密码修改成功");
  165. }
  166. }
  167. public function userAll(){
  168. $post =$this->request->post();
  169. $token = isset($post['token']) ? trim($post['token']) : "";
  170. if($token==""){
  171. return app_show(101,'token不能为空');
  172. }
  173. $effetc = VerifyTokens($token);
  174. if(!empty($effetc) && $effetc['code']!=0){
  175. return app_show($effetc['code'],$effetc['message']);
  176. }
  177. if(isset($post['status'])&&$post['status']!==''){
  178. $uid =Db::name("user_role")->where(["status"=>1,"is_del"=>0])->column("uid");
  179. if($post['status']==1){
  180. $post['uid']=$uid;
  181. }else{
  182. $post['nouid']=$uid;
  183. }
  184. unset($post['status']);
  185. }
  186. $userinfo=GetAccountall($token,$post);
  187. if(empty($userinfo)||$userinfo['code']!=0){
  188. return app_show(1002,"员工信息不存在");
  189. }
  190. $data = $userinfo['data'];
  191. $list=[];
  192. foreach ($data as $value){
  193. $role = Db::name("user_role")->alias('a')->leftJoin('role b',"a.roleid = b.id")->where("a.uid","=",$value['id'])
  194. ->field("roleid,role_name,a.status")->find();
  195. $value['roleid'] = isset($role['roleid']) ? $role['roleid'] :"";
  196. $value['role_name'] = isset($role['role_name']) ? $role['role_name'] :"";
  197. $depart = Db::name("depart_user")->where([["uid","=",$value['id']],["is_del","=",0]])->column("itemid");
  198. $value['depart']="";
  199. $value['status']= $value['status']==1?($role['status']??"0"):'0';
  200. if(!empty($depart)){
  201. $deparname = Db::name("company_item")->where(["id"=>$depart,"is_del"=>0])->field("id,name,depart_link")
  202. ->select()->toArray();
  203. array_walk($deparname,function (&$v){
  204. $v = array_filter(explode("-",$v['depart_link'])) ;
  205. });
  206. $value['depart'] = $deparname;
  207. }
  208. $list[]=$value;
  209. }
  210. return app_show(0,"获取成功",$list);
  211. }
  212. /**
  213. * @return \think\response\Json|void
  214. * @throws \think\db\exception\DataNotFoundException
  215. * @throws \think\db\exception\DbException
  216. * @throws \think\db\exception\ModelNotFoundException
  217. * @throws \think\exception\DbException
  218. */
  219. public function userList(){
  220. $post =$this->request->post();
  221. $token = isset($post['token']) ? trim($post['token']) : "";
  222. if($token==""){
  223. return app_show(101,'token不能为空');
  224. }
  225. $effetc = VerifyTokens($token);
  226. if(!empty($effetc) && $effetc['code']!=0){
  227. return app_show($effetc['code'],$effetc['message']);
  228. }
  229. $itemid = isset($post['itemid']) && $post['itemid']!=="" ? intval($post['itemid']) :"";
  230. if($itemid!==""){
  231. $uids = Db::name("depart_user")->where([["itemid","=",$itemid],["is_del","=",0]])->column("uid");
  232. $post['uid'] =$uids;
  233. }
  234. if(isset($post['status'])&&$post['status']!==''){
  235. $uid =Db::name("user_role")->where(["status"=>1,"is_del"=>0])->column("uid");
  236. if($post['status']==1){
  237. $post['uid']= isset($uids)?array_unique(array_merge($uids,$uid)):$uid;
  238. }else{
  239. $post['nouid']=$uid;
  240. unset($post['status']);
  241. }
  242. }
  243. $userinfo=GetList($token,$post);
  244. if(empty($userinfo)||$userinfo['code']!=0){
  245. return app_show($userinfo['code'],$userinfo['msg']);
  246. }
  247. $data = $userinfo['data']['list'];
  248. $list=[];
  249. foreach ($data as $value){
  250. $role = Db::name("user_role")->alias('a')->leftJoin('role b',"a.roleid = b.id")->where("a.uid","=",$value['id'])
  251. ->field("roleid,role_name,a.status")->find();
  252. $value['roleid'] = isset($role['roleid']) ? $role['roleid'] :"";
  253. $value['role_name'] = isset($role['role_name']) ? $role['role_name'] :"";
  254. $depart = Db::name("depart_user")->where([["uid","=",$data['uid']],["is_del","=",0]])->column("itemid");
  255. $value['depart']="";
  256. $value['status']=$value['status']==1?($role['status']??"0"):'0';
  257. if(!empty($depart)){
  258. $deparname = Db::name("company_item")->where(["id"=>$depart,"is_del"=>0])->field("id,name,depart_link")
  259. ->select()->toArray();
  260. $value['depart'] = $deparname;
  261. $value['depart_code'] = [];
  262. if(!empty($deparname)){
  263. foreach ($deparname as $item) {
  264. $value['depart_code'][] = array_filter(explode("-",$item['depart_link'])) ;
  265. }
  266. }
  267. }
  268. $list[]=$value;
  269. }
  270. return app_show(0,"获取成功",["list"=>$list,"count"=>$userinfo['data']["count"]]);
  271. }
  272. public function setRole(){
  273. $post =$this->request->post();
  274. $token = isset($post['token']) ? trim($post['token']) : "";
  275. if($token==""){
  276. return app_show(101,'token不能为空');
  277. }
  278. $effetc = VerifyTokens($token);
  279. if(!empty($effetc) && $effetc['code']!=0){
  280. return app_show($effetc['code'],$effetc['message']);
  281. }
  282. $uid = isset($post['id'])&&$post['id']!=='' ? intval($post['id']) :"";
  283. if($uid===''){
  284. return error_show(1004,"参数id 不能为空");
  285. }
  286. $role =isset($post['roleid']) && $post['roleid']!=="" ? intval($post['roleid']) :"";
  287. if($role===''){
  288. return error_show(1004,"参数roleid 不能为空");
  289. }
  290. $isRole = Db::name('role')->where([['id',"=",$role],['status',"=",1]])->find();
  291. if(empty($isRole)){
  292. return error_show(1004,"所选角色不存在");
  293. }
  294. $data = [
  295. 'uid'=>$uid,
  296. 'roleid'=>$role,
  297. 'status'=>1,
  298. 'addtime'=>date('Y-m-d H:i:s'),
  299. 'updatetime'=>date('Y-m-d H:i:s'),
  300. ];
  301. $insert = Db::name('user_role')->insert($data);
  302. $st = ["order_code"=>$uid,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  303. ActionLog::logAdd($token,$st,"resign_info",1,$st);
  304. return $insert? app_show(0,'数据新建成功'):error_show(1004,'数据新建失败');
  305. }
  306. /**
  307. * 保存新建的资源
  308. *
  309. * @param \think\Request $request
  310. * @return \think\Response
  311. */
  312. public function UserSave()
  313. {
  314. $post=$this->request->post();
  315. $toke= isset($post['token'])? trim($post['token']):"";
  316. if ($toke==""){
  317. return app_show(100,"token不能为空");
  318. }
  319. $verify = VerifyTokens($toke);
  320. if ($verify['code']!=0){
  321. return app_show($verify['code'],$verify['message']);
  322. }
  323. $userid = isset($post['id'])&&$post['id']!==""?intval($post['id']):"";
  324. if($userid==""){
  325. return error_show(1004,"参数id 不能为空");
  326. }
  327. $nickname= isset($post['nickname'])? trim($post['nickname']):"";
  328. if ($nickname==""){
  329. return app_show(1001,"昵称不能为空");
  330. }
  331. $mobile= isset($post['mobile'])? trim($post['mobile']):"";
  332. if ($mobile==""){
  333. return app_show(1002,"手机号不能为空");
  334. }
  335. if (checkMobile($mobile)==false){
  336. return app_show(1002,"手机号格式不正确");
  337. }
  338. $email= isset($post['email'])? trim($post['email']):"";
  339. $role =isset($post['role'])? intval($post['role']):0;
  340. if($role!=0){
  341. $roleinfo =Db::name("role")->where("id","=",$role)->find();
  342. if(empty($roleinfo)){
  343. return error_show(1002,"角色不存在");
  344. }
  345. if($roleinfo['status']==0){
  346. return error_show(1002,"角色已禁用");
  347. }
  348. }
  349. $itemid = isset($post['itemid'])&&$post['itemid']!=="" ?$post['itemid'] :"";
  350. $item_arr = [];
  351. if($itemid!==""){
  352. foreach ($itemid as $value){
  353. $item_arr[]=end($value);
  354. }
  355. $iteminfo = Db::name("company_item")->where(["id"=>$item_arr,'is_del'=>0])->select()->toArray();
  356. if(empty($iteminfo)){
  357. return error_show(1002,"未找到部门信息");
  358. }
  359. }
  360. $companyArr = isset($post['companyArr'])&&!empty($post['companyArr']) ? $post['companyArr']:"";
  361. if($companyArr==""){
  362. return error_show(1004,"参数companyArr不能为空");
  363. }
  364. $compArr=[];
  365. foreach ($companyArr as $value){
  366. $tmp=[];
  367. if(!isset($value['businessid'])||$value['businessid']==''){
  368. return error_show(1004,"参数业务公司businessid不能为空");
  369. }
  370. $tmp['userid']=$userid;
  371. $tmp['businessid']=$value['businessid'];
  372. $tmp['is_main']=isset($value['is_main'])?$value['is_main']:0;
  373. $tmp['is_del']=0;
  374. $tmp['addtime']=date("Y-m-d H:i:s");
  375. $tmp['updatetime']=date("Y-m-d H:i:s");
  376. $compArr[]=$tmp;
  377. }
  378. $platform = isset($post['platform'])&&!empty($post['platform']) ? $post['platform']:"";
  379. if($platform==""){
  380. return error_show(1004,"参数platform不能为空");
  381. }
  382. $plta =Db::name("platform")->where(["id"=>$platform,"is_del"=>0])->select()->toArray();
  383. if(empty($plta)){
  384. return error_show(1004,"未找到可用平台");
  385. }
  386. $userplat =Db::name("user_platform")->where(["uid"=>$userid,"is_del"=>0])->find();
  387. $isall = isset($post['is_all'])&&$post['is_all']!==""?intval($post['is_all']):"0";
  388. Db::startTrans();
  389. try{
  390. $sc=Db::name("user_business")->where(["userid"=>$userid,"is_del"=>0])->select()->toArray();
  391. if(!empty($sc)){
  392. $del= Db::name("user_business")->where(["userid"=>$userid,"is_del"=>0])->save(["is_del"=>1,
  393. "updatetime"=>date("Y-m-d H:i:s")]);
  394. if($del==false){
  395. Db::rollback();
  396. return error_show(1005,'业务公司添加失败');
  397. }
  398. }
  399. if(!empty($compArr)){
  400. $in = Db::name("user_business")->insertAll($compArr);
  401. if($in==0){
  402. Db::rollback();
  403. return error_show(1005,'业务公司添加失败');
  404. }
  405. }
  406. if($userplat==false){
  407. $userplat=[
  408. "uid"=>$userid,
  409. "platform"=>implode(",",$platform),
  410. "is_del"=>0,
  411. "addtime"=>date("Y-m-d H:i:s"),
  412. "updatetime"=>date("Y-m-d H:i:s")
  413. ];
  414. }else{
  415. $userplat['platform']= implode(",",$platform);
  416. $userplat['updatetime']= date("Y-m-d H:i:s");
  417. }
  418. $patup =Db::name("user_platform")->save($userplat);
  419. if($patup==false){
  420. Db::rollback();
  421. return error_show(1005,'业务平台添加失败');
  422. }
  423. $userrole = Db::name("user_role")->where(["uid"=>$userid,"is_del"=>0])->find();
  424. if(empty($userrole)){
  425. $roledata =[
  426. "uid"=>$userid,
  427. "roleid"=>$role,
  428. "status"=>1,
  429. "business_all"=>$isall,
  430. "addtime"=>date("Y-m-d H:i:s"),
  431. "updatetime"=>date("Y-m-d H:i:s")
  432. ];
  433. $up= Db::name("user_role")->insert($roledata);
  434. }else{
  435. $userrole['roleid'] = $role;
  436. $userrole['business_all'] = $isall;
  437. $userrole['updatetime'] = date("Y-m-d H:i:s");
  438. $up=Db::name("user_role")->save($userrole);
  439. }
  440. if($up){
  441. Db::name("depart_user")->where(["uid"=>$userid])->save(['is_del'=>1]);
  442. if(isset($item_arr)&&!empty($item_arr)){
  443. foreach ($item_arr as $v){
  444. $depin =[
  445. "uid"=>$userid,
  446. "nickname"=>$nickname,
  447. "itemid"=>$v,
  448. "is_del"=>0,
  449. "updatetime"=>date("Y-m-d H:i:s")
  450. ];
  451. $ist = Db::name("depart_user")->where(["uid"=>$userid,"itemid"=>$v])->find();
  452. if($ist){
  453. $up = Db::name("depart_user")->where(["uid"=>$userid,"itemid"=>$v])->save($depin);
  454. }else{
  455. $depin['addtime']=date("Y-m-d H:i:s");
  456. $up = Db::name("depart_user")->insert($depin);
  457. }
  458. if($up==false){
  459. Db::rollback();
  460. return error_show(1005,'用户部门更新失败');
  461. }
  462. }
  463. }
  464. }else{
  465. Db::rollback();
  466. return error_show(1005,'角色更新失败');
  467. }
  468. $data=[
  469. "id"=>$userid,
  470. "nickname"=>$nickname,
  471. "mobile"=>$mobile,
  472. "email"=>$email
  473. ];
  474. $save =resetinfo($toke,$data);
  475. if(!empty($save) && $save['code']!=0){
  476. Db::rollback();
  477. return error_show($save['code'],$save['message']);
  478. }
  479. Db::commit();
  480. return app_show(0,"更新成功");
  481. }catch(\Exception $e){
  482. Db::rollback();
  483. return app_show(1002,$e->getMessage());
  484. }
  485. }
  486. public function setPwd(){
  487. $post =$this->request->post();
  488. $token = isset($post['token']) ? trim($post['token']) : "";
  489. if($token==""){
  490. return error_show(101,'token不能为空');
  491. }
  492. $effetc = VerifyTokens($token);
  493. if(!empty($effetc) && $effetc['code']!=0){
  494. return error_show($effetc['code'],$effetc['message']);
  495. }
  496. $userid = isset($post['id'])&&$post['id']!==""?intval($post['id']):"";
  497. if($userid==""){
  498. return error_show(1004,"参数id 不能为空");
  499. }
  500. $newPwd= isset($post['password']) ? trim($post['password']) : "";
  501. if($newPwd==""){
  502. return error_show(1001,'密码不能为空');
  503. }
  504. $data = resetpwd($token,["id"=>$userid,'password'=>$newPwd]);
  505. if(empty($data)||$data['code']!=0){
  506. return error_show($data['code'],$data['message']);
  507. }else{
  508. return app_show(0,"密码修改成功");
  509. }
  510. }
  511. public function UserStatus()
  512. {
  513. $post=$this->request->post();
  514. $toke= isset($post['token'])? trim($post['token']):"";
  515. if ($toke==""){
  516. return app_show(100,"token不能为空");
  517. }
  518. $verify = VerifyTokens($toke);
  519. if ($verify['code']!=0){
  520. return app_show($verify['code'],$verify['message']);
  521. }
  522. $userid = isset($post['id'])&&$post['id']!==""?intval($post['id']):"";
  523. if($userid==""){
  524. return error_show(1004,"参数userid 不能为空");
  525. }
  526. $status = isset($post['status'])&&$post['status']!=""?intval($post['status']):"";
  527. if($status===""){
  528. return error_show(1004,"参数status 不能为空");
  529. }
  530. if(!in_array($status,[0,1])){
  531. return error_show(1004,"参数status无效");
  532. }
  533. $message = $status==1?"启用":"禁用";
  534. $userinfo =Db::name("user_role")->where(["uid"=>$userid,"is_del"=>0])->find();
  535. if($userinfo==false){
  536. $data=[
  537. "uid"=>$userid,
  538. "roleid"=>0,
  539. "status"=>$status,
  540. "is_del"=>0,
  541. "addtime"=>date("Y-m-d H:i:s"),
  542. "updatetime"=>date("Y-m-d H:i:s"),
  543. ];
  544. $sa=Db::name("user_role")->save($data);
  545. }else{
  546. $userinfo['status']=$status;
  547. $userinfo['updatetime']=date("Y-m-d H:i:s");
  548. $sa=Db::name("user_role")->save($userinfo);
  549. }
  550. if($sa==false){
  551. return error_show(1005,"{$message}失败");
  552. }else{
  553. return app_show(0,"{$message}成功");
  554. }
  555. // $set = resetstatus($toke,["id"=>$userid,"status"=>$status]);
  556. //
  557. // if(empty($set)||$set['code']!=0){
  558. // return error_show(1005,"{$message}失败");
  559. // }else{
  560. // D
  561. // return app_show(0,"{$message}成功");
  562. // }
  563. }
  564. public function getinfo(){
  565. $post =$this->request->post();
  566. $token = isset($post['token']) ? trim($post['token']) : "";
  567. if($token==""){
  568. return app_show(101,'token不能为空');
  569. }
  570. $effetc = VerifyTokens($token);
  571. if(!empty($effetc) && $effetc['code']!=0){
  572. return app_show($effetc['code'],$effetc['message']);
  573. }
  574. $userinfo=GetUserInfo($token);
  575. if(empty($userinfo)||$userinfo['code']!=0){
  576. return app_show(102,"员工信息不存在");
  577. }
  578. $data = $userinfo['data'];
  579. $role = Db::name("user_role")->alias('a')->leftJoin('role b',"a.roleid = b.id")->where("a.uid","=",$data['id'])
  580. ->field("roleid,role_name,business_all,uid")->find();
  581. $data['role_name']=isset($role['role_name']) ? $role['role_name'] :"";
  582. $data['roleid']=isset($role['roleid']) ? $role['roleid'] :"";
  583. $st = Db::name('user_business')->where(['userid'=>$role['uid'],"is_del"=>0])->field('businessid,is_main')->select()->toArray();
  584. $val=[];
  585. if (!empty($st)){
  586. foreach ($st as $itom){
  587. $tep=[];
  588. $business= Db::name('business')->where(['id'=>$itom['businessid'],"is_del"=>0])->field("company,companyNo")->find();
  589. $tep['company']=isset($business['company'])?$business['company']:"";
  590. $tep['companyNo']=isset($business['companyNo'])?$business['companyNo']:"";
  591. $tep['businessid']=$itom['businessid'];
  592. $tep['is_main']=$itom['is_main'];
  593. $val[]=$tep;
  594. }
  595. }
  596. $data['private_field'] = [];
  597. if($data['roleid']!=""){
  598. $action =Db::name("role_action")->where(["role_id"=>$data['roleid'],"status"=>1])->find();
  599. if($action!=false){
  600. $data['private_field']=isset($action['private_field'])&&$action['private_field']!=""?explode(",",
  601. $action['private_field']):[];
  602. }
  603. }
  604. $data['business'] =$val;
  605. $info=[];
  606. $stn = Db::name('user_platform')->where(['uid'=>$role['uid']])->find();
  607. if($stn!=false){
  608. $plat =isset($stn['platform'])?explode(",",$stn['platform']):"";
  609. if($plat!=""){
  610. $platform = Db::name('platform')->where(['id'=>$plat,'is_del'=>0])->column("id,platform_name,platform_code");
  611. $info=$platform;
  612. }
  613. }
  614. $depart = Db::name("depart_user")->where([["uid","=",$data['id']],["is_del","=",0]])->column("itemid");
  615. $data['depart']="";
  616. if(!empty($depart)){
  617. $deparname = Db::name("company_item")->where(["id"=>$depart,"is_del"=>0])->field("id,name,depart_link")->select()->toArray();
  618. if(!empty($deparname)){
  619. foreach ($deparname as $ky=> $item) {
  620. $deparname[$ky]['depart_code']= array_filter(explode("-",$item['depart_link'])) ;
  621. }
  622. }
  623. $data['depart'] = $deparname;
  624. }
  625. $data['platform']=$info;
  626. return app_show(0,"获取成功",$data);
  627. }
  628. }