Brand.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Brand extends BaseModel
  12. {
  13. public $page_info;
  14. /**
  15. * 添加品牌
  16. * @access public
  17. * @author csdeshang
  18. * @param array $data 参数内容
  19. * @return boolean
  20. */
  21. public function addBrand($data)
  22. {
  23. return Db::name('brand')->insertGetId($data);
  24. }
  25. /**
  26. * 编辑品牌
  27. * @access public
  28. * @author csdeshang
  29. * @param array $condition 检索条件
  30. * @param array $update 更新数据
  31. * @return boolean
  32. */
  33. public function editBrand($condition, $update)
  34. {
  35. return Db::name('brand')->where($condition)->update($update);
  36. }
  37. /**
  38. * 删除品牌
  39. * @access public
  40. * @author csdeshang
  41. * @param array $condition 检索条件
  42. * @return boolean
  43. */
  44. public function delBrand($condition)
  45. {
  46. $brand_array = $this->getBrandList($condition, 'brand_id,brand_pic');
  47. $brandid_array = array();
  48. foreach ($brand_array as $value) {
  49. $brandid_array[] = $value['brand_id'];
  50. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_BRAND . DIRECTORY_SEPARATOR . $value['brand_pic']);
  51. }
  52. return Db::name('brand')->where('brand_id', 'in', $brandid_array)->delete();
  53. }
  54. /**
  55. * 查询品牌数量
  56. * @access public
  57. * @author csdeshang
  58. * @param array $condition 检索条件
  59. * @return array
  60. */
  61. public function getBrandCount($condition)
  62. {
  63. return Db::name('brand')->where($condition)->count();
  64. }
  65. /**
  66. * 品牌列表
  67. * @access public
  68. * @author csdeshang
  69. * @param array $condition 检索条件
  70. * @param str $field 字段
  71. * @param int $pagesize 分页信息
  72. * @param str $order 排序
  73. * @return array
  74. */
  75. public function getBrandList($condition, $field = '*', $pagesize = 0, $order = 'brand_sort asc, brand_id desc')
  76. {
  77. if ($pagesize) {
  78. $res = Db::name('brand')->where($condition)->field($field)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  79. $this->page_info = $res;
  80. return $res->items();
  81. } else {
  82. return Db::name('brand')->where($condition)->field($field)->order($order)->select()->toArray();
  83. }
  84. }
  85. /**
  86. * 通过的品牌列表
  87. * @access public
  88. * @author csdeshang
  89. * @param array $condition 检索条件
  90. * @param str $field 字段
  91. * @param int $pagesize 分页信息
  92. * @param str $order 排序
  93. * @return array
  94. */
  95. public function getBrandPassedList($condition, $field = '*', $pagesize = 0, $order = 'brand_sort asc, brand_id desc')
  96. {
  97. $condition[] = array('brand_apply', '=', 1);
  98. return $this->getBrandList($condition, $field, $pagesize, $order);
  99. }
  100. /**
  101. * 未通过的品牌列表
  102. * @access public
  103. * @author csdeshang
  104. * @param array $condition 检索条件
  105. * @param string $field 字段
  106. * @param string $pagesize 分页信息
  107. * @return array
  108. */
  109. public function getBrandNoPassedList($condition, $field = '*', $pagesize = 0)
  110. {
  111. $condition[] = array('brand_apply', '=', 0);
  112. return $this->getBrandList($condition, $field, $pagesize);
  113. }
  114. /**
  115. * 取单个品牌内容
  116. * @access public
  117. * @author csdeshang
  118. * @param array $condition 检索条件
  119. * @param string $field 字段
  120. * @return array
  121. */
  122. public function getBrandInfo($condition, $field = '*')
  123. {
  124. return Db::name('brand')->field($field)->where($condition)->find();
  125. }
  126. }