1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php namespace Api\Lib;
- use Dever;
- class Sku
- {
- # 获取当前价格
- public function getPrice($where, $spec_type, $app)
- {
- /*
- $result['price'] = 0;
- $result['id'] = 0;
- $result['name'] = '';
- */
- $result = array();
- if ($spec_type == 2) {
- $where['key'] = '-1';
- $sku = Dever::db('sku', $app)->find($where);
- } elseif ($spec_type == 3) {
- $sku = Dever::db('sku', $app)->find($where, array('order' => 'price asc,id desc'));
- }
- if (isset($sku) && $sku) {
- $result['price'] = $sku['price'];
- $result['id'] = $sku['id'];
- $result['key'] = str_replace(',', '_', $sku['key']);
- $result['name'] = $this->getName($sku['key'], $app);
- }
- return $result;
- }
- # 多规格获取多个价格
- public function getList($where, $sku_id, $app)
- {
- $result = array();
- $sku = Dever::db('sku', $app)->select($where, array('order' => 'price asc,id desc'));
- if ($sku) {
- $result['info'] = array();
- $result['spec'] = Dever::load('spec', 'api')->getList($where, $app);
- foreach ($sku as $k => $v) {
- $t = array();
- $k = str_replace(',', '_', $v['key']);
- $t['id'] = $v['id'];
- $t['pic'] = $v['pic'];
- $t['value'] = $v['price'];
- $result['price'][$k] = $t;
- if ($sku_id && $sku_id == $v['id']) {
- $t['name'] = $this->getName($v['key'], $app);
- $result['info'] = $t;
- }
- }
- }
- return $result;
- }
- # 获取某个sku的名称
- public function getName($key, $app)
- {
- if (!$key || $key == '-1') {
- return '';
- } else {
- $name = array();
- $where['id'] = array('in', $key);
- $data = Dever::db('spec_value', $app)->select($where);
- if ($data) {
- foreach ($data as $k => $v) {
- $info = Dever::db('spec', $app)->find($v['spec_id']);
- $name[] = $info['name'] . ':' . $v['value'];
- }
- }
- return implode(',', $name);
- }
- }
- }
|