model = model('SubscripUser'); } // protected $noNeedRight = ['channel_show']; /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法 * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { $aid = $this->request->param('aid'); $active = model('SubscripActivity')->get($aid); if (empty($active)){ $this->error('活动不存在'); } $cur_day = ceil((time()-strtotime($active->begin_date))/(24*3600)); $active->is_begin = 2 ; $active->state_text = '活动进行中'; if ($cur_day < 0){ $active->is_begin = 0 ; $active->state_text = '活动未开始'; }elseif( $cur_day == 1 ){ $active->is_begin = 1 ; $active->state_text = '活动报名中'; }elseif ($cur_day > $active->days+1){ $active->is_begin = 3 ; $active->state_text = '活动结束'; $cur_day = $active->days; }else{ $cur_day--; } $active->cur_day = $cur_day; //设置过滤方法 $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 = Db::table('subscrip_user')->connect('polardb') ->field('act_id active_id,channel_id,count(user_id) as num,sum(case state when 2 then 1 else 0 end) as success_num') ->where('act_id',$aid) ->group('act_id,channel_id') ->order('channel_id','desc') ->count(); $list = Db::table('subscrip_user')->connect('polardb') ->field('act_id as active_id,channel_id,count(user_id) as num,sum(case state when 2 then 1 else 0 end) as success_num') ->where('act_id',$aid) ->group('act_id,channel_id') ->order('channel_id','desc') ->limit($offset, $limit) ->select(); if(!empty($list)){ $channelList = []; $channelIds = array_column($list,'channel_id'); $channelList = model('Admin')->whereIn('id',$channelIds)->select(); $channelList = array_column($channelList,null,'id'); foreach ($list as $key =>&$value){ $value['active_title'] = $active->title; $value['price'] = $active->price*$value['num']; $value['days'] = $active->days-1; $value['begin_date'] = $active->begin_date; $value['act_state'] = $active->state; $value['state_text'] = $active->state_text; $value['back_price'] =$active->is_begin == 3 ? $active->price*$value['success_num'] : '--'; $value['success_num'] = $active->is_begin == 3 ? $value['success_num'] : '--'; $value['channel_name'] = isset($channelList[$value['channel_id']]) ? $channelList[$value['channel_id']]['username'] : ''; } } $result = array("total" => $total, "rows" => $list); return json($result); } $this->assignconfig('aid', $aid); $this->assign('active',$active); return $this->view->fetch(); } public function channel_show() { $channel_id = 0; if($this->group == 4){ if($this->auth->agent_id){ $channel_id = $this->auth->agent_id; }else{ $channel_id = $this->auth->channel_id; } } if($this->group == 3){ $channel_id = $this->auth->channel_id; } $give_tab = 1; $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($channel_id); if ($adminConfig['give_kandian'] == 0) { $give_tab = 0; } //设置过滤方法 $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 = Db::table('subscrip_user')->connect('polardb') ->field('act_id as active_id,channel_id,count(1) as num,sum(case state when 2 then 1 else 0 end) as success_num') ->where('channel_id',$channel_id) ->group('channel_id,act_id') ->count(); $list = Db::table('subscrip_user')->connect('polardb') ->field('act_id as active_id,channel_id,count(1) as num,sum(case state when 2 then 1 else 0 end) as success_num') ->where('channel_id',$channel_id) ->group('channel_id,act_id') ->order('act_id','desc') ->limit($offset, $limit) ->select(); if(!empty($list)){ $actIds = array_column($list,'active_id'); $actives = model('SubscripActivity')->whereIn('id',$actIds)->select($actIds); if (!empty($actives)){ $actives = array_column($actives,null,'id'); } foreach ($list as $k =>&$v){ $v['active_title'] = $actives[$v['active_id']]['title'] ?? ''; $v['price'] = ($actives[$v['active_id']]['price']??0)*$v['num']; $v['begin_date'] = $actives[$v['active_id']]['begin_date'] ?? ''; $v['days'] = $actives[$v['active_id']]['days'] ?? 0; $cur_day = ceil((time()-strtotime($v['begin_date']))/(24*3600)); $v['state_text'] = '活动进行中'; $v['is_begin'] = 2; if ($cur_day < 0){ $v['is_begin'] = 0; $v['state_text'] = '活动未开始'; }elseif( $cur_day == 1 ){ $v['is_begin'] = 1; $v['state_text'] = '活动报名中'; }elseif ($cur_day > $v['days'] +1){ $v['is_begin'] = 3; $v['state_text'] = '活动结束'; }else{ $cur_day--; } $v['cur_day'] = $cur_day; $v['back_price'] = $v['is_begin'] == 3 ? ($actives[$v['active_id']]['price']??0)*$v['success_num'] : '--'; $v['success_num'] = $v['is_begin'] == 3 ? $v['success_num'] : '--'; } } $result = array("total" => $total, "rows" => $list); return json($result); } $this->assign('give_tab',$give_tab); return $this->view->fetch(); } }