重写生产券码规则

This commit is contained in:
2021-04-07 10:38:56 +08:00
parent 1e69cbfdff
commit 477fec0b80

View File

@@ -102,18 +102,29 @@ class Activity extends Model
return $this->status;
}
//发券
public function grant($mobile, $outletId = null)
public function getCode($code = 'YSD200907684743')
{
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 = '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 {
$code = $this->getCode();
if ($this->type == SELF::TYPE_EXTEND) {
$start_at = now();
$end_at = now()->addDays($this->days);