request->getServerParam('HTTP_AUTHORIZATION'); $isFront = true; if (!empty($authorization)) { self::getUserIdByAuthorization(); } $this->objMGoods = new MGoods($this->onlineEnterpriseId, $isFront, $this->onlineUserId); $this->objMGoodsCollect = new MGoodsCollect($this->onlineEnterpriseId, $this->onlineUserId); $this->objMGoodsSupport = new MGoodsSupport($this->onlineEnterpriseId, $this->onlineUserId); $this->objMGoodsBrand = new MGoodsBrand($this->onlineUserId, $this->onlineEnterpriseId); $this->objMGoodsGroups = new MGoodsGroups($this->onlineEnterpriseId, $this->onlineUserId); } /** * 前台获取商品列表 * @throws \Exception */ public function getGoodsByCategory() { $params = $this->request->getRawJson(); if( empty($params) ){ $this->sendOutput('参数为空', ErrorCode::$paramError ); } $selectParams = [ 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : '', 'keyword' => isset($params['keyword']) ? $params['keyword'] : '', 'brandId' => isset($params['brandId']) ? $params['brandId'] : [],//商品品牌 'sort' => isset($params['sort']) ? $params['sort'] : '', //销售排序 'priceSort' => isset($params['priceSort']) ? $params['priceSort'] : '', //价格排序 未完成 'support' => isset($params['support']) ? $params['support'] : [], //商品服务 'goodsGroups' => isset($params['goodsGroups']) ? $params['goodsGroups'] : '', //商品分组 'areaCode'=>$this->areaCode, 'enableStatus' => StatusCode::$standard, ]; $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; $selectParams['userCenterId'] = isset($params['userCenterId']) ? $params['userCenterId'] : $this->onlineUserId; if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId; $result = $this->objMGoods->search($selectParams); if($result->isSuccess()){ $returnData = $result->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * Doc: (des="商户详情页面 通过shopId获取商品") * User: XMing * Date: 2021/1/29 * Time: 10:33 上午 */ public function getMerchantGoodsByCategory() { $params = $this->request->getRawJson(); if( empty($params) ){ parent::sendOutput('参数为空', ErrorCode::$paramError ); } if(!isset($params['shopId']) || empty($params['shopId'])){ parent::sendOutput('shopId参数错误',ErrorCode::$paramError); } $selectParams = [ 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : '', 'keyword' => isset($params['keyword']) ? $params['keyword'] : '', 'areaCode'=>$this->areaCode, 'shopId' => $params['shopId'] ]; $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; $selectParams['userCenterId'] = isset($params['userCenterId']) ? $params['userCenterId'] : $this->onlineUserId; $result = $this->objMGoods->search($selectParams); if($result->isSuccess()){ $returnData = $result->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 商品详情 * @throws \Exception */ public function getGoodsDetail() { $goodsId = $this->request->param('request_id'); if ( !$goodsId ) { $this->sendOutput('参数错误', ErrorCode::$paramError ); } $result = $this->objMGoods->getApiGoodsInfo($goodsId, $this->areaCode); if($result->isSuccess()){ $resultData = $result->getData(); $this->sendOutput($resultData); } $this->sendOutput($result->getData(), $result->getErrorCode()); } /** * 收藏/取消收藏 * @throws \Exception */ public function collect() { $goodsId = $this->request->param('request_id'); if ( !$goodsId ) { $this->sendOutput('参数错误', ErrorCode::$paramError ); } $result = $this->objMGoodsCollect->addGoodsCollect($goodsId); if($result->isSuccess()){ $this->sendOutput($result->getData()); } $this->sendOutput($result->getData(), $result->getErrorCode()); } /** * 常购物请单 * @throws \Exception */ public function normalList() { $result = $this->objMGoodsCollect->normalList($this->areaCode); if($result->isSuccess()){ $this->sendOutput($result->getData()); } $this->sendOutput($result->getData(), $result->getErrorCode()); } /** * 小程序所有商品服务 */ public function getAllGoodsSupport() { $params = $this->request->getRawJson(); if(empty($params)){ $this->sendOutput('参数错误', ErrorCode::$paramError); } $params['servicesName'] = getArrayItem($params,'servicesName',''); $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $params['limit'] = $pageParams['limit']; $params['offset'] = $pageParams['offset']; $returnData = $this->objMGoodsSupport->getAllGoodsSupport($params); if ($returnData->isSuccess()) { $returnData = $returnData->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } else { parent::sendOutput($returnData->getData(), ErrorCode::$dberror); } } /** * 获取所有品牌 * @throws \Exception */ public function getAllBrand() { $page = $this->request->param('page') ? $this->request->param('page') : 1; $pageSize = $this->request->param('pageSize') ? $this->request->param('pageSize') : 10; $keyword = $this->request->param('keyword') ? $this->request->param('keyword') : ''; $categoryId = $this->request->param('categoryId') ? $this->request->param('categoryId') : ''; $offset = ($page - 1) * $pageSize; $selectParams = [ 'limit' => $pageSize, 'offset' => $offset, ]; if (!empty($keyword)) { $selectParams['keyword'] = $keyword; } if (!empty($categoryId)) { $selectParams['categoryId'] = $categoryId; } $reportData = $this->objMGoodsBrand->apiGetAllBrand($selectParams); // if (!empty($categoryId)){ // $reportData = $this->objMGoods->getAllBrandByCategory($categoryId); // } if ($reportData->isSuccess()) { $returnData = $reportData->getData(); $pageData = [ 'pageIndex' => $page, 'pageSize' => $pageSize, 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } parent::sendOutput($reportData->getData(), ErrorCode::$dberror); } /** * 商品分组列表 */ public function getAllGoodsGroups() { $params = $this->request->getRawJson(); $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; $selectParams['name'] = getArrayItem($params,'name',""); $result = $this->objMGoodsGroups->getAllGoodsGroups($selectParams); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), ErrorCode::$dberror); } $returnData = $result->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } /** * 商品真实销量 */ public function getAllRealSalesNum() { $params = $this->request->getRawJson(); $result = $this->objMGoods->getAllRealSalesNum($params); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), ErrorCode::$dberror); }else{ $returnData = $result->getData(); parent::sendOutput($returnData['data'], 0); } } }