ApiGoods.Class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?php
  2. /**
  3. * 前台商品接口
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/11/15
  7. * Time: 9:37
  8. */
  9. namespace JinDouYun\Controller\Goods;
  10. use JinDouYun\Model\Goods\MGoodsGroups;
  11. use JinDouYun\Model\Goods\MGoodsSupport;
  12. use JinDouYun\Model\GoodsManage\MGoodsBrand;
  13. use Mall\Framework\Core\ErrorCode;
  14. use JinDouYun\Controller\BaseController;
  15. use JinDouYun\Model\Goods\MGoods;
  16. use JinDouYun\Model\Goods\MGoodsCollect;
  17. use Mall\Framework\Core\StatusCode;
  18. /**
  19. * Class ApiGoods
  20. * @package JinDouYun\Controller\Goods
  21. */
  22. class ApiGoods extends BaseController
  23. {
  24. /**
  25. * @var MGoods
  26. */
  27. private $objMGoods;
  28. /**
  29. * @var MGoodsCollect
  30. */
  31. private $objMGoodsCollect;
  32. private $objMGoodsSupport;
  33. private $objMGoodsBrand;
  34. private $objMGoodsGroups;
  35. /**
  36. * ApiGoods constructor.
  37. * @param bool $isCheckAcl
  38. * @param bool $isMustLogin
  39. * @param bool $checkToken
  40. * @param bool $getAreaCode
  41. * @throws \Exception
  42. */
  43. public function __construct($isCheckAcl = false, $isMustLogin = false,$checkToken=true,$getAreaCode=true)
  44. {
  45. parent::__construct($isCheckAcl, $isMustLogin,$checkToken,$getAreaCode);
  46. $authorization = $this->request->getServerParam('HTTP_AUTHORIZATION');
  47. $isFront = true;
  48. if (!empty($authorization)) {
  49. self::getUserIdByAuthorization();
  50. }
  51. $this->objMGoods = new MGoods($this->onlineEnterpriseId, $isFront, $this->onlineUserId);
  52. $this->objMGoodsCollect = new MGoodsCollect($this->onlineEnterpriseId, $this->onlineUserId);
  53. $this->objMGoodsSupport = new MGoodsSupport($this->onlineEnterpriseId, $this->onlineUserId);
  54. $this->objMGoodsBrand = new MGoodsBrand($this->onlineUserId, $this->onlineEnterpriseId);
  55. $this->objMGoodsGroups = new MGoodsGroups($this->onlineEnterpriseId, $this->onlineUserId);
  56. }
  57. /**
  58. * 前台获取商品列表
  59. * @throws \Exception
  60. */
  61. public function getGoodsByCategory() {
  62. $params = $this->request->getRawJson();
  63. if( empty($params) ){
  64. $this->sendOutput('参数为空', ErrorCode::$paramError );
  65. }
  66. $selectParams = [
  67. 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : '',
  68. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',
  69. 'brandId' => isset($params['brandId']) ? $params['brandId'] : [],//商品品牌
  70. 'sort' => isset($params['sort']) ? $params['sort'] : '', //销售排序
  71. 'priceSort' => isset($params['priceSort']) ? $params['priceSort'] : '', //价格排序 未完成
  72. 'support' => isset($params['support']) ? $params['support'] : [], //商品服务
  73. 'goodsGroups' => isset($params['goodsGroups']) ? $params['goodsGroups'] : '', //商品分组
  74. 'areaCode'=>$this->areaCode,
  75. 'enableStatus' => StatusCode::$standard,
  76. ];
  77. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  78. $selectParams['limit'] = $pageParams['limit'];
  79. $selectParams['offset'] = $pageParams['offset'];
  80. $selectParams['userCenterId'] = isset($params['userCenterId']) ? $params['userCenterId'] : $this->onlineUserId;
  81. if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId;
  82. $result = $this->objMGoods->search($selectParams);
  83. if($result->isSuccess()){
  84. $returnData = $result->getData();
  85. $pageData = [
  86. 'pageIndex' => $params['page'],
  87. 'pageSize' => $params['pageSize'],
  88. 'pageTotal' => $returnData['total'],
  89. ];
  90. parent::sendOutput($returnData['data'], 0, $pageData);
  91. }
  92. parent::sendOutput($result->getData(), $result->getErrorCode());
  93. }
  94. /**
  95. * Doc: (des="商户详情页面 通过shopId获取商品")
  96. * User: XMing
  97. * Date: 2021/1/29
  98. * Time: 10:33 上午
  99. */
  100. public function getMerchantGoodsByCategory()
  101. {
  102. $params = $this->request->getRawJson();
  103. if( empty($params) ){
  104. parent::sendOutput('参数为空', ErrorCode::$paramError );
  105. }
  106. if(!isset($params['shopId']) || empty($params['shopId'])){
  107. parent::sendOutput('shopId参数错误',ErrorCode::$paramError);
  108. }
  109. $selectParams = [
  110. 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : '',
  111. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',
  112. 'areaCode'=>$this->areaCode,
  113. 'shopId' => $params['shopId']
  114. ];
  115. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  116. $selectParams['limit'] = $pageParams['limit'];
  117. $selectParams['offset'] = $pageParams['offset'];
  118. $selectParams['userCenterId'] = isset($params['userCenterId']) ? $params['userCenterId'] : $this->onlineUserId;
  119. $result = $this->objMGoods->search($selectParams);
  120. if($result->isSuccess()){
  121. $returnData = $result->getData();
  122. $pageData = [
  123. 'pageIndex' => $params['page'],
  124. 'pageSize' => $params['pageSize'],
  125. 'pageTotal' => $returnData['total'],
  126. ];
  127. parent::sendOutput($returnData['data'], 0, $pageData);
  128. }
  129. parent::sendOutput($result->getData(), $result->getErrorCode());
  130. }
  131. /**
  132. * 商品详情
  133. * @throws \Exception
  134. */
  135. public function getGoodsDetail() {
  136. $goodsId = $this->request->param('request_id');
  137. if ( !$goodsId ) {
  138. $this->sendOutput('参数错误', ErrorCode::$paramError );
  139. }
  140. $result = $this->objMGoods->getApiGoodsInfo($goodsId, $this->areaCode);
  141. if($result->isSuccess()){
  142. $resultData = $result->getData();
  143. $this->sendOutput($resultData);
  144. }
  145. $this->sendOutput($result->getData(), $result->getErrorCode());
  146. }
  147. /**
  148. * 收藏/取消收藏
  149. * @throws \Exception
  150. */
  151. public function collect()
  152. {
  153. $goodsId = $this->request->param('request_id');
  154. if ( !$goodsId ) {
  155. $this->sendOutput('参数错误', ErrorCode::$paramError );
  156. }
  157. $result = $this->objMGoodsCollect->addGoodsCollect($goodsId);
  158. if($result->isSuccess()){
  159. $this->sendOutput($result->getData());
  160. }
  161. $this->sendOutput($result->getData(), $result->getErrorCode());
  162. }
  163. /**
  164. * 常购物请单
  165. * @throws \Exception
  166. */
  167. public function normalList()
  168. {
  169. $result = $this->objMGoodsCollect->normalList($this->areaCode);
  170. if($result->isSuccess()){
  171. $this->sendOutput($result->getData());
  172. }
  173. $this->sendOutput($result->getData(), $result->getErrorCode());
  174. }
  175. /**
  176. * 小程序所有商品服务
  177. */
  178. public function getAllGoodsSupport()
  179. {
  180. $params = $this->request->getRawJson();
  181. if(empty($params)){
  182. $this->sendOutput('参数错误', ErrorCode::$paramError);
  183. }
  184. $params['servicesName'] = getArrayItem($params,'servicesName','');
  185. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  186. $params['limit'] = $pageParams['limit'];
  187. $params['offset'] = $pageParams['offset'];
  188. $returnData = $this->objMGoodsSupport->getAllGoodsSupport($params);
  189. if ($returnData->isSuccess()) {
  190. $returnData = $returnData->getData();
  191. $pageData = [
  192. 'pageIndex' => $params['page'],
  193. 'pageSize' => $params['pageSize'],
  194. 'pageTotal' => $returnData['total'],
  195. ];
  196. parent::sendOutput($returnData['data'], 0, $pageData);
  197. } else {
  198. parent::sendOutput($returnData->getData(), ErrorCode::$dberror);
  199. }
  200. }
  201. /**
  202. * 获取所有品牌
  203. * @throws \Exception
  204. */
  205. public function getAllBrand()
  206. {
  207. $page = $this->request->param('page') ? $this->request->param('page') : 1;
  208. $pageSize = $this->request->param('pageSize') ? $this->request->param('pageSize') : 10;
  209. $keyword = $this->request->param('keyword') ? $this->request->param('keyword') : '';
  210. $categoryId = $this->request->param('categoryId') ? $this->request->param('categoryId') : '';
  211. $offset = ($page - 1) * $pageSize;
  212. $selectParams = [
  213. 'limit' => $pageSize,
  214. 'offset' => $offset,
  215. ];
  216. if (!empty($keyword)) {
  217. $selectParams['keyword'] = $keyword;
  218. }
  219. if (!empty($categoryId)) {
  220. $selectParams['categoryId'] = $categoryId;
  221. }
  222. $reportData = $this->objMGoodsBrand->apiGetAllBrand($selectParams);
  223. // if (!empty($categoryId)){
  224. // $reportData = $this->objMGoods->getAllBrandByCategory($categoryId);
  225. // }
  226. if ($reportData->isSuccess()) {
  227. $returnData = $reportData->getData();
  228. $pageData = [
  229. 'pageIndex' => $page,
  230. 'pageSize' => $pageSize,
  231. 'pageTotal' => $returnData['total'],
  232. ];
  233. parent::sendOutput($returnData['data'], 0, $pageData);
  234. }
  235. parent::sendOutput($reportData->getData(), ErrorCode::$dberror);
  236. }
  237. /**
  238. * 商品分组列表
  239. */
  240. public function getAllGoodsGroups()
  241. {
  242. $params = $this->request->getRawJson();
  243. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  244. $selectParams['limit'] = $pageParams['limit'];
  245. $selectParams['offset'] = $pageParams['offset'];
  246. $selectParams['name'] = getArrayItem($params,'name',"");
  247. $result = $this->objMGoodsGroups->getAllGoodsGroups($selectParams);
  248. if (!$result->isSuccess()) {
  249. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  250. }
  251. $returnData = $result->getData();
  252. $pageData = [
  253. 'pageIndex' => $params['page'],
  254. 'pageSize' => $params['pageSize'],
  255. 'pageTotal' => $returnData['total'],
  256. ];
  257. parent::sendOutput($returnData['data'], 0, $pageData);
  258. }
  259. /**
  260. * 商品真实销量
  261. */
  262. public function getAllRealSalesNum()
  263. {
  264. $params = $this->request->getRawJson();
  265. $result = $this->objMGoods->getAllRealSalesNum($params);
  266. if (!$result->isSuccess()) {
  267. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  268. }else{
  269. $returnData = $result->getData();
  270. parent::sendOutput($returnData['data'], 0);
  271. }
  272. }
  273. }