修改后台部分问题
parent
1db88d7a2d
commit
b317777eed
|
|
@ -38,13 +38,18 @@ class CouponController extends AdminController
|
|||
}
|
||||
})->label();
|
||||
$grid->column('threshold')->append('元');
|
||||
$grid->column('limit');
|
||||
$grid->column('limit')->display(function ($value) {
|
||||
if ($value == 0) {
|
||||
return '不限量';
|
||||
}
|
||||
return $value;
|
||||
});
|
||||
$grid->column('sent');
|
||||
$grid->column('use_day')->append('天');
|
||||
$grid->column('use_start_at');
|
||||
$grid->column('use_end_at');
|
||||
$grid->column('created_at')->sortable();
|
||||
|
||||
$grid->model()->orderBy('created_at', 'desc');
|
||||
/** 操作 **/
|
||||
//新增
|
||||
if (Admin::user()->can('dcat.admin.coupons.create')) {
|
||||
|
|
@ -108,8 +113,7 @@ class CouponController extends AdminController
|
|||
$form->text('name')->required();
|
||||
$form->number('limit')->min(0)->default(0)->help('0为不限量');
|
||||
|
||||
if ($form->isEditing()) {
|
||||
if (!$form->model()->hasReceived()) {
|
||||
if ($form->isCreating() || ($form->isEditing() && !$form->model()->hasReceived())) {
|
||||
$form->radio('type')
|
||||
->when(1, function (Form $form) {
|
||||
$form->currency('amount1')->symbol('¥')->help('例:100.00表示优惠100元。')->value($form->model()->amount);
|
||||
|
|
@ -127,7 +131,6 @@ class CouponController extends AdminController
|
|||
$form->number('use_day')->min(0)->default(1)->help('单位:天;指领取后几天内有效。');
|
||||
$form->datetimeRange('use_start_at', 'use_end_at', '使用时间')->help('设置时间后,期限字段失效。');
|
||||
}
|
||||
}
|
||||
|
||||
// $form->editing(function (Form $form) {
|
||||
// if (!$form->model()->hasReceived()) {
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ class ShippingTemplateController extends AdminController
|
|||
*/
|
||||
public function ruleList(Content $content, ShippingTemplateModel $template)
|
||||
{
|
||||
return $content->header(__('coupon.labels.coupons'))
|
||||
return $content->header(__('shipping-rule.labels.ShippingRule'))
|
||||
->description($template->name)
|
||||
->body(ShippingRuleTable::grid($template->id));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Admin\Renderable;
|
||||
|
||||
use App\Admin\Repositories\CouponRange;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\ProductCategory;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Grid;
|
||||
|
|
@ -41,11 +42,12 @@ class CouponRangeTable extends Grid
|
|||
});
|
||||
$grid->column('created_at');
|
||||
$grid->column('updated_at')->sortable();
|
||||
$grid->model()->orderBy('created_at', 'desc');
|
||||
|
||||
/** 操作 **/
|
||||
//新增
|
||||
if (Admin::user()->can('dcat.admin.coupon_ranges.create')) {
|
||||
$grid->disableCreateButton(false);
|
||||
// $grid->disableCreateButton(false);
|
||||
$grid->enableDialogCreate();
|
||||
}
|
||||
//修改
|
||||
|
|
@ -63,6 +65,10 @@ class CouponRangeTable extends Grid
|
|||
$grid->model()->setConstraints([
|
||||
'coupon_id' => $couponId,
|
||||
]);
|
||||
$coupon = Coupon::findOrFail($couponId);
|
||||
if ($coupon->hasReceived()) {
|
||||
$grid->disableCreateButton();
|
||||
}
|
||||
}
|
||||
return $grid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,4 +22,14 @@ class UserCoupon extends Model
|
|||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 优惠券可用范围规则
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function ranges()
|
||||
{
|
||||
return $this->hasMany(CouponRange::class, 'coupon_id', 'coupon_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\ProductSku;
|
||||
use App\Models\User;
|
||||
use App\Models\UserCoupon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class CouponService
|
||||
{
|
||||
/**
|
||||
* 根据SKU商品ids获取可用优惠券
|
||||
*
|
||||
* @return collection
|
||||
*/
|
||||
public function availableCouponsToUser(User $user, collection $skus): collection
|
||||
{
|
||||
//获取用户当前所有可用券
|
||||
$coupons = $this->userCalidCoupons($user);
|
||||
//判断券在这批商品中是否可用
|
||||
$availableCouponIds = [];
|
||||
$availableCoupons = [];
|
||||
foreach ($coupons as $coupon) {
|
||||
if (in_array($coupon->coupon_id, $availableCouponIds)) {//遇到同样的券ID时直接跳过
|
||||
$availableCoupons[] = $coupon;
|
||||
} else {
|
||||
if ($this->isAvailableCouponToSomeSku($skus, $coupon)) {
|
||||
$availableCouponIds[] = $coupon->coupon_id;
|
||||
$availableCoupons[] = $coupon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return collect($availableCoupons);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户有效的优惠券
|
||||
*
|
||||
* @param User $user
|
||||
* @return collection
|
||||
*/
|
||||
public function userCalidCoupons(User $user): collection
|
||||
{
|
||||
return UserCoupon::with('ranges')->where([
|
||||
'user_id'=>$user->id,
|
||||
'status'=>0,
|
||||
])->where('use_start_at', '<=', now())->where('use_end_at', '>=', now())->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 这批商品中,这个券是否可用
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isAvailableCouponToSomeSku(collection $skus, UserCoupon $coupon)
|
||||
{
|
||||
$res = false;
|
||||
foreach ($skus as $sku) {
|
||||
if ($sku instanceof ProductSku && $this->isAvailableCouponToSku($sku, $coupon)) {
|
||||
$res = true;
|
||||
break;//提前退出循环
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 这个商品是否可用这个券
|
||||
*
|
||||
* @param ProductSku $productSku
|
||||
* @param Coupon $coupon
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isAvailableCouponToSku(ProductSku $sku, UserCoupon $coupon)
|
||||
{
|
||||
$res = false;
|
||||
foreach ($coupon->ranges as $range) {
|
||||
switch ($range->type) {
|
||||
case 1://指定商品分类
|
||||
if (in_array($sku->category_id, explode(',', $range->ranges))) {
|
||||
$res = true;
|
||||
}
|
||||
break;
|
||||
case 2://指定商品IDS
|
||||
if (in_array($sku->id, explode(',', $range->ranges))) {
|
||||
$res = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($res) {//如果可用提前跳出循环;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
|
@ -70,7 +70,11 @@ class AdminMenuSeeder extends Seeder
|
|||
'icon' => '',
|
||||
'uri' => 'coupons',
|
||||
],
|
||||
|
||||
[
|
||||
'title' => '运费模板管理',
|
||||
'icon' => '',
|
||||
'uri' => 'shipping-templates',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
|
|
@ -104,7 +108,7 @@ class AdminMenuSeeder extends Seeder
|
|||
'uri' => 'product-groups',
|
||||
],
|
||||
[
|
||||
'title'=> '商品标签',
|
||||
'title'=> '商品特点',
|
||||
'icon' => '',
|
||||
'uri' => 'product-features',
|
||||
],
|
||||
|
|
@ -113,11 +117,6 @@ class AdminMenuSeeder extends Seeder
|
|||
'icon' => '',
|
||||
'uri' => 'product-buynotes',
|
||||
],
|
||||
[
|
||||
'title' => '运费模板管理',
|
||||
'icon' => '',
|
||||
'uri' => 'shipping-templates',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
return [
|
||||
'labels' => [
|
||||
'ShippingRule' => 'ShippingRule',
|
||||
'shipping-rule' => 'ShippingRule',
|
||||
'ShippingRule' => '运费规则',
|
||||
'shipping-rules' => '运费规则',
|
||||
],
|
||||
'fields' => [
|
||||
'template_id' => '运费模板',
|
||||
|
|
|
|||
Loading…
Reference in New Issue