objMGoods = new MGoods($this->onlineEnterpriseId, false, $this->onlineUserId); } /** * 添加和编辑商品管理公共字段处理方法 * * @return array */ public function commonFieldFilter() { $params = $this->request->getRawJson(); if (empty($params)) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $goodsData = [ 'basicGoodsId' => isset($params['goodsBasicId']) ? $params['goodsBasicId'] : '',//基本资料id 'goodsName' => isset($params['goodsName']) ? $params['goodsName'] : '',//基本资料商品名称 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',//商铺id 'shopName' => isset($params['shopName']) ? $params['shopName'] : '',//商铺名称 'images' => isset($params['images']) ? json_encode($params['images']) : '', 'specType' => isset($params['specType']) ? $params['specType'] : null,//规格类型 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$delete, //'serviceInfo' => isset($params['serviceInfo']) ? $params['serviceInfo'] : '', 'priceData' => isset($params['price']) ? $params['price'] : '',//接json值 //'specification' => isset($params['specification']) ? json_encode($params['specification']) : '',//接json值 'createUserName' => isset($params['createUserName']) ? $params['createUserName'] : '',//添加商品人名称 ]; foreach ($goodsData as $key => $value) { if (empty($value) && $value !== 0) { parent::sendOutput($key . '参数错误', ErrorCode::$paramError); } } isset($params['deliverySupIds']) && $goodsData['deliverySupIds'] = $params['deliverySupIds']; isset($params['expressType']) && $goodsData['expressType'] = $params['expressType']; isset($params['ruleId']) && $goodsData['ruleId'] = $params['ruleId']; isset($params['expressFee']) && $goodsData['expressFee'] = $params['expressFee']; isset($params['showExpress']) && $goodsData['showExpress'] = $params['showExpress']; $goodsData['content'] = isset($params['content']) ? $params['content'] : ''; $goodsData['isRecommend'] = isset($params['isRecommend']) ? $params['isRecommend'] : StatusCode::$standard; $goodsData['createTime'] = time(); $goodsData['updateTime'] = time(); $goodsData['deleteStatus'] = StatusCode::$standard; $goodsData['sort'] = isset($params['sort']) ? $params['sort'] : 0; $goodsData['isShield'] = getArrayItem($params,'isShield',StatusCode::$delete); $goodsData['notArea'] = json_encode(getArrayItem($params,'notArea',null)); $goodsData['notCustomerType'] = getArrayItem($params,'notCustomerType',''); $goodsData['notCustomer'] = getArrayItem($params,'notCustomer',''); $goodsData['isDistribution'] = getArrayItem($params,'isDistribution',StatusCode::$delete); $goodsData['support'] = getArrayItem($params,'support',[]); $goodsData['support'] = implode(',',$goodsData['support'] ); $goodsData['goodsGroups'] = getArrayItem($params,'goodsGroups');//商品分组 $goodsData['showMinUnitPrice'] = getArrayItem($params,'showMinUnitPrice',4);//属性最小单位价格是否展示 默认 4 不展示 if ( !empty($goodsData['goodsGroups']) ){ $goodsData['goodsGroups'] = implode(',', $goodsData['goodsGroups']); } return $goodsData; } /** * 添加商品 * @throws \Exception */ public function addGoods() { $goodsData = $this->commonFieldFilter(); $result = $this->objMGoods->addGoods($goodsData); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * @throws \Exception */ public function getGoodsInfo() { $goodsId = $this->request->param('request_id'); if (!$goodsId) { $this->sendOutput('参数错误', ErrorCode::$paramError); } $params = $this->request->getRawJson(); $userCenterId = 0; if (isset($params['userCenterId']) && !empty($params['userCenterId'])) { //后台选择了客户 $this->objMGoods = new MGoods($this->onlineEnterpriseId, false, $params['userCenterId']); $userCenterId = $params['userCenterId']; } $result = $this->objMGoods->getGoodsInfo($goodsId,$userCenterId); if ($result->isSuccess()) { $resultData = $result->getData(); $this->sendOutput($resultData); } $this->sendOutput($result->getData(), $result->getErrorCode()); } /** * 更新商品上下架 * @throws \Exception */ public function updateEnableStatus() { $params = $this->request->getRawJson(); if (empty($params['id']) && empty($params['enableStatus'])) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $result = $this->objMGoods->updateEnableStatus($params); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 编辑商品 */ public function editGoods() { $goodsId = $this->request->param('request_id'); if (empty($goodsId)) { $this->sendOutput('参数错误', ErrorCode::$paramError); } $goodsData = $this->commonFieldFilter(); $goodsData['id'] = $goodsId; unset($goodsData['createTime']); $result = $this->objMGoods->editGoods($goodsData); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * Doc: (des="审核商品") * User: XMing * Date: 2020/12/7 * Time: 11:31 上午 */ public function audit() { $goodsId = $this->request->param('request_id'); if (empty($goodsId)) { $this->sendOutput('参数错误', ErrorCode::$paramError); } $result = $this->objMGoods->audit($goodsId); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 删除商品 */ public function delGoods() { $goodsId = $this->request->param('request_id'); if (!$goodsId) { $this->sendOutput('参数错误', ErrorCode::$paramError); } $result = $this->objMGoods->delGoods($goodsId); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 后台所有商品列表 * @throws \Exception */ public function getAllGoods() { $params = $this->request->getRawJson(); if (empty($params)) { $this->sendOutput('参数为空', ErrorCode::$paramError); } if (isset($this->shopId) && !empty($this->shopId)) { $selectParams['shopId'] = $this->shopId; } if (isset($params['shopId']) && !empty($params['shopId'])) { $selectParams['shopId'] = $params['shopId']; } if (isset($params['isOption']) && !empty($params['isOption'])){ $selectParams['isOption'] = $params['isOption']; } //ifMerchant (4 采购单 5商户入库单) if( isset($params['ifMerchant']) && !empty($params['ifMerchant']) ){ $selectParams['ifMerchant'] = $params['ifMerchant']; } if( isset($params['merchantId']) && !empty($params['merchantId']) ){ $selectParams['merchantId'] = $params['merchantId']; } //销售中 页面显示有库存,已上架,的商品。 if (isset($params['inSales']) && !empty($params['inSales'])) { $selectParams['enableStatus'] = StatusCode::$standard; $selectParams['inStock'] = StatusCode::$standard; } //有无库存 inStock 5仓库中 4已售空 if (isset($params['inStock']) && !empty($params['inStock'])) { if ($params['inStock'] == StatusCode::$standard) { //仓库中:有库存,未上架的商品列表 $selectParams['enableStatus'] = StatusCode::$delete; $selectParams['inStock'] = $params['inStock']; } else { //已售罄:库存为0,自动下架的商品列表 $selectParams['inStock'] = $params['inStock']; } } // 分页 $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; if (isset($params['enableStatus'])) { $selectParams['enableStatus'] = $params['enableStatus']; } // 导出 $is_export = false; if (isset($params['export']) && $params['export'] == 1) $is_export = true; $selectParams['auditStatus'] = StatusCode::$auditStatus['auditPass']; if (isset($params['auditStatus']) && !empty($params['auditStatus'])){ $selectParams['auditStatus'] = $params['auditStatus']; } $selectParams['supplierId'] = $this->supplierId; $result = $this->objMGoods->getAllGoods($selectParams, '*', 'topTime desc, sort desc,createTime desc', $is_export); 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 getAllGoodsList() { $paramsData = $this->request->getRawJson(); $params = [ 'pageSize' => isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10, 'page' => isset($paramsData['page']) ? $paramsData['page'] : 1, ]; $offset = ($params['page'] - 1) * $params['pageSize']; $selectParams = [ 'limit' => $params['pageSize'], 'offset' => $offset, ]; foreach ($selectParams as $key => $value) { if (empty($value) && $value !== 0) { $this->sendOutput($key . '参数错误', ErrorCode::$paramError); } } // keywordType 1全部商品 2(销售中 上架且有库存) 3(已售罄 上架无库存) 4(仓库中 下架) $selectParams['keywordType'] = getArrayItem($paramsData,'keywordType',1); $selectParams['keyword'] = getArrayItem($paramsData,'keyword'); // 商品名称或商品编码 $selectParams['categoryId'] = getArrayItem($paramsData,'categoryId'); // 商品分类 $selectParams['brandId'] = getArrayItem($paramsData,'brandId'); //商品品牌 $selectParams['enableStatus']= getArrayItem($paramsData,'enableStatus'); // 上下架(5上架 4下架) $selectParams['ifMerchant']= getArrayItem($paramsData,'ifMerchant'); //ifMerchant (4 采购单 5商户入库单) $selectParams['merchantId']= getArrayItem($paramsData,'merchantId'); // $export = getArrayItem($paramsData,'export',''); // 导出 if(isset($this->shopId) && !empty($this->shopId)){ $selectParams['shopId'] = $this->shopId ; }else{ $selectParams['shopId'] = getArrayItem($paramsData,'shopId',0); //销售店铺 } $selectParams['categoryPath']= getArrayItem($paramsData,'categoryPath'); $goodsData = $this->objMGoods->getAllGoodsList($selectParams,$export); if ($goodsData->isSuccess()) { $returnData = $goodsData->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } parent::sendOutput($goodsData->getData(), ErrorCode::$dberror); } /** * 格式化所有商品搜索条件 * @throws \Exception */ public function formatGoodsCondition() { $params = $this->request->param('request_id'); if (empty($params)) { parent::sendOutput('参数错误', ErrorCode::$paramError); } $result = $this->objMGoods->formatGoodsCondition($params); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), $result->getErrorCode()); } parent::sendOutput($result->getData()); } /** * 创建订单搜索商品 * @throws \Exception */ public function getGoodsByCondition() { $params = $this->request->getRawJson(); $type = isset($params['type']) ? $params['type'] : false; $data['condition'] = isset($params['condition']) ? trim($params['condition']) : ''; $data['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : 0; if (isset($this->shopId) && !empty($this->shopId)) $data['shopId'] = $this->shopId; $data['shopId'] = isset($params['shopId']) ? $params['shopId'] : []; $modelResult = $this->objMGoods->getGoodsByCondition($data, $type); if (!$modelResult->isSuccess()) { parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode()); } parent::sendOutput($modelResult->getData()); } /** * Doc: (des="es-商品搜索") * @example * 销售中 = 上架有库存 * 已售罄 = 上下架没库存的 * 仓库中 = 下架有库存 * User: XMing * Date: 2020/11/30 * Time: 10:43 上午 * @throws \Exception */ public function search() { $params = $this->request->getRawJson(); if (empty($params)) { parent::sendOutput('参数为空', ErrorCode::$paramError); } $selectParams = [ 'categoryPath' => isset($params['categoryPath']) ? $params['categoryPath'] : '', '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'] : '', ]; //销售中 页面显示有库存,已上架,的商品。 if (isset($params['inSales']) && !empty($params['inSales'])) { $selectParams['enableStatus'] = StatusCode::$standard; $selectParams['inStock'] = StatusCode::$standard; } //有无库存 inStock 5仓库中 4已售空 if (isset($params['inStock']) && !empty($params['inStock'])) { if ($params['inStock'] == StatusCode::$standard) { //仓库中:有库存,未上架的商品列表 $selectParams['enableStatus'] = StatusCode::$delete; $selectParams['inStock'] = $params['inStock']; } else { //已售罄:库存为0,自动下架的商品列表 $selectParams['inStock'] = $params['inStock']; } } if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId; $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; $is_export = false; if (isset($params['export']) && $params['export'] == 1) $is_export = true; $selectParams['auditStatus'] = StatusCode::$auditStatus['auditPass']; if (isset($params['auditStatus']) && !empty($params['auditStatus'])){ $selectParams['auditStatus'] = $params['auditStatus']; } //ifMerchant (4 采购单 5商户入库单) if( isset($params['ifMerchant']) && !empty($params['ifMerchant']) ){ $selectParams['ifMerchant'] = $params['ifMerchant']; } if( isset($params['merchantId']) && !empty($params['merchantId']) ){ $selectParams['merchantId'] = $params['merchantId']; } $result = $this->objMGoods->search($selectParams, $is_export); 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()); } //修补es数据 public function fixEsData() { $params = $this->request->getRawJson(); if (empty($params)) { $this->sendOutput('参数为空', ErrorCode::$paramError); } isset($params['id']) && $selectParams['id'] = $params['id']; $pageParams = pageToOffset(1, 4000); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; $this->objMGoods->fixEsData($selectParams); } /** * * @throws \Exception */ public function getGoodsByBarCode() { $params = $this->request->getRawJson(); if (empty($params['barCode'])) { $this->sendOutput('barCode参数为空', ErrorCode::$paramError); } $result = $this->objMGoods->getGoodsByBarCode($params['barCode']); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), $result->getErrorCode()); } parent::sendOutput($result->getData()); } /** * * @throws \Exception */ public function getAllGoodsBySku() { $params = $this->request->getRawJson(); if (empty($params)) { parent::sendOutput('参数为空', ErrorCode::$paramError); } $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10); $data['limit'] = $pageParams['limit']; $data['offset'] = $pageParams['offset']; $data['keyword'] = isset($params['keyword']) ? $params['keyword'] : ''; $data['shopId'] = isset($params['shopId']) ? $params['shopId'] : ''; $data['categoryId'] = isset($params['categoryId']) ? $params['categoryId'] : ''; $data['isRevealSku'] = getArrayItem($params,'isRevealSku',''); if (isset($this->shopId) && !empty($this->shopId)) $data['shopId'] = $this->shopId; $data['userCenterId'] = getArrayItem($params,'userCenterId',0); $result = $this->objMGoods->getAllGoodsBySku($data); if ($result->isSuccess()) { $returnData = $result->getData(); $pageData = [ 'pageIndex' => isset($params['page']) ? $params['page'] : 1, 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10, 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 获取所有sku */ public function getAllSku() { $params = $this->request->getRawJson(); $result = $this->objMGoods->getAllSku($params); if(!$result->isSuccess()){ parent::sendOutput($result->getData(),$result->getErrorCode()); } parent::sendOutput($result->getData()); } /** * Doc: (des="设置商品置顶/取消商品置顶") * User: XMing * Date: 2020/8/28 * Time: 11:04 上午 */ public function setTop() { $goodsId = $this->request->param('request_id'); if (empty($goodsId)) { parent::sendOutput('id参数错误', ErrorCode::$paramError); } $result = $this->objMGoods->setTop($goodsId); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), $result->getErrorCode()); } parent::sendOutput($result->getData()); } /** * Doc: (des="修改排序字段") */ public function setSort() { $params = $this->request->getRawJson(); $params['id'] = getArrayItem($params,'id'); $params['sort'] = getArrayItem($params,'sort',0); foreach ($params as $key => $value) { if (empty($value)) { parent::sendOutput($key . '参数错误', ErrorCode::$paramError); } } $result = $this->objMGoods->setSort($params); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), $result->getErrorCode()); } parent::sendOutput($result->getData()); } /** * Doc: (des="批量设置虚拟销量") * User: XMing * Date: 2020/9/3 * Time: 9:10 上午 * @throws \Exception */ public function setSalesNumBatch() { $params = $this->request->getRawJson(); $data = [ 'ids' => isset($params['ids']) ? $params['ids'] : null, 'minVal' => isset($params['minVal']) ? $params['minVal'] : null, 'maxVal' => isset($params['maxVal']) ? $params['maxVal'] : null, ]; foreach ($data as $key => $value) { if (empty($value) && $value != 0) { parent::sendOutput($key . '参数错误', ErrorCode::$paramError); } } if ($data['minVal'] > $data['maxVal']) { parent::sendOutput('阀值设置有误', ErrorCode::$paramError); } $result = $this->objMGoods->setSalesNumBatch($data); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), $result->getErrorCode()); } parent::sendOutput($result->getData()); } /** * Doc: (des="") * User: XMing * Date: 2020/9/10 * Time: 3:07 下午 */ public function batchGoodsExpress() { $params = $this->request->getRawJson(); $data = [ 'ids' => isset($params['ids']) ? $params['ids'] : null, 'expressType' => isset($params['expressType']) ? $params['expressType'] : null, ]; foreach ($data as $key => $value) { if (empty($value)) { parent::sendOutput($key . '参数错误', ErrorCode::$paramError); } } if ($data['expressType'] == StatusCode::$expressType['rule']) { if (!isset($params['ruleId']) || empty($params['ruleId'])) { parent::sendOutput('ruleId参数错误', ErrorCode::$paramError); } $data['ruleId'] = $params['ruleId']; } if ($data['expressType'] == StatusCode::$expressType['unify']) { if (!isset($params['expressFee']) || (empty($params['expressFee']) && $params['expressFee'] != 0)) { parent::sendOutput('expressFee参数错误', ErrorCode::$paramError); } $data['expressFee'] = $params['expressFee']; } $result = $this->objMGoods->batchGoodsExpress($data); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), $result->getErrorCode()); } parent::sendOutput($result->getData()); } /** * Doc: (des="批量设置运费") * User: XMing * Date: 2020/9/3 * Time: 10:41 上午 */ public function setSalesNum() { $params = $this->request->getRawJson(); $data = [ 'id' => isset($params['id']) ? $params['id'] : null, 'val' => isset($params['val']) ? $params['val'] : null, ]; foreach ($data as $key => $value) { if (empty($value) && $value != 0) { parent::sendOutput($key . '参数错误', ErrorCode::$paramError); } } if ($data['minVal'] > $data['maxVal']) { parent::sendOutput('阀值设置有误', ErrorCode::$paramError); } $result = $this->objMGoods->setSalesNum($data); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), $result->getErrorCode()); } parent::sendOutput($result->getData()); } /** * Doc: (des="根据基础物料id及店铺id,获取物料id对应商品id") * User: XMing * Date: 2020/12/25 * Time: 3:57 下午 */ public function getRelMap() { $params = $this->request->getRawJson(); $data = [ 'shopId' => getArrayItem($params,'shopId',null), 'materielIds' => getArrayItem($params,'materielIds',null), ]; foreach ($data as $key => $val){ if (is_null($val) || empty($val)) { parent::sendOutput($key . '参数错误', ErrorCode::$paramError); } } $result = $this->objMGoods->getRelMap($data); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), $result->getErrorCode()); } parent::sendOutput($result->getData()); } /** * Doc: (des="获取价格走势") * User: XMing * Date: 2021/3/10 * Time: 6:45 下午 * @throws \Exception */ public function getPriceTrend() { $goodsId = $this->request->param('request_id'); if (empty($goodsId)) { parent::sendOutput('goodsId参数错误', ErrorCode::$paramError); } $params = (array)$this->request->getRawJson(); $params['startTime'] = isset($params['startTime']) && !empty($params['startTime']) ? $params['startTime'] : strtotime(date('Y-m-d 00:00:00',strtotime('-10 day'))); $params['endTime'] = isset($params['endTime']) && !empty($params['endTime']) ? $params['endTime'] :strtotime(date('Y-m-d 00:00:00')); $params['type'] = getArrayItem($params,'type',StatusCode::$standard);//5销售价格 4采购价格 $result = $this->objMGoods->getPriceTrend($goodsId,$params); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), $result->getErrorCode()); } parent::sendOutput($result->getData()); } /** * Doc: (des="批量设置负库存销售") * User: XMing * Date: 2021/3/13 * Time: 10:11 上午 */ public function batchSetDistribution() { $params = $this->request->getRawJson(); $data = [ 'ids' => getArrayItem($params,'ids',null), 'isDistribution' => getArrayItem($params,'isDistribution',null), ]; foreach ($data as $key => $val){ if (is_null($val) || empty($val)) { parent::sendOutput($key . '参数错误', ErrorCode::$paramError); } } $result = $this->objMGoods->batchSetDistribution($data); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), $result->getErrorCode()); } parent::sendOutput($result->getData()); } }