123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use Think\Db;
- /**
- * 会员管理
- *
- * @icon fa fa-user
- */
- class Vipuser extends Backend
- {
- /**
- * Vipuser模型对象
- * @var \app\admin\model\Vipuser
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\Vipuser;
- $this->view->assign("statusList", $this->model->getStatusList());
- $this->view->assign("genderList", $this->model->getGenderList());
- }
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
- * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- /**
- * 查看
- */
- public function index()
- {
- $vip_id = input('vip_id', 0, 'intval'); //会员id
- if (!$vip_id) {
- $vip_id = input('ids', 0, 'intval'); //从会员列表第一次跳转过来
- }
- $this->assignconfig('vip_id', $vip_id);
- //当前是否为关联查询
- $this->relationSearch = false;
- //设置过滤方法
- $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
- ->where(['maxlevel' => ['lt', $vip_id], 'status' => 1, 'experiencetime' => ['lt', time()]])
- ->where($where)
- ->order($sort, $order)
- ->paginate($limit);
- foreach ($list as $row) {
- $row->visible(['id','username','nickname','mobile','avatar','money','realname','gender','birthday','idcard','passport','emergencycontact','contactmobile','outdoorduration','invite_no','growthvalue','growthlevel','experiencelevel','experiencetime','maxlevel','freenumber']);
-
- }
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 发放会员给用户
- */
- public function giveout() {
- $ids = input('ids', 0, 'intval'); //用户id
- $vip_id = input('vip_id', 0, 'intval'); //会员id
- if (!$ids || !$vip_id) {
- $this->error('参数缺失');
- }
- $info = Db::name('vip')->find($vip_id);
- if (!$info) {
- $this->error('会员不存在');
- }
- if ($info['id'] == 1) {
- $this->error('普通会员不用发放');
- }
- //查询用户信息
- $user_info = Db::name('user')->find($ids);
- if (!$user_info) {
- $this->error('用户不存在');
- }
- if ($user_info['status'] != 1) {
- $this->error('用户已被禁用');
- }
- if ($user_info['experiencetime'] >= time()) {
- $this->error('用户体验会员尚未到期');
- }
- if ($info['id'] <= $user_info['maxlevel']) {
- $this->error('该用户已拥有该会员或更高等级会员');
- }
- $data['user_id'] = $ids;
- $data['vip_id'] = $vip_id;
- $data['title'] = $info['title'];
- $data['level'] = $info['level'];
- $data['growthvalue'] = $info['growthvalue'];
- $data['free'] = $info['free'];
- $data['price'] = $info['price'];
- $data['endtime'] = time() + $info['day'] * 86400;
- $data['vipdiscount'] = $info['vipdiscount'];
- $data['birthdiscount'] = $info['birthdiscount'];
- $data['manypeople'] = $info['manypeople'];
- $data['createtime'] = time();
- //开启事务
- Db::startTrans();
- //添加开通记录
- $rs = Db::name('vip_log')->insertGetId($data);
- if (!$rs) {
- Db::rollback();
- $this->error('发放失败');
- }
- //成长值会员信息
- $growth_vip_info = Db::name('vip')->find($user_info['growthlevel']);
- //修改用户表信息
- $user_data['experiencelevel'] = $vip_id;
- $user_data['experiencetime'] = $data['endtime'];
- $user_data['maxlevel'] = $vip_id;
- $freenumber = $user_info['freenumber'] + $info['free'] - $growth_vip_info['free'];
- $user_data['freenumber'] = $freenumber > 0 ? $freenumber : 0;
- $rt = Db::name('user')->where([
- 'id' => $user_info['id'],
- 'experiencelevel' => $user_info['experiencelevel'],
- 'maxlevel' => $user_info['maxlevel'],
- 'freenumber' => $user_info['freenumber']])->setField($user_data);
- if (!$rt) {
- Db::rollback();
- $this->error('发放失败');
- }
- Db::commit();
- $this->success('发放成功');
- }
- }
|