作者 lyh

gx

@@ -41,19 +41,78 @@ class HrLogic extends BaseLogic @@ -41,19 +41,78 @@ class HrLogic extends BaseLogic
41 foreach ($this->model::specieField() as $v){ 41 foreach ($this->model::specieField() as $v){
42 $this->param = $this->setJson($v,$this->param); 42 $this->param = $this->setJson($v,$this->param);
43 } 43 }
  44 + if(isset($this->param['id']) && !empty($this->param['id'])){
  45 + $this->editHrManager();
  46 + }else{
  47 + $this->addHrManager();
  48 + }
  49 + return $this->success();
  50 + }
  51 +
  52 + /**
  53 + * @remark :添加人事信息时 同步添加管理员账号
  54 + * @name :addManager
  55 + * @author :lyh
  56 + * @method :post
  57 + * @time :2023/9/6 10:18
  58 + */
  59 + public function addHrManager(){
  60 + $managerModel = new Manage();
  61 + $info = $managerModel->read(['mobile'=>$this->param['mobile']]);
  62 + if($info !== false){
  63 + $this->fail('当前号码已存在');
  64 + }
  65 + $data = [
  66 + 'name'=>$this->param['name'],
  67 + 'mobile'=>$this->param['mobile'],
  68 + 'password'=>Hash::make('globalsov6'),
  69 + 'gid'=>4,
  70 + ];
44 DB::beginTransaction(); 71 DB::beginTransaction();
45 try { 72 try {
46 - if(isset($this->param['id']) && !empty($this->param['id'])){  
47 - $this->model->edit($this->param,['id'=>$this->param['id']]);  
48 - }else{  
49 - //添加管理员账号  
50 - $this->param['manage_id'] = $this->addManager($this->param['mobile'],$this->param['name']);  
51 - $this->model->add($this->param); 73 + $managerModel = new Manage();
  74 + $this->param['manage_id'] = $managerModel->addReturnId($data);
  75 + $this->model->add($this->param);
  76 + DB::commit();
  77 + }catch (\Exception $e){
  78 + DB::rollBack();
  79 + $this->fail('系统错误请联系管理员');
  80 + }
  81 + return $this->success();
  82 + }
  83 +
  84 + /**
  85 + * @remark :编辑人事信息
  86 + * @name :editHrManager
  87 + * @author :lyh
  88 + * @method :post
  89 + * @time :2023/9/20 15:06
  90 + */
  91 + public function editHrManager(){
  92 + $hrInfo = $this->model->read(['id'=>$this->param['id']],['id','mobile','manage_id']);
  93 + if($hrInfo === false){
  94 + $this->fail('当前数据不存在或已被删除');
  95 + }
  96 + $managerModel = new Manage();
  97 + if($hrInfo['mobile'] != $this->param['mobile']){
  98 + $mobileInfo = $this->model->read(['mobile'=>$this->param['mobile']],['id']);
  99 + if($mobileInfo !== false){
  100 + $this->fail('当前人事信息中手机号已存在');
52 } 101 }
  102 + $managerMobileInfo = $managerModel->read(['mobile'=>$this->param['mobile']],['id']);
  103 + if($managerMobileInfo !== false){
  104 + $this->fail('当前管理员信息中手机号已存在');
  105 + }
  106 + }
  107 + DB::beginTransaction();
  108 + try {
  109 + //同步更新管理员手机号码
  110 + $managerModel->edit(['mobile'=>$this->param['mobile']],['id'=>$hrInfo['manage_id']]);
  111 + $this->model->edit($this->param,['id'=>$this->param['id']]);
53 DB::commit(); 112 DB::commit();
54 }catch (\Exception $e){ 113 }catch (\Exception $e){
55 DB::rollBack(); 114 DB::rollBack();
56 - $this->fail('系统错误'); 115 + $this->fail('系统错误,请联系管理员');
57 } 116 }
58 return $this->success(); 117 return $this->success();
59 } 118 }
@@ -81,6 +140,13 @@ class HrLogic extends BaseLogic @@ -81,6 +140,13 @@ class HrLogic extends BaseLogic
81 return $this->success($data); 140 return $this->success($data);
82 } 141 }
83 142
  143 + /**
  144 + * @remark :转换
  145 + * @name :setJson
  146 + * @author :lyh
  147 + * @method :post
  148 + * @time :2023/9/20 15:23
  149 + */
