车辆编号
This commit is contained in:
@@ -40,7 +40,7 @@ class UsedCar extends Model
|
|||||||
/**
|
/**
|
||||||
* 允许自动填充模型字段
|
* 允许自动填充模型字段
|
||||||
*/
|
*/
|
||||||
protected $fillable = ['id', 'user_id', 'product_name', 'vin', 'price', 'source_place', 'plate_place', 'plate_time', 'displacement','mileage','power', 'body_color', 'images', 'condition_desc', 'attachment', 'crawl_title', 'crawl_brand', 'crawl_series', 'crawl_year', 'crawl_msrp', 'crawl_car_id', 'status', 'sort', 'created_at', 'updated_at'];
|
protected $fillable = ['id','code', 'user_id', 'product_name', 'vin', 'price', 'source_place', 'plate_place', 'plate_time', 'displacement','mileage','power', 'body_color', 'images', 'condition_desc', 'attachment', 'crawl_title', 'crawl_brand', 'crawl_series', 'crawl_year', 'crawl_msrp', 'crawl_car_id', 'status', 'sort', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不允许自动填充模型字段
|
* 不允许自动填充模型字段
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use GuzzleHttp\Client;
|
|||||||
use support\exception\BusinessException;
|
use support\exception\BusinessException;
|
||||||
use support\Log;
|
use support\Log;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
|
use app\common\model\User;
|
||||||
|
|
||||||
class UsedCarService
|
class UsedCarService
|
||||||
{
|
{
|
||||||
@@ -98,9 +99,78 @@ class UsedCarService
|
|||||||
$data['attachment'] = json_encode($data['attachment']);
|
$data['attachment'] = json_encode($data['attachment']);
|
||||||
}
|
}
|
||||||
$data['user_id'] = $request->user['id'];
|
$data['user_id'] = $request->user['id'];
|
||||||
|
$data['code'] = $this->getcode($request->user['id']);
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getcode($userId){
|
||||||
|
$todayStart = strtotime('today');
|
||||||
|
$count = UsedCar::where('user_id',$userId)->where('created_at','>=',$todayStart)->count();
|
||||||
|
$countCode = str_pad($count, 3, '0', STR_PAD_LEFT);
|
||||||
|
$userCode = str_pad($userId, 3, '0', STR_PAD_LEFT);
|
||||||
|
$user = User::where('id',$userId)->first();
|
||||||
|
$nameInitials = $this->getNameInitials($user['name']);
|
||||||
|
return $nameInitials . $userCode . date('Ymd') . $countCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取中文名拼音首字母
|
||||||
|
*/
|
||||||
|
function getNameInitials(string $name): string
|
||||||
|
{
|
||||||
|
$initials = '';
|
||||||
|
$len = mb_strlen($name);
|
||||||
|
for ($i = 0; $i < $len; $i++) {
|
||||||
|
$char = mb_substr($name, $i, 1);
|
||||||
|
$initials .= $this->getFirstChar($char);
|
||||||
|
}
|
||||||
|
return strtoupper($initials);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFirstChar(string $char): string
|
||||||
|
{
|
||||||
|
$s = iconv('UTF-8', 'GB2312//IGNORE', $char);
|
||||||
|
$asc = ord($s[0]);
|
||||||
|
|
||||||
|
if ($asc >= 65 && $asc <= 90) return $char;
|
||||||
|
|
||||||
|
$code = ord($s[0]) * 256 + ord($s[1]) - 65536;
|
||||||
|
|
||||||
|
$map = [
|
||||||
|
[-20319, -20284, 'A'],
|
||||||
|
[-20283, -19776, 'B'],
|
||||||
|
[-19775, -19219, 'C'],
|
||||||
|
[-19218, -18711, 'D'],
|
||||||
|
[-18710, -18527, 'E'],
|
||||||
|
[-18526, -18240, 'F'],
|
||||||
|
[-18239, -17923, 'G'],
|
||||||
|
[-17922, -17418, 'H'],
|
||||||
|
[-17417, -16475, 'J'],
|
||||||
|
[-16474, -16213, 'K'],
|
||||||
|
[-16212, -15641, 'L'],
|
||||||
|
[-15640, -15166, 'M'],
|
||||||
|
[-15165, -14923, 'N'],
|
||||||
|
[-14922, -14915, 'O'],
|
||||||
|
[-14914, -14631, 'P'],
|
||||||
|
[-14630, -14150, 'Q'],
|
||||||
|
[-14149, -14091, 'R'],
|
||||||
|
[-14090, -13319, 'S'],
|
||||||
|
[-13318, -12839, 'T'],
|
||||||
|
[-12838, -12557, 'W'],
|
||||||
|
[-12556, -11848, 'X'],
|
||||||
|
[-11847, -11056, 'Y'],
|
||||||
|
[-11055, -10247, 'Z']
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($map as [$start, $end, $letter]) {
|
||||||
|
if ($code >= $start && $code <= $end) {
|
||||||
|
return $letter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -222,7 +292,6 @@ class UsedCarService
|
|||||||
}
|
}
|
||||||
|
|
||||||
return array_values($models);
|
return array_values($models);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new \Exception($e->getMessage());
|
throw new \Exception($e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -233,7 +302,8 @@ class UsedCarService
|
|||||||
* @param string $url 完整的URL
|
* @param string $url 完整的URL
|
||||||
* @return string|null series ID或null
|
* @return string|null series ID或null
|
||||||
*/
|
*/
|
||||||
function extractSeriesId($url) {
|
function extractSeriesId($url)
|
||||||
|
{
|
||||||
// 解析URL获取路径部分
|
// 解析URL获取路径部分
|
||||||
$path = parse_url($url, PHP_URL_PATH);
|
$path = parse_url($url, PHP_URL_PATH);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user