调整生成券码
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user