1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace Scm_product\Lib;
- use Dever;
- class Sku
- {
- # 获取当前的sku
- public function get_api()
- {
- $id = Dever::input('id');
- $result = array();
- if ($id) {
- $result = Dever::db('scm_product/info_sku')->getAll(array('info_id' => $id));
- }
- return $result;
- }
- # 获取某个商品的sku商品列表
- public function getList($info, &$data)
- {
- if ($info['spec_type']) {
- $where['info_id'] = $info['id'];
- if (isset($info['sku_id'])) {
- $where['id'] = $info['sku_id'];
- }
- $sku = Dever::db('scm_product/info_sku')->select($where);
- if ($sku) {
- foreach ($sku as $k => $v) {
- $copy = $info;
- $copy['id'] .= '-' . $v['id'];
- if (isset($info['servicer_store_id']) && $info['servicer_store_id']) {
- $copy['id'] .= '-' . $info['id'];
- }
- $key = str_replace('-', ',', $v['key']);
- $spec = Dever::db('scm_product/info_spec_value')->getGroupData(array('ids' => $key));
- $copy['spec'] = '无';
- if ($spec) {
- $copy['sname'] = $copy['name'];
- $copy['spec'] = $spec['name'];
- $copy['name'] .= '-' . $spec['name'];
- if (isset($copy['value'])) {
- $copy['value'] = $copy['id'];
- }
- }
-
- $data[] = $copy;
- }
- }
- } else {
- $data[] = $info;
- }
-
- return $data;
- }
- # 获取基本信息列表
- public function getData($info_id, $sku_id = false, $type = 1)
- {
- $seller_id = Dever::input('seller_id');
- if ($seller_id) {
- $seller = Dever::db('scm_role/seller')->find($seller_id);
- }
- $where['info_id'] = $info_id;
- if ($sku_id) {
- $where['id'] = $sku_id;
- }
- $sku = Dever::db('scm_product/info_sku')->getData($where);
- if ($sku) {
- foreach ($sku as $k => $v) {
- unset($sku[$k]['key']);
- if ($seller_id && $seller) {
- list($sku[$k]['price'], $sku[$k]['buy_price']) = Dever::load('scm_product/lib/price')->get($seller['price_id'], $info_id, $v['id'], $sku[$k]['price'], $sku[$k]['buy_price']);
- }
-
- if ($type == 1) {
- unset($sku[$k]['buy_price']);
- unset($sku[$k]['cost_price']);
- } elseif ($type == 2) {
- unset($sku[$k]['price']);
- unset($sku[$k]['un_price']);
- }
- }
- }
- return $sku;
- }
- }
|