GoodsBrand.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 山西牛酷信息科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com.cn
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\model\goods;
  13. use think\facade\Cache;
  14. use app\model\BaseModel;
  15. /**
  16. * 商品品牌
  17. */
  18. class GoodsBrand extends BaseModel
  19. {
  20. /**
  21. * 添加品牌
  22. * @param array $data
  23. */
  24. public function addBrand($data)
  25. {
  26. $data['create_time'] = time();
  27. $brand_id = model('goods_brand')->add($data);
  28. Cache::tag("goods_brand")->clear();
  29. return $this->success($brand_id);
  30. }
  31. /**
  32. * 修改品牌
  33. * @param array $data
  34. * @return multitype:string
  35. */
  36. public function editBrand($data)
  37. {
  38. $res = model('goods_brand')->update($data, [ [ 'brand_id', '=', $data['brand_id'] ] ]);
  39. Cache::tag("goods_brand")->clear();
  40. return $this->success($res);
  41. }
  42. /**
  43. * 删除品牌
  44. * @param array $condition
  45. */
  46. public function deleteBrand($condition)
  47. {
  48. $res = model('goods_brand')->delete($condition);
  49. Cache::tag("goods_brand")->clear();
  50. return $this->success($res);
  51. }
  52. /**
  53. * 修改排序
  54. * @param int $sort
  55. * @param int $brand_id
  56. */
  57. public function modifyBrandSort($sort, $brand_id)
  58. {
  59. $res = model('goods_brand')->update([ 'sort' => $sort ], [ [ 'brand_id', '=', $brand_id ] ]);
  60. Cache::tag("goods_brand")->clear();
  61. return $this->success($res);
  62. }
  63. /**
  64. * 修改转移品牌
  65. * @param int $sort
  66. * @param array $condition
  67. */
  68. public function modifyBrandSite($site_id, $condition)
  69. {
  70. $res = model('goods_brand')->update([ 'site_id' => $site_id ], $condition);
  71. Cache::tag("goods_brand")->clear();
  72. return $this->success($res);
  73. }
  74. /**
  75. * 获取品牌信息
  76. * @param array $condition
  77. * @param string $field
  78. */
  79. public function getBrandInfo($condition, $field = 'brand_id, brand_name, brand_initial, image_url, sort, create_time, is_recommend')
  80. {
  81. $data = json_encode([ $condition, $field ]);
  82. $cache = Cache::get("goods_brand_getBrandInfo_" . $data);
  83. if (!empty($cache)) {
  84. return $this->success($cache);
  85. }
  86. $res = model('goods_brand')->getInfo($condition, $field);
  87. Cache::tag("goods_brand")->set("goods_brand_getBrandInfo_" . $data, $res);
  88. return $this->success($res);
  89. }
  90. /**
  91. * 获取品牌列表
  92. * @param array $condition
  93. * @param string $field
  94. * @param string $order
  95. * @param string $limit
  96. */
  97. public function getBrandList($condition = [], $field = 'brand_id, brand_name, brand_initial, image_url, sort, create_time', $order = '', $limit = null)
  98. {
  99. $data = json_encode([ $condition, $field, $order, $limit ]);
  100. $cache = Cache::get("goods_brand_getBrandList_" . $data);
  101. if (!empty($cache)) {
  102. return $this->success($cache);
  103. }
  104. $list = model('goods_brand')->getList($condition, $field, $order, '', '', '', $limit);
  105. Cache::tag("goods_brand")->set("goods_brand_getBrandList_" . $data, $list);
  106. return $this->success($list);
  107. }
  108. /**
  109. * 获取品牌分页列表
  110. * @param array $condition
  111. * @param number $page
  112. * @param string $page_size
  113. * @param string $order
  114. * @param string $field
  115. */
  116. public function getBrandPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'ngb.create_time desc', $field = 'ngb.brand_id,ngb.brand_name,ngb.brand_initial,ngb.image_url,ngb.sort,ngb.create_time,ngb.is_recommend,ngb.site_id,ns.site_name')
  117. {
  118. $data = json_encode([ $condition, $field, $order, $page, $page_size ]);
  119. $cache = Cache::get("goods_brand_getBrandPageList_" . $data);
  120. if (!empty($cache)) {
  121. return $this->success($cache);
  122. }
  123. $alias = 'ngb';
  124. $join = [
  125. [
  126. 'shop ns',
  127. 'ngb.site_id = ns.site_id',
  128. 'left'
  129. ],
  130. ];
  131. $list = model('goods_brand')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
  132. Cache::tag("goods_brand")->set("goods_brand_getBrandPageList_" . $data, $list);
  133. return $this->success($list);
  134. }
  135. }