- Contract.php: 返回合约账户余额(balance_contract) - My.php: 地址管理增加BTC/ETH - AppContract.php: 一键平仓(closeall) - AppProxy.php: 代理专属注册链接 + 分级权限(L1/L2) - site.php: 手续费减半(0.018→0.009) - agent_permission_setup.sql: 代理权限SQL - crypto_news_crawler.py: 新闻自动采集脚本
289 lines
11 KiB
PHP
Executable File
289 lines
11 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\controller\Api;
|
|
use think\Db;
|
|
use think\Config;
|
|
|
|
/**
|
|
* 天使投资
|
|
*/
|
|
class Angel extends Api
|
|
{
|
|
// 无需登录的接口,*表示全部
|
|
protected $noNeedLogin = ['*'];
|
|
// 无需鉴权的接口,*表示全部
|
|
protected $noNeedRight = ['*'];
|
|
|
|
/**
|
|
* 天使内容返回
|
|
*/
|
|
public function angel_content()
|
|
{
|
|
$array = array(
|
|
1 => __("第一阶段"),
|
|
2 => __("第二阶段"),
|
|
3 => __("第三阶段"),
|
|
4 => __("第四阶段"),
|
|
5 => __("第五阶段"),
|
|
);
|
|
$ico = Db::name("app_angel_set")->field("id,content,level,curr_id,price,all_num,count_num,real_num,status")->order("id desc")->find();
|
|
$curr = Db::name("app_currency")->where("id",$ico['curr_id'])->find();
|
|
$ico['curr_name'] = $curr['name'];
|
|
$ico['content'] = str_replace("src=\"","src=\"".Config::get("site.image_url"), $ico['content']);
|
|
|
|
$ico['content_txt'] = strip_tags($ico['content']);
|
|
$ico['content_txt'] = str_replace( ' ' , '' , $ico['content_txt'] );
|
|
$ico['price'] = rtrim(rtrim($ico['price'], '0'), '.');
|
|
$ico['jieduan'] = $array[$ico['level']];
|
|
$this->success('success',$ico);
|
|
}
|
|
|
|
|
|
/**
|
|
* 投资提交
|
|
*/
|
|
public function angel_sub()
|
|
{
|
|
$user_id = $this->auth->id;
|
|
$id = $this->request->post("id");
|
|
$num_usdt = (int)$this->request->post("num");
|
|
$pay_pwd = $this->request->post("pay_pwd");
|
|
$ico = Db::name("app_angel_set")->where("id",$id)->find();
|
|
|
|
//判断交易密码
|
|
if(strtoupper(md5(strtoupper(md5($pay_pwd.'skund')))) != $this->auth->pay_pwd)
|
|
{
|
|
$this->error(__('交易密码错误'));
|
|
}
|
|
|
|
if(empty($ico)){
|
|
$this->error(__("error"));
|
|
}
|
|
if($ico['status'] != 1){
|
|
$this->error(__("error"));
|
|
}
|
|
if(!is_numeric($num_usdt) || $num_usdt < 1){
|
|
$this->error(__("请输入有效数量"));
|
|
}
|
|
$num = sprintf("%.6f",$num_usdt/$ico['price']);
|
|
if($ico['real_num'] < $num){
|
|
$this->error(__("剩余数量不足"));////
|
|
}
|
|
|
|
$ico_usdt = $num_usdt;
|
|
$user_usdt = Db::name("app_currency_user")->where("curr_id",1)->where("user_id",$user_id)->find();
|
|
if($user_usdt['num'] < $ico_usdt){
|
|
$this->error(__("余额不足"));
|
|
}
|
|
|
|
if($ico['min_invest'] > $ico_usdt){
|
|
$this->error(__("最低投资:").$ico['min_invest']."USDT");////
|
|
}
|
|
//判断是否超过本轮投资上线
|
|
$cout_tz = Db::name("app_angel_user")->where("angel_id",$id)->where("user_id",$user_id)->sum("usdt");
|
|
if($ico['max_invest'] < $ico_usdt+$cout_tz){
|
|
$this->error(__("本轮投资上限").$ico['max_invest']."USDT");////
|
|
}
|
|
//redis防重复点击
|
|
$symbol = "angel_sub" . $this->auth->id;
|
|
$submited = pushRedis($symbol);
|
|
if (!$submited) {
|
|
$this->error(__("操作频繁"));
|
|
}
|
|
|
|
$ico_data = array(
|
|
"user_id" => $user_id,
|
|
"angel_id" => $id,
|
|
"num" => $num,
|
|
"real_num" => $num,
|
|
"usdt" => $ico_usdt,
|
|
"price" => $ico['price'],
|
|
"days" => 0,
|
|
"addtime" => time(),
|
|
"lasttime" => time(),
|
|
);
|
|
//资金明细
|
|
$detail_data[] = array(
|
|
"user_id" => $user_id,
|
|
"curr_id" => 1,
|
|
"price" => $ico_usdt,
|
|
"cart" => 2,
|
|
"type" => 11,
|
|
"description" => "天使投资",
|
|
"createtime" => time(),
|
|
"before_num" => $user_usdt['num'],
|
|
"after_num" => $user_usdt['num'] - $ico_usdt,
|
|
);
|
|
$parent_angel = Db::name("app_angel_user")->where("user_id", $this->auth->pid)->find();
|
|
Db::startTrans();
|
|
try {
|
|
Db::name("app_currency_user")->where("id",$user_usdt['id'])->update(['num'=>$user_usdt['num'] - $ico_usdt]);
|
|
Db::name("app_angel_set")->where("id",$id)->setDec("real_num",$num);
|
|
//直推奖
|
|
if($parent_angel){
|
|
$parent_curr = Db::name("app_currency_user")->where("user_id", $this->auth->pid)->where("curr_id",$ico['curr_id'])->find();
|
|
$push_num = $num*$ico['push_award']/100;
|
|
$detail_data[] = array(
|
|
"user_id" => $parent_curr['user_id'],
|
|
"curr_id" => $ico['curr_id'],
|
|
"price" => $push_num,
|
|
"cart" => 1,
|
|
"type" => 12,
|
|
"description" => "天使直推",
|
|
"createtime" => time(),
|
|
"before_num" => $parent_curr['num'],
|
|
"after_num" => $parent_curr['num'] + $push_num,
|
|
);
|
|
Db::name("app_currency_user")->where("id",$parent_curr['id'])->update(['num'=>$parent_curr['num'] + $push_num]);
|
|
//下级投资 5000USDT ~解冻20000APT 10000USDT~解冻20000APT 15000USDT~解冻20000APT 25000USDT~解冻20000APT 30000USDT~解冻20000APT
|
|
if($parent_curr['num_dj'] > 0){
|
|
$son_arr = Db::name("user")->field("id")->where("pid",$this->auth->pid)->select();
|
|
$son = [];
|
|
foreach ($son_arr as $key => $value) {
|
|
$son[] = $value['id'];
|
|
}
|
|
$son_ids = implode(",", $son);
|
|
$son_angel = Db::name("app_angel_user")->where("user_id","in",$son_ids)->sum("usdt");
|
|
$sf_num = $this->get_shifang($son_angel+$ico_usdt)-$this->get_shifang($son_angel);
|
|
if($sf_num > 0){
|
|
$sf_num = $sf_num>$parent_curr['num_dj']?$parent_curr['num_dj']:$sf_num;
|
|
$detail_data[] = array(
|
|
"user_id" => $parent_curr['user_id'],
|
|
"curr_id" => $ico['curr_id'],
|
|
"price" => $sf_num,
|
|
"cart" => 1,
|
|
"type" => 5,
|
|
"description" => "冻结释放",
|
|
"createtime" => time(),
|
|
"before_num" => $parent_curr['num'] + $push_num,
|
|
"after_num" => $parent_curr['num'] + $push_num + $sf_num,
|
|
);
|
|
Db::name("app_currency_user")->where("id",$parent_curr['id'])->update(['num'=>$parent_curr['num'] + $push_num + $sf_num,'num_dj'=>$parent_curr['num_dj']-$sf_num]);
|
|
}
|
|
}
|
|
}else{
|
|
$parent_curr = Db::name("app_currency_user")->where("user_id", $this->auth->pid)->where("curr_id",$ico['curr_id'])->find();
|
|
if($parent_curr['num_dj'] > 0){
|
|
$son_arr = Db::name("user")->field("id")->where("pid",$this->auth->pid)->select();
|
|
$son = [];
|
|
foreach ($son_arr as $key => $value) {
|
|
$son[] = $value['id'];
|
|
}
|
|
$son_ids = implode(",", $son);
|
|
$son_angel = Db::name("app_angel_user")->where("user_id","in",$son_ids)->sum("usdt");
|
|
$sf_num = $this->get_shifang($son_angel+$ico_usdt)-$this->get_shifang($son_angel);
|
|
if($sf_num > 0){
|
|
$sf_num = $sf_num>$parent_curr['num_dj']?$parent_curr['num_dj']:$sf_num;
|
|
$detail_data[] = array(
|
|
"user_id" => $parent_curr['user_id'],
|
|
"curr_id" => $ico['curr_id'],
|
|
"price" => $sf_num,
|
|
"cart" => 1,
|
|
"type" => 5,
|
|
"description" => "冻结释放",
|
|
"createtime" => time(),
|
|
"before_num" => $parent_curr['num'],
|
|
"after_num" => $parent_curr['num'] + $sf_num,
|
|
);
|
|
Db::name("app_currency_user")->where("id",$parent_curr['id'])->update(['num'=>$parent_curr['num'] + $sf_num,'num_dj'=>$parent_curr['num_dj']-$sf_num]);
|
|
}
|
|
}
|
|
}
|
|
Db::name("app_angel_user")->insert($ico_data);
|
|
Db::name("app_detailed")->insertAll($detail_data);
|
|
lopRedis($symbol);
|
|
Db::commit();
|
|
$this->success(__('Successfull'));
|
|
} catch (Exception $e) {
|
|
Db::rollback();
|
|
lopRedis($symbol);
|
|
$this->error(__('参与失败'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取对应解冻金额
|
|
* @param type $num 投资USDT
|
|
*/
|
|
public function get_shifang($num){
|
|
if($num<5000){
|
|
$sf_num = 0;
|
|
}elseif($num>=5000 && $num<10000){
|
|
$sf_num = 20000;
|
|
}elseif($num>=10000 && $num<15000){
|
|
$sf_num = 40000;
|
|
}elseif($num>=15000 && $num<25000){
|
|
$sf_num = 60000;
|
|
}elseif($num>=25000 && $num<30000){
|
|
$sf_num = 80000;
|
|
}elseif($num>=30000){
|
|
$sf_num = 100000;
|
|
}
|
|
return $sf_num;
|
|
}
|
|
|
|
/**
|
|
* 投资记录
|
|
*/
|
|
public function angel_user()
|
|
{
|
|
$user_id = $this->auth->id;
|
|
|
|
$list = Db::name("app_angel_user")->field("id,num,real_num,price,count_lixi,addtime")->where("user_id",$user_id)->order("id desc")->select();
|
|
$count_num = 0;
|
|
$count_sy = 0;
|
|
foreach ($list as $key => $value) {
|
|
$value['price'] = rtrim(rtrim($value['price'], '0'), '.');
|
|
$count_num = $count_num+$value['num'];
|
|
$count_sy = $count_sy+$value['count_lixi']+($value['num']-$value['real_num']);
|
|
$value['addtime'] = date("H:i m/d",$value['addtime']);
|
|
$list[$key] = $value;
|
|
}
|
|
$data = array(
|
|
"count_num" => $count_num,
|
|
"count_sy" => sprintf("%.6f",$count_sy),
|
|
"list" => $list,
|
|
);
|
|
$this->success("ok",$data);
|
|
}
|
|
|
|
/**
|
|
* 释放记录 头部
|
|
*/
|
|
public function angel_detail_head()
|
|
{
|
|
$user_id = $this->auth->id;
|
|
$id = $this->request->post("id");
|
|
|
|
$res = Db::name("app_angel_user")->field("id,angel_id,num,real_num,count_lixi,addtime,days")->where("id",$id)->where("user_id",$user_id)->find();
|
|
$angel = Db::name("app_angel_set")->where("id",$res['angel_id'])->find();
|
|
if(empty($res)){
|
|
$this->error("记录不存在");
|
|
}
|
|
$res['count_all'] = $res['count_lixi']+($res['num']-$res['real_num']);
|
|
$res['count_bj'] = $res['num']-$res['real_num'];
|
|
$res['day'] = $angel['freed_day']-$res['days'];
|
|
$this->success("ok",$res);
|
|
}
|
|
|
|
/**
|
|
* 释放记录
|
|
*/
|
|
public function angel_detail_log()
|
|
{
|
|
$id = $this->request->post("id");
|
|
$data = Db::name('app_angel_detail a')->field('a.num,a.type,a.addtime')
|
|
->where('a.pro_id',$id)
|
|
->order('a.id','desc')
|
|
->paginate(20,false,['query' => request()->param()]);
|
|
foreach ($data as $key => $value) {
|
|
$value['addtime'] = date("Y-m-d H:i",$value['addtime']);
|
|
$data[$key] = $value;
|
|
}
|
|
$this->success("ok",$data);
|
|
}
|
|
|
|
}
|