StoreProductController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. ]);
  56. if ($where['selectId'] && (!$where['sid'] || !$where['cid'])) {
  57. if ($services->value(['id' => $where['selectId']], 'pid')) {
  58. $where['sid'] = $where['selectId'];
  59. } else {
  60. $where['cid'] = $where['selectId'];
  61. }
  62. }
  63. $where['ids'] = stringToArray($where['ids']);
  64. if (!$where['ids']) {
  65. unset($where['ids']);
  66. }
  67. if ($where['brand_id']) {
  68. $where['brand_id'] = explode(',', $where['brand_id']);
  69. }
  70. $type = 'mid';
  71. $field = ['image', 'recommend_image'];
  72. if ($where['store_name']) {
  73. $field = ['image'];
  74. }
  75. if ($where['relation_id']) {//获取定位门店商品
  76. if ($where['delivery_type'] == 2) {// 获取自提商品
  77. //验证平台自提开启,门店自提是否开启
  78. if(!sys_config('store_self_mention', 1) || !$storeServices->value(['id' => $where['relation_id'], 'is_show' => 1, 'is_del' => 0], 'is_store')) {
  79. return app('json')->success([]);
  80. }
  81. }
  82. $where['type'] = 1;
  83. $where['show_type'] = [0, 1];
  84. $list = $this->services->getGoodsList($where, (int)$request->uid());
  85. return app('json')->successful(get_thumb_water($list, $type, $field));
  86. } else {
  87. return app('json')->success([]);
  88. }
  89. }
  90. /**
  91. * 搜索获取商品品牌列表
  92. * @param Request $request
  93. * @param StoreProductCategoryServices $services
  94. * @return mixed
  95. */
  96. public function brand(Request $request, StoreProductCategoryServices $services)
  97. {
  98. $where = $request->getMore([
  99. [['sid', 'd'], 0],
  100. [['cid', 'd'], 0],
  101. ['store_id', 0, '', 'relation_id'],
  102. ['selectId', '']
  103. ]);
  104. if ($where['selectId'] && (!$where['sid'] || !$where['cid'])) {
  105. if ($services->value(['id' => $where['selectId']], 'pid')) {
  106. $where['sid'] = $where['selectId'];
  107. } else {
  108. $where['cid'] = $where['selectId'];
  109. }
  110. }
  111. $cate_id = [];
  112. if ($where['sid']) {
  113. $cate_id = [$where['sid']];
  114. } elseif ($where['cid']) {
  115. $cate_id = array_merge([$where['cid']], $services->getColumn(['pid' => $where['cid'], 'is_show' => 1], 'id'));
  116. }
  117. if ($where['relation_id']) {//获取定位门店商品
  118. $where['type'] = 1;
  119. return app('json')->successful($this->services->getBrandList(['cate_id' => $cate_id]));
  120. } else {
  121. return app('json')->success([]);
  122. }
  123. }
  124. }