123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <?php
- namespace app\admin\controller\user;
- use app\common\controller\Backend;
- use app\common\library\Auth;
- use Think\Db;
- use app\common\library\Token;
- class User extends Backend
- {
-
- protected $searchFields = 'id,username,nickname';
- protected $selectpageFields = 'id,username,nickname,mobile';
-
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\User;
- $this->view->assign("realStatusList", $this->model->getRealStatusList());
- $this->view->assign("genderList", $this->model->getGenderList());
- $this->view->assign("idcardStatusList", $this->model->getIdcardStatusList());
- $this->view->assign("statusList", $this->model->getStatusList());
- $this->view->assign("isKefuList", $this->model->getIsKefuList());
- $this->view->assign("isRecommendList", $this->model->getIsRecommendList());
- $this->view->assign("isAgentList", $this->model->getIsAgentList());
- $this->view->assign("openMatchVideoList", $this->model->getOpenMatchVideoList());
- $this->view->assign("openMatchAudioList", $this->model->getOpenMatchAudioList());
- $this->view->assign("openMatchTypingList", $this->model->getOpenMatchTypingList());
- $this->view->assign("freeVideoList", $this->model->getFreeVideoList());
- $this->view->assign("freeAudioList", $this->model->getFreeAudioList());
- $this->view->assign("freeTypingList", $this->model->getFreeTypingList());
- $typeList = [
- 'statusList' => $this->model->getStatusList(),
- ];
- $this->view->assign($typeList);
- $this->assignconfig($typeList);
- }
- 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(['wallet'])
- ->where($where)
- ->order($sort, $order)
- ->paginate($limit);
- $day = 1;
- $wday = date('w');
- $wday_start = strtotime(date('Y-m-d', strtotime('-' . ($wday ? $wday - $day : 6) . ' day')));
- $week_map = [
- 'log_type' => ['in', [21, 22, 23, 54, 60, 72, 82 ]]
- ];
- $mt_user = Db::name('user');
- $mt_user_money_log = Db::name('user_money_log');
- $mt_pay_order = Db::name('pay_order');
- $mt_user_wallet = Db::name('user_wallet');
- $time = time();
- foreach ($list as $row) {
- $row->getRelation('wallet')->visible(['pay_money', 'get_money','vip_endtime']);
- $week_map['user_id'] = $row['id'];
-
-
-
-
-
- $week_map['createtime'] = ['egt', $wday_start];
-
-
- $week_map['createtime'] = ['between', [$wday_start - 86400 * 7, $wday_start]];
-
-
-
-
-
-
- }
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- 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) {
- $params = $this->preExcludeFields($params);
- $result = false;
- if ($params['mobile']) {
- $exists = db('user')->where('mobile', $params['mobile'])->where('id', '<>', $row['id'])->find();
- if ($exists) {
- $this->error('手机号已经被其他人使用');
- }
- }
-
- if (isset($params['intro_uid']) && $params['intro_uid'] != 0) {
- if ($params['intro_uid'] == $row['id']) {
- $this->error('推荐人ID不能填写自己');
- }
- $intro_user = db('user')->field('id, intro_uid')->where('id', $params['intro_uid'])->find();
- if(!$intro_user){
- $this->error('不存在推荐人');
- }
- if ($intro_user['intro_uid'] == $row['id']) {
- $this->error('不能填写下级邀请码作为推荐人');
- }
- }
- Db::startTrans();
- 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);
- }
- $result = $row->allowField(true)->save($params);
- if ($params['status'] != 1 || (isset($params['frozentime']) && strtotime($params['frozentime']) > time())) {
-
- Token::clear($row['id']);
- }
- Db::commit();
- } catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
- $this->success();
- } else {
- $this->error(__('No rows were updated'));
- }
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $this->view->assign("row", $row);
- return $this->view->fetch();
- }
- }
|