|
@@ -2,16 +2,7 @@
|
|
|
|
|
|
namespace app\admin\controller\user;
|
|
|
|
|
|
-use app\admin\model\Message;
|
|
|
-use app\admin\model\UserPower;
|
|
|
use app\common\controller\Backend;
|
|
|
-use app\common\library\Auth;
|
|
|
-use app\common\service\TenimService;
|
|
|
-use fast\Random;
|
|
|
-use think\Db;
|
|
|
-use think\Exception;
|
|
|
-use think\exception\PDOException;
|
|
|
-use think\exception\ValidateException;
|
|
|
|
|
|
/**
|
|
|
* 会员管理
|
|
@@ -20,11 +11,9 @@ use think\exception\ValidateException;
|
|
|
*/
|
|
|
class User extends Backend
|
|
|
{
|
|
|
-
|
|
|
- protected $relationSearch = true;
|
|
|
- protected $searchFields = 'u_id,username,nickname';
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
+ * User模型对象
|
|
|
* @var \app\admin\model\User
|
|
|
*/
|
|
|
protected $model = null;
|
|
@@ -32,383 +21,26 @@ class User extends Backend
|
|
|
public function _initialize()
|
|
|
{
|
|
|
parent::_initialize();
|
|
|
- $this->model = model('User');
|
|
|
- $typeList = [
|
|
|
- 'genderList' => $this->model->getGenderList(),
|
|
|
- 'isCoolList' => $this->model->getIsCoolList(),
|
|
|
- 'isManagerList' => $this->model->getIsManagerList(),
|
|
|
- 'isStealthList' => $this->model->getIsStealthList(),
|
|
|
- 'statusList' => $this->model->getStatusList(),
|
|
|
- 'needCheckList' => $this->model->getNeedCheckList(),
|
|
|
- ];
|
|
|
- $this->view->assign($typeList);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查看
|
|
|
- */
|
|
|
- public function index()
|
|
|
- {
|
|
|
- $this->relationSearch = true;
|
|
|
- //设置过滤方法
|
|
|
- $this->request->filter(['strip_tags', 'trim']);
|
|
|
- if ($this->request->isAjax()) {
|
|
|
- //如果发送的来源是Selectpage,则转发到Selectpage
|
|
|
- if ($this->request->request('keyField')) {
|
|
|
- return $this->selectpage();
|
|
|
- }
|
|
|
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
- $list = $this->model
|
|
|
- ->with(['noble','preuser','auth','age','userwallet'])
|
|
|
- ->where($where)
|
|
|
- ->order($sort, $order)
|
|
|
- ->paginate($limit);
|
|
|
- foreach ($list as $k => $v) {
|
|
|
- $v->avatar = $v->avatar ? cdnurl($v->avatar, true) : letter_avatar($v->nickname);
|
|
|
- $v->hidden(['password', 'salt']);
|
|
|
- $v->getRelation('age')->visible(['name']);
|
|
|
- $v->getRelation('userwallet')->visible(['money','jewel']);
|
|
|
- }
|
|
|
- $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;
|
|
|
- Db::startTrans();
|
|
|
- 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 (empty($params['avatar'])) {
|
|
|
- $params['avatar'] = '/assets/img/default_avatar.png';
|
|
|
- }
|
|
|
- $ids = $this->model->column("u_id");
|
|
|
- $invite_no = $this->model->column("invite_no");
|
|
|
- $params['u_id'] = $this->model->getUinqueId(8, [$ids]);
|
|
|
- $params['invite_no'] = $this->model->getUinqueNo(8, $invite_no);
|
|
|
- if (empty($params['nickname'])) {
|
|
|
- $params['nickname'] = 'gg_'.$params['u_id'];
|
|
|
- }
|
|
|
- $params['image'] = '/assets/img/default_avatar.png';
|
|
|
- $params['username'] = $params['mobile'];
|
|
|
- $params['status'] = 'normal';
|
|
|
- $params['salt'] = Random::alnum();
|
|
|
- $params['has_info'] = 1;
|
|
|
- $result = $this->model->allowField(true)->save($params);
|
|
|
- $userId = $this->model->id;
|
|
|
- //权限
|
|
|
- $userPower = new UserPower();
|
|
|
- $userPowerData['user_id'] = $userId;
|
|
|
- $userPowerRes = $userPower->insertGetId($userPowerData);
|
|
|
- if (!$userPowerRes) {
|
|
|
- throw new Exception('创建用户权限失败');
|
|
|
- }
|
|
|
- //钱包
|
|
|
- $userwallet = [
|
|
|
- 'user_id' => $userId,
|
|
|
- ];
|
|
|
- $userWalletRes = Db::name('user_wallet')->insertGetId($userwallet);
|
|
|
- if(!$userWalletRes){
|
|
|
- throw new Exception('创建用户钱包失败');
|
|
|
- }
|
|
|
- //创建IM用户
|
|
|
- $tenimService = new TenimService();
|
|
|
- $imParams['user_id'] = $userPowerRes;
|
|
|
- $imParams['nickname'] = $params['nickname'];
|
|
|
- $imParams['avatar'] = cdnurl($params['avatar']);
|
|
|
- $tenimRes = $tenimService->accountImport($imParams);
|
|
|
- if (!$tenimRes['status']) {
|
|
|
- throw new Exception($tenimRes['msg']);
|
|
|
- }
|
|
|
- } catch (ValidateException|PDOException|Exception $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
- }
|
|
|
- if ($result == false) {
|
|
|
- $this->error(__('No rows were inserted'));
|
|
|
- }
|
|
|
- Db::commit();
|
|
|
- $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 (!empty($params['u_id'])) {
|
|
|
- $userWhere['u_id'] = $params['u_id'];
|
|
|
- $userWhere['id'] = ['neq',$ids];
|
|
|
- $user = $this->model->where($userWhere)->find();
|
|
|
- if (!empty($user)) {
|
|
|
- throw new Exception('前端用户ID已存在');
|
|
|
- }
|
|
|
- }
|
|
|
- if (!empty($params['mobile'])) {
|
|
|
- $userWhere['mobile'] = $params['mobile'];
|
|
|
- $user = $this->model->where($userWhere)->find();
|
|
|
- if (!empty($user)) {
|
|
|
- throw new Exception('手机号已存在');
|
|
|
- }
|
|
|
- }
|
|
|
- $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();
|
|
|
+ $this->model = new \app\admin\model\User;
|
|
|
+ $this->view->assign("isLiveList", $this->model->getIsLiveList());
|
|
|
+ $this->view->assign("isOnlineList", $this->model->getIsOnlineList());
|
|
|
+ $this->view->assign("hasInfoList", $this->model->getHasInfoList());
|
|
|
+ $this->view->assign("isAuthList", $this->model->getIsAuthList());
|
|
|
+ $this->view->assign("isGuildList", $this->model->getIsGuildList());
|
|
|
+ $this->view->assign("statusList", $this->model->getStatusList());
|
|
|
+ $this->view->assign("isCoolList", $this->model->getIsCoolList());
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 删除
|
|
|
- */
|
|
|
- public function del($ids = "")
|
|
|
- {
|
|
|
- if (!$this->request->isPost()) {
|
|
|
- $this->error(__("Invalid parameters"));
|
|
|
- }
|
|
|
- $ids = $ids ? $ids : $this->request->post("ids");
|
|
|
- $row = $this->model->get($ids);
|
|
|
- $this->modelValidate = true;
|
|
|
- if (!$row) {
|
|
|
- $this->error(__('No Results were found'));
|
|
|
- }
|
|
|
- Auth::instance()->delete($row['id']);
|
|
|
- $this->success();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 详情
|
|
|
- * @param null $ids
|
|
|
- * @return string
|
|
|
- * @throws \think\Exception
|
|
|
- * @throws \think\exception\DbException
|
|
|
- */
|
|
|
- public function detail($ids = null)
|
|
|
+ public function import()
|
|
|
{
|
|
|
- /* 判断数据是否存在*/
|
|
|
- $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'));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $this->view->assign("row", $row);
|
|
|
- return $this->view->fetch();
|
|
|
+ parent::import();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 编辑
|
|
|
+ * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
|
|
+ * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
|
|
+ * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
|
|
*/
|
|
|
- public function infocheck($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);
|
|
|
- }
|
|
|
- $nickStatusStr = $statusStr = '';
|
|
|
- if (isset($params['check_nick_status'])) {
|
|
|
- if ($params['check_nick_status'] == 1) {//审核通过 更新昵称
|
|
|
- !empty($params['pre_nickname']) && $params['nickname'] = $params['pre_nickname'];
|
|
|
- $params['pre_nickname'] = '';
|
|
|
- $nickStatusStr = '昵称通过';
|
|
|
- } else {//审核拒绝 清空新昵称
|
|
|
- $params['pre_nickname'] = '';
|
|
|
- $nickStatusStr = '昵称拒绝';
|
|
|
- }
|
|
|
- }
|
|
|
- if (isset($params['check_status'])) {
|
|
|
- if ($params['check_status'] == 1) {//审核通过 更新头像
|
|
|
- !empty($params['pre_avatar']) && $params['avatar'] = $params['pre_avatar'];
|
|
|
- $params['pre_avatar'] = '';
|
|
|
- $statusStr = '头像通过';
|
|
|
- } else {//审核拒绝 清空新头像
|
|
|
- $params['pre_avatar'] = '';
|
|
|
- $statusStr = '头像拒绝';
|
|
|
- }
|
|
|
- }
|
|
|
- $params['need_check'] = 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'));
|
|
|
- }
|
|
|
- if (!empty($nickStatusStr) || !empty($statusStr)) {
|
|
|
- //通过发消息
|
|
|
- $title = '用户信息变更审核通知';
|
|
|
- $content = '您申请的'.$nickStatusStr.$statusStr;
|
|
|
- Message::addMessage($row['id'],$title,$content);
|
|
|
- }
|
|
|
-
|
|
|
- $this->success();
|
|
|
- }
|
|
|
- $checkStatusList = [1=>'通过', 0=>'拒绝'];
|
|
|
- $showNickname = $showAvatar = 0;
|
|
|
- if (!empty($row['pre_nickname']) && $row['pre_nickname'] != $row['nickname']) {
|
|
|
- $showNickname = 1;
|
|
|
- }
|
|
|
- if (!empty($row['pre_avatar']) && $row['pre_avatar'] != $row['avatar']) {
|
|
|
- $showAvatar = 1;
|
|
|
- }
|
|
|
- $this->view->assign([
|
|
|
- 'row' => $row,
|
|
|
- 'checkStatusList' => $checkStatusList,
|
|
|
- 'showNickname' => $showNickname,
|
|
|
- 'showAvatar' => $showAvatar,
|
|
|
- ]);
|
|
|
- return $this->view->fetch();
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
- /**
|
|
|
- * 钻石充值
|
|
|
- * @param null $ids
|
|
|
- * @return string
|
|
|
- */
|
|
|
- public function addJewel($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);
|
|
|
- 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);
|
|
|
- }
|
|
|
- if (!empty($params['jewel_add'])) {//钻石充值
|
|
|
- $userWhere['id'] = $row['id'];
|
|
|
- $user = Db::name('user')->where($userWhere)->find();
|
|
|
- $userwallet = Db::name('user_wallet')->where('user_id',$row['id'])->find();
|
|
|
- $jewelRes = model('Wallet')->lockChangeAccountRemain($row['id'],$params['jewel_add'],'+',0,'钻石充值',17,'jewel');
|
|
|
- if ($jewelRes['status'] == false) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($jewelRes['msg']);
|
|
|
- }
|
|
|
- $params['jewel'] = bcadd($userwallet['jewel'],$params['jewel_add']);
|
|
|
- //充值日志记录
|
|
|
- //判断是否首充
|
|
|
- $jewellogWhere['user_id'] = $row['id'];
|
|
|
- $jewellogWhere['type'] = 1;
|
|
|
- $userJewelLog = model('UserJewelLog')->where($jewellogWhere)->find();
|
|
|
- $isFirst = 1;
|
|
|
- if (!empty($userJewelLog)) {
|
|
|
- $isFirst = 0;
|
|
|
- }
|
|
|
- $preUserId = $user['pre_userid'];
|
|
|
- $userRechargeLogRes = model('UserRechargeLog')->addRecord($row['id'], $params['jewel_add'], $userwallet['money'], $params['jewel'], $userwallet['money'], 4, 4,$isFirst,$preUserId);
|
|
|
- if (!$userRechargeLogRes) {
|
|
|
- throw new Exception('充值记录生成失败');
|
|
|
- }
|
|
|
- }
|
|
|
- $result = $row->allowField(true)->save($params);
|
|
|
- if ($result == false) {
|
|
|
- throw new Exception(__('No rows were updated'));
|
|
|
- }
|
|
|
- Db::commit();
|
|
|
- $this->success();
|
|
|
- } catch (ValidateException|PDOException|Exception $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- $this->view->assign("row", $row);
|
|
|
- return $this->view->fetch();
|
|
|
- }
|
|
|
}
|