123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- namespace app\admin\controller\reward;
- use app\common\controller\Backend;
- use app\common\library\Redis;
- use think\Controller;
- use think\Request;
- /**
- * 赏金统计管理
- *
- * @icon fa fa-circle-o
- */
- class Collect extends Backend
- {
- /**
- * RewardCollect模型对象
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('Admin');
- }
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- //今日赏金
- $today = date('Ymd',time());
- $todaySum = model('reward_collect')->alias('r')->join('admin_extend e','r.admin_id=e.admin_id and r.invite_id=0 and e.create_by='.$this->auth->id)->where(['r.createdate'=>$today,'r.type'=>1,'r.flag'=>2])->sum('r.reward');
- $this->assign('todaySum',$todaySum);
- //累计赏金
- $totalSum = model('reward_collect')->alias('r')->join('admin_extend e','r.admin_id=e.admin_id and r.invite_id=0 and e.create_by='.$this->auth->id)->where(['r.type'=>2,'r.flag'=>2])->sum('r.reward');
- $this->assign('totalSum',$totalSum);
- 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('a')
- ->join('admin_extend e','e.admin_id = a.id and e.create_by = '.$this->auth->id)
- ->where($where)
- ->where('a.status','normal')
- ->count();
- $list = $this->model
- ->alias('a')
- ->join('admin_extend e','e.admin_id = a.id and e.create_by = '.$this->auth->id)
- ->join("reward_collect t","t.admin_id=a.id and t.createdate='{$today}' and t.type='1' and t.flag='2'","left")
- ->join("reward_collect all","all.admin_id=a.id and all.type='2' and all.flag='2'","left")
- ->join("reward_money m","m.admin_id=a.id","left")
- ->field('a.*,e.reward_benefit,e.reward_state,t.reward as treward,all.reward as allreward,m.no_cash_money')
- ->where($where)
- ->where('a.status','normal')
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- //dump($this->model->getLastSql());
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 编辑
- */
- public function edit($ids = NULL)
- {
- $row = $this->model->alias('a')
- ->join('admin_extend e','e.admin_id = a.id')
- ->field('a.id,a.username,e.reward_benefit,e.reward_state')
- ->where('a.id',$ids)->find();
- $this->assign('reward_state',['0'=>'关闭','1'=>'打开']);
- 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)
- {
- try
- {
- //是否采用模型验证
- if ($this->modelValidate)
- {
- $name = basename(str_replace('\\', '/', get_class($this->model)));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate;
- $row->validate($validate);
- }
- $result = model('AdminExtend')->save($params,['admin_id'=>$ids]);
- if ($result !== false)
- {
- $redis = Redis::instance();
- $key = 'AE:'.$ids;
- $redis->del($key);
- $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();
- }
- }
|