123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- <?php
- /**
- * 对外获取价格
- * Created by PhpStorm.
- * User: phperstar
- * Date: 2019/5/7
- * Time: 6:41 PM
- */
- namespace JinDouYun\Controller\Price;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Goods\MGoods;
- use Mall\Framework\Core\ErrorCode;
- use JinDouYun\Model\Price\MPrice;
- class Price extends BaseController
- {
- private $objMPrice;
- /**
- * Price constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- * @throws \Exception
- */
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMPrice = new MPrice($this->onlineUserId, $this->onlineEnterpriseId);
- }
- /**
- * 批量调价基于基本的运算公式进行调价,举例一个商品的销售价格是100元。通过批量调价,订货价=销售价-1,那么结果就是 98(订货价)=99(销售价 salePrice)-1(调价数字)
- * 一个商品多个规格,每个规格都按照此调价数字进行调价
- * @throws \Exception
- */
- public function batchPrice()
- {
- $paramsData = $this->request->getRawJson();
- $params = [
- 'rows' => isset($paramsData['rows']) ? $paramsData['rows'] : '',
- 'sales' => isset($paramsData['sales']) ? $paramsData['sales'] : '',
- 'ladder' => isset($paramsData['ladder']) ? $paramsData['ladder'] : '',
- ];
- foreach ($params as $k => $v) {
- if (empty($v) && $v !== 0) {
- parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- }
- $goodData = [];
- foreach ($paramsData['rows'] as $key => $val) {
- $goodData[$key] = [
- 'goodsId' => isset($val['goodsId']) ? $val['goodsId'] : '',
- 'shopId' => isset($val['shopId']) ? $val['shopId'] : '',
- ];
- foreach ($goodData[$key] as $k => $v) {
- if (empty($v) && $v !== 0) {
- parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- }
- }
- $params['rows'] = $goodData;
- if (!isset($params['sales']['adj']) || !isset($params['sales']['float'])) {
- parent::sendOutput('sales参数错误', ErrorCode::$paramError);
- }
- if (!isset($params['ladder']['adj']) || !isset($params['ladder']['float'])) {
- parent::sendOutput('ladder参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMPrice->batchPrice($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 根据用户定位批量获取指定物料价格
- * @throws \Exception
- */
- public function getPrice()
- {
- $paramsData = $this->request->getRawJson();
- $params = [
- 'material' => isset($paramsData['material']) ? $paramsData['material'] : '',
- 'province' => isset($paramsData['province']) ? $paramsData['province'] : '',
- 'city' => isset($paramsData['city']) ? $paramsData['city'] : '',
- 'district' => isset($paramsData['district']) ? $paramsData['district'] : '',
- ];
- foreach ($params as $k => $v) {
- if (empty($v) && $v !== 0) {
- $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- }
- $params['customerId'] = isset($paramsData['customerId']) ? $paramsData['customerId'] : '';
- $result = $this->objMPrice->getPrice($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * @throws \Exception
- */
- public function getAllGoodsPrice()
- {
- $params = $this->request->getRawJson();
- $paramsData = [
- 'page' => isset($params['page']) ? $params['page'] : 1,
- 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
- ];
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $pageParams = pageToOffset($paramsData['page'], $paramsData['pageSize']);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- if (isset($params['shopId']) && !empty($params['shopId'])) {
- $selectParams['shopId'] = $params['shopId'];
- }
- if (isset($params['merchantId']) && !empty($params['merchantId'])) {
- $selectParams['merchantId'] = $params['merchantId'];
- }
- if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId;
- $result = $this->objMPrice->getAllGoodsPrice($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $paramsData['page'],
- 'pageSize' => $paramsData['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- }
- /**
- * 价格管理搜索
- * @throws \Exception
- */
- public function search()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $selectParams = [
- 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : '',
- 'brandId' => isset($params['brandId']) ? $params['brandId'] : '',
- 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',
- 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',//销售状态
- 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
- ];
- $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId;
- $result = $this->objMPrice->search($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 价格表列表页
- */
- public function getAll()
- {
- $params = $this->request->getRawJson();
- $params = [
- 'regionalDepartmentId' => $params['regionalDepartmentId'],
- 'materialData' => $params['materialData'],
- 'shopId' => $params['shopId'],
- 'cargoOwnerType' => $params['cargoOwnerType'],
- 'cargoOwnerCode' => $params['cargoOwnerCode'],
- ];
- foreach ($params as $k => $v) {
- if (empty($v) && $v !== 0) {
- $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMPrice->getAll($params, $this->authorization);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- *
- */
- public function searchGoods()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $selectParams = [
- 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : '',
- 'brandId' => isset($params['brandId']) ? $params['brandId'] : '',
- 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',
- 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',//销售状态
- 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
- ];
- $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $result = $this->objMPrice->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());
- }
- /**
- * 获取指定店铺下指定物料的大区以及市价格(包含没有设置价格的区域)
- */
- public function getAreaPriceByMaterialCode()
- {
- $params = [
- 'marketCode' => $this->request->param('marketCode'),
- 'materialCode' => $this->request->param('materialCode'),
- 'shopId' => $this->request->param('shopId'),
- 'cargoOwnerCode' => $this->request->param('cargoOwnerCode'),
- 'weight' => $this->request->param('weight'),
- ];
- foreach ($params as $k => $v) {
- if (empty($v) && $v !== 0) {
- $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMPrice->getAreaPriceByMaterialCode($params, $this->authorization);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 获取指定店铺指定物料的设置过得全国销售价和库存数量
- */
- public function getNationalUnifiedPriceAndStock()
- {
- $params = [
- 'marketCode' => $this->request->param('marketCode'),
- 'materialCode' => $this->request->param('materialCode'),
- 'shopId' => $this->request->param('shopId'),
- 'cargoOwnerCode' => $this->request->param('cargoOwnerCode'),
- 'weight' => $this->request->param('weight'),
- ];
- foreach ($params as $k => $v) {
- if (empty($v) && $v !== 0) {
- $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMPrice->getNationalUnifiedPriceAndStock($params, $this->authorization);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 获取指定物料指定店铺当前设置过的所有区域价格(只返回设置过价格的区域)
- */
- public function getAreaPrice()
- {
- $params = [
- 'marketCode' => $this->request->param('marketCode'),
- 'materialCode' => $this->request->param('materialCode'),
- 'shopId' => $this->request->param('shopId'),
- ];
- foreach ($params as $k => $v) {
- if (empty($v) && $v !== 0) {
- $this->sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- }
- $newParams = [
- $params['shopId'] => [$params['marketCode']]
- ];
- $result = $this->objMPrice->getAllAreaPrice($newParams, $params);
- if ($result->isSuccess()) {
- $areaPice = $result->getData();
- $returnData = (isset($areaPice[$params['shopId']][$params['marketCode']]) && !empty($areaPice[$params['shopId']][$params['marketCode']])) ? $areaPice[$params['shopId']][$params['marketCode']] : (object)[];
- parent::sendOutput($returnData);
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- }
|