Spec.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php namespace Api\Lib;
  2. use Dever;
  3. class Spec
  4. {
  5. # 获取规格数据
  6. public function manage($table, $field, $id)
  7. {
  8. $result = array();
  9. if ($id) {
  10. $result = Dever::db($table)->select(array($field => $id));
  11. if ($result) {
  12. foreach ($result as $k => $v) {
  13. $result[$k]['type'] = 'show';
  14. $result[$k]['width'] = '100';
  15. $result[$k]['show'] = true;
  16. $result[$k]['fixed'] = true;
  17. $result[$k]['key'] = $v['name'];
  18. $value = Dever::db($table . '_value')->select(array($field => $id, 'spec_id' => $v['id']));
  19. if ($value) {
  20. foreach ($value as $k1 => $v1) {
  21. $value[$k1]['parent'] = $result[$k]['key'];
  22. $value[$k1]['name'] = $v1['value'];
  23. $value[$k1]['key'] = $v1['value'];
  24. if ($v1['is_checked'] == 1) {
  25. $value[$k1]['checked'] = true;
  26. } else {
  27. $value[$k1]['checked'] = false;
  28. }
  29. }
  30. }
  31. $result[$k]['value'] = $value;
  32. }
  33. }
  34. }
  35. return $result;
  36. }
  37. # 获取列表
  38. public function getList($where, $app)
  39. {
  40. $where['state'] = 1;
  41. $data = Dever::db('spec', $app)->select($where, array('col' => 'id,name'));
  42. if ($data) {
  43. foreach ($data as &$v) {
  44. $w = $where;
  45. $w['spec_id'] = $v['id'];
  46. unset($v['id']);
  47. $v['value'] = Dever::db('spec_value', $app)->select($w, array('col' => 'id,value'));
  48. }
  49. }
  50. return $data;
  51. }
  52. }