| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace mall\controllers;
- use bizHd\order\classes\PsMethodClass;
- use common\components\util;
- use Yii;
- /**
- * 商城端配送方式接口(xhPsMethod / xhPsExplain)
- * 用途:混合结算页展示各购买方式对应的配送说明;预览未达门槛附加费(与下单 calcFee 同源)
- */
- class PsMethodController extends BaseController
- {
- /**
- * 获取门店全部配送方式及说明项
- * 可选 GET:itemTotalAmount、bigNum — 一并返回各 style 附加费预览(进页一次算好)
- */
- public function actionGetAllMethod()
- {
- if (empty($this->shopId) || empty($this->mainId)) {
- util::fail('门店信息无效');
- }
- try {
- $configs = PsMethodClass::getAllConfigs($this->shopId, $this->mainId);
- $customInfo = PsMethodClass::buildCustomInfo($this->hd ?? null, $this->custom ?? null);
- $configs = PsMethodClass::applyCustomHomeRuleToConfigs($configs, $customInfo);
- $configs = PsMethodClass::applyDailyFeeLockFlags($configs, (int)($this->customId ?? 0));
- $result = ['method' => $configs];
- $itemTotalAmount = Yii::$app->request->get('itemTotalAmount');
- $bigNum = Yii::$app->request->get('bigNum');
- if ($itemTotalAmount !== null && $itemTotalAmount !== '' && $bigNum !== null && $bigNum !== '') {
- $result['fees'] = PsMethodClass::previewMixUnMeetFeeBatch(
- $this->shopId,
- $this->mainId,
- (float)$itemTotalAmount,
- (float)$bigNum,
- (int)($this->customId ?? 0),
- $this->hd ?? null,
- $this->custom ?? null
- );
- }
- util::success($result);
- } catch (\Exception $e) {
- util::fail($e->getMessage());
- }
- }
- /**
- * 混合结算页批量预览未达门槛附加费(商品金额/扎数变化时刷新,切换购买方式不再重复请求)
- * POST: itemTotalAmount, bigNum
- */
- public function actionCalcMixFeeBatch()
- {
- if (empty($this->shopId) || empty($this->mainId)) {
- util::fail('门店信息无效');
- }
- $itemTotalAmount = (float)Yii::$app->request->post('itemTotalAmount', 0);
- $bigNum = (float)Yii::$app->request->post('bigNum', 0);
- try {
- $fees = PsMethodClass::previewMixUnMeetFeeBatch(
- $this->shopId,
- $this->mainId,
- $itemTotalAmount,
- $bigNum,
- (int)($this->customId ?? 0),
- $this->hd ?? null,
- $this->custom ?? null
- );
- util::success(['fees' => $fees]);
- } catch (\Exception $e) {
- util::fail($e->getMessage());
- }
- }
- /**
- * 单购买方式预览(保留兼容)
- * POST: sendType, itemTotalAmount, bigNum
- */
- public function actionCalcMixFee()
- {
- if (empty($this->shopId) || empty($this->mainId)) {
- util::fail('门店信息无效');
- }
- $sendType = (int)Yii::$app->request->post('sendType', -1);
- if ($sendType < 0 || $sendType > 4) {
- util::fail('配送方式无效');
- }
- $itemTotalAmount = (float)Yii::$app->request->post('itemTotalAmount', 0);
- $bigNum = (float)Yii::$app->request->post('bigNum', 0);
- $customInfo = PsMethodClass::buildCustomInfo($this->hd ?? null, $this->custom ?? null);
- $customId = (int)($this->customId ?? 0);
- try {
- $result = PsMethodClass::previewMixUnMeetFee(
- $this->shopId,
- $this->mainId,
- $sendType,
- $itemTotalAmount,
- $bigNum,
- $customId,
- $customInfo
- );
- util::success($result);
- } catch (\Exception $e) {
- util::fail($e->getMessage());
- }
- }
- }
|