Talent.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\user\controller;
  15. use app\base\BaseController;
  16. use app\user\model\Talent as TalentModel;
  17. use app\user\validate\TalentValidate;
  18. use think\exception\ValidateException;
  19. use Overtrue\Pinyin\Pinyin;
  20. use think\facade\Db;
  21. use think\facade\View;
  22. class Talent extends BaseController
  23. {
  24. /**
  25. * 构造函数
  26. */
  27. protected $model;
  28. public function __construct()
  29. {
  30. parent::__construct(); // 调用父类构造函数
  31. $this->model = new TalentModel();
  32. }
  33. /**
  34. * 数据列表
  35. */
  36. public function datalist()
  37. {
  38. $param = get_params();
  39. if (request()->isAjax()) {
  40. $param = get_params();
  41. $tab = isset($param['tab']) ? $param['tab'] : 0;
  42. $uid = $this->uid;
  43. $where = array();
  44. $whereOr = array();
  45. $where[]=['delete_time','=',0];
  46. if($tab == 0){
  47. //全部
  48. $auth = isAuth($uid,'office_admin','conf_1');
  49. if($auth == 0){
  50. $whereOr[] = ['admin_id', '=', $this->uid];
  51. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  52. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  53. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  54. $dids_a = get_leader_departments($uid);
  55. $dids_b = get_role_departments($uid);
  56. $dids = array_merge($dids_a, $dids_b);
  57. if(!empty($dids)){
  58. $whereOr[] = ['did','in',$dids];
  59. }
  60. }
  61. }
  62. if($tab == 1){
  63. //我创建的
  64. $where[] = ['admin_id', '=', $this->uid];
  65. }
  66. if($tab == 2){
  67. //待我审核的
  68. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  69. }
  70. if($tab == 3){
  71. //我已审核的
  72. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  73. }
  74. if($tab == 4){
  75. //抄送给我的
  76. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  77. }
  78. if (isset($param['check_status']) && $param['check_status'] != "") {
  79. $where[] = ['check_status', '=', $param['check_status']];
  80. }
  81. if (!empty($param['keywords'])) {
  82. $where[] = ['name|mobile', 'like', '%' . $param['keywords'] . '%'];
  83. }
  84. if (!empty($param['did'])) {
  85. $where[] = ['to_did', '=',$param['did']];
  86. }
  87. //按时间检索
  88. if (!empty($param['entry_time'])) {
  89. $entry_time =explode('~', $param['entry_time']);
  90. $where[] = ['entry_time', 'between', [strtotime(urldecode($entry_time[0])),strtotime(urldecode($entry_time[1]))]];
  91. }
  92. $list = $this->model->datalist($param,$where,$whereOr);
  93. return table_assign(0, '', $list);
  94. }
  95. else{
  96. View::assign('is_auth', isAuth($this->uid,'office_admin','conf_1'));
  97. return view();
  98. }
  99. }
  100. /**
  101. * 添加/编辑
  102. */
  103. public function add()
  104. {
  105. $param = get_params();
  106. if (request()->isAjax()) {
  107. $param['entry_time'] = empty($param['entry_time']) ? '0':strtotime($param['entry_time']);
  108. $count_a=0;
  109. $count_b=0;
  110. if(!empty($param['idcard'])){
  111. $count_a = Db::name('Blacklist')->where([['idcard','=',$param['idcard']],['delete_time','=',0]])->count();
  112. }
  113. if(!empty($param['mobile'])){
  114. $count_b = Db::name('Blacklist')->where([['mobile','=',$param['mobile']],['delete_time','=',0]])->count();
  115. }
  116. if($count_a>0 || $count_b>0){
  117. return to_assign(1, '该员工的信息已被列入黑名单,不支持申请');
  118. }
  119. $count_c = Db::name('Admin')->where([['mobile','=',$param['mobile']],['status','in',['0,1']],['delete_time','=',0]])->count();
  120. $count_d = Db::name('Admin')->where([['email','=',$param['email']],['status','in',['0,1']],['delete_time','=',0]])->count();
  121. if($count_c>0){
  122. return to_assign(1, '该手机号已被其他员工占用,不支持申请');
  123. }
  124. if($count_d>0){
  125. return to_assign(1, '该邮箱已被其他员工占用,不支持申请');
  126. }
  127. if (!empty($param['id']) && $param['id'] > 0) {
  128. try {
  129. validate(IndexValidate::class)->scene('edit')->check($param);
  130. } catch (ValidateException $e) {
  131. // 验证失败 输出错误信息
  132. return to_assign(1, $e->getError());
  133. }
  134. $this->model->edit($param);
  135. } else {
  136. try {
  137. validate(IndexValidate::class)->scene('add')->check($param);
  138. } catch (ValidateException $e) {
  139. // 验证失败 输出错误信息
  140. return to_assign(1, $e->getError());
  141. }
  142. $param['admin_id'] = $this->uid;
  143. $param['did'] = $this->did;
  144. $this->model->add($param);
  145. }
  146. }else{
  147. $id = isset($param['id']) ? $param['id'] : 0;
  148. if ($id>0) {
  149. $detail = $this->model->getById($id);
  150. View::assign('detail', $detail);
  151. }
  152. $position = Db::name('Position')->where([['status', '>=', 0]])->order('create_time asc')->select();
  153. View::assign('position', $position);
  154. View::assign('id', $id);
  155. if(is_mobile()){
  156. return view('qiye@/approve/add_talent');
  157. }
  158. return view();
  159. }
  160. }
  161. /**
  162. * 查看
  163. */
  164. public function view($id)
  165. {
  166. $detail = $this->model->getById($id);
  167. if (!empty($detail)) {
  168. $detail['department'] = Db::name('Department')->where('id', '=', $detail['to_did'])->value('title');
  169. $detail['position'] = Db::name('Position')->where('id', '=', $detail['position_id'])->value('title');
  170. View::assign('detail', $detail);
  171. if(is_mobile()){
  172. return view('qiye@/approve/view_talent');
  173. }
  174. return view();
  175. }
  176. else{
  177. return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
  178. }
  179. }
  180. /**
  181. * 删除
  182. */
  183. public function del()
  184. {
  185. $id = get_params("id");
  186. if (request()->isDelete()) {
  187. $this->model->delById($id);
  188. } else {
  189. return to_assign(1, "错误的请求");
  190. }
  191. }
  192. /**
  193. * 转为正式员工
  194. */
  195. public function set()
  196. {
  197. $param = get_params();
  198. if (request()->isAjax()) {
  199. $param['update_time'] = time();
  200. $param['entry_time'] = strtotime($param['entry_time']);
  201. Db::name('Talent')->strict(false)->field(true)->update($param);
  202. $detail = Db::name('Talent')->where('id', $param['id'])->find();
  203. $count_a = Db::name('Admin')->where([['status', 'in', [0,1]],['mobile','=',$detail['mobile']],['delete_time','=',0]])->count();
  204. if($count_a>0){
  205. return to_assign(1, "同样的手机号码已经存在,请检查一下是否被离职或者禁用员工占用");
  206. }
  207. $detail['nickname'] = $detail['name'];
  208. $char = $detail['name'];
  209. $username = Pinyin::name($char,'none')->join('');
  210. $detail['username'] = $this->create_name($username,0);
  211. $detail['did'] = $detail['to_did'];
  212. $detail['salt'] = set_salt(20);
  213. $detail['reg_pwd'] = $param['reg_pwd'];
  214. $detail['thumb'] = get_file($detail['thumb']);
  215. $detail['pwd'] = set_password($detail['reg_pwd'], $detail['salt']);
  216. $detail['talent_id'] = $detail['id'];
  217. unset($detail['id']);
  218. $uid = Db::name('Admin')->strict(false)->field(true)->insertGetId($detail);
  219. if($uid!==false){
  220. Db::name('Talent')->where('id',$param ['id'])->update(['status'=>2]);
  221. add_log('add', $uid, $param);
  222. return to_assign();
  223. }
  224. else {
  225. return to_assign(1, "操作失败");
  226. }
  227. }
  228. else{
  229. $position = Db::name('Position')->where([['status', '>=', 0]])->order('create_time asc')->select();
  230. $detail = $this->model->getById($param['id']);
  231. View::assign('position', $position);
  232. //初始化密码
  233. View::assign('reg_pwd', set_salt(6));
  234. View::assign('detail', $detail);
  235. if(is_mobile()){
  236. return view('qiye@/approve/set_talent');
  237. }
  238. return view();
  239. }
  240. }
  241. //生成登录名
  242. public function create_name($name,$id=0,$total=0,$old='')
  243. {
  244. $count = Db::name('Admin')->where([['username','=',$name],['id','<>',$id]])->count();
  245. if($total==0){
  246. $old = $name;
  247. }
  248. $total++;
  249. if($count>0){
  250. $newname = $old.$total;
  251. $name = $this->create_name($newname,$id,$total,$old);
  252. }
  253. return $name;
  254. }
  255. }