Channelfufen.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use app\common\library\Redis;
  5. use app\common\model\Admin;
  6. use app\main\constants\AdminConstants;
  7. use app\main\constants\CacheConstants;
  8. use app\main\service\FufenService;
  9. /**
  10. * 管理员管理
  11. *
  12. * @icon fa fa-circle-o
  13. */
  14. class Channelfufen extends Backend
  15. {
  16. /**
  17. * @var Admin
  18. */
  19. protected $model = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = model('Admin');
  24. }
  25. public function index($ids = '')
  26. {
  27. $this->assignconfig('data', ['fufenid' => $ids]);
  28. if ($this->request->isAjax()) {
  29. list($where, $sort, $order, $offset, $limit) = $this->buildparams('', true);
  30. $channelIdList = FufenService::instance()->getFufenGroupModel()->column('channel_ids');
  31. $whereChannel = [];
  32. if ($channelIdList) {
  33. $channelIds = [];
  34. foreach ($channelIdList as $ids) {
  35. $channelIds = array_merge($channelIds, explode(',', $ids));
  36. }
  37. $whereChannel['admin.id'] = ['not in', array_unique($channelIds)];
  38. }
  39. $total = $this->model
  40. ->join('auth_group_access aga', 'aga.uid=admin.id')
  41. ->join('admin_extend ae', 'ae.admin_id=admin.id')
  42. ->where('aga.group_id', AdminConstants::ADMIN_GROUP_ID_CHANNEL)
  43. ->where($whereChannel)
  44. ->where($where)
  45. ->count();
  46. $list = $this->model
  47. ->join('auth_group_access aga', 'aga.uid=admin.id')
  48. ->join('admin_extend ae', 'ae.admin_id=admin.id')
  49. ->join('admin_config ac', 'ac.admin_id=admin.id')
  50. ->join('admin a', 'a.id=ae.create_by')
  51. ->where('aga.group_id', AdminConstants::ADMIN_GROUP_ID_CHANNEL)
  52. ->where($whereChannel)
  53. ->where($where)
  54. ->field('admin.id,admin.username,admin.nickname,ac.appid,a.nickname as c_nickname')
  55. ->limit($offset, $limit)
  56. ->order($sort, $order)
  57. ->select();
  58. return json(["total" => $total, "rows" => $list]);
  59. }
  60. return $this->view->fetch();
  61. }
  62. /**
  63. * 批量关联
  64. */
  65. public function batch_relation()
  66. {
  67. $channelids = $this->request->param('channel_ids');
  68. $fufenid = $this->request->param('fufen_id');
  69. $action = $this->request->param('action');
  70. $origin = FufenService::instance()->getFufenGroupModel()->where(['id' => $fufenid])->value('channel_ids');
  71. $origin_array = explode(',', $origin);
  72. $params = explode(',', $channelids);
  73. $all_ids = array_unique(array_merge($origin_array, $params));
  74. if ($action == 'add') {
  75. $update = $all_ids;
  76. } else {
  77. $update = array_unique(array_diff($origin_array, $params));
  78. }
  79. $update = array_filter($update, function($value){
  80. return $value;
  81. });
  82. foreach ($all_ids as $channel_id) {
  83. Redis::instance()->del(CacheConstants::getChannelWxpayIds($channel_id));
  84. }
  85. FufenService::instance()->getFufenGroupModel()->update(['channel_ids' => implode(',', $update)], ['id' => $fufenid]);
  86. $this->success();
  87. }
  88. public function show($ids = '')
  89. {
  90. $this->assignconfig('data', ['fufenid' => $ids]);
  91. if ($this->request->isAjax()) {
  92. $channelIds = FufenService::instance()->getFufenGroupModel()->where('id', $ids)->value('channel_ids');
  93. if ($channelIds) {
  94. list($where, $sort, $order, $offset, $limit) = $this->buildparams('', true);
  95. $whereChannel = [
  96. 'admin.id' => ['in', $channelIds],
  97. ];
  98. $total = $this->model
  99. ->join('auth_group_access aga', 'aga.uid=admin.id')
  100. ->join('admin_extend ae', 'ae.admin_id=admin.id')
  101. ->where('aga.group_id', AdminConstants::ADMIN_GROUP_ID_CHANNEL)
  102. ->where($whereChannel)
  103. ->where($where)
  104. ->count();
  105. $list = $this->model
  106. ->join('auth_group_access aga', 'aga.uid=admin.id')
  107. ->join('admin_extend ae', 'ae.admin_id=admin.id')
  108. ->join('admin_config ac', 'ac.admin_id=admin.id')
  109. ->join('admin a', 'a.id=ae.create_by')
  110. ->where('aga.group_id', AdminConstants::ADMIN_GROUP_ID_CHANNEL)
  111. ->where($whereChannel)
  112. ->where($where)
  113. ->field('admin.id,admin.username,admin.nickname,ac.appid,a.nickname as c_nickname')
  114. ->limit($offset, $limit)
  115. ->order($sort, $order)
  116. ->select();
  117. return json(["total" => $total, "rows" => $list]);
  118. } else {
  119. return json(["total" => 0, "rows" => []]);
  120. }
  121. }
  122. return $this->view->fetch();
  123. }
  124. }