first commit
This commit is contained in:
@@ -1,72 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2023/1/21} {16:22}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\common\model\TabConf;
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Request;
|
||||
use wanghua\general_utility_tools_php\framework\BaseController;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class BaseCommonController extends BaseController
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:检查路径维护状态
|
||||
*
|
||||
* “===”完全匹配,不能使用like
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
protected function checkMaintain(){
|
||||
|
||||
$configs = Db::table(TabConf::$fa_sys_maintain_config)
|
||||
->where('status','1')
|
||||
->cache()
|
||||
->select();
|
||||
|
||||
//模块
|
||||
$strmodule = request()->module();
|
||||
foreach ($configs as $config){
|
||||
if($strmodule == $config['url']){
|
||||
//模块维护中
|
||||
return ['is_maintain'=>true,'msg'=>$config['msg'],'openid'=>$config['openid']];
|
||||
}
|
||||
}
|
||||
|
||||
//模块/控制器
|
||||
$strcontroller = strtolower(request()->module().'/'.request()->controller());
|
||||
foreach ($configs as $config){
|
||||
if($strcontroller == $config['url']){
|
||||
//模块维护中
|
||||
return ['is_maintain'=>true,'msg'=>$config['msg'],'openid'=>$config['openid']];
|
||||
}
|
||||
}
|
||||
|
||||
//模块/控制器/方法
|
||||
$straction = strtolower(request()->module().'/'.request()->controller().'/'.request()->action());
|
||||
foreach ($configs as $config){
|
||||
if($straction == $config['url']){
|
||||
//模块维护中
|
||||
return ['is_maintain'=>true,'msg'=>$config['msg'],'openid'=>$config['openid']];
|
||||
}
|
||||
}
|
||||
|
||||
//未维护
|
||||
return ['is_maintain'=>false,'msg'=>'服务运行中'];
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/4/22} {11:52}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\index\controller\BaseCommonController;
|
||||
use think\App;
|
||||
use think\Controller;
|
||||
use think\Exception;
|
||||
use wanghua\general_utility_tools_php\tool\Ip;
|
||||
|
||||
class BaseHttpApi extends BaseCommonController
|
||||
{
|
||||
/**
|
||||
http请求专用
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
//ip校验
|
||||
//$ip = request()->ip();
|
||||
//$res = Ip::ip_is_china($ip,false);
|
||||
//if(!$res){
|
||||
// throw new Exception('ip不合法');
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/4/5} {19:55}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
class BaseWssApi extends BaseCommonController
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:socket专用json格式
|
||||
*
|
||||
* author:wh
|
||||
* @param $action
|
||||
* @param string $msg
|
||||
* @param array $items
|
||||
* @param string $method
|
||||
* @return false|string
|
||||
*/
|
||||
static function json_wss($action,$msg='', $items=[], $method='response'){
|
||||
$json = [
|
||||
'action'=>$action,
|
||||
'method'=>$method,
|
||||
'msg'=>$msg,
|
||||
'items'=>$items
|
||||
];
|
||||
return json_encode($json, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}
|
||||
166
digital_doctor_admin/application/api/controller/Common.php
Normal file
166
digital_doctor_admin/application/api/controller/Common.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\exception\UploadException;
|
||||
use app\common\library\Upload;
|
||||
use app\common\model\Area;
|
||||
use app\common\model\Version;
|
||||
use fast\Random;
|
||||
use think\captcha\Captcha;
|
||||
use think\Config;
|
||||
use think\Hook;
|
||||
|
||||
/**
|
||||
* 公共接口
|
||||
*/
|
||||
class Common extends Api
|
||||
{
|
||||
protected $noNeedLogin = ['init', 'captcha'];
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
|
||||
if (isset($_SERVER['HTTP_ORIGIN'])) {
|
||||
header('Access-Control-Expose-Headers: __token__');//跨域让客户端获取到
|
||||
}
|
||||
//跨域检测
|
||||
check_cors_request();
|
||||
|
||||
if (!isset($_COOKIE['PHPSESSID'])) {
|
||||
Config::set('session.id', $this->request->server("HTTP_SID"));
|
||||
}
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载初始化
|
||||
*
|
||||
* @param string $version 版本号
|
||||
* @param string $lng 经度
|
||||
* @param string $lat 纬度
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if ($version = $this->request->request('version')) {
|
||||
$lng = $this->request->request('lng');
|
||||
$lat = $this->request->request('lat');
|
||||
|
||||
//配置信息
|
||||
$upload = Config::get('upload');
|
||||
//如果非服务端中转模式需要修改为中转
|
||||
if ($upload['storage'] != 'local' && isset($upload['uploadmode']) && $upload['uploadmode'] != 'server') {
|
||||
//临时修改上传模式为服务端中转
|
||||
set_addon_config($upload['storage'], ["uploadmode" => "server"], false);
|
||||
|
||||
$upload = \app\common\model\Config::upload();
|
||||
// 上传信息配置后
|
||||
Hook::listen("upload_config_init", $upload);
|
||||
|
||||
$upload = Config::set('upload', array_merge(Config::get('upload'), $upload));
|
||||
}
|
||||
|
||||
$upload['cdnurl'] = $upload['cdnurl'] ? $upload['cdnurl'] : cdnurl('', true);
|
||||
$upload['uploadurl'] = preg_match("/^((?:[a-z]+:)?\/\/)(.*)/i", $upload['uploadurl']) ? $upload['uploadurl'] : url($upload['storage'] == 'local' ? '/api/common/upload' : $upload['uploadurl'], '', false, true);
|
||||
|
||||
$content = [
|
||||
'citydata' => Area::getCityFromLngLat($lng, $lat),
|
||||
'versiondata' => Version::check($version),
|
||||
'uploaddata' => $upload,
|
||||
'coverdata' => Config::get("cover"),
|
||||
];
|
||||
$this->success('', $content);
|
||||
} else {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @ApiMethod (POST)
|
||||
* @param File $file 文件流
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
Config::set('default_return_type', 'json');
|
||||
//必须设定cdnurl为空,否则cdnurl函数计算错误
|
||||
Config::set('upload.cdnurl', '');
|
||||
$chunkid = $this->request->post("chunkid");
|
||||
if ($chunkid) {
|
||||
if (!Config::get('upload.chunking')) {
|
||||
$this->error(__('Chunk file disabled'));
|
||||
}
|
||||
$action = $this->request->post("action");
|
||||
$chunkindex = $this->request->post("chunkindex/d");
|
||||
$chunkcount = $this->request->post("chunkcount/d");
|
||||
$filename = $this->request->post("filename");
|
||||
$method = $this->request->method(true);
|
||||
if ($action == 'merge') {
|
||||
$attachment = null;
|
||||
//合并分片文件
|
||||
try {
|
||||
$upload = new Upload();
|
||||
$attachment = $upload->merge($chunkid, $chunkcount, $filename);
|
||||
} catch (UploadException $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
|
||||
} elseif ($method == 'clean') {
|
||||
//删除冗余的分片文件
|
||||
try {
|
||||
$upload = new Upload();
|
||||
$upload->clean($chunkid);
|
||||
} catch (UploadException $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
} else {
|
||||
//上传分片文件
|
||||
//默认普通上传文件
|
||||
$file = $this->request->file('file');
|
||||
try {
|
||||
$upload = new Upload($file);
|
||||
$upload->chunk($chunkid, $chunkindex, $chunkcount);
|
||||
} catch (UploadException $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
} else {
|
||||
$attachment = null;
|
||||
//默认普通上传文件
|
||||
$file = $this->request->file('file');
|
||||
try {
|
||||
$upload = new Upload($file);
|
||||
$attachment = $upload->upload();
|
||||
} catch (UploadException $e) {
|
||||
$this->error($e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
* @param $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function captcha($id = "")
|
||||
{
|
||||
\think\Config::set([
|
||||
'captcha' => array_merge(config('captcha'), [
|
||||
'fontSize' => 44,
|
||||
'imageH' => 150,
|
||||
'imageW' => 350,
|
||||
])
|
||||
]);
|
||||
$captcha = new Captcha((array)Config::get('captcha'));
|
||||
return $captcha->entry($id);
|
||||
}
|
||||
}
|
||||
73
digital_doctor_admin/application/api/controller/Demo.php
Normal file
73
digital_doctor_admin/application/api/controller/Demo.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
|
||||
/**
|
||||
* 示例接口
|
||||
*/
|
||||
class Demo extends Api
|
||||
{
|
||||
|
||||
//如果$noNeedLogin为空表示所有接口都需要登录才能请求
|
||||
//如果$noNeedRight为空表示所有接口都需要验证权限才能请求
|
||||
//如果接口已经设置无需登录,那也就无需鉴权了
|
||||
//
|
||||
// 无需登录的接口,*表示全部
|
||||
protected $noNeedLogin = ['test', 'test1'];
|
||||
// 无需鉴权的接口,*表示全部
|
||||
protected $noNeedRight = ['test2'];
|
||||
|
||||
/**
|
||||
* 测试方法
|
||||
*
|
||||
* @ApiTitle (测试名称)
|
||||
* @ApiSummary (测试描述信息)
|
||||
* @ApiMethod (POST)
|
||||
* @ApiRoute (/api/demo/test/id/{id}/name/{name})
|
||||
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
||||
* @ApiParams (name="id", type="integer", required=true, description="会员ID")
|
||||
* @ApiParams (name="name", type="string", required=true, description="用户名")
|
||||
* @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
|
||||
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
||||
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
||||
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
|
||||
* @ApiReturn ({
|
||||
'code':'1',
|
||||
'msg':'返回成功'
|
||||
})
|
||||
*/
|
||||
public function test()
|
||||
{
|
||||
$this->success('返回成功', $this->request->param());
|
||||
}
|
||||
|
||||
/**
|
||||
* 无需登录的接口
|
||||
*
|
||||
*/
|
||||
public function test1()
|
||||
{
|
||||
$this->success('返回成功', ['action' => 'test1']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 需要登录的接口
|
||||
*
|
||||
*/
|
||||
public function test2()
|
||||
{
|
||||
$this->success('返回成功', ['action' => 'test2']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 需要登录且需要验证有相应组的权限
|
||||
*
|
||||
*/
|
||||
public function test3()
|
||||
{
|
||||
$this->success('返回成功', ['action' => 'test3']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/4/3} {15:43}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\api\logic\DouLogic;
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\douyin\DouYinMiniGame;
|
||||
use wanghua\general_utility_tools_php\image\Image;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class Douyin extends BaseHttpApi
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
//$logic = new DouLogic();
|
||||
//$logic->realTimeGetAccessToken();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:
|
||||
*
|
||||
* api/Douyin/getaccesstoken
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function getaccesstoken(){
|
||||
|
||||
$logic = new DouYinMiniGame();
|
||||
//tp5.1必须带app.
|
||||
$logic->appid = config('app.douyin_config_mini_game.appid');
|
||||
$logic->secret = config('app.douyin_config_mini_game.secret');
|
||||
$res = $logic->realTimeGetAccessToken();
|
||||
|
||||
return json($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:tt.login触发调用
|
||||
* 参数:code或anonymous_code
|
||||
*
|
||||
* api/Douyin/jscode2session
|
||||
*
|
||||
* "{\"anonymous_openid\":\"\",\"error\":0,\"openid\":\"_0007vGUSinv-twIOjY9MzYvzlj6U_xHa3Or\",\"session_key\":\"495rArUkMUXa4JoeT7wEVg==\",\"unionid\":\"7e1b9701-a346-5b44-9925-0acc40873cff\"}
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function jscode2session(){
|
||||
|
||||
//{"nickName":"fish","avatarUrl":"https://p26.douyinpic.com/aweme/100x100/f831000cb79d741e8c7e.jpeg?
|
||||
//from=3782654143",
|
||||
//"gender":0,"city":"","province":"","country":"","language":""}
|
||||
try {
|
||||
$clientid = input('clientid');
|
||||
if(empty($clientid)){
|
||||
return json(Tools::set_fail('clientid error'));
|
||||
}
|
||||
$json = input('json');
|
||||
$json_arr = json_decode($json, true);
|
||||
|
||||
$logic = new DouYinMiniGame();
|
||||
//tp5.1必须带app.
|
||||
$logic->appid = config('app.douyin_config_mini_game.appid');
|
||||
$logic->secret = config('app.douyin_config_mini_game.secret');
|
||||
//tt.login 接口返回的匿名登录凭证(code 和 anonymous_code 至少要有一个)
|
||||
$code = input('code');
|
||||
$anonymous_code = input('anonymous_code');
|
||||
$res = $logic->jscode2session($code,$anonymous_code);
|
||||
|
||||
//保存用户信息
|
||||
if($res['code'] != 200){
|
||||
return json($res);
|
||||
}
|
||||
$openid = $res['data']['openid'];
|
||||
$user = Db::table(TabConf::$fa_users)
|
||||
->where('openid',$openid)
|
||||
->find();
|
||||
if(empty($user)){
|
||||
$data = [
|
||||
'openid'=>$openid,
|
||||
'nickname'=>isset($json_arr['nickName'])?$json_arr['nickName']:'',
|
||||
'headimage'=>isset($json_arr['avatarUrl'])?$json_arr['avatarUrl']:'',
|
||||
'user_type'=>'douyin',
|
||||
'unionid'=>$res['data']['unionid'],
|
||||
'clientid'=>$clientid,
|
||||
'last_login_time'=>Tools::get_now_date(),
|
||||
];
|
||||
Db::table(TabConf::$fa_users)
|
||||
->data($data)
|
||||
->insert();
|
||||
}else{
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('openid',$openid)
|
||||
->data([
|
||||
'clientid'=>$clientid,
|
||||
'nickname'=>isset($json_arr['nickName'])?$json_arr['nickName']:Tools::rand_str(),
|
||||
'headimage'=>isset($json_arr['avatarUrl'])?$json_arr['avatarUrl']:request()->domain().'/static/common/headimage.jpg',
|
||||
'last_login_time'=>Tools::get_now_date(),
|
||||
])//更新登录状态
|
||||
->update();
|
||||
}
|
||||
|
||||
//初始化用户消消乐游戏奖励
|
||||
$usereliminate = Db::table(TabConf::$fa_usereliminate)
|
||||
->where('openid',$openid)
|
||||
->find();
|
||||
if(empty($usereliminate)){
|
||||
Db::table(TabConf::$fa_usereliminate)->insert([
|
||||
'openid'=>$openid
|
||||
]);
|
||||
}
|
||||
return json($res);
|
||||
}catch (\Exception $e){
|
||||
Tools::error_txt_log($e);
|
||||
return json(Tools::set_fail());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:创建二维码
|
||||
* 接口说明
|
||||
* 获取小程序/小游戏的二维码。该二维码可通过任意 app 扫码打开,
|
||||
* 能跳转到开发者指定的对应字节系 app 内拉起小程序/小游戏,并传入开发者指定的参数。
|
||||
* 通过该接口生成的二维码,永久有效,暂无数量限制。
|
||||
*
|
||||
* ⚠ Tip:在使用该功能之前请记得先配置您的默认分享文案和图片,配置方式可参考论坛。
|
||||
* ⚠ Tip:小程序的 path 要 encode 一次,如 pages%3fparam%3dtrue,小游戏的 path 为 JSON 字符串,
|
||||
* 如{"param":true},否则会导致取不到。
|
||||
*
|
||||
* 参数:
|
||||
* code和anonymous_code二选一 必须
|
||||
* appname 可选,目标打开应用名称 默认douyin
|
||||
* background 可选,背景色,rgb格式,英文逗号隔开,默认透明色
|
||||
* path 可选,小程序/小游戏启动参数,小程序则格式为 encode({path}?{query}),小游戏则格式为 JSON 字符串,默认为空
|
||||
* width 宽度 可选,二维码宽度,单位 px,最小 280px,最大 1280px,默认为 430px
|
||||
* line_color 可选,二维码线条颜色,默认为黑色,rgb格式,英文逗号隔开,默认黑色
|
||||
* set_icon 可选,是否展示小程序/小游戏 icon,默认不展示,传yes展示,no不展示,默认no
|
||||
*
|
||||
* api/douyin/createQRCode
|
||||
* 参数:openid
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function createQRCode(){
|
||||
try {
|
||||
|
||||
$openid = input('openid');
|
||||
if(empty($openid)){
|
||||
return json(Tools::set_fail('openid error'));
|
||||
}
|
||||
$logic = new DouYinMiniGame();
|
||||
//tp5.1必须带app.
|
||||
$logic->appid = config('app.douyin_config_mini_game.appid');
|
||||
$logic->secret = config('app.douyin_config_mini_game.secret');
|
||||
$path=input('path','');
|
||||
$appname=input('appname','douyin');
|
||||
$width=input('width');
|
||||
$background=input('background');
|
||||
$line_color=input('line_color');
|
||||
$set_icon=input('set_icon','yes');
|
||||
$res = $logic->createQRCode($path,$appname,$width,$background,$line_color,$set_icon);
|
||||
|
||||
|
||||
if(is_array($res)){
|
||||
return json(Tools::set_fail('错误.',$res));
|
||||
}
|
||||
$img_save_path = '/uploads/unlimited_douyin/';
|
||||
$rand_str = Tools::rand_str();
|
||||
$filename = $openid.'_'.$rand_str.'.png';
|
||||
(new Image())->binaryToImage($res,$img_save_path,$filename);
|
||||
return json(Tools::set_ok('ok',$img_save_path.$filename));
|
||||
}catch (\Exception $e){
|
||||
Tools::error_txt_log($e);
|
||||
return json(Tools::set_fail());
|
||||
}
|
||||
}
|
||||
}
|
||||
102
digital_doctor_admin/application/api/controller/Ems.php
Normal file
102
digital_doctor_admin/application/api/controller/Ems.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\library\Ems as Emslib;
|
||||
use app\common\model\User;
|
||||
use think\Hook;
|
||||
|
||||
/**
|
||||
* 邮箱验证码接口
|
||||
*/
|
||||
class Ems extends Api
|
||||
{
|
||||
protected $noNeedLogin = '*';
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $email 邮箱
|
||||
* @param string $event 事件名称
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
$email = $this->request->post("email");
|
||||
$event = $this->request->post("event");
|
||||
$event = $event ? $event : 'register';
|
||||
|
||||
$last = Emslib::get($email, $event);
|
||||
if ($last && time() - $last['createtime'] < 60) {
|
||||
$this->error(__('发送频繁'));
|
||||
}
|
||||
|
||||
$ipSendTotal = \app\common\model\Ems::where(['ip' => $this->request->ip()])->whereTime('createtime', '-1 hours')->count();
|
||||
if ($ipSendTotal >= 5) {
|
||||
$this->error(__('发送频繁'));
|
||||
}
|
||||
|
||||
if ($event) {
|
||||
$userinfo = User::getByEmail($email);
|
||||
if ($event == 'register' && $userinfo) {
|
||||
//已被注册
|
||||
$this->error(__('已被注册'));
|
||||
} elseif (in_array($event, ['changeemail']) && $userinfo) {
|
||||
//被占用
|
||||
$this->error(__('已被占用'));
|
||||
} elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
|
||||
//未注册
|
||||
$this->error(__('未注册'));
|
||||
}
|
||||
}
|
||||
$ret = Emslib::send($email, null, $event);
|
||||
if ($ret) {
|
||||
$this->success(__('发送成功'));
|
||||
} else {
|
||||
$this->error(__('发送失败'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测验证码
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $email 邮箱
|
||||
* @param string $event 事件名称
|
||||
* @param string $captcha 验证码
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$email = $this->request->post("email");
|
||||
$event = $this->request->post("event");
|
||||
$event = $event ? $event : 'register';
|
||||
$captcha = $this->request->post("captcha");
|
||||
|
||||
if ($event) {
|
||||
$userinfo = User::getByEmail($email);
|
||||
if ($event == 'register' && $userinfo) {
|
||||
//已被注册
|
||||
$this->error(__('已被注册'));
|
||||
} elseif (in_array($event, ['changeemail']) && $userinfo) {
|
||||
//被占用
|
||||
$this->error(__('已被占用'));
|
||||
} elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
|
||||
//未注册
|
||||
$this->error(__('未注册'));
|
||||
}
|
||||
}
|
||||
$ret = Emslib::check($email, $captcha, $event);
|
||||
if ($ret) {
|
||||
$this->success(__('成功'));
|
||||
} else {
|
||||
$this->error(__('验证码不正确'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/6/18} {17:39}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\api\logic\EnemyLogic;
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
/**
|
||||
* 敌人
|
||||
* Class Enemy
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Enemy extends BaseHttpApi
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:累加击杀敌人数量
|
||||
*
|
||||
* api/enemy/addKillEnemyNum
|
||||
*
|
||||
* 参数:enemy_num
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function addKillEnemyNum(){
|
||||
return Mmodel::catchJson(function (){
|
||||
|
||||
return (new EnemyLogic())->addKillEnemyNum();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/5/26} {22:58}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class Friends extends BaseHttpApi
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* desc:查询推荐好友
|
||||
*
|
||||
* api/friends/getPutFriends
|
||||
*
|
||||
* 要求:不是自己和自己的好友
|
||||
* author:wh
|
||||
*/
|
||||
function getPutFriends(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$openid_arr = [api_user_openid()];
|
||||
//查询自己的好友
|
||||
$fr = Db::table(TabConf::$fa_gamefriend)
|
||||
->where('openid',api_user_openid())
|
||||
->select();
|
||||
$arr = array_column($fr,'friend_openid');
|
||||
|
||||
$arrmg = array_merge($openid_arr,$arr);
|
||||
|
||||
$lists = Db::table(TabConf::$fa_users)
|
||||
->whereNotIn('openid',$arrmg)
|
||||
->select();
|
||||
|
||||
return Tools::set_ok('ok',$lists);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:添加好友
|
||||
* api/friends/addFriend
|
||||
* 参数:friend_openid
|
||||
*
|
||||
* 要求:不是自己和自己的好友
|
||||
* author:wh
|
||||
*/
|
||||
//function addFriend(){
|
||||
// return Mmodel::catchJson(function () {
|
||||
// $openid_arr = [api_user_openid()];
|
||||
// //查询自己的好友
|
||||
// $fr = Db::table(TabConf::$fa_gamefriend)
|
||||
// ->where('openid',api_user_openid())
|
||||
// ->select();
|
||||
// $arr = array_column($fr,'friend_openid');
|
||||
//
|
||||
// $arrmg = array_merge($openid_arr,$arr);
|
||||
//
|
||||
// $friend_openid = input('friend_openid');
|
||||
// if(empty($friend_openid)){
|
||||
// return Tools::set_fail('请输入好友openid');
|
||||
// }
|
||||
// if(in_array($friend_openid,$arrmg)){
|
||||
// return Tools::set_fail('不能添加自己和自己的好友');
|
||||
// }
|
||||
// //查询用户
|
||||
// $users = Db::table(TabConf::$fa_users)
|
||||
// ->where('openid',$friend_openid)
|
||||
// ->find();
|
||||
// if(empty($users)){
|
||||
// return Tools::set_fail('用户不存在');
|
||||
// }
|
||||
//
|
||||
// $data = [
|
||||
// 'openid'=>api_user_openid(),
|
||||
// 'nickname'=>api_user_info('nickname'),
|
||||
// 'type'=>2,
|
||||
// 'friend_openid'=>$users['openid'],
|
||||
// 'friend_nickname'=>$users['nickname'],
|
||||
// 'friend_image'=>$users['headimage'],
|
||||
// ];
|
||||
// Db::table(TabConf::$fa_gamefriend)
|
||||
// ->insert($data);
|
||||
// return Tools::set_ok('ok');
|
||||
// });
|
||||
//}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/5/22} {22:56}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class Gameemail extends BaseHttpApi
|
||||
{
|
||||
/**
|
||||
* desc:游戏邮件列表
|
||||
* api/gameemail/getlists
|
||||
*
|
||||
* is_read 阅读状态
|
||||
* is_deleted 删除标记
|
||||
*/
|
||||
function getlists(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$lists = Db::table(TabConf::$fa_gameemail)->order('id desc')->select();
|
||||
foreach ($lists as &$list){
|
||||
$is_read = Db::table(TabConf::$fa_user_email_read_record)
|
||||
->where('openid',api_user_openid())
|
||||
->where('gameemail_id',$list['id'])
|
||||
->find();
|
||||
//阅读状态
|
||||
$list['is_read'] = $is_read?1:0;
|
||||
//删除标记
|
||||
$list['is_deleted'] = $is_read?$is_read['is_deleted']:0;
|
||||
}
|
||||
return Tools::set_ok('ok',$lists);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置邮件为已读
|
||||
* api/gameemail/read
|
||||
* 参数:
|
||||
* email_id 邮件id
|
||||
*/
|
||||
function read(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$email_id = input('email_id');
|
||||
if(empty($email_id)){
|
||||
return Tools::set_fail('邮件id不能为空');
|
||||
}
|
||||
Db::table(TabConf::$fa_user_email_read_record)
|
||||
->data([
|
||||
'openid'=>api_user_openid(),
|
||||
'gameemail_id'=>$email_id,
|
||||
])
|
||||
->insert();
|
||||
return Tools::set_ok('ok');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除所有已读邮件
|
||||
* api/gameemail/delete
|
||||
* 参数:
|
||||
*/
|
||||
function delete(){
|
||||
return Mmodel::catchJson(function (){
|
||||
//记录存在表示已读
|
||||
Db::table(TabConf::$fa_user_email_read_record)
|
||||
->where('openid',api_user_openid())
|
||||
->data([
|
||||
'is_deleted'=>'1',
|
||||
])
|
||||
->update();
|
||||
return Tools::set_ok('ok');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/5/23} {0:06}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
/**
|
||||
* 游戏道具
|
||||
*
|
||||
* Class Gameprop
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Gameprop extends BaseHttpApi
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:游戏道具已解锁、未解锁接口
|
||||
* api/gameprop/getprop
|
||||
* 参数:
|
||||
*
|
||||
* 返回:
|
||||
* have_arr 已解锁
|
||||
* no_arr 未解锁
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function getprop(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$openid = api_user_openid();
|
||||
//查询所有未获取的道具列表
|
||||
$gameprop_list = Db::table(TabConf::$fa_gameprop)->select();
|
||||
|
||||
$have_arr = [];//已拥有
|
||||
$no_arr = [];//未拥有
|
||||
foreach ($gameprop_list as $item){
|
||||
$tmp_arr = [];
|
||||
$usergameprop = Db::table(TabConf::$fa_usergameprop)
|
||||
->where('openid',$openid)
|
||||
->where('gameprop_id',$item['id'])
|
||||
->find();
|
||||
if($usergameprop){
|
||||
$tmp_arr['num'] = $usergameprop['num'];
|
||||
//已拥有
|
||||
$have_arr[] = array_merge($tmp_arr, $item);
|
||||
}else{
|
||||
//未拥有
|
||||
$no_arr[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
return Tools::set_ok('ok',[
|
||||
'have_arr'=>$have_arr,
|
||||
'no_arr'=>$no_arr,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:获取游戏道具列表(肥料等各种道具)
|
||||
*
|
||||
* api/gameprop/getGamePropList
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function getGamePropList(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$gameprop_list = Db::table(TabConf::$fa_gameprop)->select();
|
||||
return Tools::set_ok('ok',$gameprop_list);
|
||||
});
|
||||
}
|
||||
}
|
||||
23
digital_doctor_admin/application/api/controller/Index.php
Normal file
23
digital_doctor_admin/application/api/controller/Index.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
|
||||
/**
|
||||
* 首页接口
|
||||
*/
|
||||
class Index extends Api
|
||||
{
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
/**
|
||||
* 首页
|
||||
*
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->success('请求成功');
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/5/22} {21:09}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class Notice extends BaseHttpApi
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:游戏公告
|
||||
* api/notice/getnotice
|
||||
*
|
||||
* author:wh
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
function getnotice(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$res = Db::table(TabConf::$fa_notice)->find();
|
||||
return Tools::set_ok('ok',$res);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/5/25} {16:30}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class Plant extends BaseHttpApi
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:查询系统植物列表
|
||||
* api/plant/getlist
|
||||
* author:wh
|
||||
*/
|
||||
function getlist(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$lists = Db::table(TabConf::$fa_plant)
|
||||
->select();
|
||||
return Tools::set_ok('ok',$lists);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 添加系统植物(前端合成植物时调用并增加用户的植物)
|
||||
* 如果用户植物存在则新增,否则增加植物数量
|
||||
* api/plant/add
|
||||
*
|
||||
* 参数:
|
||||
* name 系统植物名称 必须
|
||||
* num 用户植物增加数量,默认1(可不传)
|
||||
* plant_sit 植物合成时的位置 必须
|
||||
*/
|
||||
//function add(){
|
||||
// return Mmodel::catchTransJson(function (){
|
||||
// if(empty(input('name'))){
|
||||
// return Tools::set_fail('植物名称不能为空');
|
||||
// }
|
||||
// //重复
|
||||
// $plant = Db::table(TabConf::$fa_plant)->where('name',input('name'))->find();
|
||||
// if($plant){
|
||||
// $this->addUserPlants($plant['id']);
|
||||
// $this->userPlantConflateRecord($plant['id']);
|
||||
// return Tools::set_fail('植物名称重复');
|
||||
// }else{
|
||||
// $id = Db::table(TabConf::$fa_plant)->insertGetId([
|
||||
// 'name'=>input('name'),
|
||||
// ]);
|
||||
// $this->addUserPlants($id);
|
||||
// $this->userPlantConflateRecord($id);
|
||||
// }
|
||||
//
|
||||
// return Tools::set_ok('ok',['plant_id'=>$id]);
|
||||
// });
|
||||
//}
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * desc:合成后新增用户植物(前端合成时调用新增)
|
||||
// * num 增加数量,默认1,可不传
|
||||
// * author:wh
|
||||
// */
|
||||
//private function addUserPlants($id){
|
||||
// return Mmodel::catchTrans(function () use ($id){
|
||||
// $num = input('num',1);
|
||||
// $userplant = Db::table(TabConf::$fa_userplant)
|
||||
// ->where('openid', api_user_openid())
|
||||
// ->where('plant_id', $id)
|
||||
// ->find();
|
||||
// if($userplant){
|
||||
// Db::table(TabConf::$fa_userplant)
|
||||
// ->where('id',$userplant['id'])
|
||||
// ->setInc('num',$num);
|
||||
// }else{
|
||||
// $plant = Db::table(TabConf::$fa_plant)
|
||||
// ->where('id',$id)
|
||||
// ->find();
|
||||
// Db::table(TabConf::$fa_userplant)
|
||||
// ->insert([
|
||||
// 'openid'=>api_user_openid(),
|
||||
// 'plant_id'=>$id,
|
||||
// 'num'=>$num,
|
||||
// 'name'=>$plant['name'],
|
||||
// 'image'=>$plant['image'],
|
||||
// ]);
|
||||
// }
|
||||
// return Tools::set_ok('ok');
|
||||
// });
|
||||
//}
|
||||
//
|
||||
///**
|
||||
// * desc:用户植物合成记录
|
||||
// * author:wh
|
||||
// */
|
||||
//private function userPlantConflateRecord($plant_id){
|
||||
// $plant_sit = input('plant_sit');
|
||||
// $data = [
|
||||
// 'openid'=>api_user_openid(),
|
||||
// 'plant_sit'=>$plant_sit,
|
||||
// 'plant_id'=>$plant_id,
|
||||
// ];
|
||||
// Db::table(TabConf::$fa_userplantconflaterecord)
|
||||
// ->data($data)
|
||||
// ->insert();
|
||||
//}
|
||||
//
|
||||
//function getUserPlantConflateRecord(){
|
||||
// return Mmodel::catchJson(function (){
|
||||
//
|
||||
// });
|
||||
//}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/6/22} {15:02}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\SundryConfig;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class Power extends BaseHttpApi
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:当前用户消耗体力
|
||||
*
|
||||
* api/Power/cutPower
|
||||
*
|
||||
* 参数:
|
||||
* num 消耗体力 默认1
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function cutPower()
|
||||
{
|
||||
return Mmodel::catchJson(function (){
|
||||
$openid = api_user_openid();
|
||||
$num = input('num',1);
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('openid',$openid)
|
||||
->setDec('power',$num);
|
||||
return Tools::set_ok('ok');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:获取体力上限配置
|
||||
* api/Power/getPowerLimitConfig
|
||||
* author:wh
|
||||
*/
|
||||
function getPowerLimitConfig(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$power_limit_config = SundryConfig::val('power_limit_config');
|
||||
return Tools::set_ok('ok',$power_limit_config);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/5/27} {13:06}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class Rankinglist extends BaseHttpApi
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:查询排行榜
|
||||
* /api/rankinglist/getrankinglist
|
||||
* author:wh
|
||||
*/
|
||||
function getrankinglist(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$lists = Db::table(TabConf::$fa_users)
|
||||
->order('now_level desc')
|
||||
->select();
|
||||
return Tools::set_ok('ok',$lists);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/6/12} {11:53}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\SundryConfig;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
/**
|
||||
* Class Redeemcode 兑换码
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Redeemcode extends BaseHttpApi
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:新增一个兑换码
|
||||
* 参数: num (默认1)
|
||||
* author:wh
|
||||
*/
|
||||
function add(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$num = input('num',1);//生成数量
|
||||
for ($i=0;$i<$num;$i++){
|
||||
Db::table(TabConf::$fa_redeem_code)
|
||||
->insert(['create_time'=>Tools::get_now_date()]);
|
||||
return Tools::set_ok();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询一个没使用的兑换码
|
||||
*/
|
||||
function getOne(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$res = Db::table(TabConf::$fa_redeem_code)
|
||||
->where('is_use',0)
|
||||
//->order('id','asc')
|
||||
->find();
|
||||
if($res){
|
||||
return Tools::set_ok($res);
|
||||
}
|
||||
return Tools::set_fail('没有更多了');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 兑换码使用
|
||||
*
|
||||
* 参数:code
|
||||
*
|
||||
* 返回用户获得的道具列表(可能获得多个道具,根据系统配置定)
|
||||
*/
|
||||
function use()
|
||||
{
|
||||
return Mmodel::catchJson(function () {
|
||||
$code = input('code');
|
||||
if (!$code) {
|
||||
return Tools::set_fail('参数错误');
|
||||
}
|
||||
$res = Db::table(TabConf::$fa_redeem_code)
|
||||
->where('id', $code)
|
||||
->where('is_use', 0)
|
||||
->find();
|
||||
if (empty($res)) {
|
||||
return Tools::set_fail('兑换码不存在或已使用');
|
||||
}
|
||||
Db::table(TabConf::$fa_redeem_code)
|
||||
->where('id', $code)
|
||||
->data(['is_use' => 1])
|
||||
->update();
|
||||
//计算奖励
|
||||
$redeem_code_prize_config = SundryConfig::val('redeem_code_prize_config');
|
||||
$prize_arr = explode(',', $redeem_code_prize_config);
|
||||
|
||||
$prop_arr = [];
|
||||
foreach ($prize_arr as $prize_str){
|
||||
$prize_id = explode('-',$prize_str)[0];
|
||||
$prize_num = explode('-',$prize_str)[1];
|
||||
//查询道具
|
||||
$prop = Db::table(TabConf::$fa_gameprop)
|
||||
->where('id', $prize_id)
|
||||
->find();
|
||||
if (empty($prop)) {
|
||||
continue;
|
||||
}
|
||||
//查询道具
|
||||
$prop_user = Db::table(TabConf::$fa_usergameprop)
|
||||
->where('openid', api_user_openid())
|
||||
->where('gameprop_id', $prize_id)
|
||||
->find();
|
||||
if($prop_user){
|
||||
//更新
|
||||
Db::table(TabConf::$fa_usergameprop)
|
||||
->where('openid', api_user_openid())
|
||||
->where('gameprop_id', $prize_id)
|
||||
->setInc('num', $prize_num);
|
||||
$prop_user['num'] = $prop_user['num'] + $prize_num;
|
||||
$prop_arr[] = $prop_user;
|
||||
}else{
|
||||
$data = [
|
||||
'openid'=>api_user_openid(),
|
||||
'gameproptype_id'=>$prop['gameproptype_id'],
|
||||
'name'=>$prop['name'],
|
||||
'gameprop_id'=>$prize_id,
|
||||
'num'=>$prize_num,
|
||||
'image'=>$prop['image'],
|
||||
];
|
||||
//新增
|
||||
$data_id = Db::table(TabConf::$fa_usergameprop)
|
||||
->insertGetId($data);
|
||||
$data['id'] = $data_id;
|
||||
$prop_arr[] = $data;
|
||||
}
|
||||
}
|
||||
return Tools::set_ok('使用成功,返回用户获得的道具.',$prop_arr);
|
||||
});
|
||||
}
|
||||
}
|
||||
104
digital_doctor_admin/application/api/controller/Sms.php
Normal file
104
digital_doctor_admin/application/api/controller/Sms.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\library\Sms as Smslib;
|
||||
use app\common\model\User;
|
||||
use think\Hook;
|
||||
|
||||
/**
|
||||
* 手机短信接口
|
||||
*/
|
||||
class Sms extends Api
|
||||
{
|
||||
protected $noNeedLogin = '*';
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $mobile 手机号
|
||||
* @param string $event 事件名称
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
$mobile = $this->request->post("mobile");
|
||||
$event = $this->request->post("event");
|
||||
$event = $event ? $event : 'register';
|
||||
|
||||
if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) {
|
||||
$this->error(__('手机号不正确'));
|
||||
}
|
||||
$last = Smslib::get($mobile, $event);
|
||||
if ($last && time() - $last['createtime'] < 60) {
|
||||
$this->error(__('发送频繁'));
|
||||
}
|
||||
$ipSendTotal = \app\common\model\Sms::where(['ip' => $this->request->ip()])->whereTime('createtime', '-1 hours')->count();
|
||||
if ($ipSendTotal >= 5) {
|
||||
$this->error(__('发送频繁'));
|
||||
}
|
||||
if ($event) {
|
||||
$userinfo = User::getByMobile($mobile);
|
||||
if ($event == 'register' && $userinfo) {
|
||||
//已被注册
|
||||
$this->error(__('已被注册'));
|
||||
} elseif (in_array($event, ['changemobile']) && $userinfo) {
|
||||
//被占用
|
||||
$this->error(__('已被占用'));
|
||||
} elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
|
||||
//未注册
|
||||
$this->error(__('未注册'));
|
||||
}
|
||||
}
|
||||
if (!Hook::get('sms_send')) {
|
||||
$this->error(__('请在后台插件管理安装短信验证插件'));
|
||||
}
|
||||
$ret = Smslib::send($mobile, null, $event);
|
||||
if ($ret) {
|
||||
$this->success(__('发送成功'));
|
||||
} else {
|
||||
$this->error(__('发送失败,请检查短信配置是否正确'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测验证码
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $mobile 手机号
|
||||
* @param string $event 事件名称
|
||||
* @param string $captcha 验证码
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$mobile = $this->request->post("mobile");
|
||||
$event = $this->request->post("event");
|
||||
$event = $event ? $event : 'register';
|
||||
$captcha = $this->request->post("captcha");
|
||||
|
||||
if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) {
|
||||
$this->error(__('手机号不正确'));
|
||||
}
|
||||
if ($event) {
|
||||
$userinfo = User::getByMobile($mobile);
|
||||
if ($event == 'register' && $userinfo) {
|
||||
//已被注册
|
||||
$this->error(__('已被注册'));
|
||||
} elseif (in_array($event, ['changemobile']) && $userinfo) {
|
||||
//被占用
|
||||
$this->error(__('已被占用'));
|
||||
} elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
|
||||
//未注册
|
||||
$this->error(__('未注册'));
|
||||
}
|
||||
}
|
||||
$ret = Smslib::check($mobile, $captcha, $event);
|
||||
if ($ret) {
|
||||
$this->success(__('成功'));
|
||||
} else {
|
||||
$this->error(__('验证码不正确'));
|
||||
}
|
||||
}
|
||||
}
|
||||
42
digital_doctor_admin/application/api/controller/Token.php
Normal file
42
digital_doctor_admin/application/api/controller/Token.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use fast\Random;
|
||||
|
||||
/**
|
||||
* Token接口
|
||||
*/
|
||||
class Token extends Api
|
||||
{
|
||||
protected $noNeedLogin = [];
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
/**
|
||||
* 检测Token是否过期
|
||||
*
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$token = $this->auth->getToken();
|
||||
$tokenInfo = \app\common\library\Token::get($token);
|
||||
$this->success('', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新Token
|
||||
*
|
||||
*/
|
||||
public function refresh()
|
||||
{
|
||||
//删除源Token
|
||||
$token = $this->auth->getToken();
|
||||
\app\common\library\Token::delete($token);
|
||||
//创建新Token
|
||||
$token = Random::uuid();
|
||||
\app\common\library\Token::set($token, $this->auth->id, 2592000);
|
||||
$tokenInfo = \app\common\library\Token::get($token);
|
||||
$this->success('', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]);
|
||||
}
|
||||
}
|
||||
348
digital_doctor_admin/application/api/controller/User.php
Normal file
348
digital_doctor_admin/application/api/controller/User.php
Normal file
@@ -0,0 +1,348 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\library\Ems;
|
||||
use app\common\library\Sms;
|
||||
use fast\Random;
|
||||
use think\Config;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 会员接口
|
||||
*/
|
||||
class User extends Api
|
||||
{
|
||||
protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
|
||||
if (!Config::get('fastadmin.usercenter')) {
|
||||
$this->error(__('User center already closed'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员中心
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->success('', ['welcome' => $this->auth->nickname]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员登录
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $account 账号
|
||||
* @param string $password 密码
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$account = $this->request->post('account');
|
||||
$password = $this->request->post('password');
|
||||
if (!$account || !$password) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$ret = $this->auth->login($account, $password);
|
||||
if ($ret) {
|
||||
$data = ['userinfo' => $this->auth->getUserinfo()];
|
||||
$this->success(__('Logged in successful'), $data);
|
||||
} else {
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机验证码登录
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $mobile 手机号
|
||||
* @param string $captcha 验证码
|
||||
*/
|
||||
public function mobilelogin()
|
||||
{
|
||||
$mobile = $this->request->post('mobile');
|
||||
$captcha = $this->request->post('captcha');
|
||||
if (!$mobile || !$captcha) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
if (!Validate::regex($mobile, "^1\d{10}$")) {
|
||||
$this->error(__('Mobile is incorrect'));
|
||||
}
|
||||
if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
|
||||
$this->error(__('Captcha is incorrect'));
|
||||
}
|
||||
$user = \app\common\model\User::getByMobile($mobile);
|
||||
if ($user) {
|
||||
if ($user->status != 'normal') {
|
||||
$this->error(__('Account is locked'));
|
||||
}
|
||||
//如果已经有账号则直接登录
|
||||
$ret = $this->auth->direct($user->id);
|
||||
} else {
|
||||
$ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
|
||||
}
|
||||
if ($ret) {
|
||||
Sms::flush($mobile, 'mobilelogin');
|
||||
$data = ['userinfo' => $this->auth->getUserinfo()];
|
||||
$this->success(__('Logged in successful'), $data);
|
||||
} else {
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册会员
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $username 用户名
|
||||
* @param string $password 密码
|
||||
* @param string $email 邮箱
|
||||
* @param string $mobile 手机号
|
||||
* @param string $code 验证码
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$username = $this->request->post('username');
|
||||
$password = $this->request->post('password');
|
||||
$email = $this->request->post('email');
|
||||
$mobile = $this->request->post('mobile');
|
||||
$code = $this->request->post('code');
|
||||
if (!$username || !$password) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
if ($email && !Validate::is($email, "email")) {
|
||||
$this->error(__('Email is incorrect'));
|
||||
}
|
||||
if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
|
||||
$this->error(__('Mobile is incorrect'));
|
||||
}
|
||||
$ret = Sms::check($mobile, $code, 'register');
|
||||
if (!$ret) {
|
||||
$this->error(__('Captcha is incorrect'));
|
||||
}
|
||||
$ret = $this->auth->register($username, $password, $email, $mobile, []);
|
||||
if ($ret) {
|
||||
$data = ['userinfo' => $this->auth->getUserinfo()];
|
||||
$this->success(__('Sign up successful'), $data);
|
||||
} else {
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$this->auth->logout();
|
||||
$this->success(__('Logout successful'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改会员个人信息
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $avatar 头像地址
|
||||
* @param string $username 用户名
|
||||
* @param string $nickname 昵称
|
||||
* @param string $bio 个人简介
|
||||
*/
|
||||
public function profile()
|
||||
{
|
||||
$user = $this->auth->getUser();
|
||||
$username = $this->request->post('username');
|
||||
$nickname = $this->request->post('nickname');
|
||||
$bio = $this->request->post('bio');
|
||||
$avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
|
||||
if ($username) {
|
||||
$exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
|
||||
if ($exists) {
|
||||
$this->error(__('Username already exists'));
|
||||
}
|
||||
$user->username = $username;
|
||||
}
|
||||
if ($nickname) {
|
||||
$exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
|
||||
if ($exists) {
|
||||
$this->error(__('Nickname already exists'));
|
||||
}
|
||||
$user->nickname = $nickname;
|
||||
}
|
||||
$user->bio = $bio;
|
||||
$user->avatar = $avatar;
|
||||
$user->save();
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改邮箱
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $email 邮箱
|
||||
* @param string $captcha 验证码
|
||||
*/
|
||||
public function changeemail()
|
||||
{
|
||||
$user = $this->auth->getUser();
|
||||
$email = $this->request->post('email');
|
||||
$captcha = $this->request->post('captcha');
|
||||
if (!$email || !$captcha) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
if (!Validate::is($email, "email")) {
|
||||
$this->error(__('Email is incorrect'));
|
||||
}
|
||||
if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
|
||||
$this->error(__('Email already exists'));
|
||||
}
|
||||
$result = Ems::check($email, $captcha, 'changeemail');
|
||||
if (!$result) {
|
||||
$this->error(__('Captcha is incorrect'));
|
||||
}
|
||||
$verification = $user->verification;
|
||||
$verification->email = 1;
|
||||
$user->verification = $verification;
|
||||
$user->email = $email;
|
||||
$user->save();
|
||||
|
||||
Ems::flush($email, 'changeemail');
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改手机号
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $mobile 手机号
|
||||
* @param string $captcha 验证码
|
||||
*/
|
||||
public function changemobile()
|
||||
{
|
||||
$user = $this->auth->getUser();
|
||||
$mobile = $this->request->post('mobile');
|
||||
$captcha = $this->request->post('captcha');
|
||||
if (!$mobile || !$captcha) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
if (!Validate::regex($mobile, "^1\d{10}$")) {
|
||||
$this->error(__('Mobile is incorrect'));
|
||||
}
|
||||
if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
|
||||
$this->error(__('Mobile already exists'));
|
||||
}
|
||||
$result = Sms::check($mobile, $captcha, 'changemobile');
|
||||
if (!$result) {
|
||||
$this->error(__('Captcha is incorrect'));
|
||||
}
|
||||
$verification = $user->verification;
|
||||
$verification->mobile = 1;
|
||||
$user->verification = $verification;
|
||||
$user->mobile = $mobile;
|
||||
$user->save();
|
||||
|
||||
Sms::flush($mobile, 'changemobile');
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方登录
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $platform 平台名称
|
||||
* @param string $code Code码
|
||||
*/
|
||||
public function third()
|
||||
{
|
||||
$url = url('user/index');
|
||||
$platform = $this->request->post("platform");
|
||||
$code = $this->request->post("code");
|
||||
$config = get_addon_config('third');
|
||||
if (!$config || !isset($config[$platform])) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$app = new \addons\third\library\Application($config);
|
||||
//通过code换access_token和绑定会员
|
||||
$result = $app->{$platform}->getUserInfo(['code' => $code]);
|
||||
if ($result) {
|
||||
$loginret = \addons\third\library\Service::connect($platform, $result);
|
||||
if ($loginret) {
|
||||
$data = [
|
||||
'userinfo' => $this->auth->getUserinfo(),
|
||||
'thirdinfo' => $result
|
||||
];
|
||||
$this->success(__('Logged in successful'), $data);
|
||||
}
|
||||
}
|
||||
$this->error(__('Operation failed'), $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $mobile 手机号
|
||||
* @param string $newpassword 新密码
|
||||
* @param string $captcha 验证码
|
||||
*/
|
||||
public function resetpwd()
|
||||
{
|
||||
$type = $this->request->post("type", "mobile");
|
||||
$mobile = $this->request->post("mobile");
|
||||
$email = $this->request->post("email");
|
||||
$newpassword = $this->request->post("newpassword");
|
||||
$captcha = $this->request->post("captcha");
|
||||
if (!$newpassword || !$captcha) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
//验证Token
|
||||
if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
|
||||
$this->error(__('Password must be 6 to 30 characters'));
|
||||
}
|
||||
if ($type == 'mobile') {
|
||||
if (!Validate::regex($mobile, "^1\d{10}$")) {
|
||||
$this->error(__('Mobile is incorrect'));
|
||||
}
|
||||
$user = \app\common\model\User::getByMobile($mobile);
|
||||
if (!$user) {
|
||||
$this->error(__('User not found'));
|
||||
}
|
||||
$ret = Sms::check($mobile, $captcha, 'resetpwd');
|
||||
if (!$ret) {
|
||||
$this->error(__('Captcha is incorrect'));
|
||||
}
|
||||
Sms::flush($mobile, 'resetpwd');
|
||||
} else {
|
||||
if (!Validate::is($email, "email")) {
|
||||
$this->error(__('Email is incorrect'));
|
||||
}
|
||||
$user = \app\common\model\User::getByEmail($email);
|
||||
if (!$user) {
|
||||
$this->error(__('User not found'));
|
||||
}
|
||||
$ret = Ems::check($email, $captcha, 'resetpwd');
|
||||
if (!$ret) {
|
||||
$this->error(__('Captcha is incorrect'));
|
||||
}
|
||||
Ems::flush($email, 'resetpwd');
|
||||
}
|
||||
//模拟一次登录
|
||||
$this->auth->direct($user->id);
|
||||
$ret = $this->auth->changepwd($newpassword, '', true);
|
||||
if ($ret) {
|
||||
$this->success(__('Reset password successful'));
|
||||
} else {
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/7/1} {20:49}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class Usereliminate extends BaseHttpApi
|
||||
{
|
||||
|
||||
/**
|
||||
* 增加消消乐道具奖励数量
|
||||
*
|
||||
* @param string $openid 用户id
|
||||
* @param string prop_n 修改哪一个道具
|
||||
* @param string $num 数量 默认1
|
||||
*
|
||||
* api/usereliminate/add
|
||||
* author:wh
|
||||
*/
|
||||
function add(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$openid = input('openid');
|
||||
$prop_n = input('prop_n');
|
||||
$num = input('num',1);
|
||||
if(empty($openid)){
|
||||
return Tools::set_fail('缺少参数');
|
||||
}
|
||||
if(empty($prop_n)){
|
||||
return Tools::set_fail('缺少参数.');
|
||||
}
|
||||
if(empty($num)){
|
||||
return Tools::set_fail('缺少参数...');
|
||||
}
|
||||
$um = Db::table(TabConf::$fa_usereliminate)
|
||||
->where('openid',$openid)
|
||||
->find();
|
||||
if($um){
|
||||
Db::table(TabConf::$fa_usereliminate)
|
||||
->where('openid',$openid)
|
||||
->setInc($prop_n,$num);
|
||||
}else{
|
||||
Db::table(TabConf::$fa_usereliminate)
|
||||
->data([
|
||||
'openid'=>$openid,
|
||||
"$prop_n"=>$num
|
||||
])
|
||||
->insert();
|
||||
}
|
||||
|
||||
|
||||
return Tools::set_ok();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 减少消消乐道具奖励数量
|
||||
*
|
||||
* @param string $openid 用户id
|
||||
* @param string prop_n 修改哪一个道具
|
||||
* @param string $num 数量 默认1
|
||||
*
|
||||
* api/usereliminate/cut
|
||||
* author:wh
|
||||
*/
|
||||
function cut(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$openid = input('openid');
|
||||
$prop_n = input('prop_n');
|
||||
$num = input('num');//减少的数量
|
||||
if(empty($openid)){
|
||||
return Tools::set_fail('缺少参数');
|
||||
}
|
||||
if(empty($prop_n)){
|
||||
return Tools::set_fail('缺少参数.');
|
||||
}
|
||||
if(empty($num)){
|
||||
return Tools::set_fail('缺少参数...');
|
||||
}
|
||||
|
||||
Db::table(TabConf::$fa_usereliminate)
|
||||
->where('openid',$openid)
|
||||
->where($prop_n,'>',0)
|
||||
->setDec($prop_n,$num);
|
||||
|
||||
return Tools::set_ok();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/6/13} {11:33}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class Useremail extends BaseHttpApi
|
||||
{
|
||||
|
||||
/**
|
||||
* 查询当前登陆人收到的邮件(好友触发了某个操作,同时向你发送了消息,并非真实邮件)
|
||||
* 默认查询未读消息
|
||||
* 参数:无
|
||||
*/
|
||||
function getMyEmailMessage(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$info = Db::table(TabConf::$fa_user_email)
|
||||
->where('addressee_openid',api_user_openid())
|
||||
->where('status','0')//查询未读
|
||||
->select();
|
||||
return Tools::set_ok($info);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户邮件-设置已读
|
||||
* 参数:dataid 邮件的数据id
|
||||
*/
|
||||
function read(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$id = input('dataid');
|
||||
if(!$id){
|
||||
return Tools::set_fail('参数错误');
|
||||
}
|
||||
Db::table(TabConf::$fa_user_email)
|
||||
->where('id',$id)
|
||||
->where('addressee_openid',api_user_openid())
|
||||
->update(['status'=>'1']);
|
||||
return Tools::set_ok();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
<?php
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
/**
|
||||
* 用户游戏道具
|
||||
* Class Usergameprop
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Usergameprop extends BaseHttpApi
|
||||
{
|
||||
/**
|
||||
* 用户获得游戏道具接口
|
||||
* api /api/usergameprop/gainGameProp
|
||||
*
|
||||
* @param string $openid 用户openid
|
||||
* @param int $gameprop_id 道具id
|
||||
* @param int $num 道具数量
|
||||
*
|
||||
*/
|
||||
public function gainGameProp()
|
||||
{
|
||||
Tools::log_to_write_txt(['获取道具 入参:' => input()]);
|
||||
return Mmodel::catchJson(function (){
|
||||
$openid = input('openid', '');
|
||||
$gameprop_id = input('gameprop_id/d', 0);
|
||||
$num = input('num/d', 1);
|
||||
|
||||
if (empty($openid) || empty($gameprop_id)) {
|
||||
return Tools::set_fail('openid或gameprop_id不能为空');
|
||||
}
|
||||
|
||||
// 检查gameprop_id的有效性
|
||||
$gamepropExist = Db::table('fa_gameprop')->where('id', $gameprop_id)->find();
|
||||
if (!$gamepropExist) {
|
||||
return Tools::set_fail('无效的gameprop_id');
|
||||
}
|
||||
|
||||
// 检查用户是否已拥有该道具
|
||||
$propExist = Db::table('fa_usergameprop')
|
||||
->where('openid', $openid)
|
||||
->where('gameprop_id', $gameprop_id)
|
||||
->find();
|
||||
|
||||
if ($propExist) {
|
||||
// 更新道具数量
|
||||
Db::table('fa_usergameprop')
|
||||
->where('openid', $openid)
|
||||
->where('gameprop_id', $gameprop_id)
|
||||
->inc('num', $num)
|
||||
->update();
|
||||
} else {
|
||||
// 新增道具记录
|
||||
$gameproptype_id = $gamepropExist['gameproptype_id'];
|
||||
$newData = [
|
||||
'openid' => $openid,
|
||||
'gameproptype_id' => $gameproptype_id,
|
||||
'name' => $gamepropExist['name'],
|
||||
'gameprop_id' => $gameprop_id,
|
||||
'num' => $num,
|
||||
'image' => $gamepropExist['image'],
|
||||
];
|
||||
Db::table('fa_usergameprop')->insert($newData);
|
||||
}
|
||||
|
||||
Tools::log_to_write_txt(['获取道具 结果:' => '成功']);
|
||||
return Tools::set_ok('道具处理成功');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户获得的游戏道具列表接口
|
||||
* api/usergameprop/listUserGameProps
|
||||
*
|
||||
*/
|
||||
public function listUserGameProps()
|
||||
{
|
||||
Tools::log_to_write_txt(['查询道具列表 入参:' => input()]);
|
||||
|
||||
try {
|
||||
$openid = api_user_openid();
|
||||
|
||||
// 查询用户道具列表并格式化时间
|
||||
$props = Db::table('fa_usergameprop')
|
||||
->where('openid', $openid)
|
||||
->order('gameprop_id asc')
|
||||
->select();
|
||||
|
||||
Tools::log_to_write_txt(['查询道具列表 结果:' => count($props)]);
|
||||
return json(Tools::set_ok('查询成功', $props));
|
||||
} catch (Exception $e) {
|
||||
Tools::error_txt_log($e);
|
||||
return json(Tools::set_fail('错误', $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:用户消耗游戏道具
|
||||
*
|
||||
* api/usergameprop/cutGameProp
|
||||
* 参数:
|
||||
* usergameprop_id 用户的游戏道具id
|
||||
* num 消耗数量(默认1)
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function cutGameProp()
|
||||
{
|
||||
return Mmodel::catchJson(function (){
|
||||
$num = input('num',1);
|
||||
$openid = api_user_openid();
|
||||
$usergameprop_id = input('usergameprop_id/d', 0);//用户的游戏道具
|
||||
if (empty($openid) || empty($usergameprop_id)) {
|
||||
return Tools::set_fail('参数错误');
|
||||
}
|
||||
$propExist = Db::table(TabConf::$fa_usergameprop)
|
||||
->where('openid', $openid)
|
||||
->where('id', $usergameprop_id)
|
||||
->find();
|
||||
if(empty($propExist)){
|
||||
return Tools::set_fail('道具不存在');
|
||||
}
|
||||
if($propExist['num'] <= 0){
|
||||
return Tools::set_fail('道具不足');
|
||||
}
|
||||
if($propExist['num'] - $num < 0){
|
||||
return Tools::set_fail('道具不足.');
|
||||
}
|
||||
Db::table(TabConf::$fa_usergameprop)
|
||||
->where('id', $usergameprop_id)
|
||||
->setDec('num', $num);
|
||||
return Tools::set_ok('消耗成功');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,245 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/5/25} {16:37}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class Userplant extends BaseHttpApi
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:查询用户拥有的植物列表
|
||||
*
|
||||
* api/userplant/listUserPlants
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function listUserPlants(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$openid = api_user_openid();
|
||||
if (empty($openid)) {
|
||||
return Tools::set_fail('openid不能为空');
|
||||
}
|
||||
$plants = Db::table(TabConf::$fa_userplant)
|
||||
->where('openid', $openid)
|
||||
->select();
|
||||
//foreach ($plants as $plant){
|
||||
// Db::table(TabConf::$fa_userplantconflaterecord)
|
||||
//
|
||||
//}
|
||||
return Tools::set_ok('查询成功', $plants);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:植物合成
|
||||
* api/userplant/plantConflate
|
||||
*
|
||||
*
|
||||
* desc:operate_type=add时新增植物
|
||||
* plant_sit 新增植物位置
|
||||
* sys_plant_id 新增植物id(系统植物)
|
||||
*
|
||||
*
|
||||
* desc:operate_type=drag时拖拽
|
||||
* old_user_plant_data_id 原用户植物数据id
|
||||
* new_plant_sit 新植物位置
|
||||
*
|
||||
*
|
||||
* desc:operate_type=conflate时合成植物
|
||||
* target_plant_sit 目标植物位置
|
||||
* target_sys_plant_id 目标系统植物id
|
||||
* old_user_plant_data_id 旧用户植物数据id
|
||||
* new_sys_plant_data_id 新植物数据id
|
||||
*
|
||||
*
|
||||
* desc:击杀植物
|
||||
* operate_type=killPlant
|
||||
* user_plant_data_id 用户植物数据id
|
||||
*/
|
||||
function plantConflate(){
|
||||
return Mmodel::catchTransJson(function (){
|
||||
$operate_type = input('operate_type');//操作类型,add:新增,drag:拖拽、3 conflate
|
||||
|
||||
if($operate_type == 'add'){
|
||||
return $this->add();
|
||||
}else if ($operate_type == 'drag'){
|
||||
return $this->drag();
|
||||
}else if ($operate_type == 'conflate'){
|
||||
return $this->conflate();
|
||||
}
|
||||
else if ($operate_type == 'killPlant'){
|
||||
return $this->killPlant();
|
||||
}
|
||||
else{
|
||||
return Tools::set_fail('operate_type参数错误');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* author:wh
|
||||
*/
|
||||
private function add(){
|
||||
$plant_sit = input('plant_sit');
|
||||
if(empty($plant_sit)){
|
||||
return Tools::set_fail('plant_sit不能为空');
|
||||
}
|
||||
$sys_plant_id = input('sys_plant_id');
|
||||
if(empty($sys_plant_id)){
|
||||
return Tools::set_fail('新增植物id(系统植物)');
|
||||
}
|
||||
//有植物就返回该位置有植物
|
||||
$userplant = Db::table(TabConf::$fa_userplant)
|
||||
->where('openid', api_user_openid())
|
||||
->where('plant_id', $sys_plant_id)
|
||||
->where('plant_sit', $plant_sit)
|
||||
->find();
|
||||
if($userplant){
|
||||
return Tools::set_fail('该位置有植物');
|
||||
}
|
||||
$plant = Db::table(TabConf::$fa_plant)
|
||||
->where('id', $sys_plant_id)
|
||||
->find();
|
||||
if(empty($plant)){
|
||||
return Tools::set_fail('植物不存在');
|
||||
}
|
||||
$data = [
|
||||
'openid'=>api_user_openid(),
|
||||
'plant_sit'=>$plant_sit,
|
||||
'plant_id'=>$sys_plant_id,
|
||||
'name'=>$plant['name'],
|
||||
'image'=>$plant['image'],
|
||||
];
|
||||
//新增植物
|
||||
$dataid = Db::table(TabConf::$fa_userplant)
|
||||
->insertGetId($data);
|
||||
$data['id'] = $dataid;
|
||||
return Tools::set_ok('ok',$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* author:wh
|
||||
*/
|
||||
private function drag(){
|
||||
$new_plant_sit = input('new_plant_sit');
|
||||
if(empty($new_plant_sit)){
|
||||
return Tools::set_fail('新植物位置');
|
||||
}
|
||||
$old_user_plant_data_id = input('old_user_plant_data_id');
|
||||
if(empty($old_user_plant_data_id)){
|
||||
return Tools::set_fail('原用户植物数据id不能为空');
|
||||
}
|
||||
//原用户植物
|
||||
$old_user_plant = Db::table(TabConf::$fa_userplant)
|
||||
->where('id',$old_user_plant_data_id)
|
||||
->where('openid',api_user_openid())
|
||||
->find();
|
||||
if(empty($old_user_plant)){
|
||||
return Tools::set_fail('原用户植物数据不存在');
|
||||
}
|
||||
//有植物就返回该位置有植物
|
||||
$userplant = Db::table(TabConf::$fa_userplant)
|
||||
->where('openid', api_user_openid())
|
||||
->where('plant_sit', $new_plant_sit)
|
||||
->find();
|
||||
if($userplant){
|
||||
return Tools::set_fail('该位置有植物');
|
||||
}
|
||||
//更新该位置的植物
|
||||
Db::table(TabConf::$fa_userplant)
|
||||
->where('id', $old_user_plant['id'])
|
||||
->update([
|
||||
'plant_sit'=>$new_plant_sit,
|
||||
]);
|
||||
return Tools::set_ok('ok');
|
||||
}
|
||||
|
||||
/**
|
||||
* author:wh
|
||||
*/
|
||||
private function conflate(){
|
||||
$target_plant_sit = input('target_plant_sit');
|
||||
if(empty($target_plant_sit)){
|
||||
return Tools::set_fail('target_plant_sit目标植物位置不能为空');
|
||||
}
|
||||
$target_sys_plant_id = input('target_sys_plant_id');//目标植物
|
||||
if(empty($target_sys_plant_id)){
|
||||
return Tools::set_fail('目标系统植物id不能为空');
|
||||
}
|
||||
//合成逻辑,该位置没有植物,给与提示
|
||||
$userplant = Db::table(TabConf::$fa_userplant)
|
||||
->where('openid', api_user_openid())
|
||||
->where('plant_sit', $target_plant_sit)
|
||||
->find();
|
||||
if(empty($userplant)){
|
||||
return Tools::set_fail('该位置没有植物');
|
||||
}
|
||||
//获取该位置植物信息,如果该位置的植物不相等,提示不能合成
|
||||
if($userplant['plant_id'] != $target_sys_plant_id){
|
||||
return Tools::set_fail('该位置植物不相同,不能合成');
|
||||
}
|
||||
//删除原位置的植物,更新当前位置的植物信息
|
||||
$old_user_plant_data_id = input('old_user_plant_data_id');
|
||||
if(empty($old_user_plant_data_id)){
|
||||
return Tools::set_fail('原用户植物数据id不能为空');
|
||||
}
|
||||
Db::table(TabConf::$fa_userplant)
|
||||
->where('id', $old_user_plant_data_id)
|
||||
->where('openid', api_user_openid())
|
||||
->delete();
|
||||
$new_sys_plant_data_id = input('new_sys_plant_data_id');
|
||||
if(empty($new_sys_plant_data_id)){
|
||||
return Tools::set_fail('新系统植物id不能为空');
|
||||
}
|
||||
$new_plant = Db::table(TabConf::$fa_plant)
|
||||
->where('id', $new_sys_plant_data_id)
|
||||
->find();
|
||||
if(empty($new_plant)){
|
||||
return Tools::set_fail('新植物不存在');
|
||||
}
|
||||
//更新当前位置的植物信息
|
||||
Db::table(TabConf::$fa_userplant)
|
||||
->where('openid', api_user_openid())
|
||||
->where('plant_sit', $target_plant_sit)
|
||||
->update([
|
||||
'plant_id'=>$new_plant['id'],
|
||||
'name'=>$new_plant['name'],
|
||||
'image'=>$new_plant['image'],
|
||||
]);
|
||||
return Tools::set_ok('ok');
|
||||
}
|
||||
|
||||
/**
|
||||
* author:wh
|
||||
*/
|
||||
private function killPlant(){
|
||||
$user_plant_data_id = input('user_plant_data_id');
|
||||
if(empty($user_plant_data_id)){
|
||||
return Tools::set_fail('user_plant_data_id不能为空');
|
||||
}
|
||||
$userplant = Db::table(TabConf::$fa_userplant)
|
||||
->where('id', $user_plant_data_id)
|
||||
->where('openid', api_user_openid())
|
||||
->find();
|
||||
if(empty($userplant)){
|
||||
return Tools::set_fail('该植物不存在');
|
||||
}
|
||||
//删除该植物
|
||||
Db::table(TabConf::$fa_userplant)
|
||||
->where('id', $user_plant_data_id)
|
||||
->where('openid', api_user_openid())
|
||||
->delete();
|
||||
return Tools::set_ok('ok');
|
||||
}
|
||||
}
|
||||
@@ -1,909 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/3/26} {20:55}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\api\logic\UserOfflinePrizeLogic;
|
||||
use app\common\model\TabConf;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\SundryConfig;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
use wanghua\general_utility_tools_php\wechat\UserAuth;
|
||||
|
||||
class Users extends BaseHttpApi
|
||||
{
|
||||
/**
|
||||
* desc:根据游戏id查询用户
|
||||
* api/Users/getUserById
|
||||
* 参数:
|
||||
* gameid 用户id
|
||||
* author:wh
|
||||
*/
|
||||
function getUserById(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$gameid = input('gameid');
|
||||
if(empty($gameid)){
|
||||
return Tools::set_fail('参数错误');
|
||||
}
|
||||
$data = Db::table(TabConf::$fa_users)
|
||||
->where('id',$gameid*1)
|
||||
->find();
|
||||
return Tools::set_res(200,'查询成功',$data);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:根据openid查询用户
|
||||
* api/Users/getUserInfo
|
||||
* 参数:
|
||||
* openid
|
||||
*
|
||||
* 返回:
|
||||
* now_rank 当前排名
|
||||
* all_coins: 累计获得金币
|
||||
* enemy 累计击杀数
|
||||
* eliminate 消消乐道具
|
||||
*/
|
||||
function getUserInfo(){
|
||||
Tools::log_to_write_txt(['查询单个用户 入参:'=>input()]);
|
||||
try {
|
||||
|
||||
$openid = input('openid');
|
||||
if(empty($openid)){
|
||||
return json(Tools::set_fail('参数错误'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
$model_obj = Db::table('fa_users');
|
||||
|
||||
if(input('openid')){
|
||||
$model_obj->where('openid',input('openid'));
|
||||
}
|
||||
$data = $model_obj->find();
|
||||
if(empty($data)){
|
||||
return json(Tools::set_res(234,'用户不存在'));
|
||||
}
|
||||
//更新用户最后登录时间
|
||||
Db::table('fa_users')
|
||||
->data(['last_login_time'=>Tools::get_now_date()])
|
||||
->where('id',$data['id'])
|
||||
->update();
|
||||
|
||||
//写入登录记录
|
||||
Mmodel::existsUpdateInsert('fa_login_record',['date'=>date('Y-m-d')],[
|
||||
'openid'=>$openid,
|
||||
'date'=>date('Y-m-d')
|
||||
]);
|
||||
|
||||
//总计登录天数
|
||||
$data['total_login_days'] = Db::table('fa_login_record')
|
||||
->where('openid',$openid)
|
||||
->count('id');
|
||||
//当前排名
|
||||
$data['now_rank'] = $this->countRank($openid);
|
||||
|
||||
//eliminate
|
||||
$eliminate = Db::table('fa_usereliminate')
|
||||
->where('openid',$data['openid'])
|
||||
->select();
|
||||
$data['eliminate'] = $eliminate;
|
||||
|
||||
|
||||
return json(Tools::set_ok('ok',$data));
|
||||
}catch(\Exception $e){
|
||||
Tools::log_to_write_txt([
|
||||
'error'=>'查询单个用户.异常.'.$e->getMessage(),
|
||||
'参数'=>input(),
|
||||
'error_info'=>$e->getTraceAsString()
|
||||
]);
|
||||
return json(Tools::set_res(500,'操作异常',[]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:计算排名
|
||||
* author:wh
|
||||
*/
|
||||
private function countRank($openid){
|
||||
if(cache('user_rank_'.$openid)){
|
||||
return cache('user_rank_'.$openid);
|
||||
}
|
||||
$lists = Db::table(TabConf::$fa_users)
|
||||
->order('now_level desc')
|
||||
->field('openid,now_level')
|
||||
->select();
|
||||
|
||||
if($lists){
|
||||
foreach ($lists as $k=>$v){
|
||||
if($v['openid'] == $openid){
|
||||
cache('user_rank_'.$openid,$k+1,3600);
|
||||
return $k+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;//没有排名
|
||||
}
|
||||
/**
|
||||
* desc:微信授权,登录
|
||||
*
|
||||
* /api/users/login
|
||||
*
|
||||
* 参数:code
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function login()
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$clientid = input('clientid');
|
||||
if(empty($clientid)){
|
||||
return json(Tools::set_fail('clientid error'));
|
||||
}
|
||||
$code = input('code');
|
||||
if(empty($code)){
|
||||
return json(Tools::set_fail('CODE参数错误'));
|
||||
}
|
||||
$wxconfig = get_wechat_config();
|
||||
|
||||
Tools::log_to_write_txt(['微信授权,start'=>input(),'$wxconfig'=>$wxconfig]);
|
||||
$res = (new UserAuth($wxconfig))->usrAccessTokenApplet($code);
|
||||
Tools::log_to_write_txt(['微信授权,end'=>$res]);
|
||||
|
||||
|
||||
$openid = $res['openid'];
|
||||
|
||||
$user = Db::table(TabConf::$fa_users)->where('openid',$openid)->find();
|
||||
if(empty($user)){
|
||||
|
||||
$data = [
|
||||
'openid'=>$openid,
|
||||
'nickname'=>Tools::rand_str(),
|
||||
'headimage'=>'',
|
||||
'hint_num'=>3,
|
||||
'clientid'=>$clientid,
|
||||
'user_type'=>'wechat'
|
||||
];
|
||||
//新增一个用户
|
||||
$id = Db::table(TabConf::$fa_users)
|
||||
->insertGetId($data);
|
||||
$data['id'] = $id;
|
||||
}else{
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('openid',$openid)
|
||||
->data(['clientid'=>$clientid])//更新登录状态
|
||||
->update();
|
||||
$data = $user;
|
||||
}
|
||||
|
||||
session('api_user_info',$data);
|
||||
|
||||
Db::commit();
|
||||
return json(Tools::set_ok('ok',$res));
|
||||
}catch (\Exception $e){
|
||||
Db::rollback();
|
||||
Tools::log_to_write_text([
|
||||
'error'=>'微信授权异常。'.$e->getMessage(),
|
||||
'input'=>input(),
|
||||
'error_info'=>$e->getTraceAsString()
|
||||
]);
|
||||
return json(Tools::set_fail('请求异常'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:修改用户昵称、头像
|
||||
*
|
||||
* /api/users/updateuser
|
||||
*
|
||||
* 参数:
|
||||
* openid 必传
|
||||
* nickname,headimage
|
||||
*/
|
||||
function updateuser(){
|
||||
return Mmodel::catchJson(function (){
|
||||
|
||||
$nickname = input('nickname','');
|
||||
$headimage = input('headimage','');
|
||||
|
||||
$data = [];
|
||||
if($nickname){
|
||||
$data['nickname'] = $nickname;
|
||||
}
|
||||
if($headimage){
|
||||
$data['headimage'] = $headimage;
|
||||
}
|
||||
$openid = input('openid');
|
||||
if(empty($openid)){
|
||||
return Tools::set_fail('OPENID MUST');
|
||||
}
|
||||
if(!empty($data)){
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('openid',$openid)
|
||||
->data($data)
|
||||
->update();
|
||||
}
|
||||
|
||||
return Tools::set_ok();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:更新最新关卡
|
||||
* api/users/updatenowlevel
|
||||
*
|
||||
* 参数:
|
||||
* now_level 最新关卡
|
||||
* author:wh
|
||||
*/
|
||||
function updateNowLevel(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$now_level = input('now_level');
|
||||
if(empty($now_level)){
|
||||
return Tools::set_fail('now_level 必须');
|
||||
}
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('openid',api_user_openid())
|
||||
->update([
|
||||
'now_level'=>$now_level,
|
||||
]);
|
||||
return Tools::set_ok();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:查询好友列表-计算离线奖励
|
||||
* /api/users/getFriendsOfflinePrizeList
|
||||
*
|
||||
* 离线奖励:从用户下线时刻开始,每3个小时奖励一瓶随机等级的肥料,只取整数,不四舍五入。离线时长除以3取整数。
|
||||
* 比如:离线 0-2.9 个小时 不奖励
|
||||
离线 3-5.9 个小时 奖励 1瓶
|
||||
离线 6-8.9 个小时 奖励 2瓶
|
||||
*
|
||||
gameprop_id 道具奖品
|
||||
prize_all_num 总奖励数量
|
||||
self_got_num 自己保底所得数量(固定)
|
||||
can_lose_num 可被偷取的数量(固定)
|
||||
now_can_lose_num 已偷取(偷取后数值增加,数值大于可被偷取的总数量时,拒绝偷取)
|
||||
* author:wh
|
||||
*/
|
||||
function getFriendsOfflinePrizeList(){
|
||||
return Mmodel::catchJson(function (){
|
||||
//查询我的离线好友
|
||||
$friends = Db::table(TabConf::$fa_gamefriend)
|
||||
->where('openid',api_user_openid())
|
||||
->select();
|
||||
if(empty($friends)){
|
||||
return Tools::set_res(220,'没有好友');
|
||||
}
|
||||
//可偷取的奖励部分每次允许偷取比例配置
|
||||
$lose_rate = SundryConfig::val('offline_prize_can_lose_per_times_lose_rate');
|
||||
|
||||
|
||||
foreach ($friends as &$list){
|
||||
$friend_openid = $list['friend_openid'];
|
||||
$sql = "
|
||||
select * from fa_user_offline_prize a left join
|
||||
fa_user_offline_prize_got_record b
|
||||
on a.id = b.user_offline_prizeid
|
||||
where a.openid='{$friend_openid}' and b.user_offline_prizeid is null;
|
||||
";
|
||||
//查询好友的离线奖励
|
||||
$friend_prize = Db::query($sql);
|
||||
//统计我的已偷取数量
|
||||
//$my_already_lose_num = Db::table(TabConf::$fa_user_offline_prize_got_record)
|
||||
// ->where('openid',api_user_openid())
|
||||
// ->whereIn('user_offline_prizeid',array_column($friend_prize,'id'))
|
||||
// ->sum('num');
|
||||
//统计我的已偷取数量=$can_lose_num*$lose_rate,如果相等就设置偷取数量为0
|
||||
$can_lose_num_arr = array_column($friend_prize,'can_lose_num');
|
||||
//总的可偷取数量
|
||||
$can_lose_num = array_sum($can_lose_num_arr);
|
||||
$already_lose_num_arr = array_column($friend_prize,'already_lose_num');
|
||||
//已偷取的总数量
|
||||
$already_lose_num = array_sum($already_lose_num_arr);
|
||||
|
||||
$friend_prize['now_can_lose_num'] = floor(($can_lose_num-$already_lose_num)*$lose_rate);
|
||||
$friend_prize['lose_rate'] = $lose_rate;
|
||||
|
||||
$tmp_arr = [];
|
||||
//查询好友的奖励
|
||||
$tmp_arr['friend_prize'] = $friend_prize;
|
||||
$list = array_merge($list, $tmp_arr);
|
||||
|
||||
|
||||
//$can_lose_num_arr = array_column($friend_prize,'can_lose_num');
|
||||
//$can_lose_num = array_sum($can_lose_num_arr);//总的可偷取数量
|
||||
//if($my_already_lose_num == $can_lose_num*$lose_rate){
|
||||
// //默认为0
|
||||
// $friend_prize['now_can_lose_num'] = 0;
|
||||
// $friend_prize['lose_rate'] = 0;
|
||||
// $tmp_arr = [];
|
||||
// $tmp_arr['friend_prize'] = $friend_prize;
|
||||
// $list = array_merge($list, $tmp_arr);
|
||||
//}else{
|
||||
// //过滤已偷过的记录
|
||||
// //$already_lose_record = Db::table(TabConf::$fa_user_offline_prize_got_record)
|
||||
// // ->where('openid',api_user_openid())
|
||||
// // ->whereIn('user_offline_prizeid',array_column($friend_prize,'id'))
|
||||
// // ->select();
|
||||
// $friend_prize = Db::table(TabConf::$fa_user_offline_prize)
|
||||
// ->where('openid',$list['friend_openid'])
|
||||
// ->whereNotIn('id',array_column($already_lose_record,'id'))//剔除已偷过的记录
|
||||
// ->select();
|
||||
//
|
||||
// $can_lose_num_arr = array_column($friend_prize,'can_lose_num');
|
||||
// //总的可偷取数量
|
||||
// $can_lose_num = array_sum($can_lose_num_arr);
|
||||
// $already_lose_num_arr = array_column($friend_prize,'already_lose_num');
|
||||
// //已偷取的总数量
|
||||
// $already_lose_num = array_sum($already_lose_num_arr);
|
||||
//
|
||||
// $friend_prize['now_can_lose_num'] = floor(($can_lose_num-$already_lose_num)*$lose_rate);
|
||||
// $friend_prize['lose_rate'] = $lose_rate;
|
||||
//
|
||||
// $tmp_arr = [];
|
||||
// //查询好友的奖励
|
||||
// $tmp_arr['friend_prize'] = $friend_prize;
|
||||
// $list = array_merge($list, $tmp_arr);
|
||||
//}
|
||||
}
|
||||
return Tools::set_ok('ok',$friends);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:随机奖励
|
||||
*/
|
||||
private function random_prop($key=''){
|
||||
$count = Db::table(TabConf::$fa_gameprop)
|
||||
->count('id');
|
||||
$id = mt_rand(1,$count);
|
||||
|
||||
$p = Db::table(TabConf::$fa_gameprop)->where('id',$id)->find();
|
||||
if(empty($p)){
|
||||
$id = mt_rand(1,$count);
|
||||
$p = Db::table(TabConf::$fa_gameprop)->where('id',$id)->find();
|
||||
}
|
||||
if(empty($p)){
|
||||
throw new Exception('道具获取失败');
|
||||
}
|
||||
return $key?$p[$key]:$p;
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:(偷取)领取好友离线奖励(领取多少根据后台配置领取比例而定),偷取后发邮件给用户
|
||||
*
|
||||
* api/users/offlineprizegot
|
||||
* 参数:
|
||||
* friend_openid 好友
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function offlinePrizeGot(){
|
||||
return Mmodel::catchTransJson(function (){
|
||||
$friend_openid = input('friend_openid');
|
||||
if(empty($friend_openid)){
|
||||
return Tools::set_fail('friend_openid 必须');
|
||||
}
|
||||
//可偷取的奖励部分每次允许偷取比例配置
|
||||
$lose_rate = SundryConfig::val('offline_prize_can_lose_per_times_lose_rate');
|
||||
|
||||
$sql = "
|
||||
select a.* from fa_user_offline_prize a left join
|
||||
fa_user_offline_prize_got_record b
|
||||
on a.id = b.user_offline_prizeid
|
||||
where a.openid='{$friend_openid}' and b.user_offline_prizeid is null;
|
||||
";
|
||||
//查询好友的离线奖励
|
||||
$prize_lists = Db::query($sql);
|
||||
|
||||
$got_prize_arr = [];
|
||||
foreach ($prize_lists as $prize){
|
||||
$gameprop_id = $prize['gameprop_id'];
|
||||
//计算本次可领取奖励
|
||||
$num = floor($prize['can_lose_num'] * $lose_rate);
|
||||
if($num<=0){
|
||||
//偷取数量为0
|
||||
$got_prize_arr[]=[
|
||||
'num'=>0,
|
||||
'gameprop_id'=>0
|
||||
];
|
||||
continue;
|
||||
}
|
||||
//查询用户已有道具
|
||||
$usergameprop = Db::table(TabConf::$fa_usergameprop)
|
||||
->where('openid',api_user_openid())
|
||||
->where('gameprop_id',$gameprop_id)
|
||||
->find();
|
||||
//偷取时更新奖励
|
||||
if($usergameprop){
|
||||
//更新用户道具数量
|
||||
Db::table(TabConf::$fa_usergameprop)
|
||||
->where('openid',api_user_openid())
|
||||
->where('gameprop_id',$gameprop_id)
|
||||
->setInc('num',$num);
|
||||
}else{
|
||||
//查询道具
|
||||
$gameprop = Db::table(TabConf::$fa_gameprop)
|
||||
->where('id',$prize['gameprop_id'])
|
||||
->find();
|
||||
//新增用户道具
|
||||
Db::table(TabConf::$fa_usergameprop)
|
||||
->data([
|
||||
'gameproptype_id'=>$gameprop['gameproptype_id'],
|
||||
'name'=>$gameprop['name'],
|
||||
'image'=>$gameprop['image'],
|
||||
'openid'=>api_user_openid(),
|
||||
'num'=>$num,
|
||||
'gameprop_id'=>$gameprop_id
|
||||
])
|
||||
->insert();
|
||||
}
|
||||
|
||||
//偷取时,增加已偷取数量
|
||||
Db::table(TabConf::$fa_user_offline_prize)
|
||||
->where('id',$prize['id'])
|
||||
->setInc('already_lose_num',$num);
|
||||
|
||||
//写入(偷取)领取记录
|
||||
Db::table(TabConf::$fa_user_offline_prize_got_record)
|
||||
->data([
|
||||
'openid'=>api_user_openid(),
|
||||
'friend_openid'=>$friend_openid,
|
||||
'num'=>$num,
|
||||
'gameprop_id'=>$gameprop_id,
|
||||
'user_offline_prizeid'=>$prize['id'],//记录id
|
||||
])
|
||||
->insert();
|
||||
$got_prize_arr[]=[
|
||||
'num'=>$num,
|
||||
'gameprop_id'=>$gameprop_id
|
||||
];
|
||||
|
||||
}
|
||||
//添加一封邮件(不是真实的邮件,可以理解为消息)
|
||||
Db::table(TabConf::$fa_user_email)
|
||||
->data([
|
||||
'addresser_openid'=>api_user_openid(),
|
||||
'addressee_openid'=>$friend_openid,//收件人
|
||||
'title'=>'好友偷取奖励',
|
||||
'content'=>'您的奖励已被好友偷取啦!',
|
||||
])
|
||||
->insert();
|
||||
return Tools::set_ok('ok',$got_prize_arr);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询自己的离线奖励
|
||||
*
|
||||
* 离线奖励:从用户下线时刻开始,每3个小时奖励一瓶随机等级的肥料,只取整数,不四舍五入。离线时长除以3取整数。
|
||||
* 比如:离线 0-2.9 个小时 不奖励
|
||||
离线 3-5.9 个小时 奖励 1瓶
|
||||
离线 6-8.9 个小时 奖励 2瓶
|
||||
*
|
||||
* api/users/getselfofflineprize
|
||||
*/
|
||||
function getSelfOfflinePrize(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$lists = Db::table(TabConf::$fa_user_offline_prize)
|
||||
->where('openid',api_user_openid())
|
||||
->order('id asc')//客户端要取最早的那个时间
|
||||
->select();
|
||||
if(empty($lists)){
|
||||
return Tools::set_res(220,'没有离线奖励');
|
||||
}
|
||||
//可偷取的奖励部分每次允许偷取比例配置
|
||||
$lose_rate = SundryConfig::val('offline_prize_can_lose_per_times_lose_rate');
|
||||
$lists_data = [];
|
||||
foreach ($lists as $list){
|
||||
if($list['self_got_num']==0){
|
||||
continue;//领取过的数据,不返回
|
||||
}
|
||||
$record = Db::table(TabConf::$fa_user_offline_prize_got_record)
|
||||
->where('openid',api_user_openid())//当前登陆人
|
||||
->where('user_offline_prizeid',$list['id'])
|
||||
->find();
|
||||
if(empty($record)){//为空说明未偷取
|
||||
$lists_data[] = array_merge($list, ['now_can_lose_num'=>floor($list['can_lose_num']*$lose_rate),'lose_rate'=>$lose_rate]);
|
||||
}else{
|
||||
$lists_data[] = array_merge($list, ['now_can_lose_num'=>0]);
|
||||
}
|
||||
}
|
||||
return Tools::set_ok('ok',$lists_data);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* desc:领取自己的离线奖励(一次性领取所有离线奖励,不能分批次领取,没有部分领取一说)
|
||||
* api/users/receiveSelfOfflinePrize
|
||||
* 参数:
|
||||
* is_double 是否双倍奖励 1 一倍,2 二倍
|
||||
* author:wh
|
||||
*/
|
||||
function receiveSelfOfflinePrize(){
|
||||
return Mmodel::catchTransJson(function (){
|
||||
//查询我的离线奖励
|
||||
$prize_lists = Db::table(TabConf::$fa_user_offline_prize)
|
||||
->where('openid',api_user_openid())
|
||||
->lock(true)//锁住
|
||||
->select();
|
||||
|
||||
$got_prize_arr = [];
|
||||
//是否双倍奖励 1 一倍,2 二倍
|
||||
$is_double = input('is_double',1);
|
||||
foreach ($prize_lists as $item){
|
||||
//查询领取记录
|
||||
$offline_prize_got_record = Db::table(TabConf::$fa_user_offline_prize_got_record)
|
||||
->where('openid',api_user_openid())
|
||||
->where('user_offline_prizeid',$item['id'])
|
||||
->find();
|
||||
if($offline_prize_got_record){
|
||||
continue;//领取过的数据,不能再次领取
|
||||
}
|
||||
//道具id
|
||||
$gameprop_id = $item['gameprop_id'];
|
||||
//自己保底所得数量+可被偷取的数量-已被偷取的数量
|
||||
$prize_all_num = $item['self_got_num'] + $item['can_lose_num'] - $item['already_lose_num'];
|
||||
//乘以倍数
|
||||
$num = $prize_all_num * $is_double;
|
||||
|
||||
//查询道具
|
||||
$gameprop = Db::table(TabConf::$fa_gameprop)
|
||||
->where('id',$gameprop_id)
|
||||
->find();
|
||||
if(empty($gameprop)){
|
||||
//道具不应该不存在
|
||||
continue;
|
||||
//return Tools::set_fail('道具不存在');
|
||||
}
|
||||
//写入领取记录
|
||||
Db::table(TabConf::$fa_user_offline_prize_got_record)
|
||||
->data([
|
||||
'openid'=>api_user_openid(),
|
||||
'num'=>$num,
|
||||
'gameprop_id'=>$gameprop_id,
|
||||
'is_double'=>$is_double,
|
||||
'user_offline_prizeid'=>$item['id'],
|
||||
])
|
||||
->insert();
|
||||
//查询用户已有道具
|
||||
$usergameprop = Db::table(TabConf::$fa_usergameprop)
|
||||
->where('openid',api_user_openid())
|
||||
->where('gameprop_id',$gameprop_id)
|
||||
->find();
|
||||
if($usergameprop){
|
||||
//更新道具数量
|
||||
Db::table(TabConf::$fa_usergameprop)
|
||||
->where('openid',api_user_openid())
|
||||
->where('gameprop_id',$gameprop_id)
|
||||
->setInc('num',$num);
|
||||
}else{
|
||||
//新增道具
|
||||
Db::table(TabConf::$fa_usergameprop)
|
||||
->data([
|
||||
'gameproptype_id'=>$gameprop['gameproptype_id'],
|
||||
'name'=>$gameprop['name'],
|
||||
'image'=>$gameprop['image'],
|
||||
'openid'=>api_user_openid(),
|
||||
'num'=>$num,
|
||||
'gameprop_id'=>$gameprop_id
|
||||
])
|
||||
->insert();
|
||||
}
|
||||
|
||||
Db::table(TabConf::$fa_user_offline_prize)
|
||||
->where('id',$item['id'])
|
||||
->data([
|
||||
'self_got_num'=>0,
|
||||
'can_lose_num'=>0,
|
||||
])
|
||||
->update();
|
||||
$got_prize_arr[]=[
|
||||
'num'=>$num,
|
||||
'gameprop_id'=>$gameprop_id
|
||||
];
|
||||
}
|
||||
//领取之后删除离线奖励表
|
||||
UserOfflinePrizeLogic::deletedPrize(api_user_openid());
|
||||
return Tools::set_ok('领取成功',$got_prize_arr);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:查询我的好友列表
|
||||
*
|
||||
* api/users/getMyFriends
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function getMyFriends(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$lists = Db::table(TabConf::$fa_gamefriend)
|
||||
->where('openid',api_user_openid())
|
||||
->select();
|
||||
return Tools::set_ok('ok',$lists);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* desc:添加好友
|
||||
*
|
||||
* api/users/addFriend
|
||||
* 参数:
|
||||
* friend_openid 好友openid
|
||||
* 注意:如果好友在线,会向好友发送申请消息
|
||||
* author:wh
|
||||
*/
|
||||
function addFriend(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$friend_openid = input('friend_openid');
|
||||
if(empty($friend_openid)){
|
||||
return Tools::set_fail('请输入好友openid');
|
||||
}
|
||||
$user_friend = Db::table(TabConf::$fa_users)
|
||||
->where('openid',$friend_openid)
|
||||
->find();
|
||||
if(empty($user_friend)){
|
||||
return Tools::set_fail('好友不存在');
|
||||
}
|
||||
$uf = Db::table(TabConf::$fa_gamefriend)
|
||||
->where('openid',api_user_openid())
|
||||
->where('friend_openid',$friend_openid)
|
||||
->find();
|
||||
if($uf){
|
||||
return Tools::set_fail('不能添加自己和自己的好友');
|
||||
}
|
||||
if($friend_openid == api_user_openid()){
|
||||
return Tools::set_fail('不能添加自己');
|
||||
}
|
||||
$data = [
|
||||
'openid'=>api_user_openid(),
|
||||
'headimage'=>api_user_info('headimage'),
|
||||
'nickname'=>api_user_info('nickname'),
|
||||
'friend_openid'=>$friend_openid,
|
||||
'friend_nickname'=>$user_friend['nickname']
|
||||
];
|
||||
//如果已经申请则不再申请
|
||||
$apply_record = Db::table(TabConf::$fa_friend_apply_record)
|
||||
->where('openid',api_user_openid())
|
||||
->where('friend_openid',$friend_openid)
|
||||
->find();
|
||||
if($apply_record){
|
||||
return Tools::set_fail('你已申请过该好友');
|
||||
}
|
||||
|
||||
Db::table(TabConf::$fa_friend_apply_record)
|
||||
->data($data)
|
||||
->insert();
|
||||
|
||||
//如果好友在线,则发送添加好友申请
|
||||
if($user_friend['clientid']){
|
||||
$json = BaseWssApi::json_wss('new-friend-apply', '有新的好友申请');
|
||||
Gateway::sendToClient($user_friend['clientid'], json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
return Tools::set_ok('申请已发送');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:查询我的好友申请列表
|
||||
*
|
||||
* api/users/getFriendApplyList
|
||||
* author:wh
|
||||
*/
|
||||
function getFriendApplyList(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$friend_apply_record = Db::table(TabConf::$fa_friend_apply_record)
|
||||
->where('friend_openid',api_user_openid())
|
||||
->select();
|
||||
return Tools::set_ok('ok',$friend_apply_record);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 同意好友申请
|
||||
* api/users/agreeFriendApply
|
||||
* 参数:
|
||||
* friend_openid 好友openid
|
||||
*/
|
||||
function agreeFriendApply(){
|
||||
return Mmodel::catchTransJson(function (){
|
||||
$friend_openid = input('friend_openid');
|
||||
if(empty($friend_openid)){
|
||||
return Tools::set_fail('请输入好友openid');
|
||||
}
|
||||
$user_friend = Db::table(TabConf::$fa_users)
|
||||
->where('openid',$friend_openid)
|
||||
->find();
|
||||
if(empty($user_friend)){
|
||||
return Tools::set_fail('好友不存在.');
|
||||
}
|
||||
//好友已存在
|
||||
$uf = Db::table(TabConf::$fa_gamefriend)
|
||||
->where('openid',api_user_openid())
|
||||
->where('friend_openid',$friend_openid)
|
||||
->find();
|
||||
if($uf){
|
||||
return Tools::set_fail('好友已存在');
|
||||
}
|
||||
//添加陌生人为好友
|
||||
Db::table(TabConf::$fa_gamefriend)
|
||||
->data([
|
||||
'openid'=>api_user_openid(),
|
||||
'nickname'=>api_user_info('nickname'),
|
||||
'friend_openid'=>$friend_openid,
|
||||
'friend_nickname'=>$user_friend['nickname'],
|
||||
'friend_image'=>$user_friend['headimage'],
|
||||
])
|
||||
->insert();
|
||||
//把自己添加为陌生人的好友
|
||||
Db::table(TabConf::$fa_gamefriend)
|
||||
->data([
|
||||
'openid'=>$friend_openid,
|
||||
'nickname'=>$user_friend['nickname'],
|
||||
'friend_openid'=>api_user_openid(),
|
||||
'friend_nickname'=>api_user_info('nickname'),
|
||||
'friend_image'=>api_user_info('headimage'),
|
||||
])
|
||||
->insert();
|
||||
|
||||
//删除好友申请记录
|
||||
Db::table(TabConf::$fa_friend_apply_record)
|
||||
->where('openid',$friend_openid)
|
||||
//->where('friend_openid',$friend_openid)
|
||||
->delete();
|
||||
return Tools::set_ok('ok');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 拒绝好友申请
|
||||
*
|
||||
* api/users/refuseFriendApply
|
||||
* 参数:
|
||||
* friend_openid 好友openid
|
||||
*/
|
||||
function refuseFriendApply(){
|
||||
return Mmodel::catchTransJson(function (){
|
||||
$friend_openid = input('friend_openid');
|
||||
if(empty($friend_openid)){
|
||||
return Tools::set_fail('请输入好友openid');
|
||||
}
|
||||
$users = Db::table(TabConf::$fa_users)
|
||||
->where('openid',$friend_openid)
|
||||
->find();
|
||||
if(empty($users)){
|
||||
return Tools::set_fail('用户不存在');
|
||||
}
|
||||
//删除好友申请记录
|
||||
Db::table(TabConf::$fa_friend_apply_record)
|
||||
->where('openid',$friend_openid)
|
||||
//->where('friend_openid',$friend_openid)
|
||||
->delete();
|
||||
return Tools::set_ok('ok');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:增加金币,直接存用户信息里
|
||||
* author:wh
|
||||
* 参数:
|
||||
* coins 金币数量
|
||||
*/
|
||||
function addCoins(){
|
||||
return Mmodel::catchTransJson(function (){
|
||||
$coins = input('coins');
|
||||
if(empty($coins)){
|
||||
return Tools::set_fail('请输入金币');
|
||||
}
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('openid',api_user_openid())
|
||||
->setInc('coins',$coins);
|
||||
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('openid',api_user_openid())
|
||||
->setInc('all_coins',$coins);//累计金币
|
||||
|
||||
return Tools::set_ok('ok');
|
||||
});
|
||||
}
|
||||
/**
|
||||
* desc:消耗金币
|
||||
* author:wh
|
||||
* 参数:
|
||||
* coins 金币数量
|
||||
*/
|
||||
function cutCoins(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$coins = input('coins');
|
||||
if(empty($coins)){
|
||||
return Tools::set_fail('请输入金币');
|
||||
}
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('openid',api_user_openid())
|
||||
->setDec('coins',$coins);
|
||||
return Tools::set_ok('ok');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 消耗金币增加体力(消耗金币增加体力次数减一)
|
||||
* 参数:无
|
||||
* api/users/cutCoinsAddStrength
|
||||
*/
|
||||
function cutCoinsAddStrength(){
|
||||
return Mmodel::catchTransJson(function (){
|
||||
//消耗金币增加体力的金币数值配置
|
||||
$cut_n_coins_add_power = SundryConfig::val('cut_n_coins_add_power');
|
||||
$user = Db::table(TabConf::$fa_users)
|
||||
->where('openid',api_user_openid())
|
||||
->lock(true)
|
||||
->find();
|
||||
if($user['coin_power_times'] <= 0){
|
||||
return Tools::set_fail('金币增加体力次数不足');
|
||||
}
|
||||
if($user['coins'] < $cut_n_coins_add_power){
|
||||
return Tools::set_fail('金币不足');
|
||||
}
|
||||
//消耗金币
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('openid',api_user_openid())
|
||||
->setDec('coins',$cut_n_coins_add_power);
|
||||
//增加体力
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('openid',api_user_openid())
|
||||
->setInc('power',1);
|
||||
|
||||
//减少金币增加体力次数
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('openid',api_user_openid())
|
||||
->where('coin_power_times','>',0)
|
||||
->setDec('coin_power_times',1);
|
||||
|
||||
return Tools::set_ok('ok');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 看广告增加体力 (看广告增加体力次数减一)
|
||||
* 参数:无
|
||||
* api/users/lookAdAddPower
|
||||
*/
|
||||
function lookAdAddPower(){
|
||||
return Mmodel::catchTransJson(function (){
|
||||
$user = Db::table(TabConf::$fa_users)
|
||||
->where('openid',api_user_openid())
|
||||
->lock(true)
|
||||
->find();
|
||||
if($user['ad_power_times'] <= 0){
|
||||
return Tools::set_fail('看广告增加体力次数不足');
|
||||
}
|
||||
//增加体力
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('openid',api_user_openid())
|
||||
->setInc('power',1);
|
||||
|
||||
//
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('openid',api_user_openid())
|
||||
->where('ad_power_times','>',0)
|
||||
->setDec('ad_power_times',1);
|
||||
|
||||
return Tools::set_ok('ok');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
163
digital_doctor_admin/application/api/controller/Validate.php
Normal file
163
digital_doctor_admin/application/api/controller/Validate.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\model\User;
|
||||
|
||||
/**
|
||||
* 验证接口
|
||||
*/
|
||||
class Validate extends Api
|
||||
{
|
||||
protected $noNeedLogin = '*';
|
||||
protected $layout = '';
|
||||
protected $error = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测邮箱
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $email 邮箱
|
||||
* @param string $id 排除会员ID
|
||||
*/
|
||||
public function check_email_available()
|
||||
{
|
||||
$email = $this->request->post('email');
|
||||
$id = (int)$this->request->post('id');
|
||||
$count = User::where('email', '=', $email)->where('id', '<>', $id)->count();
|
||||
if ($count > 0) {
|
||||
$this->error(__('邮箱已经被占用'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测用户名
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $username 用户名
|
||||
* @param string $id 排除会员ID
|
||||
*/
|
||||
public function check_username_available()
|
||||
{
|
||||
$username = $this->request->post('username');
|
||||
$id = (int)$this->request->post('id');
|
||||
$count = User::where('username', '=', $username)->where('id', '<>', $id)->count();
|
||||
if ($count > 0) {
|
||||
$this->error(__('用户名已经被占用'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测昵称
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $nickname 昵称
|
||||
* @param string $id 排除会员ID
|
||||
*/
|
||||
public function check_nickname_available()
|
||||
{
|
||||
$nickname = $this->request->post('nickname');
|
||||
$id = (int)$this->request->post('id');
|
||||
$count = User::where('nickname', '=', $nickname)->where('id', '<>', $id)->count();
|
||||
if ($count > 0) {
|
||||
$this->error(__('昵称已经被占用'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测手机
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $mobile 手机号
|
||||
* @param string $id 排除会员ID
|
||||
*/
|
||||
public function check_mobile_available()
|
||||
{
|
||||
$mobile = $this->request->post('mobile');
|
||||
$id = (int)$this->request->post('id');
|
||||
$count = User::where('mobile', '=', $mobile)->where('id', '<>', $id)->count();
|
||||
if ($count > 0) {
|
||||
$this->error(__('该手机号已经占用'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测手机
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $mobile 手机号
|
||||
*/
|
||||
public function check_mobile_exist()
|
||||
{
|
||||
$mobile = $this->request->post('mobile');
|
||||
$count = User::where('mobile', '=', $mobile)->count();
|
||||
if (!$count) {
|
||||
$this->error(__('手机号不存在'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测邮箱
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $mobile 邮箱
|
||||
*/
|
||||
public function check_email_exist()
|
||||
{
|
||||
$email = $this->request->post('email');
|
||||
$count = User::where('email', '=', $email)->count();
|
||||
if (!$count) {
|
||||
$this->error(__('邮箱不存在'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测手机验证码
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $mobile 手机号
|
||||
* @param string $captcha 验证码
|
||||
* @param string $event 事件
|
||||
*/
|
||||
public function check_sms_correct()
|
||||
{
|
||||
$mobile = $this->request->post('mobile');
|
||||
$captcha = $this->request->post('captcha');
|
||||
$event = $this->request->post('event');
|
||||
if (!\app\common\library\Sms::check($mobile, $captcha, $event)) {
|
||||
$this->error(__('验证码不正确'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测邮箱验证码
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $email 邮箱
|
||||
* @param string $captcha 验证码
|
||||
* @param string $event 事件
|
||||
*/
|
||||
public function check_ems_correct()
|
||||
{
|
||||
$email = $this->request->post('email');
|
||||
$captcha = $this->request->post('captcha');
|
||||
$event = $this->request->post('event');
|
||||
if (!\app\common\library\Ems::check($email, $captcha, $event)) {
|
||||
$this->error(__('验证码不正确'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/4/5} {19:51}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\api\logic\StatisticsLogic;
|
||||
use app\common\model\TabConf;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Date;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
|
||||
/**
|
||||
* socket 主动推送
|
||||
*
|
||||
* Class Wsspush
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Wsspush extends BaseWssApi
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$socketTaskId = input('socketTaskId');
|
||||
Gateway::sendToClient($socketTaskId,json_encode(Tools::set_ok('向指定客户端发送信息。',$socketTaskId),JSON_UNESCAPED_UNICODE));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function hello($name = 'ThinkPHP5')
|
||||
{
|
||||
return 'hello,' . $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:向客户端推送消息
|
||||
*
|
||||
* 接收一维数组表单
|
||||
*
|
||||
* /api/wsspush/pushMessageToClient
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function pushMessageToClient(){
|
||||
$socketTaskId = input('clientid');
|
||||
if(empty($socketTaskId)){
|
||||
return json(Tools::set_fail('客户端id必须'));
|
||||
}
|
||||
|
||||
$action = input('action');
|
||||
if(empty($action)){
|
||||
return json(Tools::set_fail('ACTION MUST'));
|
||||
}
|
||||
|
||||
$msg = input('msg');
|
||||
if(empty($msg)){
|
||||
return json(Tools::set_fail('MSG MUST'));
|
||||
}
|
||||
$all_params = [];
|
||||
foreach (input() as $key=>$item){
|
||||
if(in_array($key, ['clientid','action','msg'])){
|
||||
continue;
|
||||
}
|
||||
$all_params[$key] = $item;
|
||||
}
|
||||
|
||||
//json_encode(Tools::set_ok('向指定客户端发送信息。',$socketTaskId),JSON_UNESCAPED_UNICODE);
|
||||
$json = self::json_wss($action,$msg,$all_params);
|
||||
|
||||
Gateway::sendToClient($socketTaskId, $json);
|
||||
return json(Tools::set_ok('向指定客户端发送信息成功。'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user