Frontlimit.php 4.2 KB

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