调整活动
parent
641b8f9e46
commit
661c9739a7
|
|
@ -245,7 +245,8 @@ class ActivityController extends AdminController
|
||||||
0=>'按订单赠送',
|
0=>'按订单赠送',
|
||||||
1=>'其他活动来源',
|
1=>'其他活动来源',
|
||||||
])->default(0);
|
])->default(0);
|
||||||
$form->number('value', '门槛')->help('每N元赠送一份');
|
$form->number('value', '门槛')->help('满N元赠送');
|
||||||
|
// $form->number('qty', '总量')->help('前N单能获得');
|
||||||
$form->radio('times', '可领次数')->options([
|
$form->radio('times', '可领次数')->options([
|
||||||
'0'=>'仅首单',
|
'0'=>'仅首单',
|
||||||
'1'=>'不限',
|
'1'=>'不限',
|
||||||
|
|
@ -257,7 +258,8 @@ class ActivityController extends AdminController
|
||||||
0=>'按订单赠送',
|
0=>'按订单赠送',
|
||||||
1=>'其他活动来源',
|
1=>'其他活动来源',
|
||||||
])->default(0);
|
])->default(0);
|
||||||
$form->number('value', '门槛')->help('每N元赠送一份');
|
$form->number('value', '门槛')->help('满N元赠送');
|
||||||
|
// $form->number('qty', '总量')->help('前N单能获得');
|
||||||
$form->radio('times', '可领次数')->options([
|
$form->radio('times', '可领次数')->options([
|
||||||
'0'=>'仅首单',
|
'0'=>'仅首单',
|
||||||
'1'=>'不限',
|
'1'=>'不限',
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ class UserCoupon extends Model
|
||||||
'is_use',
|
'is_use',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
|
'activity_id',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,7 @@ class CouponService
|
||||||
*/
|
*/
|
||||||
public function receiveActivityCoupons(Activity $activity, User $user)
|
public function receiveActivityCoupons(Activity $activity, User $user)
|
||||||
{
|
{
|
||||||
|
$someCoupons = [];
|
||||||
foreach ($activity->coupons as $coupon) {
|
foreach ($activity->coupons as $coupon) {
|
||||||
$someCoupons[] = [
|
$someCoupons[] = [
|
||||||
'coupon'=>$coupon,
|
'coupon'=>$coupon,
|
||||||
|
|
@ -121,7 +122,7 @@ class CouponService
|
||||||
$coupon['coupon']->decrement('stock', $coupon['num']);
|
$coupon['coupon']->decrement('stock', $coupon['num']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// dd($userCoupons);
|
||||||
UserCoupon::insert($userCoupons);
|
UserCoupon::insert($userCoupons);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -421,40 +421,45 @@ class OrderService
|
||||||
}
|
}
|
||||||
//返回赠品
|
//返回赠品
|
||||||
$_gifts = $partActivity->activity->gifts;
|
$_gifts = $partActivity->activity->gifts;
|
||||||
|
$_num = 0;
|
||||||
foreach ($_gifts as $_gift) {
|
foreach ($_gifts as $_gift) {
|
||||||
$giveGifts[] = [
|
if ($_gift->stock - $_gift->pivot->qty >= 0) {
|
||||||
'gift_for_sku_id'=> null,
|
$_num += $_gift->pivot->qty;
|
||||||
'user_id' => $order->user_id,
|
$giveGifts[] = [
|
||||||
'order_id' => $order->id,
|
'gift_for_sku_id'=> null,
|
||||||
'spu_id' => $_gift->spu_id,
|
'user_id' => $order->user_id,
|
||||||
'sku_id' => $_gift->id,
|
'order_id' => $order->id,
|
||||||
'category_id' => $_gift->category_id,
|
'spu_id' => $_gift->spu_id,
|
||||||
'name' => $_gift->name,
|
'sku_id' => $_gift->id,
|
||||||
'specs' => json_encode($_gift->specs),
|
'category_id' => $_gift->category_id,
|
||||||
'cover' => $_gift->cover,
|
'name' => $_gift->name,
|
||||||
'weight' => $_gift->weight,
|
'specs' => json_encode($_gift->specs),
|
||||||
'sell_price' => $_gift->sell_price,
|
'cover' => $_gift->cover,
|
||||||
'vip_price' => $_gift->vip_price,
|
'weight' => $_gift->weight,
|
||||||
'sales_value' => 0, // 赠品不算销售值
|
'sell_price' => $_gift->sell_price,
|
||||||
'quantity' => $_gift->pivot->qty,
|
'vip_price' => $_gift->vip_price,
|
||||||
'remain_quantity' => $_gift->pivot->qty, // 剩余发货数量
|
'sales_value' => 0, // 赠品不算销售值
|
||||||
'coupon_discount_amount' => 0,
|
'quantity' => $_gift->pivot->qty,
|
||||||
'vip_discount_amount' => 0,
|
'remain_quantity' => $_gift->pivot->qty, // 剩余发货数量
|
||||||
'total_amount' => 0,
|
'coupon_discount_amount' => 0,
|
||||||
'created_at' => $order->created_at,
|
'vip_discount_amount' => 0,
|
||||||
'updated_at' => $order->updated_at,
|
'total_amount' => 0,
|
||||||
'is_gift'=> true,
|
'created_at' => $order->created_at,
|
||||||
'activity_id'=>$partActivity->activity_id,
|
'updated_at' => $order->updated_at,
|
||||||
];
|
'is_gift'=> true,
|
||||||
// 扣除商品库存
|
'activity_id'=>$partActivity->activity_id,
|
||||||
$this->deductProduct($_gift, $_gift->pivot->qty);
|
];
|
||||||
|
// 扣除商品库存
|
||||||
|
$this->deductProduct($_gift, $_gift->pivot->qty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($_num > 0) {
|
||||||
|
//记录订单参与活动信息
|
||||||
|
OrderActivity::firstOrCreate([
|
||||||
|
'order_id'=>$order->id,
|
||||||
|
'activity_id'=>$partActivity->activity_id,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//记录订单参与活动信息
|
|
||||||
OrderActivity::firstOrCreate([
|
|
||||||
'order_id'=>$order->id,
|
|
||||||
'activity_id'=>$partActivity->activity_id,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $giveGifts;
|
return $giveGifts;
|
||||||
|
|
@ -1001,21 +1006,32 @@ class OrderService
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$gift = ProductGift::where('sku_id', $product->gift_for_sku_id)
|
//原赠品
|
||||||
->where('gift_sku_id', $product->sku_id)
|
if ($product->gift_for_sku_id) {
|
||||||
->first();
|
$gift = ProductGift::where('sku_id', $product->gift_for_sku_id)
|
||||||
|
->where('gift_sku_id', $product->sku_id)
|
||||||
|
->first();
|
||||||
|
|
||||||
if ($gift === null) {
|
if ($gift === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($gift->isLimit()) {
|
||||||
|
$gift->update([
|
||||||
|
'remaining' => DB::raw("remaining+{$product->quantity}"),
|
||||||
|
'sent' => DB::raw("sent-{$product->quantity}"),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$gift->decrement('sent', $product->quantity);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
} else {//新赠品, 则直接增加商品库存
|
||||||
|
$product->spu?->increment('sales', -$product->quantity);
|
||||||
if ($gift->isLimit()) {
|
$product->sku?->update([
|
||||||
$gift->update([
|
'stock' => DB::Raw("stock + {$product->quantity}"),
|
||||||
'remaining' => DB::raw("remaining+{$product->quantity}"),
|
'sales' => DB::Raw("sales - {$product->quantity}"),
|
||||||
'sent' => DB::raw("sent-{$product->quantity}"),
|
|
||||||
]);
|
]);
|
||||||
} else {
|
continue;
|
||||||
$gift->decrement('sent', $product->quantity);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue