330 lines
11 KiB
PHP
330 lines
11 KiB
PHP
|
<?php
|
|||
|
/**
|
|||
|
* @Created by PhpStorm.
|
|||
|
* @Author:Soar
|
|||
|
* @Time:2023/7/19 14:44
|
|||
|
*/
|
|||
|
namespace app\admin\controller;
|
|||
|
|
|||
|
use addons\cms\model\Player;
|
|||
|
use app\admin\model\cms\Archives;
|
|||
|
use app\admin\model\MatchContestant;
|
|||
|
use app\admin\model\MessageLog;
|
|||
|
use app\admin\model\Players;
|
|||
|
use app\common\controller\Backend;
|
|||
|
use think\Db;
|
|||
|
use app\admin\model\Club;
|
|||
|
use app\common\model\User;
|
|||
|
use app\admin\model\shopro\ClubThirdOauth;
|
|||
|
use app\index\controller\Wxmb;
|
|||
|
|
|||
|
class Contestants extends Backend
|
|||
|
{
|
|||
|
/**
|
|||
|
* @var \app\admin\model\cms\Archives
|
|||
|
*/
|
|||
|
protected $model = null;
|
|||
|
|
|||
|
public function _initialize()
|
|||
|
{
|
|||
|
parent::_initialize();
|
|||
|
$this->model = new MatchContestant();
|
|||
|
}
|
|||
|
|
|||
|
public function check_leagueuser()
|
|||
|
{
|
|||
|
$Club = new Club();
|
|||
|
$User = new User();
|
|||
|
$Wxmb = new Wxmb();
|
|||
|
$archives = new Archives();
|
|||
|
$ClubThirdOauth = new ClubThirdOauth();
|
|||
|
$type = $this->request->param('type');
|
|||
|
$id = $this->request->param('ids');
|
|||
|
$mark = $this->request->param('mark');
|
|||
|
$apply_res = $this->model->field('match_id,club_id')->where('id', 'eq', $id)->find();
|
|||
|
$club_info = $Club->where("id", $apply_res['club_id'])->find();
|
|||
|
$user_info = $User->where('id',$club_info['user_id'])->find();
|
|||
|
// $matchId = $apply_res['match_id'];
|
|||
|
// var_dump($matchId['match_id']);exit;
|
|||
|
// $apply_allplayer = $this->model->where(['club_id'=>$apply_res['club_id'],'match_id'=>$apply_res['match_id'],'club_status'=>1])->find();
|
|||
|
$apply_allplayer = $this->model->where(['club_id'=>$apply_res['club_id'],'match_id'=>$apply_res['match_id']])->select();
|
|||
|
|
|||
|
$info = $this->model->find($id);
|
|||
|
if (empty($apply_res)){
|
|||
|
$this->error(__("信息出错,请刷新后重试!"));
|
|||
|
}
|
|||
|
|
|||
|
if ($type == "pass"){
|
|||
|
// 启动事务
|
|||
|
Db::startTrans();
|
|||
|
try{
|
|||
|
// var_dump($apply_allplayer);exit;
|
|||
|
foreach ($apply_allplayer as $value){
|
|||
|
$data = array('status'=>2,'updated_at' => date("Y-m-d H:i:s", time()));
|
|||
|
$this->model->where('id', $value['id'])->data($data,true)->update();
|
|||
|
}
|
|||
|
// 提交事务
|
|||
|
Db::commit();
|
|||
|
} catch (\Exception $e) {
|
|||
|
// 回滚事务
|
|||
|
Db::rollback();
|
|||
|
$this->error(__("操作失败!"));
|
|||
|
}
|
|||
|
$oauth_res = $ClubThirdOauth->where('user_id',$club_info['user_id'])->find();
|
|||
|
if(!empty($oauth_res)){
|
|||
|
$oauth_res = $oauth_res->toArray();
|
|||
|
$push_arr = array('title'=>'赛事报名审核通过','username'=> $club_info['name_short'],'type'=>'系统通知');
|
|||
|
$Wxmb->leaguepush($push_arr,$oauth_res['openid']);
|
|||
|
}
|
|||
|
#发短信
|
|||
|
if (!empty($user_info->mobile)) {
|
|||
|
// $user_info->mobile = '13626832346';
|
|||
|
$match_info = $archives->find($info->match_id);
|
|||
|
$alisms = new \addons\alisms\library\Alisms();
|
|||
|
$config = get_addon_config('alisms');
|
|||
|
$template = "SMS_466345112";
|
|||
|
// $sign = $config['sign'];
|
|||
|
$sign = '中国无人机竞速联赛';
|
|||
|
$param = [
|
|||
|
'name' => $club_info->name_short,
|
|||
|
'content' => "《" . $match_info->title . "》"
|
|||
|
];
|
|||
|
$res = $alisms->mobile($user_info->mobile)
|
|||
|
->template($template)
|
|||
|
->sign($sign)
|
|||
|
->param($param)
|
|||
|
->send();
|
|||
|
}
|
|||
|
|
|||
|
$this->success(__("审核成功!"));
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
if ($type == "refuse"){
|
|||
|
//获取飞手信息
|
|||
|
|
|||
|
if (!empty($user_info->mobile)) {
|
|||
|
// $user_info->mobile = '13626832346';
|
|||
|
// var_dump($user_info->mobile);exit;
|
|||
|
//获取赛事信息
|
|||
|
$match_info = $archives->find($info->match_id);
|
|||
|
$alisms = new \addons\alisms\library\Alisms();
|
|||
|
$config = get_addon_config('alisms');
|
|||
|
$template = "SMS_466440085";
|
|||
|
$sign = '中国无人机竞速联赛';
|
|||
|
$param = [
|
|||
|
'name' => $club_info->name_short,
|
|||
|
'content' => "《" . $match_info->title . "》"
|
|||
|
];
|
|||
|
// var_dump($club_info->name_short);exit;
|
|||
|
$res = $alisms->mobile($user_info->mobile)
|
|||
|
->template($template)
|
|||
|
->sign($sign)
|
|||
|
->param($param)
|
|||
|
->send();
|
|||
|
// var_dump($res);exit;
|
|||
|
|
|||
|
Db::startTrans();
|
|||
|
try{
|
|||
|
// var_dump($apply_allplayer);exit;
|
|||
|
foreach ($apply_allplayer as $value){
|
|||
|
$data = array('status'=> -1,'updated_at' => date("Y-m-d H:i:s", time()));
|
|||
|
$this->model->where('id', $value['id'])->data($data,true)->update();
|
|||
|
}
|
|||
|
// exit;
|
|||
|
// 提交事务
|
|||
|
Db::commit();
|
|||
|
} catch (\Exception $e) {
|
|||
|
// 回滚事务
|
|||
|
Db::rollback();
|
|||
|
$this->error(__("操作失败2!"));
|
|||
|
}
|
|||
|
$this->success(__("驳回成功!"));
|
|||
|
$messageLogModel = new MessageLog();
|
|||
|
|
|||
|
$message_log_id = $messageLogModel->insertGetId(
|
|||
|
[
|
|||
|
'phone' => $user_info->mobile,
|
|||
|
'code' => $param['content'],
|
|||
|
'code2' => $mark,
|
|||
|
'type' => 4,
|
|||
|
'used' => 0,
|
|||
|
'template_id' => $template,
|
|||
|
'created_at' => date("Y-m-d H:i:s", time())
|
|||
|
]
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
$info->save(['message_logs_id' => $message_log_id]);
|
|||
|
|
|||
|
if ($info->save(['status' => -1, 'updated_at' => date("Y-m-d H:i:s", time()), 'mark' => $mark])){
|
|||
|
$this->success(__("审核成功!"));
|
|||
|
}
|
|||
|
|
|||
|
$this->error(__("审核失败!"));
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public function check_user()
|
|||
|
{
|
|||
|
$type = $this->request->param('type');
|
|||
|
$id = $this->request->param('ids');
|
|||
|
$mark = $this->request->param('mark');
|
|||
|
|
|||
|
$info = $this->model->find($id);
|
|||
|
if (empty($info)){
|
|||
|
$this->error(__("信息出错,请刷新后重试!"));
|
|||
|
}
|
|||
|
|
|||
|
if ($type == "pass"){
|
|||
|
if ($info->save(['status' => 2, 'updated_at' => date("Y-m-d H:i:s", time())])){
|
|||
|
$this->success(__("审核成功!"));
|
|||
|
}
|
|||
|
|
|||
|
$this->error(__("审核失败!"));
|
|||
|
}
|
|||
|
|
|||
|
if ($type == "refuse"){
|
|||
|
//获取飞手信息
|
|||
|
$playerModel = new Players();
|
|||
|
$player_info = $playerModel->with('member')->find($info->player_id);
|
|||
|
if (!empty($player_info->phone)) {
|
|||
|
//获取赛事信息
|
|||
|
$archives = new Archives();
|
|||
|
$match_info = $archives->find($info->match_id);
|
|||
|
|
|||
|
$alisms = new \addons\alisms\library\Alisms();
|
|||
|
|
|||
|
$config = get_addon_config('alisms');
|
|||
|
|
|||
|
$template = "SMS_463726010";
|
|||
|
|
|||
|
$sign = $config['sign'];
|
|||
|
$param = [
|
|||
|
'name' => $player_info->real_name,
|
|||
|
'content' => "《" . $match_info->title . "》"
|
|||
|
];
|
|||
|
|
|||
|
$alisms->mobile($player_info->phone)
|
|||
|
->template($template)
|
|||
|
->sign($sign)
|
|||
|
->param($param)
|
|||
|
->send();
|
|||
|
|
|||
|
$messageLogModel = new MessageLog();
|
|||
|
|
|||
|
$message_log_id = $messageLogModel->insertGetId(
|
|||
|
[
|
|||
|
'phone' => $player_info->phone,
|
|||
|
'code' => $param['content'],
|
|||
|
'code2' => $mark,
|
|||
|
'type' => 4,
|
|||
|
'used' => 0,
|
|||
|
'template_id' => $template,
|
|||
|
'created_at' => date("Y-m-d H:i:s", time())
|
|||
|
]
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
$info->save(['message_logs_id' => $message_log_id]);
|
|||
|
|
|||
|
if ($info->save(['status' => -1, 'updated_at' => date("Y-m-d H:i:s", time()), 'mark' => $mark])){
|
|||
|
$this->success(__("审核成功!"));
|
|||
|
}
|
|||
|
|
|||
|
$this->error(__("审核失败!"));
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public function sendSMS()
|
|||
|
{
|
|||
|
$id = $this->request->param('ids');
|
|||
|
//获取飞手信息
|
|||
|
$match_contestants_info = $this->model->find($id);
|
|||
|
|
|||
|
if (empty($match_contestants_info)){
|
|||
|
$this->error(__("信息出错,请刷新后重试!"));
|
|||
|
}
|
|||
|
|
|||
|
if ($match_contestants_info->status != 2){
|
|||
|
$this->error(__("无法给审核未通过的选手发送短信!"));
|
|||
|
}
|
|||
|
|
|||
|
//获取飞手信息
|
|||
|
$playerModel = new Players();
|
|||
|
$player_info = $playerModel->with('member')->find($match_contestants_info->player_id);
|
|||
|
|
|||
|
$archives = new Archives();
|
|||
|
$match_info = $archives->find($match_contestants_info->match_id);
|
|||
|
|
|||
|
if (empty($player_info) || empty($player_info->member)){
|
|||
|
$this->error(__("获取用户信息出错!"));
|
|||
|
}
|
|||
|
$mobile = $player_info->phone ? $player_info->phone : $player_info->member->mobile;
|
|||
|
|
|||
|
if (empty($mobile) || !isset($mobile)){
|
|||
|
$this->error(__("获取用户手机号出错!"));
|
|||
|
}
|
|||
|
|
|||
|
$alisms = new \addons\alisms\library\Alisms();
|
|||
|
|
|||
|
$config = get_addon_config('alisms');
|
|||
|
|
|||
|
$template = $config['template']['notice'];
|
|||
|
|
|||
|
$sign = $config['sign'];
|
|||
|
$param = [
|
|||
|
'name' => $player_info->real_name,
|
|||
|
'matchTitle' => "《" . $match_info->title . "》"
|
|||
|
];
|
|||
|
|
|||
|
$ret = $alisms->mobile($mobile)
|
|||
|
->template($template)
|
|||
|
->sign($sign)
|
|||
|
->param($param)
|
|||
|
->send();
|
|||
|
|
|||
|
$messageLogModel = new MessageLog();
|
|||
|
|
|||
|
$message_log_id = $messageLogModel->insertGetId(
|
|||
|
[
|
|||
|
'phone' => $mobile,
|
|||
|
'type' => 4,
|
|||
|
'used' => 0,
|
|||
|
'template_id' => $template,
|
|||
|
'created_at' => date("Y-m-d H:i:s", time())
|
|||
|
]
|
|||
|
);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
if ($ret && $message_log_id && $match_contestants_info->save(['message_logs_id' => $message_log_id])){
|
|||
|
$this->success(__("发送成功!"));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 删除
|
|||
|
* @param mixed $ids
|
|||
|
*/
|
|||
|
public function del($ids = "")
|
|||
|
{
|
|||
|
$res = $this->model->where('id',intval($ids))->find();
|
|||
|
// var_dump($res);exit;
|
|||
|
if($res['club_id']){
|
|||
|
$contes_res = $this->model->where('club_id',$res['club_id'])->where('match_id',$res['match_id'])->select();
|
|||
|
$str = '';
|
|||
|
foreach ($contes_res as $val){
|
|||
|
$str = $str.','.$val['id'];
|
|||
|
}
|
|||
|
parent::del($str);
|
|||
|
}else{
|
|||
|
parent::del($ids);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|