Ranking.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * 各种排行榜
  4. */
  5. namespace app\smartbc\controller\api\v1;
  6. use app\common\model\SystemUser;
  7. use app\smartbc\controller\api\Base;
  8. use app\smartbc\model\SmartbcAdwords;
  9. use think\helper\Time;
  10. class Ranking extends Base{
  11. //省钱榜冠军
  12. public function topfirst(){
  13. $rel = $this->apiSign();
  14. if ($rel['code'] != 200) {
  15. return enjson($rel['code'],'签名验证失败');
  16. }
  17. list($start, $end) = Time::lastMonth();
  18. $condition[] = ['u.update_time','>=',$start];
  19. $condition[] = ['u.update_time','<=',$end];
  20. $list = SystemUser::alias('c')->where(['c.member_miniapp_id' => $this->miniapp_id])->join('SmartbcCouponUser u', 'c.id = u.uid')->where(['u.member_miniapp_id' => $this->miniapp_id,'is_end' => 1])->where('money','<>',null)->where($condition)
  21. ->field('c.face,c.nickname,sum(money) as save')->group('u.uid')->order('money desc,c.create_time desc')->find();
  22. if (empty($list)) {
  23. return enjson(204,'没有数据');
  24. }
  25. $list->month = date('n',$start);
  26. return enjson(200,$list);
  27. }
  28. //省钱榜
  29. public function topMoney(){
  30. $param['page'] = $this->request->param('page/d',1);
  31. $rel = $this->apiSign($param);
  32. if ($rel['code'] != 200) {
  33. return enjson($rel['code'],'签名验证失败');
  34. }
  35. $list = SystemUser::alias('c')->where(['c.member_miniapp_id' => $this->miniapp_id])->join('SmartbcCouponUser u', 'c.id = u.uid')->where(['u.member_miniapp_id' => $this->miniapp_id,'is_end' => 1])->where('money','<>',null)
  36. ->field('c.face,c.nickname,sum(money) as save')->group('u.uid')->order('money desc,c.create_time desc')->page($param['page'],10)->select();
  37. if ($list->isEmpty()) {
  38. return enjson(204,'没有数据');
  39. }
  40. return enjson(200,$list);
  41. }
  42. }