Exemplo n.º 1
0
 /**
  * 活动列表
  * @date: 2016年1月4日 
  * @author: chenxiaolin
  */
 public function listAction()
 {
     $this->setLeftNav('list');
     $req = $this->request;
     $page = intval($req->getQuery('page', null, 1));
     $page = $page > 0 ? $page : 1;
     $limit = $this->pageNavLimit;
     $offset = $limit * ($page - 1);
     $filterCity = intval($req->getQuery('filterCity', null, -10000));
     $activity_state = intval($req->getQuery('activity_state', null, -10000));
     $activity_title = $req->getQuery('activity_title');
     $activity_time = $req->getQuery('activity_time');
     $timeSlotarr = explode("至", $activity_time);
     $columns = ['activity_id', 'city_name', 'create_user', 'activity_title', 'activity_state', 'activity_start_time', 'activity_end_time', 'activity_end_time - NOW() AS ts', 'activity_start_time - NOW() AS stime', 'posion_banner', 'out_link'];
     $where = [];
     $bind = [];
     $medal = [];
     //获取当前时间
     $date = date("Y-m-d H:i:s");
     //通过状态筛选数据
     if ($activity_state > -10000) {
         /* $where [] = 'activity_state = :state:';
            $bind ['state'] = $activity_state; */
         //已结束数据:状态为2,或者结束时间小于当前时间
         if ($activity_state == 2) {
             $where[] = "(activity_state = 2 or activity_end_time < '{$date}')";
         } else {
             //正常数据:状态为1,且结束时间大于当前时间
             if ($activity_state == 1) {
                 $where[] = " (activity_state = {$activity_state} and activity_end_time >= '{$date}') ";
             }
             //待发布数据:状态为0,且结束时间大于当前时间
             if ($activity_state == 0) {
                 //$where [] = "activity_end_time >= '$date'";
                 $where[] = " activity_state = {$activity_state} ";
             }
         }
     }
     //通过城市筛选数据
     if ($filterCity > -10000) {
         $where[] = 'Apps\\Common\\Models\\Activity.city_id = :city:';
         $bind['city'] = $filterCity;
     }
     //通过活动标题筛选数据
     if ($activity_title != '') {
         $where[] = "activity_title like '%" . $activity_title . "%'";
         $this->view->setVar("activity_title", $activity_title);
     }
     //通过活动周期筛选数据
     if ($activity_time != '') {
         $where[] = "activity_start_time > '" . $timeSlotarr[0] . "'";
         $where[] = "activity_end_time < '" . $timeSlotarr[1] . "'";
     }
     //$where [] = 'activity_state > -1';
     $whereStr = implode(' AND ', $where);
     $query = Activity::query()->columns($columns)->leftJoin('Apps\\Common\\Models\\SysOpenCity', 'soc.city_id=Apps\\Common\\Models\\Activity.city_id', 'soc');
     if (!empty($whereStr)) {
         $query = $query->where($whereStr);
     }
     if (count($bind) > 0) {
         $query = $query->bind($bind);
     }
     $data = $query->orderBy('activity_update_time DESC,activity_id DESC')->limit($limit, $offset)->execute()->toArray();
     foreach ($data as $k => $v) {
         if (empty($data[$k]['activity_end_time'])) {
             $data[$k]['ts'] = 1;
         }
     }
     // 总数
     $total = Activity::count(['conditions' => $whereStr, 'bind' => $bind]);
     $this->view->setVar('filterCity', $filterCity);
     $this->view->setVar('activity_state', $activity_state);
     $this->view->setVar("activity_time", $activity_time);
     $this->view->setVar('total', $total);
     $this->view->setVar('page', $page);
     $this->view->setVar('limit', $limit);
     $this->view->setVar('data', $data);
     $this->view->setVar('openCity', SysOpenCity::find('city_state = 1'));
     $this->view->setVar('stateList', ActivityState::valuesExplain());
 }
Exemplo n.º 2
0
 /**
  * 活动列表
  */
 public function listAction()
 {
     $this->setLeftNav('list');
     $req = $this->request;
     $page = intval($req->getQuery('page', null, 1));
     $page = $page > 0 ? $page : 1;
     $limit = $this->pageNavLimit;
     $offset = $limit * ($page - 1);
     $filterCity = intval($req->getQuery('filterCity', null, -10000));
     $filterState = intval($req->getQuery('filterState', null, -10000));
     $columns = ['activity_id', 'city_name', 'activity_title', 'activity_state', 'activity_start_time', 'activity_end_time', 'activity_end_time - NOW() AS ts', 'posion_banner', 'out_link'];
     $where = [];
     $bind = [];
     $medal = [];
     //获取当前时间
     $date = date("Y-m-d H:i:s");
     if ($filterState > -10000) {
         //已结束数据:状态为2,或者结束时间小于当前时间
         if ($filterState == 2) {
             $where[] = " activity_state = 2 or activity_end_time < '{$date}' ";
         } else {
             //正常数据:状态为1,且结束时间大于当前时间
             if ($filterState == 1) {
                 $where[] = "activity_end_time >= '{$date}'";
             }
             //待发布数据:状态为0,且结束时间大于当前时间
             if ($filterState == 0) {
                 $where[] = "activity_end_time >= '{$date}'";
             }
             $where[] = 'activity_state = :state:';
             $bind['state'] = $filterState;
         }
     }
     if ($filterCity > -10000) {
         $where[] = 'Apps\\Common\\Models\\Activity.city_id = :city:';
         $bind['city'] = $filterCity;
     }
     $where[] = 'activity_state > -1';
     $whereStr = implode(' AND ', $where);
     $query = Activity::query()->columns($columns)->leftJoin('Apps\\Common\\Models\\SysOpenCity', 'soc.city_id=Apps\\Common\\Models\\Activity.city_id', 'soc');
     if (!empty($whereStr)) {
         $query = $query->where($whereStr);
     }
     if (count($bind) > 0) {
         $query = $query->bind($bind);
     }
     $data = $query->orderBy('activity_id DESC')->limit($limit, $offset)->execute();
     // 总数
     $total = Activity::count(['conditions' => $whereStr, 'bind' => $bind]);
     $this->view->setVar('filterCity', $filterCity);
     $this->view->setVar('filterState', $filterState);
     $this->view->setVar('total', $total);
     $this->view->setVar('page', $page);
     $this->view->setVar('limit', $limit);
     $this->view->setVar('data', $data);
     $this->view->setVar('openCity', SysOpenCity::find());
     $this->view->setVar('stateList', ActivityState::valuesExplain());
 }