1
This commit is contained in:
@@ -10,6 +10,7 @@ use support\exception\BusinessException;
|
|||||||
use support\Log;
|
use support\Log;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
use app\common\model\User;
|
use app\common\model\User;
|
||||||
|
use support\Redis;
|
||||||
|
|
||||||
class UsedCarService
|
class UsedCarService
|
||||||
{
|
{
|
||||||
@@ -97,6 +98,8 @@ class UsedCarService
|
|||||||
}
|
}
|
||||||
if (!empty($data['attachment'])) {
|
if (!empty($data['attachment'])) {
|
||||||
$data['attachment'] = json_encode($data['attachment']);
|
$data['attachment'] = json_encode($data['attachment']);
|
||||||
|
}else{
|
||||||
|
$data['attachment'] = '';
|
||||||
}
|
}
|
||||||
$data['user_id'] = $request->user['id'];
|
$data['user_id'] = $request->user['id'];
|
||||||
$data['code'] = $this->getcode($request->user['id']);
|
$data['code'] = $this->getcode($request->user['id']);
|
||||||
@@ -104,10 +107,13 @@ class UsedCarService
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getcode($userId){
|
public function getcode($userId){
|
||||||
|
$userCount = Redis::get('used_car_count_'.$userId, 0);
|
||||||
$todayStart = strtotime('today');
|
$todayStart = strtotime('today');
|
||||||
$count = UsedCar::where('user_id',$userId)->where('created_at','>=',$todayStart)->count();
|
$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);
|
$countCode = str_pad($count, 3, '0', STR_PAD_LEFT);
|
||||||
$userCode = str_pad($userId, 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();
|
$user = User::where('id',$userId)->first();
|
||||||
$nameInitials = $this->getNameInitials($user['name']);
|
$nameInitials = $this->getNameInitials($user['name']);
|
||||||
return $nameInitials . $userCode . date('Ymd') . $countCode;
|
return $nameInitials . $userCode . date('Ymd') . $countCode;
|
||||||
|
|||||||
Reference in New Issue
Block a user