123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- namespace app\admin\controller\invite;
- use app\common\controller\Backend;
- use think\Controller;
- use think\Request;
- use fast\Random;
- /**
- * #邀请记录管理
- *
- * @icon fa fa-circle-o
- */
- class Record extends Backend
- {
-
- /**
- * InviteRecord模型对象
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('InviteRecord');
- $this->view->assign("payTypeList", $this->model->getPayTypeList());
- $this->view->assign("statusList", $this->model->getStatusList());
- }
-
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
- * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax())
- {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('pkey_name'))
- {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model->alias('r')
- ->join('admin_extend e','e.admin_id=r.invite_id and e.create_by='.$this->auth->id)
- ->where($where)
- ->count();
- $list = $this->model->alias('r')
- ->join('admin a','r.invite_id = a.id')
- ->join('admin_extend e','e.admin_id=r.invite_id and e.create_by='.$this->auth->id)
- ->field('r.*,a.nickname as anickname')
- ->where($where)
- ->order('r.status asc,r.id desc')
- ->limit($offset, $limit)
- ->select();
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 编辑
- */
- public function edit($ids = NULL)
- {
- $row = $this->model->get($ids);
- $this->assign('id',$ids);
- $extend = model('admin_extend')->where('admin_id',$this->auth->id)->find();
- $this->assign('extend',$extend);
- 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");
- $extends = $this->request->post("extend/a");
- $id = $this->request->post("activity_id");
- if ($params)
- {
- try
- {
- $this->model=model('admin');
- $params['salt'] = Random::alnum();
- $params['password'] = md5(md5($params['password']) . $params['salt']);
- $params['avatar'] = asset('/img/avatar.png'); //设置新管理员默认头像。
- $result = $this->model->validate('Admin.add')->insertGetId($params);
- if ($result)
- {
- $dataset = [];
- $dataset[] = ['uid' => $result, 'group_id' => 4];
- model('AuthGroupAccess')->saveAll($dataset); //分组表
- model('invite_record')->update(['admin_id'=>$result,'status'=>'1'],['id'=>$id]);
- $extends['create_by'] = $this->auth->id;
- $extends['admin_id'] = $result;
- $extends['createtime'] = time();
- $extends['updatetime'] = time();
- if($extends['pay_method'] == 1){
- $extends['pay_method'] = 3;
- }elseif($extends['pay_method'] == 2){
- $extends['pay_method'] = 4;
- }else{
- $extends['pay_method'] = 2;
- }
- model('admin_extend')->insert($extends);
- $this->success();
- }
- else
- {
- $this->error($row->getError());
- }
- }
- catch (\think\exception\PDOException $e)
- {
- $this->error($e->getMessage());
- }
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $this->view->assign("row", $row);
- return $this->view->fetch();
- }
-
- }
|