|
@@ -103,52 +103,37 @@ class Kan extends Base
|
|
|
*/
|
|
|
public function buyCheck($buyInfo, $activity)
|
|
|
{
|
|
|
- $buy_type = request()->param('buy_type', 'kan');
|
|
|
- $groupon_id = request()->param('kan_id', 0);
|
|
|
- // 拼团
|
|
|
+ $buy_type = 'kan';
|
|
|
+ $kan_id = request()->param('kan_id', 0);
|
|
|
+ $user = auth_user();
|
|
|
+
|
|
|
+
|
|
|
+ // 砍价
|
|
|
$rules = $activity['rules'];
|
|
|
|
|
|
$currentSkuPrice = $buyInfo['current_sku_price'];
|
|
|
- $is_leader_discount = $currentSkuPrice['is_leader_discount'];
|
|
|
-
|
|
|
- // 成团人数
|
|
|
- $num = $rules['team_num'] ?? 1;
|
|
|
- // 额外需要的库存
|
|
|
- $need_add_num = 0;
|
|
|
-
|
|
|
- // 要单独购买
|
|
|
- if ($buy_type == 'alone') {
|
|
|
- // 不允许单独购买
|
|
|
- if (!$is_alone) {
|
|
|
- throw new ShoproException('该商品不允许单独购买');
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 拼团,临时将拼团价设置为商品价格
|
|
|
- if (!$groupon_id && $is_leader_discount) {
|
|
|
- // 开新团,并且有团长优惠,使用优惠价格
|
|
|
- $buyInfo['current_sku_price']['price'] = $currentSkuPrice['leader_price'];
|
|
|
- } else {
|
|
|
- // 参与团,或者没有团长优惠
|
|
|
- $buyInfo['current_sku_price']['price'] = $currentSkuPrice['groupon_price'];
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- // 如果是开新团
|
|
|
- if (!$groupon_id && $buy_type == 'groupon') {
|
|
|
- // 开团需要的最小库存
|
|
|
- $need_add_num = ($num - 1);
|
|
|
- }
|
|
|
+
|
|
|
+ //砍价情况
|
|
|
+ $map_kan = [
|
|
|
+ 'id' => $kan_id,
|
|
|
+ 'user_id' => $user['id'],
|
|
|
+ 'goods_id' => $currentSkuPrice['goods_id'],
|
|
|
+ 'goods_sku_price_id' => $currentSkuPrice['id'],
|
|
|
+ 'activity_id' => $currentSkuPrice['activity_id'],
|
|
|
+ 'status' => ['IN',['ing','finish']],
|
|
|
+ ];
|
|
|
+ $kan_total_price = Db::name('shopro_activity_kan')->where($map_kan)->value('total_kan_price');
|
|
|
+ $kan_price = $kan_total_price ? $kan_total_price : 0;
|
|
|
+ //砍价情况
|
|
|
+
|
|
|
+ $buyInfo['current_sku_price']['price'] = $buyInfo['current_sku_price']['old_price'] - $kan_total_price;
|
|
|
+
|
|
|
|
|
|
// 当前库存,小于要购买的数量
|
|
|
$need_num = $buyInfo['goods_num'] + ($need_add_num ?? 0);
|
|
|
if ($currentSkuPrice['stock'] < $need_num) {
|
|
|
- if ($need_add_num && $is_alone && !$groupon_id && $buy_type == 'groupon') {
|
|
|
- throw new ShoproException('商品库存不足以开团,请选择单独购买');
|
|
|
- } else if ($buy_type == 'alone') {
|
|
|
- throw new ShoproException('商品库存不足');
|
|
|
- } else {
|
|
|
- throw new ShoproException('该商品不允商品库存不足以开团许单独购买');
|
|
|
- }
|
|
|
+ throw new ShoproException('商品库存不足');
|
|
|
}
|
|
|
|
|
|
$buyInfo['is_commission'] = $rules['is_commission'] ?? 0; // 是否参与分销
|