123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use think\Exception;
- class UserPower extends Backend
- {
-
-
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\UserPower;
- $this->view->assign("privateMessagesList", $this->model->getPrivateMessagesList());
- $this->view->assign("speakList", $this->model->getSpeakList());
- $this->view->assign("rechargeList", $this->model->getRechargeList());
- $this->view->assign("raffleList", $this->model->getRaffleList());
- $this->view->assign("giveGiftList", $this->model->getGiveGiftList());
- $this->view->assign("transferList", $this->model->getTransferList());
- $this->view->assign("payorderList", $this->model->getPayorderList());
- $this->view->assign("attireList", $this->model->getAttireList());
- $this->view->assign("nobleList", $this->model->getNobleList());
- $this->view->assign("withdrawList", $this->model->getWithdrawList());
- }
- public function import()
- {
- parent::import();
- }
-
-
-
- public function index()
- {
-
- $this->relationSearch = true;
-
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
-
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $list = $this->model
- ->with(['user'])
- ->where($where)
- ->order($sort, $order)
- ->paginate($limit);
- foreach ($list as $row) {
-
- $row->getRelation('user')->visible(['nickname','mobile','avatar']);
- }
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- return $this->view->fetch();
- }
-
- public function add()
- {
- if ($this->request->isPost()) {
- $params = $this->request->post("row/a");
- $params = $this->preExcludeFields($params);
- if (!$params) {
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $result = false;
- try {
-
- if ($this->modelValidate) {
- $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
- $this->model->validateFailException(true)->validate($validate);
- }
- if (isset($params['private_messages_time']) && !empty($params['private_messages_time'])) {
- $params['private_messages_time'] = strtotime($params['private_messages_time']);
- }
- if (isset($params['speak_time']) && !empty($params['speak_time'])) {
- $params['speak_time'] = strtotime($params['speak_time']);
- }
- $result = $this->model->allowField(true)->save($params);
- } catch (ValidateException|PDOException|Exception $e) {
- $this->error($e->getMessage());
- }
- if ($result == false) {
- $this->error(__('No rows were inserted'));
- }
- $this->success();
- }
- return $this->view->fetch();
- }
-
- public function edit($ids = null)
- {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- if (!in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- }
- if ($this->request->isPost()) {
- $params = $this->request->post("row/a");
- if (!$params) {
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $params = $this->preExcludeFields($params);
- $result = false;
- try {
-
- if ($this->modelValidate) {
- $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
- $row->validateFailException(true)->validate($validate);
- }
- if (isset($params['private_messages_time']) && !empty($params['private_messages_time'])) {
- $params['private_messages_time'] = strtotime($params['private_messages_time']);
- } else {
- $params['private_messages_time'] = 0;
- }
- if (isset($params['speak_time']) && !empty($params['speak_time'])) {
- $params['speak_time'] = strtotime($params['speak_time']);
- } else {
- $params['speak_time'] = 0;
- }
- $result = $row->allowField(true)->save($params);
- } catch (ValidateException|PDOException|Exception $e) {
- $this->error($e->getMessage());
- }
- if ($result == false) {
- $this->error(__('No rows were updated'));
- }
- $this->success('操作成功');
- }
- $this->view->assign("row", $row);
- return $this->view->fetch();
- }
-
- public function powerBan($ids = null)
- {
- try {
- $row = $this->model->get($ids);
- if (!$row) {
- throw new Exception(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- if (!in_array($row[$this->dataLimitField], $adminIds)) {
- throw new Exception(__('You have no permission'));
- }
- }
- $data = [
- 'private_messages' => 2,
- 'private_messages_time' => 0,
- 'speak' => 2,
- 'speak_time' => 0,
- 'recharge' => 1,
- 'raffle' => 1,
- 'give_gift' => 1,
- 'transfer' => 1,
- 'payorder' => 1,
- 'attire' => 1,
- 'noble' => 1,
- 'withdraw' => 1,
- ];
- $where['id'] = $ids;
- $res = $this->model->update($data,$where);
- $this->success('操作成功');
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- }
-
- public function powerUnban($ids = null)
- {
- try {
- $row = $this->model->get($ids);
- if (!$row) {
- throw new Exception(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- if (!in_array($row[$this->dataLimitField], $adminIds)) {
- throw new Exception(__('You have no permission'));
- }
- }
- $data = [
- 'private_messages' => 0,
- 'private_messages_time' => 0,
- 'speak' => 0,
- 'speak_time' => 0,
- 'recharge' => 0,
- 'raffle' => 0,
- 'give_gift' => 0,
- 'transfer' => 0,
- 'payorder' => 0,
- 'attire' => 0,
- 'noble' => 0,
- 'withdraw' => 0,
- ];
- $where['id'] = $ids;
- $res = $this->model->update($data,$where);
- $this->success('操作成功');
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- }
- }
|