Channelfunctionmanage.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\admin\controller\auth;
  3. use app\common\controller\Backend;
  4. class Channelfunctionmanage extends Backend
  5. {
  6. protected $model = null;
  7. protected $relationModel = null;
  8. public function _initialize()
  9. {
  10. parent::_initialize();
  11. $this->model = model("ChannelSpecialManage");
  12. }
  13. /**
  14. * 查看
  15. */
  16. public function index()
  17. {
  18. //设置过滤方法
  19. $this->request->filter(['strip_tags']);
  20. if ($this->request->isAjax()) {
  21. //如果发送的来源是Selectpage,则转发到Selectpage
  22. if ($this->request->request('pkey_name')) {
  23. return $this->selectpage();
  24. }
  25. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  26. $aWhere = ['type' => 2];
  27. $total = $this->model
  28. ->where($where)
  29. ->where($aWhere)
  30. ->order($sort, $order)
  31. ->count();
  32. $list = $this->model
  33. ->where($where)
  34. ->where($aWhere)
  35. ->order($sort, $order)
  36. ->limit($offset, $limit)
  37. ->select();
  38. $result = array("total" => $total, "rows" => $list);
  39. return json($result);
  40. }
  41. return $this->view->fetch();
  42. }
  43. /**
  44. * 关联渠道
  45. */
  46. public function operate()
  47. {
  48. if ($this->request->isAjax()) {
  49. $id = $this->request->param('id');
  50. $channelIds = $this->request->param('channel_ids');
  51. $operate = $this->request->param('method');
  52. $row = $this->model->get($id);
  53. if ($row) {
  54. //更新
  55. $menuRow = model("ChannelMenuList")->where('id', 'eq', $row['channel_id'])->find();
  56. if ($menuRow) {
  57. $hasChannelIds = explode(',', $menuRow['channel_id']);
  58. if ($hasChannelIds) {
  59. if ($operate == 'add') {
  60. if ($channelIds == "*") {
  61. $updateChannelIds = "*";
  62. } else {
  63. $channelIds = explode(',', $channelIds);
  64. $updateChannelIds = implode(',', array_unique(array_merge($hasChannelIds, $channelIds)));
  65. }
  66. } else {
  67. if ($channelIds == "*") {
  68. $updateChannelIds = '';
  69. } else {
  70. $channelIds = explode(',', $channelIds);
  71. $updateChannelIdsArr = array_diff($hasChannelIds, $channelIds);
  72. $updateChannelIds = '';
  73. if ($updateChannelIdsArr) {
  74. $updateChannelIds = implode(',', $updateChannelIdsArr);
  75. }
  76. }
  77. }
  78. } else {
  79. $updateChannelIds = $channelIds;
  80. }
  81. model("ChannelMenuList")->update(['channel_id' => $updateChannelIds, 'updatetime' => time()], ['id' => $menuRow['id']]);
  82. } else {
  83. //新增
  84. $insertId = model("ChannelMenuList")->allowField(true)->insertGetId([
  85. 'channel_id' => $channelIds,
  86. 'updatetime' => time(),
  87. 'createtime' => time()]);
  88. $this->model->update(['channel_id' => $insertId, 'updatetime' => time()], ['id' => $row['id']]);
  89. }
  90. $row->removeCache($row['rule_name']);
  91. } else {
  92. //新增
  93. exit(json_encode(['code' => 201, 'msg' => '记录不存在']));
  94. }
  95. }
  96. exit(json_encode(['code' => 200]));
  97. }
  98. }