You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.3 KiB
PHP

<?php
namespace Admin\Controller;
use User\Api\UserApi as UserApi;
class CloseAccountController extends ThinkController {
public $STATUS = [
0=>"未审核",
1=>"审核通过",
2=>"撤销申请",
];
public $admininfo;
public $DBModel;
public function _initialize()
{
$this->admininfo = $_SESSION['onethink_admin']['user_auth'];
$this->DBModel = M("close_account_log","tab_");
parent::_initialize();
}
public function list()
{
$page = I('p', 1);
$row = I('row', 10);
if(isset($_REQUEST['account'])){
$map['account']=array('like','%'.trim($_REQUEST['account']).'%');
}
if(isset($_REQUEST['user_id'])){
$map['user_id']=trim($_REQUEST['user_id']);
}
if(isset($_REQUEST['phone'])){
$map['phone']=$_REQUEST['phone'];
}
if(isset($_REQUEST['status'])){
$map['status']= $_REQUEST['status'];
}
if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) {
$time_start = strtotime($_REQUEST['time_start']);
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
$map["_string"] = "(create_time BETWEEN {$time_start} AND {$time_end})";
} elseif (isset($_REQUEST['time_start'])) {
$time_start = strtotime($_REQUEST['time_start']);
$map["_string"] = "(create_time >= {$time_start} )";
} elseif (isset($_REQUEST['time_end'])) {
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
$map["_string"] = "(create_time <= {$time_end} )";
}
$data = $this->DBModel->where($map)->order("create_time desc")->page($page, $row)->select();
if($data){
$game = M("game","tab_")->where(['id'=>["in",array_column($data,'game_id')]])->getField("id,game_name",true);
$admin = M("member")->where(['uid'=>["in",array_column($data,'admin_id')]])->getField("uid,nickname",true);
foreach ($data as $k => &$v) {
$v['game_name'] = $game[$v['game_id']] ?? "--";
$v['admin_name'] = $admin[$v['admin_id']] ?? "--";
$v['create_time'] = date("Y-m-d H:i:s",$v['create_time']);
$v['update_time'] = $v['update_time'] ? date("Y-m-d H:i:s",$v['update_time']) : '--';
$v['status_str'] = $this->STATUS[$v['status']] ?? "--";
}
}
$count = $this->DBModel->where($map)->count();
$page = set_pagination($count, $row);
if ($page) {
$this->assign('_page', $page);
}
$Rule = strtolower(MODULE_NAME . '/' . CONTROLLER_NAME . '/check');
if ($this->checkRule($Rule, array('in', '1,2')) || IS_ROOT) {
$this->assign("check",true);
}
$this->assign("data",$data);
$this->display();
}
public function check(){
$status = $_REQUEST['status'];
$ids = $_REQUEST['ids'];
if (!$ids) {
$this->ajaxReturn(['status'=>0,'msg'=>'数据错误']);
}
$userIds = $this->DBModel->where(['id'=>['in',$ids],'status'=>0])->getField('user_id',true);
if($status == 1){
$this->closeAccount($userIds);
}
if($status == 2){
$this->cancel($userIds);
}
$this->resetCloseAccount($ids,$status);
$this->ajaxReturn(['status'=>1,'msg'=>'操作成功']);
}
private function closeAccount($userIds)
{
$userBase = [
'lock_status'=>0,
'lock_remark'=>"用户注销锁定",
'phone'=>''
];
$userDB = M('user',"tab_");
foreach ($userIds as $k => $v) {
$userBase['account'] = "zxzh".substr(md5($v.time()),8,16);
$userBase['id'] = $v;
$userDB->save($userBase);
}
}
private function cancel($userIds)
{
$userBase = [
'lock_status'=>1,
'lock_remark'=>"",
'id'=>['in',$userIds]
];
M('user',"tab_")->save($userBase);
}
private function resetCloseAccount($ids,$status)
{
$base = [
'status'=>$status,
'id'=>['in',$ids],
'admin_id'=>$this->admininfo['uid'],
'update_time'=>time(),
];
$this->DBModel->save($base);
}
}