1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php namespace Api\Lib;
- use Dever;
- class Spec
- {
- # 获取规格数据
- public function manage($table, $field, $id)
- {
- $result = array();
- if ($id) {
- $result = Dever::db($table)->select(array($field => $id));
- if ($result) {
- foreach ($result as $k => $v) {
- $result[$k]['type'] = 'show';
- $result[$k]['width'] = '100';
- $result[$k]['show'] = true;
- $result[$k]['fixed'] = true;
- $result[$k]['key'] = $v['name'];
- $value = Dever::db($table . '_value')->select(array($field => $id, 'spec_id' => $v['id']));
- if ($value) {
- foreach ($value as $k1 => $v1) {
- $value[$k1]['parent'] = $result[$k]['key'];
- $value[$k1]['name'] = $v1['value'];
- $value[$k1]['key'] = $v1['value'];
- if ($v1['is_checked'] == 1) {
- $value[$k1]['checked'] = true;
- } else {
- $value[$k1]['checked'] = false;
- }
- }
- }
- $result[$k]['value'] = $value;
- }
- }
- }
- return $result;
- }
- # 获取列表
- public function getList($where, $app)
- {
- $where['state'] = 1;
- $data = Dever::db('spec', $app)->select($where, array('col' => 'id,name'));
- if ($data) {
- foreach ($data as &$v) {
- $w = $where;
- $w['spec_id'] = $v['id'];
- unset($v['id']);
- $v['value'] = Dever::db('spec_value', $app)->select($w, array('col' => 'id,value'));
- }
- }
- return $data;
- }
- }
|