123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- namespace app\admin\controller\subscrip;
- use app\common\controller\Backend;
- use app\main\service\AdminService;
- use think\Controller;
- use think\Request;
- use think\Db;
- /**
- * 订阅活动报名管理
- *
- * @icon fa fa-circle-o
- */
- class Activecollect extends Backend
- {
-
- /**
- * SubscripUser模型对象
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->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();
- }
-
- }
|