- 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: 新闻自动采集脚本
284 lines
12 KiB
PHP
Executable File
284 lines
12 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\admin\controller\app;
|
|
|
|
use app\common\controller\Backend;
|
|
use think\Db;
|
|
use think\Config;
|
|
|
|
/**
|
|
* 私募记录
|
|
*
|
|
* @icon fa fa-circle-o
|
|
*/
|
|
class AppIcoUser extends Backend
|
|
{
|
|
|
|
/**
|
|
* AppIcoUser模型对象
|
|
* @var \app\admin\model\app\AppIcoUser
|
|
*/
|
|
protected $model = null;
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->model = new \app\admin\model\app\AppIcoUser;
|
|
|
|
}
|
|
|
|
public function import()
|
|
{
|
|
parent::import();
|
|
}
|
|
|
|
/**
|
|
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
|
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
|
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
|
*/
|
|
|
|
/**
|
|
* 查看
|
|
*/
|
|
public function index()
|
|
{
|
|
//设置过滤方法
|
|
$this->request->filter(['strip_tags']);
|
|
if ($this->request->isAjax())
|
|
{
|
|
//如果发送的来源是Selectpage,则转发到Selectpage
|
|
if ($this->request->request('keyField'))
|
|
{
|
|
return $this->selectpage();
|
|
}
|
|
// list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
$offset = $this->request->get("offset", 0);
|
|
$limit = $this->request->get("limit", 0);
|
|
$params = json_decode(input('filter'),true);
|
|
$op = json_decode(input('op'),true);
|
|
if(count($params) > 0){
|
|
$new_params = $new_op = [];
|
|
foreach ($params as $key => $value) {
|
|
if($key == 'mobile')
|
|
{
|
|
$new_params['u.' . $key] = $value;
|
|
$new_op['u.' . $key] = $op[$key];
|
|
}else if($key == 'nickname'){
|
|
$new_params['u.nickname'] = $value;
|
|
$new_op['u.nickname'] = $op[$key];
|
|
}else if($key == 'ico_name'){
|
|
$new_params['b.name'] = $value;
|
|
$new_op['b.name'] = $op[$key];
|
|
}elseif ($key == 'daili_name') {
|
|
$new_params['e.nickname'] = $value;
|
|
$new_op['e.nickname'] = $op[$key];
|
|
}else {
|
|
$new_params['a.' . $key] = $value;
|
|
$new_op['a.' . $key] = $op[$key];
|
|
}
|
|
}
|
|
$w = $this->rewriteQuery($new_params, $new_op);
|
|
}else{
|
|
$w['a.id'] = array('>', 0);
|
|
}
|
|
$admin_id = $this->auth->id;
|
|
if($admin_id > 1){
|
|
$user = Db::name("user")->where("admin_id",$admin_id)->find();
|
|
if($user){
|
|
$w['u.path'] = array("like",$user['path']."%");
|
|
}
|
|
}
|
|
$total = Db::name('app_ico_user')
|
|
->alias('a')
|
|
->field('a.*,u.nickname,b.name as ico_name,e.nickname as daili_name')
|
|
->join('fa_user u', 'a.user_id = u.id')
|
|
->join('fa_app_ico_set b', 'a.ico_id = b.id')
|
|
->join('admin e', 'u.p_admin_id = e.id' , 'left')
|
|
->where($w)
|
|
->count();
|
|
$list = Db::name('app_ico_user')
|
|
->alias('a')
|
|
->field('a.*,u.nickname,b.name as ico_name,e.nickname as daili_name')
|
|
->join('fa_user u', 'a.user_id = u.id')
|
|
->join('fa_app_ico_set b', 'a.ico_id = b.id')
|
|
->join('admin e', 'u.p_admin_id = e.id' , 'left')
|
|
->where($w)
|
|
->order('a.id', 'desc')
|
|
->limit($offset, $limit)
|
|
->select();
|
|
$result = array("total" => $total, "rows" => $list);
|
|
|
|
return json($result);
|
|
}
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
/**
|
|
* 编辑
|
|
*/
|
|
public function edit($ids = null)
|
|
{
|
|
$row = $this->model->get($ids);
|
|
if (!$row) {
|
|
$this->error(__('No Results were found'));
|
|
}
|
|
$adminIds = $this->getDataLimitAdminIds();
|
|
if (is_array($adminIds)) {
|
|
if (!in_array($row[$this->dataLimitField], $adminIds)) {
|
|
$this->error(__('You have no permission'));
|
|
}
|
|
}
|
|
if ($this->request->isPost()) {
|
|
$params = $this->request->post("row/a");
|
|
if ($params) {
|
|
$params = $this->preExcludeFields($params);
|
|
$result = false;
|
|
Db::startTrans();
|
|
try {
|
|
if($row['status'] != '0')
|
|
{
|
|
$this->error('编辑非法,已审核记录不可重复审核');
|
|
}else{
|
|
if($params['status'] == '1') { //审核通过
|
|
$user_usdt = Db::name('app_currency_user')
|
|
->where('user_id',$params['user_id'])
|
|
->where('curr_id','1')
|
|
->find();
|
|
$ico_user = Db::name("app_ico_user a")->field("b.price as ico_price,b.curr_id")
|
|
->join("app_ico_set b","a.ico_id=b.id","left")
|
|
->where('a.id',$row['id'])
|
|
->find();
|
|
$user_curr = Db::name('app_currency_user')
|
|
->where('user_id',$params['user_id'])
|
|
->where('curr_id',$ico_user['curr_id'])
|
|
->find();
|
|
$price = $params['num']*$params['bili']/100;
|
|
$detail_data[] = array(
|
|
"user_id" => $user_curr['user_id'],
|
|
"curr_id" => $user_curr['curr_id'],
|
|
"price" => $price,
|
|
"cart" => 1,
|
|
"type" => 5,
|
|
"description" => "ICO",
|
|
"createtime" => time(),
|
|
"before_num" => $user_curr['num'],
|
|
"after_num" => $user_curr['num'] + $price,
|
|
);
|
|
Db::name("app_currency_user")->where("id",$user_curr['id'])->setInc("num",$price);
|
|
$usdt_num = sprintf("%.4f",(100-$params['bili'])*$params['num']*$ico_user['ico_price']/100);
|
|
if($usdt_num > 0){
|
|
$detail_data[] = array(
|
|
"user_id" => $user_usdt['user_id'],
|
|
"curr_id" => $user_usdt['curr_id'],
|
|
"price" => $usdt_num,
|
|
"cart" => 1,
|
|
"type" => 5,
|
|
"description" => "ICO",
|
|
"createtime" => time(),
|
|
"before_num" => $user_usdt['num'],
|
|
"after_num" => $user_usdt['num'] + $usdt_num,
|
|
);
|
|
Db::name("app_currency_user")->where("id",$user_usdt['id'])->setInc("num",$usdt_num);
|
|
}
|
|
Db::name("app_detailed")->insertAll($detail_data);
|
|
Db::name("app_ico_set")->where("id",$ico_user['ico_id'])->setDec("real_num",$price);
|
|
$result = Db::name('app_ico_user')->where('id',$row['id'])->update($params);
|
|
}else{ //审核失败
|
|
$result = Db::name('app_ico_user')->where('id',$row['id'])->update($params);
|
|
}
|
|
}
|
|
Db::commit();
|
|
} catch (ValidateException $e) {
|
|
Db::rollback();
|
|
$this->error($e->getMessage());
|
|
} catch (PDOException $e) {
|
|
Db::rollback();
|
|
$this->error($e->getMessage());
|
|
} catch (Exception $e) {
|
|
Db::rollback();
|
|
$this->error($e->getMessage());
|
|
}
|
|
if ($result !== false) {
|
|
$this->success();
|
|
} else {
|
|
$this->error(__('No rows were updated'));
|
|
}
|
|
}
|
|
$this->error(__('Parameter %s can not be empty', ''));
|
|
}
|
|
$this->view->assign("row", $row);
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
/**
|
|
* 启用
|
|
*/
|
|
public function start($ids = '')
|
|
{
|
|
$default_bili = Config::get("site.default_bili");
|
|
if($ids){
|
|
$w['a.id'] = array("in",$ids);
|
|
}
|
|
$w['a.status'] = array("eq",0);
|
|
$w['c.curr_id'] = array("eq",1);
|
|
$list = Db::name("app_ico_user a")->field("a.*,c.num as curr_num,c.id as cid,b.curr_id,b.price as ico_price")
|
|
->join("app_ico_set b","a.ico_id=b.id","left")
|
|
->join("app_currency_user c","a.user_id=c.user_id","left")
|
|
->where($w)
|
|
->select();
|
|
if(empty($list)){
|
|
$this->error("暂无可发放记录");
|
|
}
|
|
Db::startTrans();
|
|
try {
|
|
foreach ($list as $key => $value) {
|
|
if($value['bili'] > 0){
|
|
$bili = $value['bili'];
|
|
}else{
|
|
$bili = $default_bili;
|
|
}
|
|
$user_curr = Db::name("app_currency_user")->where("user_id",$value['user_id'])->where("curr_id",$value['curr_id'])->find();
|
|
$price = $value['num']*$bili/100;
|
|
$detail_data[] = array(
|
|
"user_id" => $value['user_id'],
|
|
"curr_id" => $user_curr['curr_id'],
|
|
"price" => $price,
|
|
"cart" => 1,
|
|
"type" => 5,
|
|
"description" => "ICO",
|
|
"createtime" => time(),
|
|
"before_num" => $user_curr['num'],
|
|
"after_num" => $user_curr['num'] + $price,
|
|
);
|
|
Db::name("app_currency_user")->where("id",$user_curr['id'])->setInc("num",$price);
|
|
$usdt_num = sprintf("%.4f",(100-$bili)*$value['num']*$value['ico_price']/100);
|
|
if($usdt_num > 0){
|
|
$detail_data[] = array(
|
|
"user_id" => $value['user_id'],
|
|
"curr_id" => 1,
|
|
"price" => $usdt_num,
|
|
"cart" => 1,
|
|
"type" => 5,
|
|
"description" => "ICO",
|
|
"createtime" => time(),
|
|
"before_num" => $value['curr_num'],
|
|
"after_num" => $value['curr_num'] + $usdt_num,
|
|
);
|
|
Db::name("app_currency_user")->where("id",$value['cid'])->setInc("num",$usdt_num);
|
|
}
|
|
Db::name("app_ico_user")->where("id",$value['id'])->update(['bili'=>$bili,'status'=>1]);
|
|
Db::name("app_ico_set")->where("id",$value['ico_id'])->setDec("real_num",$price);
|
|
}
|
|
Db::name("app_detailed")->insertAll($detail_data);
|
|
Db::commit();
|
|
$this->success(__('发放成功'));
|
|
} catch (Exception $e) {
|
|
Db::rollback();
|
|
$this->error(__('系统繁忙'));
|
|
}
|
|
}
|
|
|
|
|
|
}
|