调整活动

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) {
@@ -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

@@ -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
@@ -122,6 +123,7 @@ class IndexController extends AdminController
->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', '有效时间');
}) })
->help('当月券,领取的月底到期')
->required(); ->required();
$form->radio('channel', '核销途径') $form->radio('channel', '核销途径')
@@ -130,6 +132,8 @@ class IndexController extends AdminController
->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)
@@ -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']) : [];
@@ -274,7 +278,7 @@ 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) {

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) {
//
});
}
}