AdminTalentAdminController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\talent\model\TalentAdminModel;
  13. use cmf\controller\AdminBaseController;
  14. class AdminTalentAdminController extends AdminBaseController
  15. {
  16. public function index()
  17. {
  18. $param = $this->request->param();
  19. //搜索条件
  20. $where = [];
  21. if (!empty($param['name'])) {
  22. $where[] = ['name', 'like', "%{$param['name']}%"];
  23. }
  24. if (!empty($param['account'])) {
  25. $where[] = ['account', 'like', "%{$param['account']}%"];
  26. }
  27. $list = TalentAdminModel::where($where)->paginate(10, false, ['query' => $param]);
  28. $this->assign('name', isset($param['name']) ? $param['name'] : '');
  29. $this->assign('account', isset($param['account']) ? $param['account'] : '');
  30. $this->assign('list', $list->items());
  31. $this->assign('page', $list->render());
  32. return $this->fetch();
  33. }
  34. public function add()
  35. {
  36. return $this->fetch();
  37. }
  38. public function addPost()
  39. {
  40. if ($this->request->isPost()) {
  41. $data = $this->request->post();
  42. TalentAdminModel::create($data);
  43. $this->success('添加成功!', url('index'));
  44. }
  45. }
  46. public function edit()
  47. {
  48. $id = $this->request->param('id', 0, 'intval');
  49. $info = TalentAdminModel::get($id);
  50. $this->assign('info', $info);
  51. return $this->fetch();
  52. }
  53. public function editPost()
  54. {
  55. if ($this->request->isPost()) {
  56. $data = $this->request->post();
  57. TalentAdminModel::update($data, ['id' => $data['id']]);
  58. $this->success('编辑成功!', url('index'));
  59. }
  60. }
  61. public function delete()
  62. {
  63. $id = $this->request->param('id', 0, 'intval');
  64. TalentAdminModel::destroy($id);
  65. $this->success('删除成功');
  66. }
  67. }