objMCustomerTypePriceAdjustment = new MCustomerTypePriceAdjustment($this->onlineUserId, $this->onlineEnterpriseId); } /** * 公共接收参数方法 * @return mixed */ public function commonParams() { $params = $this->request->getRawJson(); if (empty($params)) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $sheetData = []; foreach ($params as $key => $value) { $sheetData[$key] = [ 'createUserId' => $this->onlineUserId, 'createUserName' => isset($value['createUserName']) ? $value['createUserName'] : '', 'goodsName' => isset($value['goodsName']) ? $value['goodsName'] : '', 'goodsId' => isset($value['goodsId']) ? $value['goodsId'] : '', 'shopId' => isset($value['shopId']) ? $value['shopId'] : '', 'shopName' => isset($value['shopName']) ? $value['shopName'] : '', 'salePrice' => isset($value['salePrice']) ? $value['salePrice'] : '', 'createTime' => time(), 'updateTime' => time(), 'deleteStatus' => StatusCode::$standard, 'effectiveStatus' => StatusCode::$auditStatus['auditing'], 'customerName' => isset($value['customerName']) ? $value['customerName'] : '', 'customerType' => isset($value['customerType']) ? $value['customerType'] : '', ]; foreach ($sheetData[$key] as $k => $v) { if (empty($v) && $v !== 0) { $this->sendOutput($k . '参数错误', ErrorCode::$paramError); } } $sheetData[$key]['createTime'] = time(); $sheetData[$key]['updateTime'] = time(); $sheetData[$key]['startTime'] = isset($value['startTime']) ? $value['startTime'] : ''; $sheetData[$key]['endTime'] = isset($value['endTime']) ? $value['endTime'] : ''; $sheetData[$key]['goodsCode'] = createCode(StatusCode::$code['goodsBasic']['prefix'], $sheetData[$key]['goodsId'], StatusCode::$code['goodsBasic']['length']); $sheetData[$key]['salePrice'] = json_encode($sheetData[$key]['salePrice']); $sheetData[$key]['effective'] = getArrayItem($value,'effective',StatusCode::$delete); } return $sheetData; } /** * 新增客户调价单 * * @throws \Exception */ public function add() { $sheetData = self::commonParams(); $result = $this->objMCustomerTypePriceAdjustment->add($sheetData); if ($result->isSuccess()) { //调价单生效操作 $sheetIds = $result->getData(); foreach ($sheetIds as $key => $id){ $row = getArrayItem($sheetData,$key,[]); if($row['effective'] == StatusCode::$standard){ $effectiveResult = $this->objMCustomerTypePriceAdjustment->effective($id,$row); if (!$effectiveResult->isSuccess()){ parent::sendOutput($effectiveResult->getData()); } } } parent::sendOutput($result->getData()); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 类型调价单列表 */ public function getAll() { $params['page'] = $this->request->param('page') ?: 1; $params['pageSize'] = $this->request->param('pageSize') ?: 10; $params['startTime'] = $this->request->param('startTime'); $params['endTime'] = $this->request->param('endTime'); $params['effectiveStatus'] = $this->request->param('effectiveStatus'); $params['keyword'] = $this->request->param('keyword'); $params['goodsId'] = $this->request->param('goodsId'); $export = $this->request->param('export'); if (isset($this->shopId) && !empty($this->shopId)) $params['shopId'] = $this->shopId; $result = $this->objMCustomerTypePriceAdjustment->getAll($params,$export); 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()); } } /** * 生效操作 * @throws \Exception */ public function effective() { $id = $this->request->param('request_id'); if (!$id) { parent::sendOutput('请指定要生效的数据id', ErrorCode::$paramError); } $paramsData = $this->request->getRawJson(); $params = [ 'createTime' => isset($paramsData['createTime']) ? $paramsData['createTime'] : '', 'effectiveUserName' => isset($paramsData['effectiveUserName']) ? $paramsData['effectiveUserName'] : '', 'effectiveUserId' => $this->onlineUserId, ]; foreach ($params as $k => $v) { if (empty($v) && $v !== 0) { $this->sendOutput($k . '参数错误', ErrorCode::$paramError); } } $result = $this->objMCustomerTypePriceAdjustment->effective($id, $params); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 获取指定商品的最后生效的客户类型调价数据 */ public function getCustomerTypePriceByGoodsIds() { $params['page'] = $this->request->param('page') ?: 1; $params['pageSize'] = $this->request->param('pageSize') ?: 10; $params['goodsId'] = $this->request->param('goodsId'); $result = $this->objMCustomerTypePriceAdjustment->getCustomerTypePriceByGoodsIds($params); 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 delCustomerTypePrice() { $paramsDate = $this->request->getRawJson(); $params['id'] = $paramsDate['id']; $params['skuId'] = $paramsDate['skuId']; foreach ($params as $k => $v) { if (empty($v) && $v !== 0) { $this->sendOutput($k . '参数错误', ErrorCode::$paramError); } } $result = $this->objMCustomerTypePriceAdjustment->delCustomerTypePrice($params); if($result->isSuccess()){ parent::sendOutput($result->getData()); }else{ parent::sendOutput($result->getData(), $result->getErrorCode()); } } }