ShippingAddress.Class.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /**
  3. * 客户收货地址管理Controller
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2019/10/31
  7. * Time: 11:30
  8. */
  9. namespace JinDouYun\Controller\Customer;
  10. use Exception;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\StatusCode;
  13. use JinDouYun\Controller\BaseController;
  14. use JinDouYun\Model\Customer\MShippingAddress;
  15. use JinDouYun\Model\Customer\MCustomer;
  16. class ShippingAddress extends BaseController
  17. {
  18. private $objMShippingAddress;
  19. private $objMCustomer;
  20. public function __construct($isCheckAcl = false, $isMustLogin = true)
  21. {
  22. parent::__construct($isCheckAcl, $isMustLogin);
  23. $this->objMShippingAddress = new MShippingAddress($this->onlineEnterpriseId);
  24. $this->objMCustomer = new MCustomer($this->onlineEnterpriseId, $this->onlineUserId);
  25. }
  26. /**
  27. * 获取参数
  28. *
  29. * @return array
  30. */
  31. public function commonFieldFilter()
  32. {
  33. $params = $this->request->getRawJson();
  34. if (empty($params)) {
  35. $this->sendOutput('参数为空', ErrorCode::$paramError);
  36. }
  37. $ShippingAddressData = [
  38. 'name' => isset($params['name']) ? $params['name'] : '',//客户收货姓名
  39. 'mobile' => isset($params['mobile']) ? $params['mobile'] : '',//客户收货手机号
  40. 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',//客户收货地址省份编码
  41. 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',//客户收货地址城市编码
  42. 'districtCode' => isset($params['districtCode']) ? $params['districtCode'] : '',//客户收货地址区县编码
  43. 'address' => isset($params['address']) ? $params['address'] : '',//详细收货地址
  44. ];
  45. //必填项
  46. foreach ($ShippingAddressData as $key => $value) {
  47. if (empty($value) && $value !== 0) {
  48. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  49. }
  50. }
  51. //选填项
  52. $ShippingAddressData['updateTime'] = time();
  53. $ShippingAddressData['deleteStatus'] = isset($params['deleteStatus']) ? $params['deleteStatus'] : StatusCode::$standard;
  54. $ShippingAddressData['defaultStatus'] = isset($params['defaultStatus']) ? $params['defaultStatus'] : StatusCode::$delete;
  55. $ShippingAddressData['customerId'] = isset($params['customerId']) ? $params['customerId'] : $this->objMCustomer->getCustomerIdByUserCenterId($this->onlineUserId);
  56. isset($params['customerId']) && $ShippingAddressData['extend'] = json_encode(['createType' => StatusCode::$roleType['admin']]);
  57. return $ShippingAddressData;
  58. }
  59. /**
  60. * 增
  61. */
  62. /**
  63. * 客户收货地址添加
  64. */
  65. public function addShippingAddress()
  66. {
  67. $addShippingAddressData = $this->commonFieldFilter();
  68. $result = $this->objMShippingAddress->addShippingAddress($addShippingAddressData);
  69. if ($result->isSuccess()) {
  70. parent::sendOutput($result->getData());
  71. } else {
  72. parent::sendOutput($result->getData(), $result->getErrorCode());
  73. }
  74. }
  75. /**
  76. * 删
  77. */
  78. /**
  79. * 客户收货地址删除
  80. * @throws Exception
  81. */
  82. public function deleteShippingAddress()
  83. {
  84. $id = $this->request->param('request_id');
  85. if (empty($id)) {
  86. $this->sendOutput('参数为空', ErrorCode::$paramError);
  87. }
  88. $params['id'] = $id;
  89. $result = $this->objMShippingAddress->deleteShippingAddress($params);
  90. if ($result->isSuccess()) {
  91. parent::sendOutput($result->getData());
  92. } else {
  93. parent::sendOutput($result->getData(), $result->getErrorCode());
  94. }
  95. }
  96. /**
  97. * 改
  98. */
  99. /**
  100. * 客户收货地址修改
  101. */
  102. public function updateShippingAddress()
  103. {
  104. $params['id'] = $this->request->param('request_id');
  105. if (empty($params)) {
  106. $this->sendOutput('参数为空', ErrorCode::$paramError);
  107. }
  108. $shippingAddressData = $this->commonFieldFilter();
  109. $result = $this->objMShippingAddress->updateShippingAddress($shippingAddressData, $params);
  110. if ($result->isSuccess()) {
  111. parent::sendOutput($result->getData());
  112. } else {
  113. parent::sendOutput($result->getData(), $result->getErrorCode());
  114. }
  115. }
  116. /**
  117. * 查
  118. */
  119. /**
  120. * 客户收货地址列表
  121. */
  122. public function getAllShippingAddress()
  123. {
  124. $id = $this->request->param('request_id');
  125. $params = $this->request->getRawJson();
  126. $page = isset($params['page']) ? $params['page']: 1;
  127. $pageSize = isset($params['pageSize']) ? $params['pageSize']: 10;
  128. $pageParams = pageToOffset($page, $pageSize);
  129. $selectParams['limit'] = $pageParams['limit'];
  130. $selectParams['offset'] = $pageParams['offset'];
  131. $selectParams['customerId'] = $id ? $id : $this->objMCustomer->getCustomerIdByUserCenterId($this->onlineUserId);
  132. $result = $this->objMShippingAddress->getAllShippingAddress($selectParams);
  133. if ($result->isSuccess()) {
  134. $returnData = $result->getData();
  135. $pageData = [
  136. 'pageIndex' => $page,
  137. 'pageSize' => $pageSize,
  138. 'pageTotal' => $returnData['total'],
  139. ];
  140. parent::sendOutput($returnData['data'], 0, $pageData);
  141. } else {
  142. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  143. }
  144. }
  145. /**
  146. * 客户收货地址详情
  147. */
  148. public function getShippingAddressInfo()
  149. {
  150. $id = $this->request->param('request_id');
  151. if (empty($id)) {
  152. $this->sendOutput('参数为空', ErrorCode::$paramError);
  153. }
  154. //自增id
  155. $selectParams['id'] = $id;
  156. $result = $this->objMShippingAddress->getShippingAddressInfo($selectParams);
  157. if ($result->isSuccess()) {
  158. parent::sendOutput($result->getData());
  159. } else {
  160. parent::sendOutput($result->getData(), $result->getErrorCode());
  161. }
  162. }
  163. }