# 商品规格
商品规格
文件路径:shop/controllers/Seller/Goods/SpecCtl.php;
商品类别:
```
<pre class="calibre14">```
<span class="token5">//获取路径:</span>
url<span class="token1">:</span> SITE_URL <span class="token">+</span> <span class="token4">'?ctl=Goods_Cat&met=cat&typ=json&type_number=goods_cat&is_delete=2&filter=true'</span><span class="token1">,</span>
<span class="token5">//如果存在父类</span>
$data_rows <span class="token">=</span> $Goods_CatModel<span class="token">-</span><span class="token">></span><span class="token3">getCatTreeData</span><span class="token1">(</span>$cat_parent_id<span class="token1">,</span> <span class="token6">false</span><span class="token1">,</span> <span class="token6">1</span><span class="token1">)</span><span class="token1">;</span>
<span class="token2">if</span> <span class="token1">(</span><span class="token3">is_array</span><span class="token1">(</span>$cat_parent_id<span class="token1">)</span><span class="token1">)</span>
<span class="token1">{</span>
$cond_row <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token4">'cat_parent_id:in'</span> <span class="token">=</span><span class="token">></span> $cat_parent_id<span class="token1">)</span><span class="token1">;</span>
$cache_key <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>_cacheKeyPrefix <span class="token1">.</span> <span class="token4">'cat_parent_id|'</span> <span class="token1">.</span> <span class="token3">implode</span><span class="token1">(</span><span class="token4">':'</span><span class="token1">,</span> $cat_parent_id<span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
$cond_row <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token4">'cat_parent_id'</span> <span class="token">=</span><span class="token">></span> $cat_parent_id<span class="token1">)</span><span class="token1">;</span>
$cache_key <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>_cacheKeyPrefix <span class="token1">.</span> <span class="token4">'cat_parent_id|'</span> <span class="token1">.</span> $cat_parent_id<span class="token1">;</span>
<span class="token1">}</span>
<span class="token5">//设置cache</span>
$Cache <span class="token">=</span> Yf_Cache<span class="token1">:</span><span class="token1">:</span><span class="token3">create</span><span class="token1">(</span><span class="token4">'base'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token5">//如果有缓存</span>
<span class="token2">if</span> <span class="token1">(</span>$cat_rows <span class="token">=</span> $Cache<span class="token">-</span><span class="token">></span><span class="token3">get</span><span class="token1">(</span>$cache_key<span class="token1">)</span><span class="token1">)</span>
<span class="token1">{</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
$cat_rows <span class="token">=</span> $this<span class="token">-</span><span class="token">></span><span class="token3">getByWhere</span><span class="token1">(</span>$cond_row<span class="token1">,</span> <span class="token3">array</span><span class="token1">(</span><span class="token4">'cat_displayorder'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'ASC'</span><span class="token1">)</span><span class="token1">)</span><span class="token1">;</span>
$Cache<span class="token">-</span><span class="token">></span><span class="token3">save</span><span class="token1">(</span>$cat_rows<span class="token1">,</span> $cache_key<span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token5">//不存在父类</span>
$data <span class="token">=</span> $Goods_CatModel<span class="token">-</span><span class="token">></span><span class="token3">getCatTree</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$Cache <span class="token">=</span> Yf_Cache<span class="token1">:</span><span class="token1">:</span><span class="token3">create</span><span class="token1">(</span><span class="token4">'base'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token2">if</span> <span class="token1">(</span>$data_rows <span class="token">=</span> $Cache<span class="token">-</span><span class="token">></span><span class="token3">get</span><span class="token1">(</span>$this<span class="token">-</span><span class="token">></span>treeAllKey<span class="token1">)</span><span class="token1">)</span>
<span class="token1">{</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
$data_rows <span class="token">=</span> $this<span class="token">-</span><span class="token">></span><span class="token3">getCatTreeData</span><span class="token1">(</span>$cat_parent_id<span class="token1">,</span> $recursive<span class="token1">,</span> $level<span class="token1">)</span><span class="token1">;</span>
$Cache<span class="token">-</span><span class="token">></span><span class="token3">save</span><span class="token1">(</span>$data_rows<span class="token1">,</span> $this<span class="token">-</span><span class="token">></span>treeAllKey<span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
```
```
添加/修改规格值(spec())
表单提交:
```
<pre class="calibre14">```
$<span class="token1">(</span><span class="token4">'#form'</span><span class="token1">)</span><span class="token1">.</span><span class="token3">prop</span><span class="token1">(</span><span class="token4">'action'</span><span class="token1">,</span> SITE_URL <span class="token">+</span> <span class="token4">"?ctl=Seller_Goods_Spec&met=saveSpecValue&typ=json&spec_id="</span> <span class="token">+</span> param_data<span class="token1">.</span>spec_id<span class="token1">)</span><span class="token1">;</span>
<span class="token5">//如果存在旧数据</span>
foreach <span class="token1">(</span>$old_data as $key <span class="token">=</span><span class="token">></span> $val<span class="token1">)</span>
<span class="token1">{</span>
$update_data<span class="token1">[</span><span class="token4">'spec_value_displayorder'</span><span class="token1">]</span> <span class="token">=</span> $val<span class="token1">[</span><span class="token4">'displayorder'</span><span class="token1">]</span><span class="token1">;</span>
$update_data<span class="token1">[</span><span class="token4">'spec_value_name'</span><span class="token1">]</span> <span class="token">=</span> $val<span class="token1">[</span><span class="token4">'spec_value_name'</span><span class="token1">]</span><span class="token1">;</span>
$flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>goodsSpecValueModel<span class="token">-</span><span class="token">></span><span class="token3">editSpecValue</span><span class="token1">(</span>$key<span class="token1">,</span> $update_data<span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token5">//如果存在新数据</span>
$update_data<span class="token1">[</span><span class="token4">'spec_id'</span><span class="token1">]</span> <span class="token">=</span> $spec_id<span class="token1">;</span>
foreach <span class="token1">(</span>$new_data as $key <span class="token">=</span><span class="token">></span> $val<span class="token1">)</span>
<span class="token1">{</span>
$update_data<span class="token1">[</span><span class="token4">'spec_value_displayorder'</span><span class="token1">]</span> <span class="token">=</span> $val<span class="token1">[</span><span class="token4">'displayorder'</span><span class="token1">]</span><span class="token1">;</span>
$update_data<span class="token1">[</span><span class="token4">'spec_value_name'</span><span class="token1">]</span> <span class="token">=</span> $val<span class="token1">[</span><span class="token4">'spec_value_name'</span><span class="token1">]</span><span class="token1">;</span>
$this<span class="token">-</span><span class="token">></span>goodsSpecValueModel<span class="token">-</span><span class="token">></span><span class="token3">addSpecValue</span><span class="token1">(</span>$update_data<span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token5">//商城添加规格值</span>
$spec_value_id <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>goodsSpecValueModel<span class="token">-</span><span class="token">></span><span class="token3">addSpecValue</span><span class="token1">(</span>$update_data<span class="token1">,</span> <span class="token6">true</span><span class="token1">)</span><span class="token1">;</span>
```
```
删除规格值:
```
<pre class="calibre15">```
$<span class="token1">(</span><span class="token4">'.delete'</span><span class="token1">)</span><span class="token1">.</span><span class="token3">click</span><span class="token1">(</span><span class="token2">function</span><span class="token1">(</span><span class="token1">)</span><span class="token1">{</span>
var _this <span class="token">=</span> $<span class="token1">(</span>this<span class="token1">)</span><span class="token1">;</span>
$<span class="token1">.</span>dialog<span class="token1">.</span><span class="token3">confirm</span><span class="token1">(</span><span class="token4">'<?=__("删除的数据将不能恢复,请确认是否删除")?>?'</span><span class="token1">,</span><span class="token2">function</span><span class="token1">(</span><span class="token1">)</span><span class="token1">{</span>
spec_value_id <span class="token">=</span> _this<span class="token1">.</span><span class="token3">children</span><span class="token1">(</span><span class="token4">'a'</span><span class="token1">)</span><span class="token1">.</span><span class="token3">data</span><span class="token1">(</span><span class="token4">'id'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token2">if</span> <span class="token1">(</span>typeof spec_value_id <span class="token">!=</span> <span class="token4">'undefined'</span><span class="token1">)</span> <span class="token1">{</span>
$<span class="token1">.</span><span class="token3">post</span><span class="token1">(</span> SITE_URL <span class="token">+</span> <span class="token4">"?ctl=Seller_Goods_Spec&met=removeSpecValue&typ=json"</span><span class="token1">,</span> <span class="token1">{</span> spec_value_id<span class="token1">:</span> spec_value_id<span class="token1">}</span><span class="token1">,</span> <span class="token2">function</span><span class="token1">(</span>data<span class="token1">)</span> <span class="token1">{</span>
<span class="token1">}</span><span class="token1">)</span>
<span class="token1">}</span> <span class="token2">else</span> <span class="token1">{</span>
_this<span class="token1">.</span><span class="token3">parent</span><span class="token1">(</span><span class="token1">)</span><span class="token1">.</span><span class="token3">parent</span><span class="token1">(</span><span class="token1">)</span><span class="token1">.</span><span class="token3">remove</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token1">}</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span><span class="token1">)</span><span class="token1">;</span>
$spec_value_id <span class="token">=</span> <span class="token3">request_int</span><span class="token1">(</span><span class="token4">'spec_value_id'</span><span class="token1">)</span><span class="token1">;</span>
$flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>goodsSpecValueModel<span class="token">-</span><span class="token">></span><span class="token3">removeSpecValue</span><span class="token1">(</span>$spec_value_id<span class="token1">)</span><span class="token1">;</span>
```
```
- 序言
- 系统要求
- 版本更新日志
- 远丰商城技术对接说明
- 开发指导
- 框架内容
- 基础
- 开发规范
- 目录结构
- 架构
- 架构总览
- 数据库
- 数据库连接
- 基本使用
- 缓存
- 配置
- 路由
- 数据字典
- ucenter
- shop
- paycenter
- ucenter_admin
- shop_admin
- paycenter_admin
- 通讯内容
- 商家中心
- 顶部导航栏
- 店铺信息栏
- 店铺及商品提示栏
- 交易提示栏
- 销售情况统计栏
- 单品销量排行栏
- 店铺运营推广栏
- 平台联系方式栏
- 订单物流
- 商品
- 商品列表
- 商品详情
- 商品发布与编辑
- 分销商品
- 关联版式
- 商品规格
- 图片空间
- 淘宝导入
- 订单流程
- 交易订单
- 订单退款/退货
- 促销
- 团购管理
- 加价购
- 限时折扣
- 满即送
- 代金券管理
- 分销
- 店铺
- 店铺设置
- 自销产品供应商
- 实体店铺
- 品牌申请
- 店铺信息
- 消费者保障服务
- 门店账号
- 分销商--产品供应商
- 分销明细
- 批发市场
- 售后服务
- 咨询管理
- 投诉管理
- 退款管理
- 退货管理
- 云方案架构
- 负载集群
- 云存储
- 接口
- Api接口说明
- 品牌
- 商品规格
- 商品类型
- 商品分类
- 商品
- 订单
- 商品/店铺收藏
- 足迹
- 退款及退货
- 商家店铺
- 会员
- 入驻协议
- 订单接口
- 商品接口
- 订单物流接口
- 商家中心接口
- 促销接口
- 快递鸟物流接口
- 代金券接口
- 首页版块
- 团购
- 平台红包
- 限时折扣接口
- 拼团接口
- wap首页模板
- 杂项
- 远程上传图片
- JS
- 银联支付
- 多语言
- 商品评分
- 图片加载
- 买家申请退款退货
- 商家退款退货
- 平台退款退货
- 添加发票
- 提交订单
- 确认订单
- 运费销售区域
- 获取会员地址
- 充值
- 导出XLS
- 商城系统集成
- 多语言实现
- 三级分销推广链接发展推广员
- app.ini.php
- 去分销
- 版本更新
- 物流支持
- 运营人员建议
- 业务逻辑
- 统计结算
- 客服消息
- 账号
- 三级分销
- IM
- 配置
- 平台帐号
- 活动数据表说明