84 //数组转json存储 150 //数组转json存储
85 public function setJson($str,$param){ 151 public function setJson($str,$param){
86 if(isset($param[$str]) && is_array($param[$str])){ 152 if(isset($param[$str]) && is_array($param[$str])){
@@ -194,27 +260,6 @@ class HrLogic extends BaseLogic @@ -194,27 +260,6 @@ class HrLogic extends BaseLogic
194 return $this->success($data); 260 return $this->success($data);
195 } 261 }
196 262
197 - /**  
198 - * @remark :添加人事信息时 同步添加管理员账号  
199 - * @name :addManager  
200 - * @author :lyh  
201 - * @method :post  
202 - * @time :2023/9/6 10:18  
203 - */  
204 - public function addManager($mobile,$name){  
205 - $managerModel = new Manage();  
206 - $info = $managerModel->read(['mobile'=>$mobile]);  
207 - if($info !== false){  
208 - $this->fail('当前号码已存在');  
209 - }  
210 - $data = [  
211 - 'name'=>$name,  
212 - 'mobile'=>$mobile,  
213 - 'password'=>Hash::make('globalsov6'),  
214 - 'gid'=>4,  
215 - ];  
216 - return $managerModel->addReturnId($data);  
217 - }  
218 263
219 /** 264 /**
220 * @param $page_size 265 * @param $page_size
@@ -6,6 +6,7 @@ namespace App\Http\Logic\Aside\Manage; @@ -6,6 +6,7 @@ namespace App\Http\Logic\Aside\Manage;
6 use App\Helper\Common; 6 use App\Helper\Common;
7 use App\Http\Logic\Aside\BaseLogic; 7 use App\Http\Logic\Aside\BaseLogic;
8 use App\Models\Manage\Manage; 8 use App\Models\Manage\Manage;
  9 +use App\Models\Manage\ManageHr;
9 use App\Models\Manage\Menu; 10 use App\Models\Manage\Menu;
10 use Illuminate\Support\Facades\Cache; 11 use Illuminate\Support\Facades\Cache;
11 use Illuminate\Support\Facades\Hash; 12 use Illuminate\Support\Facades\Hash;
@@ -35,22 +36,65 @@ class ManageLogic extends BaseLogic @@ -35,22 +36,65 @@ class ManageLogic extends BaseLogic
35 public function managerSave(){ 36 public function managerSave(){
36 try { 37 try {
37 if(isset($this->param['id']) && !empty($this->param['id'])){ 38 if(isset($this->param['id']) && !empty($this->param['id'])){
38 - if(isset($this->param['password']) && !empty($this->param['password'])){  
39 - $this->param['password'] = Hash::make($this->param['password']);  
40 - }  
41 - $this->model->edit($this->param,['id'=>$this->param['id']]); 39 + $this->editManager();
42 Common::del_user_cache('manager',$this->param['id'],'A'); 40 Common::del_user_cache('manager',$this->param['id'],'A');
43 }else{ 41 }else{
44 - $this->param['password'] = Hash::make($this->param['password']);  
45 - $this->model->add($this->param); 42 + $this->addManager();
46 } 43 }
47 }catch (\Exception $e){ 44 }catch (\Exception $e){
48 $this->fail('系统错误,请联系管理员'); 45 $this->fail('系统错误,请联系管理员');
49 } 46 }
50 -  
51 return $this->success(); 47 return $this->success();
52 } 48 }
53 49
  50 + /**
  51 + * @remark :添加管理员
  52 + * @name :addManager
  53 + * @author :lyh
  54 + * @method :post
  55 + * @time :2023/9/20 15:49
  56 + */
  57 + public function addManager(){
  58 + $managerInfo = $this->model->read(['mobile'=>$this->param['mobile']]);
  59 + if($managerInfo !== false){
  60 + $this->fail('当前手机号码已存在');
  61 + }
  62 + $this->param['password'] = Hash::make($this->param['password']);
  63 + $this->model->add($this->param);
  64 + $this->success();
  65 + }
  66 +
  67 + /**
  68 + * @remark :编辑管理员
  69 + * @name :editManager
  70 + * @author :lyh
  71 + * @method :post
  72 + * @time :2023/9/20 15:51
  73 + */
  74 + public function editManager(){
  75 + $info = $this->model->read(['id'=>$this->param['id']]);
  76 + if($info['mobile'] != $this->param['mobile']){
  77 + $mobileInfo = $this->model->read(['mobile'=>$this->param['mobile']]);
  78 + if($mobileInfo !== false){
  79 + $this->fail('当前手机号码在管理员信息中已存在');
  80 + }
  81 + //查看人事信息中是否关联当前管理员账号
  82 + $hrManagerModel = new ManageHr();
  83 + $hrInfo = $hrManagerModel->read(['manage_id'=>$this->param['id']]);
  84 + if($hrInfo !== false){
  85 + //查看是否号码在存在人事表中
  86 + $hrMobileInfo = $hrManagerModel->read(['mobile'=>$this->param['mobile']]);
  87 + if($hrMobileInfo !== false){
  88 + $this->fail('当前号码已存在人事信息中');
  89 + }
  90 + $hrManagerModel->edit(['mobile'=>$this->param['mobile']],['manage_id'=>$this->param['id']]);
  91 + }
  92 + }
  93 + if(isset($this->param['password']) && !empty($this->param['password'])){
  94 + $this->param['password'] = Hash::make($this->param['password']);
  95 + }
  96 + $this->model->edit($this->param,['id'=>$this->param['id']]);
  97 + }
54 98
55 /** 99 /**
56 * @remark :设置排序 100 * @remark :设置排序
@@ -75,14 +119,10 @@ class ManageLogic extends BaseLogic @@ -75,14 +119,10 @@ class ManageLogic extends BaseLogic
75 * @time :2023/8/28 16:10 119 * @time :2023/8/28 16:10
76 */ 120 */
77 public function getManagerInfo(){ 121 public function getManagerInfo(){
78 - $info = Common::get_user_cache('manager',$this->param['id'],'A');  
79 - if(empty($info)){  
80 - $info = $this->model->read(['id'=>$this->param['id']],  
81 - ['id','name','email','mobile','status','gid','sort','dept_id','is_dept_manager','created_at','role','updated_at']);  
82 - if($info === false){  
83 - $this->fail('error');  
84 - }  
85 - Common::set_user_cache($info,'manager',$this->param['id'],'A'); 122 + $info = $this->model->read(['id'=>$this->param['id']],
  123 + ['id','name','email','mobile','status','gid','sort','dept_id','is_dept_manager','created_at','role','updated_at']);
  124 + if($info === false){
  125 + $this->fail('error');
86 } 126 }
87 return $this->success($info); 127 return $this->success($info);
88 } 128 }