Messages.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace app\admin\controller\messages;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use think\Exception;
  6. use think\exception\PDOException;
  7. /**
  8. * 消息管理
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class Messages extends Backend
  13. {
  14. /**
  15. * MessagesModel模型对象
  16. * @var \app\admin\model\messages\MessagesModel
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = new \app\admin\model\messages\MessagesModel;
  23. }
  24. /**
  25. * 查看
  26. */
  27. public function index()
  28. {
  29. //设置过滤方法
  30. $this->request->filter(['strip_tags']);
  31. if ($this->request->isAjax()) {
  32. //如果发送的来源是Selectpage,则转发到Selectpage
  33. if ($this->request->request('keyField')) {
  34. return $this->selectpage();
  35. }
  36. list($where, $sort, $order, $offset, $limit) = $this->buildparams($this->searchFields, true);
  37. $join = [
  38. ['doctors d','m.doctor_id = d.id','LEFT'],
  39. ['institution i','m.institution_id = i.id','LEFT'],
  40. ['department de','m.department_id = de.id','LEFT'],
  41. ];
  42. $field = ['m.*','d.realname as doctor_name','i.name as institution_name','de.department_name'];
  43. // 过滤机构
  44. $childInsIds = $this->auth->getMyInsId();
  45. if($childInsIds == false){
  46. $more = false;
  47. } else {
  48. $more = ['m.institution_id' => ['in', $childInsIds]];
  49. }
  50. $total = $this->model->alias('m')
  51. ->join($join)
  52. ->where($more)
  53. ->where($where)
  54. ->order($sort, $order)
  55. ->count();
  56. $list = $this->model->alias('m')
  57. ->join($join)
  58. ->where($more)
  59. ->where($where)
  60. ->order($sort, $order)
  61. ->limit($offset, $limit)
  62. ->field($field)
  63. ->select();
  64. $list = collection($list)->toArray();
  65. $result = array("total" => $total, "rows" => $list);
  66. return json($result);
  67. }
  68. return $this->view->fetch();
  69. }
  70. /**
  71. * 删除
  72. */
  73. public function del($ids = "")
  74. {
  75. if ($ids) {
  76. $pk = $this->model->getPk();
  77. $adminIds = $this->getDataLimitAdminIds();
  78. if (is_array($adminIds)) {
  79. $this->model->where($this->dataLimitField, 'in', $adminIds);
  80. }
  81. $list = $this->model->where($pk, 'in', $ids)->select();
  82. $count = 0;
  83. Db::startTrans();
  84. try {
  85. $update = [
  86. 'status' => '1'
  87. ];
  88. foreach ($list as $k => $v) {
  89. $count += $v->where('id',$v['id'])->update($update);
  90. }
  91. Db::commit();
  92. } catch (PDOException $e) {
  93. Db::rollback();
  94. $this->error($e->getMessage());
  95. } catch (Exception $e) {
  96. Db::rollback();
  97. $this->error($e->getMessage());
  98. }
  99. if ($count) {
  100. $this->success();
  101. } else {
  102. $this->error(__('No rows were deleted'));
  103. }
  104. }
  105. $this->error(__('Parameter %s can not be empty', 'ids'));
  106. }
  107. }