AdminTalentController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 小夏 < 449134904@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\talent\controller;
  12. use app\admin\model\UserModel;
  13. use app\talent\model\TalentModel;
  14. use cmf\controller\AdminBaseController;
  15. class AdminTalentController extends AdminBaseController
  16. {
  17. public function index()
  18. {
  19. $param = $this->request->param();
  20. //搜索条件
  21. $where = [];
  22. if (!empty($param['name'])) {
  23. $where[] = ['name', 'like', "%{$param['name']}%"];
  24. }
  25. if (!empty($param['card_no'])) {
  26. $where[] = ['card_no', 'like', "%{$param['card_no']}%"];
  27. }
  28. if (!empty($param['mobile'])) {
  29. $where[] = ['mobile', '=', $param['mobile']];
  30. }
  31. $list = TalentModel::where($where)->paginate(10, false, ['query' => $param]);
  32. $this->assign('name', isset($param['name']) ? $param['name'] : '');
  33. $this->assign('card_no', isset($param['card_no']) ? $param['card_no'] : '');
  34. $this->assign('mobile', isset($param['mobile']) ? $param['mobile'] : '');
  35. $this->assign('list', $list->items());
  36. $this->assign('page', $list->render());
  37. return $this->fetch();
  38. }
  39. public function add()
  40. {
  41. return $this->fetch();
  42. }
  43. public function addPost()
  44. {
  45. if ($this->request->isPost()) {
  46. $data = $this->request->post();
  47. TalentModel::create($data);
  48. $this->success('添加成功!', url('index'));
  49. }
  50. }
  51. public function edit()
  52. {
  53. $id = $this->request->param('id', 0, 'intval');
  54. $info = TalentModel::get($id);
  55. $this->assign('info', $info);
  56. return $this->fetch();
  57. }
  58. public function editPost()
  59. {
  60. if ($this->request->isPost()) {
  61. $data = $this->request->post();
  62. TalentModel::update($data, ['id' => $data['id']]);
  63. $this->success('编辑成功!', url('index'));
  64. }
  65. }
  66. public function delete()
  67. {
  68. $id = $this->request->param('id', 0, 'intval');
  69. TalentModel::destroy($id);
  70. UserModel::update(['talent_id' => 0], ['talent_id' => $id]);
  71. $this->success('删除成功');
  72. }
  73. public function clearBind()
  74. {
  75. $id = $this->request->param('id', 0, 'intval');
  76. UserModel::update(['talent_id' => 0], ['talent_id' => $id]);
  77. $this->success('操作成功');
  78. }
  79. public function setting()
  80. {
  81. $setting = cmf_get_option('talent_setting');
  82. $this->assign($setting);
  83. return $this->fetch();
  84. }
  85. public function settingPost()
  86. {
  87. $post = array_map('trim', $this->request->param());
  88. if (strlen($post['mobile']) != 11) {
  89. $this->error('手机号格式错误。');
  90. }
  91. cmf_set_option('talent_setting', $post);
  92. $this->success("保存成功!");
  93. }
  94. }