From 7b10f1a51bb1788fe1f3191f4f80be11c243a358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=98=8A=E5=A4=A9?= <442384644@qq.com> Date: Wed, 4 Jan 2023 18:15:16 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=A8=8B=E5=BA=8F=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E3=80=91=E4=BC=98=E6=83=A0=E5=88=B8=E9=97=AE=E9=A2=98=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity/coupon/StoreCouponIssueDao.php | 38 +++++++++++-------- .../coupon/StoreCouponIssueServices.php | 14 +++---- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/crmeb/app/dao/activity/coupon/StoreCouponIssueDao.php b/crmeb/app/dao/activity/coupon/StoreCouponIssueDao.php index b4bf3acfa..fa071b517 100644 --- a/crmeb/app/dao/activity/coupon/StoreCouponIssueDao.php +++ b/crmeb/app/dao/activity/coupon/StoreCouponIssueDao.php @@ -74,7 +74,7 @@ class StoreCouponIssueDao extends BaseDao * 获取优惠券列表 * @param int $uid 用户ID * @param int $type 0通用,1分类,2商品 - * @param int $typeId 分类ID或商品ID + * @param array|int $typeId 分类ID或商品ID * @param int $page * @param int $limit * @return array @@ -101,11 +101,13 @@ class StoreCouponIssueDao extends BaseDao }]) ->where('type', $type) ->when($type == 1, function ($query) use ($typeId) { - $query->where(function ($query) use ($typeId) { - $query->where('id', 'in', function ($query) use ($typeId) { - $query->name('store_coupon_product')->whereIn('category_id', $typeId)->field(['coupon_id'])->select(); - })->whereOr('category_id', 'in', $typeId); - }); + if ($typeId) { + $query->where(function ($query) use ($typeId) { + $query->where('id', 'in', function ($query) use ($typeId) { + $query->name('store_coupon_product')->whereIn('category_id', $typeId)->field(['coupon_id'])->select(); + })->whereOr('category_id', 'in', $typeId); + }); + } }) ->when($type == 2, function ($query) use ($typeId) { if ($typeId) $query->whereFindinSet('product_id', $typeId); @@ -153,11 +155,11 @@ class StoreCouponIssueDao extends BaseDao /** * 获取优惠券数量 - * @param int $productId - * @param int $cateId + * @param $productId + * @param $cateId * @return mixed */ - public function getIssueCouponCount($productId = 0, $cateId = 0) + public function getIssueCouponCount($productId, $cateId) { $model = function ($query) { $query->where('status', 1) @@ -174,12 +176,18 @@ class StoreCouponIssueDao extends BaseDao }); }; $count[0] = $this->getModel()->where($model)->where('type', 0)->count(); - $count[1] = $this->getModel()->where($model)->where('type', 1)->when($cateId != 0, function ($query) use ($cateId) { - if ($cateId) $query->where('category_id', 'in', $cateId); - })->count(); - $count[2] = $this->getModel()->where($model)->where('type', 2)->when($productId != 0, function ($query) use ($productId) { - if ($productId) $query->whereFindinSet('product_id', $productId); - })->count(); + $count[1] = $this->getModel()->where($model)->where('type', 1) + ->when(count($cateId) != 0, function ($query) use ($cateId) { + $query->where(function ($query) use ($cateId) { + $query->where('id', 'in', function ($query) use ($cateId) { + $query->name('store_coupon_product')->whereIn('category_id', $cateId)->field(['coupon_id'])->select(); + })->whereOr('category_id', 'in', $cateId); + }); + })->count(); + $count[2] = $this->getModel()->where($model)->where('type', 2) + ->when($productId != 0, function ($query) use ($productId) { + if ($productId) $query->whereFindinSet('product_id', $productId); + })->count(); return $count; } diff --git a/crmeb/app/services/activity/coupon/StoreCouponIssueServices.php b/crmeb/app/services/activity/coupon/StoreCouponIssueServices.php index b78fc3c47..fe36d03dd 100644 --- a/crmeb/app/services/activity/coupon/StoreCouponIssueServices.php +++ b/crmeb/app/services/activity/coupon/StoreCouponIssueServices.php @@ -296,24 +296,22 @@ class StoreCouponIssueServices extends BaseServices public function getIssueCouponList(int $uid, array $where) { [$page, $limit] = $this->getPageValue(); + $cateId = []; if ($where['product_id'] == 0) { - $typeId = 0; - $cateId = 0; if ($where['type'] == -1) { // PC端获取优惠券 - $list = $this->dao->getPcIssueCouponList($uid, [], 0, 0); + $list = $this->dao->getPcIssueCouponList($uid, []); } else { - $list = $this->dao->getIssueCouponList($uid, (int)$where['type'], $typeId, $page, $limit); - if (!$list) $list = $this->dao->getIssueCouponList($uid, 1, $typeId, $page, $limit); - if (!$list) $list = $this->dao->getIssueCouponList($uid, 2, $typeId, $page, $limit); + $list = $this->dao->getIssueCouponList($uid, (int)$where['type'], 0, $page, $limit); + if (!$list) $list = $this->dao->getIssueCouponList($uid, 1, 0, $page, $limit); + if (!$list) $list = $this->dao->getIssueCouponList($uid, 2, 0, $page, $limit); } } else { /** @var StoreProductServices $storeProductService */ $storeProductService = app()->make(StoreProductServices::class); /** @var StoreCategoryServices $storeCategoryService */ $storeCategoryService = app()->make(StoreCategoryServices::class); - $cateId = $storeProductService->value(['id' => $where['product_id']], 'cate_id'); - $cateId = explode(',', $cateId); + $cateId = explode(',', (string)$cateId); $cateId = array_merge($cateId, $storeCategoryService->cateIdByPid($cateId)); $cateId = array_diff($cateId, [0]); if ($where['type'] == -1) { // PC端获取优惠券