first(); $configParams = json_decode($config->config_value_json, true); Db::beginTransaction(); try { $order = Order::where('order_id', $params['orderId'])->where('order_status_payment', 'SUCCESS')->first(); // 有传过来的 if (!empty($params['join_invite_member_id'])) { $inviteMemberId = $params['join_invite_member_id']; } else { // 下单人 $member = Member::where('member_id', $order->join_order_member_id)->first(); if (empty($member->join_invite_member_id)) { throw new BusinessException("没有直属上级"); } $inviteMemberId = $member->join_invite_member_id; } // 上级 $memberUp = Member::where('member_id', $inviteMemberId)->first(); if ($memberUp->member_is_partner == 'Y') { $identity = 'PARTNER'; } elseif ($memberUp->member_is_referrer == 'Y') { $identity = 'REFERRER'; }else{ throw new BusinessException("直属上级非合伙人或者推荐官"); } // 记录的JSON $accountListJson = [ 'line' => 'relate-consum', 'amount' => $order->order_amount_pay, 'identity' => $identity, 'order_id' => $order->order_id, 'master_member_id' => $order->join_order_member_id ]; // 提成 $this->commissionToMember($inviteMemberId, $accountListJson, round($configParams['commission']['relate-consum'] * $order->order_amount_pay, 2), '消费'); Db::commit(); _syslog("提成", "计算提成成功"); } catch (BusinessException $e) { Db::rollBack(); _syslog("提成", "计算提成失败:" . $e->getMessage()); } catch (\Exception $e) { dump($e->getMessage()); Db::rollBack(); _syslog("提成", "计算提成失败"); } } /** * @Desc * @Author Gorden * @Date 2024/9/25 15:14 * * @param $memberId * @param $accountListJson * @param $money * @return void */ private function commissionToMember($memberId, $accountListJson, $money, $accountListCategory) { $account = MemberAccount::where('join_account_member_id', $memberId)->where('member_account_classify', 'CASH')->first(); $account->member_account_income = $account->member_account_income + $money; $account->member_account_surplus = $account->member_account_surplus + $money; $account->save(); MemberAccountList::insert([ 'join_list_member_account_nbr' => $memberId . '-CASH', 'join_member_account_list_member_id' => $memberId, 'member_account_list_status' => 'ACTIVED', 'member_account_list_attr' => 'IN', 'member_account_list_classify' => $accountListJson['identity'], 'member_account_list_category' => $accountListCategory, 'member_account_list_datetime' => date('Y-m-d H:i:s'), 'member_account_list_amount' => $money, 'member_account_list_json' => json_encode($accountListJson), 'member_account_list_addtimes' => time() ]); } }