1
This commit is contained in:
@@ -10,6 +10,7 @@ use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
use support\Request;
|
||||
use app\common\model\User;
|
||||
use support\Redis;
|
||||
|
||||
class UsedCarService
|
||||
{
|
||||
@@ -97,6 +98,8 @@ class UsedCarService
|
||||
}
|
||||
if (!empty($data['attachment'])) {
|
||||
$data['attachment'] = json_encode($data['attachment']);
|
||||
}else{
|
||||
$data['attachment'] = '';
|
||||
}
|
||||
$data['user_id'] = $request->user['id'];
|
||||
$data['code'] = $this->getcode($request->user['id']);
|
||||
@@ -104,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;
|
||||
|
||||
Reference in New Issue
Block a user