brand.model.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * 商品品牌模型
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class brandModel extends Model {
  11. public function __construct() {
  12. parent::__construct('brand');
  13. }
  14. /**
  15. * 添加品牌
  16. * @param array $insert
  17. * @return boolean
  18. */
  19. public function addBrand($insert) {
  20. return $this->insert($insert);
  21. }
  22. /**
  23. * 编辑品牌
  24. * @param array $condition
  25. * @param array $update
  26. * @return boolean
  27. */
  28. public function editBrand($condition, $update) {
  29. return $this->where($condition)->update($update);
  30. }
  31. /**
  32. * 删除品牌
  33. * @param unknown $condition
  34. * @return boolean
  35. */
  36. public function delBrand($condition) {
  37. $brand_array = $this->getBrandList($condition, 'brand_id,brand_pic');
  38. $brandid_array = array();
  39. foreach ($brand_array as $value) {
  40. $brandid_array[] = $value['brand_id'];
  41. @unlink(BASE_UPLOAD_PATH.DS.ATTACH_BRAND.DS.$value['brand_pic']);
  42. }
  43. return $this->where(array('brand_id' => array('in', $brandid_array)))->delete();
  44. }
  45. /**
  46. * 查询品牌数量
  47. * @param array $condition
  48. * @return array
  49. */
  50. public function getBrandCount($condition) {
  51. return $this->where($condition)->count();
  52. }
  53. /**
  54. * 品牌列表
  55. * @param array $condition
  56. * @param string $field
  57. * @param string $order
  58. * @param number $page
  59. * @param string $limit
  60. * @return array
  61. */
  62. public function getBrandList($condition, $field = '*', $page = 0, $order = 'brand_sort asc, brand_id desc', $limit = '') {
  63. return $this->where($condition)->field($field)->order($order)->page($page)->limit($limit)->select();
  64. }
  65. /**
  66. * 通过的品牌列表
  67. *
  68. * @param array $condition
  69. * @param string $field
  70. * @return array
  71. */
  72. public function getBrandPassedList($condition, $field = '*', $page = 0, $order = 'brand_sort asc, brand_id desc', $limit = '') {
  73. $condition['brand_apply'] = 1;
  74. return $this->getBrandList($condition, $field, $page, $order, $limit);
  75. }
  76. /**
  77. * 未通过的品牌列表
  78. * @param array $condition
  79. * @param string $field
  80. * @return array
  81. */
  82. public function getBrandNoPassedList($condition, $field = '*', $page = 0) {
  83. $condition['brand_apply'] = 0;
  84. return $this->getBrandList($condition, $field, $page);
  85. }
  86. /**
  87. * 取单个品牌内容
  88. * @param array $condition
  89. * @param string $field
  90. * @return array
  91. */
  92. public function getBrandInfo($condition, $field = '*') {
  93. return $this->field($field)->where($condition)->find();
  94. }
  95. }