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();