// +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Date: 2017-5-25 // +---------------------------------------------------------------------- namespace api\activity\controller; use api\activity\model\ActivityModel; use api\activity\model\ActivitySiteModel; use cmf\controller\RestBaseController; class SiteController extends RestBaseController { /** * 列表 */ public function index() { $param = $this->request->param(); $page = empty($param['page']) ? 1 : $param['page']; $size = empty($param['size']) ? 10 : $param['size']; //搜索条件 $where = []; if (!empty($param['keyword'])) { $where[] = ['site_name', 'like', "%{$param['keyword']}%"]; } $list = ActivitySiteModel::where($where)->order('create_time', 'DESC')->page($page, $size)->select(); $this->success('成功', $list); } /** * 所有列表 */ public function all() { $where = []; $is_map = $this->request->param('is_map', 0); $keyword = $this->request->param('keyword', ''); if (!empty($is_map)) { $where[] = ['latitude', '>', 0]; } if (!empty($keyword)) { $where[] = ['site_name', 'like', "%{$keyword}%"]; } $list = ActivitySiteModel::order('list_order', 'ASC')->where($where)->select(); //数据处理 if (!$list->isEmpty()) { foreach ($list as $v) { $v['main_image'] = cmf_get_image_preview_url($v['main_image']); } } $this->success('成功', $list); } /** * 详情 */ public function detail() { $id = $this->request->post('id'); $info = ActivitySiteModel::get($id); $info['main_image'] = cmf_get_image_preview_url($info['main_image']); $this->success('成功', $info); } /** * 统计 */ public function getCount() { $id = $this->request->param('id'); $total = ActivityModel::where('user_id', $id)->count(); $month_start = strtotime(date('Y-m-01')); $month_end = strtotime(date('Y-m-01') . ' +1 month') - 1; $month_total = ActivityModel::where('user_id', $id)->where('create_time', 'between', [$month_start, $month_end])->count(); $year_start = strtotime(date('Y-01-01')); $year_end = strtotime(date('Y-01-01') . ' +1 year') - 1; $year_total = ActivityModel::where('user_id', $id)->where('create_time', 'between', [$year_start, $year_end])->count(); $this->success('成功', [ 'total' => $total, 'month_total' => $month_total, 'year_total' => $year_total, ]); } }