This commit is contained in:
knowpia
2022-09-08 15:23:13 +08:00
commit 96a49d1bd6
26 changed files with 1597 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
<?php
namespace app\controller;
use think\facade\Db;
class Address
{
//地址管理
public function lists(){
$userid = $GLOBALS['data']['userid'];
if (empty($userid)) {
return show("请登录后再发布!");
}
$list = Db::name("app_address")->where("userid",$userid)->select()->toArray();
return show("获取成功!",SUCCESS_CODE,$list);
}
//地址详细信息
public function getaddress(){
$userid = $GLOBALS['data']['userid'];
if (empty($userid)) {
return show("请登录后再发布!");
}
$address_id = $GLOBALS['data']['data']['address_id'];
if (empty($address_id)) {
return show("请输入地址编号!");
}
$info = Db::name("app_address")->where("id",$address_id)->find();
if(empty($info) || $info['userid']!=$userid){
return show("找不到该地址信息!");
}
return show("获取成功!",SUCCESS_CODE,$info);
}
//添加地址
public function plus()
{
$post = $GLOBALS['data']['data'];
$userid = $GLOBALS['data']['userid'];
if (empty($userid)) {
return show("请登录后再发布!");
}
if(empty($post['name'])) return show("请输入收货人收件人姓名!");
if(empty($post['mobile'])) return show("请输入收货人电话!");
if(empty($post['province'])) return show("请输入省份!");
if(empty($post['city'])) return show("请输入城市!");
if(empty($post['area'])) return show("请输入区!");
if(empty($post['detail'])) return show("请输入详细地址!");
$default = $post['is_default'];
if(!in_array($default, [0,1])){
return show("默认地址值超出范围!");
}else{
if($default == 1){
Db::name("app_address")->where("userid",$userid)->update(["is_default"=>0]);
}
}
Db::name("app_address")->insert([
"userid"=>$userid,
"name"=>$post['name'],
"mobile"=>$post['mobile'],
"province"=>$post['province'],
"city"=>$post['city'],
"area"=>$post['area'],
"detail"=>$post['detail'],
"is_default"=>$post['is_default'],
]);
return show("添加成功!", SUCCESS_CODE, []);
}
}

116
app/controller/Article.php Normal file
View File

@@ -0,0 +1,116 @@
<?php
namespace app\controller;
use think\facade\Db;
class Article
{
public function plus()
{
$post = $GLOBALS['data']['data'];
$userid = $GLOBALS['data']['userid'];
if(empty($userid)){
return show("请登录后再发布!");
}
if(empty($post['content'])){
return show("内容不能为空!");
}
if(empty($post['imgs'])){
return show("图片不能为空!");
}
Db::name("app_article")->insert([
"text"=>$post['content'],
"imgs"=>$post['imgs'],
"userid"=>$userid,
"createtime"=>time(),
"click"=>0
]);
Db::name("student")->inc("article_count",1)->where("id",$userid)->update();
return show("发布成功!",SUCCESS_CODE,[]);
}
public function delete(){
$userid = $GLOBALS['data']['userid'];
if(empty($userid)){
return show("请登录后操作!");
}
$article_id = $GLOBALS['data']['data']["article_id"];
if(empty($article_id)){
return show("请上输入动态ID");
}
$info = Db::name("app_article")->where("id",$article_id)->find();
if(empty($info) || $info['userid']!=$userid){
return show("找不到该动态信息!");
}
Db::name("app_article")->where("id",$article_id)->delete();
return show("删除成功!",SUCCESS_CODE,[]);
}
public function lists(){
$userid = $GLOBALS['data']['userid'];
if(empty($userid)){
return show("请登录后操作!");
}
$lastIndex = empty($GLOBALS['data']['data']["lastindex"])?0:$GLOBALS['data']['data']["lastindex"];
if($lastIndex == 0){
$where = "userid={$userid} and id>0";
}else{
$where = "userid={$userid} and id<".$lastIndex;
}
$result["lastIndex"] = 0;
$list = Db::name("app_article")->where($where)->order("id desc")->order('id desc')->limit(env("page_count"))->select()->toArray();
foreach($list as $vo){
$result['lastIndex'] = $vo['id'];
$result["list"][] = $vo;
}
if(count($list)<env("page_count")){
$result["lastIndex"] = 0;
}
return show(SUCCESS_MESSAGE,SUCCESS_CODE,$result);
}
public function detail(){
if(empty($GLOBALS['data']['data']['article_id'])){
return show("请上传动态ID");
}
$article_id = $GLOBALS['data']['data']['article_id'];
$info = Db::name('app_article')->where("id",$article_id)->find();
if(empty($info)) return show("找不到该动态信息!");
return show(SUCCESS_MESSAGE,SUCCESS_CODE,$info);
}
public function getlists(){
$userid = $GLOBALS['data']['userid'];
if(empty($userid)){
return show("请登录后操作!");
}
if(empty($GLOBALS['data']['data']['student_userid'])){
return show("请输入用户ID");
}
$student_userid = $GLOBALS['data']['data']['student_userid'];
$student = Db::name("student")->field("id")->where("id",$student_userid)->find();
if(empty($student)) return show("找不到用户信息!");
$lastIndex = empty($GLOBALS['data']['data']["lastindex"])?0:$GLOBALS['data']['data']["lastindex"];
if($lastIndex == 0){
$where = "userid={$student_userid} and id>0";
}else{
$where = "userid={$student_userid} and id<".$lastIndex;
}
$result["lastIndex"] = 0;
$list = Db::name("app_article")->where($where)->order("id desc")->order('id desc')->limit(env("page_count"))->select()->toArray();
foreach($list as $vo){
$result['lastIndex'] = $vo['id'];
$result["list"][] = $vo;
}
if(count($list)<env("page_count")){
$result["lastIndex"] = 0;
}
return show(SUCCESS_MESSAGE,SUCCESS_CODE,$result);
}
}

