调整大礼包限购
This commit is contained in:
parent
e1cc420068
commit
224f7707f1
@ -10,15 +10,18 @@
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\repositories\store\coupon;
|
||||
|
||||
|
||||
use app\common\dao\store\coupon\StoreCouponUserDao;
|
||||
use app\common\Enum;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\product\ProductCate;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* Class StoreCouponUserRepository
|
||||
@ -113,4 +116,46 @@ class StoreCouponUserRepository extends BaseRepository
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
/**
|
||||
* 大礼包限购校验
|
||||
* @param $carts
|
||||
* @param $uid
|
||||
* @return bool
|
||||
*/
|
||||
public function checkBuyLimit($carts, $uid)
|
||||
{
|
||||
$hasPlatformCard = false;
|
||||
$otherProduct = false;
|
||||
foreach ($carts as $cart) {
|
||||
if ($cart['product']->isPlatformCard()) {
|
||||
$hasPlatformCard = true;
|
||||
} else {
|
||||
$otherProduct = true;
|
||||
}
|
||||
}
|
||||
if ($hasPlatformCard && $otherProduct) {
|
||||
throw new ValidateException('大礼包不支持与其他商品一起购买');
|
||||
}
|
||||
if ($hasPlatformCard) {
|
||||
$merchantTypeId = Merchant::where('uid', $uid)->value('type_id');
|
||||
if (empty($merchantTypeId) || $merchantTypeId != 21) {
|
||||
throw new ValidateException('大礼包仅限种养殖户购买');
|
||||
}
|
||||
//平台购物卡仅能购买一次
|
||||
$productIds = ProductCate::where('mer_cate_id', env('PLATFORM_CARD_CATE_ID'))->column('product_id');
|
||||
$orderRecord = StoreOrder::alias('t1')
|
||||
->leftJoin('store_order_product t2', 't1.order_id = t2.order_id')
|
||||
->whereIn('product_id', $productIds)
|
||||
->where('t1.uid', $uid)
|
||||
->where('is_del', 0)
|
||||
->where('is_system_del', 0)
|
||||
->where('status', '<>', Enum::STATUS_REFUNDED)
|
||||
->count();
|
||||
if ($orderRecord > 0) {
|
||||
throw new ValidateException('大礼包仅能购买一次');
|
||||
}
|
||||
}
|
||||
return $hasPlatformCard;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,11 +4,8 @@ namespace app\common\repositories\store\order;
|
||||
|
||||
use app\common\dao\store\coupon\StoreCouponUserDao;
|
||||
use app\common\Enum;
|
||||
use app\common\model\store\coupon\StoreCoupon;
|
||||
use app\common\model\store\coupon\StoreCouponUser;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\product\Spu;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\repositories\system\form\FormRepository;
|
||||
use app\common\repositories\system\RecordRepository;
|
||||
use crmeb\jobs\SendSmsJob;
|
||||
@ -87,8 +84,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
//下单用户关联的商户id
|
||||
$merId = $user->getMerId();
|
||||
// 循环计算每个店铺的订单数据
|
||||
/** @var StoreCouponUserRepository $userCouponRepo */
|
||||
$userCouponRepo = app()->make(StoreCouponUserRepository::class);
|
||||
foreach ($merchantCartList as &$merchantCart) {
|
||||
$isPlatformCard = $this->checkBuyLimit($merchantCart['list'], $uid);
|
||||
$isPlatformCard = $userCouponRepo->checkBuyLimit($merchantCart['list'], $uid);
|
||||
//用户关联了商户id且下单店铺支持批发
|
||||
$isWholeSale = StoreOrder::isWholesale($merchantCart['wholesale'], $merId, $this->saleType);
|
||||
$postageRule = [];
|
||||
@ -1505,36 +1504,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
unset($merchantCart, $cart);
|
||||
}
|
||||
|
||||
/**
|
||||
* 大礼包限购校验
|
||||
* @param $carts
|
||||
* @param $uid
|
||||
* @return bool
|
||||
*/
|
||||
public function checkBuyLimit($carts, $uid)
|
||||
{
|
||||
$hasPlatformCard = false;
|
||||
foreach ($carts as $cart) {
|
||||
if ($cart['product']->isPlatformCard()) {
|
||||
$hasPlatformCard = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($hasPlatformCard) {
|
||||
$merchantTypeId = Merchant::where('uid', $uid)->value('type_id');
|
||||
if (empty($merchantTypeId) || $merchantTypeId != 21) {
|
||||
throw new ValidateException('大礼包仅限种养殖户购买');
|
||||
}
|
||||
//平台购物卡仅能购买一次
|
||||
$couponId = StoreCoupon::where('type', StoreCouponRepository::TYPE_PLATFORM_CARD)->value('coupon_id');
|
||||
$userCoupon = StoreCouponUser::where('coupon_id', $couponId)->where('uid', $uid)->value('coupon_user_id');
|
||||
if ($userCoupon > 0) {
|
||||
throw new ValidateException('大礼包仅能购买一次');
|
||||
}
|
||||
}
|
||||
return $hasPlatformCard;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user