Browse Source

新增修改管理员密码接口,优化中奖记录接口

master
wanghongjun 2 years ago
parent
commit
40700ef160
  1. 13
      app/controller/AdminStatistics.php
  2. 32
      app/controller/AdminUser.php
  3. 38
      app/model/AdminUser.php

13
app/controller/AdminStatistics.php

@ -163,10 +163,13 @@ class AdminStatistics extends BaseController
$data = Request::param();
$limit = $data['limit'] ?? 10;
$date = $data['date'] ?? date("Y-m-d",time());
$start_time = $date . ' 00:00:00';
$end_time = $date . ' 23:59:59';
$where = [['create_time','>=',$start_time],['create_time', '<=', $end_time]];
$where = [];
if (isset($data['date'])) {
$date = $data['date'] ?? date("Y-m-d",time());
$start_time = $date . ' 00:00:00';
$end_time = $date . ' 23:59:59';
$where = [['create_time','>=',$start_time],['create_time', '<=', $end_time]];
}
$records = new AwardsRecords();
@ -182,7 +185,7 @@ class AdminStatistics extends BaseController
$user = UserModel::withTrashedUserInfo($item['user_id']);
$item['phone'] = $user['phone'];
$item['awards_amount'] *= 1;
$item['datetime'] = date("H:i:s",strtotime($item['create_time']));
$item['datetime'] = date("Y-m-d H:i:s",strtotime($item['create_time']));
unset($item['create_time']);
}

32
app/controller/AdminUser.php

@ -47,6 +47,38 @@ class AdminUser extends BaseController
}
}
/**
* 修改密码
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function updatePassword()
{
$data = Request::param();
$adminData = $this->request->userInfo;
try {
// 验证用户输入
validate()->rule([
'password|新密码' => 'require|min:6|max:20'
])->check($data);
$AdminModel = new AdminModel();
$user = $AdminModel->modifyPassword($data,$adminData['id']);
if ($user['status']) {
return $this->renderSuccess('修改成功');
} else {
return $this->renderError($user['msg']);
}
} catch (ValidateException $exception) {
return $this->renderError($exception->getMessage());
}
}
/**
* 管理员信息
* @return array

38
app/model/AdminUser.php

@ -86,6 +86,44 @@ class AdminUser extends Model
return ['status' => true];
}
/**
* 更新密码
* @param $data
* @param $a_id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function modifyPassword($data,$a_id):array
{
$user = ['id' => $a_id];
if ($a_id) {
$AdminModel = $this->find($user['id']);
$password = $this->generateHashedPassword($data['password'], $AdminModel->salt);
if ($AdminModel->password == $password) {
return ['status' => false, 'msg' => '新密码与原密码一致'];
}
// 生成盐值
$salt = generate_random_str(6);
$new_password = $this->generateHashedPassword($data['password'], $salt);
// 密码加盐值后哈希存储
$AdminModel->password = $new_password;
$AdminModel->salt = $salt;
$AdminModel->save();
return ['status' => true, 'msg' => '修改成功'];
}
return ['status' => false, 'msg' => '数据有误'];
}
/**
* 生成密码
* @param $password

Loading…
Cancel
Save