diff --git a/app/common/service/UsedCarService.php b/app/common/service/UsedCarService.php index b7afd1e..ddd7cb8 100644 --- a/app/common/service/UsedCarService.php +++ b/app/common/service/UsedCarService.php @@ -10,6 +10,7 @@ use support\exception\BusinessException; use support\Log; use support\Request; use app\common\model\User; +use support\Redis; class UsedCarService { @@ -106,10 +107,13 @@ class UsedCarService } public function getcode($userId){ + $userCount = Redis::get('used_car_count_'.$userId, 0); $todayStart = strtotime('today'); $count = UsedCar::where('user_id',$userId)->where('created_at','>=',$todayStart)->count(); + $count = $count<$userCount ? $userCount +1 : $count +1; $countCode = str_pad($count, 3, '0', STR_PAD_LEFT); $userCode = str_pad($userId, 3, '0', STR_PAD_LEFT); + Redis::set('used_car_count_'.$userId, $count, 86400); $user = User::where('id',$userId)->first(); $nameInitials = $this->getNameInitials($user['name']); return $nameInitials . $userCode . date('Ymd') . $countCode;