www_fpvone_cn/application/admin/controller/user/Player.php

235 lines
8.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\admin\controller\user;
use app\admin\model\PlayerCheck;
use app\admin\model\Players;
use app\common\controller\Backend;
use app\common\library\Auth;
use think\Db;
/**
* 飞手管理
*
* @icon fa fa-user
*/
class Player extends Backend
{
protected $relationSearch = true;
protected $searchFields = 'id,username,nickname';
/**
* @var \app\admin\model\User
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = model('Players');
}
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
$this->model->query("UPDATE peewee_players SET age = FLOOR(TIMESTAMPDIFF(SECOND, birthday, NOW())/(60*60*24*365))");
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
// ->alias('players')
// ->join('user b', 'players.member_id = b.id')
->with('member')
->where($where)
->order("player_status asc")
->paginate($limit);
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
{
if ($this->request->isPost()) {
$this->token();
}
if ($this->request->param('player_id')){
$ids = $this->request->param('player_id');
}
$row = $this->model
->with('member')->find($ids);
// if (strpos($row['player_pic'], 'https://ydool2017.oss-cn-shanghai.aliyuncs.com/') === false) {
// // $headers = get_headers('https://ydool2017.oss-cn-shanghai.aliyuncs.com/'.$row['card_front_view']);
// // if (!is_array($headers) || strpos($headers[0], '200 OK') === false) {
// $row['player_pic'] = "https://www.fpvone.cn".$row['player_pic'];
// // var_dump($row['card_front_view']);exit;
// // }
// }
// if (strpos($row['card_front_view'], 'https://ydool2017.oss-cn-shanghai.aliyuncs.com/') === false) {
// // $headers = get_headers('https://ydool2017.oss-cn-shanghai.aliyuncs.com/'.$row['card_front_view']);
// // if (!is_array($headers) || strpos($headers[0], '200 OK') === false) {
// $row['card_front_view'] = "https://www.fpvone.cn".$row['card_front_view'];
// // var_dump($row['card_front_view']);exit;
// // }
// }
// if (strpos($row['card_back_view'], 'https://ydool2017.oss-cn-shanghai.aliyuncs.com/') === false) {
// // $headers = get_headers('https://ydool2017.oss-cn-shanghai.aliyuncs.com/'.$row['card_back_view']);
// // if (!is_array($headers) || strpos($headers[0], '200 OK') === false) {
// $row['card_back_view'] = "https://www.fpvone.cn".$row['card_back_view'];
// // }
// }
if ($this->request->isAjax()) {
$audit_status = $this->request->post('audit_status');
$reason = $this->request->post('reason', null);
$real_name = $this->request->post('row.real_name');
if(empty($real_name)) {$this->error('姓名不能为空');}
// $real_name = input('post.row.real_name');
// var_dump($real_name);exit;
// var_dump($_POST['row']['real_name']);exit;
if ($audit_status != 0 && $reason == null){
$this->error("请填写审核内容!");
}
//判断审核表里是否有该数据
$playerCheck = new PlayerCheck();
$check_info = $playerCheck->where(['player_id' => $ids])->find();
if (empty($check_info)){
$player_info = $this->model->find($ids);
$add_check_player['member_id'] = $player_info->member_id;
$add_check_player['player_id'] = $ids;
$add_check_player['before_status'] = $player_info->player_status;
$add_check_player['after_status'] = $audit_status;
$add_check_player['mark'] = $reason;
$add_check_player['created_at'] = date("Y-m-d H:i:s", time());
}else{
$player_info = $this->model->find($ids);
$add_check_player['member_id'] = $player_info->member_id;
$add_check_player['player_id'] = $ids;
$add_check_player['before_status'] = $check_info->before_status;
$add_check_player['after_status'] = $audit_status;
$add_check_player['mark'] = $reason;
$add_check_player['created_at'] = $check_info->created_at;
$add_check_player['updated_at'] = date("Y-m-d H:i:s", time());
}
// var_dump($audit_status);exit;
// 启动事务
Db::startTrans();
try {
$playerCheck->insert($add_check_player);
switch ($audit_status){
case 0:
$audit_status = 9;
break;
case 1:
$audit_status = 2;
break;
default:
$audit_status = -1;
break;
}
$this->model->update(['id' => $player_info->id, 'player_status' => $audit_status, 'real_name' => $real_name]);
if (!empty($player_info->phone)) {
$alisms = new \addons\alisms\library\Alisms();
$config = get_addon_config('alisms');
$template = "SMS_465344628";
$sign = $config['sign'];
if ($audit_status == 9) {
$param = [
'name' => $player_info->real_name,
'content' => "已经过确认和审核。"
];
} else {
$param = [
'name' => $player_info->real_name,
'content' => "未通过审核,请根据审核内容修改后重新提交。"
];
}
// var_dump($player_info->real_name);exit;
// $player_info->phone = '13626832346';
$res = $alisms->mobile($player_info->phone)
->template($template)
->sign($sign)
->param($param)
->send();
// var_dump($res);exit;
}
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
$this->error($e->getMessage());
}
$this->success();
}
if ($this->request->param('player_id')){
$row['is_show'] = 1;
}
$this->modelValidate = true;
if (!$row) {
$this->error(__('No Results were found'));
}
$this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['member']['group_id'], ['class' => 'form-control selectpicker']));
$this->view->assign('row', $row);
return $this->view->fetch();
}
public function save_style_photo()
{
$id = $this->request->post("id");
$photo = $this->request->post("style_photo");
$row = $this->model->update(['id' => $id, 'style_photo' => $photo]);
if ($row) {
$this->success("保存成功");
} else {
$this->error("保存失败");
}
}
public function save_player_pic()
{
$id = $this->request->post("id");
$photo = $this->request->post("style_photo");
$row = $this->model->update(['id' => $id, 'player_pic' => $photo]);
if ($row) {
$this->success("保存成功");
} else {
$this->error("保存失败");
}
}
}