From 72fa9bff267f818737b6c14023f51942ad77d78c Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Tue, 2 Jul 2024 15:53:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=99=BE=E4=BA=BF=E8=A1=A5?= =?UTF-8?q?=E8=B4=B4=E6=98=BE=E7=A4=BA=E6=9C=80=E9=AB=98=E8=A1=A5=E8=B4=B4?= =?UTF-8?q?=E7=AD=89=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/Billions.php | 4 ++++ app/api/logic/BillionsLogic.php | 25 ++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/api/controller/Billions.php b/app/api/controller/Billions.php index 1578f1b7..b41f4861 100644 --- a/app/api/controller/Billions.php +++ b/app/api/controller/Billions.php @@ -14,6 +14,10 @@ class Billions extends Api $size = $this->request->get('page_size', $this->page_size); $state = $this->request->get('state', 0); $list = BillionsLogic::lists($page, $size, $state, $this->user_id); + foreach($list['list'] as $key=>$value){ + $ranking = BillionsLogic::getRanking($value['billions_id']); + $list['list'][$key]['ranking'] = $ranking; + } return JsonServer::success('获取成功', $list); } } \ No newline at end of file diff --git a/app/api/logic/BillionsLogic.php b/app/api/logic/BillionsLogic.php index 17fa4eb2..68a1bc3f 100644 --- a/app/api/logic/BillionsLogic.php +++ b/app/api/logic/BillionsLogic.php @@ -7,6 +7,7 @@ use app\common\model\billions\Billions; class BillionsLogic extends Logic { + // 获取数据 public static function lists($page, $size, $state, $user_id) { $where[] = ['b.user_id', '=', $user_id]; @@ -17,19 +18,25 @@ class BillionsLogic extends Logic } $list = Billions::alias('b')->where($where) - ->join('order o', 'o.id = b.order_id') - ->join('goods g', 'g.id = b.goods_id') - ->field('b.*, o.order_sn') - ->order('billions_id desc')->page($page,$size)->select(); + ->join('order o', 'o.id = b.order_id') + ->join('goods g', 'g.id = b.goods_id') + ->join('shop s', 's.id = b.shop_id') + ->field('b.*, o.order_sn, s.name') + ->page($page,$size)->select(); $count = Billions::alias('b')->where($where) ->alias('b') ->join('order o', 'o.id = b.order_id') ->join('goods g', 'g.id = b.goods_id') + ->join('shop s', 's.id = b.shop_id') ->count(); + // 消费订单笔数 $historyOrder = Billions::where('user_id', $user_id)->count(); + // 商家最高补贴 + $highSubsidy = Billions::where('user_id', $user_id)->sum('order_price', false); + $more = is_more($count, $page, $size); //是否有下一页 $data = [ @@ -38,8 +45,16 @@ class BillionsLogic extends Logic 'page_size' => $size, 'count' => $count, 'more' => $more, - 'historyOrder' => $historyOrder + 'historyOrder' => $historyOrder, + 'highSubsidy' => $highSubsidy ]; return $data; } + + // 获取排名 + public static function getRanking($billions_id){ + $where[] = ['billions_id', '<=', $billions_id]; + $where[] = ['state', '=', 0]; + return Billions::where($where)->count(); + } } \ No newline at end of file