103
app/controller/Help.php Normal file
View File

@@ -0,0 +1,103 @@
<?php
namespace app\controller;
use think\facade\Db;
class Help
{
//为用户助力
public function me()
{
$userid = $GLOBALS['data']['userid'];
if(empty($userid)){
return show("请登录后再助力!");
}
if(empty($GLOBALS['data']['data']['student_id'])){
return show("请输入要助力的用户id");
}
$student_id = $GLOBALS['data']['data']['student_id'];
$info = Db::name("student")->where("id",$student_id)->field("id")->find();
if(empty($info)){
return show("找不到该学生信息!");
}
$data = [
"userid"=>$userid,
"student_id"=>$student_id,
"createtime"=>date("Y-m-d",time())
];
$data['sha'] = sha1(json_encode($data));
Db::startTrans();
try {
$info = Db::name("app_help_log")->where("sha", $data['sha'])->find();
if (!empty($info)) {
return show("你今天已经为他助力过,谢谢!");
} else {
Db::name("app_help_log")->insert($data);
}
$appHelp = Db::name("app_help")->where(["userid" => $userid, "student_id" => $student_id])->find();
if (empty($appHelp)) {
Db::name("app_help")->insert([
"userid" => $userid,
"student_id" => $student_id,
"count" => 1
]);
} else {
Db::name("app_help")->where(["id" => $appHelp['id']])->inc("count", 1)->update();
}
Db::commit();
return show("助力成功!", SUCCESS_CODE, []);
}catch (\Exception $e) {
Db::rollback();
return show("助力失败!");
}
}
public function lists(){
if(empty($GLOBALS['data']['data']['student_id'])){
return show("请输入要助力的用户id");
}
$student_id = $GLOBALS['data']['data']['student_id'];
$info = Db::name("student")->where("id",$student_id)->field("id")->find();
if(empty($info)){
return show("找不到该学生信息!");
}
$lastIndex = lastindex();
if($lastIndex == 0) {
$lastIndex = 1;
}
$result = [];
$list = Db::name("appHelp")->where("student_id",$student_id)->limit(env("page_count"))->order('count desc')->paginate([
"list_rows"=>env("page_count"),
"page"=>$lastIndex
]);
if(empty($list)) return show("获取成功", SUCCESS_CODE,$result);
if($list->currentPage() < $list->lastPage()){
$result['lastIndex'] = $lastIndex +1;
}else{
$result['lastIndex'] = 0;
}
$users = getAllUsersMessage($list,'userid','id,nickname,avatar');
foreach($list as $vo){
$result['list'][] = [
"id"=>$vo['id'],
"userid"=>$vo['userid'],
"username"=>empty($users[$vo['userid']]['nickname'])?'':$users[$vo['userid']]['nickname'],
"count"=>$vo['count']
];
}
return show("获取成功!", SUCCESS_CODE, $result);
}
}

145
app/controller/Main.php Normal file
View File

