MOrderProcess.Class.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * 订单相关处理方法
  4. */
  5. namespace JinDouYun\Model\Order;
  6. use Mall\Framework\Core\ResultWrapper;
  7. use Mall\Framework\Core\StatusCode;
  8. use Mall\Framework\Core\ErrorCode;
  9. use JinDouYun\Model\Customer\MCustomer;
  10. use JinDouYun\Model\Finance\MCustomerBalance;
  11. use JinDouYun\Model\Stock\MReservoirArea;
  12. use JinDouYun\Model\System\MDeliverySetting;
  13. use JinDouYun\Model\Customer\MShippingAddress;
  14. class MOrderProcess
  15. {
  16. private $onlineUserId;
  17. private $onlineEnterpriseId;
  18. public function __construct($onlineUserId, $onlineEnterpriseId)
  19. {
  20. $this->onlineUserId = $onlineUserId;
  21. $this->onlineEnterpriseId = $onlineEnterpriseId;
  22. }
  23. /**
  24. * 格式化订单关联数据
  25. * @param $common
  26. * @return ResultWrapper
  27. * @throws \Exception
  28. */
  29. public function formatCommonParams($common)
  30. {
  31. $objMCustomer = new MCustomer($this->onlineEnterpriseId, $this->onlineUserId);
  32. $objMCustomerBalance = new MCustomerBalance($this->onlineEnterpriseId, $this->onlineUserId);
  33. // 获取客户信息
  34. $customerData = $objMCustomer->getCustomerInfoByUserCenterId($common['userCenterId']);
  35. if (!$customerData->isSuccess()) {
  36. return ResultWrapper::fail($customerData->getData(), $customerData->getErrorCode());
  37. }
  38. $customerData = $customerData->getData();
  39. // 获取客户当前欠款
  40. $customerOwe = $objMCustomerBalance->getCustomerBalance($customerData['id']);
  41. $customerData['customerOwe'] = $customerOwe;
  42. unset($customerData['remark']);
  43. $common = array_merge($common, $customerData);
  44. if (isset($common['version']) && $common['version'] == 1){
  45. //多配送方式
  46. foreach ($common['proporties'] as $shopId => &$item){
  47. $deliveryResult = self::getObjectByDeliveryType($item);
  48. if (!$deliveryResult->isSuccess()){
  49. return ResultWrapper::fail($deliveryResult->getData(),$deliveryResult->getErrorCode());
  50. }
  51. $deliveryData = $deliveryResult->getData();
  52. $item['selfRuleData'] = getArrayItem($deliveryData,'selfRuleData',[]);
  53. $item['addressData'] = getArrayItem($deliveryData,'addressData',[]);
  54. }
  55. unset($item);
  56. }
  57. // 获取物流信息
  58. $deliveryResult = self::getObjectByDeliveryType($common);
  59. if (!$deliveryResult->isSuccess()){
  60. return ResultWrapper::fail($deliveryResult->getData(),$deliveryResult->getErrorCode());
  61. }
  62. $deliveryData = $deliveryResult->getData();
  63. $common['selfRuleData'] = getArrayItem($deliveryData,'selfRuleData',[]);
  64. $common['addressData'] = getArrayItem($deliveryData,'addressData',[]);
  65. // 根据客户的库位id获取库位信息
  66. $reservoir = [];
  67. $reservoirId = getArrayItem($customerData, 'reservoirId', 0);
  68. if (!empty($reservoirId)) {
  69. $objMReservoirArea = new MReservoirArea($this->onlineEnterpriseId, $this->onlineUserId);
  70. $reservoirResult = $objMReservoirArea->getReservoirInfo($reservoirId);
  71. if (!$reservoirResult->isSuccess()) {
  72. return ResultWrapper::fail($reservoirResult->getData(), $reservoirResult->getErrorCode());
  73. }
  74. $reservoir = $reservoirResult->getData();
  75. $reservoir = [
  76. 'name' => getArrayItem($reservoir, 'name', ''),
  77. 'warehouseId' => getArrayItem($reservoir, 'warehouseId', 0),
  78. 'code' => getArrayItem($reservoir, 'code', ''),
  79. 'type' => getArrayItem($reservoir, 'type', 0)
  80. ];
  81. }
  82. $common['reservoir'] = $reservoir;
  83. return ResultWrapper::success($common);
  84. }
  85. public function getObjectByDeliveryType(array $common): ResultWrapper
  86. {
  87. $objMDeliverySetting = new MDeliverySetting($this->onlineUserId, $this->onlineEnterpriseId);
  88. $selfRuleData = [];
  89. $addressData = [];
  90. switch ($common['deliveryType']) {
  91. case StatusCode::$deliveryType['selfMention']:
  92. if (isset($common['selfRuleId']) && !empty($common['selfRuleId'])) {
  93. $selfRuleDataResult = $objMDeliverySetting->getSelfRuleInfo($common['selfRuleId']);
  94. if (!$selfRuleDataResult->isSuccess()) {
  95. return ResultWrapper::fail($selfRuleDataResult->getData(), $selfRuleDataResult->getErrorCode());
  96. }
  97. $selfRuleData = $selfRuleDataResult->getData();
  98. $selfRuleData = isset($selfRuleData['setData']) ? $selfRuleData['setData'] : [];
  99. }
  100. break;
  101. case in_array( $common['deliveryType'],[StatusCode::$deliveryType['goodsDelivery'],StatusCode::$deliveryType['logistics']] ):
  102. if (isset($common['addressId']) && !empty($common['addressId'])){
  103. $common['receiveAddressId'] = $common['addressId'];
  104. }
  105. if (isset($common['receiveAddressId']) && !empty($common['receiveAddressId'])) {
  106. $objMShippingAddress = new MShippingAddress($this->onlineEnterpriseId);
  107. $result = $objMShippingAddress->getShippingAddressInfo($common['receiveAddressId']);
  108. if (!$result->isSuccess()) {
  109. return ResultWrapper::fail($result->getData(), ErrorCode::$dberror);
  110. }
  111. $addressData = $result->getData();
  112. if (empty($addressData)) {
  113. return ResultWrapper::fail('收货地址信息不存在', ErrorCode::$dberror);
  114. }
  115. }
  116. break;
  117. }
  118. return ResultWrapper::success([
  119. 'selfRuleData' => $selfRuleData,
  120. 'addressData' => $addressData
  121. ]);
  122. }
  123. }