fixed
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class BaseCommonController extends BaseController
|
||||
foreach ($configs as $config){
|
||||
if($straction == $config['url']){
|
||||
//模块维护中
|
||||
return ['is_maintain'=>true,'msg'=>$config['msg'],'openid'=>$config['openid']];
|
||||
return ['is_maintain'=>true,'msg'=>$config['msg'],'openid'=>isset($config['openid'])?$config['openid']:''];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,205 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/6/3} {15:56}
|
||||
*/
|
||||
|
||||
namespace app\index\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\SundryConfig;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
/**
|
||||
* 离线奖励计算任务
|
||||
*
|
||||
* Class Offlineprizetimer
|
||||
* @package app\index\controller
|
||||
*/
|
||||
class Offlineprizetimer
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:定时计算任务,每小时执行一次
|
||||
* author:wh
|
||||
*/
|
||||
function count()
|
||||
{
|
||||
$this->countOfflinePrize();
|
||||
$this->recoveryPower();
|
||||
$this->recoveryPowerTimes();
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:计算离线奖励并写入离线奖励表
|
||||
*
|
||||
* 每1小时执行一次
|
||||
*
|
||||
* index/Offlineprizetimer/count
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
private function countOfflinePrize(){
|
||||
|
||||
Tools::log_to_write_txt(['开始计算离线奖励']);
|
||||
return Mmodel::catchJson(function (){
|
||||
//一定时间内可领取的离线奖励次数
|
||||
$time_inner_get_prize_times = SundryConfig::val('time_inner_get_prize_times');
|
||||
$exp_arr = explode('-',$time_inner_get_prize_times);
|
||||
$max_hours = $exp_arr[0];
|
||||
$limit_time = time()-$max_hours * 3600;//n小时以内的离线用户
|
||||
|
||||
//$can_get_times = $exp_arr[1];//可领取次数
|
||||
|
||||
//所有离线时间大于 $max_hours 的用户
|
||||
$all_users = Db::table(TabConf::$fa_users)
|
||||
->where('offline_time','egt',date('Y-m-d H:i:s',$limit_time))//规定离线时间内
|
||||
->where('clientid','')//已离线
|
||||
->select();
|
||||
//每离线N小时可获得奖励
|
||||
$offline_n_hour_gift_can_prize = SundryConfig::val('offline_n_hour_gift_can_prize');
|
||||
//计算奖励
|
||||
foreach ($all_users as &$user){
|
||||
if(empty($user['offline_time'])){
|
||||
//刚注册,未离线
|
||||
continue;
|
||||
}
|
||||
if($user['clientid']){
|
||||
//在线
|
||||
continue;
|
||||
}
|
||||
/** 下方是已离线用户↓ **/
|
||||
|
||||
//查询最近计算奖励的时间
|
||||
$last_prize_time = Db::table(TabConf::$fa_user_offline_prize)
|
||||
->where('openid',$user['openid'])
|
||||
->order('id desc')
|
||||
->find();
|
||||
$offline_time = '';
|
||||
if($last_prize_time){
|
||||
//如果最近领取了奖励则以最近领取时间为准
|
||||
$offline_time = $last_prize_time['create_time'];
|
||||
}else{
|
||||
//取离线时间
|
||||
$offline_time = $user['offline_time'];
|
||||
}
|
||||
//离线时间超过3小时才能计算奖励
|
||||
if(time() - strtotime($offline_time) < 3*3600 ){
|
||||
//上次计算奖励的时间到现在还没到3小时
|
||||
continue;
|
||||
}
|
||||
|
||||
if(time()-$max_hours*3600 < strtotime($offline_time)){//在72小时以内
|
||||
//减去领奖时间
|
||||
$offline_time_hours = (time() - strtotime($offline_time)) / 3600;//得到小时数
|
||||
$prize_num = floor($offline_time_hours / $offline_n_hour_gift_can_prize);//得到本次可领取的奖品数量
|
||||
}else{//在72小时以外按72小时计算
|
||||
$prize_num = floor($max_hours / $offline_n_hour_gift_can_prize);//得到本次可领取的奖品数量
|
||||
}
|
||||
if($prize_num<=0){
|
||||
//离线时间不足,不计算奖励
|
||||
continue;
|
||||
}
|
||||
|
||||
//离线奖励获得数值
|
||||
$offline_prize_got_num_value = SundryConfig::val('offline_prize_got_num_value');
|
||||
//随机一个奖品
|
||||
$prop_id = $this->random_prop('id');
|
||||
//离线奖励可被偷取的百分比
|
||||
$lose_percent = SundryConfig::val('offline_prize_can_lose_percent');
|
||||
|
||||
$prize_all_num = $prize_num * $offline_prize_got_num_value;
|
||||
$can_lose_num = floor($prize_all_num * $lose_percent);
|
||||
$self_got_num = $prize_all_num - $can_lose_num;
|
||||
//计算奖品数值
|
||||
$gameprop_arr = [
|
||||
'openid'=>$user['openid'],
|
||||
//奖品
|
||||
'gameprop_id'=>$prop_id,
|
||||
//奖品总数量
|
||||
'prize_all_num'=>$prize_all_num,
|
||||
//可被偷取的数量
|
||||
'can_lose_num'=>$can_lose_num,//被偷取时,该值减少
|
||||
//自己保底所得数量
|
||||
'self_got_num'=>$self_got_num?:0,
|
||||
];
|
||||
|
||||
Db::table(TabConf::$fa_user_offline_prize)
|
||||
->insert($gameprop_arr);
|
||||
}
|
||||
Tools::log_to_write_txt(['结束计算离线奖励']);
|
||||
return Tools::set_ok('ok');
|
||||
});
|
||||
}
|
||||
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:每小时恢复一点体力,上限5点
|
||||
* author:wh
|
||||
*/
|
||||
private function recoveryPower(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$users = Db::table(TabConf::$fa_users)
|
||||
->where('power','<',5)
|
||||
->select();
|
||||
foreach ($users as $user){
|
||||
try {
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('id',$user['id'])
|
||||
->setInc('power',1);
|
||||
}catch (\Exception $e){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 每日凌晨恢复看广告增加体力次数和消耗金币增加体力次数
|
||||
*/
|
||||
private function recoveryPowerTimes(){
|
||||
return Mmodel::catchJson(function (){
|
||||
//判断当前时间是否是零点
|
||||
$now_time = date('H');
|
||||
if($now_time !== '00'){
|
||||
return '';
|
||||
}
|
||||
|
||||
$per_day_coin_add_power_times = SundryConfig::val('per_day_coin_add_power_times');
|
||||
$per_day_look_ad_add_power_times = SundryConfig::val('per_day_look_ad_add_power_times');
|
||||
$users = Db::table(TabConf::$fa_users)->select();
|
||||
foreach ($users as $user){
|
||||
try {
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('id',$user['id'])
|
||||
->data([
|
||||
'coin_power_times'=>$per_day_coin_add_power_times,
|
||||
'ad_power_times'=>$per_day_look_ad_add_power_times,
|
||||
]);
|
||||
}catch (\Exception $e){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -30,25 +30,25 @@ if (!function_exists('auto_choose_db_conf')) {
|
||||
'sdsdsd.playone.cn'
|
||||
])){
|
||||
$hostname = 'localhost';
|
||||
$database = 'cup_defense';
|
||||
$username = 'cup_defense';
|
||||
$password = 'cup_defense';
|
||||
$database = 'ss';
|
||||
$username = 'sss';
|
||||
$password = 'sss';
|
||||
$hostport = '3306';
|
||||
}
|
||||
|
||||
//测试 socket请求这里$domain=null,【上线正式环境之后把null移动到正式环境配置】
|
||||
else if(in_array($domain, [null,'cupdefense.playone.cn','testzckj.zcc10.com'])) {
|
||||
else if(in_array($domain, [null,'ssss.playone.cn','ssss.zcc10.com'])) {
|
||||
$hostname = 'localhost';
|
||||
$database = 'cup_defense';
|
||||
$username = 'cup_defense';
|
||||
$password = 'z8PMXE3PGsy7WiFP';
|
||||
$database = 'sss';
|
||||
$username = 'sss';
|
||||
$password = 'sss';
|
||||
$hostport = '3306';
|
||||
}
|
||||
|
||||
//本地
|
||||
else{
|
||||
$hostname = '127.0.0.1';
|
||||
$database = 'cup_defense';
|
||||
$database = 'digital_doctor';
|
||||
$username = 'root';
|
||||
$password = 'root';//root or 123456
|
||||
$hostport = '3306';
|
||||
|
||||
Reference in New Issue
Block a user