www_fpvone_cn/application/index/controller/User.php

1095 lines
48 KiB
PHP
Raw Normal View History

2024-12-20 12:29:51 +08:00
<?php
namespace app\index\controller;
use addons\wechat\model\WechatCaptcha;
use app\admin\model\MatchContestant;
use app\common\controller\Frontend;
use app\common\library\Ems;
use app\common\library\Sms;
use app\common\model\Attachment;
use app\common\model\Players;
// use app\common\model\Club;
use think\Config;
use think\Cookie;
use think\Exception;
use think\Hook;
use think\Request;
use think\response\Json;
use think\Validate;
use app\index\controller\Wxmb;
use app\admin\model\Renzheng;
use app\admin\model\Club as ClubModel;
use app\admin\model\ClubPlayercheck;
use app\admin\model\ClubInvate;
use app\admin\model\shopro\ClubThirdOauth;
use think\Response;
use app\common\model\User as UserModel;
/**
* 会员中心
*/
class User extends Frontend
{
protected $layout = 'defaults';
protected $noNeedLogin = ['login', 'register', 'third','logins'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$auth = $this->auth;
if (!Config::get('fastadmin.usercenter')) {
$this->error(__('User center already closed'), '/');
}
//监听注册登录退出的事件
Hook::add('user_login_successed', function ($user) use ($auth) {
$expire = input('post.keeplogin') ? 30 * 86400 : 0;
Cookie::set('uid', $user->id, $expire);
Cookie::set('token', $auth->getToken(), $expire);
});
Hook::add('user_register_successed', function ($user) use ($auth) {
Cookie::set('uid', $user->id);
Cookie::set('token', $auth->getToken());
});
Hook::add('user_delete_successed', function ($user) use ($auth) {
Cookie::delete('uid');
Cookie::delete('token');
});
Hook::add('user_logout_successed', function ($user) use ($auth) {
Cookie::delete('uid');
Cookie::delete('token');
});
}
public function judge_status(){
$user_id = $this->auth->id;
if (empty($user_id)){
$this->error("请先登录!");
}
$playersModel = new Players();
$club = new ClubModel();
$clubinvate = new ClubInvate();
$club_info = $club
->where('user_id', $user_id)
->find();
$player_info = $playersModel
->where('member_id', $user_id)
->find();
// $this->view->assign('user_type', 0);
$data['user_type'] = 0;
if(!empty($club_info)){
$data['user_type'] = 2;
}
// $this->view->assign('user_player_status', 0);
$data['user_player_status'] = 0;
if(!empty($player_info)) {
// $this->view->assign('user_type', 1);
$data['user_type'] = 1;
$club_invateres = $clubinvate->where('player_id',$player_info['id'])->where('status',6)->where('deletetime',null)->find();
// $club_invateres2 = $clubinvate->where('player_id',$player_info['id'])->where('status',9)->where('deletetime',null)->find();
$club_invateres1 = $clubinvate->where('player_id',$player_info['id'])->where('status',5)->where('deletetime',null)->find();
if(!empty($club_invateres)) $data['user_player_status'] = 2;
if(!empty($club_invateres1)) $data['user_player_status'] = 3;
// if(!empty($club_invateres2)) $data['user_player_status'] = 4;
}
$datas['code'] = 1;
$datas['msg'] = 'success';
$datas['data'] = $data;
return json($datas);
}
/**
* 会员中心
*/
public function index()
{
$this->view->assign('title', __('User center'));
$user_id = $this->auth->id;
if (empty($user_id)){
$this->error("请先登录!",url('user/login'));
}
$playersModel = new Players();
$club = new ClubModel();
$clubinvate = new ClubInvate();
$ClubThirdOauth = new ClubThirdOauth();
$club_info = $club
->where('user_id', $user_id)
->find();
$player_info = $playersModel
->where('member_id', $user_id)
->find();
$this->view->assign('user_type', 0);
if(!empty($club_info)){
$this->view->assign('club_info', $club_info);
$this->view->assign('user_type', 2);
}
$this->view->assign('user_player_status', 0);
$count_match = 0;
if(!empty($player_info)) {
$this->view->assign('user_type', 1);
// $club_invateres = $clubinvate->where('player_id',$player_info['id'])->where('status',6)->where('deletetime',null)->find();
// // $club_invateres1 = $clubinvate->where('player_id',$player_info['id'])->where('status',1)->where('deletetime',null)->find();
// $club_invateres1 = $clubinvate->where('player_id',$player_info['id'])->where('status',5)->where('deletetime',null)->find();
// // var_dump($club_invateres1);exit;
// if(!empty($club_invateres)) $this->view->assign('user_player_status', 2);
// if(!empty($club_invateres1)) $this->view->assign('user_player_status', 3);
// 如果是飞手则获取报名成功的赛事总计
$matchModel = new MatchContestant();
$count_match = $matchModel->where('player_id', $player_info['id'])->where('status', 2)->count("*");
if($player_info['is_sociaty'] == '' ) {
if($player_info['first_show'] == ''){
$playersModel->save([
'first_show'=>1,
'updated_at' => date('Y-m-d H:i:s',time()),
],['id'=>$player_info['id']]);
return $this->redirect('players/sociaty');
}
}
}
$userInfo = \app\admin\model\User::get($user_id);
$oauth_res = $ClubThirdOauth->where('user_id',$user_id)->find();
if(!empty($oauth_res)) {
$this->view->assign('is_notice', 1);
}else{
$this->view->assign('is_notice', 0);
}
$this->view->assign('count_match', $count_match);
$this->view->assign('playerinfo', $player_info);
$this->view->assign('userinfo', $userInfo);
return $this->view->fetch();
}
/**
* 注册会员
*/
public function register()
{
$this->layout = 'default';
$this->view->engine->layout('layout/' . $this->layout);
$url = $this->request->request('url', '', 'trim');
if ($this->auth->id) {
$this->success(__('You\'ve logged in, do not login again'), $url ? $url : url('user/index'));
}
if ($this->request->isPost()) {
$username = $this->request->post('username');
$password = $this->request->post('password');
$email = $this->request->post('email');
$mobile = $this->request->post('mobile', '');
$captcha = $this->request->post('captcha');
$dialCode = $this->request->post("dialCode");
// var_dump($dialCode);exit;
$token = $this->request->post('__token__');
$rule = [
'username' => 'require|length:3,30',
'password' => 'require|length:6,30',
// 'mobile' => 'regex:/^1\d{10}$/',
'__token__' => 'require|token',
];
$msg = [
'username.require' => 'Username can not be empty',
'username.length' => 'Username must be 3 to 30 characters',
'password.require' => 'Password can not be empty',
'password.length' => 'Password must be 6 to 30 characters',
// 'mobile' => 'Mobile is incorrect',
];
$data = [
'username' => $username,
'password' => $password,
'email' => $email,
'mobile' => $mobile,
'__token__' => $token,
];
//验证码
$captchaResult = true;
$captchaType = config("fastadmin.user_register_captcha");
$check_mobile = $mobile;
$event = 'register';
//中国大陆手机号
if($dialCode == "+86"){
if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) {
$this->error(__('手机号不正确'));
}
}elseif(!empty($dialCode) && $dialCode != "+86"){
$check_mobile = $dialCode.$mobile;
$event = 'inter_'.$event;
}
if ($captchaType) {
if ($captchaType == 'mobile') {
$captchaResult = Sms::check($check_mobile, $captcha, $event);
} elseif ($captchaType == 'email') {
$captchaResult = Ems::check($email, $captcha, 'register');
} elseif ($captchaType == 'wechat') {
$captchaResult = WechatCaptcha::check($captcha, 'register');
} elseif ($captchaType == 'text') {
$captchaResult = \think\Validate::is($captcha, 'captcha');
}
}
if (!$captchaResult) {
$this->error(__('Captcha is incorrect'));
}
$validate = new Validate($rule, $msg);
$result = $validate->check($data);
if (!$result) {
$this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
}
if ($this->auth->register($username, $password, $email, $mobile,array('dial_code'=>$dialCode))) {
$this->success(__('Sign up successful'), $url ? $url : url('user/index'));
} else {
$this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
}
}
//判断来源
$referer = $this->request->server('HTTP_REFERER');
if (!$url && (strtolower(parse_url($referer, PHP_URL_HOST)) == strtolower($this->request->host()))
&& !preg_match("/(user\/login|user\/register|user\/logout)/i", $referer)) {
$url = $referer;
}
$this->view->assign('captchaType', config('fastadmin.user_register_captcha'));
$this->view->assign('url', $url);
$this->view->assign('title', __('Register'));
return $this->view->fetch();
}
/**
* 会员登录
*/
public function login()
{
$this->layout = 'default';
$this->view->engine->layout('layout/' . $this->layout);
$url = $this->request->request('url', '', 'trim');
if ($this->auth->id) {
$this->success(__('You\'ve logged in, do not login again'), $url ? $url : url('user/index'));
}
if ($this->request->isPost()) {
$account = $this->request->post('account');
$password = $this->request->post('password');
$keeplogin = (int)$this->request->post('keeplogin');
$token = $this->request->post('__token__');
$returnURL = $this->request->post('returnURL','');
$istype = $this->request->post('istype');
$mobile = $this->request->post('mobile');
$dialCode = $this->request->post('dialCode');
$code = '';
//手机类型登录
if($istype == '1'){
if($dialCode == '+86'){
$dialCode = null;
}
$UserModel = new UserModel();
$user_res = $UserModel->where('mobile',$mobile)->where('dial_code',$dialCode)->find();
if (empty($user_res)) {
$this->error('Account is incorrect');
return false;
}
$account = $mobile;
$code = 1;
}
$rule = [
'account' => 'require|length:3,50',
'password' => 'require|length:6,30',
'__token__' => 'require|token',
];
$msg = [
'account.require' => 'Account can not be empty',
'account.length' => 'Account must be 3 to 50 characters',
'password.require' => 'Password can not be empty',
'password.length' => 'Password must be 6 to 30 characters',
];
$data = [
'account' => $account,
'password' => $password,
'__token__' => $token,
];
$validate = new Validate($rule, $msg);
$result = $validate->check($data);
if (!$result) {
$this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
return false;
}
if ($this->auth->login($account, $password,$code)) {
$this->success(__('Logged in successful'), $url ? $url : url('user/index'));
} else {
$this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
}
}
//判断来源
$referer = $this->request->server('HTTP_REFERER');
if (!$url && (strtolower(parse_url($referer, PHP_URL_HOST)) == strtolower($this->request->host()))
&& !preg_match("/(user\/login|user\/register|user\/logout)/i", $referer)) {
$url = $referer;
}
$this->view->assign('url', $url);
$this->view->assign('title', __('Login'));
return $this->view->fetch();
}
//dra登录跳转
public function logins()
{
$this->layout = 'default';
$this->view->engine->layout('layout/' . $this->layout);
$url = $this->request->request('url', '', 'trim');
if ($this->auth->id) {
$this->success(__('You\'ve logged in, do not login again'),'https://www.fpvone.cn/index/user/index.html','',1);
}
if ($this->request->isPost()) {
$account = $this->request->post('account');
$password = $this->request->post('password');
$keeplogin = (int)$this->request->post('keeplogin');
$token = $this->request->post('__token__');
$rule = [
'account' => 'require|length:3,50',
'password' => 'require|length:6,30',
// '__token__' => 'require|token',
];
$msg = [
'account.require' => 'Account can not be empty',
'account.length' => 'Account must be 3 to 50 characters',
'password.require' => 'Password can not be empty',
'password.length' => 'Password must be 6 to 30 characters',
];
$data = [
'account' => $account,
'password' => $password,
// '__token__' => $token,
];
$validate = new Validate($rule, $msg);
$result = $validate->check($data);
if (!$result) {
$this->error(__($validate->getError()), 'https://www.fpvone.cn/index/user/index.html');
return false;
}
if ($this->auth->login($account, $password)) {
$this->success(__('Logged in successful'), 'https://www.fpvone.cn/index/user/index.html','',1);
} else {
$this->error($this->auth->getError(), 'https://www.fpvone.cn/index/user/index.html');
}
}
//判断来源
$referer = $this->request->server('HTTP_REFERER');
if (!$url && (strtolower(parse_url($referer, PHP_URL_HOST)) == strtolower($this->request->host()))
&& !preg_match("/(user\/login|user\/register|user\/logout)/i", $referer)) {
$url = $referer;
}
$this->view->assign('url', $url);
$this->view->assign('title', __('Login'));
return $this->view->fetch();
}
/**
* 退出登录
*/
public function logout()
{
if ($this->request->isPost()) {
$this->token();
//退出本站
$this->auth->logout();
$this->success(__('Logout successful'), url('user/index'));
}
$html = "<form id='logout_submit' name='logout_submit' action='' method='post'>" . token() . "<input type='submit' value='ok' style='display:none;'></form>";
$html .= "<script>document.forms['logout_submit'].submit();</script>";
return $html;
}
/**
* 个人信息
*/
public function profile()
{
$this->view->assign('title', __('Profile'));
return $this->view->fetch();
}
/**
* 修改密码
*/
public function changepwd()
{
$this->layout = 'default';
$this->view->engine->layout('layout/' . $this->layout);
if ($this->request->isPost()) {
$oldpassword = $this->request->post("oldpassword");
$newpassword = $this->request->post("newpassword");
$renewpassword = $this->request->post("renewpassword");
$token = $this->request->post('__token__');
$rule = [
'oldpassword' => 'require|regex:\S{6,30}',
'newpassword' => 'require|regex:\S{6,30}',
'renewpassword' => 'require|regex:\S{6,30}|confirm:newpassword',
'__token__' => 'token',
];
$msg = [
'renewpassword.confirm' => __('Password and confirm password don\'t match')
];
$data = [
'oldpassword' => $oldpassword,
'newpassword' => $newpassword,
'renewpassword' => $renewpassword,
'__token__' => $token,
];
$field = [
'oldpassword' => __('Old password'),
'newpassword' => __('New password'),
'renewpassword' => __('Renew password')
];
$validate = new Validate($rule, $msg, $field);
$result = $validate->check($data);
if (!$result) {
$this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
return false;
}
$ret = $this->auth->changepwd($newpassword, $oldpassword);
if ($ret) {
$this->success(__('Reset password successful'), url('user/login'));
} else {
$this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
}
}
$this->view->assign('title', __('Change password'));
return $this->view->fetch();
}
public function attachment()
{
//设置过滤方法
$this->request->filter(['strip_tags']);
if ($this->request->isAjax()) {
$mimetypeQuery = [];
$where = [];
$filter = $this->request->request('filter');
$filterArr = (array)json_decode($filter, true);
if (isset($filterArr['mimetype']) && preg_match("/(\/|\,|\*)/", $filterArr['mimetype'])) {
$this->request->get(['filter' => json_encode(array_diff_key($filterArr, ['mimetype' => '']))]);
$mimetypeQuery = function ($query) use ($filterArr) {
$mimetypeArr = array_filter(explode(',', $filterArr['mimetype']));
foreach ($mimetypeArr as $index => $item) {
$query->whereOr('mimetype', 'like', '%' . str_replace("/*", "/", $item) . '%');
}
};
} elseif (isset($filterArr['mimetype'])) {
$where['mimetype'] = ['like', '%' . $filterArr['mimetype'] . '%'];
}
if (isset($filterArr['filename'])) {
$where['filename'] = ['like', '%' . $filterArr['filename'] . '%'];
}
if (isset($filterArr['createtime'])) {
$timeArr = explode(' - ', $filterArr['createtime']);
$where['createtime'] = ['between', [strtotime($timeArr[0]), strtotime($timeArr[1])]];
}
$search = $this->request->get('search');
if ($search) {
$where['filename'] = ['like', '%' . $search . '%'];
}
$model = new Attachment();
$offset = $this->request->get("offset", 0);
$limit = $this->request->get("limit", 0);
$total = $model
->where($where)
->where($mimetypeQuery)
->where('user_id', $this->auth->id)
->order("id", "DESC")
->count();
$list = $model
->where($where)
->where($mimetypeQuery)
->where('user_id', $this->auth->id)
->order("id", "DESC")
->limit($offset, $limit)
->select();
$cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $this->request->root());
foreach ($list as $k => &$v) {
$v['fullurl'] = ($v['storage'] == 'local' ? $cdnurl : $this->view->config['upload']['cdnurl']) . $v['url'];
}
unset($v);
$result = array("total" => $total, "rows" => $list);
return json($result);
}
$mimetype = $this->request->get('mimetype', '');
$mimetype = substr($mimetype, -1) === '/' ? $mimetype . '*' : $mimetype;
$this->view->assign('mimetype', $mimetype);
$this->view->assign("mimetypeList", \app\common\model\Attachment::getMimetypeList());
return $this->view->fetch();
}
public function authenticationflayers()
{
//获取用户id
$user_id = $this->auth->id;
if (empty($user_id)){
$this->error("请先登录!",url('user/login'));
}
$Players = new Players();
$players_info = $Players
->where('member_id', $user_id)
->find();
if (empty($players_info)){
return $this->view->fetch('identitylist');
}
$this->view->assign('title', "身份认证");
$this->view->assign('players', $players_info);
return $this->view->fetch();
}
public function identitylist()
{
return $this->view->fetch();
}
/**
* @DESC 更新用户信息
*/
public function updateuser()
{
$update_data['nickname'] = $this->request->post("nick_name");
$update_data['wechat'] = $this->request->post("vx");
$update_data['qq'] = $this->request->post("qq");
$update_data['avatar'] = $this->request->post("avater");
$player_data['fai_number'] = $this->request->post("fai_number");
$player_data['updated_at'] = date("Y-m-d H:i:s", time());
// $update_data['type'] = $this->request->post("type");
// var_dump($update_data);exit;
try {
$playersModel = new Players();
$userModel = new \app\common\model\User();
$userModel->update($update_data, ['id' => $this->auth->id]);
// if(!empty($player_data['fai_number'])){
// $userinfo = $userModel->where('id',$this->auth->id)->find();
$playersModel->update($player_data, ['member_id' => $this->auth->id]);
// }
}catch (Exception $exception){
$this->error($exception->getMessage());
}
if($this->request->post("type") == 'douyin'){
return json(array('code'=>1,'message'=>'success'));
}
$this->success("保存成功 / Save successfully");
}
/**
* @Author Soar
* @DESC 注册飞手
* @return json
*/
public function registeredFlyer(Request $request)
{
$user_id = $this->auth->id;
$club = new ClubModel();
$club_res =$club->where('user_id',$user_id)->find();
if(!empty($club_res)) $this->error('该账号已注册过俱乐部身份');
// var_dump($user_id);exit;
$id = $this->request->post("id");
$add_data['real_name'] = $this->request->post("real_name");
$add_data['gender'] = $this->request->post("gender");
$add_data['birthday'] = $this->request->post("birthday");
$add_data['age'] = $this->request->post("age");
$add_data['country'] = $this->request->post("country");
$add_data['province'] = $this->request->post("province");
$add_data['city'] = $this->request->post("city");
$add_data['district'] = $this->request->post("district");
$add_data['address'] = $this->request->post("address");
$add_data['player_pic'] = $this->request->post("player_pic");
$add_data['experience'] = $this->request->post("experience");
$add_data['guarder_name'] = $this->request->post("guarder_name");
$add_data['guarder_phone'] = $this->request->post("guarder_phone");
$add_data['guarder_card_number'] = $this->request->post("guarder_card_number");
$add_data['guarder_card_type'] = $this->request->post("guarder_card_type");
$add_data['guarder_card_front_view'] = $this->request->post("guarder_card_front_view");
$add_data['guarder_card_back_view'] = $this->request->post("guarder_card_back_view");
$add_data['card_type'] = $this->request->post("card_type");
$add_data['card_number'] = $this->request->post("card_number");
$add_data['card_front_view'] = $this->request->post("card_front_view");
$add_data['card_back_view'] = $this->request->post("card_back_view");
$add_data['card_view_same'] = $this->request->post("card_view_same");
$add_data['guarder_card_view_same'] = $this->request->post("guarder_card_view_same");
$add_data['asfc_user'] = $this->request->post("asfc_user");
$add_data['membership_id'] = $this->request->post("membership_id");
$add_data['flight_number'] = $this->request->post("flight_number");
$add_data['club_members'] = $this->request->post("club_members");
$add_data['club_name'] = $this->request->post("club_name");
$add_data['duties'] = $this->request->post("duties");
$post_type = $this->request->post("post_type");
$add_data['counselor_name'] = $this->request->post("counselor_name");
$add_data['eng_name'] = $this->request->post("eng_name");
$add_data['fai_number'] = $this->request->post("fai_number");
$validate = [
["real_name", "require", '姓名不可为空!'],
["gender", "require", '请选择性别!'],
["birthday", "require", '出生日期不可为空!'],
["country", "require", '国籍不可为空!'],
["address", "require", '详细地址不可为空!'],
["player_pic", "require", '请上传证件照!'],
['card_front_view', 'require', "请上传正面证件照片"],
['card_number', 'require', "请输入{$add_data['card_type']}证件号码"]
];
if ($add_data['country'] == "中国 China"){
array_push(
$validate,
['province', 'require', "请选择省份"],
['city', 'require', "请选择市"],
['district', 'require', "请选择区/县"]
);
}
// 如果是 ASFC 获取会员编号
if ($add_data['asfc_user'] == Players::ASFC_VIP) {
array_push(
$validate,
['membership_id', 'require', '请填写 ASFC会员 证号!']
);
}
if ($add_data['club_members'] == Players::CLUP_USER) {
array_push(
$validate,
['club_name', 'require', '请填写俱乐部名称!'],
['duties', 'require', '请填写所在俱乐部职务!'],
);
}
if ($add_data['age'] < Players::ADULT) {
//监护人
array_push(
$validate,
['guarder_name', 'require', '请输入监护人姓名!'],
['guarder_phone', 'require', '请输入监护人手机号'],
['guarder_card_type', 'require', '请选择监护人证件类型'],
['guarder_card_number', 'require', "请输入监护人{$add_data['guarder_card_type']}证件号码"],
['guarder_card_front_view', 'require', "请上传监护人正面证件照片"],
// ['guarder_card_back_view', 'require', "请上传监护人{$add_data['guarder_card_type']}证件照片"]
);
//护照特殊判断
if ($add_data['guarder_card_type'] == Players::CARD_TYPE[0]){
array_push(
$validate,
['guarder_card_view_same', 'require', "请选择人像页类型"]
);
}
//排除护照单页的情况,背面必传
if (!($add_data['guarder_card_type'] == Players::CARD_TYPE[1] && isset($add_data["guarder_card_view_same"]) && $add_data["guarder_card_view_same"] == 2)) {
if ($add_data['guarder_card_type'] == Players::CARD_TYPE[1]){
array_push(
$validate,
['guarder_card_back_view', 'require', "请上传监护人证件签名页照片"]
);
}
array_push(
$validate,
['card_back_view', 'require', "请上传反面证件照片"],
['guarder_card_back_view', 'require', "请上传监护人反面证件照片"]
);
}
//比较麻烦的判断
if ($add_data["guarder_card_type"] == Players::CARD_TYPE[1] && $add_data["guarder_card_view_same"] == 2) {
$add_data["guarder_card_back_view"] = null;
} elseif ($add_data["guarder_card_type"] != "护照") {
$add_data["guarder_card_view_same"] = 1;
}
}else{
array_push(
$validate,
['card_type', 'require', '请选择证件类型!']
);
//护照特殊判断
if ($add_data['card_type'] == Players::CARD_TYPE[0]){
array_push(
$validate,
['card_view_same', 'require', "请选择人像页类型"]
);
}
//排除护照单页的情况,背面必传
if (!($add_data['card_type'] == Players::CARD_TYPE[1] && isset($add_data["card_view_same"]) && $add_data["card_view_same"] == 2)) {
if ($add_data['card_type'] == Players::CARD_TYPE[1]){
array_push(
$validate,
['card_back_view', 'require', "请上传证件签名页照片"]
);
}
array_push(
$validate,
['card_back_view', 'require', "请上传反面证件照片"]
);
}
//比较麻烦的判断
if ($add_data["card_type"] == "护照" && $add_data["card_view_same"] == 2) {
$add_data["card_back_view"] = null;
} elseif ($add_data["card_type"] != "护照") {
$add_data["card_view_same"] = 1;
}
}
$validate = new \think\Validate($validate);
if (!$validate->check($add_data)){
$this->error($validate->getError());
}
$playersModel = new Players();
$playersinfo = $playersModel->getPlayers($this->auth->id);
try {
$add_data['member_id'] = $this->auth->id;
$add_data['club_id'] = 0;
$add_data['phone'] = $this->auth->mobile;
$add_data['player_status'] = Players::PLAYERS_APPLYING;
$add_data['updated_at'] = date("Y-m-d H:i:s", time());
if ($id){
$add_data['id'] = $id;
$add_data['player_status'] = Players::PLAYERS_REAPPLY;
}else{
$add_data['created_at'] = date("Y-m-d H:i:s", time());
}
if($id){
$playersinfo->save($add_data);
}else{
// 判断该手机号和身份证是否存在
$playersModel->insert($add_data);
}
}catch (Exception $exception){
$this->error($exception->getMessage());
}
if ($id){
if (!empty($post_type) && $post_type == "json") {
return json(['code' => 1, 'date' => [], 'msg' => '重新申请成功']);
}
$this->success("重新申请成功!", url('players/index'));
}
if (!empty($post_type) && $post_type == "json") {
return json(['code' => 1, 'date' => [], 'msg' => '注册成功']);
}
//模板消息通知
$renzheng = new Renzheng();
$res = $renzheng->where('id',1)->find();
if(!empty($res)) $res = $res->toArray();
if($res['status'] == 1){
$wxmb = new Wxmb();
$wxmb->renzhengpush($add_data,$res['openid']);
}
$this->success("注册成功/successfully registered", url('players/index'));
}
//注册俱乐部
public function register_club(){
//俱乐部认证开关
$renzheng = new Renzheng();
$res = $renzheng->where('id',2)->find();
if(!empty($res)) $res = $res->toArray();
if($res['status'] == 0){
$this->error('2024年中国无人机竞速联赛参赛主体认证已截止。咨询电话:13136225305');
}
// $this->error('2024年中国无人机竞速联赛参赛主体预注册已截止请等待正式注册通知。咨询电话:13136225305');
// header('Access-Control-Allow-Origin:*');
// header('Access-Control-Allow-Methods:*');
// header('Access-Control-Allow-Headers:x-requested-with,content-type');
$user_id = $this->auth->id;
if (empty($user_id)){
$this->error("请先登录!",url('user/login'));
}
$club = new ClubModel();
$players = new Players();
$player_res = $players->where('member_id',$user_id)->find();
if(!empty($player_res)) $this->error('该账号已注册过飞手身份');
$id = $this->request->post("id");
$add_data['name'] = $this->request->post("name");
$add_data['name_short'] = $this->request->post("name_short");
$add_data['user_id'] = $user_id;
$add_data['competitors'] = $this->request->post("competitors");
$add_data['competitors_type'] = $this->request->post("competitors_type"); //主体类型
// $add_data['type'] = 1;
$add_data['business_num'] = $this->request->post("business_num");
$add_data['business_license'] = $this->request->post("business_license");
$add_data['card_front_view'] = $this->request->post("card_front_view"); //法人身份证
$add_data['card_back_view'] = $this->request->post("card_back_view");
$add_data['is_asfc'] = $this->request->post("is_asfc"); //是否中国航空团体会员 0否 1是
$add_data['asfc_num'] = $this->request->post("asfc_num"); //证书编号
$add_data['asfc_cert'] = $this->request->post("asfc_cert"); //证书
$add_data['province'] = $this->request->post("province");
$add_data['city'] = $this->request->post("city");
$add_data['district'] = $this->request->post("district");
$add_data['address'] = $this->request->post("address");
$add_data['logo'] = $this->request->post("logo");
$add_data['flag'] = $this->request->post("flag");
$add_data['competition_slogan'] = $this->request->post("competition_slogan");
$add_data['legal_name'] = $this->request->post("legal_name"); //法人
$add_data['legal_tel'] = $this->request->post("legal_tel");
$add_data['legal_card'] = $this->request->post("legal_card");
// var_dump($add_data['leader_tel']);exit;
$add_data['leader'] = $this->request->post("leader"); //领队
$add_data['leader_tel'] = intval($this->request->post("leader_tel"));
// var_dump($add_data['leader_tel']);exit;
$add_data['deputy_leader1'] = $this->request->post("deputy_leader1"); //副领队1
$add_data['deputy_leader1_tel'] = $this->request->post("deputy_leader1_tel");
$add_data['deputy_leader2'] = $this->request->post("deputy_leader2"); //副领队2
$add_data['deputy_leader2_tel'] = $this->request->post("deputy_leader2_tel");
$add_data['head_coach'] = $this->request->post("head_coach"); //主教练
$add_data['head_coach_tel'] = $this->request->post("head_coach_tel");
$add_data['coach1'] = $this->request->post("coach1");
$add_data['coach1_tel'] = $this->request->post("coach1_tel");
$add_data['coach2'] = $this->request->post("coach2");
$add_data['coach2_tel'] = $this->request->post("coach2_tel");
$add_data['coach3'] = $this->request->post("coach3");
$add_data['coach3_tel'] = $this->request->post("coach3_tel");
$add_data['coach4'] = $this->request->post("coach4");
$add_data['coach4_tel'] = $this->request->post("coach4_tel");
$add_data['player_coach_stuff'] = $this->request->post("player_coach_stuff"); //运动员教练名单
$add_data['job_situ'] = $this->request->post("job_situ"); //工作情况
$add_data['promise_stuff'] = $this->request->post("promise_stuff"); //参赛承诺
$add_data['is_media'] = $this->request->post("is_media"); //是否有媒体宣传账号
$add_data['media_platform'] = $this->request->post("media_platform"); //媒体平台
$add_data['media_name'] = $this->request->post("media_name"); //
$add_data['club_clothes1'] = $this->request->post("club_clothes1"); //
$add_data['club_clothes2'] = $this->request->post("club_clothes2"); //
$add_data['club_clothes3'] = $this->request->post("club_clothes3"); //
$add_data['club_clothes4'] = $this->request->post("club_clothes4"); //
// $add_data['hk_card'] = $this->request->post("hk_card"); //
$add_data['status'] = 1;
$add_data['createtime'] = time();
$add_data['updatetime'] = time();
$validate = [
["name", "require", '俱乐部名称不可为空!'],
["competitors", "require", '赛事主体不可为空!'],
["business_license", "require", '请上传营业执照!'],
["logo", "require", '请上传俱乐部队徽!'],
["flag", "require", '请上传俱乐部队旗!'],
['province', 'require', "请选择省份"],
['city', 'require', "请选择市"],
['district', 'require', "请选择区/县"],
["address", "require", '详细地址不可为空!'],
// ["player_pic", "require", '请上传证件照!'],
['card_front_view', 'require', "请上传法人正面证件照片"],
['card_back_view', 'require', "请上传法人反面证件照片"],
['legal_name', 'require', "法人名称不可为空"],
['legal_tel', 'require', "法人电话不可为空"],
['legal_card', 'require', "法人身份证不可为空"],
// ['gym_nature', 'require', "场地性质不可为空"],
// ['respon_tel', 'require', "负责人电话不可为空"],
['deputy_leader1_tel', 'require', "副领队1电话不可为空"],
['deputy_leader2', 'require', "副领队2名称不可为空"],
['deputy_leader2_tel', 'require', "副领队2电话不可为空"],
['head_coach', 'require', "主教练名称不可为空"],
['head_coach_tel', 'require', "主教练电话不可为空"],
['coach1', 'require', "教练员1名称不可为空"],
['coach1_tel', 'require', "教练员1电话不可为空"],
];
$validate = new \think\Validate($validate);
if (!$validate->check($add_data)){
$this->error($validate->getError());
}
$club_res = $club->where('competitors',$add_data['competitors'])->where('status',9)->find();
if(!empty($club_res)) $this->error('参赛主体已注册');
$club->insert($add_data);
//微信通知
$renzheng = new Renzheng();
$res = $renzheng->where('id',1)->find();
if(!empty($res)) $res = $res->toArray();
if($res['status'] == 1){
$wxmb = new Wxmb();
$wxmb->clubpush($add_data,$res['openid']);
}
$this->success("提交成功", url('club/index'));
}
//重新申请俱乐部
public function club_resubmit(){
$user_id = $this->auth->id;
if (empty($user_id)){
$this->error("请先登录!",url('user/login'));
}
$club = new ClubModel();
$players = new Players();
$player_res = $players->where('member_id',$user_id)->find();
if(!empty($player_res)) $this->error('该账号已注册过飞手身份');
$id = $this->request->post("id");
if(empty($id)) $this->error("缺少参数!");
$club_res = $club->where('id',$id)->where('user_id',$user_id)->find();
if(empty($club_res)) $this->error("没有权限!");
$add_data['name'] = $this->request->post("name");
$add_data['name_short'] = $this->request->post("name_short");
$add_data['user_id'] = $user_id;
$add_data['competitors'] = $this->request->post("competitors");
$add_data['competitors_type'] = $this->request->post("competitors_type"); //主体类型
// $add_data['type'] = 1;
$add_data['business_num'] = $this->request->post("business_num"); //营业执照编号
// var_dump($add_data);exit;
$add_data['business_license'] = $this->request->post("business_license");
$add_data['card_front_view'] = $this->request->post("card_front_view");
$add_data['card_back_view'] = $this->request->post("card_back_view");
$add_data['is_asfc'] = $this->request->post("is_asfc"); //是否中国航空团体会员 0否 1是
$add_data['asfc_num'] = $this->request->post("asfc_num"); //证书编号
$add_data['asfc_cert'] = $this->request->post("asfc_cert");
$add_data['province'] = $this->request->post("province");
$add_data['city'] = $this->request->post("city");
$add_data['district'] = $this->request->post("district");
$add_data['address'] = $this->request->post("address");
$add_data['logo'] = $this->request->post("logo");
$add_data['flag'] = $this->request->post("flag");
$add_data['competition_slogan'] = $this->request->post("competition_slogan");
$add_data['legal_name'] = $this->request->post("legal_name"); //法人
$add_data['legal_tel'] = $this->request->post("legal_tel");
$add_data['legal_card'] = $this->request->post("legal_card");
// var_dump($add_data['leader_tel']);exit;
$add_data['leader'] = $this->request->post("leader"); //领队
$add_data['leader_tel'] = intval($this->request->post("leader_tel"));
// var_dump($add_data['leader_tel']);exit;
$add_data['deputy_leader1'] = $this->request->post("deputy_leader1"); //副领队1
$add_data['deputy_leader1_tel'] = $this->request->post("deputy_leader1_tel");
$add_data['deputy_leader2'] = $this->request->post("deputy_leader2"); //副领队2
$add_data['deputy_leader2_tel'] = $this->request->post("deputy_leader2_tel");
$add_data['head_coach'] = $this->request->post("head_coach"); //主教练
$add_data['head_coach_tel'] = $this->request->post("head_coach_tel");
$add_data['coach1'] = $this->request->post("coach1");
$add_data['coach1_tel'] = $this->request->post("coach1_tel");
$add_data['coach2'] = $this->request->post("coach2");
$add_data['coach2_tel'] = $this->request->post("coach2_tel");
$add_data['coach3'] = $this->request->post("coach3");
$add_data['coach3_tel'] = $this->request->post("coach3_tel");
$add_data['coach4'] = $this->request->post("coach4");
$add_data['coach4_tel'] = $this->request->post("coach4_tel");
$add_data['player_coach_stuff'] = $this->request->post("player_coach_stuff"); //运动员教练名单
$add_data['job_situ'] = $this->request->post("job_situ"); //工作情况
$add_data['promise_stuff'] = $this->request->post("promise_stuff"); //参赛承诺
$add_data['is_media'] = $this->request->post("is_media"); //是否有媒体宣传账号
$add_data['media_platform'] = $this->request->post("media_platform"); //媒体平台
$add_data['media_name'] = $this->request->post("media_name"); //
$add_data['club_clothes1'] = $this->request->post("club_clothes1"); //
$add_data['club_clothes2'] = $this->request->post("club_clothes2"); //
$add_data['club_clothes3'] = $this->request->post("club_clothes3"); //
$add_data['club_clothes4'] = $this->request->post("club_clothes4"); //
// $add_data['hk_card'] = $this->request->post("hk_card"); //
$add_data['status'] = 4;
$add_data['updatetime'] = time();
$validate = [
["name", "require", '俱乐部名称不可为空!'],
["competitors", "require", '赛事主体不可为空!'],
["business_license", "require", '请上传营业执照!'],
["logo", "require", '请上传俱乐部队徽!'],
["flag", "require", '请上传俱乐部队旗!'],
['province', 'require', "请选择省份"],
['city', 'require', "请选择市"],
['district', 'require', "请选择区/县"],
["address", "require", '详细地址不可为空!'],
// ["player_pic", "require", '请上传证件照!'],
['card_front_view', 'require', "请上传法人正面证件照片"],
['card_back_view', 'require', "请上传法人反面证件照片"],
['leader', 'require', "领队名称不可为空"],
['leader_tel', 'require', "领队电话不可为空"],
['deputy_leader1', 'require', "副领队1名称不可为空"],
['deputy_leader1_tel', 'require', "副领队1电话不可为空"],
['deputy_leader2', 'require', "副领队2名称不可为空"],
['deputy_leader2_tel', 'require', "副领队2电话不可为空"],
['head_coach', 'require', "主教练名称不可为空"],
['head_coach_tel', 'require', "主教练电话不可为空"],
['coach1', 'require', "教练员1名称不可为空"],
['coach1_tel', 'require', "教练员1电话不可为空"],
];
$validate = new \think\Validate($validate);
if (!$validate->check($add_data)){
$this->error($validate->getError());
}
// $club_res = $club->where('competitors',$add_data['competitors'])->where('status',9)->find();
// if(!empty($club_res)) $this->error('参赛主体已注册');
$club->save($add_data,['id'=>$id]);
//微信通知
$renzheng = new Renzheng();
$res = $renzheng->where('id',1)->find();
if(!empty($res)) $res = $res->toArray();
if($res['status'] == 1){
$wxmb = new Wxmb();
$wxmb->clubpush($add_data,$res['openid']);
}
$this->success("重新申请成功!", url('club/index'));
}
}