Attribute.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * ============================================================================
  12. * 数据层模型
  13. */
  14. class Attribute extends BaseModel {
  15. const SHOW0 = 0; // 不显示
  16. const SHOW1 = 1; // 显示
  17. /**
  18. * 属性列表
  19. * @access public
  20. * @author csdeshang
  21. * @param array $condition 检索条件
  22. * @param string $field 字段
  23. * @return array
  24. */
  25. public function getAttributeList($condition, $field = '*') {
  26. return Db::name('attribute')->where($condition)->field($field)->order('attr_sort asc')->select()->toArray();
  27. }
  28. /**
  29. * 属性列表
  30. * @access public
  31. * @author csdeshang
  32. * @param array $condition 检索条件
  33. * @param string $field 字段
  34. * @return array
  35. */
  36. public function getAttributeShowList($condition, $field = '*') {
  37. $condition[] = array('attr_show','=',self::SHOW1);
  38. return $this->getAttributeList($condition, $field);
  39. }
  40. /**
  41. * 属性值列表
  42. * @access public
  43. * @author csdeshang
  44. * @param array $condition 检索条件
  45. * @param string $field 字段
  46. * @return array
  47. */
  48. public function getAttributeValueList($condition, $field = '*') {
  49. return Db::name('attributevalue')->where($condition)->field($field)->order('attrvalue_sort asc,attrvalue_id asc')->select()->toArray();
  50. }
  51. /**
  52. * 保存属性值
  53. * @access public
  54. * @author csdeshang
  55. * @param array $data 参数内容
  56. * @return boolean
  57. */
  58. public function addAttributeValueAll($data) {
  59. return Db::name('attributevalue')->insertAll($data);
  60. }
  61. /**
  62. * 保存属性值
  63. * @access public
  64. * @author csdeshang
  65. * @param array $data 参数内容
  66. * @return boolean
  67. */
  68. public function addAttributeValue($data) {
  69. return Db::name('attributevalue')->insertGetId($data);
  70. }
  71. /**
  72. * 编辑属性值
  73. * @access public
  74. * @author csdeshang
  75. * @param array $update 更新数据
  76. * @param array $condition 条件
  77. * @return boolean
  78. */
  79. public function editAttributeValue($update, $condition) {
  80. return Db::name('attributevalue')->where($condition)->update($update);
  81. }
  82. }