t
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?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'=>'服务运行中'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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不合法');
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
187
digital_doctor_admin/application/api/controller/Douyin.php
Normal file
187
digital_doctor_admin/application/api/controller/Douyin.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
}
|
||||
41
digital_doctor_admin/application/api/controller/Enemy.php
Normal file
41
digital_doctor_admin/application/api/controller/Enemy.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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();
|
||||
});
|
||||
}
|
||||
}
|
||||
95
digital_doctor_admin/application/api/controller/Friends.php
Normal file
95
digital_doctor_admin/application/api/controller/Friends.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?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');
|
||||
// });
|
||||
//}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?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');
|
||||
});
|
||||
}
|
||||
}
|
||||
81
digital_doctor_admin/application/api/controller/Gameprop.php
Normal file
81
digital_doctor_admin/application/api/controller/Gameprop.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?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);
|
||||
});
|
||||
}
|
||||
}
|
||||
33
digital_doctor_admin/application/api/controller/Notice.php
Normal file
33
digital_doctor_admin/application/api/controller/Notice.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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);
|
||||
});
|
||||
}
|
||||
}
|
||||
120
digital_doctor_admin/application/api/controller/Plant.php
Normal file
120
digital_doctor_admin/application/api/controller/Plant.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?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 (){
|
||||
//
|
||||
// });
|
||||
//}
|
||||
}
|
||||
54
digital_doctor_admin/application/api/controller/Power.php
Normal file
54
digital_doctor_admin/application/api/controller/Power.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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);
|
||||
});
|
||||
}
|
||||
}
|
||||
128
digital_doctor_admin/application/api/controller/Redeemcode.php
Normal file
128
digital_doctor_admin/application/api/controller/Redeemcode.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?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);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?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();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?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();
|
||||
});
|
||||
}
|
||||
}
|
||||
140
digital_doctor_admin/application/api/controller/Usergameprop.php
Normal file
140
digital_doctor_admin/application/api/controller/Usergameprop.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?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('消耗成功');
|
||||
});
|
||||
}
|
||||
}
|
||||
245
digital_doctor_admin/application/api/controller/Userplant.php
Normal file
245
digital_doctor_admin/application/api/controller/Userplant.php
Normal file
@@ -0,0 +1,245 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
909
digital_doctor_admin/application/api/controller/Users.php
Normal file
909
digital_doctor_admin/application/api/controller/Users.php
Normal file
@@ -0,0 +1,909 @@
|
||||
<?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');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
81
digital_doctor_admin/application/api/controller/Wsspush.php
Normal file
81
digital_doctor_admin/application/api/controller/Wsspush.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?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('向指定客户端发送信息成功。'));
|
||||
}
|
||||
}
|
||||
103
digital_doctor_admin/application/api/logic/BaseLogic.php
Normal file
103
digital_doctor_admin/application/api/logic/BaseLogic.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/5/23} {18:01}
|
||||
*/
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\api\controller\BaseWssApi;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class BaseLogic
|
||||
{
|
||||
function domsg($client_id, $data){
|
||||
try {
|
||||
$res = @json_decode($data, true);
|
||||
Tools::log_to_write_txt(['json_decode:', $res]);
|
||||
if (!$res) {
|
||||
$json = BaseWssApi::json_wss('error', '消息格式错误');
|
||||
Gateway::sendToClient($client_id, json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
return;
|
||||
}
|
||||
if (empty($res['action'])) {
|
||||
$json = BaseWssApi::json_wss('error', '消息格式错误,action必须');
|
||||
Gateway::sendToClient($client_id, json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
return;
|
||||
}
|
||||
$act_arr = explode('/', $res['action']);
|
||||
if (empty($act_arr[0])) {
|
||||
$json = BaseWssApi::json_wss('error', '错误的action格式');
|
||||
Gateway::sendToClient($client_id, json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
return;
|
||||
}
|
||||
if (empty($act_arr[1])) {
|
||||
$json = BaseWssApi::json_wss('error', '错误的action格式!');
|
||||
Gateway::sendToClient($client_id, json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
return;
|
||||
}
|
||||
//根据action执行业务逻辑
|
||||
$controller = ucfirst($act_arr[0]);
|
||||
$function = $act_arr[1];
|
||||
$object = '\\app\\api\\logic\\' . $controller . 'Logic';
|
||||
$obj = $this->getinstance($object);
|
||||
$obj->$function($client_id, $res);
|
||||
} catch (\Exception $e) {
|
||||
Tools::error_txt_log($e);
|
||||
$json = BaseWssApi::json_wss('error', '服务繁忙');
|
||||
Gateway::sendToClient($client_id, json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
function getinstance($className)
|
||||
{
|
||||
// 类名字符串
|
||||
// 参数数组
|
||||
|
||||
// 确保类存在
|
||||
if (!class_exists($className)) {
|
||||
throw new \InvalidArgumentException("Class {$className} does not exist.");
|
||||
}
|
||||
// 创建反射类实例
|
||||
$reflection = new \ReflectionClass($className);
|
||||
|
||||
// 检查构造函数是否存在
|
||||
//if (!$reflection->hasMethod('__construct')) {
|
||||
// throw new \LogicException("Class {$className} has no constructor.");
|
||||
//}
|
||||
//$constructor = $reflection->getConstructor();
|
||||
|
||||
// 如果构造函数有参数,我们需要匹配参数
|
||||
//if ($constructor !== null) {
|
||||
// $constructorParams = $constructor->getParameters();
|
||||
//
|
||||
// // 确保参数数量匹配
|
||||
// if (count($constructorParams) !== count($params)) {
|
||||
// throw new \InvalidArgumentException("Number of constructor parameters does not match provided arguments.");
|
||||
//
|
||||
// }
|
||||
// // 创建参数数组,将参数类型与值匹配
|
||||
// $matchedParams = [];
|
||||
// foreach ($constructorParams as $index => $param) {
|
||||
// // 如果参数允许null,或者参数类型与传递的值兼容,添加到匹配参数数组
|
||||
// if ($param->allowsNull() || $param->getClass() === null || $param->getClass()->isInstance($params[$index])) {
|
||||
// $matchedParams[] = $params[$index];
|
||||
// } else {
|
||||
// throw new \InvalidArgumentException("Provided argument does not match constructor parameter type at position {$index}.");
|
||||
// }
|
||||
// }
|
||||
// // 使用反射类创建并初始化类实例
|
||||
// $instance = $reflection->newInstanceArgs($matchedParams);
|
||||
//} else {
|
||||
//
|
||||
//}
|
||||
// 构造函数无参数,直接创建实例
|
||||
$instance = $reflection->newInstanceWithoutConstructor();
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
36
digital_doctor_admin/application/api/logic/EnemyLogic.php
Normal file
36
digital_doctor_admin/application/api/logic/EnemyLogic.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/6/18} {18:05}
|
||||
*/
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class EnemyLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:累加击杀敌人数量
|
||||
*
|
||||
* 参数:enemy_num
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function addKillEnemyNum(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$enemy_num = input('enemy_num',1);
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('openid',api_user_openid())
|
||||
->setInc('enemy',$enemy_num);//累加击杀敌人数量
|
||||
return Tools::set_ok();
|
||||
});
|
||||
}
|
||||
}
|
||||
70
digital_doctor_admin/application/api/logic/UserLogic.php
Normal file
70
digital_doctor_admin/application/api/logic/UserLogic.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/5/23} {18:01}
|
||||
*/
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\api\controller\BaseWssApi;
|
||||
use app\common\model\TabConf;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class UserLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:客户端离线
|
||||
* author:wh
|
||||
*/
|
||||
function offline($client_id){
|
||||
Mmodel::catchTrans(function () use ($client_id){
|
||||
Tools::log_to_write_txt(['服务端收到客户端离线消息:client_id:' . $client_id]);
|
||||
|
||||
$user = Db::table(TabConf::$fa_users)
|
||||
->where('clientid', $client_id)
|
||||
->find();
|
||||
if(empty($user)){
|
||||
Tools::log_to_write_txt(['error:客户端离线,用户不存在:client_id:' . $client_id]);
|
||||
return ;
|
||||
}
|
||||
|
||||
Tools::log_to_write_txt(['写入离线记录:openid:' . $user['openid']]);
|
||||
//写入离线记录
|
||||
Db::table(TabConf::$fa_user_offline_record)
|
||||
->insert([
|
||||
'openid'=>$user['openid'],
|
||||
]);
|
||||
|
||||
Tools::log_to_write_txt(['设置离线时间:clientid:' . $client_id]);
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('clientid', $client_id)
|
||||
->data([
|
||||
'clientid'=>'',
|
||||
'offline_time'=>Tools::get_now_date(),//离线时间
|
||||
])
|
||||
->update();
|
||||
|
||||
Tools::log_to_write_txt(['好友列表设置为离线:openid:' . $user['openid']]);
|
||||
//好友列表设置为离线
|
||||
Db::table(TabConf::$fa_gamefriend)
|
||||
->data([
|
||||
'offline_time'=>Tools::get_now_date(),//离线时间
|
||||
])
|
||||
->where('friend_openid',$user['openid'])
|
||||
->update();
|
||||
|
||||
Tools::log_to_write_txt(['返回离线消息']);
|
||||
|
||||
//在$client_id无效的情况下可能会抛出异常
|
||||
//$json = BaseWssApi::json_wss('ok', '用户已离线');
|
||||
//Gateway::sendToClient($client_id, json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/6/2} {10:51}
|
||||
*/
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
|
||||
/**
|
||||
* 用户离线奖品表(用户上线时写入,领取后删除)
|
||||
* Class UserOfflinePrizeLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class UserOfflinePrizeLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:查询最早的一条奖品数据
|
||||
* author:wh
|
||||
* @param $openid
|
||||
*/
|
||||
static function getFirstPrizeRecord($openid){
|
||||
return Db::table(TabConf::$fa_user_offline_prize)
|
||||
->where('openid',$openid)
|
||||
->order('id asc')
|
||||
->find();
|
||||
}
|
||||
/**
|
||||
* desc:用户上线时写入奖品(存在则num加1)
|
||||
* author:wh
|
||||
*/
|
||||
static function insertPrize($openid,$gameprop_id,$num){
|
||||
//
|
||||
$prize = Db::table(TabConf::$fa_user_offline_prize)
|
||||
->where('openid',$openid)
|
||||
->where('gameprop_id',$gameprop_id)
|
||||
->find();
|
||||
if($prize){
|
||||
Db::table(TabConf::$fa_user_offline_prize)
|
||||
->where('id',$prize['id'])
|
||||
->setInc('num',$num);
|
||||
}else{
|
||||
Db::table(TabConf::$fa_user_offline_prize)
|
||||
->insert([
|
||||
'openid'=>$openid,
|
||||
'gameprop_id'=>$gameprop_id,
|
||||
'num'=>$num
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:领取后删除
|
||||
* author:wh
|
||||
* @param $openid
|
||||
*/
|
||||
static function deletedPrize($openid){
|
||||
Db::table(TabConf::$fa_user_offline_prize)
|
||||
->where('openid',$openid)
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/5/23} {17:34}
|
||||
*/
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\api\controller\BaseWssApi;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class WssMessageLogic extends BaseLogic
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user