feat: 商品详情添加自定义参数字段
parent
6aac9f0db2
commit
e4e36ad392
|
@ -58,7 +58,7 @@ class GoodsLogic extends Logic
|
|||
];
|
||||
|
||||
$goodsDetail = Goods::with(['goods_image', 'goods_item', 'shop'])
|
||||
->field('id,type,name,image,video,remark,content,market_price,min_price,max_price,is_show_stock,stock,sales_actual,sales_virtual,clicks,shop_id,poster')
|
||||
->field('id,type,name,image,video,remark,content,market_price,min_price,max_price,is_show_stock,stock,sales_actual,sales_virtual,clicks,shop_id,poster,custom_params')
|
||||
->where($onSaleWhere)
|
||||
->where('id', $goodsId)
|
||||
->findOrEmpty();
|
||||
|
@ -96,6 +96,13 @@ class GoodsLogic extends Logic
|
|||
$goodsDetail->clicks += 1;
|
||||
$goodsDetail->save();
|
||||
|
||||
// 自定义规格转换
|
||||
if (!empty($goodsDetail->custom_params)) {
|
||||
$goodsDetail->custom_params = self::str2arr($goodsDetail->custom_params);
|
||||
} else {
|
||||
$goodsDetail->custom_params = [];
|
||||
}
|
||||
|
||||
// 转数组
|
||||
$goodsDetailArr = $goodsDetail->toArray();
|
||||
$goodsDetailArr['poster'] = !empty($goodsDetailArr['poster']) ? UrlServer::getFileUrl($goodsDetailArr['poster']) : '';
|
||||
|
@ -286,6 +293,28 @@ class GoodsLogic extends Logic
|
|||
}
|
||||
}
|
||||
|
||||
protected static function str2arr(string $str): array
|
||||
{
|
||||
// $str = "参数1:值1;参数2:值2";
|
||||
|
||||
// 使用分号分割数组
|
||||
$params = explode(";", $str);
|
||||
|
||||
// 遍历每个参数对,并使用冒号分割键与值
|
||||
$result = array();
|
||||
foreach ($params as $param) {
|
||||
// 使用冒号分割键与值
|
||||
$paramPair = explode(":", $param);
|
||||
if (count($paramPair) === 2) {
|
||||
$key = trim($paramPair[0]);
|
||||
$value = trim($paramPair[1]);
|
||||
$result[] = [$key => $value];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 热销榜单
|
||||
*/
|
||||
|
|
|
@ -345,6 +345,7 @@ class GoodsLogic extends Logic
|
|||
$data = [
|
||||
'name' => $post['name'],
|
||||
'code' => $post['code'],
|
||||
'custom_params' => $post['custom_params'] ?? '',
|
||||
'shop_cate_id' => $post['shop_cate_id'],
|
||||
'first_cate_id' => $post['first_cate_id'],
|
||||
'second_cate_id' => $post['second_cate_id'],
|
||||
|
@ -655,6 +656,7 @@ class GoodsLogic extends Logic
|
|||
'name' => trim($post['name']),
|
||||
'code' => trim($post['code']) ? trim($post['code']) : create_goods_code($shop_id),
|
||||
'shop_id' => $shop_id,
|
||||
'custom_params' => $post['custom_params'] ?? '',
|
||||
'shop_cate_id' => $post['shop_cate_id'],
|
||||
'first_cate_id' => $post['first_cate_id'],
|
||||
'second_cate_id' => $post['second_cate_id'],
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
, likeedit = layui.likeedit;
|
||||
|
||||
//---------------------------------------平台分类联动 begin ----------------------------------
|
||||
var categorys = {$category_lists | raw};
|
||||
var categorys = {$category_lists | raw};
|
||||
setSelectFirst();
|
||||
|
||||
function setSelectFirst(default_id) {
|
||||
|
@ -727,6 +727,7 @@
|
|||
$('input[name="goods_id"]').val(goods_info['base']['id']);
|
||||
$('input[name="name"]').val(goods_info['base']['name']);
|
||||
$('input[name="code"]').val(goods_info['base']['code']);
|
||||
$('textarea[name="custom_params"]').val(goods_info['base']['custom_params']);
|
||||
setSelectFirst(goods_info['base']['first_cate_id']);
|
||||
setSelectSecond(goods_info['base']['second_cate_id']);
|
||||
setSelectThird(goods_info['base']['third_cate_id']);
|
||||
|
|
|
@ -31,6 +31,15 @@
|
|||
<input type="text" name="code" lay-verType="tips" placeholder="若不填,系统随机8位数字" autocomplete="off" switch-tab="0" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--自定义参数-->
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">自定义参数:</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea name="custom_params" placeholder="格式:规格1:值1;规格2:值2;规格3:值3 使用英文冒号与分号" class="layui-textarea"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--平台分类-->
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="form-label-asterisk">*</span>平台分类:</label>
|
||||
|
|
Loading…
Reference in New Issue