123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- /**
- * 客户收货地址管理Controller
- * Created by PhpStorm.
- * User: 小威
- * Date: 2019/10/31
- * Time: 11:30
- */
- namespace JinDouYun\Controller\Customer;
- use Exception;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Customer\MShippingAddress;
- use JinDouYun\Model\Customer\MCustomer;
- class ShippingAddress extends BaseController
- {
- private $objMShippingAddress;
- private $objMCustomer;
- public function __construct($isCheckAcl = false, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->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());
- }
- }
- }
|