mall_id, AddonsEnum::ADDONS_NAME_VALET_ORDER)) { $config = \Yii::$app->services->setting->addons->get($form->mall_id, AddonsEnum::ADDONS_NAME_VALET_ORDER, 'basic'); if (!empty($config['is_enable']) && !empty($config['is_enable_sms_code']) && !empty($form->data['extra_info']['valet_order']['mobile'])) { if (empty($form->data['captcha'])) throw new \Exception('短信验证码不能为空'); if (YII_ENV == 'prod') { // 短信验证码 if (!Sms::checkValidateCode($form->data['extra_info']['valet_order']['mobile'], $form->data['captcha'], ValetOrderEnum::SMS_TYPE)) throw new \Exception('验证码不正确'); } } // TODO 这个参数不为空,就是代客下单? // 如果后台开启了限制同个团队购买,并且这个用户绑定了上级(没有绑定的则会绑定到自身,则不需要验证) if (!empty($config['is_enable']) && !empty($form->data['extra_info']['valet_order']['mobile'])) { // 判断这个会员的等级是否能代下单 if (!(new SettingService())->getIsShowValetOrderBtn($form->mall_id, $form->user->level, $config)) { throw new \Exception('当前用户不允许代下单'); } // 验证新会员手机号不能填自己 if ($form->data['extra_info']['valet_order']['mobile'] == $form->user->mobile) { throw new \Exception('不允许为自己代下单'); } // 两个手机号相同 if ($form->data['extra_info']['valet_order']['mobile'] == ($form->data['extra_info']['valet_order']['parent'] ?? '')) { throw new \Exception('新会员手机号和直属老师手机号不能相同'); } // 代客下单不能下自提订单 if (isset($form->data['shipping_type']) && $form->data['shipping_type'] == 2) { throw new \Exception('站点自提不支持代客下单'); } if (!empty($config['is_limit_same_team'])) { // 根据手机号查询出用户id $userInfoByMobile = User::find() ->where([ 'mobile' => $form->data['extra_info']['valet_order']['mobile'], 'mall_id' => $form->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED] ]) ->select('id, parent_id') ->one(); $parent = $form->data['extra_info']['valet_order']['parent'] ?? ''; // 因为是限制了同一团队,所以手机号只能填帮代下单的手机号,只能成为他的下级 if ($parent && $form->user->mobile != $parent) { throw new \Exception('直属老师手机号只能是下单用户的手机号!'); } if ($userInfoByMobile) { switch ($config['is_limit_same_team']) { case 1: // 同团队 if ( $userInfoByMobile->parent_id && !UserPartitionRelationship::isMyTeam($form->user_id, $userInfoByMobile->id) ) { throw new \Exception('代客下单用户不在您的团队,不允许下单'); } break; case 2: // 仅限下级 if ($userInfoByMobile->parent_id) { if ($userInfoByMobile->parent_id != $form->user_id) { throw new \Exception('只允许给直推下级代下单'); } } else { if (UserPartitionRelationship::isMyTeam($form->user_id, $userInfoByMobile->id)) { throw new \Exception('只允许给直推下级代下单'); } } break; } } } } } } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } }