BrandController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/3
  6. * Time: 下午2:29
  7. */
  8. namespace app\frontend\modules\goods\controllers;
  9. use app\common\components\ApiController;
  10. use Illuminate\Support\Facades\Cookie;
  11. use app\common\components\BaseController;
  12. use app\common\helpers\PaginationHelper;
  13. use app\common\helpers\Url;
  14. use Setting;
  15. use Illuminate\Support\Facades\DB;
  16. use Illuminate\Session\Store;
  17. use app\common\models\Goods;
  18. use app\frontend\modules\goods\models\Brand;
  19. use app\frontend\modules\goods\services\BrandService;
  20. class BrandController extends ApiController
  21. {
  22. public function getBrand()
  23. {
  24. app('db')->cacheSelect = true;
  25. $pageSize = 100;
  26. $list = Brand::getBrands();
  27. if (isset(\YunShop::request()->is_recommend))
  28. {
  29. $is_recommend = intval(\YunShop::request()->is_recommend);
  30. $list = $list->where('is_recommend',intval($is_recommend));
  31. }
  32. $list = $list->paginate($pageSize)->toArray();
  33. if($list['data']){
  34. foreach ($list['data'] as &$item) {
  35. $item['logo'] = replace_yunshop(yz_tomedia($item['logo']));
  36. }
  37. return $this->successJson('获取品牌数据成功!', $list);
  38. }
  39. return $this->errorJson('未检测到品牌数据!', $list);
  40. }
  41. public function getBrandGoods()
  42. {
  43. $id = intval(\YunShop::request()->id);
  44. if (!$id) {
  45. return $this->errorJson('请传入正确参数.');
  46. }
  47. $brand_detail = Brand::uniacid()->select("name", "logo", "id", "desc")->find($id);
  48. if (!$brand_detail) {
  49. return $this->errorJson('品牌已被删除或不存在...');
  50. }
  51. if ($brand_detail->logo) {
  52. $brand_detail->logo = yz_tomedia($brand_detail->logo);
  53. }
  54. $brand_detail->desc = html_entity_decode($brand_detail->desc);
  55. $list = Goods::select('id', 'id as goods_id', 'title', 'thumb', 'price', 'market_price','plugin_id')
  56. ->where("status", 1)
  57. ->where(function($query) {
  58. //$query->where("plugin_id", 0)->orWhere('plugin_id', 40)->orWhere('plugin_id', 92);
  59. $query->whereIn("plugin_id", [0,40,92,44]);
  60. })->where('brand_id', $id)->orderBy('display_order', 'desc')
  61. ->paginate(20)->toArray();
  62. if ($list['total'] > 0) {
  63. $data = collect($list['data'])->map(function($rows) {
  64. return collect($rows)->map(function($item, $key) {
  65. if ($key == 'thumb') {
  66. return replace_yunshop(yz_tomedia($item));
  67. } else {
  68. return $item;
  69. }
  70. });
  71. })->toArray();
  72. $list['data'] = $data;
  73. }
  74. if (empty($list)) {
  75. return $this->errorJson('该品牌下没有商品.');
  76. }
  77. $brand_detail['goods'] = $list;
  78. return $this->successJson('成功', $brand_detail);
  79. }
  80. public function getBrandDetail()
  81. {
  82. $id = intval(\YunShop::request()->id);
  83. if (!$id) {
  84. return $this->errorJson('请传入正确参数.');
  85. }
  86. $brand_detail = Brand::uniacid()->select("name", "logo", "id", "desc")->find($id);
  87. if (!$brand_detail) {
  88. return $this->errorJson('品牌已被删除或不存在...');
  89. }
  90. if ($brand_detail->logo) {
  91. $brand_detail->logo = yz_tomedia($brand_detail->logo);
  92. }
  93. $brand_detail->desc = html_entity_decode($brand_detail->desc);
  94. return $this->successJson('brand_detail', $brand_detail);
  95. }
  96. }