Brand.php 4.1 KB

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