SiteController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 文件说明:幻灯片
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: wuwu <15093565100@163.com>
  8. // +----------------------------------------------------------------------
  9. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  10. // +----------------------------------------------------------------------
  11. // | Date: 2017-5-25
  12. // +----------------------------------------------------------------------
  13. namespace api\activity\controller;
  14. use api\activity\model\ActivityModel;
  15. use api\activity\model\ActivitySiteModel;
  16. use cmf\controller\RestBaseController;
  17. class SiteController extends RestBaseController
  18. {
  19. /**
  20. * 列表
  21. */
  22. public function index()
  23. {
  24. $param = $this->request->param();
  25. $page = empty($param['page']) ? 1 : $param['page'];
  26. $size = empty($param['size']) ? 10 : $param['size'];
  27. //搜索条件
  28. $where = [];
  29. if (!empty($param['keyword'])) {
  30. $where[] = ['site_name', 'like', "%{$param['keyword']}%"];
  31. }
  32. $list = ActivitySiteModel::where($where)->order('create_time', 'DESC')->page($page, $size)->select();
  33. $this->success('成功', $list);
  34. }
  35. /**
  36. * 所有列表
  37. */
  38. public function all()
  39. {
  40. $where = [];
  41. $is_map = $this->request->param('is_map', 0);
  42. $keyword = $this->request->param('keyword', '');
  43. if (!empty($is_map)) {
  44. $where[] = ['latitude', '>', 0];
  45. }
  46. if (!empty($keyword)) {
  47. $where[] = ['site_name', 'like', "%{$keyword}%"];
  48. }
  49. $list = ActivitySiteModel::order('list_order', 'ASC')->where($where)->select();
  50. //数据处理
  51. if (!$list->isEmpty()) {
  52. foreach ($list as $v) {
  53. $v['main_image'] = cmf_get_image_preview_url($v['main_image']);
  54. }
  55. }
  56. $this->success('成功', $list);
  57. }
  58. /**
  59. * 详情
  60. */
  61. public function detail()
  62. {
  63. $id = $this->request->post('id');
  64. $info = ActivitySiteModel::get($id);
  65. $info['main_image'] = cmf_get_image_preview_url($info['main_image']);
  66. $this->success('成功', $info);
  67. }
  68. /**
  69. * 统计
  70. */
  71. public function getCount()
  72. {
  73. $id = $this->request->param('id');
  74. $total = ActivityModel::where('user_id', $id)->count();
  75. $month_start = strtotime(date('Y-m-01'));
  76. $month_end = strtotime(date('Y-m-01') . ' +1 month') - 1;
  77. $month_total = ActivityModel::where('user_id', $id)->where('create_time', 'between', [$month_start, $month_end])->count();
  78. $year_start = strtotime(date('Y-01-01'));
  79. $year_end = strtotime(date('Y-01-01') . ' +1 year') - 1;
  80. $year_total = ActivityModel::where('user_id', $id)->where('create_time', 'between', [$year_start, $year_end])->count();
  81. $this->success('成功', [
  82. 'total' => $total,
  83. 'month_total' => $month_total,
  84. 'year_total' => $year_total,
  85. ]);
  86. }
  87. }