调整活动

This commit is contained in:
2023-05-16 11:23:35 +08:00
parent 44de095f40
commit 538306bb4f
8 changed files with 2920 additions and 1084 deletions

1
.gitignore vendored
View File

@@ -8,3 +8,4 @@
/storage/framework /storage/framework
/storage/debugbar/ /storage/debugbar/
/bootstrap/cache /bootstrap/cache
./composer.lock

View File

@@ -24,11 +24,6 @@ class CouponController extends AdminController
$filter->column(1 / 2, function ($filter) { $filter->column(1 / 2, function ($filter) {
$filter->equal('status', '状态')->select(ActivityCoupon::STATUS); $filter->equal('status', '状态')->select(ActivityCoupon::STATUS);
$filter->between('used_at', '核销时间')->datetime(); $filter->between('used_at', '核销时间')->datetime();
$users = User::whereHas('identity', function ($query) {
$query->where('identity_id', 1);
})->get()->pluck('nickname', 'id');
$filter->where(function ($query) { $filter->where(function ($query) {
$query->whereHas('outlet', function ($query) { $query->whereHas('outlet', function ($query) {
$query->whereHas('info', function ($query) { $query->whereHas('info', function ($query) {
@@ -52,11 +47,11 @@ class CouponController extends AdminController
}, '优惠政策', 'rule_code')->select(ActivityRule::where('status', 1)->pluck('title', 'code')); }, '优惠政策', 'rule_code')->select(ActivityRule::where('status', 1)->pluck('title', 'code'));
$users = User::query() $users = User::query()
->whereHas('identity', function ($query) { ->whereHas('identity', function ($query) {
$query->where('identity_id', 1); $query->where('identity_id', 1);
}) })
->get() ->get()
->pluck('nickname', 'id'); ->pluck('nickname', 'id');
$filter->where(function ($query) { $filter->where(function ($query) {
$query->whereHas('outlet', function ($query) { $query->whereHas('outlet', function ($query) {
@@ -81,12 +76,12 @@ class CouponController extends AdminController
$grid->column('code', '卡券编号'); $grid->column('code', '卡券编号');
$grid->column('status', '状态') $grid->column('status', '状态')
->using(ActivityCoupon::STATUS) ->using(ActivityCoupon::STATUS)
->label([ ->label([
1 => 'default', 1 => 'default',
2 => 'warning', 2 => 'warning',
3 => 'info', 3 => 'info',
]); ]);
$grid->column('used_at', '核销时间'); $grid->column('used_at', '核销时间');
$grid->column('created_at', '创建时间'); $grid->column('created_at', '创建时间');
@@ -98,10 +93,10 @@ class CouponController extends AdminController
return strip_tags($value); return strip_tags($value);
}); });
$export->column('mobile', function ($value, $original) { $export->column('mobile', function ($value, $original) {
return $value . "\t"; return $value."\t";
}); });
$export->filename($this->title . date("YmdHis")); $export->filename($this->title.date("YmdHis"));
}); });
return $grid; return $grid;

View File

@@ -50,30 +50,30 @@ class IndexController extends AdminController
}); });
$grid->column('channel', '核销途径') $grid->column('channel', '核销途径')
->using(Activity::CHANNELS) ->using(Activity::CHANNELS)
->label([ ->label([
Activity::CHANNEL_YSD => 'info', Activity::CHANNEL_YSD => 'info',
Activity::CHANNEL_UNION => 'success', Activity::CHANNEL_UNION => 'success',
]); ]);
$grid->column('days', '延期(天)'); $grid->column('days', '延期(天)');
$grid->column('rule.full', '满足金额'); $grid->column('rule.full', '满足金额');
$grid->column('rule.take', '扣除金额'); $grid->column('rule.take', '扣除金额');
$grid->column('发券渠道') $grid->column('发券渠道')
->display(function () { ->display(function () {
return $this->grants->pluck('user_nickname'); return $this->grants->pluck('user_nickname');
}) })
->label() ->label()
->width(350) ->width(350)
->hide(); ->hide();
$grid->column('核券渠道') $grid->column('核券渠道')
->display(function () { ->display(function () {
return $this->verifications->pluck('user_nickname'); return $this->verifications->pluck('user_nickname');
}) })
->label() ->label()
->width(350) ->width(350)
->hide(); ->hide();
$grid->column('开始时间')->display(function () { $grid->column('开始时间')->display(function () {
return $this->type == Activity::TYPE_SCOPE ? $this->start_at->format('Y-m-d') : '---'; return $this->type == Activity::TYPE_SCOPE ? $this->start_at->format('Y-m-d') : '---';
@@ -94,6 +94,7 @@ class IndexController extends AdminController
/** /**
* Make a form builder. * Make a form builder.
*
* @return Form * @return Form
*/ */
protected function form(): Form protected function form(): Form
@@ -104,92 +105,95 @@ class IndexController extends AdminController
$form->textarea('description', '活动说明')->required(); $form->textarea('description', '活动说明')->required();
$form->select('activity_rule_id', '所属规则') $form->select('activity_rule_id', '所属规则')
->options(function ($option, $info) { ->options(function ($option, $info) {
return ActivityRule::where('status', 1)->pluck('title', 'id'); return ActivityRule::where('status', 1)->pluck('title', 'id');
}) })
->required(); ->required();
$form->number('total', '总数') $form->number('total', '总数')
->help('可发券总数0为不限制') ->help('可发券总数0为不限制')
->default(10000) ->default(10000)
->required(); ->required();
$form->radio('type', '类型') $form->radio('type', '类型')
->options(Activity::TYPES) ->options(Activity::TYPES)
->when(Activity::TYPE_EXTEND, function (Form $form) { ->when(Activity::TYPE_EXTEND, function (Form $form) {
$form->number('days', '延期天数')->default(60)->help('到期日期=发券日期+延期天数'); $form->number('days', '延期天数')->default(60)->help('到期日期=发券日期+延期天数');
}) })
->when(Activity::TYPE_SCOPE, function (Form $form) { ->when(Activity::TYPE_SCOPE, function (Form $form) {
$form->dateRange('start_at', 'end_at', '有效时间'); $form->dateRange('start_at', 'end_at', '有效时间');
}) })
->required(); ->help('当月券,领取的月底到期')
->required();
$form->radio('channel', '核销途径') $form->radio('channel', '核销途径')
->options(Activity::CHANNELS) ->options(Activity::CHANNELS)
->default(Activity::CHANNEL_YSD) ->default(Activity::CHANNEL_YSD)
->help('券码核销的途径亿时代是自己核销银联是银联pos核销') ->help('券码核销的途径亿时代是自己核销银联是银联pos核销')
->required(); ->required();
$form->number('day_times','每天可用次数')->default(0)->help('每天可用次数0未不限制');
$form->switch('status', '状态')->default(1); $form->switch('status', '状态')->default(1);
$form->switch('need_check', '多次校验') $form->switch('need_check', '多次校验')
->default(1) ->default(1)
->help('同一订单多次核销时校验订单每满100元可核销一笔。'); ->help('同一订单多次核销时校验订单每满100元可核销一笔。');
$users = User::query() $users = User::query()
->with('info') ->with('info')
->whereHas('identity', function ($q) { ->whereHas('identity', function ($q) {
$q->where('identity_id', 1); $q->where('identity_id', 1);
}) })
->orderBy('id', 'desc') ->orderBy('id', 'desc')
->get() ->get()
->pluck('nickname', 'id'); ->pluck('nickname', 'id');
$form->listbox('grants.user_id', '可发券渠道') $form->listbox('grants.user_id', '可发券渠道')
->options($users) ->options($users)
->default(function ($form) { ->default(function ($form) {
if ($form->isEditing()) { if ($form->isEditing()) {
return $form->model()->grants()->pluck('user_id')->toArray(); return $form->model()->grants()->pluck('user_id')->toArray();
} else { } else {
return []; return [];
} }
}) })
->required(); ->required();
$form->listbox('verifications.user_id', '可核券渠道') $form->listbox('verifications.user_id', '可核券渠道')
->options($users) ->options($users)
->default(function ($form) { ->default(function ($form) {
if ($form->isEditing()) { if ($form->isEditing()) {
return $form->model()->verifications()->pluck('user_id')->toArray(); return $form->model()->verifications()->pluck('user_id')->toArray();
} else { } else {
return []; return [];
} }
}) })
->required(); ->required();
$form->radio('verify_shop', '网点校验') $form->radio('verify_shop', '网点校验')
->options(Activity::VERIFY_SHOPS) ->options(Activity::VERIFY_SHOPS)
->default(Activity::VERIFY_SHOP_NO) ->default(Activity::VERIFY_SHOP_NO)
->when(Activity::VERIFY_SHOP_YES, function (Form $form) use ($users) { ->when(Activity::VERIFY_SHOP_YES, function (Form $form) use ($users) {
$form->listbox('shops.user_id', '可核券渠道') $form->listbox('shops.user_id', '可核券渠道')
->options(function () { ->options(function () {
return User::query() return User::query()
->with('info') ->with('info')
->whereHas('identity', function ($q) { ->whereHas('identity', function ($q) {
$q->where('identity_id', 2); $q->where('identity_id', 2);
}) })
->where('status', 1) ->where('status', 1)
->orderBy('id', 'desc') ->orderBy('id', 'desc')
->get() ->get()
->pluck('nickname', 'id'); ->pluck('nickname', 'id');
}) })
->default(function ($form) { ->default(function ($form) {
if ($form->isEditing()) { if ($form->isEditing()) {
return $form->model()->shops()->pluck('user_id')->toArray(); return $form->model()->shops()->pluck('user_id')->toArray();
} else { } else {
return []; return [];
} }
}); });
}); });
$form->saving(function (Form $form) { $form->saving(function (Form $form) {
$request = request(); $request = request();
@@ -222,11 +226,11 @@ class IndexController extends AdminController
} }
if (request()->start) { if (request()->start) {
$form->start_at = $form->start_at . ' 00:00:01'; $form->start_at = $form->start_at.' 00:00:01';
} }
if (request()->end_at) { if (request()->end_at) {
$form->end_at = $form->end_at . ' 23:59:59'; $form->end_at = $form->end_at.' 23:59:59';
} }
$shops = isset(request()->shops) ? array_filter(request()->shops['user_id']) : []; $shops = isset(request()->shops) ? array_filter(request()->shops['user_id']) : [];
@@ -249,10 +253,10 @@ class IndexController extends AdminController
foreach ($form->grants['user_id'] as $key => $user_id) { foreach ($form->grants['user_id'] as $key => $user_id) {
if ($user_id) { if ($user_id) {
$form->model() $form->model()
->grants() ->grants()
->updateOrCreate([ ->updateOrCreate([
'user_id' => $user_id, 'user_id' => $user_id,
]); ]);
$users[] = $user_id; $users[] = $user_id;
} }
} }
@@ -263,10 +267,10 @@ class IndexController extends AdminController
foreach ($form->verifications['user_id'] as $key => $user_id) { foreach ($form->verifications['user_id'] as $key => $user_id) {
if ($user_id) { if ($user_id) {
$form->model() $form->model()
->verifications() ->verifications()
->updateOrCreate([ ->updateOrCreate([
'user_id' => $user_id, 'user_id' => $user_id,
]); ]);
$users[] = $user_id; $users[] = $user_id;
} }
} }
@@ -274,16 +278,16 @@ class IndexController extends AdminController
$shops = isset(request()->shops) ? array_filter(request()->shops['user_id']) : []; $shops = isset(request()->shops) ? array_filter(request()->shops['user_id']) : [];
if (!empty($shops)) { if (! empty($shops)) {
//设置核销网点 //设置核销网点
$users = []; $users = [];
foreach ($form->shops['user_id'] as $key => $user_id) { foreach ($form->shops['user_id'] as $key => $user_id) {
if ($user_id) { if ($user_id) {
$form->model() $form->model()
->shops() ->shops()
->updateOrCreate([ ->updateOrCreate([
'user_id' => $user_id, 'user_id' => $user_id,
]); ]);
$users[] = $user_id; $users[] = $user_id;
} }
} }

View File

@@ -20,9 +20,11 @@ class Activity extends Model
const TYPE_EXTEND = 1; const TYPE_EXTEND = 1;
const TYPE_SCOPE = 2; const TYPE_SCOPE = 2;
const TYPE_MONTH = 3;
const TYPES = [ const TYPES = [
self::TYPE_EXTEND => '延期', self::TYPE_EXTEND => '延期',
self::TYPE_SCOPE => '固定', self::TYPE_SCOPE => '固定',
self::TYPE_MONTH => '当月',
]; ];
const STATUS_OPEN = 1; const STATUS_OPEN = 1;
@@ -48,6 +50,7 @@ class Activity extends Model
/** /**
* 默认加载的关联 * 默认加载的关联
*
* @var array * @var array
*/ */
protected $with = ['rule']; protected $with = ['rule'];
@@ -57,7 +60,7 @@ class Activity extends Model
parent::boot(); parent::boot();
self::creating(function ($model) { self::creating(function ($model) {
$model->code = 'ysd' . date('Ym') . mt_rand(100, 999); $model->code = 'ysd'.date('Ym').mt_rand(100, 999);
}); });
} }
@@ -87,6 +90,7 @@ class Activity extends Model
/** /**
* Notes: 关联可发券渠道中间表 * Notes: 关联可发券渠道中间表
*
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/8/21 11:09 * @Date : 2020/8/21 11:09
*/ */
@@ -97,6 +101,7 @@ class Activity extends Model
/** /**
* Notes: 可发券的渠道 * Notes: 可发券的渠道
*
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2021/4/25 11:36 * @Date : 2021/4/25 11:36
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
@@ -108,6 +113,7 @@ class Activity extends Model
/** /**
* Notes: 关联可核券网点中间表 * Notes: 关联可核券网点中间表
*
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/8/21 11:09 * @Date : 2020/8/21 11:09
*/ */
@@ -118,6 +124,7 @@ class Activity extends Model
/** /**
* Notes: 关联可核销渠道 * Notes: 关联可核销渠道
*
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/8/21 11:09 * @Date : 2020/8/21 11:09
*/ */
@@ -128,6 +135,7 @@ class Activity extends Model
/** /**
* Notes: 可核销的渠道 * Notes: 可核销的渠道
*
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2021/4/25 11:37 * @Date : 2021/4/25 11:37
*/ */
@@ -138,6 +146,7 @@ class Activity extends Model
/** /**
* Notes: 是否可以发券 * Notes: 是否可以发券
*
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2021/4/25 10:41 * @Date : 2021/4/25 10:41
* @return mixed * @return mixed
@@ -149,28 +158,28 @@ class Activity extends Model
/** /**
* Notes: 生成优惠券码 * Notes: 生成优惠券码
*
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2021/4/25 10:41 * @Date : 2021/4/25 10:41
* @return mixed|string * @return mixed|string
*/ */
public function getCode() public function getCode()
{ {
//判断生成何种码 //判断生成何种码
if ($this->channel == self::CHANNEL_UNION) { if ($this->channel == self::CHANNEL_UNION) {
$code = '66406' . date('ymdHi') . mt_rand(10000, 99999); $code = '66406'.date('ymdHi').mt_rand(10000, 99999);
} else { } else {
$code_length = config('pingan.code_length'); $code_length = config('pingan.code_length');
switch ($code_length) { switch ($code_length) {
case 17://17位长度 case 17://17位长度
$code = 'YSD' . substr(date('ymdHi'), 1) . mt_rand(10000, 99999); $code = 'YSD'.substr(date('ymdHi'), 1).mt_rand(10000, 99999);
break; break;
case 15://15位长度 case 15://15位长度
$code = 'YSD' . substr(date('ymdH'), 1) . mt_rand(10000, 99999); $code = 'YSD'.substr(date('ymdH'), 1).mt_rand(10000, 99999);
break; break;
default://默认15位长度 default://默认15位长度
$code = 'YSD' . substr(date('ymdH'), 1) . mt_rand(10000, 99999); $code = 'YSD'.substr(date('ymdH'), 1).mt_rand(10000, 99999);
break; break;
} }
@@ -194,6 +203,9 @@ class Activity extends Model
if ($this->type == SELF::TYPE_EXTEND) { if ($this->type == SELF::TYPE_EXTEND) {
$start_at = now(); $start_at = now();
$end_at = now()->addDays($this->days); $end_at = now()->addDays($this->days);
} elseif ($this->type == self::TYPE_MONTH) {
$start_at = now();
$end_at = now()->endOfMonth();
} else { } else {
$start_at = $this->start_at->startOfDay(); $start_at = $this->start_at->startOfDay();
$end_at = $this->end_at->endOfDay(); $end_at = $this->end_at->endOfDay();
@@ -220,7 +232,5 @@ class Activity extends Model
return $e->getMessage(); return $e->getMessage();
} }
} }
} }

View File

@@ -37,7 +37,7 @@ class ActivityCoupon extends Model
* @Date : 2020/6/30 9:40 * @Date : 2020/6/30 9:40
* @return string * @return string
*/ */
public function getStatusTextAttribute() public function getStatusTextAttribute(): string
{ {
return self::STATUS[$this->status] ?? '未知'; return self::STATUS[$this->status] ?? '未知';
} }
@@ -48,7 +48,7 @@ class ActivityCoupon extends Model
* @Date : 2020/6/30 9:41 * @Date : 2020/6/30 9:41
* @return bool * @return bool
*/ */
public function canRedemption() public function canRedemption(): bool
{ {
return $this->status == ActivityCoupon::STATUS_INIT; return $this->status == ActivityCoupon::STATUS_INIT;
} }
@@ -59,7 +59,7 @@ class ActivityCoupon extends Model
* @Date : 2020/6/30 9:41 * @Date : 2020/6/30 9:41
* @return bool * @return bool
*/ */
public function canDestroy() public function canDestroy(): bool
{ {
return $this->canRedemption(); return $this->canRedemption();
} }
@@ -70,7 +70,7 @@ class ActivityCoupon extends Model
* @Date : 2020/10/12 11:57 * @Date : 2020/10/12 11:57
* @return bool * @return bool
*/ */
public function canReversal() public function canReversal(): bool
{ {
return $this->status == self::STATUS_USED; return $this->status == self::STATUS_USED;
} }

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use App\Models\Traits\BelongsToOutlet; use App\Models\Traits\BelongsToOutlet;
use App\Models\Traits\BelongsToUser; use App\Models\Traits\BelongsToUser;
use Illuminate\Database\Eloquent\Relations\HasOne;
class Coupon extends Model class Coupon extends Model
{ {
@@ -22,7 +23,7 @@ class Coupon extends Model
]; ];
//状态 //状态
public function getStatusTextAttribute() public function getStatusTextAttribute(): string
{ {
switch ($this->status) { switch ($this->status) {
case 0: case 0:
@@ -46,7 +47,7 @@ class Coupon extends Model
} }
} }
public function getProfitTextAttribute() public function getProfitTextAttribute(): string
{ {
switch ($this->is_profit) { switch ($this->is_profit) {
case 0: case 0:
@@ -63,23 +64,25 @@ class Coupon extends Model
/** /**
* 是否可以分润 * 是否可以分润
* @author 玄尘 2020-03-13 *
* @return bool [type] [description] * @return bool [type] [description]
* @author 玄尘 2020-03-13
*/ */
public function canProfit() public function canProfit(): bool
{ {
return ($this->is_profit === 0 && $this->status == 2); return ($this->is_profit === 0 && $this->status == 2);
} }
/** /**
* 分润 * 分润
* @author 玄尘 2020-03-13 *
* @return bool|string [type] [description] * @return bool|string [type] [description]
* @author 玄尘 2020-03-13
*/ */
public function profit() public function profit()
{ {
$log = AccountLog::where('source->coupon_id', $this->id)->first(); $log = AccountLog::where('source->coupon_id', $this->id)->first();
if (!$log && $this->user && $this->profit) { if (! $log && $this->user && $this->profit) {
return $this->user->account->rule('freeze', $this->profit, false, [ return $this->user->account->rule('freeze', $this->profit, false, [
'coupon_id' => $this->id, 'coupon_id' => $this->id,
'redemptionCode' => $this->redemptionCode, 'redemptionCode' => $this->redemptionCode,
@@ -93,6 +96,7 @@ class Coupon extends Model
/** /**
* Notes: 撤销 * Notes: 撤销
*
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/10/12 13:56 * @Date : 2020/10/12 13:56
*/ */
@@ -114,6 +118,7 @@ class Coupon extends Model
/** /**
* Notes: 撤销分润 * Notes: 撤销分润
*
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/10/9 14:07 * @Date : 2020/10/9 14:07
*/ */
@@ -132,8 +137,9 @@ class Coupon extends Model
/** /**
* 打款 * 打款
* @author 玄尘 2020-03-13 *
* @return bool|string [type] [description] * @return bool|string [type] [description]
* @author 玄尘 2020-03-13
*/ */
public function sendMoney() public function sendMoney()
{ {
@@ -160,6 +166,7 @@ class Coupon extends Model
/** /**
* Notes: 格式化时间 年-月-日 * Notes: 格式化时间 年-月-日
*
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/4/7 16:24 * @Date : 2020/4/7 16:24
* @return mixed * @return mixed
@@ -169,4 +176,12 @@ class Coupon extends Model
return $this->created_at->format('Y-m-d'); return $this->created_at->format('Y-m-d');
} }
/*
* 关联自有券
*/
public function activityCoupon(): HasOne
{
return $this->hasOne(ActivityCoupon::class, 'code', 'redemptionCode');
}
} }

3671
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddDayTimesToActivitiesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('activities', function (Blueprint $table) {
$table->integer('day_times')->default(0)->comment('每天可用次数');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('activities', function (Blueprint $table) {
//
});
}
}