PsMethodController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * 用途:混合结算页展示各购买方式对应的配送说明
  9. */
  10. class PsMethodController extends BaseController
  11. {
  12. /**
  13. * 获取门店全部配送方式及说明项
  14. */
  15. public function actionGetAllMethod()
  16. {
  17. if (empty($this->shopId) || empty($this->mainId)) {
  18. util::fail('门店信息无效');
  19. }
  20. try {
  21. $configs = PsMethodClass::getAllConfigs($this->shopId, $this->mainId);
  22. // 客户单独送货上门规则覆盖 style=0
  23. if (!empty($this->custom) || !empty($this->hd)) {
  24. $customInfo = [];
  25. if (!empty($this->hd)) {
  26. $customInfo = is_array($this->hd) ? $this->hd : $this->hd->toArray();
  27. }
  28. if (!empty($this->custom)) {
  29. $customInfo = array_merge($customInfo, is_array($this->custom) ? $this->custom : $this->custom->toArray());
  30. }
  31. foreach ($configs as &$config) {
  32. if ((int)($config['style'] ?? 0) === 0) {
  33. $config = PsMethodClass::applyCustomHomeRule($config, $customInfo);
  34. }
  35. }
  36. unset($config);
  37. }
  38. // 今日已对附加费做过决策时,前端不再展示门槛加收(每日每客户每购买方式只收一次;首单未收则当日不再收)
  39. $customId = (int)($this->customId ?? 0);
  40. if ($customId > 0) {
  41. foreach ($configs as &$config) {
  42. $style = (int)($config['style'] ?? 0);
  43. $unMeet = (int)($config['unMeet'] ?? 0);
  44. $hasSendDecision = PsMethodClass::hasSendFeeDecisionToday($customId, $style);
  45. $hasPackDecision = PsMethodClass::hasPackFeeDecisionToday($customId, $style);
  46. $config['todaySendFeeLocked'] = $hasSendDecision ? 1 : 0;
  47. $config['todayPackFeeLocked'] = $hasPackDecision ? 1 : 0;
  48. if ($unMeet === 0 && $hasSendDecision) {
  49. $config['minAmount'] = 0;
  50. $config['minNum'] = 0;
  51. $config['unMeetFee'] = 0;
  52. } elseif ($unMeet === 2 && $hasPackDecision) {
  53. $config['minAmount'] = 0;
  54. $config['minNum'] = 0;
  55. $config['unMeetFee'] = 0;
  56. }
  57. }
  58. unset($config);
  59. }
  60. util::success(['method' => $configs]);
  61. } catch (\Exception $e) {
  62. util::fail($e->getMessage());
  63. }
  64. }
  65. }