调整活动
parent
48385aa158
commit
34e2dbaee5
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Admin\Controllers;
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
use App\Admin\Repositories\Activity;
|
use App\Admin\Repositories\Activity;
|
||||||
|
use App\Models\Activity as ActivityModel;
|
||||||
use App\Models\Coupon;
|
use App\Models\Coupon;
|
||||||
use App\Models\ProductPart;
|
use App\Models\ProductPart;
|
||||||
use App\Models\ProductSku;
|
use App\Models\ProductSku;
|
||||||
|
|
@ -12,6 +13,7 @@ use Dcat\Admin\Form;
|
||||||
use Dcat\Admin\Grid;
|
use Dcat\Admin\Grid;
|
||||||
use Dcat\Admin\Grid\Column;
|
use Dcat\Admin\Grid\Column;
|
||||||
use Dcat\Admin\Http\Controllers\AdminController;
|
use Dcat\Admin\Http\Controllers\AdminController;
|
||||||
|
use Dcat\Admin\Layout\Row;
|
||||||
use Dcat\Admin\Show;
|
use Dcat\Admin\Show;
|
||||||
|
|
||||||
class ActivityController extends AdminController
|
class ActivityController extends AdminController
|
||||||
|
|
@ -72,19 +74,111 @@ class ActivityController extends AdminController
|
||||||
*/
|
*/
|
||||||
protected function detail($id)
|
protected function detail($id)
|
||||||
{
|
{
|
||||||
return Show::make($id, new Activity(), function (Show $show) {
|
return function (Row $row) use ($id) {
|
||||||
$show->field('id');
|
$activity = ActivityModel::with(['parts', 'coupons', 'gifts'])->findOrFail($id);
|
||||||
$show->field('title');
|
$row->column(6, function ($column) use ($activity) {
|
||||||
$show->field('cover');
|
$column->row(Show::make($activity, function (Show $show) use ($activity) {
|
||||||
$show->field('content');
|
$show->row(function (Show\Row $show) use ($activity) {
|
||||||
$show->field('is_use');
|
$show->field('id')->width(10, 1);
|
||||||
$show->field('started_at');
|
$show->field('title')->width(10, 1);
|
||||||
$show->field('ended_at');
|
$show->field('cover')->width(10, 1)->image();
|
||||||
$show->field('coupons_rule');
|
$show->field('is_use')->using([0=>'未开启', '已开启'])->dot([
|
||||||
$show->field('gifts_rule');
|
'0'=>'#b3b9bf',
|
||||||
$show->field('created_at');
|
'1'=>'success',
|
||||||
$show->field('updated_at');
|
])->width(10, 1);
|
||||||
|
$show->width(6)->field('started_at');
|
||||||
|
$show->width(6)->field('ended_at');
|
||||||
|
$show->width(12)->field('parts', '分区关联')->width(10, 1)->as(function ($value) {
|
||||||
|
return array_column($value, 'name');
|
||||||
|
})->label();
|
||||||
|
|
||||||
|
foreach ($activity->coupons as $coupon) {
|
||||||
|
$show->width(6)->field('coupon.name', '优惠券名称')->as(function () use ($coupon) {
|
||||||
|
return $coupon->name;
|
||||||
|
})->label();
|
||||||
|
$show->width(6)->field('coupon.qty', '赠送数量')->as(function () use ($coupon) {
|
||||||
|
return $coupon->pivot->qty;
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
foreach ($activity->gifts as $gift) {
|
||||||
|
$show->width(6)->field('gift.name', '赠品名称')->as(function () use ($gift) {
|
||||||
|
return $gift->name;
|
||||||
|
})->label();
|
||||||
|
$show->width(6)->field('gift.qty', '赠送数量')->as(function () use ($gift) {
|
||||||
|
return $gift->pivot->qty;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$show->width(6)->field('created_at');
|
||||||
|
$show->width(6)->field('updated_at');
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
$row->column(6, function ($column) use ($activity) {
|
||||||
|
$column->row(Show::make($activity, function (Show $show) use ($activity) {
|
||||||
|
$show->panel()
|
||||||
|
->tools(function ($tools) {
|
||||||
|
$tools->disableEdit();
|
||||||
|
$tools->disableList();
|
||||||
|
$tools->disableDelete();
|
||||||
|
});
|
||||||
|
$show->row(function (Show\Row $show) {
|
||||||
|
$show->width(12)->field('coupons_rule')->as(function ($value) {
|
||||||
|
$str = '';
|
||||||
|
// dd($value);
|
||||||
|
foreach ($value as $key => $v) {
|
||||||
|
switch ($key) {
|
||||||
|
case 'type':
|
||||||
|
if ($v) {
|
||||||
|
$str .= '其他活动来源-';
|
||||||
|
} else {
|
||||||
|
$str .= '按订单赠送-';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'value':
|
||||||
|
$str .= '满'.$v.'赠送-';
|
||||||
|
break;
|
||||||
|
case 'times':
|
||||||
|
if ($v) {
|
||||||
|
$str .= '不限次数-';
|
||||||
|
} else {
|
||||||
|
$str .= '仅首单-';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rtrim($str, '-');
|
||||||
|
})->width(10, 1);
|
||||||
|
$show->width(12)->field('gifts_rule')->as(function ($value) {
|
||||||
|
$str = '';
|
||||||
|
foreach ($value as $key => $v) {
|
||||||
|
switch ($key) {
|
||||||
|
case 'type':
|
||||||
|
if ($v) {
|
||||||
|
$str .= '其他活动来源-';
|
||||||
|
} else {
|
||||||
|
$str .= '按订单赠送-';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'value':
|
||||||
|
$str .= '满'.$v.'赠送-';
|
||||||
|
break;
|
||||||
|
case 'times':
|
||||||
|
if ($v) {
|
||||||
|
$str .= '不限次数-';
|
||||||
|
} else {
|
||||||
|
$str .= '仅首单-';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rtrim($str, '-');
|
||||||
|
})->width(10, 1);
|
||||||
|
$show->field('content')->unescape()->width(10, 1);
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ use App\Admin\Renderable\PackageProductSimpleTable;
|
||||||
use App\Admin\Repositories\Order;
|
use App\Admin\Repositories\Order;
|
||||||
use App\Enums\PayWay;
|
use App\Enums\PayWay;
|
||||||
use App\Models\Order as OrderModel;
|
use App\Models\Order as OrderModel;
|
||||||
|
use App\Models\OrderActivity;
|
||||||
use App\Models\OrderLog;
|
use App\Models\OrderLog;
|
||||||
use App\Models\OrderPackage;
|
use App\Models\OrderPackage;
|
||||||
use App\Models\OrderProduct;
|
use App\Models\OrderProduct;
|
||||||
|
|
@ -434,6 +435,18 @@ class OrderController extends AdminController
|
||||||
$column->row($packagesBox->collapsable());
|
$column->row($packagesBox->collapsable());
|
||||||
$logsBox = Box::make('操作记录', $orderLogoGrid);
|
$logsBox = Box::make('操作记录', $orderLogoGrid);
|
||||||
$column->row($logsBox->collapsable());
|
$column->row($logsBox->collapsable());
|
||||||
|
$activityBox = Box::make('参与活动', Grid::make(OrderActivity::with('activity'), function (Grid $grid) {
|
||||||
|
$grid->column('activity.title', '活动名称');
|
||||||
|
$grid->column('show', '活动详情')->display(function () {
|
||||||
|
return '查看';
|
||||||
|
})->link(function () {
|
||||||
|
return admin_route('activities.show', ['activity' =>$this->activity_id]);
|
||||||
|
})->setHeaderAttributes(['style' => 'color:#5b69bc']);
|
||||||
|
$grid->disableActions();
|
||||||
|
$grid->disablePagination();
|
||||||
|
$grid->disableRefreshButton();
|
||||||
|
}));
|
||||||
|
$column->row($activityBox->collapsable());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace App\Listeners;
|
||||||
|
|
||||||
use App\Events\OrderPaid;
|
use App\Events\OrderPaid;
|
||||||
use App\Models\ActivityProductPart;
|
use App\Models\ActivityProductPart;
|
||||||
|
use App\Models\OrderActivity;
|
||||||
use App\Models\ProductPartSku;
|
use App\Models\ProductPartSku;
|
||||||
use App\Models\UserCoupon;
|
use App\Models\UserCoupon;
|
||||||
use App\Services\CouponService;
|
use App\Services\CouponService;
|
||||||
|
|
@ -68,6 +69,12 @@ class SendCoupons
|
||||||
}
|
}
|
||||||
//赠券
|
//赠券
|
||||||
(new CouponService())->receiveActivityCoupons($partActivity->activity, $order->user, $order->id);
|
(new CouponService())->receiveActivityCoupons($partActivity->activity, $order->user, $order->id);
|
||||||
|
|
||||||
|
//记录订单参与活动信息
|
||||||
|
OrderActivity::firstOrCreate([
|
||||||
|
'order_id'=>$order->id,
|
||||||
|
'activity_id'=>$partActivity->activity_id,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
DB::commit();
|
DB::commit();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class OrderActivity extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
use HasDateTimeFormatter;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'order_id', 'activity_id',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function activity()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Activity::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,7 @@ use App\Exceptions\ShippingNotSupportedException;
|
||||||
use App\Models\ActivityProductPart;
|
use App\Models\ActivityProductPart;
|
||||||
use App\Models\DistributionPreIncomeJob;
|
use App\Models\DistributionPreIncomeJob;
|
||||||
use App\Models\Order;
|
use App\Models\Order;
|
||||||
|
use App\Models\OrderActivity;
|
||||||
use App\Models\OrderProduct;
|
use App\Models\OrderProduct;
|
||||||
use App\Models\ProductGift;
|
use App\Models\ProductGift;
|
||||||
use App\Models\ProductPartSku;
|
use App\Models\ProductPartSku;
|
||||||
|
|
@ -243,6 +244,7 @@ class OrderService
|
||||||
|
|
||||||
$orderProducts[] = [
|
$orderProducts[] = [
|
||||||
'gift_for_sku_id' => null,
|
'gift_for_sku_id' => null,
|
||||||
|
'activity_id'=>null,
|
||||||
'is_gift'=> false,
|
'is_gift'=> false,
|
||||||
'user_id' => $order->user_id,
|
'user_id' => $order->user_id,
|
||||||
'order_id' => $order->id,
|
'order_id' => $order->id,
|
||||||
|
|
@ -393,7 +395,7 @@ class OrderService
|
||||||
|
|
||||||
$giveGifts = [];
|
$giveGifts = [];
|
||||||
foreach ($partActivities as $partActivity) {
|
foreach ($partActivities as $partActivity) {
|
||||||
//获取活动的赠送规则
|
//获取活动的赠品赠送规则
|
||||||
$_giftsRule = $partActivity->activity?->gifts_rule;
|
$_giftsRule = $partActivity->activity?->gifts_rule;
|
||||||
//判断是否首单:times=0为仅首单赠送, 1为不限
|
//判断是否首单:times=0为仅首单赠送, 1为不限
|
||||||
if ($_giftsRule['times'] == 0 && OrderProduct::where('activity_id', $partActivity->activity_id)->exists()) {
|
if ($_giftsRule['times'] == 0 && OrderProduct::where('activity_id', $partActivity->activity_id)->exists()) {
|
||||||
|
|
@ -428,10 +430,17 @@ class OrderService
|
||||||
'created_at' => $order->created_at,
|
'created_at' => $order->created_at,
|
||||||
'updated_at' => $order->updated_at,
|
'updated_at' => $order->updated_at,
|
||||||
'is_gift'=> true,
|
'is_gift'=> true,
|
||||||
|
'activity_id'=>$partActivity->activity_id,
|
||||||
];
|
];
|
||||||
// 扣除商品库存
|
// 扣除商品库存
|
||||||
$this->deductProduct($_gift, $_gift->pivot->qty);
|
$this->deductProduct($_gift, $_gift->pivot->qty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//记录订单参与活动信息
|
||||||
|
OrderActivity::firstOrCreate([
|
||||||
|
'order_id'=>$order->id,
|
||||||
|
'activity_id'=>$partActivity->activity_id,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $giveGifts;
|
return $giveGifts;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateOrderActivitiesTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('order_activities', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->unsignedBigInteger('order_id');
|
||||||
|
$table->unsignedBigInteger('activity_id');
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->unique(['order_id', 'activity_id']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('order_activities');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,7 +9,7 @@ return [
|
||||||
'title' => '标题',
|
'title' => '标题',
|
||||||
'cover' => '封面图',
|
'cover' => '封面图',
|
||||||
'content' => '内容',
|
'content' => '内容',
|
||||||
'is_use' => '是否上架',
|
'is_use' => '状态',
|
||||||
'started_at' => '开始时间',
|
'started_at' => '开始时间',
|
||||||
'ended_at' => '结束时间',
|
'ended_at' => '结束时间',
|
||||||
'coupons_rule' => '优惠券规则',
|
'coupons_rule' => '优惠券规则',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue