调整生成券码

This commit is contained in:
2021-04-25 11:29:42 +08:00
parent d563199daf
commit 2431d08ff7
3 changed files with 35 additions and 47 deletions

View File

@@ -5,18 +5,15 @@ namespace App\Admin\Controllers\Activity;
use App\Models\Activity; use App\Models\Activity;
use App\Models\ActivityRule; use App\Models\ActivityRule;
use App\Models\User; use App\Models\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Controllers\HasResourceActions; use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form; use Encore\Admin\Form;
use Encore\Admin\Grid; use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Illuminate\Support\MessageBag; use Illuminate\Support\MessageBag;
use Illuminate\Routing\Controller as AdminController;
class IndexController extends AdminController class IndexController extends AdminController
{ {
use HasResourceActions;
protected $title = '活动管理'; protected $title = '活动管理';
/** /**
@@ -28,44 +25,7 @@ class IndexController extends AdminController
return $this->title; return $this->title;
} }
/** protected function grid(): Grid
* Index interface.
* @param Content $content
* @return Content
*/
public function index(Content $content)
{
return $content->title($this->title())
->description($this->description['index'] ?? trans('admin.list'))
->body($this->grid());
}
/**
* Edit interface.
* @param mixed $id
* @param Content $content
* @return Content
*/
public function edit($id, Content $content)
{
return $content->title($this->title())
->description($this->description['edit'] ?? trans('admin.edit'))
->body($this->form($id)->edit($id));
}
/**
* Create interface.
* @param Content $content
* @return Content
*/
public function create(Content $content)
{
return $content->title($this->title())
->description($this->description['create'] ?? trans('admin.create'))
->body($this->form());
}
protected function grid()
{ {
$grid = new Grid(new Activity); $grid = new Grid(new Activity);
$grid->model()->withCount('coupons'); $grid->model()->withCount('coupons');

View File

@@ -97,25 +97,50 @@ class Activity extends Model
} }
/**
* Notes: 是否可以发券
* @Author: 玄尘
* @Date : 2021/4/25 10:41
* @return mixed
*/
public function canGrant() public function canGrant()
{ {
return $this->status; return $this->status;
} }
public function getCode($code = 'YSD200907684743') /**
* Notes: 生成优惠券码
* @Author: 玄尘
* @Date : 2021/4/25 10:41
* @return mixed|string
*/
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 = 'YSD' . substr(date('ymd'), 1) . mt_rand(100000000, 999999999); $code_length = config('pingan.code_length');
switch ($code_length) {
case 17://17位长度
$code = 'YSD' . substr(date('ymdHi'), 1) . mt_rand(10000, 99999);
break;
case 15://15位长度
$code = 'YSD' . substr(date('ymdH'), 1) . mt_rand(10000, 99999); $code = 'YSD' . substr(date('ymdH'), 1) . mt_rand(10000, 99999);
break;
default://默认15位长度
$code = 'YSD' . substr(date('ymdH'), 1) . mt_rand(10000, 99999);
break;
}
} }
//查询是否存在,存在重新生成
$exists = ActivityCoupon::where('code', $code)->exists(); $exists = ActivityCoupon::where('code', $code)->exists();
if ($exists) { if ($exists) {
return $this->getCode(null); return $this->getCode();
} }
return $code; return $code;

View File

@@ -51,4 +51,7 @@ return [
'bslive',//本时生活 'bslive',//本时生活
], ],
//券码长度 15 或 17
'code_length' => 15,
]; ];