UserPower.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Exception;
  5. /**
  6. * 会员权限管理
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class UserPower extends Backend
  11. {
  12. /**
  13. * UserPower模型对象
  14. * @var \app\admin\model\UserPower
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\UserPower;
  21. $this->view->assign("privateMessagesList", $this->model->getPrivateMessagesList());
  22. $this->view->assign("speakList", $this->model->getSpeakList());
  23. $this->view->assign("rechargeList", $this->model->getRechargeList());
  24. $this->view->assign("raffleList", $this->model->getRaffleList());
  25. $this->view->assign("giveGiftList", $this->model->getGiveGiftList());
  26. $this->view->assign("transferList", $this->model->getTransferList());
  27. $this->view->assign("payorderList", $this->model->getPayorderList());
  28. $this->view->assign("attireList", $this->model->getAttireList());
  29. $this->view->assign("nobleList", $this->model->getNobleList());
  30. $this->view->assign("withdrawList", $this->model->getWithdrawList());
  31. }
  32. public function import()
  33. {
  34. parent::import();
  35. }
  36. /**
  37. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  38. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  39. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  40. */
  41. /**
  42. * 查看
  43. */
  44. public function index()
  45. {
  46. //当前是否为关联查询
  47. $this->relationSearch = true;
  48. //设置过滤方法
  49. $this->request->filter(['strip_tags', 'trim']);
  50. if ($this->request->isAjax()) {
  51. //如果发送的来源是Selectpage,则转发到Selectpage
  52. if ($this->request->request('keyField')) {
  53. return $this->selectpage();
  54. }
  55. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  56. $list = $this->model
  57. ->with(['user'])
  58. ->where($where)
  59. ->order($sort, $order)
  60. ->paginate($limit);
  61. foreach ($list as $row) {
  62. $row->getRelation('user')->visible(['nickname','mobile','avatar']);
  63. }
  64. $result = array("total" => $list->total(), "rows" => $list->items());
  65. return json($result);
  66. }
  67. return $this->view->fetch();
  68. }
  69. /**
  70. * 添加
  71. */
  72. public function add()
  73. {
  74. if ($this->request->isPost()) {
  75. $params = $this->request->post("row/a");
  76. $params = $this->preExcludeFields($params);
  77. if (!$params) {
  78. $this->error(__('Parameter %s can not be empty', ''));
  79. }
  80. $result = false;
  81. try {
  82. //是否采用模型验证
  83. if ($this->modelValidate) {
  84. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  85. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  86. $this->model->validateFailException(true)->validate($validate);
  87. }
  88. if (isset($params['private_messages_time']) && !empty($params['private_messages_time'])) {
  89. $params['private_messages_time'] = strtotime($params['private_messages_time']);
  90. }
  91. if (isset($params['speak_time']) && !empty($params['speak_time'])) {
  92. $params['speak_time'] = strtotime($params['speak_time']);
  93. }
  94. $result = $this->model->allowField(true)->save($params);
  95. } catch (ValidateException|PDOException|Exception $e) {
  96. $this->error($e->getMessage());
  97. }
  98. if ($result == false) {
  99. $this->error(__('No rows were inserted'));
  100. }
  101. $this->success();
  102. }
  103. return $this->view->fetch();
  104. }
  105. /**
  106. * 编辑
  107. */
  108. public function edit($ids = null)
  109. {
  110. $row = $this->model->get($ids);
  111. if (!$row) {
  112. $this->error(__('No Results were found'));
  113. }
  114. $adminIds = $this->getDataLimitAdminIds();
  115. if (is_array($adminIds)) {
  116. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  117. $this->error(__('You have no permission'));
  118. }
  119. }
  120. if ($this->request->isPost()) {
  121. $params = $this->request->post("row/a");
  122. if (!$params) {
  123. $this->error(__('Parameter %s can not be empty', ''));
  124. }
  125. $params = $this->preExcludeFields($params);
  126. $result = false;
  127. try {
  128. //是否采用模型验证
  129. if ($this->modelValidate) {
  130. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  131. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  132. $row->validateFailException(true)->validate($validate);
  133. }
  134. if (isset($params['private_messages_time']) && !empty($params['private_messages_time'])) {
  135. $params['private_messages_time'] = strtotime($params['private_messages_time']);
  136. } else {
  137. $params['private_messages_time'] = 0;
  138. }
  139. if (isset($params['speak_time']) && !empty($params['speak_time'])) {
  140. $params['speak_time'] = strtotime($params['speak_time']);
  141. } else {
  142. $params['speak_time'] = 0;
  143. }
  144. $result = $row->allowField(true)->save($params);
  145. } catch (ValidateException|PDOException|Exception $e) {
  146. $this->error($e->getMessage());
  147. }
  148. if ($result == false) {
  149. $this->error(__('No rows were updated'));
  150. }
  151. $this->success('操作成功');
  152. }
  153. $this->view->assign("row", $row);
  154. return $this->view->fetch();
  155. }
  156. /**
  157. * 一键禁用
  158. */
  159. public function powerBan($ids = null)
  160. {
  161. try {
  162. $row = $this->model->get($ids);
  163. if (!$row) {
  164. throw new Exception(__('No Results were found'));
  165. }
  166. $adminIds = $this->getDataLimitAdminIds();
  167. if (is_array($adminIds)) {
  168. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  169. throw new Exception(__('You have no permission'));
  170. }
  171. }
  172. $data = [
  173. 'private_messages' => 2,//禁止私聊:0=正常,1=禁止.2=禁止(永久)
  174. 'private_messages_time' => 0,//禁止私聊时间
  175. 'speak' => 2,//禁言弹幕:0=正常,1=禁止.2=禁止(永久)
  176. 'speak_time' => 0,//禁言时间
  177. 'recharge' => 1,//充值:0=正常,1=禁止
  178. 'raffle' => 1,//抽奖:0=正常,1=禁止
  179. 'give_gift' => 1,//赠送礼物:0=正常,1=禁止
  180. 'transfer' => 1,//转账:0=正常,1=禁止
  181. 'payorder' => 1,//下单:0=正常,1=禁止
  182. 'attire' => 1,//购买装扮:0=正常,1=禁止
  183. 'noble' => 1,//开通贵族:0=正常,1=禁止
  184. 'withdraw' => 1,//提现:0=允许,1=禁止
  185. ];
  186. $where['id'] = $ids;
  187. $res = $this->model->update($data,$where);
  188. $this->success('操作成功');
  189. } catch (Exception $e) {
  190. $this->error($e->getMessage());
  191. }
  192. }
  193. /**
  194. * 一键解禁
  195. */
  196. public function powerUnban($ids = null)
  197. {
  198. try {
  199. $row = $this->model->get($ids);
  200. if (!$row) {
  201. throw new Exception(__('No Results were found'));
  202. }
  203. $adminIds = $this->getDataLimitAdminIds();
  204. if (is_array($adminIds)) {
  205. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  206. throw new Exception(__('You have no permission'));
  207. }
  208. }
  209. $data = [
  210. 'private_messages' => 0,//禁止私聊:0=正常,1=禁止.2=禁止(永久)
  211. 'private_messages_time' => 0,//禁止私聊时间
  212. 'speak' => 0,//禁言弹幕:0=正常,1=禁止.2=禁止(永久)
  213. 'speak_time' => 0,//禁言时间
  214. 'recharge' => 0,//充值:0=正常,1=禁止
  215. 'raffle' => 0,//抽奖:0=正常,1=禁止
  216. 'give_gift' => 0,//赠送礼物:0=正常,1=禁止
  217. 'transfer' => 0,//转账:0=正常,1=禁止
  218. 'payorder' => 0,//下单:0=正常,1=禁止
  219. 'attire' => 0,//购买装扮:0=正常,1=禁止
  220. 'noble' => 0,//开通贵族:0=正常,1=禁止
  221. 'withdraw' => 0,//提现:0=允许,1=禁止
  222. ];
  223. $where['id'] = $ids;
  224. $res = $this->model->update($data,$where);
  225. $this->success('操作成功');
  226. } catch (Exception $e) {
  227. $this->error($e->getMessage());
  228. }
  229. }
  230. }