SchoolPhysicalExamination/application/app/controller/Myinformation.php

236 lines
10 KiB
PHP

<?php
namespace app\app\controller;
use think\Db;
use app\app\controller\Login;
class Myinformation extends Base{
protected $myinformation_use_db_name = [
'1'=>'app_account_number',
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 获取账号下信息
public function get_my_account_msg($data = ['token'=>'e0966788d02cc93290d9d674921d9715']){
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005);
}
$return_data = $this->get_my_account_msg_action($data);
// 成功
$this->record_api_log($data, null, $return_data);
return $return_data;
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
// 修改昵称
public function update_my_nickname($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca','nickname'=>'']){
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('nickname', $data) || !array_key_exists('token', $data)){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['nickname'],'str')){
return $this->msg(10005);
}
$return_data = $this->update_my_nickname_action($data);
// 成功
$this->record_api_log($data, null, $return_data);
return $return_data;
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
// 邮箱/手机绑定
public function update_my_account_msg($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca','data'=>'tsf3920322@126.com','code'=>'123456']){
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('data', $data) || !array_key_exists('token', $data) || !array_key_exists('code', $data)){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['code'],'intnum')){
return $this->msg(10005);
}
$return_data = $this->update_my_account_msg_action($data);
// 成功
$this->record_api_log($data, null, $return_data);
return $return_data;
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
// 修改密码
public function update_my_password($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca','password'=>'ceshi1','c_password'=>'ceshi1']){
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('token', $data)){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['password'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['c_password'],'str')){
return $this->msg(10005);
}
$return_data = $this->update_my_password_action($data);
// 成功
$this->record_api_log($data, null, $return_data);
return $return_data;
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
################################################################业务################################################################
################################################################get_my_account_msg
public function get_my_account_msg_action($data){
$result = Db::table($this->myinformation_use_db_name['1'])->where(['token'=>$data['token'],'is_del'=>0])->find();
if($result){
return $this->msg([
'my_tel'=>$result['tel'],
'my_email'=>$result['email'],
'create_time'=>$result['create_time'],
'token'=>$result['token'],
'nickname'=>$result['nickname'],
'head_pic'=>$result['head_pic'],
'last_update_time'=>$result['update_time'],
]);
}else{
return $this->msg(10002);
}
}
################################################################update_my_nickname
public function update_my_nickname_action($data){
$result = Db::table($this->myinformation_use_db_name['1'])->where(['token'=>$data['token'],'is_del'=>0])->update([
'nickname'=>$data['nickname'],
'update_time'=>date('Y-m-d H:i:s')
]);
if($result){
return $this->msg([]);
}else{
return $this->msg(10002);
}
}
################################################################update_my_account_msg
public function update_my_account_msg_action($data){
$login_action = new Login();
$validate_result = $login_action->check_code($data['data'],$data['code']);
if($validate_result !== true){
return $this->msg(10001,$validate_result);
}
$montage_data = $this->is_tel_email($data['data']);
if($montage_data == false){
return $this->msg(10005);
}
$result = Db::table($this->myinformation_use_db_name['1'])->where(['token'=>$data['token'],'is_del'=>0])->update([
$montage_data=>$data['data'],
'update_time'=>date('Y-m-d H:i:s')
]);
if($result){
return $this->msg([]);
}else{
return $this->msg(10002);
}
}
################################################################update_my_password
public function update_my_password_action($data){
if($data['password'] != $data['c_password']){
return $this->msg(10003,'两次密码不一致');
}
if($data['password'] == ''){
return $this->msg(10003,'密码不能为空');
}
$result = Db::table($this->myinformation_use_db_name['1'])->where(['token'=>$data['token'],'is_del'=>0])->update([
'password'=>$data['password'],
'update_time'=>date('Y-m-d H:i:s')
]);
if($result){
return $this->msg([]);
}else{
return $this->msg(10002);
}
}
}