Browse Source

回退

master
wanghongjun 2 years ago
parent
commit
bda762701d
  1. 17
      app/controller/AdminAgentTeam.php
  2. 28
      app/controller/AdminUserTeam.php
  3. 18
      app/model/User.php
  4. 5
      app/validate/Agent.php
  5. 5
      app/validate/User.php

17
app/controller/AdminAgentTeam.php

@ -58,7 +58,7 @@ class AdminAgentTeam extends BaseController
}
# 查询用户列表
$field = 'id,aid,phone,avatar,balance,withdrawal_balance,status,rate';
$field = 'id,aid,phone,avatar,balance,withdrawal_balance,status';
$userRes = $UserModel->field($field)->where($where)->order('id desc')->paginate($limit);
$list = $userRes->items();
@ -73,7 +73,6 @@ class AdminAgentTeam extends BaseController
$rebate_ratio = $AgentInfo->where('aid',$item['id'])->value('rebate_ratio');
$item['rebate_ratio'] = $rebate_ratio ? round($rebate_ratio * 100,2) : '0';
$item['grade'] = empty($item['aid']) ? '1级' : 'id:' . $item['aid'];
$item['rate'] = round($item['rate'] * 100,2);
unset($item['aid']);
}
@ -176,15 +175,11 @@ class AdminAgentTeam extends BaseController
'aid|代理id' => 'require|number',
'password|密码' => 'min:6|max:20',
'rebate_ratio|返点占比' => 'float|between:0.01,100',
'rate|中奖比率' => 'float|between:0.01,100',
])->check($param);
$password = $param['password'] ?? '';
$param['rebate_ratio'] = $param['rebate_ratio'] ?? '';
$rebate_ratio = (string) $param['rebate_ratio'];
$param['rate'] = $param['rate'] ?? '';
$rate = (string) $param['rate'];
if (empty($password) && strlen($rebate_ratio) <= 0 && strlen($rate) <= 0) {
throw new ValidateException('请填写至少一项修改');
$rebate_ratio = (string) $param['rebate_ratio'] ?? '';
if (empty($password) && strlen($rebate_ratio) <= 0) {
throw new ValidateException('请填写修改的密码或返点占比');
}
# 开启事务
@ -210,10 +205,6 @@ class AdminAgentTeam extends BaseController
if ($validateAgentRebateRatio !== true) throw new ValidateException($validateAgentRebateRatio);
AgentInfo::updateRebateRatio($param['aid'],$rebate_ratio);
}
# 保存占比
if (!empty($rate)) {
User::saveRate($param['aid'],$rate);
}
$connection->commit();
return $this->renderSuccess('成功');

28
app/controller/AdminUserTeam.php

@ -59,7 +59,7 @@ class AdminUserTeam extends BaseController
}
# 查询用户列表
$field = 'id,aid,phone,avatar,balance,withdrawal_balance,status,rate';
$field = 'id,aid,phone,avatar,balance,withdrawal_balance,status';
$userRes = $UserModel->field($field)->where($where)->order('id desc')->paginate($limit);
$list = $userRes->items();
@ -69,7 +69,6 @@ class AdminUserTeam extends BaseController
$item['avatar'] = get_image_url($item['avatar']);
$item['status'] = $item['status'] == 1 ? '正常' : '停用';
$item['rate'] = round($item['rate'] * 100,2);
}
return $this->renderSuccess('数据返回成功', ['list' => $list, 'total' => $total]);
@ -110,36 +109,19 @@ class AdminUserTeam extends BaseController
try {
validate()->rule([
'user_id|用户id' => 'require|number',
'password|密码' => 'min:6|max:20',
'rate|中奖比率' => 'float|between:0.01,100',
])->check($param);
$password = $param['password'] ?? '';
$rate = $param['rate'] ?? '';
if (empty($password) && strlen($rate) <= 0) {
throw new ValidateException('请填写至少一项修改');
}
validate(UserValidate::class)->scene('editUser')->check($param);
$UserModel = new User();
$result = [];
if ($password) {
$result = $UserModel->retrieve($param);
if (!$result['status']) throw new ValidateException($result['msg']);
}
$result = $UserModel->retrieve($param);
if ($rate) User::saveRate($param['user_id'],$rate);
if (!$result['status']) throw new ValidateException($result['msg']);
$event = new UserPasswordChange($param['user_id']);
Event::trigger(UserPasswordChange::class,$event);
return $this->renderSuccess('修改成功');
return $this->renderSuccess($result['msg']);
} catch (ValidateException $validateException) {
return $this->renderError($validateException->getMessage());
} catch (\Exception $e) {
return $this->renderError('操作失败');
}
}

18
app/model/User.php

@ -52,9 +52,6 @@ class User extends Model
$rand = rand(5,50);
$save['id'] = $lastId + $rand;
}
if (isset($data['rate']) && $data['rate'] > 0) {
$save['rate'] = round($data['rate'] / 100,4);
}
$User->save($save);
return $User->id;
@ -403,21 +400,6 @@ class User extends Model
return $UserData;
}
/**
* 编辑概率
* @param $user_id
* @param $rate
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function saveRate($user_id,$rate)
{
$User = User::find($user_id);
$User->rate = round($rate / 100,4);
$User->save();
}
/**
* 生成盐值
* @return string

5
app/validate/Agent.php

@ -21,8 +21,7 @@ class Agent extends Validate
'repassword|确认密码' => 'require|confirm:password',
'aid|代理id' => 'require|number',
'phone|手机号' => 'require|mobile',
'rebate_ratio|返点占比' => 'float|between:0.01,100',
'rate|比率' => 'float|between:0.01,100',
'rebate_ratio|返点占比' => 'float|between:0.01,100'
];
/**
@ -37,7 +36,7 @@ class Agent extends Validate
'scores' => ['user_id','quota'],
'edit' => ['aid','password','rebate_ratio'],
'del' => ['aid'],
'register' => ['phone','password','rebate_ratio','rate'],
'register' => ['phone','password','rebate_ratio'],
'modifyPassword' => ['password','repassword'],
'promotion' => ['user_id','rebate_ratio']
];

5
app/validate/User.php

@ -19,8 +19,7 @@ class User extends Validate
'password|密码' => 'require|min:6|max:20',
'repassword|确认密码' => 'require|confirm:password',
'phone|手机号' => 'require|mobile',
'user_id|用户id' => 'require|number',
'rate|中奖比率' => 'float|between:0.01,100',
'user_id|用户id' => 'require|number'
];
/**
@ -35,7 +34,7 @@ class User extends Validate
= [
'modifyPassword' => ['password', 'repassword'],
'editUser' => ['user_id', 'password'],
'register' => ['phone', 'password','rate'],
'register' => ['phone', 'password'],
'delUser' => ['user_id'],
];

Loading…
Cancel
Save