StoreProductController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\v1\store;
  12. use app\Request;
  13. use app\services\product\category\StoreProductCategoryServices;
  14. use app\services\product\product\StoreProductServices;
  15. use app\services\store\SystemStoreServices;
  16. /**
  17. * 商品类
  18. * Class StoreProductController
  19. * @package app\controller\api\store
  20. */
  21. class StoreProductController
  22. {
  23. /**
  24. * 商品services
  25. * @var StoreProductServices
  26. */
  27. protected $services;
  28. public function __construct(StoreProductServices $services)
  29. {
  30. $this->services = $services;
  31. }
  32. /**
  33. * 商品列表
  34. * @param Request $request
  35. * @return mixed
  36. */
  37. public function lst(Request $request, StoreProductCategoryServices $services, SystemStoreServices $storeServices)
  38. {
  39. $where = $request->getMore([
  40. [['sid', 'd'], 0],
  41. [['cid', 'd'], 0],
  42. ['keyword', '', '', 'store_name'],
  43. ['priceOrder', ''],
  44. ['salesOrder', ''],
  45. [['news', 'd'], 0, '', 'is_new'],
  46. [['type', ''], '', '', 'status'],
  47. ['ids', ''],
  48. [['selectId', 'd'], ''],
  49. ['productId', ''],
  50. ['brand_id', ''],
  51. ['promotions_id', 0],
  52. ['store_id', 0, '', 'relation_id'],
  53. ['delivery_type', ''],
  54. [['collate_code_id', 'd'], 0], //拼单ID 、桌码ID
  55. ['award', -1], //拼单ID 、桌码ID
  56. ]);
  57. if ($where['selectId'] && (!$where['sid'] || !$where['cid'])) {
  58. if ($services->value(['id' => $where['selectId']], 'pid')) {
  59. $where['sid'] = $where['selectId'];
  60. } else {
  61. $where['cid'] = $where['selectId'];
  62. }
  63. }
  64. $where['ids'] = stringToArray($where['ids']);
  65. if (!$where['ids']) {
  66. unset($where['ids']);
  67. }
  68. if ($where['brand_id']) {
  69. $where['brand_id'] = explode(',', $where['brand_id']);
  70. }
  71. $type = 'mid';
  72. $field = ['image', 'recommend_image'];
  73. if ($where['store_name']) {
  74. $field = ['image'];
  75. }
  76. if ($where['relation_id']) {//获取定位门店商品
  77. if ($where['delivery_type'] == 2) {// 获取自提商品
  78. //验证平台自提开启,门店自提是否开启
  79. if (!sys_config('store_self_mention', 1) || !$storeServices->value(['id' => $where['relation_id'], 'is_show' => 1, 'is_del' => 0], 'is_store')) {
  80. return app('json')->success([]);
  81. }
  82. }
  83. $where['type'] = 1;
  84. $where['show_type'] = [0, 1];
  85. $list = $this->services->getGoodsList($where, (int)$request->uid());
  86. return app('json')->successful(get_thumb_water($list, $type, $field));
  87. } else {
  88. return app('json')->success([]);
  89. }
  90. }
  91. /**
  92. * 搜索获取商品品牌列表
  93. * @param Request $request
  94. * @param StoreProductCategoryServices $services
  95. * @return mixed
  96. */
  97. public function brand(Request $request, StoreProductCategoryServices $services)
  98. {
  99. $where = $request->getMore([
  100. [['sid', 'd'], 0],
  101. [['cid', 'd'], 0],
  102. ['store_id', 0, '', 'relation_id'],
  103. ['selectId', '']
  104. ]);
  105. if ($where['selectId'] && (!$where['sid'] || !$where['cid'])) {
  106. if ($services->value(['id' => $where['selectId']], 'pid')) {
  107. $where['sid'] = $where['selectId'];
  108. } else {
  109. $where['cid'] = $where['selectId'];
  110. }
  111. }
  112. $cate_id = [];
  113. if ($where['sid']) {
  114. $cate_id = [$where['sid']];
  115. } elseif ($where['cid']) {
  116. $cate_id = array_merge([$where['cid']], $services->getColumn(['pid' => $where['cid'], 'is_show' => 1], 'id'));
  117. }
  118. if ($where['relation_id']) {//获取定位门店商品
  119. $where['type'] = 1;
  120. return app('json')->successful($this->services->getBrandList(['cate_id' => $cate_id]));
  121. } else {
  122. return app('json')->success([]);
  123. }
  124. }
  125. }