Activecollect.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. namespace app\admin\controller\subscrip;
  3. use app\common\controller\Backend;
  4. use app\main\service\AdminService;
  5. use think\Controller;
  6. use think\Request;
  7. use think\Db;
  8. /**
  9. * 订阅活动报名管理
  10. *
  11. * @icon fa fa-circle-o
  12. */
  13. class Activecollect extends Backend
  14. {
  15. /**
  16. * SubscripUser模型对象
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = model('SubscripUser');
  23. }
  24. // protected $noNeedRight = ['channel_show'];
  25. /**
  26. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
  27. * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
  28. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  29. */
  30. /**
  31. * 查看
  32. */
  33. public function index()
  34. {
  35. $aid = $this->request->param('aid');
  36. $active = model('SubscripActivity')->get($aid);
  37. if (empty($active)){
  38. $this->error('活动不存在');
  39. }
  40. $cur_day = ceil((time()-strtotime($active->begin_date))/(24*3600));
  41. $active->is_begin = 2 ;
  42. $active->state_text = '活动进行中';
  43. if ($cur_day < 0){
  44. $active->is_begin = 0 ;
  45. $active->state_text = '活动未开始';
  46. }elseif( $cur_day == 1 ){
  47. $active->is_begin = 1 ;
  48. $active->state_text = '活动报名中';
  49. }elseif ($cur_day > $active->days+1){
  50. $active->is_begin = 3 ;
  51. $active->state_text = '活动结束';
  52. $cur_day = $active->days;
  53. }else{
  54. $cur_day--;
  55. }
  56. $active->cur_day = $cur_day;
  57. //设置过滤方法
  58. $this->request->filter(['strip_tags']);
  59. if ($this->request->isAjax())
  60. {
  61. //如果发送的来源是Selectpage,则转发到Selectpage
  62. if ($this->request->request('pkey_name'))
  63. {
  64. return $this->selectpage();
  65. }
  66. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  67. $total = Db::table('subscrip_user')->connect('polardb')
  68. ->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')
  69. ->where('act_id',$aid)
  70. ->group('act_id,channel_id')
  71. ->order('channel_id','desc')
  72. ->count();
  73. $list = Db::table('subscrip_user')->connect('polardb')
  74. ->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')
  75. ->where('act_id',$aid)
  76. ->group('act_id,channel_id')
  77. ->order('channel_id','desc')
  78. ->limit($offset, $limit)
  79. ->select();
  80. if(!empty($list)){
  81. $channelList = [];
  82. $channelIds = array_column($list,'channel_id');
  83. $channelList = model('Admin')->whereIn('id',$channelIds)->select();
  84. $channelList = array_column($channelList,null,'id');
  85. foreach ($list as $key =>&$value){
  86. $value['active_title'] = $active->title;
  87. $value['price'] = $active->price*$value['num'];
  88. $value['days'] = $active->days-1;
  89. $value['begin_date'] = $active->begin_date;
  90. $value['act_state'] = $active->state;
  91. $value['state_text'] = $active->state_text;
  92. $value['back_price'] =$active->is_begin == 3 ? $active->price*$value['success_num'] : '--';
  93. $value['success_num'] = $active->is_begin == 3 ? $value['success_num'] : '--';
  94. $value['channel_name'] = isset($channelList[$value['channel_id']]) ? $channelList[$value['channel_id']]['username'] : '';
  95. }
  96. }
  97. $result = array("total" => $total, "rows" => $list);
  98. return json($result);
  99. }
  100. $this->assignconfig('aid', $aid);
  101. $this->assign('active',$active);
  102. return $this->view->fetch();
  103. }
  104. public function channel_show()
  105. {
  106. $channel_id = 0;
  107. if($this->group == 4){
  108. if($this->auth->agent_id){
  109. $channel_id = $this->auth->agent_id;
  110. }else{
  111. $channel_id = $this->auth->channel_id;
  112. }
  113. }
  114. if($this->group == 3){
  115. $channel_id = $this->auth->channel_id;
  116. }
  117. $give_tab = 1;
  118. $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($channel_id);
  119. if ($adminConfig['give_kandian'] == 0) {
  120. $give_tab = 0;
  121. }
  122. //设置过滤方法
  123. $this->request->filter(['strip_tags']);
  124. if ($this->request->isAjax())
  125. {
  126. //如果发送的来源是Selectpage,则转发到Selectpage
  127. if ($this->request->request('pkey_name'))
  128. {
  129. return $this->selectpage();
  130. }
  131. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  132. $total = Db::table('subscrip_user')->connect('polardb')
  133. ->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')
  134. ->where('channel_id',$channel_id)
  135. ->group('channel_id,act_id')
  136. ->count();
  137. $list = Db::table('subscrip_user')->connect('polardb')
  138. ->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')
  139. ->where('channel_id',$channel_id)
  140. ->group('channel_id,act_id')
  141. ->order('act_id','desc')
  142. ->limit($offset, $limit)
  143. ->select();
  144. if(!empty($list)){
  145. $actIds = array_column($list,'active_id');
  146. $actives = model('SubscripActivity')->whereIn('id',$actIds)->select($actIds);
  147. if (!empty($actives)){
  148. $actives = array_column($actives,null,'id');
  149. }
  150. foreach ($list as $k =>&$v){
  151. $v['active_title'] = $actives[$v['active_id']]['title'] ?? '';
  152. $v['price'] = ($actives[$v['active_id']]['price']??0)*$v['num'];
  153. $v['begin_date'] = $actives[$v['active_id']]['begin_date'] ?? '';
  154. $v['days'] = $actives[$v['active_id']]['days'] ?? 0;
  155. $cur_day = ceil((time()-strtotime($v['begin_date']))/(24*3600));
  156. $v['state_text'] = '活动进行中';
  157. $v['is_begin'] = 2;
  158. if ($cur_day < 0){
  159. $v['is_begin'] = 0;
  160. $v['state_text'] = '活动未开始';
  161. }elseif( $cur_day == 1 ){
  162. $v['is_begin'] = 1;
  163. $v['state_text'] = '活动报名中';
  164. }elseif ($cur_day > $v['days'] +1){
  165. $v['is_begin'] = 3;
  166. $v['state_text'] = '活动结束';
  167. }else{
  168. $cur_day--;
  169. }
  170. $v['cur_day'] = $cur_day;
  171. $v['back_price'] = $v['is_begin'] == 3 ? ($actives[$v['active_id']]['price']??0)*$v['success_num'] : '--';
  172. $v['success_num'] = $v['is_begin'] == 3 ? $v['success_num'] : '--';
  173. }
  174. }
  175. $result = array("total" => $total, "rows" => $list);
  176. return json($result);
  177. }
  178. $this->assign('give_tab',$give_tab);
  179. return $this->view->fetch();
  180. }
  181. }