PsMethodController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace mall\controllers;
  3. use bizHd\order\classes\PsMethodClass;
  4. use common\components\util;
  5. use Yii;
  6. /**
  7. * 商城端配送方式接口(xhPsMethod / xhPsExplain)
  8. * 用途:混合结算页展示各购买方式对应的配送说明;预览未达门槛附加费(与下单 calcFee 同源)
  9. */
  10. class PsMethodController extends BaseController
  11. {
  12. /**
  13. * 获取门店全部配送方式及说明项
  14. * 可选 GET:itemTotalAmount、bigNum — 一并返回各 style 附加费预览(进页一次算好)
  15. */
  16. public function actionGetAllMethod()
  17. {
  18. if (empty($this->shopId) || empty($this->mainId)) {
  19. util::fail('门店信息无效');
  20. }
  21. try {
  22. $configs = PsMethodClass::getAllConfigs($this->shopId, $this->mainId);
  23. $customInfo = PsMethodClass::buildCustomInfo($this->hd ?? null, $this->custom ?? null);
  24. $configs = PsMethodClass::applyCustomHomeRuleToConfigs($configs, $customInfo);
  25. $configs = PsMethodClass::applyDailyFeeLockFlags($configs, (int)($this->customId ?? 0));
  26. $result = ['method' => $configs];
  27. $itemTotalAmount = Yii::$app->request->get('itemTotalAmount');
  28. $bigNum = Yii::$app->request->get('bigNum');
  29. if ($itemTotalAmount !== null && $itemTotalAmount !== '' && $bigNum !== null && $bigNum !== '') {
  30. $result['fees'] = PsMethodClass::previewMixUnMeetFeeBatch(
  31. $this->shopId,
  32. $this->mainId,
  33. (float)$itemTotalAmount,
  34. (float)$bigNum,
  35. (int)($this->customId ?? 0),
  36. $this->hd ?? null,
  37. $this->custom ?? null
  38. );
  39. }
  40. util::success($result);
  41. } catch (\Exception $e) {
  42. util::fail($e->getMessage());
  43. }
  44. }
  45. /**
  46. * 混合结算页批量预览未达门槛附加费(商品金额/扎数变化时刷新,切换购买方式不再重复请求)
  47. * POST: itemTotalAmount, bigNum
  48. */
  49. public function actionCalcMixFeeBatch()
  50. {
  51. if (empty($this->shopId) || empty($this->mainId)) {
  52. util::fail('门店信息无效');
  53. }
  54. $itemTotalAmount = (float)Yii::$app->request->post('itemTotalAmount', 0);
  55. $bigNum = (float)Yii::$app->request->post('bigNum', 0);
  56. try {
  57. $fees = PsMethodClass::previewMixUnMeetFeeBatch(
  58. $this->shopId,
  59. $this->mainId,
  60. $itemTotalAmount,
  61. $bigNum,
  62. (int)($this->customId ?? 0),
  63. $this->hd ?? null,
  64. $this->custom ?? null
  65. );
  66. util::success(['fees' => $fees]);
  67. } catch (\Exception $e) {
  68. util::fail($e->getMessage());
  69. }
  70. }
  71. /**
  72. * 单购买方式预览(保留兼容)
  73. * POST: sendType, itemTotalAmount, bigNum
  74. */
  75. public function actionCalcMixFee()
  76. {
  77. if (empty($this->shopId) || empty($this->mainId)) {
  78. util::fail('门店信息无效');
  79. }
  80. $sendType = (int)Yii::$app->request->post('sendType', -1);
  81. if ($sendType < 0 || $sendType > 4) {
  82. util::fail('配送方式无效');
  83. }
  84. $itemTotalAmount = (float)Yii::$app->request->post('itemTotalAmount', 0);
  85. $bigNum = (float)Yii::$app->request->post('bigNum', 0);
  86. $customInfo = PsMethodClass::buildCustomInfo($this->hd ?? null, $this->custom ?? null);
  87. $customId = (int)($this->customId ?? 0);
  88. try {
  89. $result = PsMethodClass::previewMixUnMeetFee(
  90. $this->shopId,
  91. $this->mainId,
  92. $sendType,
  93. $itemTotalAmount,
  94. $bigNum,
  95. $customId,
  96. $customInfo
  97. );
  98. util::success($result);
  99. } catch (\Exception $e) {
  100. util::fail($e->getMessage());
  101. }
  102. }
  103. }