12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace Product\Lib;
- use Dever;
- class Sku
- {
- # 获取当前的规格
- public function spec_api()
- {
- $id = Dever::input('id');
- $result = array();
- if ($id) {
- $result = Dever::db('product/info_spec')->getAll(array('info_id' => $id));
- if ($result) {
- foreach ($result as $k => $v) {
- $result[$k]['child'] = Dever::db('product/info_spec_value')->getAll(array('info_id' => $id, 'spec_id' => $v['id']));
- }
- }
- }
- return $result;
- }
- # 获取当前的sku
- public function sku_api()
- {
- $id = Dever::input('id');
- $result = array();
- if ($id) {
- $result = Dever::db('product/info_sku')->getAll(array('info_id' => $id));
- }
- return $result;
- }
- # 获取某个商品的sku
- public function getList($info, &$data)
- {
- if ($info['spec_type'] == 2) {
- $where['info_id'] = $info['id'];
- $sku = Dever::db('product/info_sku')->select($where);
- if ($sku) {
- foreach ($sku as $k => $v) {
- $copy = $info;
- $key = str_replace('-', ',', $v['key']);
- $spec = Dever::db('product/info_spec_value')->getData(array('ids' => $key));
- if ($spec) {
- $copy['name'] .= '-' . $spec['name'];
- $copy['id'] .= '-' . $v['key'];
- if (isset($copy['value'])) {
- $copy['value'] = $copy['id'];
- }
- }
-
- $data[] = $copy;
- }
- }
- } else {
- $data[] = $info;
- }
-
- return $data;
- }
- }
|