Specialist.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\controller\base\Permissions;
  4. use think\Db;
  5. class Specialist extends Permissions
  6. {
  7. private function getModel()
  8. {
  9. return new \app\common\model\Specialist();
  10. }
  11. public function index()
  12. {
  13. if ($this->request->isAjax()) {
  14. $post = $this->request->param();
  15. $where = [];
  16. if (isset($post['ids']) and !empty($post['ids'])) {
  17. $where['id'] = ['in', $post['ids']];
  18. }
  19. if (!empty($post["name"])) {
  20. $where["name"] = ['like', '%' . $post["name"] . '%'];
  21. }
  22. if (!empty($post["title"])) {
  23. $where["title"] = ['like', '%' . $post["title"] . '%'];
  24. }
  25. if (!empty($post["head_pic"])) {
  26. $where["head_pic"] = ['like', '%' . $post["head_pic"] . '%'];
  27. }
  28. if (isset($post["sex"]) and "" != $post["sex"]) {
  29. $where["sex"] = $post["sex"];
  30. }
  31. if (!empty($post["desc"])) {
  32. $where["desc"] = ['like', '%' . $post["desc"] . '%'];
  33. }
  34. if (!empty($post["consultation_direction"])) {
  35. $where["consultation_direction"] = ['like', '%' . $post["consultation_direction"] . '%'];
  36. }
  37. if (isset($post["address_id"]) and "" != $post["address_id"]) {
  38. $where["address_id"] = $post["address_id"];
  39. }
  40. if (isset($post["module"]) and "" != $post["module"]) {
  41. $where["module"] = $post["module"];
  42. }
  43. $model = $this->getModel();
  44. $count = $model->where($where)->count();
  45. $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('id desc')->select();
  46. $boxsIdAndName = (new \app\common\model\ConfigOption())->where(['pid' => 2])->column('name', 'id');
  47. foreach ($data as $key => $value) {
  48. $value['head_pic_url'] = geturl($value['head_pic']);
  49. $value['sex_text'] = $value->sex_text;
  50. $value['address_name'] = $value->address ? $value->address->title : '';
  51. $value['module_name'] = $boxsIdAndName[$value->module]??'';
  52. $data[$key] = $value;
  53. }
  54. return array('code' => 0, 'count' => $count, 'data' => $data);
  55. } else {
  56. $this->assign('addresslist', \app\common\model\Address::all());
  57. $boxs = (new \app\common\model\ConfigOption())->where(['pid' => 2, 'status' => \app\common\model\ConfigOption::STATUS_OPEN])->order('sort desc')->select();
  58. $this->assign('modules', $boxs);
  59. return $this->fetch();
  60. }
  61. }
  62. public function publish()
  63. {
  64. $id = $this->request->param('id', 0, 'intval');
  65. $model = $this->getModel();
  66. $post = $this->request->post();
  67. if ($this->request->isPost()) {
  68. //验证
  69. $validate = new \think\Validate([
  70. ['name|名字', 'require|max:50'],
  71. ['title|职称', 'require|max:50'],
  72. ['head_pic|头像', 'max:255'],
  73. ['sex|性别', 'number'],
  74. ['desc|简介', 'max:500'],
  75. ['consultation_direction|咨询方向', 'max:500'],
  76. ['address_id|地址', 'require|number'],
  77. ['phone|联系电话', 'max:50'],
  78. ]);
  79. if (!$validate->check($post)) {
  80. $this->error('提交失败:' . $validate->getError());
  81. }
  82. } else {
  83. $this->assign('addresslist', \app\common\model\Address::all());
  84. $boxs = (new \app\common\model\ConfigOption())->where(['pid' => 2, 'status' => \app\common\model\ConfigOption::STATUS_OPEN])->order('sort desc')->select();
  85. $this->assign('modules', $boxs);
  86. }
  87. if ($id > 0) {
  88. //修改
  89. $data = $model->where('id', $id)->find();
  90. if (empty($data)) {
  91. $this->error('id不正确');
  92. }
  93. if ($this->request->isPost()) {
  94. if (false == $model->allowField(true)->save($post, ['id' => $id])) {
  95. $this->error('修改失败');
  96. } else {
  97. $this->success('修改成功');
  98. }
  99. } else {
  100. $this->assign('data', $data);
  101. return $this->fetch();
  102. }
  103. } else {
  104. //新增
  105. if ($this->request->isPost()) {
  106. if (false == $model->allowField(true)->save($post)) {
  107. $this->error('添加失败');
  108. } else {
  109. //新增放号设置记录
  110. $webconfig = \app\common\model\Webconfig::get(1);
  111. $data['provider_id'] = $model->id;
  112. $data['weeks'] = $webconfig->weeks;
  113. $data['morning_time_periods'] = $webconfig->morning_time_periods;
  114. $data['afternoon_time_periods'] = $webconfig->afternoon_time_periods;
  115. (new \app\common\model\Appointment())->allowField(true)->save($data);
  116. $this->success('添加成功', 'index');
  117. }
  118. } else {
  119. return $this->fetch();
  120. }
  121. }
  122. }
  123. public function delete()
  124. {
  125. if ($this->request->isAjax()) {
  126. $id = $this->request->param('id', 0, 'intval');
  127. if (false == $this->getModel()->where('id', $id)->delete()) {
  128. $this->error('删除失败');
  129. } else {
  130. $this->success('删除成功', 'index');
  131. }
  132. }
  133. }
  134. public function deletes()
  135. {
  136. if ($this->request->isAjax()) {
  137. $post = $this->request->param();
  138. $ids = $post['ids'];
  139. if ($this->getModel()->where('id', 'in', $ids)->delete()) {
  140. $this->success('删除成功');
  141. }
  142. }
  143. }
  144. }