Browse Source

返回代理列表优化 编辑代理优化 代理返利优化

master
wanghongjun 2 years ago
parent
commit
97acdd5b71
  1. 7
      app/controller/AdminAgentTeam.php
  2. 2
      app/controller/AdminStatistics.php
  3. 24
      app/model/User.php
  4. 20
      app/validate/Agent.php

7
app/controller/AdminAgentTeam.php

@ -58,7 +58,7 @@ class AdminAgentTeam extends BaseController
}
# 查询用户列表
$field = 'id,phone,avatar,balance,withdrawal_balance,status';
$field = 'id,aid,phone,avatar,balance,withdrawal_balance,status';
$userRes = $UserModel->field($field)->where($where)->order('id desc')->paginate($limit);
$list = $userRes->items();
@ -72,6 +72,8 @@ class AdminAgentTeam extends BaseController
# 获取返点占比
$rebate_ratio = $AgentInfo->where('aid',$item['id'])->value('rebate_ratio');
$item['rebate_ratio'] = $rebate_ratio * 100;
$item['grade'] = empty($item['aid']) ? '1级' : 'id:' . $item['aid'];
unset($item['aid']);
}
return $this->renderSuccess('数据返回成功', ['list' => $list, 'total' => $total]);
@ -199,12 +201,15 @@ class AdminAgentTeam extends BaseController
# 保存返点占比
if (strlen($rebate_ratio) > 0) {
$rebate_ratio = $param['rebate_ratio'] ?? 0;
$validateAgentRebateRatio = validate(Agent::class)->validateAgentRebateRatio($param['aid'],$rebate_ratio);
if ($validateAgentRebateRatio !== true) throw new ValidateException($validateAgentRebateRatio);
AgentInfo::updateRebateRatio($param['aid'],$rebate_ratio);
}
$connection->commit();
return $this->renderSuccess('成功');
} catch (ValidateException $validateException) {
$connection->rollback();
return $this->renderError($validateException->getMessage());
} catch (\Exception $exception) {
$connection->rollback();

2
app/controller/AdminStatistics.php

@ -179,7 +179,7 @@ class AdminStatistics extends BaseController
$sumRes = $records->field('SUM(awards_amount) as sum_amount')->where($where)->find();
foreach ($data as &$item) {
$user = UserModel::field('phone')->find($item['user_id']);
$user = UserModel::withTrashedUserInfo($item['user_id']);
$item['phone'] = $user['phone'];
$item['awards_amount'] *= 1;
$item['datetime'] = date("H:i:s",strtotime($item['create_time']));

24
app/model/User.php

@ -347,11 +347,12 @@ class User extends Model
# 获取用户代理
$aid = User::where('id',$user_id)->value('aid');
if (empty($aid)) return false;
if (empty(self::$trade_id)) {
self::$trade_id = $user_id;
}
# 当前操作记录ID
if (empty(self::$trade_id)) self::$trade_id = $user_id;
# 获取代理返点比率
$rebate_ratio = AgentInfo::where('aid',$aid)->value('rebate_ratio');
$AgentInfo = AgentInfo::where('aid',$aid)->field('rebate_ratio')->find();
if (!$AgentInfo) return false;
$rebate_ratio = $AgentInfo['rebate_ratio'];
if (!$rebate_ratio || !($rebate_ratio * 1)) return false;
# 减去下级返点比率
$rebate_ratio -= $superior_rebate_ratio;
@ -367,6 +368,21 @@ class User extends Model
self::addRebateRatioAmount($aid,$amount,$rebate_ratio);
}
/**
* 查询获取用户信息(包括已删除的)
* @param $user_id
* @return User|array|mixed|Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function withTrashedUserInfo($user_id)
{
$UserData = User::withTrashed()->where('id',$user_id)->field('phone,avatar')->find();
$UserData['avatar'] = get_image_url($UserData['avatar']);
return $UserData;
}
/**
* 生成盐值
* @return string

20
app/validate/Agent.php

@ -76,4 +76,24 @@ class Agent extends Validate
}
return true;
}
/**
* 限制总后台设置代理反比权限
* @param $aid
* @param $rebate_ratio
* @return bool|string
*/
public function validateAgentRebateRatio($aid,$rebate_ratio)
{
$last_aid = \app\model\User::where('id',$aid)->where('identity',2)->value('aid');
if (!empty($last_aid)) {
$last_rebate_ratio = AgentInfo::where('aid',$last_aid)->value('rebate_ratio');
if (empty($last_rebate_ratio)) return '当前代理上级代理未有返点权限,不能设置该代理返点占比';
$rebate_ratio = $rebate_ratio / 100;
if ($rebate_ratio >= $last_rebate_ratio) {
return '填写返点占比不能超出上级代理的返点占比,上级代理返点比率为:'.($last_rebate_ratio*100).'%';
}
}
return true;
}
}

Loading…
Cancel
Save