objMShippingAddress = new MShippingAddress($this->onlineEnterpriseId); $this->objMCustomer = new MCustomer($this->onlineEnterpriseId, $this->onlineUserId); } /** * 获取参数 * * @return array */ public function commonFieldFilter() { $params = $this->request->getRawJson(); if (empty($params)) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $ShippingAddressData = [ 'name' => isset($params['name']) ? $params['name'] : '',//客户收货姓名 'mobile' => isset($params['mobile']) ? $params['mobile'] : '',//客户收货手机号 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',//客户收货地址省份编码 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',//客户收货地址城市编码 'districtCode' => isset($params['districtCode']) ? $params['districtCode'] : '',//客户收货地址区县编码 'address' => isset($params['address']) ? $params['address'] : '',//详细收货地址 ]; //必填项 foreach ($ShippingAddressData as $key => $value) { if (empty($value) && $value !== 0) { $this->sendOutput($key . '参数错误', ErrorCode::$paramError); } } //选填项 $ShippingAddressData['updateTime'] = time(); $ShippingAddressData['deleteStatus'] = isset($params['deleteStatus']) ? $params['deleteStatus'] : StatusCode::$standard; $ShippingAddressData['defaultStatus'] = isset($params['defaultStatus']) ? $params['defaultStatus'] : StatusCode::$delete; $ShippingAddressData['customerId'] = isset($params['customerId']) ? $params['customerId'] : $this->objMCustomer->getCustomerIdByUserCenterId($this->onlineUserId); isset($params['customerId']) && $ShippingAddressData['extend'] = json_encode(['createType' => StatusCode::$roleType['admin']]); return $ShippingAddressData; } /** * 增 */ /** * 客户收货地址添加 */ public function addShippingAddress() { $addShippingAddressData = $this->commonFieldFilter(); $result = $this->objMShippingAddress->addShippingAddress($addShippingAddressData); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 删 */ /** * 客户收货地址删除 * @throws Exception */ public function deleteShippingAddress() { $id = $this->request->param('request_id'); if (empty($id)) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $params['id'] = $id; $result = $this->objMShippingAddress->deleteShippingAddress($params); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 改 */ /** * 客户收货地址修改 */ public function updateShippingAddress() { $params['id'] = $this->request->param('request_id'); if (empty($params)) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $shippingAddressData = $this->commonFieldFilter(); $result = $this->objMShippingAddress->updateShippingAddress($shippingAddressData, $params); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 查 */ /** * 客户收货地址列表 */ public function getAllShippingAddress() { $id = $this->request->param('request_id'); $params = $this->request->getRawJson(); $page = isset($params['page']) ? $params['page']: 1; $pageSize = isset($params['pageSize']) ? $params['pageSize']: 10; $pageParams = pageToOffset($page, $pageSize); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; $selectParams['customerId'] = $id ? $id : $this->objMCustomer->getCustomerIdByUserCenterId($this->onlineUserId); $result = $this->objMShippingAddress->getAllShippingAddress($selectParams); if ($result->isSuccess()) { $returnData = $result->getData(); $pageData = [ 'pageIndex' => $page, 'pageSize' => $pageSize, 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } else { parent::sendOutput($result->getData(), ErrorCode::$dberror); } } /** * 客户收货地址详情 */ public function getShippingAddressInfo() { $id = $this->request->param('request_id'); if (empty($id)) { $this->sendOutput('参数为空', ErrorCode::$paramError); } //自增id $selectParams['id'] = $id; $result = $this->objMShippingAddress->getShippingAddressInfo($selectParams); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } }