| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 | 
							- <?php
 
- namespace app\admin\controller;
 
- use app\admin\controller\base\Permissions;
 
- use think\Db;
 
- class Specialist extends Permissions
 
- {
 
-     private function getModel()
 
-     {
 
-         return new \app\common\model\Specialist();
 
-     }
 
-     public function index()
 
-     {
 
-         if ($this->request->isAjax()) {
 
-             $post = $this->request->param();
 
-             $where = [];
 
-             if (isset($post['ids']) and !empty($post['ids'])) {
 
-                 $where['id'] = ['in', $post['ids']];
 
-             }
 
-             if (!empty($post["name"])) {
 
-                 $where["name"] = ['like', '%' . $post["name"] . '%'];
 
-             }
 
-             if (!empty($post["title"])) {
 
-                 $where["title"] = ['like', '%' . $post["title"] . '%'];
 
-             }
 
-             if (!empty($post["head_pic"])) {
 
-                 $where["head_pic"] = ['like', '%' . $post["head_pic"] . '%'];
 
-             }
 
-             if (isset($post["sex"]) and "" != $post["sex"]) {
 
-                 $where["sex"] = $post["sex"];
 
-             }
 
-             if (!empty($post["desc"])) {
 
-                 $where["desc"] = ['like', '%' . $post["desc"] . '%'];
 
-             }
 
-             if (!empty($post["consultation_direction"])) {
 
-                 $where["consultation_direction"] = ['like', '%' . $post["consultation_direction"] . '%'];
 
-             }
 
-             if (isset($post["address_id"]) and "" != $post["address_id"]) {
 
-                 $where["address_id"] = $post["address_id"];
 
-             }
 
-             if (isset($post["module"]) and "" != $post["module"]) {
 
-                 $where["module"] = $post["module"];
 
-             }
 
-             $model = $this->getModel();
 
-             $count = $model->where($where)->count();
 
-             $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('id desc')->select();
 
-             $boxsIdAndName = (new \app\common\model\ConfigOption())->where(['pid' => 2])->column('name', 'id');
 
-             foreach ($data as $key => $value) {
 
-                 $value['head_pic_url'] = geturl($value['head_pic']);
 
-                 $value['sex_text'] = $value->sex_text;
 
-                 $value['address_name'] = $value->address ? $value->address->title : '';
 
-                 $value['module_name'] = $boxsIdAndName[$value->module]??'';
 
-                 $data[$key] = $value;
 
-             }
 
-             return array('code' => 0, 'count' => $count, 'data' => $data);
 
-         } else {
 
-             $this->assign('addresslist', \app\common\model\Address::all());
 
-             $boxs = (new \app\common\model\ConfigOption())->where(['pid' => 2, 'status' => \app\common\model\ConfigOption::STATUS_OPEN])->order('sort desc')->select();
 
-             $this->assign('modules', $boxs);
 
-             return $this->fetch();
 
-         }
 
-     }
 
-     public function publish()
 
-     {
 
-         $id = $this->request->param('id', 0, 'intval');
 
-         $model = $this->getModel();
 
-         $post = $this->request->post();
 
-         if ($this->request->isPost()) {
 
-             //验证
 
-             $validate = new \think\Validate([
 
-                 ['name|名字', 'require|max:50'],
 
-                 ['title|职称', 'require|max:50'],
 
-                 ['head_pic|头像', 'max:255'],
 
-                 ['sex|性别', 'number'],
 
-                 ['desc|简介', 'max:500'],
 
-                 ['consultation_direction|咨询方向', 'max:500'],
 
-                 ['address_id|地址', 'require|number'],
 
-                 ['phone|联系电话', 'max:50'],
 
-             ]);
 
-             if (!$validate->check($post)) {
 
-                 $this->error('提交失败:' . $validate->getError());
 
-             }
 
-         } else {
 
-             $this->assign('addresslist', \app\common\model\Address::all());
 
-             $boxs = (new \app\common\model\ConfigOption())->where(['pid' => 2, 'status' => \app\common\model\ConfigOption::STATUS_OPEN])->order('sort desc')->select();
 
-             $this->assign('modules', $boxs);
 
-         }
 
-         if ($id > 0) {
 
-             //修改
 
-             $data = $model->where('id', $id)->find();
 
-             if (empty($data)) {
 
-                 $this->error('id不正确');
 
-             }
 
-             if ($this->request->isPost()) {
 
-                 if (false == $model->allowField(true)->save($post, ['id' => $id])) {
 
-                     $this->error('修改失败');
 
-                 } else {
 
-                     $this->success('修改成功');
 
-                 }
 
-             } else {
 
-                 $this->assign('data', $data);
 
-                 return $this->fetch();
 
-             }
 
-         } else {
 
-             //新增
 
-             if ($this->request->isPost()) {
 
-                 if (false == $model->allowField(true)->save($post)) {
 
-                     $this->error('添加失败');
 
-                 } else {
 
-                     //新增放号设置记录
 
-                     $webconfig = \app\common\model\Webconfig::get(1);
 
-                     $data['provider_id'] = $model->id;
 
-                     $data['weeks'] = $webconfig->weeks;
 
-                     $data['morning_time_periods'] = $webconfig->morning_time_periods;
 
-                     $data['afternoon_time_periods'] = $webconfig->afternoon_time_periods;
 
-                     (new \app\common\model\Appointment())->allowField(true)->save($data);
 
-                     $this->success('添加成功', 'index');
 
-                 }
 
-             } else {
 
-                 return $this->fetch();
 
-             }
 
-         }
 
-     }
 
-     public function delete()
 
-     {
 
-         if ($this->request->isAjax()) {
 
-             $id = $this->request->param('id', 0, 'intval');
 
-             if (false == $this->getModel()->where('id', $id)->delete()) {
 
-                 $this->error('删除失败');
 
-             } else {
 
-                 $this->success('删除成功', 'index');
 
-             }
 
-         }
 
-     }
 
-     public function deletes()
 
-     {
 
-         if ($this->request->isAjax()) {
 
-             $post = $this->request->param();
 
-             $ids = $post['ids'];
 
-             if ($this->getModel()->where('id', 'in', $ids)->delete()) {
 
-                 $this->success('删除成功');
 
-             }
 
-         }
 
-     }
 
- }
 
 
  |