diff --git a/app/controller/AdminStatistics.php b/app/controller/AdminStatistics.php index 3bbe842..a280d40 100644 --- a/app/controller/AdminStatistics.php +++ b/app/controller/AdminStatistics.php @@ -9,6 +9,7 @@ use app\model\AdminDownScoresRecords; use app\model\AdminUpScoresRecords; use app\model\AgentDownScoresRecords; use app\model\AgentUpScoresRecords; +use app\model\AwardsRecords; use think\exception\ValidateException; use think\facade\Request; use app\model\User as UserModel; @@ -152,4 +153,45 @@ class AdminStatistics extends BaseController return $data; } + /** + * 中奖记录 + * @return array + * @throws \think\db\exception\DbException + */ + public function awardRecords() + { + $data = Request::param(); + + $limit = $data['limit'] ?? 10; + $date = $data['date'] ?? date("Y-m-d",time()); + $start_time = $date . ' 00:00:00'; + $end_time = $date . ' 23:59:59'; + $where = [['create_time','>=',$start_time],['create_time', '<=', $end_time]]; + + $records = new AwardsRecords(); + + $list = $records->field('user_id,awards_amount,create_time') + ->where($where) + ->order('create_time desc') + ->paginate($limit); + + $data = $list->toArray()['data']; + + $sumRes = $records->field('SUM(awards_amount) as sum_amount')->where($where)->find(); + foreach ($data as &$item) { + $user = UserModel::field('phone')->find($item['user_id']); + $item['phone'] = $user['phone']; + $item['awards_amount'] *= 1; + $item['datetime'] = date("H:i:s",strtotime($item['create_time'])); + unset($item['create_time']); + } + + return $this->renderSuccess('数据返回成功',[ + 'list' => $data, + 'total' => $list->total(), + 'sum_amount' => $sumRes['sum_amount'] * 1, + 'unit' => '元' + ]); + } + }