Merge branch 'develop' into feature/mzl_dev

This commit is contained in:
mzl
2025-09-18 15:04:59 +08:00
23 changed files with 933 additions and 6 deletions
+46
View File
@@ -3,6 +3,7 @@
namespace app\admin\service;
use app\admin\validate\BrandSeriesValidate;
use app\common\model\Brand;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\BrandSeries;
use support\Request;
@@ -77,4 +78,49 @@ class BrandSeriesService
return $config;
}
/**
* 生成唯一的7位颜色编码
* 格式:C + (O/I) + 5位字母数字组合
*
* @param int $type 类型
* @return string 7位唯一编码
*/
public function generateUniqueModificationCode($brand_id)
{
$chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$maxAttempts = 10; // 防止无限循环
$brand_code = Brand::where('id', $brand_id)->value('brand_code');
$brand_code = $brand_code??'BS';
for ($attempt = 0; $attempt < $maxAttempts; $attempt++) {
// 生成后5位随机字符
$suffix = '';
for ($i = 0; $i < 6; $i++) {
$suffix .= $chars[rand(0, strlen($chars) - 1)];
}
$code = $brand_code . $suffix;
// 检查是否已存在
$existing = BrandSeries::where('series_code', $code)->first();
if (!$existing) {
return $code;
}
}
// 如果1000次尝试后仍然重复,使用时间戳确保唯一性
$timestamp = substr(time(), -6);
return $brand_code . $timestamp;
}
/**
* 添加前置处理
*/
public function beforeServiceStore($data, Request $request)
{
$brand_id = $data['brand_id'] ?? 0;
$data['series_code'] = $this->generateUniqueModificationCode($brand_id);
return $data;
}
}
+1
View File
@@ -43,6 +43,7 @@ class BrandService
switch ($scene) {
case 'index':
// ====== ====== 排序 ====== ======
$config['order']['hot'] = 'desc';
$config['order']['sort'] = 'desc';
$config['order']['id'] = 'desc';