AdminMatchmakerController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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\matchmaker\controller;
  12. use app\matchmaker\model\MatchmakerModel;
  13. use app\matchmaker\model\MatchmakerUserModel;
  14. use cmf\controller\AdminBaseController;
  15. use think\db\Query;
  16. class AdminMatchmakerController extends AdminBaseController
  17. {
  18. /**
  19. * 红娘管理
  20. */
  21. public function index()
  22. {
  23. $name = $this->request->param('name');
  24. $mobile = $this->request->param('mobile');
  25. $list = MatchmakerModel::where(function (Query $query) use ($name, $mobile) {
  26. if ($name) {
  27. $query->where('name', 'like', "%$name%");
  28. }
  29. if ($mobile) {
  30. $query->where('mobile', 'like', "%$mobile%");
  31. }
  32. })
  33. ->order("id DESC")
  34. ->paginate(10);
  35. $list->appends(['name' => $name, 'mobile' => $mobile]);
  36. // 获取分页显示
  37. $page = $list->render();
  38. $this->assign("page", $page);
  39. $this->assign("list", $list);
  40. return $this->fetch();
  41. }
  42. /**
  43. * 添加
  44. */
  45. public function add()
  46. {
  47. return $this->fetch();
  48. }
  49. /**
  50. * 添加提交
  51. */
  52. public function addPost()
  53. {
  54. if ($this->request->isPost()) {
  55. $data = $this->request->param();
  56. $post = $data['post'];
  57. $post['password'] = trim($post['password']);
  58. MatchmakerModel::create($post);
  59. $this->success('添加成功!', url('index'));
  60. }
  61. }
  62. /**
  63. * 编辑
  64. */
  65. public function edit()
  66. {
  67. $id = $this->request->param('id', 0, 'intval');
  68. $post = MatchmakerModel::get($id);
  69. $this->assign('post', $post);
  70. return $this->fetch();
  71. }
  72. /**
  73. * 编辑提交
  74. */
  75. public function editPost()
  76. {
  77. if ($this->request->isPost()) {
  78. $data = $this->request->param();
  79. $post = $data['post'];
  80. $post['password'] = trim($post['password']);
  81. if (empty($post['password'])) {
  82. unset($post['password']);
  83. }
  84. MatchmakerModel::update($post, ['id' => $post['id']]);
  85. $this->success('编辑成功!', url('index'));
  86. }
  87. }
  88. /**
  89. * 删除
  90. */
  91. public function delete()
  92. {
  93. $id = $this->request->param('id');
  94. if (empty($id)) {
  95. $this->error('参数错误');
  96. }
  97. $check = MatchmakerUserModel::where('matchmaker_id',$id)->find();
  98. if (!empty($check)) {
  99. $this->error('该红娘下还有人员,无法删除');
  100. }
  101. MatchmakerModel::destroy($id);
  102. $this->success('删除成功!');
  103. }
  104. }