diff --git a/app/Model/v3/ShoppingCart.php b/app/Model/v3/ShoppingCart.php index a730691..b07b814 100644 --- a/app/Model/v3/ShoppingCart.php +++ b/app/Model/v3/ShoppingCart.php @@ -3,11 +3,9 @@ namespace App\Model\v3; use App\Model\Model; -use Hyperf\Database\Model\SoftDeletes; class ShoppingCart extends Model { - use SoftDeletes; protected $table = 'lanzu_shopping_cart'; diff --git a/app/Service/v3/Implementations/CouponRecService.php b/app/Service/v3/Implementations/CouponRecService.php index ac57d12..aa2e49c 100644 --- a/app/Service/v3/Implementations/CouponRecService.php +++ b/app/Service/v3/Implementations/CouponRecService.php @@ -164,13 +164,65 @@ class CouponRecService implements CouponRecServiceInterface $carts = $this->shopCartService->allForUser($userId, $marketId); $totalAmount = $carts['total']; - // 获取用户可用优惠券(1) - $coupons = CouponRec::query() - ->join('lanzu_coupon as coupon', 'coupon.id', '=', '') - ->where(['user_id' => $userId]) - ->where('number_remain', '>', 0) - ->whereIn('status', [0,1]) - ->get(); + // 获取购物车中商品和店铺的类别 + $storeCategoryIds = []; + $goodsCategoryIds = []; + foreach ($carts as $key => &$cart) { + if (isset($cart['store']['category_id']) && $cart['store']['category_id']) { + array_push($storeCategoryIds, $cart['store']['category_id']); + } + + if (isset($cart['shopping_cart']) && is_array($cart['shopping_cart'])) { + foreach ($cart['shopping_cart'] as $key2 => &$goods) { + if (isset($goods['goods']['category_id']) && $goods['goods']['category_id']) { + array_push($goodsCategoryIds, $goods['goods']['category_id']); + } + } + } + } + $categoryIds = array_merge($storeCategoryIds, $goodsCategoryIds); + + $coupon = ApplicationContext::getContainer()->get(Coupon::class); + $couponRec = ApplicationContext::getContainer()->get(Coupon::class); + $couponTable = $coupon->getTable(); + $receiveTable = $couponRec->getTable(); + + $currentTime = time(); + + // 获取用户已领取的优惠券,同时是在使用期内的优惠券 + $builder = $couponRec->join($couponTable, "{$couponTable}.id", "=", "{$receiveTable}.coupon_id") + ->where("{$receiveTable}.user_id", $userId) + ->where("{$receiveTable}.number_remain", ">", 0) + ->whereIn("{$receiveTable}.status", [0,1]) + ->where("{$couponTable}.usable_start_time", "<=", $currentTime) + ->where("{$couponTable}.usable_end_time", ">=", $currentTime); + + if (!empty($marketId)) { # 市场限制 + $builder->where(function ($query) use ($marketId, $couponTable) { + return $query->whereJsonContains("{$couponTable}.market_ids", [(string)$marketId]) + ->orWhereJsonLength("{$couponTable}.market_ids", '=', 0); + }); + } + + if (!empty($categoryIds)) { # 分类限制 + $builder->where(function ($query) use ($categoryIds, $couponTable) { + return $query->whereJsonContains("{$couponTable}.category_ids", $categoryIds) + ->orWhereJsonLength("{$couponTable}.category_ids", '=', 0); + }); + } + + $couponReceives = $builder->orderByRaw("{$couponTable}.usable_end_time ASC")->get(); + + // 循环摘出失效不可用的优惠券 + foreach ($couponReceives as $key => &$couponReceive) { + + // 有活动商品不可用优惠券,全部都不可用了 + + // 不满订单金额 + + // 今日已使用 + + } } diff --git a/app/Service/v3/Implementations/WxLoginService.php b/app/Service/v3/Implementations/WxLoginService.php index 97a0e3a..032e788 100644 --- a/app/Service/v3/Implementations/WxLoginService.php +++ b/app/Service/v3/Implementations/WxLoginService.php @@ -36,7 +36,7 @@ class WxLoginService implements \App\Service\v3\Interfaces\WxLoginServiceInterfa // 登录成功 $hash = ApplicationContext::getContainer()->get(Hashids::class); - $hashIds = $hash->encode((int)$user['id'], time()); + $hashIds = $hash->encode((int)$user['id']); $user['user_token'] = $hashIds; $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); diff --git a/app/Service/v3/Interfaces/CouponRecServiceInterface.php b/app/Service/v3/Interfaces/CouponRecServiceInterface.php index 34ebfaa..bb37912 100644 --- a/app/Service/v3/Interfaces/CouponRecServiceInterface.php +++ b/app/Service/v3/Interfaces/CouponRecServiceInterface.php @@ -9,4 +9,5 @@ interface CouponRecServiceInterface public function undo(); public function allForOrderOlAvailable($totalAmount,$userId,$marketId,$type,$storeTypeId); public function getListByUser($userId,$type,$page = 1,$pagesize = 5); + public function allForOnlineOrderAvailable($userId, $marketId); } \ No newline at end of file