This commit is contained in:
2022-04-08 16:21:47 +08:00
parent c3461e1335
commit 491a907250
5 changed files with 49 additions and 61 deletions

View File

@@ -13,7 +13,7 @@ class CouponController extends AdminController
protected $title = '卡券列表管理'; protected $title = '卡券列表管理';
protected function grid() protected function grid(): Grid
{ {
$grid = new Grid(new ActivityCoupon); $grid = new Grid(new ActivityCoupon);
$grid->model()->with(['outlet'])->latest(); $grid->model()->with(['outlet'])->latest();
@@ -25,9 +25,6 @@ class CouponController extends AdminController
$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) {
@@ -52,11 +49,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 +78,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 +95,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

@@ -36,9 +36,7 @@ class IndexController extends AdminController
$filter->between('start_at', '开始时间')->datetime(); $filter->between('start_at', '开始时间')->datetime();
$filter->between('end_at', '结束时间')->datetime(); $filter->between('end_at', '结束时间')->datetime();
$filter->equal('channel', '核销途径')->select(Activity::CHANNELS); $filter->equal('channel', '核销途径')->select(Activity::CHANNELS);
}); });
}); });
$grid->column('id', '#ID#'); $grid->column('id', '#ID#');
@@ -50,27 +48,22 @@ class IndexController extends AdminController
$grid->column('类型')->display(function () { $grid->column('类型')->display(function () {
return $this->type_text; return $this->type_text;
}); });
$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('发券渠道')->display(function ($title, $column) { $grid->column('发券渠道')->display(function ($title, $column) {
return '查看'; return '查看';
})->modal(Grants::class); })->modal(Grants::class);
$grid->column('核券渠道')->display(function ($title, $column) { $grid->column('核券渠道')->display(function ($title, $column) {
return '查看'; return '查看';
})->modal(Verifications::class); })->modal(Verifications::class);
$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') : '---';
}); });

View File

@@ -2,7 +2,6 @@
namespace App\Admin\Controllers\Activity; namespace App\Admin\Controllers\Activity;
use App\Admin\Renderable\Activity\Grants;
use App\Models\ActivityCouponLog; use App\Models\ActivityCouponLog;
use Encore\Admin\Controllers\HasResourceActions; use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Grid; use Encore\Admin\Grid;
@@ -18,19 +17,21 @@ class LogController extends AdminController
/** /**
* Get content title. * Get content title.
*
* @return string * @return string
*/ */
protected function title() protected function title(): string
{ {
return $this->title; return $this->title;
} }
/** /**
* Index interface. * Index interface.
*
* @param Content $content * @param Content $content
* @return Content * @return Content
*/ */
public function index(Content $content) public function index(Content $content): Content
{ {
return $content return $content
->title($this->title()) ->title($this->title())
@@ -38,7 +39,7 @@ class LogController extends AdminController
->body($this->grid()); ->body($this->grid());
} }
protected function grid() protected function grid(): Grid
{ {
$grid = new Grid(new ActivityCouponLog); $grid = new Grid(new ActivityCouponLog);
@@ -54,35 +55,30 @@ class LogController extends AdminController
$filter->column(1 / 2, function ($filter) { $filter->column(1 / 2, function ($filter) {
$filter->equal('status', '状态')->select(ActivityCouponLog::STATUS); $filter->equal('status', '状态')->select(ActivityCouponLog::STATUS);
$filter->between('created_at', '开始时间')->datetime(); $filter->between('created_at', '开始时间')->datetime();
}); });
}); });
$grid->column('id', '#ID#'); $grid->column('id', '#ID#');
$grid->column('code', '卡券编号'); $grid->column('code', '卡券编号');
$grid->column('type', '分类') $grid->column('type', '分类')
->using(ActivityCouponLog::TYPES) ->using(ActivityCouponLog::TYPES)
->label([ ->label([
1 => 'default', 1 => 'default',
2 => 'warning', 2 => 'warning',
3 => 'info', 3 => 'info',
]); ]);
$grid->column('status', '状态') $grid->column('status', '状态')
->using(ActivityCouponLog::STATUS) ->using(ActivityCouponLog::STATUS)
->label([ ->label([
1 => 'default', 1 => 'default',
2 => 'warning', 2 => 'warning',
3 => 'info', 3 => 'info',
]); ]);
$grid->column('remark', '处理结果'); $grid->column('remark', '处理结果');
$grid->column('created_at', '操作时间'); $grid->column('created_at', '操作时间');
return $grid; return $grid;
} }
} }

View File

@@ -12,10 +12,9 @@ use RuLong\Identity\Models\Identity;
class RuleController extends AdminController class RuleController extends AdminController
{ {
protected $title = '规则管理'; protected $title = '规则管理';
protected function grid() protected function grid(): Grid
{ {
$grid = new Grid(new ActivityRule); $grid = new Grid(new ActivityRule);
@@ -34,15 +33,15 @@ class RuleController extends AdminController
]); ]);
$grid->column('created_at', '创建时间'); $grid->column('created_at', '创建时间');
return $grid; return $grid;
} }
/** /**
* Make a form builder. * Make a form builder.
*
* @return Form * @return Form
*/ */
protected function form() protected function form(): Form
{ {
$form = new Form(new ActivityRule); $form = new Form(new ActivityRule);
@@ -58,7 +57,7 @@ class RuleController extends AdminController
$code = $form->code; $code = $form->code;
$ticket = explode('-', $code); $ticket = explode('-', $code);
if (!is_array($ticket) || count($ticket) != 3) { if (! is_array($ticket) || count($ticket) != 3) {
$error = new MessageBag([ $error = new MessageBag([
'title' => '错误', 'title' => '错误',
'message' => '规则编号格式错误', 'message' => '规则编号格式错误',
@@ -79,5 +78,4 @@ class RuleController extends AdminController
return $form; return $form;
} }
} }

View File

@@ -48,6 +48,7 @@ class Activity extends Model
/** /**
* 默认加载的关联 * 默认加载的关联
*
* @var array * @var array
*/ */
protected $with = ['rule']; protected $with = ['rule'];
@@ -57,7 +58,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 +88,7 @@ class Activity extends Model
/** /**
* Notes: 关联可发券渠道中间表 * Notes: 关联可发券渠道中间表
*
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/8/21 11:09 * @Date : 2020/8/21 11:09
*/ */
@@ -97,6 +99,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 +111,7 @@ class Activity extends Model
/** /**
* Notes: 关联可核券网点中间表 * Notes: 关联可核券网点中间表
*
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/8/21 11:09 * @Date : 2020/8/21 11:09
*/ */
@@ -118,6 +122,7 @@ class Activity extends Model
/** /**
* Notes: 关联可核销渠道 * Notes: 关联可核销渠道
*
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/8/21 11:09 * @Date : 2020/8/21 11:09
*/ */
@@ -128,6 +133,7 @@ class Activity extends Model
/** /**
* Notes: 可核销的渠道 * Notes: 可核销的渠道
*
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2021/4/25 11:37 * @Date : 2021/4/25 11:37
*/ */
@@ -138,6 +144,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 +156,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;
} }
@@ -217,10 +224,7 @@ class Activity extends Model
return $coupon; return $coupon;
} catch (\Exception $e) { } catch (\Exception $e) {
DB::rollback(); DB::rollback();
return $e->getMessage(); return $e->getMessage();
} }
} }
} }