| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace hd\controllers;
- use bizGhs\order\classes\ShMethodClass;
- use bizHd\ghs\classes\GhsClass;
- use Yii;
- use common\components\util;
- /**
- * 花店配送方式接口(供货商 xhSh* 表,供进货结算等场景)
- * 用途:门店向供货商下单时读取配送配置;设置页请走 PsMethodController
- */
- 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::isUnMeetSendFeeLocked($customId, $style, $config);
- $hasPaidPackCost = ShMethodClass::isUnMeetPackFeeLocked($customId, $style, $config);
- $hasOrderToday = ShMethodClass::isSendCostPaidToday($customId, $style)
- || ShMethodClass::isPackPaidToday($customId, $style);
- // 如果是加收运费、加收包装费或不能下单,并且锁定期内已收过/已下过单
- // 则将前端展示的条件清空(设为0),从而不再显示要收附加费或限制下单的提示
- if (($unMeet === 0 && $hasPaidSendCost) || ($unMeet === 1 && $hasPaidPackCost) || ($unMeet === 2 && $hasOrderToday)) {
- $config['minAmount'] = 0;
- $config['minNum'] = 0;
- $config['unMeetFee'] = 0;
- }
- }
- }
- util::success(['method' => $configs]);
- } catch (\Exception $e) {
- util::fail($e->getMessage());
- }
- }
- }
|