| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace hd\controllers;
- use bizGhs\order\classes\ShMethodClass;
- use bizHd\ghs\classes\GhsClass;
- use Yii;
- use common\components\util;
- class ShMethodController extends BaseController
- {
- /**
- * 获取供货商所有的5种配送方式配置
- * 如果数据库里没有,则取默认配置进行初始化
- */
- public function actionGetAllMethod()
- {
- $ghsId = Yii::$app->request->get('ghsId', 0);
- $ghs = GhsClass::getById($ghsId);
- if (empty($ghs)) {
- util::fail('没有供货商信息');
- }
- if ($ghs['ownMainId'] != $this->mainId) {
- util::fail('不是你的供货商');
- }
- $shopId = $ghs['shopId'] ?? 0;
- $mainId = $ghs['mainId'] ?? 0;
- if (!in_array($shopId, [36523, 0])) {
- util::success([]);
- }
- try {
- $customId = $ghs['customId'] ?? 0;
- $configs = ShMethodClass::getAllConfigs($shopId, $mainId);
- if (isset($ghs['homeRule']) && $ghs['homeRule'] == 1) {
- foreach ($configs as &$config) {
- if ($config['style'] == 0) {
- $config['status'] = $ghs['home'] ?? 0;
- $config['minAmount'] = $ghs['homeAmount'] ?? 0;
- $config['minNum'] = $ghs['homeNum'] ?? 0;
- $config['unMeet'] = $ghs['homeUnMeet'] ?? 0;
- $config['unMeetFee'] = $ghs['homeUnFee'] ?? 0;
- }
- }
- }
- if ($customId > 0) {
- foreach ($configs as &$config) {
- $style = (int)($config['style'] ?? 0);
- $unMeet = (int)($config['unMeet'] ?? 0);
- // 针对每个配送方式分别检查是否已支付运费或包装费
- $hasPaidSendCost = ShMethodClass::isSendCostPaidToday($customId, $style);
- $hasPaidPackCost = ShMethodClass::isPackPaidToday($customId, $style);
- // 如果是加收运费、加收包装费或不能下单,并且今天已经成功下单/收取过费用
- // 则将前端展示的条件清空(设为0),从而不再显示要收附加费或限制下单的提示
- if (($unMeet === 0 && $hasPaidSendCost) || ($unMeet === 1 && $hasPaidPackCost) || ($unMeet === 2 && ($hasPaidSendCost || $hasPaidPackCost))) {
- $config['minAmount'] = 0;
- $config['minNum'] = 0;
- $config['unMeetFee'] = 0;
- }
- }
- }
- util::success(['method' => $configs]);
- } catch (\Exception $e) {
- util::fail($e->getMessage());
- }
- }
- }
|