ApiDelivery.Class.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace JinDouYun\Controller\System;
  3. use JinDouYun\Controller\BaseController;
  4. use JinDouYun\Model\Customer\MCustomer;
  5. use JinDouYun\Model\Customer\MShippingAddress;
  6. use JinDouYun\Model\System\MDeliverySetting;
  7. use Mall\Framework\Core\ResultWrapper;
  8. use Mall\Framework\Core\StatusCode;
  9. /**
  10. * @copyright Copyright (c) https://www.qianniaovip.com All rights reserved
  11. * Description: 配送方式
  12. * Class ApiDelivery
  13. * @package JinDouYun\Controller\System
  14. */
  15. class ApiDelivery extends BaseController
  16. {
  17. private $objMDeliverySetting;
  18. /**
  19. * ApiDelivery constructor.
  20. * @param bool $isCheckAcl
  21. * @param bool $isMustLogin
  22. * @param bool $checkToken
  23. * @param bool $getAreaCode
  24. * @param bool $checkShopToken
  25. * @param bool $checkSupplierToken
  26. * @throws \Exception
  27. */
  28. public function __construct($isCheckAcl = true, $isMustLogin = true, $checkToken = true, $getAreaCode = true, $checkShopToken = true, $checkSupplierToken = true)
  29. {
  30. parent::__construct($isCheckAcl, $isMustLogin, $checkToken, $getAreaCode, $checkShopToken, $checkSupplierToken);
  31. $this->objMDeliverySetting = new MDeliverySetting($this->onlineUserId,$this->onlineEnterpriseId);
  32. }
  33. /**
  34. * Doc: (des="")
  35. * User: XMing
  36. * Date: 2021/2/3
  37. * Time: 4:47 下午
  38. * @throws \Exception
  39. */
  40. public function getDeliveryType()
  41. {
  42. $shopIds = $this->request->param('shopId');
  43. $map = [];
  44. $objMDeliverySetting = new MDeliverySetting($this->onlineUserId, $this->onlineEnterpriseId);
  45. $objMCustomer = new MCustomer($this->onlineEnterpriseId,$this->onlineUserId);
  46. $objMShippingAddress = new MShippingAddress($this->onlineEnterpriseId);
  47. $customerId = $objMCustomer->getCustomerIdByUserCenterId($this->onlineUserId);
  48. $addressResult = $objMShippingAddress->getAllShippingAddress(['limit' => 20,'offset' => 0,'customerId' => $customerId]);
  49. if (!$addressResult->isSuccess()){
  50. parent::sendOutput($addressResult->getData(), $addressResult->getErrorCode());
  51. }
  52. $addressLists = $addressResult->getData();
  53. foreach ($shopIds as $key => $shopId){
  54. $modelResult = $this->objMDeliverySetting->allDelivery($shopId);
  55. if (!$modelResult->isSuccess()) {
  56. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  57. }
  58. $results = $modelResult->getData()['data'];
  59. if (empty($results)){
  60. //此店铺没有配置
  61. $shopId = 0;
  62. $modelResult = $this->objMDeliverySetting->allDelivery($shopId);
  63. if (!$modelResult->isSuccess()) {
  64. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  65. }
  66. $results = $modelResult->getData()['data'];
  67. }
  68. foreach ($results as &$val){
  69. switch ($val['deliveryType']){
  70. case StatusCode::$deliveryType['goodsDelivery']:
  71. //商品配送
  72. $val['lists'] = $addressLists['data'];
  73. break;
  74. case StatusCode::$deliveryType['selfMention']:
  75. //上门自提
  76. $selfExpressRuleResult = $objMDeliverySetting->getAllSelfExpressRule($shopId);
  77. if (!$selfExpressRuleResult->isSuccess()) {
  78. return ResultWrapper::fail($selfExpressRuleResult->getData(), $selfExpressRuleResult->getErrorCode());
  79. }
  80. $val['lists'] = $selfExpressRuleResult->getData();
  81. break;
  82. }
  83. }
  84. $map[$shopIds[$key]] = $results;
  85. }
  86. parent::sendOutput($map);
  87. ; }
  88. /**
  89. * Doc: (des="")
  90. * User: XMing
  91. * Date: 2021/2/4
  92. * Time: 2:29 下午
  93. * @return ResultWrapper
  94. * @throws \Exception
  95. */
  96. public function getAllSelfExpressRule()
  97. {
  98. //获取自提点
  99. $objMDeliverySetting = new MDeliverySetting($this->onlineUserId, $this->onlineEnterpriseId);
  100. $shopIds = $this->request->param('shopId');
  101. $map = [];
  102. foreach ($shopIds as $shopId){
  103. $selfExpressRuleResult = $objMDeliverySetting->getAllSelfExpressRule($shopId);
  104. if (!$selfExpressRuleResult->isSuccess()) {
  105. return ResultWrapper::fail($selfExpressRuleResult->getData(), $selfExpressRuleResult->getErrorCode());
  106. }
  107. $selfExpressRule = $selfExpressRuleResult->getData();
  108. $map[$shopId] = $selfExpressRule;
  109. }
  110. parent::sendOutput($map);
  111. }
  112. }