From 2c06abadf494f10716e58d2f5421f68ed2de24d3 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Mon, 11 Mar 2024 10:32:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BA=A2=E5=8C=85=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/StoreActivityUserDao.php | 29 +++++++++++++++++++ app/controller/api/store/StoreActivity.php | 20 ++++++++++++- route/api.php | 1 + 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/app/common/dao/store/StoreActivityUserDao.php b/app/common/dao/store/StoreActivityUserDao.php index 1006aa55..56ee6dff 100755 --- a/app/common/dao/store/StoreActivityUserDao.php +++ b/app/common/dao/store/StoreActivityUserDao.php @@ -5,6 +5,7 @@ namespace app\common\dao\store; use app\common\dao\BaseDao; use app\common\dao\store\consumption\StoreConsumptionUserDao; use app\common\model\store\consumption\StoreConsumption; +use app\common\model\store\consumption\StoreConsumptionDetail; use app\common\model\store\consumption\StoreConsumptionUser; use app\common\model\store\StoreActivityOrder; use app\common\model\store\StoreActivityUser; @@ -249,6 +250,34 @@ class StoreActivityUserDao extends BaseDao return ['total_amount' => $totalAmount, 'count' => $count, 'record' => $record]; } + /** + * 红包获取记录 + * @param int $userId + * @param int $type + * @param int $page + * @param int $limit + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function useRecord(int $userId, int $type, int $page, int $limit) + { + $totalAmount = StoreConsumptionUser::where('uid', $userId) + ->whereIn('type', $type) + ->where('status', StoreConsumptionUser::STATUS_UNUSED) + ->sum('balance'); + $query = StoreConsumptionDetail::field('create_time,order_id,amount coupon_price,pay_price') + ->where('user_id', $userId) + ->where('type', 1); + $count = $query->count(); + $record = $query->page($page)->limit($limit)->select()->toArray(); + foreach ($record as &$item) { + $item['order_amount'] = bcadd($item['coupon_price'], $item['pay_price'], 2); + } + return ['total_amount' => $totalAmount, 'count' => $count, 'record' => $record]; + } + /** * 红包余额统计 * @param int $userId diff --git a/app/controller/api/store/StoreActivity.php b/app/controller/api/store/StoreActivity.php index ecb77a82..4aa74048 100755 --- a/app/controller/api/store/StoreActivity.php +++ b/app/controller/api/store/StoreActivity.php @@ -133,4 +133,22 @@ class StoreActivity extends BaseController return app('json')->success($result); } -} \ No newline at end of file + /** + * 红包获取记录 + * @param StoreActivityUserDao $dao + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function useRecord(StoreActivityUserDao $dao) + { + $userId = $this->request->uid(); + $type = $this->request->get('type', 1); + $page = $this->request->get('page', 1); + $limit = $this->request->get('limit', 10); + $result = $dao->useRecord($userId, $type, $page, $limit); + return app('json')->success($result); + } + +} diff --git a/route/api.php b/route/api.php index e5ed425a..ad1f009c 100755 --- a/route/api.php +++ b/route/api.php @@ -476,6 +476,7 @@ Route::group('api/', function () { Route::get('total', 'api.store.StoreActivity/total'); //活动红包统计 Route::get('product', 'api.store.StoreActivity/product'); //活动商品专区 Route::get('district', 'api.store.StoreActivity/district'); //活动地区列表 + Route::get('useRecord', 'api.store.StoreActivity/useRecord'); //活动红包获取记录 }); })->middleware(UserTokenMiddleware::class, true);