Collect.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. use app\common\model\UserCollect;
  5. use app\main\constants\AdminConstants;
  6. use app\main\constants\ApiConstants;
  7. use app\main\service\ApiService;
  8. use app\main\service\UserCollectService;
  9. use app\main\service\UserService;
  10. use app\main\service\VisitLimitService;
  11. /**
  12. * 数据统计-用户统计
  13. *
  14. * @icon fa fa-circle-o
  15. */
  16. class Collect extends Backend
  17. {
  18. /**
  19. * @var UserCollect
  20. */
  21. protected $model = null;
  22. protected $groupId;
  23. public function _initialize()
  24. {
  25. parent::_initialize();
  26. $this->model = model('UserCollect');
  27. $group = model('AuthGroupAccess')->where('uid',$this->auth->id)->find();
  28. $this->groupId = $group->group_id;
  29. $this->assign('groupId',$this->groupId);
  30. $this->assignconfig('groupId',$this->groupId);
  31. }
  32. /**
  33. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
  34. * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
  35. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  36. */
  37. /**
  38. * 查看
  39. */
  40. public function index()
  41. {
  42. if(isset($_GET['ids']) && !empty($_GET['ids'])){
  43. $admin_id = $_GET['ids'];
  44. }else{
  45. $admin_id = $this->auth->id;
  46. }
  47. $this->assignconfig('ids', $admin_id);
  48. if ($this->request->isAjax())
  49. {
  50. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  51. $result = UserCollectService::instance()->getUserCollectDateListData($admin_id, $where, $sort, $order, $offset, $limit, $this->group);
  52. return json($result->data);
  53. }
  54. if (VisitLimitService::instance()->checkMigratedV2()) {
  55. $data = UserCollectService::instance()->getMigrateCollectData($admin_id, $this->group)->data;
  56. } else {
  57. $data = UserCollectService::instance()->getCollectData($this->auth->id)->data;
  58. }
  59. $this->assign($data);
  60. return $this->view->fetch();
  61. }
  62. public function ajaxToday(){
  63. if (VisitLimitService::instance()->checkMigratedV2()) {
  64. if ($this->group == AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN) {
  65. $admin_id = 0;
  66. } else {
  67. $admin_id = $this->auth->id;
  68. }
  69. $todayData = UserCollectService::instance()->getMigrateTodayData($admin_id);
  70. } else {
  71. $todayData = UserCollectService::instance()->getUserCollectToday($this->auth->id);
  72. }
  73. return json($todayData->data);
  74. }
  75. public function recharge_new()
  76. {
  77. $data = [];
  78. $filter = $this->request->get('filter');
  79. $where = [
  80. ];
  81. if ($filter) {
  82. $filter = json_decode($filter, TRUE);
  83. if (array_key_exists('reg_date', $filter)) {
  84. $range = explode(' - ', $filter['reg_date']);
  85. $data['begin_date'] = $range[0];
  86. $data['end_date'] = $range[1];
  87. $range[0] = str_replace('-', '', $range[0]);
  88. $range[1] = str_replace('-', '', $range[1]);
  89. $where['reg_date'] = ['between', [$range[0], $range[1]]];
  90. }
  91. }
  92. list(, $sort, $order, $offset, $limit) = $this->buildparams();
  93. $list = model('recharge_new_analysis')
  94. ->where('channel_id', $this->auth->id)
  95. ->field('id,channel_id,reg_date,new,cost,day1,day2,day3,day5,day7,day15,day30')
  96. ->order('reg_date', 'desc')
  97. ->where($where)
  98. ->limit($offset, $limit)
  99. ->select();
  100. $count = model('recharge_new_analysis')
  101. ->where('channel_id', $this->auth->id)
  102. ->order('reg_date', 'desc')
  103. ->where($where)
  104. ->count();
  105. $data['total'] = $count;
  106. $data['rows'] = $list;
  107. return json($data);
  108. }
  109. public function recharge_cost($cost, $id)
  110. {
  111. model('recharge_new_analysis')->update(['cost' => $cost], ['id' => $id]);
  112. $this->success();
  113. }
  114. }