Talent.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\AdminBaseController;
  4. use app\common\model\TalentUserModel;
  5. use app\common\model\TalentWorkModel;
  6. use app\common\validate\TalentUserValidate;
  7. use think\exception\ValidateException;
  8. use think\facade\Validate;
  9. class Talent extends AdminBaseController
  10. {
  11. /**
  12. * 用户列表
  13. */
  14. public function user()
  15. {
  16. return view('', [
  17. 'status_list' => TalentUserModel::STATUS,
  18. ]);
  19. }
  20. public function listUser()
  21. {
  22. $map = $this->dealEqualInput(['status'], $this->dealLikeInput(['name', 'mobile', 'department']));
  23. $list = TalentUserModel::where($map)
  24. ->limit(input('limit'))
  25. ->page(input('page'))
  26. ->append(['status_text'])->select();
  27. $count = TalentUserModel::where($map)->count();
  28. if ($count == 0) {
  29. ajax_return(1, '未查询到数据');
  30. }
  31. list_return($list, $count);
  32. }
  33. public function delUser()
  34. {
  35. $id = input('id/d', 0);
  36. if (empty($id)) {
  37. ajax_return(1, '未查询到数据');
  38. }
  39. $check = TalentWorkModel::where('user_id', $id)->find();
  40. if (!empty($check)) {
  41. ajax_return(1, '该用户已有人才挂钩工作登记表记录,无法删除');
  42. }
  43. TalentUserModel::destroy($id);
  44. ajax_return();
  45. }
  46. /**
  47. * 编辑用户
  48. */
  49. public function userForm()
  50. {
  51. $id = input('id/d', 0);
  52. $info = TalentUserModel::find($id);
  53. return view('', [
  54. 'info' => $info,
  55. 'status_list' => TalentUserModel::STATUS,
  56. ]);
  57. }
  58. public function editUser()
  59. {
  60. $data = input('post.');
  61. try {
  62. validate(TalentUserValidate::class)->check($data);
  63. } catch (ValidateException $e) {
  64. ajax_return(1, $e->getError());
  65. }
  66. //手机号
  67. $check_mobile_where = [['mobile', '=', $data['mobile']]];
  68. if (!empty($data['id'])) {
  69. $check_mobile_where[] = ['id', '<>', $data['id']];
  70. }
  71. $check_mobile = TalentUserModel::where($check_mobile_where)->find();
  72. if (!empty($check_mobile)) {
  73. ajax_return(1, '手机号已存在');
  74. }
  75. //密码
  76. if (empty($data['id']) && empty($data['password'])) {
  77. ajax_return(1, '请输入一个初始密码');
  78. }
  79. if (empty($data['password'])) {
  80. unset($data['password']);
  81. } else {
  82. $data['salt'] = rand_str();
  83. $data['password'] = md5(md5($data['salt']) . $data['password']);
  84. }
  85. if (empty($data['id'])) {
  86. TalentUserModel::create($data);
  87. } else {
  88. TalentUserModel::update($data, ['id' => $data['id']]);
  89. }
  90. ajax_return();
  91. }
  92. /**
  93. * 用户导入
  94. */
  95. public function importUser()
  96. {
  97. return view('public/import', [
  98. 'url' => url('talent/importUserPost'),
  99. 'last_table' => 'lay-talent-user-table',
  100. 'template_file' => '/static/common/exl/talent_user.xls',
  101. ]);
  102. }
  103. /**
  104. * 用户导入提交
  105. */
  106. public function importUserPost()
  107. {
  108. $file_url = input('file_url/s', "");
  109. if (!file_exists($file_url)) {
  110. ajax_return(1, '文件不存在');
  111. }
  112. //初始化数据
  113. $data = ['name', 'department', 'mobile'];
  114. $list = import_exl($file_url, $data, 1);
  115. if (empty($list)) {
  116. ajax_return(1, '请上传有数据的文件');
  117. }
  118. $empty_check = [
  119. 'name' => '姓名',
  120. 'department' => '部门',
  121. 'mobile' => '手机号',
  122. ];
  123. //获取手机号
  124. $mobile_list = array_column($list, 'mobile');
  125. $mobile_check_list = TalentUserModel::where('mobile', 'in', $mobile_list)->column('mobile');
  126. //错误判断
  127. $validate = Validate::rule('mobile', 'mobile');
  128. $time = time();
  129. foreach ($list as $k => $v) {
  130. foreach ($empty_check as $key => $value) {
  131. if (empty($v[$key])) {
  132. return ajax_return(1, '第' . ($k + 2) . '行的' . $value . '不能为空');
  133. }
  134. }
  135. if (!$validate->check($v)) {
  136. return ajax_return(1, '第' . ($k + 2) . '行的手机号格式不对');
  137. }
  138. if (!empty(in_array($v['mobile'], $mobile_check_list))) {
  139. return ajax_return(1, '第' . ($k + 2) . '行的手机号已存在');
  140. }
  141. $list[$k]['salt'] = rand_str();
  142. $list[$k]['password'] = md5(md5($list[$k]['salt']) . '123456');
  143. $list[$k]['create_time'] = $list[$k]['update_time'] = $time;
  144. }
  145. TalentUserModel::insertAll($list);
  146. ajax_return(0);
  147. }
  148. /**
  149. * 挂钩工作登记表
  150. */
  151. public function work()
  152. {
  153. return view();
  154. }
  155. public function listWork()
  156. {
  157. $model = new TalentWorkModel();
  158. $param = input('param.');
  159. //姓名
  160. if (!empty($param['name'])) {
  161. $model = $model->where([
  162. ['user_id', 'in', function ($query) use ($param) {
  163. $query->name('talent_user')->field('id')->where('name', 'like', "%{$param['name']}%")->buildSql();
  164. }],
  165. ]);
  166. }
  167. //部门
  168. if (!empty($param['department'])) {
  169. $model = $model->where([
  170. ['user_id', 'in', function ($query) use ($param) {
  171. $query->name('talent_user')->field('id')->where('department', 'like', "%{$param['department']}%")->buildSql();
  172. }],
  173. ]);
  174. }
  175. //手机号
  176. if (!empty($param['mobile'])) {
  177. $model = $model->where([
  178. ['user_id', 'in', function ($query) use ($param) {
  179. $query->name('talent_user')->field('id')->where('mobile', 'like', "%{$param['mobile']}%")->buildSql();
  180. }],
  181. ]);
  182. }
  183. //月份
  184. if (!empty($param['month'])) {
  185. $model = $model->where('month', $param['month']);
  186. }
  187. $list = $model->with('user')->limit(input('limit'))->page(input('page'))->order('update_time desc')->select();
  188. $count = $model->count();
  189. if ($count == 0) {
  190. ajax_return(1, '未查询到数据');
  191. }
  192. list_return($list, $count);
  193. }
  194. public function workDetail()
  195. {
  196. $id = input('id', 0);
  197. if (empty($id)) {
  198. return '数据错误,请关闭';
  199. }
  200. $info = TalentWorkModel::with('user')->where('id', $id)->find();
  201. if (empty($info)) {
  202. return '数据错误,请关闭';
  203. }
  204. return view('', [
  205. 'info' => $info,
  206. ]);
  207. }
  208. /**
  209. * 未登记用户
  210. */
  211. public function unRegister()
  212. {
  213. $month = date('Y-m');
  214. return view('', [
  215. 'month' => $month,
  216. ]);
  217. }
  218. public function unRegisterPost()
  219. {
  220. $month = input('month', '');
  221. if (empty($month)) {
  222. ajax_return();
  223. }
  224. $user_ids = TalentUserModel::where('status', TalentUserModel::STATUS_NORMAL)->column('id');
  225. $register_ids = TalentWorkModel::where('month', $month)->column('user_id');
  226. $diff_id = array_diff($user_ids, $register_ids);
  227. $user = TalentUserModel::where('id', 'in', $diff_id)->select();
  228. $res = [];
  229. foreach ($user as $item) {
  230. $res[] = $item['name'] . "(" . $item['department'] . ")";
  231. }
  232. ajax_return(0, '', implode(',', $res));
  233. }
  234. /**
  235. * 导出挂钩工作登记表
  236. */
  237. public function exportWork()
  238. {
  239. $model = new TalentWorkModel();
  240. $param = input('param.');
  241. if (!empty($param['id'])) {
  242. $model = $model->where('id', 'in', $param['id']);
  243. }
  244. //姓名
  245. if (!empty($param['name'])) {
  246. $model = $model->where([
  247. ['user_id', 'in', function ($query) use ($param) {
  248. $query->name('talent_user')->field('id')->where('name', 'like', "%{$param['name']}%")->buildSql();
  249. }],
  250. ]);
  251. }
  252. //部门
  253. if (!empty($param['department'])) {
  254. $model = $model->where([
  255. ['user_id', 'in', function ($query) use ($param) {
  256. $query->name('talent_user')->field('id')->where('department', 'like', "%{$param['department']}%")->buildSql();
  257. }],
  258. ]);
  259. }
  260. //手机号
  261. if (!empty($param['mobile'])) {
  262. $model = $model->where([
  263. ['user_id', 'in', function ($query) use ($param) {
  264. $query->name('talent_user')->field('id')->where('mobile', 'like', "%{$param['mobile']}%")->buildSql();
  265. }],
  266. ]);
  267. }
  268. //月份
  269. if (!empty($param['month'])) {
  270. $model = $model->where('month', $param['month']);
  271. }
  272. $list = $model->with('user')->order('update_time desc')->select();
  273. foreach ($list as $v) {
  274. $v['user_name'] = $v['user']['name'];
  275. $v['user_department'] = $v['user']['department'];
  276. $v['user_mobile'] = $v['user']['mobile'];
  277. $v['contact_text'] = implode(',', $v['contact']);
  278. $v['cate_text'] = implode(',', $v['cate']);
  279. }
  280. $xlsCell = [
  281. ['user_name', '姓名'],
  282. ['user_department', '部门'],
  283. ['user_mobile', '手机号'],
  284. ['month', '月份'],
  285. ['should_num', '应挂钩人数'],
  286. ['new_num', '本月新增人数'],
  287. ['unfinished_num', '未完成挂钩人数'],
  288. ['reason', '未挂钩联系原因'],
  289. ['consult_num', '本月回答咨询次数'],
  290. ['contact_text', '联系方式'],
  291. ['cate_text', '咨询问题类别'],
  292. ['description', '具体问题描述及解决措施描述'],
  293. ['assist', '需协调事项说明'],
  294. ['update_time', '填表时间'],
  295. ];
  296. export_exl("挂钩工作登记表", $xlsCell, $list);
  297. }
  298. }