first(); if (!$orderSheet) { throw new BusinessException('订单数据异常'); } $goods = Goods::find($orderSheet->join_sheet_goods_id); // 自定义充值产品 if($goods->join_goods_category_id == 210){ return 0; } if (empty($goods->goods_attribute_json)) { throw new BusinessException('产品数据异常'); } $attributeJson = json_decode($goods->goods_attribute_json, true); if (!isset($attributeJson['added'])) { throw new BusinessException('产品数据异常'); } return $attributeJson['added']['nbr']; } /** * @Desc * @Author Gorden * @Date 2024/5/29 16:25 * * @param $memberId * @param $payAmount * @return false|mixed * @throws BusinessException */ public static function disposeRole($memberId, $payAmount) { $memberAccount = MemberAccount::where('member_account_classify', 'CASH') ->where('join_account_member_id', $memberId) ->first(); if (!$memberAccount) { throw new BusinessException('账户异常'); } $income = floatval($memberAccount->member_account_income); $expend = floatval($memberAccount->member_account_expen); $money = max($income, $expend); $memberRoles = MemberRole::where('member_role_status', 'ACTIVED')->get()->toArray(); foreach ($memberRoles as $role) { if ($money >= floatval($role['member_role_range_begin']) && $money < floatval($role['member_role_range_end'])) { return $role['member_role_id']; } } return false; } /** * @Desc * @Author Gorden * @Date 2024/5/28 18:03 * * @param $roleId * @param $memberId * @return void * @throws BusinessException */ public static function disposeAdded($roleId, $memberId) { $role = MemberRole::find($roleId); if (empty($role->member_role_rule_json)) { throw new BusinessException('增值套包数据异常'); } $ruleJson = json_decode($role->member_role_rule_json, true); if (!isset($ruleJson['added'])) { throw new BusinessException('增值套包数据异常'); } $addedId = $ruleJson['added']; $added = RuleAdded::find($addedId); if (!$added) { throw new BusinessException('增值套包数据异常'); } $diff = $added->rule_added_goods_diff; $components = RuleAddedComponent::where('join_component_rule_added_id', $addedId)->get()->toArray(); switch ($diff) { case "SUM": self::diffSum($memberId, $components); break; case "REPLACE": self::diffReplace($memberId, $components); break; case "NONE": self::diffNone($memberId, $components); } } /** * @Desc * @Author Gorden * @Date 2024/5/28 18:03 * * @param $memberId * @param $components * @return void */ public static function diffSum($memberId, $components) { foreach ($components as $component) { self::saveMemberQuota($memberId, $component); } } /** * @Desc * @Author Gorden * @Date 2024/5/28 18:02 * * @param $memberId * @param $components * @return void */ public static function diffReplace($memberId, $components) { foreach ($components as $component) { if (MemberQuota::where('join_quota_member_id', $memberId)->where('join_member_rule_added_component_id', $component['rule_added_component_id'])->exists()) { MemberQuota::where('join_quota_member_id', $memberId) ->where('join_member_rule_added_component_id', $component['rule_added_component_id']) ->where('member_quota_status', 'PENDING') ->delete(); } self::saveMemberQuota($memberId, $component); } } /** * @Desc * @Author Gorden * @Date 2024/5/28 18:02 * * @param $memberId * @param $components * @return void */ public static function diffNone($memberId, $components) { foreach ($components as $component) { if (MemberQuota::where('join_quota_member_id', $memberId)->where('join_member_rule_added_component_id', $component['rule_added_component_id'])->exists()) { continue; } self::saveMemberQuota($memberId, $component); } } /** * @Desc * @Author Gorden * @Date 2024/5/28 18:02 * * @param $memberId * @param $component * @return void */ private static function saveMemberQuota($memberId, $component) { if ($component['rule_added_component_classify'] == 'MONTH') { $total = 12 * intval($component['rule_added_component_goods_nbr']); for ($i = 0; $i < $total; $i++) { self::doSaveMemberQuota($memberId, $component, 1); } } elseif ($component['rule_added_component_classify'] == 'YEAR') { if ($component['rule_added_component_goods_nbr'] == "-99.00") { self::doSaveMemberQuota($memberId, $component, -99); } else { for ($i = 0; $i < intval($component['rule_added_component_goods_nbr']); $i++) { self::doSaveMemberQuota($memberId, $component, 1); } } } else { if ($component['rule_added_component_goods_nbr'] == "-99.00") { self::doSaveMemberQuota($memberId, $component, -99); } else { for ($i = 0; $i < intval($component['rule_added_component_goods_nbr']); $i++) { self::doSaveMemberQuota($memberId, $component, 1); } } } } private static function doSaveMemberQuota($memberId, $component, $nbr) { $model = new MemberQuota(); $model->member_quota_id = 'MQ' . date('YmdHis') . random_string(6, 'up'); $model->join_quota_member_id = $memberId; $model->join_member_rule_added_component_id = $component['rule_added_component_id']; $model->member_quota_status = 'PENDING'; $model->member_quota_category = $component['rule_added_component_category']; $model->member_quota_name = $component['rule_added_component_name']; $model->member_quota_nbr = $nbr; $model->member_quota_json = $component['rule_added_component_goods_json']; $model->member_quota_addtimes = time(); $model->save(); } }