Brand.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 数据层模型
  14. */
  15. class Brand extends BaseModel {
  16. public $page_info;
  17. /**
  18. * 添加品牌
  19. * @access public
  20. * @author csdeshang
  21. * @param array $data 参数内容
  22. * @return boolean
  23. */
  24. public function addBrand($data) {
  25. return Db::name('brand')->insertGetId($data);
  26. }
  27. /**
  28. * 编辑品牌
  29. * @access public
  30. * @author csdeshang
  31. * @param array $condition 检索条件
  32. * @param array $update 更新数据
  33. * @return boolean
  34. */
  35. public function editBrand($condition, $update) {
  36. return Db::name('brand')->where($condition)->update($update);
  37. }
  38. /**
  39. * 删除品牌
  40. * @access public
  41. * @author csdeshang
  42. * @param array $condition 检索条件
  43. * @return boolean
  44. */
  45. public function delBrand($condition) {
  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. return Db::name('brand')->where($condition)->count();
  63. }
  64. /**
  65. * 品牌列表
  66. * @access public
  67. * @author csdeshang
  68. * @param array $condition 检索条件
  69. * @param str $field 字段
  70. * @param int $pagesize 分页信息
  71. * @param str $order 排序
  72. * @return array
  73. */
  74. public function getBrandList($condition, $field = '*', $pagesize = 0, $order = 'brand_sort asc, brand_id desc') {
  75. if($pagesize) {
  76. $res= Db::name('brand')->where($condition)->field($field)->order($order)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  77. $this->page_info=$res;
  78. return $res->items();
  79. }else{
  80. return Db::name('brand')->where($condition)->field($field)->order($order)->select()->toArray();
  81. }
  82. }
  83. /**
  84. * 通过的品牌列表
  85. * @access public
  86. * @author csdeshang
  87. * @param array $condition 检索条件
  88. * @param str $field 字段
  89. * @param int $pagesize 分页信息
  90. * @param str $order 排序
  91. * @return array
  92. */
  93. public function getBrandPassedList($condition, $field = '*', $pagesize = 0, $order = 'brand_sort asc, brand_id desc') {
  94. $condition[] = array('brand_apply','=',1);
  95. return $this->getBrandList($condition, $field, $pagesize, $order);
  96. }
  97. /**
  98. * 未通过的品牌列表
  99. * @access public
  100. * @author csdeshang
  101. * @param array $condition 检索条件
  102. * @param string $field 字段
  103. * @param string $pagesize 分页信息
  104. * @return array
  105. */
  106. public function getBrandNoPassedList($condition, $field = '*', $pagesize = 0) {
  107. $condition[] = array('brand_apply','=',0);
  108. return $this->getBrandList($condition, $field, $pagesize);
  109. }
  110. /**
  111. * 取单个品牌内容
  112. * @access public
  113. * @author csdeshang
  114. * @param array $condition 检索条件
  115. * @param string $field 字段
  116. * @return array
  117. */
  118. public function getBrandInfo($condition, $field = '*') {
  119. return Db::name('brand')->field($field)->where($condition)->find();
  120. }
  121. }
  122. ?>