| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace mall\controllers;
- use bizHd\order\classes\PsMethodClass;
- use common\components\util;
- use Yii;
- /**
- * 商城端配送方式接口(xhPsMethod / xhPsExplain)
- * 用途:混合结算页展示各购买方式对应的配送说明
- */
- class PsMethodController extends BaseController
- {
- /**
- * 获取门店全部配送方式及说明项
- */
- public function actionGetAllMethod()
- {
- if (empty($this->shopId) || empty($this->mainId)) {
- util::fail('门店信息无效');
- }
- try {
- $configs = PsMethodClass::getAllConfigs($this->shopId, $this->mainId);
- // 客户单独送货上门规则覆盖 style=0
- if (!empty($this->custom) || !empty($this->hd)) {
- $customInfo = [];
- if (!empty($this->hd)) {
- $customInfo = is_array($this->hd) ? $this->hd : $this->hd->toArray();
- }
- if (!empty($this->custom)) {
- $customInfo = array_merge($customInfo, is_array($this->custom) ? $this->custom : $this->custom->toArray());
- }
- foreach ($configs as &$config) {
- if ((int)($config['style'] ?? 0) === 0) {
- $config = PsMethodClass::applyCustomHomeRule($config, $customInfo);
- }
- }
- unset($config);
- }
- // 今日已对附加费做过决策时,前端不再展示门槛加收(每日每客户每购买方式只收一次;首单未收则当日不再收)
- $customId = (int)($this->customId ?? 0);
- if ($customId > 0) {
- foreach ($configs as &$config) {
- $style = (int)($config['style'] ?? 0);
- $unMeet = (int)($config['unMeet'] ?? 0);
- $hasSendDecision = PsMethodClass::hasSendFeeDecisionToday($customId, $style);
- $hasPackDecision = PsMethodClass::hasPackFeeDecisionToday($customId, $style);
- $config['todaySendFeeLocked'] = $hasSendDecision ? 1 : 0;
- $config['todayPackFeeLocked'] = $hasPackDecision ? 1 : 0;
- if ($unMeet === 0 && $hasSendDecision) {
- $config['minAmount'] = 0;
- $config['minNum'] = 0;
- $config['unMeetFee'] = 0;
- } elseif ($unMeet === 2 && $hasPackDecision) {
- $config['minAmount'] = 0;
- $config['minNum'] = 0;
- $config['unMeetFee'] = 0;
- }
- }
- unset($config);
- }
- util::success(['method' => $configs]);
- } catch (\Exception $e) {
- util::fail($e->getMessage());
- }
- }
- }
|