@@ -0,0 +1,145 @@
<?php
namespace app\controller;
//use app\model\AppToken;
class Main
{
public function index()
{
// $j = ["userid"=>1];
// echo authcode(json_encode($j),'f');
$GLOBALS['data'] = []; // 全局变量
$api_version = ''; //当前版本号
$timeout = env('APP_DEBUG')?1000000:20; //处理超时时间
$userid = 0; //默认用户ID是0
$appKey = env('app.DEFAULT_KEY');
$GLOBALS['appKey'] = env('app.DEFAULT_KEY');//定义全局变量,报错时使用
$startTime = microtime(true); //开始时间时间
$LogArray = []; //记录日志数组
$message = [
'token_error' => 'Token验证失败',
'token_Illegal' => 'Token非法',
'data_Illegal' => '非法数据',
'logout_success' => '退出成功',
'sign_error' => '数据签名错误',
'data_timeout' => '请求数据超时',
'cmd_error' => '没有CMD信息',
];
// $independent = ["user.logout"];
try {
//获取访问者IP
$LogArray['ip'] = get_client_ip();
//获取用户上传的token
$clientToken = request()->post('tk');
//如果TOKEN不存在则设置为空
$clientToken = !empty($clientToken)?$clientToken:'';
//记录日志开始记录token和开始时间
$LogArray['token'] = $clientToken;
$LogArray['start_time'] = $startTime;
//如果存在TOKEN则需要解析token
$appToken = "";
if ($clientToken) {
$tk = json_decode(authcode($clientToken),true);
$userid = $tk['userid'];
}
//解密数据
$data = request()->post();
//定义常量
define('PLATFORM', $data['RequestBody']['Platform'] ?? ''); //手机系统平台 IOS、ANDROID
define('DEVICE', $data['RequestBody']['Device'] ?? ''); //手机型号
define('IM_NUMBER', $data['RequestBody']['IM'] ?? ''); //设备码
define('APP_VERSION', $data['RequestBody']['APPVersion'] ?? ''); //版本号
$LogArray['userid'] = $userid;
$LogArray['platform'] = PLATFORM;
$LogArray['device'] = DEVICE;
$LogArray['im_number'] = IM_NUMBER;
$LogArray['app_version'] = APP_VERSION;
$LogArray['api_version'] = $api_version;
$LogArray['cmd'] = !empty($data['RequestBody']['CMD'])?$data['RequestBody']['CMD']:'';
$LogArray['data'] = json_encode($data);
if(empty($data['cmd'])) {
return show($message['cmd_error'],MISSING_PARAMETER);
}
/**********
* start 调用退出 *************
* 把apptoken表数据清空只退出当前设置
* 其它设置信息保留
*/
if (strtolower($data['cmd']) == "sign.logout") {
if(!empty($appToken['id'])) {
$this->logout($appToken['id']);
$LogArray['return_data'] = $message['logout_success'];
$this->log($LogArray);
}
return show("退出成功!",SUCCESS_CODE);
}
if (($data['cmd'])) {
$action = explode('.', $data['cmd']);
if (is_array($action)) {
$ClassName = '\\app\\controller\\' . ucfirst($action[0]);
$FunctionName = $action[1];
$class = new $ClassName();
$GLOBALS['data'] = [
'data' => $data,
'userid' => $userid
];
if(!empty($_FILES['file'])){
$GLOBALS['data']['file'] = $_FILES['file'];
}
$backdata = $class->$FunctionName();
$LogArray['return_data'] = !empty($GLOBALS['data']['returnData'])?$GLOBALS['data']['returnData']:'';
$this->log($LogArray);
unset($data);
return $backdata;
}
}
} catch (\Exception $e) {
if(env("APP_DEBUG")){$msg = $e->getMessage();}else{$msg = "服务器故障!";}
return show($msg,SYSTEM_ERROR_CODE);
}
}
private function logout($userid)
{
(new \app\model\AppToken)->where('id', $userid)->delete();
}
private function log($data)
{
$addData = [
'ip' => !empty($data['ip'])?$data['ip']:'',
'token' => !empty($data['token'])?$data['token']:'',
'start_time' => !empty($data['start_time'])?$data['start_time']:'',
'userid' => !empty($data['userid'])?$data['userid']:'',
'platform' => !empty($data['platform'])?$data['platform']:'',
'device' => !empty($data['device'])?$data['device']:'',
'im_number' => !empty($data['im_number'])?$data['im_number']:'',
'app_version' => !empty($data['app_version'])?$data['app_version']:'',
'api_version' => !empty($data['api_version'])?$data['api_version']:'',
'cmd' => !empty($data['cmd'])?$data['cmd']:'',
'data' => !empty($data['data'])?$data['data']:'',
'return_data' => !empty($data['return_data'])?$data['return_data']:'',
'end_time' => microtime(true),
'usetime' => microtime(true) - $data['start_time']
];
$applog = (new \app\model\AppLog)->insertGetId($addData);
return $applog;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace app\controller;
use think\facade\Db;
class Ranking
{
public function lists()
{
$post = $GLOBALS['data']['data'];
if(empty($post['type'])){
return show("请选择传类型");
}
$type = $post['type'];
$typeArray = [1,2,3,4];
if(!in_array($type,$typeArray)){
return show("不支持当前类型!");
}
$where = [];
//1=未来之星;2=适龄儿童;3=残联儿童;4=全部
if($type == 1) $where = "type=1";
if($type == 2) $where = "type=2";
if($type == 3) $where = "disabled=1";
if($type == 4) $where = "";
$lastIndex = lastindex();
if($lastIndex == 0) {
$lastIndex = 1;
}
$result = [];
$list = Db::name("student")->where($where)->limit(env("page_count"))->order('hot desc')->paginate([
"list_rows"=>env("page_count"),
"page"=>$lastIndex
]);
if(empty($list)) return show("获取成功", SUCCESS_CODE,$result);
if($list->currentPage() < $list->lastPage()){
$result['lastIndex'] = $lastIndex +1;
}else{
$result['lastIndex'] = 0;
}
$result = StudentToArray($list);
return show(SUCCESS_MESSAGE,SUCCESS_CODE,$result);
}
}

28
app/controller/Search.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
namespace app\controller;
use think\facade\Db;
class Search
{
public function keywords()
{
$post = $GLOBALS['data']['data'];
if(empty($post['keywords'])){
return show("请输入搜索关键字");
}
$lastIndex = $GLOBALS['data']['data']["lastindex"]??0;
if($lastIndex == 0){
$where = "id > 0";
}else{
$where = "id < ".$lastIndex;
}
$KEY = $post['keywords'];
$list = Db::name("student")->where("nickname like '{$KEY}%' or city like '{$KEY}%' or school like '{$KEY}%'")->order('hot desc')->limit(env("page_count"))->where($where)->select()->toArray();
$result = StudentToArray($list);
return show(SUCCESS_MESSAGE,SUCCESS_CODE,$result);
}
}

111
app/controller/Sign.php Normal file
View File

@@ -0,0 +1,111 @@
<?php
namespace app\controller;
use app\v1\model\AppToken;
use think\facade\Db;
class Sign
{
public function password(){
if(empty($GLOBALS['data']['data']['mobile'])){
return show("手机号不能为空!");
}
if(empty($GLOBALS['data']['data']['password'])){
return show("密码不能为空!");
}
$password = md5($GLOBALS['data']['data']['password']);
$info = Db::name("student")->where("mobile",$GLOBALS['data']['data']['mobile'])->find();
if(empty($info)){
return show("找不到家长信息!");
}
if($info['password']!=$password){
return show("密码不正确,请重试!");
}
$tokenData = ['userid' => $info['id'],'loginTime' => time(),'rankStr' => strRand(5)];
$tk = authcode(json_encode($tokenData), 'ENCODE');
unset($info['password']);
$res = [
'TK' => $tk,
'user' => [
"userid"=>$info['id'],
"identifier"=>$info['identifier'],
"nickname"=>$info['nickname'],
"mobile"=>$info['mobile'],
"avatar"=> env("admin_pannel_address") . $info['avatar'],
"gender"=>$info['gender'],
"birthday"=>$info['birthday'],
"age"=>$info['age'],
"createtime"=>$info['createtime'],
"is_disabled"=>$info['disabled'],
"type"=>$info["type"],
"hot"=>$info['hot']
]
];
return show("验证成功!",SUCCESS_CODE,$res);
}
public function getuser(){
if(empty($GLOBALS['data']['userid'])){
return show("请上传TOKEN");
}
$info = Db::name("student")->where("id",$GLOBALS['data']['userid'])->find();
if(empty($info)){
return show("找不到家长信息!");
}
$res = [
'user' => [
"userid"=>$info['id'],
"identifier"=>$info['identifier'],
"nickname"=>$info['nickname'],
"mobile"=>$info['mobile'],
"avatar"=> env("admin_pannel_address") . $info['avatar'],
"gender"=>$info['gender'],
"birthday"=>$info['birthday'],
"age"=>$info['age'],
"createtime"=>$info['createtime'],
"is_disabled"=>$info['disabled'],
"type"=>$info["type"],
"hot"=>$info['hot']
]
];
return show("操作成功!",SUCCESS_CODE,$res);
}
public function repass(){
if(empty($GLOBALS['data']['data']['mobile'])){
return show("手机号不能为空!");
}
$mobile = $GLOBALS['data']['data']['mobile'];
$info = Db::name("student")->where("mobile",$mobile)->find();
if(empty($info)){
return show("找不到用户信息!");
}
if(empty($GLOBALS['data']['data']['code'])){
return show("验证码不能为空!");
}
$code = $GLOBALS['data']['data']['code'];
if(empty($GLOBALS['data']['data']['password'])){
return show("请输入密码!");
}
$password = $GLOBALS['data']['data']['password'];
$code = Db::name("app_sms")->order("id desc")->where("mobile", $mobile)->find();
if(empty($code)){
return show("请发送短信后再试!");
}
Db::name("app_sms")->where("id",$code['id'])->inc("count",1)->update();
if((time() - $code['create_time'])>15*60){
return show("短信已经失效,请重新发送!");
}
Db::name("student")->where("id",$info['id'])->update([
"password" => md5($password)
]);
return show(SUCCESS_MESSAGE,SUCCESS_CODE,[]);
}
}

44
app/controller/Sms.php Normal file
View File

@@ -0,0 +1,44 @@
<?php
namespace app\controller;
use think\facade\Db;
class Sms
{
public function send(){
if(empty($GLOBALS['data']['data']['mobile'])){
return show("手机号不能为空!");
}
$mobileNumber = $GLOBALS['data']['data']['mobile'];
if(!is_mobile_number($mobileNumber)){
return show("手机号不正确!");
}
$timeOut = 60;
$info = Db::name("app_sms")->order("id desc")->where("mobile",$mobileNumber)->find();
if(!empty($info) && (time() - $info['create_time'])<$timeOut){
return show("请在". ($timeOut-(time()-$info['create_time'])) ."后重新发送!");
}
$code = rand(111111,999999);
try {
if(!env("APP_DEBUG")){
$result = \app\tools\Sms::sendmsg($mobileNumber,$code);
if($result['code'] != 1){
return show("运营商接口无法返回!");
}
}else{
$code = "000000";
}
Db::name("app_sms")->insert([
"ipaddress"=>get_client_ip(),
"mobile"=>$mobileNumber,
"code"=>$code,
"create_time"=>time(),
"count"=>0
]);
return show("发送成功!",SUCCESS_CODE);
}catch(\Exception $e){
return show("发送失败,请联系客服人员!");
}
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace app\controller;
use think\facade\Db;
class Student
{
public function lists()
{
$post = $GLOBALS['data']['data'];
if(empty($post['type'])){
return show("请选择传类型");
}
$type = $post['type'];
$typeArray = [1,2,3,4];
if(!in_array($type,$typeArray)){
return show("不支持当前类型!");
}
//1=未来之星;2=适龄儿童;3=残联儿童;4=全部
if($type == 1) $where = "type=1";
if($type == 2) $where = "type=2";
if($type == 3) $where = "disabled=1";
if($type == 4) $where = "";
$lastIndex = lastindex();
if($lastIndex == 0) {
$lastIndex = 1;
}
$result = [];
$list = Db::name("student")->where($where)->limit(env("page_count"))->order('hot desc')->paginate([
"list_rows"=>env("page_count"),
"page"=>$lastIndex
]);
if(empty($list)) return show("获取成功", SUCCESS_CODE,$result);
if($list->currentPage() < $list->lastPage()){
$result['lastIndex'] = $lastIndex +1;
}else{
$result['lastIndex'] = 0;
}
$result = StudentToArray($list);
return show(SUCCESS_MESSAGE,SUCCESS_CODE,$result);
}
}

34
app/controller/Upload.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
namespace app\controller;
use think\facade\Db;
class Upload
{
public function image()
{
if(empty($GLOBALS['data']['userid'])){
return show("请上传TOKEN");
}
if(empty($GLOBALS['data']['file'])){
return show("请选择图片!");
}
$file = $GLOBALS['data']['file'];
$dir = env('upload_directory');
if(!is_dir($dir)){
mkdir($dir, 0777, true);
}
$ext = getExt($file['name']);
$newfilename = uniqid().rand(10000,99999).'.'.$ext;
if(move_uploaded_file($file['tmp_name'], $dir.'/'.$newfilename)){
$but = aliyun($newfilename);
if(empty($but["url"])){
return show('服务器繁忙,请联系管理员');
}
return show('上传成功',SUCCESS_CODE,['url'=>$but['url']]);
}else{
return show('服务器繁忙,请联系管理员');
}
}
}

128
app/controller/User.php Normal file
View File

@@ -0,0 +1,128 @@
<?php
namespace app\controller;
use think\facade\Db;
class User
{
//获取用户信息
public function info()
{
if(empty($GLOBALS['data']['userid'])){
return show("请上传TOKEN");
}
$userid = $GLOBALS['data']['userid'];
$info = Db::name("app_users")->where("id",$userid)->find();
if(empty($info)) return show("无此用户信息");
unset($info['openid']);
return show(SUCCESS_MESSAGE,SUCCESS_CODE,$info);
}
//修改头像
public function modify_avatar(){
if(empty($GLOBALS['data']['userid'])){
return show("请上传TOKEN");
}
$userid = $GLOBALS['data']['userid'];
$avatarUrl = $GLOBALS['data']['data']['avatar_url'];
if(empty($avatarUrl)){
return show("请上传头像!");
}
Db::name("app_users")->where("id",$userid)->update(['avatar'=>$avatarUrl]);
return show("头像修改成功!",SUCCESS_CODE,[]);
}
//修改昵称
public function modify_nickname(){
if(empty($GLOBALS['data']['userid'])){
return show("请上传TOKEN");
}
$userid = $GLOBALS['data']['userid'];
$nickname = $GLOBALS['data']['data']['nickname'];
if(empty(nickname)){
return show("请输入昵称!");
}
Db::name("app_users")->where("id",$userid)->update(['nickname'=>$nickname]);
return show("昵称修改成功!",SUCCESS_CODE,[]);
}
//狮友认证
public function verify(){
if(empty($GLOBALS['data']['userid'])){
return show("请上传TOKEN");
}
$userid = $GLOBALS['data']['userid'];
$mobileNumber = $GLOBALS['data']['data']['mobile'];
if(!is_mobile_number($mobileNumber)){
return show("手机号不正确!");
}
$res = Db::name("shiyou")->where("mobile",$mobileNumber)->find();
if(empty($res)) {
return show("未找到狮友信息!");
}
$code = Db::name("app_sms")->order("id desc")->where("mobile", $mobileNumber)->find();
if(empty($code)){
return show("请发送短信后再试!");
}
Db::name("app_sms")->where("id",$code['id'])->inc("count",1)->update();
if((time() - $code['create_time'])>15*60){
return show("短信已经失效,请重新发送!");
}
if($GLOBALS['data']['data']['code'] != $code["code"]){
return show("验证码不正确!");
}
Db::name("app_users")->where("id",$userid)->update(['identity'=>1]);
return show("狮友认证成功!",SUCCESS_CODE,[]);
}
//发送验证码
public function getcode(){
if(empty($GLOBALS['data']['data']['mobile'])){
return show("手机号不能为空!");
}
$mobileNumber = $GLOBALS['data']['data']['mobile'];
if(!is_mobile_number($mobileNumber)){
return show("手机号不正确!");
}
$user = Db::name("shiyou")->where("mobile",$mobileNumber)->find();
if(empty($user)) return show("手机号狮友库中未找到,请核对!");
$timeOut = 60;
$info = Db::name("app_sms")->order("id desc")->where("mobile",$mobileNumber)->find();
if(!empty($info) && (time() - $info['create_time'])<$timeOut){
return show("请在". ($timeOut-(time()-$info['create_time'])) ."后重新发送!");
}
$code = rand(111111,999999);
try {
if(!env("APP_DEBUG")){
$result = \app\tools\Sms::sendmsg($mobileNumber,$code);
if($result['code'] != 1){
return show("运营商接口无法返回!");
}
}else{
$code = "000000";
}
Db::name("app_sms")->insert([
"ipaddress"=>get_client_ip(),
"mobile"=>$mobileNumber,
"code"=>$code,
"create_time"=>time(),
"count"=>0
]);
return show("发送成功!",SUCCESS_CODE);
}catch(\Exception $e){
return show("发送失败,请联系客服人员!");
}
}
}