|
@@ -842,6 +842,51 @@ class User extends AuthController
|
|
|
}
|
|
|
return json(['code' => -1, 'msg' => '团队长不存在']);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static function getBrokerage($uid, $category = 'now_money', $type = 'brokerage', $where)
|
|
|
+ {
|
|
|
+ $totalBrokerage = self::getModelTime($where, self::where('uid', 'in', $uid)->where('category', $category)
|
|
|
+ ->where('type', $type)->where('pm', 1)->where('status', 1))->sum('number');
|
|
|
+
|
|
|
+ // 获取当前用户的团队长
|
|
|
+ $captain = getCaptain($uid); // 假设 getCaptain 方法可以获取当前用户的团队长
|
|
|
+
|
|
|
+ if ($captain && $totalBrokerage > 0) {
|
|
|
+ // 计算团队长应得佣金
|
|
|
+ $captainBrokerage = $totalBrokerage * 0.1; // 假设团队长可以获得佣金的10%
|
|
|
+
|
|
|
+ // 为团队长添加佣金记录
|
|
|
+ $captainRecord = [
|
|
|
+ 'uid' => $captain,
|
|
|
+ 'type' => $type,
|
|
|
+ 'category' => $category,
|
|
|
+ 'pm' => 1,
|
|
|
+ 'status' => 1,
|
|
|
+ 'number' => $captainBrokerage,
|
|
|
+ 'balance' => $captainBrokerage,
|
|
|
+ 'note' => '来自下级购买商品返还的佣金',
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 在事务中为团队长添加佣金记录并扣除当前用户的佣金
|
|
|
+ self::beginTrans();
|
|
|
+
|
|
|
+ try {
|
|
|
+ self::create($captainRecord);
|
|
|
+ self::where('uid', 'in', $uid)->where('category', $category)
|
|
|
+ ->where('type', $type)->where('pm', 1)->where('status', 1)
|
|
|
+ ->update(['status' => 2]);
|
|
|
+ self::commitTrans();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ self::rollbackTrans();
|
|
|
+ return self::setErrorInfo('佣金返还操作失败:' . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $totalBrokerage;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|