123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- namespace Product\Lib;
- use Dever;
- class Info
- {
-
- public function getList()
- {
-
- }
-
- public function getInfo($id)
- {
- $info = Dever::db('product/info')->find($id);
- $info = $this->get($info);
- return $info;
- }
- private function get($info)
- {
-
-
-
-
- }
-
- public function getSetList($table, $other_where, $cate_id = false, $col = 'goods_id', $set = array())
- {
- $price = Dever::input('price', 0);
- $buy_price = Dever::input('buy_price', 0);
- $total = Dever::input('total', 1);
- if ($cate_id) {
- $where['top_category_id'] = $cate_id;
- }
- $where['status'] = 1;
- $data = Dever::db('product/info')->getData($where);
- $result = array();
- if ($data) {
- $i = 0;
- foreach ($data as $k => $v) {
-
- $sku = Dever::db('product/info_sku')->select(array('info_id' => $v['id']));
- if ($sku) {
- $other_where[$col] = $v['id'];
- $other_where['sku_id'] = -1;
- $other = Dever::db($table)->find($other_where);
- if ($set) {
- $result[$i]['set'] = $set;
- }
-
- $result[$i]['id'] = $v['id'];
- $result[$i]['name'] = $v['name'];
- $result[$i]['type'] = $v['type'];
- $result[$i]['stock'] = $v['stock'];
- $result[$i]['commission'] = $v['commission'];
- $result[$i]['old_price'] = 0;
- $result[$i]['old_buy_price'] = 0;
- $result[$i]['price'] = $price;
- $result[$i]['buy_price'] = $buy_price;
- $result[$i]['select'] = 2;
- $result[$i]['del'] = 1;
- $result[$i]['total'] = 0;
-
- if ($other) {
- if (isset($other['commission']) && $other['commission']) {
- $result[$i]['commission'] = $other['commission'];
- }
- if (isset($other['price']) && $other['price']) {
- $result[$i]['price'] = $other['price'];
- }
- if (isset($other['buy_price']) && $other['buy_price']) {
- $result[$i]['buy_price'] = $other['buy_price'];
- }
- if (isset($other['min']) && $other['min']) {
- $result[$i]['min'] = $other['min'];
- }
- if (isset($other['total_num'])) {
- if (isset($other['sell_num'])) {
- $result[$i]['total'] = $other['total_num'] - $other['sell_num'];
- } else {
- $result[$i]['total'] = $other['total_num'];
- }
-
- } elseif (isset($other['num'])) {
- $result[$i]['total'] = $other['num'];
- }
-
- $result[$i]['select'] = $other['state'];
- }
- $result[$i]['total'] = $result[$i]['total'] * $total;
- $result[$i]['children'] = array();
- $num = count($sku);
- if ($sku[0]['key'] == -1) {
- $result[$i]['old_price'] = $sku[0]['price'];
- $result[$i]['old_buy_price'] = $sku[0]['buy_price'];
- if (!$price && $result[$i]['price'] <= 0) {
- $result[$i]['price'] = $sku[0]['price'];
- }
- if (!$buy_price && $result[$i]['buy_price'] <= 0) {
- $result[$i]['buy_price'] = $sku[0]['buy_price'];
- }
-
-
- $result[$i]['end'] = true;
- } else {
- foreach ($sku as $k1 => $v1) {
- $v1['sku_name'] = '';
- if ($v1['key']) {
- $key = str_replace('-', ',', $v1['key']);
- $spec = Dever::db('product/info_spec_value')->getData(array('ids' => $key));
- $v1['sku_name'] = $spec['name'];
- }
- $name = $v['name'];
- if ($v1['sku_name']) {
- $name .= '-' . $v1['sku_name'];
- }
- $children = array
- (
- 'id' => $v['id'] . '-' . $v1['id'],
- 'name' => $name,
- 'stock' => $v['stock'],
- 'commission' => $v['commission'],
- 'old_price' => $v1['price'] ? $v1['price'] : 0,
- 'old_buy_price' => $v1['buy_price'] ? $v1['buy_price'] : 0,
- 'price' => $price ? $price : $v1['price'],
- 'buy_price' => $buy_price ? $buy_price : $v1['buy_price'],
- 'type' => $v['type'],
- 'del' => 1,
- 'end' => true,
- 'total' => 0,
- );
- $other_where['sku_id'] = $v1['id'];
- $other_sku = Dever::db($table)->find($other_where);
- $children['select'] = 2;
- $children['total'] = 0;
- if ($set) {
- $children['set'] = $set;
- }
- if ($other_sku) {
- if (isset($other_sku['commission']) && $other_sku['commission']) {
- $children['commission'] = $other_sku['commission'];
- }
- if (isset($other_sku['price']) && $other_sku['price']) {
- $children['price'] = $other_sku['price'];
- }
- if (isset($other_sku['buy_price']) && $other_sku['buy_price']) {
- $children['buy_price'] = $other_sku['buy_price'];
- }
- if (isset($other_sku['min']) && $other_sku['min']) {
- $children['min'] = $other_sku['min'];
- }
- if (isset($other_sku['total_num'])) {
- if (isset($other_sku['sell_num'])) {
- $children['total'] = $other_sku['total_num'] - $other_sku['sell_num'];
- } else {
- $children['total'] = $other_sku['total_num'];
- }
- } elseif (isset($other_sku['num'])) {
- $children['total'] = $other_sku['num'];
- }
-
- $children['select'] = $other_sku['state'];
- }
- $children['total'] = $children['total']*$total;
- $result[$i]['children'][] = $children;
- }
- }
- $i++;
- }
- }
- }
- return $result;
- }
- }
|