123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace app\admin\controller\messages;
- use app\common\controller\Backend;
- use think\Db;
- use think\Exception;
- use think\exception\PDOException;
- /**
- * 消息管理
- *
- * @icon fa fa-circle-o
- */
- class Messages extends Backend
- {
-
- /**
- * MessagesModel模型对象
- * @var \app\admin\model\messages\MessagesModel
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\messages\MessagesModel;
- }
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams($this->searchFields, true);
- $join = [
- ['doctors d','m.doctor_id = d.id','LEFT'],
- ['institution i','m.institution_id = i.id','LEFT'],
- ['department de','m.department_id = de.id','LEFT'],
- ];
- $field = ['m.*','d.realname as doctor_name','i.name as institution_name','de.department_name'];
- // 过滤机构
- $childInsIds = $this->auth->getMyInsId();
- if($childInsIds == false){
- $more = false;
- } else {
- $more = ['m.institution_id' => ['in', $childInsIds]];
- }
- $total = $this->model->alias('m')
- ->join($join)
- ->where($more)
- ->where($where)
- ->order($sort, $order)
- ->count();
- $list = $this->model->alias('m')
- ->join($join)
- ->where($more)
- ->where($where)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->field($field)
- ->select();
- $list = collection($list)->toArray();
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 删除
- */
- public function del($ids = "")
- {
- if ($ids) {
- $pk = $this->model->getPk();
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- $this->model->where($this->dataLimitField, 'in', $adminIds);
- }
- $list = $this->model->where($pk, 'in', $ids)->select();
- $count = 0;
- Db::startTrans();
- try {
- $update = [
- 'status' => '1'
- ];
- foreach ($list as $k => $v) {
- $count += $v->where('id',$v['id'])->update($update);
- }
- Db::commit();
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($count) {
- $this->success();
- } else {
- $this->error(__('No rows were deleted'));
- }
- }
- $this->error(__('Parameter %s can not be empty', 'ids'));
- }
- }
|