MsgPushConfig.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\admin\controller\msgPushConfig;
  3. use app\admin\controller\Base;
  4. use app\common\model\base\org\OrgRole;
  5. use app\common\model\msgPushConfig\MsgPushConfig as MsgPushConfigModel;
  6. class MsgPushConfig extends Base
  7. {
  8. protected $model = null;
  9. public function initialize()
  10. {
  11. parent::initialize();
  12. $this->model = new MsgPushConfigModel;
  13. }
  14. /**
  15. * @title:创建统一查询条件
  16. * @desc: 描述
  17. * @param {string} {keyword} {} {搜索关键词,可搜索角色类型分类|角色分类名称|关联角色类型}
  18. * @return {*}
  19. * @author: 系统开发
  20. * @method: POST
  21. * @Date: 2025-01-18 16:58:47
  22. */
  23. private function createWhere()
  24. {
  25. $data = $this->request->param();
  26. $where = [];
  27. $whereOr = [];
  28. if (!empty($data['org_id'])) {
  29. $where[] = ['org_id', '=', $data['org_id']];
  30. }
  31. return ['where' => $where, 'whereOr' => $whereOr];
  32. }
  33. /**
  34. * @title:查询数据列表
  35. * @desc: 描述
  36. * @param {string} {keyword} {} {搜索关键词,可搜索角色类型分类|角色分类名称|关联角色类型}
  37. * @param {int} {pageNo} {0} {页码}
  38. * @param {int} {pageSize} {10} {每页数量}
  39. * @return {*}
  40. * @author: 系统开发
  41. * @method: POST
  42. * @Date: 2025-01-18 16:58:47
  43. */
  44. public function getList(int $pageNo = 0, int $pageSize = 10)
  45. {
  46. $whereAry = $this->createWhere();
  47. if (!empty($pageNo)) {
  48. $res = $this->model->where($whereAry['where'])->with([
  49. "org" => function ($query) {
  50. $query->field('org_id,name');
  51. },
  52. ])->paginate(['page' => $pageNo, 'list_rows' => $pageSize]);
  53. $list = $res->items();
  54. foreach ($list as $k => $v) {
  55. $v['role_name'] = OrgRole::where('role_id', 'in', $v['role_ids'])->column('name');
  56. $v['role_name'] = implode(',', $v['role_name'] );
  57. }
  58. return pageRes(1, '获取成功', $res->total(), $list);
  59. } else {
  60. $list = $this->model->where($whereAry['where'])->select();
  61. return res(1, '获取成功', $list);
  62. }
  63. }
  64. /**
  65. * @title:新增/编辑信息
  66. * @desc: 描述
  67. * @param {int} {id} {} {主键ID,不传或传0表示新增,大于0表示修改}
  68. * @return {*}
  69. * @author: 系统开发
  70. * @method: POST
  71. * @Date: 2025-01-18 16:58:47
  72. */
  73. public function doEdit()
  74. {
  75. $data = $this->request->param();
  76. if (empty($data['org_id'])) return res(2, '请选择组织');
  77. if (empty($data['role_ids'])) return res(2, '请选择角色');
  78. if (is_array($data['role_ids'])) {
  79. $data['role_ids'] = implode(',', $data['role_ids']);
  80. }
  81. $res = $this->model->replace()->save($data);
  82. return res(1, '编辑成功');
  83. }
  84. /**
  85. * @title:删除信息
  86. * @desc: 描述
  87. * @param {int} id {} {信息ID}
  88. * @return {*}
  89. * @author: 系统开发
  90. * @method: POST
  91. * @Date: 2025-01-18 16:58:47
  92. */
  93. public function doDelete(int $id = 0)
  94. {
  95. $info = $this->model->find($id);
  96. $info->delete();
  97. return res(1, '删除成功');
  98. }
  99. }