diff --git a/app/Admin/Controllers/Activity/IndexController.php b/app/Admin/Controllers/Activity/IndexController.php index b6f5acf..6c9a43d 100644 --- a/app/Admin/Controllers/Activity/IndexController.php +++ b/app/Admin/Controllers/Activity/IndexController.php @@ -5,18 +5,15 @@ namespace App\Admin\Controllers\Activity; use App\Models\Activity; use App\Models\ActivityRule; use App\Models\User; +use Encore\Admin\Controllers\AdminController; use Encore\Admin\Controllers\HasResourceActions; use Encore\Admin\Form; use Encore\Admin\Grid; -use Encore\Admin\Layout\Content; use Illuminate\Support\MessageBag; -use Illuminate\Routing\Controller as AdminController; class IndexController extends AdminController { - use HasResourceActions; - protected $title = '活动管理'; /** @@ -28,44 +25,7 @@ class IndexController extends AdminController return $this->title; } - /** - * 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() + protected function grid(): Grid { $grid = new Grid(new Activity); $grid->model()->withCount('coupons'); diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 6ed7d4e..b545f82 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -97,25 +97,50 @@ class Activity extends Model } + /** + * Notes: 是否可以发券 + * @Author: 玄尘 + * @Date : 2021/4/25 10:41 + * @return mixed + */ public function canGrant() { 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) { $code = '66406' . date('ymdHi') . mt_rand(10000, 99999); } else { - // $code = 'YSD' . substr(date('ymd'), 1) . mt_rand(100000000, 999999999); - $code = 'YSD' . substr(date('ymdH'), 1) . mt_rand(10000, 99999); + $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); + break; + default://默认15位长度 + $code = 'YSD' . substr(date('ymdH'), 1) . mt_rand(10000, 99999); + break; + } } + //查询是否存在,存在重新生成 $exists = ActivityCoupon::where('code', $code)->exists(); if ($exists) { - return $this->getCode(null); + return $this->getCode(); } return $code; diff --git a/config/pingan.php b/config/pingan.php index d2bdb60..e1ff732 100644 --- a/config/pingan.php +++ b/config/pingan.php @@ -46,9 +46,12 @@ return [ 7 => '未激活', ], - 'froms' => [ + 'froms' => [ 'bsshop',//本时商城 'bslive',//本时生活 ], + //券码长度 15 或 17 + 'code_length' => 15, + ];