123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- <?php
- /**
- * 前台商品接口
- * Created by PhpStorm.
- * User: wxj
- * Date: 2019/11/15
- * Time: 9:37
- */
- namespace JinDouYun\Controller\Goods;
- use JinDouYun\Model\Goods\MGoodsGroups;
- use JinDouYun\Model\Goods\MGoodsSupport;
- use JinDouYun\Model\GoodsManage\MGoodsBrand;
- use Mall\Framework\Core\ErrorCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Goods\MGoods;
- use JinDouYun\Model\Goods\MGoodsCollect;
- use Mall\Framework\Core\StatusCode;
- /**
- * Class ApiGoods
- * @package JinDouYun\Controller\Goods
- */
- class ApiGoods extends BaseController
- {
- /**
- * @var MGoods
- */
- private $objMGoods;
- /**
- * @var MGoodsCollect
- */
- private $objMGoodsCollect;
- private $objMGoodsSupport;
- private $objMGoodsBrand;
- private $objMGoodsGroups;
- /**
- * ApiGoods constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- * @param bool $checkToken
- * @param bool $getAreaCode
- * @throws \Exception
- */
- public function __construct($isCheckAcl = false, $isMustLogin = false,$checkToken=true,$getAreaCode=true)
- {
- parent::__construct($isCheckAcl, $isMustLogin,$checkToken,$getAreaCode);
- $authorization = $this->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);
- }
- }
- }
|