From 477fec0b803868a86c753225cb2ec902bd47c874 Mon Sep 17 00:00:00 2001 From: xuanchen <122383162@qq.com> Date: Wed, 7 Apr 2021 10:38:56 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E7=94=9F=E4=BA=A7=E5=88=B8?= =?UTF-8?q?=E7=A0=81=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Activity.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 27062ee..304ddf0 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -102,17 +102,28 @@ class Activity extends Model return $this->status; } + public function getCode($code = 'YSD200907684743') + { + //判断生成何种码 + 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); + } + + $exists = ActivityCoupon::where('code', $code)->exists(); + if ($exists) { + return $this->getCode(null); + } + + return $code; + } + //发券 public function grant($mobile, $outletId = null) { - try { - //判断生成何种码 - if ($this->channel == self::CHANNEL_UNION) { - $code = '66406' . date('ymdHi') . mt_rand(10000, 99999); - } else { - $code = 'YSD' . substr(date('ymdHi'), 1) . mt_rand(100, 999); - } + $code = $this->getCode(); if ($this->type == SELF::TYPE_EXTEND) { $start_at = now();