feat: 项目基础框架+配置+Kernel
This commit is contained in:
@@ -0,0 +1,408 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: swl
|
||||
* Date: 2018/7/3
|
||||
* Time: 10:23
|
||||
*/
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\Users;
|
||||
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AccountLog extends Model
|
||||
{
|
||||
protected $table = 'account_log';
|
||||
public $timestamps = false;
|
||||
const CREATED_AT = 'created_time';
|
||||
protected $appends = [
|
||||
'account_number',
|
||||
'account',
|
||||
'currency_name',//币种
|
||||
'before',//交易前
|
||||
'after',//交易后
|
||||
'transaction_info',//交易信息
|
||||
'balance_type',
|
||||
// 'type_info',
|
||||
// 'type_info_m',
|
||||
// 'type_info_e',
|
||||
// 'type_info_j'
|
||||
];
|
||||
|
||||
|
||||
const ADMIN_LEGAL_BALANCE = 1;//后台调节资金账户余额
|
||||
const ADMIN_LOCK_LEGAL_BALANCE = 2;//后台调节资金账户锁定余额
|
||||
const ADMIN_CHANGE_BALANCE = 3;//后台调节币币账户余额
|
||||
const ADMIN_LOCK_CHANGE_BALANCE = 4;//后台调节币币账户锁定余额
|
||||
const ADMIN_LEVER_BALANCE = 5;//后台调节合约账户余额
|
||||
const ADMIN_LOCK_LEVER_BALANCE = 6;//后台调节合约账户锁定余额
|
||||
const ADMIN_MICRO_BALANCE = 7; //后台调节期权账户余额
|
||||
const ADMIN_LOCK_MICRO_BALANCE = 8; //后台调节期权账户锁定余额
|
||||
|
||||
const WALLET_CURRENCY_OUT = 7;//提币记录
|
||||
const WALLET_CURRENCY_IN = 8;//充币记录
|
||||
|
||||
const WALLET_LEGAL_OUT = 9;
|
||||
const WALLET_LEGAL_IN = 10;
|
||||
const WALLET_CHANGE_IN = 11;//资金划入记录
|
||||
const WALLET_CHANGE_OUT = 12;//资金划出记录
|
||||
const WALLET_CHANGE_LEVEL_OUT = 13;//资金划出记录
|
||||
const WALLET_CHANGE_LEVEL_IN = 14;//资金划出记录
|
||||
const WALLET_LEVER_IN = 15;
|
||||
const WALLET_LEVER_OUT = 16;
|
||||
const WALLET_MCIRO_IN = 15;
|
||||
const WALLET_MCIRO_OUT = 16;
|
||||
|
||||
|
||||
const INVITATION_TO_RETURN = 33;//邀请返佣
|
||||
|
||||
const LEGAL_DEAL_SEND_SELL = 60;//商家发布资金出售
|
||||
const LEGAL_DEAL_USER_SELL = 61;//出售给商家资金
|
||||
const LEGAL_USER_BUY = 62;//用户购买商家资金成功
|
||||
const LEGAL_SELLER_BUY = 63;//商家购买用户资金成功
|
||||
const LEGAL_DEAL_USER_SELL_CANCEL = 64;//出售给商家资金-取消
|
||||
const INTO_TRA_FB = 65;//美丽链资金转入(imc)
|
||||
const INTO_TRA_BB = 66;//美丽链币币转入(imc)
|
||||
const INTO_TRA_GG = 67;//美丽链合约转入(imc)
|
||||
const ADMIN_SELLER_BALANCE = 70;//后台调节商家余额
|
||||
const LEGAL_DEAL_BACK_SEND_SELL = 71;//商家撤回发布资金出售
|
||||
const LEGAL_DEAL_ERROR_SEND_SELL = 72;//商家撤回发布资金出售
|
||||
const LEGAL_DEAL_AUTO_CANCEL = 68;//自动取消资金交易
|
||||
|
||||
/* const BUY_BLOCK_CHAIN = 1;//购买区块链
|
||||
const ADJUDT_SUB_BALANCE = 2;//后台调节账户余额
|
||||
const TRANSFER_IN = 3;//转入
|
||||
const TRANSFER_OUT = 4;//转出
|
||||
const ETH_EXCHANGE = 5;//以太币兑换
|
||||
|
||||
const USER_BONUS = 6;//日均收益
|
||||
const ECOLOGY_BONUS = 7;//更新生态推广奖励
|
||||
const AGENT_REWARD = 8;//代理商管理奖励
|
||||
|
||||
const ADMIN_LOCK_BALANCE = 9; //后台调节锁定余额
|
||||
const ADMIN_REMAIN_LOCK_BALANCE = 10; //后台调节锁定余额相应剩余锁定余额
|
||||
|
||||
const LOCK_BALANCE = 11; //锁仓增加
|
||||
const LOCK_REMAIN_BALANCE = 12; //锁仓减少
|
||||
const ACCEPTOR_SELL = 13; //用户提现承兑申请
|
||||
const ACCEPTOR_RECHARGE = 14; //用户充值承兑确认
|
||||
const ACCEPTOR_RECHARGE_VAR = 15; //用户充值承兑手续费
|
||||
const ACCEPTOR_RECHARGE_DEC = 16; //确认用户充值,承兑商充值额度减少
|
||||
const ACCEPTOR_CASH_INC = 17; //确认用户充值,承兑商提现额度增加
|
||||
const ACCEPTOR_CASH_DEC = 18; //确认用户提现,承兑商提现额度减少
|
||||
const ACCEPTOR_RECHARGE_INC = 19; //确认用户提现,承兑商充值额度增加
|
||||
const ACCEPTOR_SELL_RETURN = 20; //取消用户提现承兑申请
|
||||
const ACCEPTOR_CASH_RETURN = 91; //取消用户提现承兑,承兑商提现额度增加
|
||||
|
||||
*/
|
||||
const TRANSACTIONOUT_SUBMIT_REDUCE = 21; //提交卖出,扣除
|
||||
|
||||
const TRANSACTIONIN_REDUCE = 22; //买入扣除
|
||||
const TRANSACTIONIN_SELLER = 23; //扣除卖方
|
||||
const TRANSACTIONIN_SUBMIT_REDUCE = 24; //提交买入,扣除
|
||||
|
||||
const TRANSACTIONIN_REDUCE_ADD = 25; //买方增加币
|
||||
const TRANSACTIONIN_SELLER_ADD = 26; //卖方增加cny
|
||||
|
||||
const TRANSACTIONIN_REVOKE_ADD = 27; //撤销增加
|
||||
const TRANSACTIONOUT_REVOKE_ADD = 28; //撤销增加
|
||||
|
||||
const TRANSACTION_FEE = 29; //卖出手续费
|
||||
|
||||
const LEVER_TRANSACTION = 30; //合约交易扣除保证金
|
||||
const LEVER_TRANSACTION_ADD = 31; //平仓增加
|
||||
const LEVER_TRANSACTION_FROZEN = 32; //爆仓冻结
|
||||
const LEVER_TRANSACTION_OVERNIGHT = 34; //隔夜费
|
||||
const LEVER_TRANSACTION_FEE = 35; //交易手续费
|
||||
const LEVER_TRANSACTIO_CANCEL = 36; //合约交易取消
|
||||
const CANDY_LEVER_BALANCE = 37; //通证兑换合约币增加
|
||||
const TOBE_SELLER_SUB_USDT = 38; //申请成为商家扣除USDT
|
||||
const CURRENCY_TO_USDT_MUL = 39; //资产兑换 减少兑换币
|
||||
const CURRENCY_TO_USDT_ADD = 40; //资产兑换 增加USDT资金
|
||||
const JOIN_BOSS = 41;
|
||||
const TRANSFER_TO_LH_ACCOUNT = 42; //转账入余币宝
|
||||
const BOSS_WITHDRAW = 43;
|
||||
const BANK_WITHDRAW = 44;
|
||||
const LH_LOAN = 45;
|
||||
const COIN_TRADE_FROZEN = 50;
|
||||
const COIN_TRADE = 51;
|
||||
const WALLETOUT = 99; //用户申请提币
|
||||
const WALLETOUTDONE = 100; //用户提币成功
|
||||
const WALLETOUTBACK = 101; //用户提币失败
|
||||
const TRANSACTIONIN_IN_DEL = 102;//取消买入交易
|
||||
const TRANSACTIONIN_OUT_DEL = 103;//取消买出交易
|
||||
|
||||
const CHANGE_LEVER_BALANCE = 104;//合约交易账户变化
|
||||
|
||||
const REWARD_CANDY = 105; //奖励通证
|
||||
const REWARD_CURRENCY = 106; //奖励数字货币
|
||||
|
||||
const CANDY_TOUSDT_CANDY = 107; //通证兑换USDT
|
||||
const ADMIN_CANDY_BALANCE = 108; //后台调节通证
|
||||
|
||||
const SELLER_BACK_SEND = 299;//合约交易账户变化
|
||||
const CHANGEBALANCE = 401; //转账
|
||||
const LTC_IN = 301; //来自矿机的转账
|
||||
const LTC_SEND = 302; //转账余额至矿机
|
||||
|
||||
const ETH_EXCHANGE = 200; //充币增加余额
|
||||
const CHAIN_RECHARGE = 200;
|
||||
|
||||
//c2c交易
|
||||
const C2C_DEAL_SEND_SELL = 201;//用户发布资金出售
|
||||
const C2C_DEAL_AUTO_CANCEL = 202;//自动取消c2c资金交易
|
||||
const C2C_DEAL_USER_SELL = 203;//出售给用户资金
|
||||
const C2C_USER_BUY = 204;//用户购买资金成功
|
||||
const C2C_DEAL_BACK_SEND_SELL = 205;//商家撤回发布资金出售
|
||||
|
||||
const WALLET_LEGAL_LEVEL_OUT = 206;//资金(c2c)转入合约
|
||||
const WALLET_LEGAL_LEVEL_IN = 207;//资金(c2c)转入合约
|
||||
const WALLET_LEVEL_LEGAL_OUT = 208;//合约转入资金(c2c)
|
||||
const WALLET_LEVEL_LEGAL_IN = 209;//合约转入资金(c2c)
|
||||
const WALLET_DONGJIEGANGGAN = 210;
|
||||
const WALLET_JIEDONGGANGGAN = 211;//审核不通过解冻合约冻结
|
||||
|
||||
const PROFIT_LOSS_RELEASE = 212;//历史盈亏释放,增加合约币
|
||||
|
||||
const MICRO_TRADE_SUBMIT = 501; //期权下单
|
||||
const MICRO_TRADE_CLOSE_SETTLE = 502; //期权平仓结算
|
||||
|
||||
const DEBIT_BALANCE_MINUS = 600;//闪兑减少余额
|
||||
const DEBIT_BALANCE_ADD = 601;//闪兑通过,增加余额
|
||||
const DEBIT_BALANCE_MINUS_LOCK = 602;//闪兑减少锁定余额
|
||||
const DEBIT_BALANCE_ADD_LOCK = 603;//闪兑增加锁定余额
|
||||
const DEBIT_BALANCE_ADD_REJECT = 604;//闪兑驳回,增加余额
|
||||
|
||||
|
||||
// const WALLET_MICRO_LEVEL_OUT = 206;//期权(c2c)转入合约
|
||||
// const WALLET_MICRO_LEVEL_IN = 207;//期权(c2c)转入合约
|
||||
// const WALLET_LEVEL_MICRO_OUT = 208;//合约转入期权(c2c)
|
||||
// const WALLET_LEVEL_MICRO_IN = 209;//合约转入期权(c2c)
|
||||
|
||||
// const WALLET_LEGAL_MICRO_OUT = 206;//资金(c2c)转入期权
|
||||
// const WALLET_LEGAL_MICRO_IN = 207;//资金(c2c)转入期权
|
||||
// const WALLET_MICRO_LEGAL_OUT = 208;//期权转入资金(c2c)
|
||||
// const WALLET_MICRO_LEGAL_IN = 209;//期权转入资金(c2c)
|
||||
|
||||
// const WALLET_CNANGE_LEVEL_OUT = 206;//闪兑转入合约
|
||||
// const WALLET_CNANGE_LEVEL_IN = 207;//闪兑转入合约
|
||||
// const WALLET_LEVEL_CNANGE_OUT = 208;//合约转入闪兑
|
||||
// const WALLET_LEVEL_CNANGE_IN = 209;//合约转入闪兑
|
||||
|
||||
const WALLET_USDT_MINUS = 220; //usdt兑换bmb 减少usdt
|
||||
const WALLET_USDT_BMB_FEE = 221;//usdt兑换手续费
|
||||
const WALLET_BMB_ADD = 221;//usdt兑换BMB手续费
|
||||
|
||||
const USER_BUY_INSURANCE = 230;//用户购买保险
|
||||
const USER_CLAIM_COMPENSATION = 231;//赔偿用户
|
||||
const USER_CLAIM_CLEAR = 232;//赔偿用户,清除受保金额
|
||||
const INSURANCE_RESCISSION1 = 233;//保险解约,清除受保金额
|
||||
const INSURANCE_RESCISSION2 = 234;//保险解约,清除保险金额
|
||||
const INSURANCE_RESCISSION_ADD = 234;//保险解约,赔付用户
|
||||
|
||||
const RETURN_INSURANCE_TRADE_FEE = 235;//释放保险交易手续费
|
||||
|
||||
|
||||
const LOWER_REBATE = 250;//下级返利
|
||||
const INSURANCE_MONEY = 251;//持币生币
|
||||
const IEO_OPERATION = 700;
|
||||
|
||||
//新加部分log
|
||||
const USER_EXCHANGE_ADD = 701; //币币划转增加
|
||||
const USER_EXCHANGE_DOWN = 702;//币币划转减少
|
||||
const USER_EXCHANGE_FEE = 703;//币币划转手续费
|
||||
const MINING_BUY = 704; //锁仓挖矿
|
||||
const MINING_RETURN = 705; //挖矿收益
|
||||
const MICRO_SECONDS_TIPS = 706; //期权下单提示
|
||||
|
||||
//跟单
|
||||
const LEVER_TRANSACTION_DEDUCT_CAUTION = 707; //合约交易-扣除保证金
|
||||
const LEVER_TRANSACTION_TRADE_FEE = 708; //合约交易-扣除手续费
|
||||
|
||||
|
||||
//新加部分
|
||||
const USER_DUAL_ORDER_BUY = 1000;
|
||||
const USER_DUAL_ORDER_RETURN = 1001;
|
||||
const USER_BUY_NFT_TYPE_1 = 1002;//一口价购买nft
|
||||
const USER_BUY_MARGIN_NFT = 1003;//竞拍保证金
|
||||
const USER_RETURN_MARGIN_NFT = 1004; //退还保证金
|
||||
const USER_ORDER_PAY_NFT = 1005;
|
||||
|
||||
public function getAccountNumberAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Users', 'id', 'user_id')->value('account_number');
|
||||
}
|
||||
|
||||
public function getAccountAttribute()
|
||||
{
|
||||
$value = $this->hasOne('App\Users', 'id', 'user_id')->value('phone');
|
||||
if (empty($value)) {
|
||||
$value = $this->hasOne('App\Users', 'id', 'user_id')->value('email');
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getCreatedTimeAttribute()
|
||||
{
|
||||
$value = $this->attributes['created_time'] ? date('Y-m-d H:i:s', $this->attributes['created_time']) : '';
|
||||
|
||||
if (env('TIME_UTC') && $this->attributes['created_time']) {
|
||||
$value = date('Y-m-d H:i:s', intval($this->attributes['created_time']) - 28800);
|
||||
}
|
||||
|
||||
return $value ? $value : '';
|
||||
}
|
||||
|
||||
public function getBeforeAttribute()
|
||||
{
|
||||
return $this->walletLog()->value('before');
|
||||
}
|
||||
|
||||
public function getAfterAttribute()
|
||||
{
|
||||
return $this->walletLog()->value('after');
|
||||
}
|
||||
|
||||
public function getBalancetypeAttribute()
|
||||
{
|
||||
return $this->walletLog()->value('balance_type');
|
||||
}
|
||||
|
||||
|
||||
public function getTransactionInfoAttribute()
|
||||
{
|
||||
$type1 = [
|
||||
'0' => '无',
|
||||
'1' => '资金',
|
||||
'2' => '币币',
|
||||
'3' => '合约',
|
||||
'4' => '期权',
|
||||
'5' => '保险'
|
||||
];
|
||||
$type2 = ['', '[锁定]'];
|
||||
$balance_type = $this->walletLog()->value('balance_type');
|
||||
$lock_tpye = $this->walletLog()->value('lock_type');
|
||||
array_key_exists($balance_type, $type1) ?: $balance_type = 0;
|
||||
array_key_exists($lock_tpye, $type2) ?: $lock_tpye = 0;
|
||||
return $type1[$balance_type] . $type2[$lock_tpye];
|
||||
|
||||
}
|
||||
|
||||
public function getCurrencyNameAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Currency', 'id', 'currency')->value('name');
|
||||
}
|
||||
|
||||
public static function insertLog($data = array(), $data2 = array())
|
||||
{
|
||||
$data = is_array($data) ? $data : func_get_args();
|
||||
$log = new self();
|
||||
$log->user_id = $data['user_id'] ?? false;;
|
||||
$log->value = $data['value'] ?? '';
|
||||
$log->created_time = $data['created_time'] ?? time();
|
||||
$log->info = $data['info'] ?? '';
|
||||
$log->type = $data['type'] ?? 0;
|
||||
$log->currency = $data['currency'] ?? 0;
|
||||
$data_wallet['balance_type'] = $data2['balance_type'] ?? 0;
|
||||
$data_wallet['wallet_id'] = $data2['wallet_id'] ?? 0;
|
||||
$data_wallet['lock_type'] = $data2['lock_type'] ?? 0;
|
||||
$data_wallet['before'] = $data2['before'] ?? 0;
|
||||
$data_wallet['change'] = $data2['change'] ?? 0;
|
||||
$data_wallet['after'] = $data2['after'] ?? 0;
|
||||
$data_wallet['memo'] = $data['info'] ?? 0;
|
||||
$data_wallet['create_time'] = $data2['create_time'] ?? time();
|
||||
//dd($data_wallet);
|
||||
try {
|
||||
DB::transaction(function () use ($log, $data_wallet) {
|
||||
$log->save();
|
||||
$log->walletLog()->create($data_wallet);
|
||||
});
|
||||
return true;
|
||||
} catch (\Exception $ex) {
|
||||
throw new \Exception($ex->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function newinsertLog($data = array(), $data2 = array())
|
||||
{
|
||||
$data = is_array($data) ? $data : func_get_args();
|
||||
$log = new self();
|
||||
$log->user_id = $data['user_id'] ?? false;;
|
||||
$log->value = $data['value'] ?? '';
|
||||
$log->created_time = $data['created_time'] ?? time();
|
||||
$log->info = $data['info'] ?? '';
|
||||
$log->type = $data['type'] ?? 0;
|
||||
$log->currency = $data['currency'] ?? 0;
|
||||
// $data_wallet['balance_type'] = $data2['balance_type']?? 0;
|
||||
// $data_wallet['wallet_id'] = $data2['wallet_id']?? 0;
|
||||
// $data_wallet['lock_type'] = $data2['lock_type']?? 0;
|
||||
// $data_wallet['before'] = $data2['before']?? 0;
|
||||
// $data_wallet['change'] = $data2['change']?? 0;
|
||||
// $data_wallet['after'] = $data2['after']?? 0;
|
||||
// $data_wallet['memo'] = $data['info']?? 0;
|
||||
// $data_wallet['create_time'] = $data2['create_time']?? time();
|
||||
//dd($data_wallet);
|
||||
try {
|
||||
DB::transaction(function () use ($log) {
|
||||
$log->save();
|
||||
// $log->walletLog()->create($data_wallet);
|
||||
});
|
||||
return true;
|
||||
} catch (\Exception $ex) {
|
||||
throw new \Exception($ex->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getInfoAttribute()
|
||||
{
|
||||
$type = $this->attributes['type'];
|
||||
if ($type == 8) {
|
||||
$type = 3;
|
||||
}
|
||||
if ($type == 502) {
|
||||
$type = 8;
|
||||
}
|
||||
// var_dump($this);
|
||||
$prefix = '';
|
||||
//$lang = session()->get('lang');
|
||||
if ($this->attributes['is_lock']) {
|
||||
$prefix = str_replace('account_log_info.', '', __("account_log_info.is_lock")) . ' ';
|
||||
}
|
||||
$info = str_replace('account_log_info.', '', __("account_log_info.$type"));
|
||||
if ($info == $type) {
|
||||
$info = str_replace('account_log_info.', '', __("account_log_info.unknown"));
|
||||
}
|
||||
|
||||
return $prefix . $info;
|
||||
}
|
||||
|
||||
//中文简体(兼容之前的调用)
|
||||
public static function getTypeInfo($type)
|
||||
{
|
||||
App::setLocale('zh');
|
||||
$info = str_replace('account_log_info.', '', __("account_log_info.$type"));
|
||||
if ($info == $type) {
|
||||
$info = '未知类型';
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Users', 'user_id', 'id');
|
||||
}
|
||||
|
||||
//关联钱包记录模型
|
||||
public function walletLog()
|
||||
{
|
||||
return $this->hasOne('App\WalletLog', 'account_log_id', 'id')->withDefault();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Address extends Model
|
||||
{
|
||||
protected $table = 'address';
|
||||
public $timestamps = false;
|
||||
protected $appends = [];
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* create by vscode
|
||||
* @author lion
|
||||
*/
|
||||
namespace App;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Admin extends Model
|
||||
{
|
||||
protected $table = 'admin';
|
||||
public $timestamps = false;
|
||||
protected $appends = ['role_name'];
|
||||
|
||||
public function getRoleNameAttribute(){
|
||||
return $this->hasOne('App\AdminRole','id','role_id')->value('name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\Scopes\SiteScope;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
||||
class AdminModule extends Model
|
||||
{
|
||||
/**
|
||||
* The database table used by the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'admin_module';
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
public function actions()
|
||||
{
|
||||
return $this->hasMany('App\AdminModuleAction');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
||||
class AdminModuleAction extends Model
|
||||
{
|
||||
/**
|
||||
* The database table used by the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'admin_module_action';
|
||||
public $timestamps = false;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\Scopes\SiteScope;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
||||
class AdminRole extends Model
|
||||
{
|
||||
/**
|
||||
* The database table used by the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'admin_role';
|
||||
public $timestamps = false;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
||||
class AdminRolePermission extends Model
|
||||
{
|
||||
/**
|
||||
* The database table used by the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'admin_role_permission';
|
||||
public $timestamps = false;
|
||||
|
||||
}
|
||||
+704
@@ -0,0 +1,704 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: zef
|
||||
* Date: 2018/11/23
|
||||
* Time: 10:23
|
||||
*/
|
||||
|
||||
namespace App;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\{Users, AgentMoneylog};
|
||||
|
||||
class Agent extends Model
|
||||
{
|
||||
protected $table = 'agent';
|
||||
public $timestamps = false;
|
||||
const CREATED_AT = 'created_time';
|
||||
|
||||
protected $appends = [
|
||||
'phone',
|
||||
'email',
|
||||
'parent_id',
|
||||
'nickname',
|
||||
'parent_agent_name',
|
||||
'agent_name',
|
||||
'son_level',
|
||||
'max_pro_loss',
|
||||
'max_pro_ser',
|
||||
'self_info'
|
||||
];
|
||||
|
||||
const AGENT_TYPE = 1; //后台调节法币账户余额
|
||||
|
||||
public function getPhoneAttribute()
|
||||
{
|
||||
//$value = $this->attributes['username'];
|
||||
$is_admin = $this->attributes['is_admin'];
|
||||
if ($is_admin == 1) {
|
||||
return '';
|
||||
} else {
|
||||
return self::hasOne(Users::class, 'id', 'user_id')->value('phone');
|
||||
}
|
||||
}
|
||||
|
||||
public function getEmailAttribute()
|
||||
{
|
||||
|
||||
$is_admin = $this->attributes['is_admin'];
|
||||
if ($is_admin == 1) {
|
||||
return '';
|
||||
} else {
|
||||
return self::hasOne(Users::class, 'id', 'user_id')->value('email');
|
||||
}
|
||||
}
|
||||
|
||||
public function getParentIdAttribute()
|
||||
{
|
||||
$value = $this->attributes['username'];
|
||||
$is_admin = $this->attributes['is_admin'];
|
||||
if ($value == 'admin' && $is_admin == 1) {
|
||||
return 0;
|
||||
} else {
|
||||
return self::hasOne(Users::class, 'id', 'user_id')->value('parent_id');
|
||||
}
|
||||
}
|
||||
|
||||
public function getNicknameAttribute()
|
||||
{
|
||||
$value = $this->attributes['username'];
|
||||
$is_admin = $this->attributes['is_admin'];
|
||||
if ($is_admin == 1) {
|
||||
return '超管';
|
||||
} else {
|
||||
return self::hasOne(Users::class, 'id', 'user_id')->value('nickname');
|
||||
}
|
||||
}
|
||||
|
||||
public function getRegTimeAttribute()
|
||||
{
|
||||
$value = $this->attributes['reg_time'];
|
||||
if ($value > 0) {
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
} else {
|
||||
return '无';
|
||||
}
|
||||
}
|
||||
|
||||
public function getLockTimeAttribute()
|
||||
{
|
||||
$value = $this->attributes['lock_time'];
|
||||
if ($value > 0) {
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
} else {
|
||||
return '无';
|
||||
}
|
||||
}
|
||||
|
||||
public function getProLossAttribute()
|
||||
{
|
||||
$value = $this->attributes['pro_loss'];
|
||||
if ($value > 0) {
|
||||
return $value;
|
||||
} else {
|
||||
return '0.00';
|
||||
}
|
||||
}
|
||||
|
||||
public function getProSerAttribute()
|
||||
{
|
||||
$value = $this->attributes['pro_ser'];
|
||||
if ($value > 0) {
|
||||
return $value;
|
||||
} else {
|
||||
return '0.00';
|
||||
}
|
||||
}
|
||||
|
||||
public function getParentAgentNameAttribute()
|
||||
{
|
||||
$value = $this->attributes['parent_agent_id'];
|
||||
if ($value > 0) {
|
||||
$p = self::getAgentById($value);
|
||||
return $p?$p->username:'';
|
||||
} else {
|
||||
return '无';
|
||||
}
|
||||
}
|
||||
|
||||
public function getAgentNameAttribute()
|
||||
{
|
||||
$value = $this->attributes['level'];
|
||||
if ($value > 0) {
|
||||
$p = $value . '级代理商';
|
||||
return $p;
|
||||
}else if($value == 0){
|
||||
return '超级';
|
||||
}else {
|
||||
return '无';
|
||||
}
|
||||
}
|
||||
|
||||
public static function getAllChildAgent($agent_id, $refresh = false)
|
||||
{
|
||||
if ($refresh) {
|
||||
$child_agents = self::getRealChildAgent($agent_id);
|
||||
} else {
|
||||
if (Cache::has("child_agents:{$agent_id}")) {
|
||||
$child_agents = Cache::get("child_agents:{$agent_id}");
|
||||
} else {
|
||||
$child_agents = self::getRealChildAgent($agent_id);
|
||||
}
|
||||
}
|
||||
return $child_agents;
|
||||
}
|
||||
|
||||
private static function getRealChildAgent($agent_id)
|
||||
{
|
||||
$child_agents = self::whereRaw('find_in_set(?, agent_path)', [$agent_id])->get();
|
||||
Cache::put("child_agents:{$agent_id}", $child_agents, Carbon::now()->addMinutes(5));
|
||||
return $child_agents;
|
||||
}
|
||||
|
||||
public function getSonLevelAttribute()
|
||||
{
|
||||
$level = $this->attributes['level'];
|
||||
$is_admin = $this->attributes['is_admin'];
|
||||
if ($level >= 0 && $is_admin >= 0) {
|
||||
|
||||
if ($level == 0 && $is_admin == 1) {
|
||||
$son_level = 1;
|
||||
} else if ($is_admin == 0) {
|
||||
$son_level = $level + 1;
|
||||
}
|
||||
return $son_level;
|
||||
} else {
|
||||
return '无';
|
||||
}
|
||||
}
|
||||
|
||||
public function getMaxProLossAttribute()
|
||||
{
|
||||
$value = $this->attributes['pro_loss'];
|
||||
$p_id = $this->attributes['parent_agent_id'];
|
||||
$p_info = self::getAgentById($p_id);
|
||||
if ($p_info != null) {
|
||||
return $p_info['pro_loss'];
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getMaxProSerAttribute()
|
||||
{
|
||||
$value = $this->attributes['pro_ser'];
|
||||
$p_id = $this->attributes['parent_agent_id'];
|
||||
$p_info = self::getAgentById($p_id);
|
||||
if ($p_info != null) {
|
||||
return $p_info['pro_ser'];
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPasswordAttribute()
|
||||
{
|
||||
return '**********';
|
||||
}
|
||||
|
||||
public function getSelfInfoAttribute()
|
||||
{
|
||||
$value = $this->attributes['level'];
|
||||
$agent_max_level = Setting::getValueByKey('agent_max_level', 4);
|
||||
if ($value > 0 && $value <= $agent_max_level) {
|
||||
$_level = $value . '级代理商';
|
||||
// } else if ($value == 2) {
|
||||
// $_level = '二级代理商';
|
||||
// } else if ($value == 3) {
|
||||
// $_level = '三级代理商';
|
||||
// } else if ($value == 4) {
|
||||
// $_level = '四级代理商';
|
||||
} else {
|
||||
$_level = '超级代理商';
|
||||
}
|
||||
|
||||
return $_level;
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
if ($this->is_admin != 1) {
|
||||
return $this->belongsTo(Users::class, 'user_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $mobile
|
||||
* @return string
|
||||
*/
|
||||
public static function getUserByUsername($username)
|
||||
{
|
||||
if (empty($username)) return "";
|
||||
return self::where("username", $username)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $mobile
|
||||
* @return string
|
||||
*/
|
||||
public static function getAgentById($id = 0)
|
||||
{
|
||||
if ($id == 0) return "";
|
||||
return self::where("id", $id)->first();
|
||||
}
|
||||
|
||||
public static function getAgentId()
|
||||
{
|
||||
|
||||
return session()->get('agent_id');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 获取该用户的代理商信息
|
||||
*/
|
||||
public static function getAgent()
|
||||
{
|
||||
return self::getAgentById(self::getAgentId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $obj
|
||||
* @return mixed
|
||||
*/
|
||||
public static function object2array($obj)
|
||||
{
|
||||
return json_decode(json_encode($obj), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $obj
|
||||
*/
|
||||
public static function updateSession($agent)
|
||||
{
|
||||
if ($agent != null) {
|
||||
$access_token = md5($agent->id . $agent->username . $agent->reg_time);
|
||||
session()->put($access_token, $agent->id);
|
||||
session()->put('access_token', $access_token);
|
||||
return $access_token;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $obj
|
||||
*/
|
||||
public static function delSession($request)
|
||||
{
|
||||
|
||||
if ($request->session()->has('agent_id')) {
|
||||
|
||||
session()->put('agent_id', '');
|
||||
session()->put('agent_username', '');
|
||||
|
||||
return true;
|
||||
} elseif (session()->has('access_token')) {
|
||||
$access_token = session()->get('access_token');
|
||||
session()->put($access_token, '');
|
||||
session()->put('access_token', '');
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册的时候,获取上级用户的上级代理商
|
||||
*/
|
||||
public static function reg_get_agent_id_by_parentid($parent = 0)
|
||||
{
|
||||
if ($parent == 0) {
|
||||
//无上级是,获取admin的id
|
||||
// $p = self::where('is_admin', 1)->where('level', 0)->first();
|
||||
// var_dump($p);
|
||||
// return $p->id;
|
||||
return 0;
|
||||
} else {
|
||||
$_p_info = DB::table('users')->where('id', $parent)->first();
|
||||
if ($_p_info != null && !empty($_p_info)) {
|
||||
//如果该用户是代理商,返回该用户的代理商id
|
||||
if ($_p_info->agent_id > 0) {
|
||||
return $_p_info->agent_id;
|
||||
} else if ($_p_info->agent_id == 0 && $_p_info->agent_note_id > 0) {
|
||||
//如果该用户不是代理商,但是用户属于某个代理商,返回所属代理商id
|
||||
return $_p_info->agent_note_id;
|
||||
} else {
|
||||
//其他情况,
|
||||
$p = self::where('is_admin', 1)->where('level', 0)->first();
|
||||
return $p->id;
|
||||
}
|
||||
} else {
|
||||
//无上级是,获取admin的id
|
||||
$p = self::where('is_admin', 1)->where('level', 0)->first();
|
||||
return $p->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户的代理商管理数组
|
||||
* @return array
|
||||
*/
|
||||
public static function getUserParentAgent($user_id = 0)
|
||||
{
|
||||
|
||||
if ($user_id == 0) {
|
||||
return [];
|
||||
} else {
|
||||
$agent_note = DB::table('users')->where("id", $user_id)->select("agent_note_id")->first();
|
||||
if (!empty($agent_note) && $agent_note->agent_note_id == 0) {
|
||||
return [];
|
||||
} else {
|
||||
$arr = [];
|
||||
$_zero = self::getAgentById($agent_note->agent_note_id);
|
||||
|
||||
//上级代理商
|
||||
if ($_zero != null && !empty($_zero)) {
|
||||
if ($_zero->admin != 1) {
|
||||
$_z = [];
|
||||
$_z['agent_id'] = $_zero->id;
|
||||
$_z['user_id'] = $_zero->user_id;
|
||||
$_z['is_admin'] = $_zero->is_admin;
|
||||
$_z['level'] = $_zero->level;
|
||||
$_z['pro_loss'] = $_zero->pro_loss;
|
||||
$_z['pro_ser'] = $_zero->pro_ser;
|
||||
$arr[] = $_z;
|
||||
}
|
||||
|
||||
//上上级代理商
|
||||
if ($_zero->parent_agent_id > 0) {
|
||||
$_two = self::getAgentById($_zero->parent_agent_id);
|
||||
if ($_two->admin != 1) {
|
||||
$_t = [];
|
||||
$_t['agent_id'] = $_two->id;
|
||||
$_t['user_id'] = $_two->user_id;
|
||||
$_t['is_admin'] = $_two->is_admin;
|
||||
$_t['level'] = $_two->level;
|
||||
$_t['pro_loss'] = bcsub($_two->pro_loss, $_zero->pro_loss, 2);
|
||||
$_t['pro_ser'] = bcsub($_two->pro_ser, $_zero->pro_ser, 2);
|
||||
$arr[] = $_t;
|
||||
}
|
||||
|
||||
//上上上级代理商
|
||||
if ($_two->parent_agent_id > 0) {
|
||||
$_three = self::getAgentById($_two->parent_agent_id);
|
||||
if ($_three->admin != 1) {
|
||||
$_th = [];
|
||||
$_th['agent_id'] = $_three->id;
|
||||
$_th['user_id'] = $_three->user_id;
|
||||
$_th['is_admin'] = $_three->is_admin;
|
||||
$_th['level'] = $_three->level;
|
||||
$_th['pro_loss'] = bcsub($_three->pro_loss, $_two->pro_loss, 2);
|
||||
$_th['pro_ser'] = bcsub($_three->pro_ser, $_two->pro_ser, 2);
|
||||
$arr[] = $_th;
|
||||
}
|
||||
|
||||
//上上上上级代理商
|
||||
if ($_three->parent_agent_id > 0) {
|
||||
$_four = self::getAgentById($_three->parent_agent_id);
|
||||
if ($_four->admin != 1) {
|
||||
$_f = [];
|
||||
$_f['agent_id'] = $_four->id;
|
||||
$_f['user_id'] = $_four->user_id;
|
||||
$_f['is_admin'] = $_four->is_admin;
|
||||
$_f['level'] = $_four->level;
|
||||
$_f['pro_loss'] = bcsub($_four->pro_loss, $_three->pro_loss, 2);
|
||||
$_f['pro_ser'] = bcsub($_four->pro_ser, $_three->pro_ser, 2);
|
||||
$arr[] = $_f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 改变用户余额并记录日志
|
||||
*
|
||||
* @param App\User $user 要改变余额的用户模型实例
|
||||
* @param integer $type 类型:1.头寸收益,2.手续费收益
|
||||
* @param float $change 变动数量:正数为添加,负数为减少
|
||||
* @param integer $relate_id 关联Id
|
||||
* @param string $memo 备注
|
||||
* @return true|string
|
||||
*/
|
||||
public static function change_agent_money($agent_id, $type, $change, $relate_id, $memo = '', $son_user_id = 0,$legal_id)
|
||||
{
|
||||
|
||||
|
||||
//记录余额专用流水明细
|
||||
$moneyLog = new AgentMoneylog();
|
||||
$moneyLog->agent_id = $agent_id;
|
||||
$moneyLog->type = $type;
|
||||
$moneyLog->relate_id = $relate_id;
|
||||
//$moneyLog->before = $before ?? 0;
|
||||
$moneyLog->change = $change;
|
||||
//$moneyLog->after = $after;
|
||||
$moneyLog->memo = $memo;
|
||||
$moneyLog->son_user_id = $son_user_id;
|
||||
$moneyLog->legal_id = $legal_id;
|
||||
|
||||
$moneyLog->created_time = time();
|
||||
$moneyLog->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据指定日期获取所在周的起始时间和结束时间
|
||||
*/
|
||||
public static function get_weekinfo_by_date($date)
|
||||
{
|
||||
$idx = strftime("%u", strtotime($date));
|
||||
$mon_idx = $idx - 1;
|
||||
$sun_idx = $idx - 7;
|
||||
return array(
|
||||
'week_start_day' => strftime('%Y-%m-%d', strtotime($date) - $mon_idx * 86400),
|
||||
'week_end_day' => strftime('%Y-%m-%d', strtotime($date) - $sun_idx * 86400),
|
||||
);
|
||||
}
|
||||
/**
|
||||
* 根据指定日期获取所在月的起始时间和结束时间
|
||||
*/
|
||||
public static function get_monthinfo_by_date($date)
|
||||
{
|
||||
$ret = array();
|
||||
$timestamp = strtotime($date);
|
||||
$mdays = date('t', $timestamp);
|
||||
return array(
|
||||
'month_start_day' => date('Y-m-1', $timestamp),
|
||||
'month_end_day' => date('Y-m-' . $mdays, $timestamp)
|
||||
);
|
||||
}
|
||||
/**
|
||||
* 获取指定日期之间的各个周
|
||||
*/
|
||||
public static function get_weeks($sdate, $edate)
|
||||
{
|
||||
$range_arr = array();
|
||||
// 检查日期有效性
|
||||
self::check_date(array($sdate, $edate));
|
||||
// 计算各个周的起始时间
|
||||
do {
|
||||
$weekinfo = self::get_weekinfo_by_date($sdate);
|
||||
$end_day = $weekinfo['week_end_day'];
|
||||
$start = self::substr_date($weekinfo['week_start_day']);
|
||||
$end = self::substr_date($weekinfo['week_end_day']);
|
||||
$range = "{$start}/{$end}";
|
||||
$range_arr[] = $range;
|
||||
$sdate = date('Y-m-d', strtotime($sdate) + 7 * 86400);
|
||||
} while ($end_day < $edate);
|
||||
return $range_arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定日期之间的各个月
|
||||
*/
|
||||
public static function get_months($sdate, $edate)
|
||||
{
|
||||
$range_arr = array();
|
||||
do {
|
||||
$monthinfo = self::get_monthinfo_by_date($sdate);
|
||||
$end_day = $monthinfo['month_end_day'];
|
||||
$start = self::substr_date($monthinfo['month_start_day']);
|
||||
$end = self::substr_date($monthinfo['month_end_day']);
|
||||
$range = "{$start} ~ {$end}";
|
||||
$range_arr[] = $range;
|
||||
$sdate = date('Y-m-d', strtotime($sdate . '+1 month'));
|
||||
} while ($end_day < $edate);
|
||||
return $range_arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取日期中的月份和日
|
||||
* @param string $date
|
||||
* @return string $date
|
||||
*/
|
||||
public static function substr_date($date)
|
||||
{
|
||||
if (!$date) return FALSE;
|
||||
return date('Y-m-d', strtotime($date));
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查日期的有效性 YYYY-mm-dd
|
||||
* @param array $date_arr
|
||||
* @return boolean
|
||||
*/
|
||||
public static function check_date($date_arr)
|
||||
{
|
||||
$invalid_date_arr = array();
|
||||
foreach ($date_arr as $row) {
|
||||
$timestamp = strtotime($row);
|
||||
$standard = date('Y-m-d', $timestamp);
|
||||
if ($standard != $row) $invalid_date_arr[] = $row;
|
||||
}
|
||||
if (!empty($invalid_date_arr)) {
|
||||
die("invalid date -> " . print_r($invalid_date_arr, TRUE));
|
||||
}
|
||||
}
|
||||
|
||||
/**获取我自己四级代理商所有的id 待优化
|
||||
*
|
||||
*/
|
||||
public static function getLevel4AgentId($agent_id, $id_list = [], $level = 0)
|
||||
{
|
||||
if ($level == 4) {
|
||||
return $id_list;
|
||||
}
|
||||
|
||||
$agent_list = static::where('parent_agent_id', $agent_id)->get();
|
||||
|
||||
if (!$agent_list) {
|
||||
return $id_list;
|
||||
}
|
||||
|
||||
$level += 1;
|
||||
|
||||
foreach ($agent_list as $agent) {
|
||||
$id_list[] = $agent->id;
|
||||
$id_list = static::getLevel4AgentId($agent->id, $id_list, $level);
|
||||
}
|
||||
return $id_list;
|
||||
}
|
||||
|
||||
//获取用户的代理商关系
|
||||
public static function agentPath($parent = 0)
|
||||
{
|
||||
|
||||
if ($parent == 0) {
|
||||
//无上级是,获取admin的id
|
||||
// $p = self::where('is_admin', 1)->where('level', 0)->first();
|
||||
// return $p->id;
|
||||
return 0;
|
||||
} else {
|
||||
$_p_info = Users::find($parent);
|
||||
if (!empty($_p_info)) {
|
||||
if ($_p_info->agent_id > 0) {
|
||||
//
|
||||
$agent = self::find($_p_info->agent_id);
|
||||
|
||||
return $agent ? $agent->agent_path : $_p_info->agent_path;
|
||||
} else {
|
||||
|
||||
return $_p_info->agent_path;
|
||||
}
|
||||
} else {
|
||||
//无上级是,获取admin的id
|
||||
$p = self::where('is_admin', 1)->where('level', 0)->first();
|
||||
return $p->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//结算测试
|
||||
public static function dojie($lever_ids) {
|
||||
|
||||
LeverTransaction::where('status' , LeverTransaction::CLOSED)
|
||||
->where('settled' , 0)
|
||||
->whereIn('id',$lever_ids)
|
||||
->chunk(100, function($lever_transactions) {
|
||||
foreach ($lever_transactions as $key => $trade) {
|
||||
try {
|
||||
DB::transaction(function () use ($trade) {
|
||||
//取出该用户的代理商关系数组
|
||||
$agent_path=$trade->agent_path;
|
||||
|
||||
|
||||
$_p_arr =explode(',', $agent_path);
|
||||
//var_dump($_p_arr);
|
||||
|
||||
if (!empty($_p_arr)) {
|
||||
|
||||
$da=[];
|
||||
foreach($_p_arr as $k=>$v){
|
||||
$agent=Agent::getAgentById($v);
|
||||
|
||||
$da[$k]['agent_id']=$v;
|
||||
$da[$k]['pro_loss']=$agent->pro_loss;
|
||||
$da[$k]['pro_ser']=$agent->pro_ser;
|
||||
|
||||
}
|
||||
|
||||
//var_dump($da);exit;
|
||||
|
||||
//极差收益
|
||||
foreach ($da as $k=>$val){
|
||||
|
||||
if($k==0){
|
||||
$pro_loss=$val['pro_loss'];
|
||||
$pro_ser=$val['pro_ser'];
|
||||
}else{
|
||||
$n=$k-1;
|
||||
$pro_loss=bc_sub($val['pro_loss'],$da[$n]['pro_loss']);
|
||||
$pro_ser=bc_sub($val['pro_ser'],$da[$n]['pro_ser']);
|
||||
}
|
||||
|
||||
//头寸收益
|
||||
if ($pro_loss > 0){
|
||||
//盈亏收益 . 头寸收益是反的,需要取相反数
|
||||
$_base_money =bc_mul($trade->fact_profits , -1);
|
||||
$change = bc_mul($_base_money , $pro_loss/100);
|
||||
|
||||
Agent::change_agent_money(
|
||||
$val['agent_id'] ,
|
||||
1 ,
|
||||
$change,
|
||||
$trade->id,
|
||||
'您的下级用户'.$trade->user_id.'的订单产生的头寸收益为'.$change.'。订单编号为'.$trade->id,
|
||||
$trade->user_id,
|
||||
$trade->legal
|
||||
);
|
||||
}
|
||||
|
||||
//手续费收益
|
||||
if ($pro_ser >0){
|
||||
//手续费收益
|
||||
$change = bc_mul($trade->trade_fee ,$pro_ser/100);
|
||||
|
||||
Agent::change_agent_money(
|
||||
$val['agent_id'],
|
||||
2 ,
|
||||
$change,
|
||||
$trade->id,
|
||||
'您的下级用户'.$trade->user_id.'的订单产生的手续费收益为'.$change.'。订单编号为'.$trade->id,
|
||||
$trade->user_id,
|
||||
$trade->legal
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
LeverTransaction::where('id' , $trade->id)->update(['settled' =>1]);
|
||||
});
|
||||
|
||||
} catch (\Exception $e) {
|
||||
echo 'File :' . $e->getFile() . PHP_EOL;
|
||||
echo 'Line :' . $e->getLine() . PHP_EOL;
|
||||
echo 'Msg :' . $e->getMessage(). PHP_EOL;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,558 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: zef
|
||||
* Date: 2018/11/23
|
||||
* Time: 10:23
|
||||
*/
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\Users;
|
||||
use App\AgentMoneylog;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
class Agent extends Model {
|
||||
|
||||
protected $table = 'agent';
|
||||
public $timestamps = false;
|
||||
const CREATED_AT = 'created_time';
|
||||
protected $appends = [
|
||||
'phone',
|
||||
'parent_id',
|
||||
'nickname',
|
||||
'parent_agent_name',
|
||||
'agent_name',
|
||||
'son_level',
|
||||
'max_pro_loss',
|
||||
'max_pro_ser',
|
||||
'self_info'
|
||||
];
|
||||
const AGENT_TYPE = 1;//后台调节法币账户余额
|
||||
|
||||
public function getPhoneAttribute() {
|
||||
$value = $this->attributes['username'];
|
||||
$is_admin = $this->attributes['is_admin'];
|
||||
if ($value == 'admin' && $is_admin == 1){
|
||||
return '';
|
||||
}else{
|
||||
return self::hasOne('App\Users', 'id', 'user_id')->value('phone');
|
||||
}
|
||||
}
|
||||
|
||||
public function getParentIdAttribute(){
|
||||
$value = $this->attributes['username'];
|
||||
$is_admin = $this->attributes['is_admin'];
|
||||
if ($value == 'admin' && $is_admin == 1){
|
||||
return 0;
|
||||
}else{
|
||||
return self::hasOne('App\Users', 'id', 'user_id')->value('parent_id');
|
||||
}
|
||||
}
|
||||
|
||||
public function getNicknameAttribute() {
|
||||
$value = $this->attributes['username'];
|
||||
$is_admin = $this->attributes['is_admin'];
|
||||
if ($value == 'admin' && $is_admin == 1){
|
||||
return '超级管理员';
|
||||
}else{
|
||||
return self::hasOne('App\Users', 'id', 'user_id')->value('nickname');
|
||||
}
|
||||
}
|
||||
|
||||
public function getRegTimeAttribute() {
|
||||
$value = $this->attributes['reg_time'];
|
||||
if ($value > 0){
|
||||
return date('Y-m-d H:i:s' , $value);
|
||||
}else{
|
||||
return '无';
|
||||
}
|
||||
}
|
||||
|
||||
public function getLockTimeAttribute() {
|
||||
$value = $this->attributes['lock_time'];
|
||||
if ($value > 0){
|
||||
return date('Y-m-d H:i:s' , $value);
|
||||
}else{
|
||||
return '无';
|
||||
}
|
||||
}
|
||||
|
||||
public function getProLossAttribute() {
|
||||
$value = $this->attributes['pro_loss'];
|
||||
if ($value > 0){
|
||||
return $value;
|
||||
}else{
|
||||
return '0.00';
|
||||
}
|
||||
}
|
||||
|
||||
public function getProSerAttribute() {
|
||||
$value = $this->attributes['pro_ser'];
|
||||
if ($value > 0){
|
||||
return $value;
|
||||
}else{
|
||||
return '0.00';
|
||||
}
|
||||
}
|
||||
|
||||
public function getParentAgentNameAttribute() {
|
||||
$value = $this->attributes['parent_agent_id'];
|
||||
if ($value > 0){
|
||||
$p = self::getAgentById($value);
|
||||
return $p->username;
|
||||
}else{
|
||||
return '无';
|
||||
}
|
||||
}
|
||||
|
||||
public function getAgentNameAttribute() {
|
||||
$value = $this->attributes['level'];
|
||||
if ($value > 0){
|
||||
$p = '';
|
||||
switch ($value) {
|
||||
case 1:
|
||||
$p = '一级代理商';
|
||||
break;
|
||||
case 2:
|
||||
$p = '二级代理商';
|
||||
break;
|
||||
case 3:
|
||||
$p = '三级代理商';
|
||||
break;
|
||||
case 4:
|
||||
$p = '四级代理商';
|
||||
break;
|
||||
default:
|
||||
$p = '未知';
|
||||
}
|
||||
|
||||
return $p;
|
||||
}else{
|
||||
return '无';
|
||||
}
|
||||
}
|
||||
|
||||
public function getSonLevelAttribute() {
|
||||
$level = $this->attributes['level'];
|
||||
$is_admin = $this->attributes['is_admin'];
|
||||
if ($level >= 0 && $is_admin >= 0){
|
||||
|
||||
if ($level == 0 && $is_admin == 1) {
|
||||
$son_level = 1;
|
||||
} else if ($level == 1 && $is_admin == 0) {
|
||||
$son_level = 2;
|
||||
} else if ($level == 2 && $is_admin == 0) {
|
||||
$son_level = 3;
|
||||
} else if ($level == 3 && $is_admin == 0) {
|
||||
$son_level = 4;
|
||||
}else{
|
||||
$son_level = 5;
|
||||
}
|
||||
return $son_level;
|
||||
}else{
|
||||
return '无';
|
||||
}
|
||||
}
|
||||
|
||||
public function getMaxProLossAttribute() {
|
||||
$value = $this->attributes['pro_loss'];
|
||||
$p_id = $this->attributes['parent_agent_id'];
|
||||
$p_info = self::getAgentById($p_id);
|
||||
if ($p_info != null){
|
||||
return $p_info['pro_loss'];
|
||||
}else{
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
public function getMaxProSerAttribute() {
|
||||
$value = $this->attributes['pro_ser'];
|
||||
$p_id = $this->attributes['parent_agent_id'];
|
||||
$p_info = self::getAgentById($p_id);
|
||||
if ($p_info != null){
|
||||
return $p_info['pro_ser'];
|
||||
}else{
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPasswordAttribute() {
|
||||
return '**********';
|
||||
}
|
||||
|
||||
public function getSelfInfoAttribute() {
|
||||
$value = $this->attributes['level'];
|
||||
|
||||
if ($value == 1) {
|
||||
$_level = '一级代理商';
|
||||
} else if ($value == 2) {
|
||||
$_level = '二级代理商';
|
||||
} else if ($value == 3) {
|
||||
$_level = '三级代理商';
|
||||
} else if ($value == 4) {
|
||||
$_level = '四级代理商';
|
||||
}else{
|
||||
$_level = '不能添加代理商';
|
||||
}
|
||||
|
||||
return $_level;
|
||||
}
|
||||
|
||||
public function user(){
|
||||
if($this->is_admin != 1){
|
||||
return $this->belongsTo('App\Users','user_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $mobile
|
||||
* @return string
|
||||
*/
|
||||
public static function getUserByUsername($username) {
|
||||
if (empty($username)) return "";
|
||||
return self::where("username", $username)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $mobile
|
||||
* @return string
|
||||
*/
|
||||
public static function getAgentById($id = 0) {
|
||||
if ($id == 0) return "";
|
||||
return self::where("id", $id)->first();
|
||||
}
|
||||
|
||||
|
||||
public static function getAgentId() {
|
||||
if (session()->get('access_token')) {
|
||||
$access_token = session()->get('access_token');
|
||||
return session()->get($access_token);
|
||||
}else{
|
||||
return session()->get('user_id');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 获取该用户的代理商信息
|
||||
*/
|
||||
public static function getAgent() {
|
||||
return self::getAgentById(self::getAgentId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $obj
|
||||
* @return mixed
|
||||
*/
|
||||
public static function object2array($obj){
|
||||
return json_decode( json_encode( $obj),true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $obj
|
||||
*/
|
||||
public static function updateSession($agent){
|
||||
if ($agent != null ){
|
||||
$access_token = md5($agent->id . $agent->username . $agent->reg_time);
|
||||
session()->put($access_token , $agent->id);
|
||||
session()->put('access_token', $access_token);
|
||||
return $access_token;
|
||||
}else{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $obj
|
||||
*/
|
||||
public static function delSession($request){
|
||||
if ($request->session()->has('access_token')) {
|
||||
$access_token = session()->get('access_token');
|
||||
session()->put($access_token , '');
|
||||
session()->put('access_token', '');
|
||||
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册的时候,获取上级用户的上级代理商
|
||||
*/
|
||||
public static function reg_get_agent_id_by_parentid ( $parent = 0){
|
||||
if ($parent == 0){
|
||||
//无上级是,获取admin的id
|
||||
$p = self::where('is_admin' , 1)->where('level' , 0)->first();
|
||||
return $p->id;
|
||||
}else{
|
||||
$_p_info = DB::table('users')->where('id' , $parent)->first();
|
||||
if ($_p_info!=null && !empty($_p_info)) {
|
||||
if ($_p_info->agent_id > 0){
|
||||
return $_p_info->agent_id;
|
||||
}else if ($_p_info->agent_id == 0 && $_p_info->agent_note_id>0) {
|
||||
return $_p_info->agent_note_id;
|
||||
}else{
|
||||
$p = self::where('is_admin' , 1)->where('level' , 0)->first();
|
||||
return $p->id;
|
||||
}
|
||||
}else{
|
||||
//无上级是,获取admin的id
|
||||
$p = self::where('is_admin' , 1)->where('level' , 0)->first();
|
||||
return $p->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的代理商管理数组
|
||||
* @return array
|
||||
*/
|
||||
public static function getUserParentAgent($user_id = 0){
|
||||
|
||||
if ($user_id == 0){
|
||||
return [];
|
||||
}else{
|
||||
$agent_note = DB::table('users')->where("id",$user_id)->select("agent_note_id")->first();
|
||||
if (!empty($agent_note) && $agent_note->agent_note_id == 0){
|
||||
return [];
|
||||
}else{
|
||||
$arr = [];
|
||||
$_zero = self::getAgentById($agent_note->agent_note_id);
|
||||
|
||||
//上级代理商
|
||||
if ($_zero != null && !empty($_zero)){
|
||||
if ($_zero->admin != 1){
|
||||
$_z = [];
|
||||
$_z['agent_id'] = $_zero->id;
|
||||
$_z['user_id'] = $_zero->user_id;
|
||||
$_z['is_admin'] = $_zero->is_admin;
|
||||
$_z['level'] = $_zero->level;
|
||||
$_z['pro_loss'] = $_zero->pro_loss;
|
||||
$_z['pro_ser'] = $_zero->pro_ser;
|
||||
$arr[] = $_z;
|
||||
}
|
||||
|
||||
//上上级代理商
|
||||
if ($_zero->parent_agent_id > 0){
|
||||
$_two = self::getAgentById($_zero->parent_agent_id);
|
||||
if ($_two->admin != 1){
|
||||
$_t = [];
|
||||
$_t['agent_id'] = $_two->id;
|
||||
$_t['user_id'] = $_two->user_id;
|
||||
$_t['is_admin'] = $_two->is_admin;
|
||||
$_t['level'] = $_two->level;
|
||||
$_t['pro_loss'] = bcsub($_two->pro_loss , $_zero->pro_loss ,2);
|
||||
$_t['pro_ser'] = bcsub($_two->pro_ser ,$_zero->pro_ser , 2);
|
||||
$arr[] = $_t;
|
||||
}
|
||||
|
||||
//上上上级代理商
|
||||
if ($_two->parent_agent_id > 0){
|
||||
$_three = self::getAgentById($_two->parent_agent_id);
|
||||
if ($_three->admin != 1) {
|
||||
$_th = [];
|
||||
$_th['agent_id'] = $_three->id;
|
||||
$_th['user_id'] = $_three->user_id;
|
||||
$_th['is_admin'] = $_three->is_admin;
|
||||
$_th['level'] = $_three->level;
|
||||
$_th['pro_loss'] = bcsub($_three->pro_loss, $_two->pro_loss, 2);
|
||||
$_th['pro_ser'] = bcsub($_three->pro_ser, $_two->pro_ser, 2);
|
||||
$arr[] = $_th;
|
||||
}
|
||||
|
||||
//上上上上级代理商
|
||||
if ($_three->parent_agent_id > 0){
|
||||
$_four = self::getAgentById($_three->parent_agent_id);
|
||||
if ($_four->admin != 1) {
|
||||
$_f = [];
|
||||
$_f['agent_id'] = $_four->id;
|
||||
$_f['user_id'] = $_four->user_id;
|
||||
$_f['is_admin'] = $_four->is_admin;
|
||||
$_f['level'] = $_four->level;
|
||||
$_f['pro_loss'] = bcsub($_four->pro_loss, $_three->pro_loss, 2);
|
||||
$_f['pro_ser'] = bcsub($_four->pro_ser, $_three->pro_ser, 2);
|
||||
$arr[] = $_f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 改变用户余额并记录日志
|
||||
*
|
||||
* @param App\User $user 要改变余额的用户模型实例
|
||||
* @param integer $type 类型:1.头寸收益,2.手续费收益
|
||||
* @param float $change 变动数量:正数为添加,负数为减少
|
||||
* @param integer $relate_id 关联Id
|
||||
* @param string $memo 备注
|
||||
* @return true|string
|
||||
*/
|
||||
public static function change_agent_money($agent, $type, $change, $relate_id, $memo = '' , $son_user_id = 0) {
|
||||
|
||||
$change = number_format($change, 2, '.', '');
|
||||
|
||||
if (bc_comp($change, '0') === 0) {
|
||||
throw new \Exception('变动数量不能为0');
|
||||
}
|
||||
|
||||
$before = $agent->money;
|
||||
$after = bc_add($before, $change , 8);
|
||||
|
||||
DB::table('agent')->where('id' , $agent->id)->update(['money'=>$after]);
|
||||
|
||||
//记录余额专用流水明细
|
||||
$moneyLog = new AgentMoneylog();
|
||||
$moneyLog->agent_id = $agent->id;
|
||||
$moneyLog->type = $type;
|
||||
$moneyLog->relate_id = $relate_id;
|
||||
$moneyLog->before = $before ?? 0;
|
||||
$moneyLog->change = $change;
|
||||
$moneyLog->after = $after;
|
||||
$moneyLog->memo = $memo;
|
||||
$moneyLog->son_user_id = $son_user_id;
|
||||
$moneyLog->created_time = time();
|
||||
$moneyLog->save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据指定日期获取所在周的起始时间和结束时间
|
||||
*/
|
||||
public static function get_weekinfo_by_date($date) {
|
||||
$idx = strftime("%u", strtotime($date));
|
||||
$mon_idx = $idx - 1;
|
||||
$sun_idx = $idx - 7;
|
||||
return array(
|
||||
'week_start_day' => strftime('%Y-%m-%d', strtotime($date) - $mon_idx * 86400),
|
||||
'week_end_day' => strftime('%Y-%m-%d', strtotime($date) - $sun_idx * 86400),
|
||||
);
|
||||
}
|
||||
/**
|
||||
* 根据指定日期获取所在月的起始时间和结束时间
|
||||
*/
|
||||
public static function get_monthinfo_by_date($date){
|
||||
$ret = array();
|
||||
$timestamp = strtotime($date);
|
||||
$mdays = date('t', $timestamp);
|
||||
return array(
|
||||
'month_start_day' => date('Y-m-1', $timestamp),
|
||||
'month_end_day' => date('Y-m-'.$mdays, $timestamp)
|
||||
);
|
||||
}
|
||||
/**
|
||||
* 获取指定日期之间的各个周
|
||||
*/
|
||||
public static function get_weeks($sdate, $edate) {
|
||||
$range_arr = array();
|
||||
// 检查日期有效性
|
||||
self::check_date(array($sdate, $edate));
|
||||
// 计算各个周的起始时间
|
||||
do {
|
||||
$weekinfo = self::get_weekinfo_by_date($sdate);
|
||||
$end_day = $weekinfo['week_end_day'];
|
||||
$start = self::substr_date($weekinfo['week_start_day']);
|
||||
$end = self::substr_date($weekinfo['week_end_day']);
|
||||
$range = "{$start}/{$end}";
|
||||
$range_arr[] = $range;
|
||||
$sdate = date('Y-m-d', strtotime($sdate)+7*86400);
|
||||
}while($end_day < $edate);
|
||||
return $range_arr;
|
||||
}
|
||||
/**
|
||||
* 获取指定日期之间的各个月
|
||||
*/
|
||||
public static function get_months($sdate, $edate) {
|
||||
$range_arr = array();
|
||||
do {
|
||||
$monthinfo = self::get_monthinfo_by_date($sdate);
|
||||
$end_day = $monthinfo['month_end_day'];
|
||||
$start = self::substr_date($monthinfo['month_start_day']);
|
||||
$end = self::substr_date($monthinfo['month_end_day']);
|
||||
$range = "{$start} ~ {$end}";
|
||||
$range_arr[] = $range;
|
||||
$sdate = date('Y-m-d', strtotime($sdate.'+1 month'));
|
||||
}while($end_day < $edate);
|
||||
return $range_arr;
|
||||
}
|
||||
/**
|
||||
* 截取日期中的月份和日
|
||||
* @param string $date
|
||||
* @return string $date
|
||||
*/
|
||||
public static function substr_date($date) {
|
||||
if ( ! $date) return FALSE;
|
||||
return date('Y-m-d', strtotime($date));
|
||||
}
|
||||
/**
|
||||
* 检查日期的有效性 YYYY-mm-dd
|
||||
* @param array $date_arr
|
||||
* @return boolean
|
||||
*/
|
||||
public static function check_date($date_arr) {
|
||||
$invalid_date_arr = array();
|
||||
foreach ($date_arr as $row) {
|
||||
$timestamp = strtotime($row);
|
||||
$standard = date('Y-m-d', $timestamp);
|
||||
if ($standard != $row) $invalid_date_arr[] = $row;
|
||||
}
|
||||
if ( ! empty($invalid_date_arr)) {
|
||||
die("invalid date -> ".print_r($invalid_date_arr, TRUE));
|
||||
}
|
||||
}
|
||||
|
||||
/**获取我自己四级代理商所有的id
|
||||
*
|
||||
*/
|
||||
public static function getLevel4AgentId($agent_id,$id_list=[],$level=0){
|
||||
if($level==4){
|
||||
return $id_list;
|
||||
}
|
||||
|
||||
$agent_list=static::where('parent_agent_id',$agent_id)->get();
|
||||
|
||||
if(!$agent_list){
|
||||
return $id_list;
|
||||
}
|
||||
|
||||
$level+=1;
|
||||
|
||||
foreach ($agent_list as $agent){
|
||||
$id_list[]=$agent->id;
|
||||
$id_list= static::getLevel4AgentId($agent->id,$id_list,$level);
|
||||
}
|
||||
return $id_list;
|
||||
}
|
||||
|
||||
public static function getAllChildAgent($agent_id, $refresh = false)
|
||||
{
|
||||
if ($refresh) {
|
||||
$child_agents = self::getRealChildAgent($agent_id);
|
||||
} else {
|
||||
if (Cache::has("child_agents:{$agent_id}")) {
|
||||
$child_agents = Cache::get("child_agents:{$agent_id}");
|
||||
} else {
|
||||
$child_agents = self::getRealChildAgent($agent_id);
|
||||
}
|
||||
}
|
||||
return $child_agents;
|
||||
}
|
||||
|
||||
private static function getRealChildAgent($agent_id)
|
||||
{
|
||||
$child_agents = self::whereRaw('find_in_set(?, lavel_path)', [$agent_id])->get();
|
||||
Cache::put("child_agents:{$agent_id}", $child_agents, 5);
|
||||
return $child_agents;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\Scopes\SiteScope;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
||||
class AgentAdmin extends Model
|
||||
{
|
||||
/**
|
||||
* The database table used by the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'agent_admin';
|
||||
public $timestamps = false;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
class AgentMoneylog extends Model
|
||||
{
|
||||
protected $table = 'agent_money_log';
|
||||
public $timestamps = false;
|
||||
protected $appends = [
|
||||
'user_name',
|
||||
'agent_level',
|
||||
'jie_agent_name',
|
||||
'jie_agent_level',
|
||||
'legal_name'
|
||||
];
|
||||
|
||||
public function getCreatedTimeAttribute($value)
|
||||
{
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
|
||||
public function getUserNameAttribute()
|
||||
{
|
||||
|
||||
// $user=$this->user()->getResults();
|
||||
|
||||
// return $user?$user->account_number:'';
|
||||
|
||||
$user=$this->user()->value('account_number');
|
||||
|
||||
return $user??'';
|
||||
|
||||
}
|
||||
|
||||
public function getJieAgentNameAttribute()
|
||||
{
|
||||
$agent=$this->agent()->getResults();
|
||||
|
||||
return $agent?$agent->username:'';
|
||||
}
|
||||
|
||||
public function getJieAgentLevelAttribute()
|
||||
{
|
||||
$agent=$this->agent()->getResults();
|
||||
|
||||
return $agent->is_admin==1?'超级代理商':$agent->level.'级代理商';
|
||||
}
|
||||
|
||||
public function getLegalNameAttribute()
|
||||
{
|
||||
$value = $this->attributes['legal_id'];
|
||||
$legal=Currency::find($value);
|
||||
|
||||
return $legal?$legal->name:'';
|
||||
}
|
||||
|
||||
|
||||
public function getAgentLevelAttribute() {
|
||||
// $value = $this->attributes['son_user_id'];
|
||||
|
||||
// $user = self::get_user($value);
|
||||
$user=$this->user()->getResults();
|
||||
if ($user->agent_id == 0){
|
||||
return '普通用户';
|
||||
}else{
|
||||
$agent = DB::table('agent')->where('id' , $user->agent_id)->first();
|
||||
|
||||
if($agent && $agent->level == 0){
|
||||
$agent_name = '超级代理商';
|
||||
}else if($agent && $agent->level > 0){
|
||||
$agent_name = "{$agent->level}级代理商";
|
||||
}else{
|
||||
$agent_name = '普通用户';
|
||||
}
|
||||
return $agent_name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static function get_user($uid){
|
||||
return DB::table('users')->where('id' , $uid)->first();
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(Users::class, 'son_user_id', 'id');
|
||||
}
|
||||
|
||||
public function agent()
|
||||
{
|
||||
return $this->belongsTo(Agent::class, 'agent_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AgentMoneylog extends Model
|
||||
{
|
||||
protected $table = 'agent_money_log';
|
||||
public $timestamps = false;
|
||||
protected $appends = [
|
||||
'user_name',
|
||||
'agent_level'
|
||||
];
|
||||
|
||||
public function getCreatedTimeAttribute($value)
|
||||
{
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
|
||||
public function getUserNameAttribute($value)
|
||||
{
|
||||
$value = $this->attributes['son_user_id'];
|
||||
|
||||
$user = self::get_user($value);
|
||||
|
||||
return $user->account_number;
|
||||
}
|
||||
|
||||
|
||||
public function getAgentLevelAttribute() {
|
||||
$value = $this->attributes['son_user_id'];
|
||||
|
||||
$user = self::get_user($value);
|
||||
if ($user->agent_id == 0){
|
||||
return '普通用户';
|
||||
}else{
|
||||
$agent = DB::table('agent')->where('id' , $user->agent_id)->first();
|
||||
|
||||
$agent_name = '';
|
||||
switch ($agent->level){
|
||||
case 0:
|
||||
$agent_name = '超级管理员';
|
||||
break;
|
||||
case 1:
|
||||
$agent_name = '一级代理商';
|
||||
break;
|
||||
case 2:
|
||||
$agent_name = '二级代理商';
|
||||
break;
|
||||
case 3:
|
||||
$agent_name = '三级代理商';
|
||||
break;
|
||||
case 4:
|
||||
$agent_name = '四级代理商';
|
||||
break;
|
||||
default:
|
||||
$agent_name = '普通用户';
|
||||
}
|
||||
return $agent_name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static function get_user($uid){
|
||||
return DB::table('users')->where('id' , $uid)->first();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\Scopes\SiteScope;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
||||
class AgentRole extends Model
|
||||
{
|
||||
/**
|
||||
* The database table used by the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'agent_role';
|
||||
public $timestamps = false;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AiCurrency extends Model
|
||||
{
|
||||
protected $table = 'ai_currency';
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
|
||||
public function getCurrencyNameAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Currency', 'id', 'currency_id')->value('name');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\BaseModel;
|
||||
|
||||
class AiList extends Model
|
||||
{
|
||||
|
||||
protected $table = "ai_list";
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AiOrder extends Model
|
||||
{
|
||||
protected $table = 'ai_order';
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
|
||||
|
||||
public function getCurrencyNameAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Currency', 'id', 'currency_id')->value('name');
|
||||
}
|
||||
|
||||
public function getDualNameAttribute()
|
||||
{
|
||||
return $this->hasOne('App\AiCurrency', 'id', 'ai_id')->value('name');
|
||||
}
|
||||
|
||||
public static function random_float($min, $max) {
|
||||
return $min + mt_rand() / mt_getrandmax() * ($max - $min);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Seller;
|
||||
|
||||
class Algebra extends Model
|
||||
{
|
||||
protected $table = 'algebra';
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* create by vscode
|
||||
* @author lion
|
||||
*/
|
||||
namespace App;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AreaCode extends Model
|
||||
{
|
||||
protected $table = 'area_code';
|
||||
public $timestamps = false;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AutoList extends Model
|
||||
{
|
||||
protected $table = 'auto_list';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $appends = ['buy_account','sell_account','currency_name','legal_name'];
|
||||
|
||||
public function getBuyAccountAttribute(){
|
||||
return $this->hasOne('App\Users','id','buy_user_id')->value('account_number') ?? '';
|
||||
}
|
||||
|
||||
public function getSellAccountAttribute(){
|
||||
return $this->hasOne('App\Users','id','sell_user_id')->value('account_number') ?? '';
|
||||
}
|
||||
|
||||
public function getCurrencyNameAttribute(){
|
||||
return $this->hasOne('App\Currency','id','currency_id')->value('name');
|
||||
}
|
||||
|
||||
public function getLegalNameAttribute(){
|
||||
return $this->hasOne('App\Currency','id','legal_id')->value('name');
|
||||
}
|
||||
|
||||
public function getCreateTimeAttribute(){
|
||||
return date('Y-m-d H:i:s',$this->attributes['create_time']);
|
||||
}
|
||||
|
||||
public static function getPriceArea($currency_id,$legal_id){
|
||||
$results = array();
|
||||
//买入最高价
|
||||
$in = TransactionIn::where('currency',$currency_id)->where('legal',$legal_id)->where('number','>',0)->orderBy('price','desc')->first();
|
||||
//卖出最低价
|
||||
$out = TransactionOut::where('currency',$currency_id)->where('legal',$legal_id)->where('number','>',0)->orderBy('price','asc')->first();
|
||||
if (!empty($in) && !empty($out)){
|
||||
$results['min'] = $in->price;
|
||||
$results['max'] = $out->price;
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: swl
|
||||
* Date: 2018/7/3
|
||||
* Time: 10:23
|
||||
*/
|
||||
|
||||
namespace App;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BalanceList extends Model
|
||||
{
|
||||
protected $table = 'balance_list';
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Bank extends Model
|
||||
{
|
||||
protected $table = 'bank';
|
||||
public $timestamps = false;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* hujinsuo01
|
||||
* 继承此类可以创建此model的触发器
|
||||
*
|
||||
*/
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BaseModel extends Model
|
||||
{
|
||||
public static function boot() {
|
||||
parent::boot();
|
||||
$myself = get_called_class();
|
||||
$hooks = array('before' => 'ing', 'after' => 'ed');
|
||||
$radicals = array('sav', 'validat', 'creat', 'updat', 'delet');
|
||||
foreach ($radicals as $rad) {
|
||||
foreach ($hooks as $hook => $event) {
|
||||
$method = $hook.ucfirst($rad).'e';
|
||||
if (method_exists($myself, $method)) {
|
||||
$eventMethod = $rad.$event;
|
||||
self::$eventMethod(function($model) use ($method){
|
||||
return $model->$method($model);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\{
|
||||
Address,
|
||||
Currency,
|
||||
UsersInsurance,
|
||||
InsuranceType,
|
||||
InsuranceClaimApply,
|
||||
Users,
|
||||
UserCashInfo,
|
||||
UserReal,
|
||||
UsersWallet,
|
||||
BindBoxOrder,
|
||||
BindBoxQuotationLog,
|
||||
BindBoxCollect
|
||||
};
|
||||
|
||||
class BindBox extends Model
|
||||
{
|
||||
protected $table = 'bind_box';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $appends = [
|
||||
'head_portrait',
|
||||
'author_name',
|
||||
'currency_name',
|
||||
];
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo(Currency::class);
|
||||
}
|
||||
|
||||
public function getCurrencyNameAttribute()
|
||||
{
|
||||
return $this->currency()->value('name');
|
||||
}
|
||||
|
||||
public function getHeadPortraitAttribute()
|
||||
{
|
||||
$user = Users::find($this->attributes['author']);
|
||||
if (!empty($user)) {
|
||||
return $user->head_portrait;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getAuthorNameAttribute()
|
||||
{
|
||||
$user = Users::find($this->attributes['author']);
|
||||
if (!empty($user)) {
|
||||
return $user->nickname;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BindBoxCollect extends Model
|
||||
{
|
||||
protected $table = 'bind_box_collect';
|
||||
public $timestamps = false;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Currency;
|
||||
|
||||
class BindBoxMarginLog extends Model
|
||||
{
|
||||
protected $table = 'bind_box_margin_log';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $appends = [
|
||||
'currency_name',
|
||||
];
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo(Currency::class);
|
||||
}
|
||||
|
||||
public function getCurrencyNameAttribute()
|
||||
{
|
||||
return $this->currency()->value('name');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Currency;
|
||||
|
||||
class BindBoxOrder extends Model
|
||||
{
|
||||
protected $table = 'bind_box_order';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $appends = [
|
||||
'currency_name',
|
||||
];
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo(Currency::class);
|
||||
}
|
||||
|
||||
public function getCurrencyNameAttribute()
|
||||
{
|
||||
return $this->currency()->value('name');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Currency;
|
||||
use App\Users;
|
||||
use App\BindBox;
|
||||
|
||||
class BindBoxQuotationLog extends Model
|
||||
{
|
||||
protected $table = 'bind_box_quotation_log';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $appends = [
|
||||
'head_portrait',
|
||||
'currency_name',
|
||||
'nick_name',
|
||||
'nft_name',
|
||||
'nft_image',
|
||||
];
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo(Currency::class);
|
||||
}
|
||||
|
||||
public function getCurrencyNameAttribute()
|
||||
{
|
||||
return $this->currency()->value('name');
|
||||
}
|
||||
|
||||
public function getHeadPortraitAttribute()
|
||||
{
|
||||
$user = Users::find($this->attributes['buyer_id']);
|
||||
if (!empty($user)) {
|
||||
return $user->head_portrait;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getNftImageAttribute()
|
||||
{
|
||||
|
||||
$BindBox = BindBox::where('code',$this->attributes['code'])->first();
|
||||
if (!empty($BindBox)) {
|
||||
return $BindBox->image;
|
||||
}
|
||||
return '';
|
||||
|
||||
}
|
||||
public function getNftNameAttribute()
|
||||
{
|
||||
|
||||
$BindBox = BindBox::where('code',$this->attributes['code'])->first();
|
||||
if (!empty($BindBox)) {
|
||||
return $BindBox->name;
|
||||
}
|
||||
return '';
|
||||
|
||||
}
|
||||
public function getNickNameAttribute()
|
||||
{
|
||||
|
||||
$user = Users::find($this->attributes['buyer_id']);
|
||||
if (!empty($user)) {
|
||||
return $user->nickname;
|
||||
}
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Currency;
|
||||
|
||||
class BindBoxRaityHouse extends Model
|
||||
{
|
||||
protected $table = 'bind_box_raity_house';
|
||||
public $timestamps = false;
|
||||
|
||||
// protected $appends = [
|
||||
// 'currency_name',
|
||||
// ];
|
||||
|
||||
// public function currency()
|
||||
// {
|
||||
// return $this->belongsTo(Currency::class);
|
||||
// }
|
||||
|
||||
// public function getCurrencyNameAttribute()
|
||||
// {
|
||||
// return $this->currency()->value('name');
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Currency;
|
||||
use App\BindBox;
|
||||
|
||||
class BindBoxSuccessOrder extends Model
|
||||
{
|
||||
protected $table = 'bind_box_success_order';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $appends = [
|
||||
'currency_name',
|
||||
'image',
|
||||
'end_time',
|
||||
'name',
|
||||
'price',
|
||||
];
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo(Currency::class);
|
||||
}
|
||||
|
||||
public function getCurrencyNameAttribute()
|
||||
{
|
||||
return $this->currency()->value('name');
|
||||
}
|
||||
|
||||
public function getPriceAttribute()
|
||||
{
|
||||
$BindBox = BindBox::where('code',$this->attributes['code'])->first();
|
||||
if (!empty($BindBox)) {
|
||||
return $BindBox->price;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getImageAttribute()
|
||||
{
|
||||
$BindBox = BindBox::where('code',$this->attributes['code'])->first();
|
||||
if (!empty($BindBox)) {
|
||||
return $BindBox->image;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getEndTimeAttribute()
|
||||
{
|
||||
$BindBox = BindBox::where('code',$this->attributes['code'])->first();
|
||||
if (!empty($BindBox)) {
|
||||
return $BindBox->end_time;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getNameAttribute()
|
||||
{
|
||||
$BindBox = BindBox::where('code',$this->attributes['code'])->first();
|
||||
if (!empty($BindBox)) {
|
||||
return $BindBox->name;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+283
@@ -0,0 +1,283 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class C2cDeal extends Model
|
||||
{
|
||||
protected $table = 'c2c_deal';
|
||||
public $timestamps = false;
|
||||
protected $appends = [
|
||||
'deal_money',
|
||||
'currency_name',
|
||||
'type',
|
||||
'account_number',
|
||||
'phone',
|
||||
'seller_name',
|
||||
'price',
|
||||
'hes_account',
|
||||
'hes_realname',
|
||||
'way_name',
|
||||
'format_create_time',
|
||||
'is_seller',
|
||||
'user_cash_info',
|
||||
'seller_phone',
|
||||
'user_realname',
|
||||
'format_update_time',
|
||||
'sell_cash_info',
|
||||
];
|
||||
public function getSellCashInfoAttribute(){
|
||||
return UserCashInfo::where('user_id',$this->attributes['seller_id'])->first();
|
||||
}
|
||||
public function getUserCashInfoAttribute()
|
||||
{
|
||||
$user = $this->user()->getResults();
|
||||
if (!$user) {
|
||||
return [];
|
||||
}
|
||||
$cashinfo = $user->cashinfo;
|
||||
if (!$cashinfo) {
|
||||
return [];
|
||||
}
|
||||
return $cashinfo;
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Users', 'user_id', 'id');
|
||||
}
|
||||
public function seller()
|
||||
{
|
||||
return $this->belongsTo('App\Users', 'seller_id', 'id');
|
||||
}
|
||||
|
||||
public function legalDealSend()
|
||||
{
|
||||
return $this->hasOne('App\C2cDealSend', 'id', 'legal_deal_send_id');
|
||||
}
|
||||
|
||||
public function getCreateTimeAttribute()
|
||||
{
|
||||
return date('H:i m/d', $this->attributes['create_time']);
|
||||
}
|
||||
public function getFormatCreateTimeAttribute()
|
||||
{
|
||||
return date('Y-m-d H:i:s', $this->attributes['create_time']);
|
||||
}
|
||||
|
||||
public function getFormatUpdateTimeAttribute()
|
||||
{
|
||||
$time=isset($this->attributes['update_time'])?$this->attributes['update_time']:0;
|
||||
return $time?date('Y-m-d H:i:s',$time):'';
|
||||
|
||||
}
|
||||
|
||||
public function getDealMoneyAttribute()
|
||||
{
|
||||
$legal = C2cDealSend::find($this->attributes['legal_deal_send_id']);
|
||||
if (!empty($legal)) {
|
||||
return bcmul($this->attributes['number'], $legal->price, 6);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public function getCurrencyNameAttribute()
|
||||
{
|
||||
$legal = C2cDealSend::find($this->attributes['legal_deal_send_id']);
|
||||
if (!empty($legal)) {
|
||||
return $legal->currency_name;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getSellerPhoneAttribute(){
|
||||
$seller = Users::find($this->attributes['seller_id']);
|
||||
if (empty($seller)) return null;
|
||||
// $user = Users::find($seller->user_id);
|
||||
if (!empty($seller)){
|
||||
return $seller->phone;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTypeAttribute()
|
||||
{
|
||||
return $this->hasOne('App\C2cDealSend', 'id', 'legal_deal_send_id')->value('type');
|
||||
}
|
||||
|
||||
public function getAccountNumberAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Users', 'id', 'user_id')->value('account_number');
|
||||
}
|
||||
|
||||
public function getPhoneAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Users', 'id', 'user_id')->value('account_number');
|
||||
}
|
||||
|
||||
public function getSellerNameAttribute()
|
||||
{
|
||||
//return $this->hasOne('App\Seller', 'id', 'seller_id')->value('name');
|
||||
return $this->hasOne('App\Users', 'id', 'seller_id')->value('account_number');
|
||||
}
|
||||
|
||||
public function getPriceAttribute()
|
||||
{
|
||||
return $this->hasOne('App\C2cDealSend', 'id', 'legal_deal_send_id')->value('price');
|
||||
}
|
||||
|
||||
public function getHesAccountAttribute()
|
||||
{
|
||||
$legal_send = C2cDealSend::find($this->attributes['legal_deal_send_id']);
|
||||
if (!empty($legal_send)) {
|
||||
$seller = Users::find($legal_send->seller_id)->cashinfo;
|
||||
if (!empty($seller)) {
|
||||
|
||||
if ($legal_send->way == 'bank') {
|
||||
return $seller->bank_account;
|
||||
} elseif ($legal_send->way == 'we_chat') {
|
||||
return $seller->wechat_account;
|
||||
} elseif ($legal_send->way == 'ali_pay') {
|
||||
return $seller->ali_account;
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getHesRealnameAttribute()
|
||||
{
|
||||
|
||||
$seller_id=$this->attributes['seller_id'];
|
||||
|
||||
$real = UserReal::where('user_id', $seller_id)->where('review_status', 2)->first();
|
||||
if (!empty($real)) {
|
||||
return $real->name;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getUserRealnameAttribute()
|
||||
{
|
||||
$user_real = UserReal::where('user_id', $this->attributes['user_id'])->first();
|
||||
if (empty($user_real)) {
|
||||
return '';
|
||||
}
|
||||
return $user_real->name;
|
||||
}
|
||||
|
||||
public function getWayNameAttribute()
|
||||
{
|
||||
return C2cDealSend::find($this->attributes['legal_deal_send_id'])->way_name;
|
||||
}
|
||||
|
||||
// 是否卖方
|
||||
public function getIsSellerAttribute()
|
||||
{
|
||||
$user_id = Users::getUserId();
|
||||
$legal_send = C2cDealSend::find($this->attributes['legal_deal_send_id']);
|
||||
$seller = Seller::find($this->attributes['seller_id']);
|
||||
if ($legal_send == null || $seller == null) {
|
||||
return 0;
|
||||
}
|
||||
if (($this->attributes['user_id'] == $user_id) && ($legal_send->type == 'buy')) {
|
||||
return 1;
|
||||
} elseif (($legal_send->type == 'sell') && ($user_id == $seller->user_id)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static function cancelLegalDealById($legal_deal_id,$type = AccountLog::C2C_DEAL_AUTO_CANCEL){
|
||||
// DB::beginTransaction();
|
||||
try{
|
||||
$legal_deal = C2cDeal::find($legal_deal_id);
|
||||
$legal_deal_send = C2cDealSend::lockForUpdate()->find($legal_deal->legal_deal_send_id);
|
||||
$users_wallet = UsersWallet::where('user_id', $legal_deal->user_id)->lockForUpdate()->where('currency', $legal_deal_send->currency_id)->first();
|
||||
if ($legal_deal_send->type == 'buy') { //求购
|
||||
// do something
|
||||
// if ($users_wallet->legal_balance < $number){
|
||||
// DB::rollback();
|
||||
// return $this->error('您的法币余额不足');
|
||||
// }
|
||||
// $legal_deal_send->surplus_number += $legal_deal->number;//
|
||||
// $legal_deal_send->surplus_number = bc_add($legal_deal_send->surplus_number,$legal_deal->number,5);//
|
||||
// if ($legal_deal_send->surplus_number > 0) {
|
||||
// $legal_deal_send->is_done = 0;
|
||||
// }
|
||||
$legal_deal_send->is_done = 0;
|
||||
$data_wallet1 = [
|
||||
'balance_type' => 2,
|
||||
'wallet_id' => $users_wallet->id,
|
||||
'lock_type' => 0,
|
||||
'create_time' => time(),
|
||||
'before' => $users_wallet->legal_balance,
|
||||
'change' => $legal_deal->number,
|
||||
'after' => bc_add($users_wallet->legal_balance, $legal_deal->number, 5),
|
||||
];
|
||||
$data_wallet2 = [
|
||||
'balance_type' => 2,
|
||||
'wallet_id' => $users_wallet->id,
|
||||
'lock_type' => 1,
|
||||
'create_time' => time(),
|
||||
'before' => $users_wallet->lock_legal_balance,
|
||||
'change' => -$legal_deal->number,
|
||||
'after' => bc_sub($users_wallet->lock_legal_balance, $legal_deal->number, 5),
|
||||
];
|
||||
// $users_wallet->legal_balance += $legal_deal->number;
|
||||
$users_wallet->legal_balance = bc_add($users_wallet->legal_balance,$legal_deal->number,5);
|
||||
// $users_wallet->lock_legal_balance -= $legal_deal->number;
|
||||
$users_wallet->lock_legal_balance = bc_sub($users_wallet->lock_legal_balance,$legal_deal->number,5);
|
||||
$users_wallet->save();
|
||||
$legal_deal_send->save();
|
||||
|
||||
AccountLog::insertLog(
|
||||
[
|
||||
'user_id' => $legal_deal->user_id,
|
||||
'value' => $legal_deal->number,
|
||||
'info' => '取消出售给商家法币,余额增加',
|
||||
'type' => $type,
|
||||
'currency' => $legal_deal_send->currency_id
|
||||
],
|
||||
$data_wallet1
|
||||
);
|
||||
AccountLog::insertLog(
|
||||
[
|
||||
'user_id' => $legal_deal->user_id,
|
||||
'value' => -$legal_deal->number,
|
||||
'info' => '取消出售给商家法币,锁定余额减少',
|
||||
'type' => $type,
|
||||
'currency' => $legal_deal_send->currency_id
|
||||
],
|
||||
$data_wallet2
|
||||
);
|
||||
} elseif ($legal_deal_send->type == 'sell') { //出售
|
||||
// $legal_deal_send->surplus_number += $legal_deal->number;
|
||||
// $legal_deal_send->surplus_number = bc_add($legal_deal_send->surplus_number,$legal_deal->number,5);
|
||||
// if ($legal_deal_send->surplus_number > 0) {
|
||||
// $legal_deal_send->is_done = 0;
|
||||
// }
|
||||
$legal_deal_send->is_done = 0;
|
||||
$legal_deal_send->save();
|
||||
}
|
||||
$legal_deal->is_sure = 2;
|
||||
$legal_deal->save();
|
||||
$legal_deal->update_time = time();
|
||||
// DB::commit();
|
||||
return true;
|
||||
|
||||
}catch (\Exception $exception){
|
||||
throw new \Exception($exception->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class C2cDealSend extends Model
|
||||
{
|
||||
protected $table = 'c2c_deal_send';
|
||||
public $timestamps = false;
|
||||
protected $appends = ['seller_name','currency_name','limitation','way_name','currency_logo'];
|
||||
|
||||
public function getCreateTimeAttribute(){
|
||||
return date('Y-m-d H:i:s',$this->attributes['create_time']);
|
||||
}
|
||||
|
||||
public function getSellerNameAttribute(){
|
||||
return $this->hasOne('App\Users','id','seller_id')->value('account_number');
|
||||
}
|
||||
public function user(){
|
||||
return $this->hasOne('App\Users','id','seller_id');
|
||||
}
|
||||
|
||||
public function getCurrencyNameAttribute(){
|
||||
return $this->hasOne('App\Currency','id','currency_id')->value('name');
|
||||
}
|
||||
|
||||
public function getCurrencyLogoAttribute(){
|
||||
return $this->hasOne('App\Currency','id','currency_id')->value('logo');
|
||||
}
|
||||
|
||||
public function getLimitationAttribute(){
|
||||
return array('min'=>bc_mul($this->attributes['min_number'] , $this->attributes['price'],5),
|
||||
'max'=>bc_mul($this->attributes['surplus_number'] , $this->attributes['price'],5)
|
||||
);
|
||||
}
|
||||
|
||||
public function getWayNameAttribute(){
|
||||
if ($this->attributes['way'] == 'ali_pay'){
|
||||
return '支付宝';
|
||||
}elseif ($this->attributes['way'] == 'we_chat'){
|
||||
return '微信';
|
||||
}elseif ($this->attributes['way'] == 'bank'){
|
||||
//return Seller::find($this->attributes['seller_id'])->bank_name;
|
||||
return UserCashInfo::where('user_id',$this->attributes['seller_id'])->first()->bank_name;
|
||||
}
|
||||
}
|
||||
|
||||
//该发布信息下是否有未完成的订单
|
||||
public static function isHasIncompleteness($id){
|
||||
$is_deal = C2cDeal::where('legal_deal_send_id', $id)->pluck('is_sure')->toArray();
|
||||
// var_dump($is_deal);die;
|
||||
if (in_array(0,$is_deal)) {
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//撤回发布
|
||||
public static function sendBack($id){
|
||||
//找到撤回的交易记录
|
||||
$send = self::find($id);
|
||||
try{
|
||||
$results = C2cDeal::where('legal_deal_send_id',$id)
|
||||
->where('is_sure',0)->get();
|
||||
if (!empty($results)){
|
||||
foreach ($results as $result){
|
||||
|
||||
C2cDeal::cancelLegalDealById($result->id,AccountLog::C2C_DEAL_AUTO_CANCEL);
|
||||
|
||||
}
|
||||
$send->is_done = 1;
|
||||
$send->save();
|
||||
}
|
||||
return true;
|
||||
}catch (\Exception $exception){
|
||||
throw new \Exception($exception->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function legalDeal(){
|
||||
return $this->hasOne('App\C2cDeal','legal_deal_send_id','id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Users;
|
||||
//use App\CandyTransfer;
|
||||
|
||||
class CandyTransfer extends Model
|
||||
{
|
||||
protected $table = 'candy_transfer';
|
||||
public $timestamps = false;
|
||||
const CREATED_AT = 'create_time';
|
||||
|
||||
protected $appends = [
|
||||
'to_user_phone',
|
||||
'from_user_phone',
|
||||
];
|
||||
public function getCreateTimeAttribute()
|
||||
{
|
||||
$value = $this->attributes['create_time'];
|
||||
return $value ? date('Y-m-d H:i:s', $value) : '';
|
||||
}
|
||||
|
||||
|
||||
public function toUser()
|
||||
{
|
||||
return $this->belongsTo('App\Users', 'to_user_id', 'id')->withDefault();
|
||||
}
|
||||
|
||||
public function fromUser()
|
||||
{
|
||||
return $this->belongsTo('App\Users', 'from_user_id', 'id')->withDefault();
|
||||
}
|
||||
public function getToUserPhoneAttribute()
|
||||
{
|
||||
return $this->toUser()->value('account_number');
|
||||
}
|
||||
|
||||
public function getFromUserPhoneAttribute()
|
||||
{
|
||||
return $this->fromUser()->value('account_number');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ChainHash extends Model
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: swl
|
||||
* Date: 2018/7/3
|
||||
* Time: 10:23
|
||||
*/
|
||||
|
||||
namespace App;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ChargeReq extends Model
|
||||
{
|
||||
protected $table = 'charge_req';
|
||||
public $timestamps = false;
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(Users::class, 'uid', 'id')->withDefault();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ChatLog extends Model
|
||||
{
|
||||
//
|
||||
protected $table = 'chat_log';
|
||||
|
||||
protected $appends = ['from_user_head'];
|
||||
|
||||
public function getFromUserHeadAttribute()
|
||||
{
|
||||
return $this->from_user()->value('head_portrait');
|
||||
}
|
||||
|
||||
public function from_user()
|
||||
{
|
||||
return $this->belongsTo(Users::class, 'from_user');
|
||||
}
|
||||
|
||||
public function to_user()
|
||||
{
|
||||
return $this->belongsTo(Users::class, 'to_user');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: YSX
|
||||
* Date: 2019/3/15
|
||||
* Time: 17:01
|
||||
*/
|
||||
namespace App\CoinDriver;
|
||||
|
||||
use App\AccountLog;
|
||||
use App\UsersWallet;
|
||||
use App\WalletLog;
|
||||
|
||||
class BTC extends Coin
|
||||
{
|
||||
|
||||
/**
|
||||
* 转账
|
||||
*
|
||||
* @param
|
||||
* $from_address
|
||||
* @param
|
||||
* $to_address
|
||||
* @param
|
||||
* $number
|
||||
* @param
|
||||
* $private_key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function transfer($from_address, $to_address, $number, $private_key)
|
||||
{
|
||||
// TODO: Implement transfer() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取余额
|
||||
*
|
||||
* @param
|
||||
* $address
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function balance($address)
|
||||
{
|
||||
// TODO: Implement balance() method.
|
||||
$api = 'http://43.129.16.120:82/wallet/btc/balance';
|
||||
|
||||
$response = $this->http($api, [
|
||||
'address' => $address
|
||||
]);
|
||||
|
||||
if ($response['errcode'] != 0) {
|
||||
exception('errorinfo');
|
||||
}
|
||||
$lessen = pow(10, $this->currency->decimal_scale);
|
||||
return $response['data']['balance'] / $lessen;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新钱包余额
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateBalance($wallet)
|
||||
{
|
||||
// TODO: Implement updateBalance() method.
|
||||
$this->canUpdateBalance($wallet);
|
||||
$balance = $this->balance($wallet->address);
|
||||
|
||||
if ($balance > $wallet->old_balance) {
|
||||
|
||||
$wallet->old_balance = $balance;
|
||||
$number = $balance - $wallet->old_balance;
|
||||
$wallet->save();
|
||||
|
||||
UsersWallet::changeBalance($wallet->user_id, $wallet->currency_id, $number, AccountLog::UPDATED_BALACNE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: YSX
|
||||
* Date: 2019/3/11
|
||||
* Time: 15:51
|
||||
*/
|
||||
namespace App\CoinDriver;
|
||||
|
||||
use App\Model\Currency;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
abstract class Coin
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Currency
|
||||
*/
|
||||
public $currency;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var
|
||||
*
|
||||
*/
|
||||
public $type;
|
||||
|
||||
public function __construct($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
$currency = Currency::where('type', $this->type)->first();
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账
|
||||
*
|
||||
* @param $from_address 转出地址
|
||||
* @param $to_address 转入地址
|
||||
* @param $number 数量
|
||||
* @param $private_key 转出钱包的私钥
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public abstract function transfer($from_address, $to_address, $number, $private_key);
|
||||
|
||||
/**
|
||||
* 获取余额
|
||||
*
|
||||
* @param
|
||||
* $address
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public abstract function balance($address);
|
||||
|
||||
/**
|
||||
* 更新钱包余额
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public abstract function updateBalance($wallet);
|
||||
|
||||
/**
|
||||
* 获取钱包余额
|
||||
*
|
||||
* @param
|
||||
* $user_id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getAddress($user_id)
|
||||
{}
|
||||
|
||||
/**
|
||||
* 判断能不能更新余额
|
||||
*
|
||||
* @param
|
||||
* $wallet
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function canUpdateBalance($wallet)
|
||||
{
|
||||
if ($wallet->gl_time > time() - 15 * 60) {
|
||||
exception('归拢时间内不能从链上监听余额');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取驱动
|
||||
*
|
||||
* @param
|
||||
* $type
|
||||
*
|
||||
* @return Coin
|
||||
*/
|
||||
public static function newInstance($type)
|
||||
{
|
||||
$type = strtoupper($type);
|
||||
$path = "App\CoinDriver\\{$type}";
|
||||
$instance = new $path($type);
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public function http($url, $data = null, $method = 'GET')
|
||||
{
|
||||
$query = strtoupper($method) == 'GET' ? $data : null;
|
||||
$body = strtoupper($method) == 'POST' ? $data : null;
|
||||
|
||||
$client = new Client();
|
||||
$response = $client->request($method, $url, [
|
||||
'query' => $query,
|
||||
'form_params' => $body
|
||||
])
|
||||
->getBody()
|
||||
->getContents();
|
||||
|
||||
return json_decode($response, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: YSX
|
||||
* Date: 2019/3/15
|
||||
* Time: 17:01
|
||||
*/
|
||||
namespace App\CoinDriver;
|
||||
|
||||
use App\AccountLog;
|
||||
use App\UsersWallet;
|
||||
|
||||
class EOS extends Coin
|
||||
{
|
||||
|
||||
/**
|
||||
* 转账
|
||||
*
|
||||
* @param
|
||||
* $from_address
|
||||
* @param
|
||||
* $to_address
|
||||
* @param
|
||||
* $number
|
||||
* @param
|
||||
* $private_key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function transfer($from_address, $to_address, $number, $private_key)
|
||||
{
|
||||
// TODO: Implement transfer() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取余额
|
||||
*
|
||||
* @param
|
||||
* $address
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function balance($address)
|
||||
{
|
||||
// TODO: Implement balance() method.
|
||||
// TODO: Implement balance() method.
|
||||
$api = 'http://43.129.16.120:82/wallet/eos/balance';
|
||||
|
||||
$response = $this->http($api, [
|
||||
'address' => $address
|
||||
]);
|
||||
|
||||
if ($response['errcode'] != 0) {
|
||||
exception('errorinfo');
|
||||
}
|
||||
$lessen = pow(10, $this->currency->decimal_scale);
|
||||
return $response['data']['balance'] / $lessen;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新钱包余额
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateBalance($wallet)
|
||||
{
|
||||
// TODO: Implement updateBalance() method.
|
||||
$this->canUpdateBalance($wallet);
|
||||
$balance = $this->balance($wallet->address);
|
||||
|
||||
if ($balance > $wallet->old_balance) {
|
||||
|
||||
$wallet->old_balance = $balance;
|
||||
$number = $balance - $wallet->old_balance;
|
||||
$wallet->save();
|
||||
|
||||
UsersWallet::changeBalance($wallet->user_id, $wallet->currency_id, $number, AccountLog::UPDATED_BALACNE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: YSX
|
||||
* Date: 2019/2/21
|
||||
* Time: 16:35
|
||||
*/
|
||||
namespace App\CoinDriver;
|
||||
|
||||
use App\Model\AccountLog;
|
||||
use App\Model\UserWallet;
|
||||
|
||||
class ETH extends Coin
|
||||
{
|
||||
|
||||
protected $api = '';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param
|
||||
* $address
|
||||
*
|
||||
* @return float|int|mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function balance($address)
|
||||
{
|
||||
$api = 'http://43.129.16.120:82/wallet/eth/balance';
|
||||
|
||||
$response = $this->http($api, [
|
||||
'address' => $address
|
||||
]);
|
||||
|
||||
if ($response['errcode'] != 0) {
|
||||
exception('errorinfo');
|
||||
}
|
||||
$lessen = pow(10, $this->currency->decimal_scale);
|
||||
return $response['data']['balance'] / $lessen;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新钱包余额
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function updateBalance($wallet)
|
||||
{
|
||||
$this->canUpdateBalance($wallet);
|
||||
$balance = $this->balance($wallet->address);
|
||||
|
||||
if ($balance > $wallet->old_balance) {
|
||||
|
||||
$wallet->old_balance = $balance;
|
||||
$number = $balance - $wallet->old_balance;
|
||||
$wallet->save();
|
||||
|
||||
UserWallet::changeBalance($wallet->user_id, $wallet->currency_id, $number, AccountLog::UPDATED_BALACNE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账
|
||||
*
|
||||
* @param
|
||||
* $from_address
|
||||
* @param
|
||||
* $to_address
|
||||
* @param
|
||||
* $number
|
||||
* @param
|
||||
* $private_key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function transfer($from_address, $to_address, $number, $private_key)
|
||||
{
|
||||
// TODO: Implement transfer() method.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CoinTrade extends Model
|
||||
{
|
||||
public $table = 'coin_trade';
|
||||
const TRADE_TYPE_SELL = 2;
|
||||
const TRADE_TYPE_BUY = 1;
|
||||
public static function newTrade($userId,$type,$currencyId,$legalId,$amount,$tradePrice,$targetPrice){
|
||||
$fee = Setting::getValueByKey('COIN_TRADE_FEE');
|
||||
$tmp = new self();
|
||||
$tmp->num = time().$userId;
|
||||
$tmp->u_id = $userId;
|
||||
$tmp->currency_id = $currencyId;
|
||||
$tmp->legal_id = $legalId;
|
||||
$tmp->type = $type;
|
||||
$tmp->target_price = $targetPrice;
|
||||
$tmp->trade_price = $tradePrice;
|
||||
$tmp->trade_amount = $amount;
|
||||
$tmp->charge_fee = $fee;
|
||||
$tmp->save();
|
||||
return $tmp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
Commands\LHDisptchInterest::class,
|
||||
Commands\Locking::class,
|
||||
Commands\BonusAlgorithm::class,
|
||||
Commands\MonitorEthLog::class,
|
||||
Commands\HistoricalDatas::class,
|
||||
Commands\AutoCancelLegal::class,
|
||||
Commands\UpdateBalance::class,
|
||||
Commands\MakeOneWallet::class,
|
||||
//Commands\UpdateSortNum::class,
|
||||
Commands\AutoCancelC2C::class,
|
||||
Commands\AutoCancelC2CDeal::class,
|
||||
Commands\ReturnProfit::class,
|
||||
Commands\CancelC2ctime::class,
|
||||
Commands\OvernightFee::class,
|
||||
Commands\UserLevel::class,
|
||||
Commands\UpdateFund::class,
|
||||
Commands\Test::class,
|
||||
Commands\RemoveQueue::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
$schedule->command('follow')->everyMinute()->withoutOverlapping(); //处理跟随者 跟单逻辑
|
||||
$schedule->command('remove_queue')->hourly()->withoutOverlapping(); //移除积压
|
||||
$schedule->command('lhdispatch_interest')->dailyAt('00:01')->appendOutputTo('./storage/logs/lhdispatch_interest.log'); // 锁仓派息
|
||||
$schedule->command('auto_option_settle')->everyMinute()->withoutOverlapping()->appendOutputTo('./storage/logs/auto_option_settle.log'); // 期权自动结算
|
||||
$schedule->command('auto_credit_overdue')->hourly()->withoutOverlapping(); // 信用IEO逾期标记
|
||||
|
||||
/**
|
||||
$schedule->command('update_hash_status')->everyMinute()->withoutOverlapping(); //更新哈希值状态
|
||||
$schedule->command('lever:overnight')->dailyAt('00:01')->appendOutputTo('./storage/logs/lever_overnight.log'); //收取隔夜费
|
||||
$schedule->command('update_user_fund')->daily()->appendOutputTo('./storage/logs/update_user_fund.log'); //更新期权资产
|
||||
// $schedule->command('update_user_level')->dailyAt('01:00')->appendOutputTo('./storage/logs/update_user_level.log'); //
|
||||
// $schedule->command('return:profit')->dailyAt('00:10')->appendOutputTo('./storage/logs/return_profit.log'); //历史盈亏释放 add by tian
|
||||
$schedule->command('cancel:c2cdeal')->everyMinute()->appendOutputTo('./storage/logs/cancel_c2cdeal.log'); //c2c取消订单倒计时执行 add by tian
|
||||
$schedule->command('auto_cancel_legal')->hourly()->appendOutputTo('./storage/logs/auto_cancel_legal.log');
|
||||
// $schedule->command('update_balance')->everyTenMinutes()->withoutOverlapping()->appendOutputTo('./storage/logs/update_balance.log');
|
||||
|
||||
$schedule->command('insurance_money')->dailyAt('00:01')->appendOutputTo('./storage/logs/insurance_money.log'); //持币生息
|
||||
$schedule->command('return_service_charge')->dailyAt('00:02')->appendOutputTo('./storage/logs/return_service_charge.log'); //返还保险交易手续费
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__ . '/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Conversion extends Model
|
||||
{
|
||||
protected $table = 'conversion';
|
||||
public $timestamps = false;
|
||||
protected $appends = ['mobile','form_currency','to_currency'];
|
||||
|
||||
public function getMobileAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Users', 'id', 'user_id')->value('account_number');
|
||||
}
|
||||
public function getFormCurrencyAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Currency', 'id', 'form_currency_id')->value('name');
|
||||
}
|
||||
public function getToCurrencyAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Currency', 'id', 'to_currency_id')->value('name');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getCreateTimeAttribute()
|
||||
{
|
||||
return date('Y-m-d H:i:s', $this->attributes['create_time']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Users;
|
||||
class CurrencyApplication extends Model
|
||||
{
|
||||
protected $table = 'currency_application';
|
||||
public $timestamps = false;
|
||||
protected $appends = ['account_number'];
|
||||
|
||||
public function getCreateTimeAttribute()
|
||||
{
|
||||
return date('Y-m-d H:i:s', $this->attributes['create_time']);
|
||||
}
|
||||
public function getReplyTimeAttribute()
|
||||
{
|
||||
if($this->attributes['reply_time']){
|
||||
return date('Y-m-d H:i:s', $this->attributes['reply_time']);
|
||||
}
|
||||
|
||||
}
|
||||
public static function getNameById($currency_id)
|
||||
{
|
||||
$currency = self::find($currency_id);
|
||||
return $currency->name;
|
||||
}
|
||||
public function getAccountNumberAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Users', 'id', 'user_id')->value('account_number');
|
||||
}
|
||||
// public function getImgAttribute($value)
|
||||
// {
|
||||
// return unserialize($value);
|
||||
// }
|
||||
|
||||
// public function setImgAttribute($value)
|
||||
// {
|
||||
// if (empty($value)) {
|
||||
// $this->attributes['discuss_img'] = "0";
|
||||
// } else {
|
||||
// $this->attributes['discuss_img'] = serialize($value);
|
||||
// }
|
||||
|
||||
// }
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Users', 'user_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\BaseModel;
|
||||
class CurrencyClass extends BaseModel
|
||||
{
|
||||
protected $table = "currency_class";
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\BaseModel;
|
||||
class CurrencyContact extends BaseModel
|
||||
{
|
||||
protected $table = "currency_contact";
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CurrencyDepositOrder extends Model
|
||||
{
|
||||
public $table = 'currency_deposit_order';
|
||||
public $appends = [
|
||||
'currency_name' ,
|
||||
'currency_logo',
|
||||
'output_currency_name',
|
||||
'output_currency_logo',
|
||||
'total_output'
|
||||
];
|
||||
|
||||
public function getCurrencyNameAttribute(){
|
||||
// $id = $this->attributes['currency_id'];
|
||||
return $this->currencyCoin()->value('name');
|
||||
}
|
||||
public function getCurrencyLogoAttribute(){
|
||||
// $id = $this->attributes['currency_id'];
|
||||
return $this->currencyCoin()->value('logo');
|
||||
}
|
||||
public function getOutputCurrencyLogoAttribute(){
|
||||
// $id = $this->attributes['currency_id'];
|
||||
return $this->outputCurrencyCoin()->value('logo');
|
||||
}
|
||||
public function getOutputCurrencyNameAttribute(){
|
||||
return $this->outputCurrencyCoin()->value('name');
|
||||
}
|
||||
public function currencyCoin()
|
||||
{
|
||||
return $this->belongsTo(Currency::class, 'currency_id', 'id');
|
||||
}
|
||||
public function outputCurrencyCoin()
|
||||
{
|
||||
return $this->belongsTo(Currency::class, 'output_currency_id', 'id');
|
||||
}
|
||||
public static function dispatchInterest($orderId){
|
||||
$model = self::find($orderId);
|
||||
if(!$model){
|
||||
return false;
|
||||
}
|
||||
$legal = UsersWallet::where("user_id", $model->u_id)
|
||||
->where("currency", $model->currency_id)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
//先判断上次派息时间是否存在 不存在从开始时间派息
|
||||
$startDay = $model->last_settle_time?date("Y-m-d",strtotime($model->last_settle_time)):$model->start_at;
|
||||
$endDay = date("Y-m-d",strtotime('-1 day'));
|
||||
if($model->last_settle_time >= date("Y-m-d")){
|
||||
return false;
|
||||
}
|
||||
//结息时间异常时
|
||||
if($startDay > $endDay){
|
||||
//不需要结息
|
||||
return false;
|
||||
}
|
||||
//当有结息时间时 且结息时间和开始时间相同 直接返回
|
||||
// if($startDay == $endDay && $model->last_settle_time){
|
||||
// return false;
|
||||
// }
|
||||
|
||||
//计算需要派息的天数
|
||||
$d1=strtotime($startDay);
|
||||
$d2=strtotime($endDay);
|
||||
$dayCount=round(($d2-$d1)/3600/24);
|
||||
$totalInterest = 0;
|
||||
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
for($i=0;$i<=$dayCount;$i++){
|
||||
//执行结息操作
|
||||
//1先加钱
|
||||
$day = date("Y-m-d",strtotime("+$i day",strtotime($startDay)));
|
||||
|
||||
$interest = bc_mul($model->amount ,$model->day_rate/100,8);
|
||||
$totalInterest = bc_add($totalInterest,$interest);
|
||||
//写入结息的log
|
||||
// LhDepositOrderLog::newLog($model->bank_account_id,$model->id,$interest,$day);
|
||||
}
|
||||
//更新订单利息
|
||||
$model->total_interest += $totalInterest;
|
||||
$model->last_settle_time = date("Y-m-d");
|
||||
//写入结息的log
|
||||
DB::table('currency_deposit_order_log')->insert([
|
||||
'amount' => $totalInterest,
|
||||
'currency_id' => $model->currency_id,
|
||||
'order_id' => $model->id,
|
||||
'user_id' => $model->user_id
|
||||
]);
|
||||
// change_wallet_balance(
|
||||
// $legal,
|
||||
// 2,
|
||||
// $totalInterest,
|
||||
// AccountLog::LH_LOAN,
|
||||
// '质押利息',
|
||||
// false,
|
||||
// 0,
|
||||
// 0,
|
||||
// serialize([])
|
||||
// );
|
||||
//最后一天 退钱
|
||||
if($model->end_at == date('Y-m-d')){
|
||||
//结单 退钱操作
|
||||
change_wallet_balance(
|
||||
$legal,
|
||||
2,
|
||||
$model->amount,
|
||||
AccountLog::LH_LOAN,
|
||||
'质押返还',
|
||||
false,
|
||||
0,
|
||||
0,
|
||||
serialize([])
|
||||
);
|
||||
$model->status = 2;
|
||||
}
|
||||
$model->save();
|
||||
DB::commit();
|
||||
}catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
throw $e;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getTotalOutputAttribute(){
|
||||
|
||||
$amount = $this->amount*(100+$this->total_rate)/100;
|
||||
//获取交易币汇率
|
||||
if($this->output_currency_id == $this->currency_id){
|
||||
$rate = 1;
|
||||
}else{
|
||||
if($this->currency_id == 3){
|
||||
$payPrice = 1;
|
||||
}else{
|
||||
$payPrice = CurrencyQuotation::where('legal_id',3)->where('currency_id',$this->currency_id)->value('now_price');
|
||||
}
|
||||
|
||||
if($this->output_currency_id == 3){
|
||||
$outPrice = 1;
|
||||
}else{
|
||||
$outPrice = CurrencyQuotation::where('legal_id',3)->where('currency_id',$this->output_currency_id)->value('now_price');
|
||||
}
|
||||
$rate = $payPrice/$outPrice;
|
||||
}
|
||||
return $amount *= $rate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
class CurrencyMatch extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
protected $appends = ["legal_name", "currency_name", "market_from_name", "type", "is_class", "change", "volume", "now_price", "rmb_relation", "logo", "category_text", "content", "issue_num", "sell_status","real_name"];
|
||||
public function getSellStatusAttribute()
|
||||
{
|
||||
return $this->currency()->value("sell_status");
|
||||
}
|
||||
|
||||
public function getRealNameAttribute()
|
||||
{
|
||||
return $this->currency()->value("real_name");
|
||||
}
|
||||
public function getIssueNumAttribute()
|
||||
{
|
||||
return $this->currency()->value("issue_num");
|
||||
}
|
||||
|
||||
public function getTypeAttribute()
|
||||
{
|
||||
return $this->currency()->value("type");
|
||||
}
|
||||
|
||||
public function getIsClassAttribute()
|
||||
{
|
||||
return $this->currency()->value("is_class");
|
||||
}
|
||||
public function getContentAttribute()
|
||||
{
|
||||
return $this->currency()->value("content");
|
||||
}
|
||||
public function getRmbRelationAttribute()
|
||||
{
|
||||
return $this->currency()->value("rmb_relation");
|
||||
}
|
||||
protected static $marketFromNames = ["无", "交易所", "A股", "B股", "港股", "NASDA", "股票", "币安", "欧易", "ETF", "H股"];
|
||||
protected function getLogoAttribute()
|
||||
{
|
||||
return $this->currency()->value("logo");
|
||||
}
|
||||
protected function getCategoryTextAttribute()
|
||||
{
|
||||
switch ($this->attributes["category"]) {
|
||||
case 1:
|
||||
return "主流区";
|
||||
break;
|
||||
case 2:
|
||||
return "创新区";
|
||||
break;
|
||||
default:
|
||||
return "未知区";
|
||||
}
|
||||
}
|
||||
public function legal()
|
||||
{
|
||||
return $this->belongsTo(Currency::class, "legal_id", "id")->withDefault();
|
||||
}
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo(Currency::class, "currency_id", "id")->withDefault();
|
||||
}
|
||||
public static function enumMarketFromNames()
|
||||
{
|
||||
return self::$marketFromNames;
|
||||
}
|
||||
public function getSymbolAttribute()
|
||||
{
|
||||
return $this->getCurrencyNameAttribute() . "/" . $this->getLegalNameAttribute();
|
||||
}
|
||||
public function getMatchNameAttribute()
|
||||
{
|
||||
return strtolower($this->getCurrencyNameAttribute() . $this->getLegalNameAttribute());
|
||||
}
|
||||
public function getLegalNameAttribute()
|
||||
{
|
||||
return $this->legal()->value("name");
|
||||
}
|
||||
public function getCurrencyNameAttribute()
|
||||
{
|
||||
return $this->currency()->value("name");
|
||||
}
|
||||
public function getMarketFromNameAttribute($value)
|
||||
{
|
||||
return self::$marketFromNames[$this->attributes["market_from"]];
|
||||
}
|
||||
public function getCreateTimeAttribute($value)
|
||||
{
|
||||
return $value === null ? "" : date("Y-m-d H:i:s", $value);
|
||||
}
|
||||
public function getDaymarketAttribute()
|
||||
{
|
||||
$JZCwucJ = $this->attributes["legal_id"];
|
||||
$PslPuOv = $this->attributes["currency_id"];
|
||||
CurrencyQuotation::unguard();
|
||||
$NiSCQSJ = CurrencyQuotation::firstOrCreate(["legal_id" => $JZCwucJ, "currency_id" => $PslPuOv], ["match_id" => $this->attributes["id"], "change" => "", "volume" => 0, "now_price" => 0, "add_time" => time()]);
|
||||
CurrencyQuotation::reguard();
|
||||
return $NiSCQSJ;
|
||||
}
|
||||
public function getChangeAttribute()
|
||||
{
|
||||
return $this->getDaymarketAttribute()->change;
|
||||
}
|
||||
public function getVolumeAttribute()
|
||||
{
|
||||
return $this->getDaymarketAttribute()->volume;
|
||||
}
|
||||
public function getNowPriceAttribute()
|
||||
{
|
||||
return $this->getDaymarketAttribute()->now_price;
|
||||
}
|
||||
public function quotation()
|
||||
{
|
||||
return $this->hasOne("App\\CurrencyQuotation", "legal_id", "legal_id");
|
||||
}
|
||||
public static function getHuobiMatchs()
|
||||
{
|
||||
$qBXDpPQ = self::with(["legal", "currency"])->where("market_from", 2)->get();
|
||||
$huobi_symbols = HuobiSymbol::pluck("symbol")->all();
|
||||
$qBXDpPQ->transform(function ($item, $key) {
|
||||
$item->addHidden("currency");
|
||||
$item->addHidden("legal");
|
||||
$item->append("match_name");
|
||||
return $item;
|
||||
});
|
||||
$qBXDpPQ = $qBXDpPQ->filter(function ($value, $key) use($huobi_symbols) {
|
||||
return in_array($value->match_name, $huobi_symbols);
|
||||
});
|
||||
return $qBXDpPQ;
|
||||
}
|
||||
|
||||
public static function forward()
|
||||
{
|
||||
$currency_match = self::with(['legal', 'currency'])
|
||||
->where('market_from', 3)
|
||||
->get();
|
||||
$currency_match->transform(function ($item, $key) {
|
||||
$item->addHidden('currency');
|
||||
$item->addHidden('legal');
|
||||
$item->append('match_name');
|
||||
return $item;
|
||||
});
|
||||
return $currency_match;
|
||||
}
|
||||
|
||||
|
||||
public static function forward_etf()
|
||||
{
|
||||
$info = DB::table('currency_matches')->where('market_from',9)->paginate(100);
|
||||
$info = json_encode($info);
|
||||
$info = json_decode($info,true);
|
||||
$info = $info['data'][rand(0,count($info['data'])-1)];
|
||||
|
||||
$currency_quotation = DB::table('currency_quotation')->where('currency_id',$info['currency_id'])->first();
|
||||
$currency_quotation = json_encode($currency_quotation);
|
||||
$currency_quotation = json_decode($currency_quotation,true);
|
||||
|
||||
$currency = DB::table('currency')->where('id',$info['currency_id'])->first();
|
||||
$currency = json_encode($currency);
|
||||
$currency = json_decode($currency,true);
|
||||
$data['match_id'] = $info['id'];//交易对id
|
||||
$data['currency_id'] = $info['currency_id'];//币id
|
||||
$data['open'] = $currency_quotation['open'];//开
|
||||
$data['close'] = $currency_quotation['now_price'];
|
||||
$data['high'] = $currency_quotation['high'];
|
||||
$data['low'] = $currency_quotation['low'];
|
||||
$data['name'] = $currency['name'];
|
||||
$data['volume'] = $currency_quotation['volume'];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static function forward_gp()
|
||||
{
|
||||
$info = DB::table('currency_matches')->where('market_from',6)->paginate(100);
|
||||
$info = json_encode($info);
|
||||
$info = json_decode($info,true);
|
||||
$info = $info['data'][rand(0,count($info['data'])-1)];
|
||||
|
||||
$currency_quotation = DB::table('currency_quotation')->where('currency_id',$info['currency_id'])->first();
|
||||
$currency_quotation = json_encode($currency_quotation);
|
||||
$currency_quotation = json_decode($currency_quotation,true);
|
||||
|
||||
$currency = DB::table('currency')->where('id',$info['currency_id'])->first();
|
||||
$currency = json_encode($currency);
|
||||
$currency = json_decode($currency,true);
|
||||
$data['match_id'] = $info['id'];//交易对id
|
||||
$data['currency_id'] = $info['currency_id'];//币id
|
||||
$data['open'] = $currency_quotation['open'];//开
|
||||
$data['close'] = $currency_quotation['now_price'];
|
||||
$data['high'] = $currency_quotation['high'];
|
||||
$data['low'] = $currency_quotation['low'];
|
||||
$data['name'] = $currency['name'];
|
||||
$data['volume'] = $currency_quotation['volume'];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function forward_sj()
|
||||
{
|
||||
$info = DB::table('currency_matches')->where('market_from',3)->paginate(100);
|
||||
$info = json_encode($info);
|
||||
$info = json_decode($info,true);
|
||||
$info = $info['data'][rand(0,count($info['data'])-1)];
|
||||
|
||||
$currency_quotation = DB::table('currency_quotation')->where('currency_id',$info['currency_id'])->first();
|
||||
$currency_quotation = json_encode($currency_quotation);
|
||||
$currency_quotation = json_decode($currency_quotation,true);
|
||||
|
||||
$currency = DB::table('currency')->where('id',$info['currency_id'])->first();
|
||||
$currency = json_encode($currency);
|
||||
$currency = json_decode($currency,true);
|
||||
$data['match_id'] = $info['id'];//交易对id
|
||||
$data['currency_id'] = $info['currency_id'];//币id
|
||||
$data['open'] = $currency_quotation['open'];//开
|
||||
$data['close'] = $currency_quotation['now_price'];
|
||||
$data['high'] = $currency_quotation['high'];
|
||||
$data['low'] = $currency_quotation['low'];
|
||||
$data['name'] = $currency['name'];
|
||||
$data['volume'] = $currency_quotation['volume'];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function foreign_sj()
|
||||
{
|
||||
$info = DB::table('currency_matches')->where('market_from',0)->paginate(100);
|
||||
$info = json_encode($info);
|
||||
$info = json_decode($info,true);
|
||||
$info = $info['data'][rand(0,count($info['data'])-1)];
|
||||
|
||||
$currency_quotation = DB::table('currency_quotation')->where('currency_id',$info['currency_id'])->first();
|
||||
$currency_quotation = json_encode($currency_quotation);
|
||||
$currency_quotation = json_decode($currency_quotation,true);
|
||||
|
||||
$currency = DB::table('currency')->where('id',$info['currency_id'])->first();
|
||||
$currency = json_encode($currency);
|
||||
$currency = json_decode($currency,true);
|
||||
$data['match_id'] = $info['id'];//交易对id
|
||||
$data['currency_id'] = $info['currency_id'];//币id
|
||||
$data['open'] = $currency_quotation['open'];//开
|
||||
$data['close'] = $currency_quotation['now_price'];
|
||||
$data['high'] = $currency_quotation['high'];
|
||||
$data['low'] = $currency_quotation['low'];
|
||||
$data['name'] = $currency['name'];
|
||||
$data['volume'] = $currency_quotation['volume'];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function getRiskGroupResultNameAttribute()
|
||||
{
|
||||
$wrVJFiQ = [-1 => "亏损", 0 => "无", 1 => "盈利"];
|
||||
$pklTcwv = $this->attributes["risk_group_result"] ?? 0;
|
||||
return $wrVJFiQ[$pklTcwv];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CurrencyProject extends Model
|
||||
{
|
||||
public $table = 'currency_project';
|
||||
protected $appends = [
|
||||
'time_status',
|
||||
'currency_name',
|
||||
'pay_currency_name'
|
||||
];
|
||||
public function getCurrencyNameAttribute(){
|
||||
$currency_id = $this->attributes['currency_id'];
|
||||
return Currency::find($currency_id)->name;
|
||||
}
|
||||
public function getPayCurrencyNameAttribute(){
|
||||
$currency_id = $this->attributes['pay_currency_id'];
|
||||
return Currency::find($currency_id)->name;
|
||||
}
|
||||
public function getTimeStatusAttribute(){
|
||||
$start_at = $this->attributes['start_at'];
|
||||
$end_at = $this->attributes['end_at'];
|
||||
|
||||
|
||||
if(time()<strtotime($start_at)){
|
||||
return 1;
|
||||
}elseif(time()<strtotime($end_at)){
|
||||
return 2;
|
||||
}else{
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CurrencyProjectOrder extends Model
|
||||
{
|
||||
public $table = 'currency_project_order';
|
||||
|
||||
protected $appends = [
|
||||
'type_text',
|
||||
'status_text',
|
||||
];
|
||||
public function getTypeTextAttribute() {
|
||||
$value = $this->attributes['type'];
|
||||
$arr = [1=>'认购',2=>'抽签'];
|
||||
|
||||
return @$arr[$value];
|
||||
}
|
||||
public function getStatusTextAttribute() {
|
||||
$value = $this->attributes['status'];
|
||||
$arr = [1=>'已申请',2=>'已扣费',3=>'已完成'];
|
||||
|
||||
return @$arr[$value];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CurrencyQuotation extends Model
|
||||
{
|
||||
protected $table = 'currency_quotation';
|
||||
public $timestamps = false;
|
||||
protected $appends = [
|
||||
'currency_name',
|
||||
'legal_name',
|
||||
'rmb_relation'
|
||||
];
|
||||
|
||||
public function getRmbRelationAttribute()
|
||||
{
|
||||
return $this->currency()->value('rmb_relation');
|
||||
}
|
||||
public function updateData($data)
|
||||
{
|
||||
self::unguard();
|
||||
$result = $this->fill($data)->save();
|
||||
self::reguard();
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getInstance($legal_id, $currency_id)
|
||||
{
|
||||
$quotation = self::where('legal_id', $legal_id)
|
||||
->where('currency_id', $currency_id)
|
||||
->first();
|
||||
if (!$quotation) {
|
||||
$currency_match = CurrencyMatch::where('legal_id', $legal_id)
|
||||
->where('currency_id', $currency_id)
|
||||
->first();
|
||||
$quotation = new self();
|
||||
$quotation->match_id = $currency_match->id ?? 0;
|
||||
$quotation->legal_id = $legal_id;
|
||||
$quotation->currency_id = $currency_id;
|
||||
$quotation->change = '';
|
||||
$quotation->volume = 0;
|
||||
$quotation->now_price = 0;
|
||||
}
|
||||
$quotation->add_time = time();
|
||||
$result = $quotation->save();
|
||||
return $quotation;
|
||||
}
|
||||
|
||||
public static function updateTodayPriceTable($data)
|
||||
{
|
||||
|
||||
$quotation = self::getInstance($data['legal_id'], $data['currency_id']);
|
||||
if (!isset($data['change'])) {
|
||||
//获得开盘价
|
||||
$open_price = TransactionComplete::getOpenPrice($data['currency_id'], $data['legal_id']);
|
||||
//计算涨跌百分比
|
||||
$change_ratio = bc_mul(bc_div(bc_sub($data['now_price'], $open_price), $open_price), 100, 4);
|
||||
if (bc_comp($change_ratio, 0) > 0) {
|
||||
$change_ratio = '+' . $change_ratio;
|
||||
}
|
||||
$data['change'] = $change_ratio;
|
||||
}
|
||||
$result = $quotation->updateData($data);
|
||||
|
||||
$quotation->setAttribute('type', 'daymarket');
|
||||
$quotation->addHidden('id');
|
||||
//推送数据
|
||||
$send_data = $quotation->toArray();
|
||||
UserChat::sendChat($send_data);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo('App\Currency', 'currency_id', 'id')->withDefault();
|
||||
}
|
||||
|
||||
public function legal()
|
||||
{
|
||||
return $this->belongsTo('App\Currency', 'legal_id', 'id')->withDefault();
|
||||
}
|
||||
|
||||
public function getCurrencyNameAttribute()
|
||||
{
|
||||
return $this->currency()->value('name');
|
||||
}
|
||||
|
||||
public function getLegalNameAttribute()
|
||||
{
|
||||
return $this->legal()->value('name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,474 @@
|
||||
<?php
|
||||
|
||||
namespace App\DAO;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use App\AccountLog;
|
||||
use App\Currency;
|
||||
use App\ChainHash;
|
||||
use App\LbxHash;
|
||||
use App\UsersWallet;
|
||||
use App\Jobs\UpdateBalance;
|
||||
class BlockChain
|
||||
{
|
||||
|
||||
public static function getChainBalance($wallet, $chain_currency = '')
|
||||
{
|
||||
try {
|
||||
throw_unless($wallet, new \Exception('钱包不存在'));
|
||||
throw_if(empty($wallet->address), new \Exception('钱包地址不存在'));
|
||||
$currency = Currency::find($wallet->currency);
|
||||
throw_unless($currency, new \Exception('币种不存在'));
|
||||
$address = $wallet->address;
|
||||
$method = 'GET';
|
||||
$chain_currency == '' && $chain_currency = $currency->type;
|
||||
switch ($chain_currency) {
|
||||
case 'eth':
|
||||
$uri = '/wallet/eth/balance';
|
||||
$params = [
|
||||
'query' => [
|
||||
'address' => $address,
|
||||
]
|
||||
];
|
||||
break;
|
||||
case 'erc20':
|
||||
$uri = '/wallet/eth/tokenbalance';
|
||||
$params = [
|
||||
'query' => [
|
||||
'address' => $address,
|
||||
'tokenaddress' => $currency->contract_address,
|
||||
]
|
||||
];
|
||||
break;
|
||||
case 'btc':
|
||||
$uri = '/wallet/btc/balance';
|
||||
$params = [
|
||||
'query' => [
|
||||
'address' => $address,
|
||||
]
|
||||
];
|
||||
break;
|
||||
case 'usdt':
|
||||
$uri = '/wallet/usdt/balance';
|
||||
$params = [
|
||||
'query' => [
|
||||
'address' => $address,
|
||||
]
|
||||
];
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('不支持的数字货币');
|
||||
break;
|
||||
}
|
||||
$http_client = app('LbxChainServer');
|
||||
$response = $http_client->request($method, $uri, $params);
|
||||
$result = $response->getBody()->getContents();
|
||||
$result = json_decode($result, true);
|
||||
//echo $uri;
|
||||
//var_dump($params);
|
||||
//var_dump($result);
|
||||
if (!isset($result['code']) || !isset($result['data'])) {
|
||||
throw new \Exception('请求接口发生错误');
|
||||
}
|
||||
if ($result['code'] != 0) {
|
||||
throw new \Exception($result['msg'] ?? $result['errorinfo']);
|
||||
}
|
||||
$balance_data = $result['data'];
|
||||
$chain_balance = $balance_data['balance'];
|
||||
$lessen = bc_pow(10, $currency->decimal_scale);
|
||||
$fact_chain_balance = bc_div($chain_balance, $lessen);
|
||||
return $fact_chain_balance;
|
||||
} catch (\Throwable $th) {
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateWalletBalance($wallet, $no_balance_continue = false)
|
||||
{
|
||||
try {
|
||||
$fact_chain_balance = self::getChainBalance($wallet);
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$wallet->refresh();
|
||||
//比较现链上余额是否比原链上余额要大
|
||||
$compare_result = bc_comp($fact_chain_balance, $wallet->old_balance);
|
||||
if ($compare_result > 0) {
|
||||
$diff_balance = bc_sub($fact_chain_balance, $wallet->old_balance);
|
||||
$wallet->old_balance = $fact_chain_balance; //更新链上余额
|
||||
$save_result = $wallet->save();
|
||||
if (!$save_result) {
|
||||
throw new \Exception('更新链上余额失败');
|
||||
}
|
||||
$change_result = change_wallet_balance($wallet, 4, $diff_balance, AccountLog::ETH_EXCHANGE, '链上充币增加');
|
||||
if ($change_result !== true) {
|
||||
throw new \Exception($change_result);
|
||||
}
|
||||
} elseif ($compare_result == 0) {
|
||||
// throw new \Exception(
|
||||
// '用户id:' . $wallet->user_id . ',币种:' . $wallet->currencyCoin->name
|
||||
// . '(' . $wallet->currencyCoin->type . '):链上余额无增加'
|
||||
// );
|
||||
if ($no_balance_continue) {
|
||||
UpdateBalance::dispatch($wallet, false)
|
||||
->onQueue('update:block:balance')
|
||||
->delay(Carbon::now()->addMinutes(5));
|
||||
}
|
||||
} else {
|
||||
|
||||
if ($no_balance_continue) {
|
||||
UpdateBalance::dispatch($wallet, false)
|
||||
->onQueue('update:block:balance')
|
||||
->delay(Carbon::now()->addMinutes(5));
|
||||
}
|
||||
throw new \Exception(
|
||||
'用户id:' . $wallet->user_id . ',币种:' . $wallet->currencyCoin->name
|
||||
. '(' . $wallet->currencyCoin->type . '):链上余额小于系统链上余额'
|
||||
);
|
||||
}
|
||||
DB::commit();
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
return true;
|
||||
} catch (\Throwable $th) {
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 链上转账
|
||||
*
|
||||
* @param string $currency_name 钱包本身对应的币种名称
|
||||
* @param string $chain_currency 要转的链上币种类型,例如用usdt的钱包地址不仅可以转USDT还可以转BTC,用erc20的钱包地址不仅可以转ERC20代币还可以转ETH
|
||||
* @param string $to_address 转入地址
|
||||
* @param float $transfer_qty 转账数量
|
||||
* @param string $from_address 转出地址
|
||||
* @param string $from_private_key 转出私钥
|
||||
* @param integer $type 转账类型 1 归拢,2 打入手续费,3 提币
|
||||
* @param float $fee 链上手续费
|
||||
* @param string $verificationcode 验证码
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function transfer($currency_name, $chain_currency, $to_address, $transfer_qty, $from_address, $from_private_key, $type, $fee = 0, $verificationcode = '')
|
||||
{
|
||||
try {
|
||||
$currency = Currency::where('name', $currency_name)->first();
|
||||
$chain_currency = Currency::where('name', $chain_currency)->first();
|
||||
if (!$currency) {
|
||||
throw new \Exception('货币不存在');
|
||||
}
|
||||
if (!in_array($currency->type, ['eth', 'erc20', 'usdt', 'btc'])) {
|
||||
throw new \Exception('货币类型不支持');
|
||||
}
|
||||
if (
|
||||
empty($to_address)
|
||||
|| empty($transfer_qty)
|
||||
|| bc_comp($transfer_qty, 0) <= 0
|
||||
|| empty($from_address)
|
||||
|| empty($from_private_key)
|
||||
) {
|
||||
throw new \Exception('参数不完整或不合法');
|
||||
}
|
||||
$origin_transfer_qty = $transfer_qty;
|
||||
$decimal_scale = $chain_currency->decimal_scale ?? 0; //调整为按链上通道的小数位数,解决代币和主链小数位数不一致的问题
|
||||
$lessen = bc_pow(10, $decimal_scale);
|
||||
$transfer_qty = bc_mul($transfer_qty, $lessen, 0); //转账数量转换为区块链上的单位
|
||||
$fee = bc_mul($currency->chain_fee, $lessen, 0); //手续费转换为区域链上的单位
|
||||
$http_client = app('LbxChainServer');
|
||||
$method = 'POST';
|
||||
$result = [];
|
||||
$params = [
|
||||
'multipart' => [
|
||||
[
|
||||
'name' => 'type',
|
||||
'contents' => $type,
|
||||
],
|
||||
[
|
||||
'name' => 'fromaddress',
|
||||
'contents' => $from_address,
|
||||
],
|
||||
[
|
||||
'name' => 'privkey',
|
||||
'contents' => $from_private_key,
|
||||
],
|
||||
[
|
||||
'name' => 'toaddress',
|
||||
'contents' => $to_address,
|
||||
],
|
||||
[
|
||||
'name' => 'amount',
|
||||
'contents' => $transfer_qty,
|
||||
],
|
||||
[
|
||||
'name' => 'tokenaddress',
|
||||
'contents' => $currency->contract_address ?? '',
|
||||
],
|
||||
[
|
||||
'name' => 'fee',
|
||||
'contents' => $fee,
|
||||
],
|
||||
[
|
||||
'name' => 'verificationcode',
|
||||
'contents' => $verificationcode,
|
||||
],
|
||||
]
|
||||
];
|
||||
switch ($chain_currency->type) {
|
||||
case 'erc20':
|
||||
$uri = '/v3/wallet/eth/tokensendto';
|
||||
break;
|
||||
case 'eth':
|
||||
$uri = '/v3/wallet/eth/sendto';
|
||||
break;
|
||||
case 'btc':
|
||||
$uri = '/v3/wallet/btc/sendto';
|
||||
break;
|
||||
case 'usdt':
|
||||
$uri = '/v3/wallet/usdt/sendto';
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('暂不支持' . $chain_currency->type . '币种');
|
||||
break;
|
||||
}
|
||||
|
||||
$response = $http_client->request($method, $uri, $params);
|
||||
$result = json_decode($response->getBody()->getContents(), true);
|
||||
isset($result['txid']) || $result['txid'] = $result['data']['txHex'] ?? ($result['data']['txid'] ?? '');
|
||||
if (isset($result['code']) && $result['code'] == 0) {
|
||||
$chain_hash = [
|
||||
'code' => strtoupper($currency->type),
|
||||
'txid' => $result['txid'],
|
||||
'amount' => $origin_transfer_qty,
|
||||
'sender' => $from_address,
|
||||
'recipient' => $to_address,
|
||||
];
|
||||
ChainHash::unguarded(function () use ($chain_hash) {
|
||||
return ChainHash::create($chain_hash);
|
||||
});
|
||||
} else {
|
||||
throw new \Exception($result['msg'] ?? var_export($result, true));
|
||||
}
|
||||
//dump($params);
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 打入手续费
|
||||
*
|
||||
* @param UsersWallet $wallet
|
||||
* @param boolean $refresh_balance
|
||||
* @return void
|
||||
*/
|
||||
public static function transferPoundage(UsersWallet $wallet, $refresh_balance = false)
|
||||
{
|
||||
try {
|
||||
//检测当前是否已有手续费打入的交易hash
|
||||
//是否先刷新链上余额
|
||||
if ($refresh_balance) {
|
||||
$wallet->refresh();
|
||||
self::updateWalletBalance($wallet);
|
||||
}
|
||||
$wallet->refresh();
|
||||
if (bc_comp($wallet->old_balance, 0) <= 0) {
|
||||
throw new \Exception('用户链上余额为0,无须打入手续费');
|
||||
}
|
||||
$fee_currency = $currency = $wallet->currencyCoin;
|
||||
$currency_type = $currency->type;
|
||||
$fee_name = '';
|
||||
if ($currency_type == 'eth' || $currency_type == 'btc' || $currency_type == 'eos' || $currency_type == 'xrp') {
|
||||
throw new \Exception($wallet->currencyCoin->name . '币种无需额外打入归拢手续费');
|
||||
} elseif ($currency_type == 'erc20') {
|
||||
//从总账号往钱包打入eth
|
||||
$transfer_qty = $fee_currency->chain_fee;
|
||||
$from_address = $fee_currency->total_account;
|
||||
$from_private_key = $fee_currency->origin_key;
|
||||
$fee_name = 'eth';
|
||||
} elseif ($currency_type == 'usdt') {
|
||||
//从总账号往钱包打入btc
|
||||
$transfer_qty = bc_add($fee_currency->chain_fee, '0.00000546');
|
||||
$from_address = $fee_currency->total_account;
|
||||
$from_private_key = $fee_currency->origin_key;
|
||||
$fee_name = 'btc';
|
||||
} else {
|
||||
throw new \Exception('不支持的数字货币');
|
||||
}
|
||||
if (empty($from_address) || empty($from_private_key)) {
|
||||
throw new \Exception($fee_name . '币种总账号信息未设置');
|
||||
}
|
||||
$fee_balance = self::getChainBalance($wallet, $fee_name);
|
||||
//当链上手续费余额大于需要转入的手续费时,提示无须再打入手续费
|
||||
if (bc_comp($fee_balance, $transfer_qty) >= 0) {
|
||||
throw new \Exception('钱包内' . $fee_name . '余额充足,无须打入');
|
||||
} else {
|
||||
//当有余额时看相差多少,只打入相差的部分
|
||||
$transfer_qty = bc_sub($transfer_qty, bc_comp($fee_balance, 0) >= 0 ? $fee_balance : 0);
|
||||
}
|
||||
|
||||
$params = [
|
||||
'currency_type' => $currency_type,
|
||||
'fee_name' => $fee_name,
|
||||
'to_address' => $wallet->address,
|
||||
'transfer_qty' => $transfer_qty,
|
||||
'from_address' => $from_address,
|
||||
'from_private_key' => $from_private_key,
|
||||
'type' => 2,
|
||||
];
|
||||
$query_str = md5(http_build_query($params));
|
||||
if (Cache::has($query_str)) {
|
||||
throw new \Exception('当前链上已有手续费交易正在确认,请勿重复打入手续费!交易哈希:' . Cache::get($query_str));
|
||||
}
|
||||
|
||||
// 从当日哈希表中检测是否已有未确认的打入手续费的交易
|
||||
$fee_transaction = LbxHash::where('wallet_id', $wallet->id)
|
||||
->where('created_at', '>=', Carbon::today())
|
||||
->where('type', 2)
|
||||
->where('status', 0)
|
||||
->first();
|
||||
if ($fee_transaction) {
|
||||
throw new \Exception('当前链上已有手续费交易正在确认,请勿重复打入手续费!交易哈希:' . $fee_transaction->txid);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
$result = self::transfer($currency_type, $fee_name, $wallet->address, $transfer_qty, $from_address, $from_private_key, 2);
|
||||
if ($result['code'] == 0) {
|
||||
Cache::put($query_str, $result['txid'], 20);
|
||||
//记录链上哈希信息
|
||||
$lbx_hash_data = [
|
||||
'wallet_id' => $wallet->id,
|
||||
'txid' => $result['txid'],
|
||||
'type' => 2, //打入手续费
|
||||
'amount' => $transfer_qty,
|
||||
'status' => 0,
|
||||
];
|
||||
LbxHash::unguarded(function () use ($lbx_hash_data) {
|
||||
return LbxHash::create($lbx_hash_data);
|
||||
});
|
||||
}
|
||||
DB::commit();
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 钱包链上余额归拢到总账号
|
||||
*
|
||||
* @param \App\UsersWallet $wallet 要归拢的钱包
|
||||
* @param bool $refresh_balance 是否从链上刷新余额
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function collect(UsersWallet $wallet, $refresh_balance = false)
|
||||
{
|
||||
$currency = $wallet->currencyCoin;
|
||||
if (!$currency) {
|
||||
throw new \Exception('对应币种不存在');
|
||||
}
|
||||
$from_address = $wallet->address;
|
||||
$from_private_key = $wallet->private;
|
||||
|
||||
//$to_address = $currency->total_account;
|
||||
$to_address = $currency->collect_account;
|
||||
$contract_address = $currency->contract_address;
|
||||
$currency_type = $currency->type;
|
||||
if (empty($to_address)) {
|
||||
throw new \Exception('归拢地址未设置');
|
||||
}
|
||||
if ($currency_type == 'erc20' && empty($contract_address)) {
|
||||
throw new \Exception('合约地址未设置');
|
||||
}
|
||||
// 根据币种手续费计算
|
||||
$base_transfer_use_qty = 0; //除手续费消耗主链的数量
|
||||
switch ($currency_type) {
|
||||
case 'eth':
|
||||
$fee_currency_name = 'eth';
|
||||
$transfer_fee = $currency->chain_fee ?? 0.001;
|
||||
break;
|
||||
case 'btc':
|
||||
$fee_currency_name = 'btc';
|
||||
$transfer_fee = $currency->chain_fee ?? 0.00006;
|
||||
break;
|
||||
case 'erc20':
|
||||
$fee_currency_name = 'eth';
|
||||
$transfer_fee = $currency->chain_fee ?? 0.001;
|
||||
break;
|
||||
case 'usdt':
|
||||
$fee_currency_name = 'btc';
|
||||
$base_transfer_use_qty = 0.00000546;
|
||||
$transfer_fee = $currency->chain_fee ?? 0.00006;
|
||||
break;
|
||||
default:
|
||||
$fee_currency_name = '';
|
||||
$transfer_fee = 0;
|
||||
}
|
||||
// 查询上次归拢是否完成
|
||||
$lbx_hash = LbxHash::where('status', 0)
|
||||
->where('type', 0)
|
||||
->where('wallet_id', $wallet->id)
|
||||
->first();
|
||||
if ($lbx_hash) {
|
||||
throw new \Exception('当前有归拢操作未完成');
|
||||
}
|
||||
// 是否先刷新链上余额
|
||||
if ($refresh_balance) {
|
||||
self::updateWalletBalance($wallet);
|
||||
}
|
||||
$wallet->refresh();
|
||||
if ($currency_type == 'erc20' || $currency_type == 'usdt') {
|
||||
//检测手续费是否充足:erc20扣eth, usdt扣btc
|
||||
$fee_balance = self::getChainBalance($wallet, $fee_currency_name);
|
||||
$base_total_use_qty = bc_add($base_transfer_use_qty, $transfer_fee); //手续费+链上交易额外消耗,例如USDT要额外消耗0.00000546BTC
|
||||
|
||||
if (bc_comp($fee_balance, $base_total_use_qty) < 0) {
|
||||
throw new \Exception('钱包内手续费可用余额(' . $fee_balance . ')不足,不能归拢');
|
||||
}
|
||||
$transfer_qty = $wallet->old_balance; //代币有多少归多少
|
||||
} else {
|
||||
$transfer_qty = bc_sub($wallet->old_balance, $transfer_fee); //主链归拢减去手续费
|
||||
}
|
||||
//如果链上余额为空或者只有手续费(ETH、BTC)就没必要做归拢
|
||||
if (bc_comp($transfer_qty, 0) <= 0) {
|
||||
throw new \Exception('余额为空或手续费不足,不能归拢');
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$result = self::transfer($currency->name, $currency->type, $to_address, $transfer_qty, $from_address, $from_private_key, 1);
|
||||
if (!isset($result['code']) || $result['code'] != 0) {
|
||||
throw new \Exception(var_export($result, true));
|
||||
}
|
||||
//记录链上哈希信息
|
||||
$lbx_hash_data = [
|
||||
'wallet_id' => $wallet->id,
|
||||
'txid' => $result['txid'],
|
||||
'type' => 0,
|
||||
'amount' => $transfer_qty,
|
||||
'status' => 0,
|
||||
];
|
||||
LbxHash::unguarded(function () use ($lbx_hash_data) {
|
||||
return LbxHash::create($lbx_hash_data);
|
||||
});
|
||||
$wallet->refresh();
|
||||
$wallet->txid = $result['txid'];
|
||||
$wallet->gl_time = time();
|
||||
$wallet->save();
|
||||
DB::commit();
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace App\DAO;
|
||||
|
||||
use DB;
|
||||
use App\Utils\RPC;
|
||||
use App\Brand;
|
||||
|
||||
use Request;
|
||||
|
||||
class BrandDAO
|
||||
{
|
||||
public static function lists($num = 0) {
|
||||
if($num == 0) {
|
||||
$brand = Brand::get();
|
||||
} else {
|
||||
$brand = Brand::paginate($num);
|
||||
}
|
||||
return $brand;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
namespace App\DAO;
|
||||
|
||||
use App\Activity;
|
||||
use App\ActivityItem;
|
||||
use App\Utils\RPC;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: joey
|
||||
* Date: 2018/1/31
|
||||
* Time: 15:54
|
||||
*/
|
||||
class ExpressADO
|
||||
{
|
||||
/**
|
||||
* 获取物流详情
|
||||
* @param string $url 请求Url
|
||||
* @param array $datas 提交的数据
|
||||
* @return url响应返回的html
|
||||
*/
|
||||
public static function getContetn($ShipperCode, $LogisticCode)
|
||||
{
|
||||
$kdniao = Config::get("express.kdniao");
|
||||
if (empty($ShipperCode) || empty($LogisticCode))
|
||||
return "";
|
||||
$requestData= "{'OrderCode':'','ShipperCode':'".$ShipperCode."','LogisticCode':'".$LogisticCode."'}";
|
||||
$datas = array(
|
||||
'EBusinessID' => $kdniao["EBusinessID"],
|
||||
'RequestType' => '1002',
|
||||
'RequestData' => urlencode($requestData) ,
|
||||
'DataType' => '2',
|
||||
);
|
||||
$datas['DataSign'] = ExpressADO::encrypt($requestData, $kdniao["AppKey"]);
|
||||
$result = ExpressADO::sendPost($kdniao["ReqURL"], $datas);
|
||||
$result = json_decode($result,true);
|
||||
return $result["Traces"];
|
||||
}
|
||||
/**
|
||||
* post提交数据
|
||||
* @param string $url 请求Url
|
||||
* @param array $datas 提交的数据
|
||||
* @return url响应返回的html
|
||||
*/
|
||||
public static function sendPost($url, $datas)
|
||||
{
|
||||
$temps = array();
|
||||
foreach ($datas as $key => $value) {
|
||||
$temps[] = sprintf('%s=%s', $key, $value);
|
||||
}
|
||||
$post_data = implode('&', $temps);
|
||||
$url_info = parse_url($url);
|
||||
if(empty($url_info['port']))
|
||||
{
|
||||
$url_info['port']=80;
|
||||
}
|
||||
$httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
|
||||
$httpheader.= "Host:" . $url_info['host'] . "\r\n";
|
||||
$httpheader.= "Content-Type:application/x-www-form-urlencoded\r\n";
|
||||
$httpheader.= "Content-Length:" . strlen($post_data) . "\r\n";
|
||||
$httpheader.= "Connection:close\r\n\r\n";
|
||||
$httpheader.= $post_data;
|
||||
$fd = fsockopen($url_info['host'], $url_info['port']);
|
||||
fwrite($fd, $httpheader);
|
||||
$gets = "";
|
||||
$headerFlag = true;
|
||||
while (!feof($fd)) {
|
||||
if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (!feof($fd)) {
|
||||
$gets.= fread($fd, 128);
|
||||
}
|
||||
fclose($fd);
|
||||
|
||||
return $gets;
|
||||
}
|
||||
/**
|
||||
* 电商Sign签名生成
|
||||
* @param data 内容
|
||||
* @param appkey Appkey
|
||||
* @return DataSign签名
|
||||
*/
|
||||
public static function encrypt($data, $appkey) {
|
||||
return urlencode(base64_encode(md5($data.$appkey)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace App\DAO;
|
||||
|
||||
use App\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Users;
|
||||
use App\Level;
|
||||
use App\UserUpgradeLog;
|
||||
use App\PrizePool;
|
||||
use App\LeverTransaction;
|
||||
use App\UsersWallet;
|
||||
USE App\UsersWalletcopy;
|
||||
use App\Setting;
|
||||
use App\AccountLog;
|
||||
|
||||
|
||||
class FactprofitsDAO
|
||||
{
|
||||
/**
|
||||
* 会员历史总盈亏释放
|
||||
* @param project $user_id 要释放用户的id
|
||||
*/
|
||||
public static function Profit_loss_release($user_id)
|
||||
{
|
||||
$profit_loss_release=Setting::getValueByKey('profit_loss_release','')/1000;
|
||||
$sum=LeverTransaction::where("user_id","=",$user_id)->where("status","=",3)->sum("fact_profits");
|
||||
// var_dump($profit_loss_release);
|
||||
// var_dump($sum);die;
|
||||
if($sum<0)
|
||||
{
|
||||
$aaaa=UsersWalletcopy::leftjoin("currency","currency.id","=","users_wallet.currency")->where("currency.name","=","USDC")->where("users_wallet.user_id","=",$user_id)->select("users_wallet.id","users_wallet.lever_balance","users_wallet.user_id","currency.id as currency_id")->first();
|
||||
$user_walllet=UsersWalletcopy::where("user_id","=",$aaaa->user_id)->where("currency","=",$aaaa->currency_id)->first();
|
||||
$number=-bc_mul($sum,$profit_loss_release,8);
|
||||
$user_walllet->lever_balance=$user_walllet->lever_balance+$number;
|
||||
$user_walllet->save();
|
||||
try {
|
||||
//增加杠杆币日志记录
|
||||
$result = change_wallet_balance(
|
||||
$user_walllet,
|
||||
3,
|
||||
+$number,
|
||||
AccountLog::PROFIT_LOSS_RELEASE,
|
||||
'历史盈亏释放,增加杠杆币'.$number,
|
||||
false,
|
||||
$user_id,
|
||||
0
|
||||
);
|
||||
if ($result !== true) {
|
||||
throw new \Exception('历史盈亏释放,增加杠杆币:' . $result);
|
||||
}
|
||||
DB::commit();
|
||||
return true;
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
<?PHP
|
||||
namespace App\DAO\Lib;
|
||||
class mail
|
||||
{
|
||||
|
||||
protected $base_url = 'http://api.mysubmail.com/';
|
||||
|
||||
protected $mail_configs;
|
||||
protected $signType = 'normal';
|
||||
|
||||
function __construct($mail_config)
|
||||
{
|
||||
$this->mail_configs = $mail_config;
|
||||
if (!empty($mail_config['server'])) {
|
||||
$this->base_url = $mail_config['server'];
|
||||
}
|
||||
}
|
||||
|
||||
protected function createSignature($request)
|
||||
{
|
||||
$r = "";
|
||||
switch ($this->signType) {
|
||||
case 'normal':
|
||||
$r = $this->mail_configs['appkey'];
|
||||
break;
|
||||
case 'md5':
|
||||
$r = $this->buildSignature($this->argSort($request));
|
||||
break;
|
||||
case 'sha1':
|
||||
$r = $this->buildSignature($this->argSort($request));
|
||||
break;
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
protected function buildSignature($request)
|
||||
{
|
||||
$arg = "";
|
||||
$app = $this->mail_configs['appid'];
|
||||
$appkey = $this->mail_configs['appkey'];
|
||||
while (list ($key, $val) = each($request)) {
|
||||
if (strpos($key, "attachments") === false) {
|
||||
$arg .= $key . "=" . $val . "&";
|
||||
}
|
||||
}
|
||||
$arg = substr($arg, 0, count($arg) - 2);
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$arg = stripslashes($arg);
|
||||
}
|
||||
if ($this->signType == 'sha1') {
|
||||
$r = sha1($app . $appkey . $arg . $app . $appkey);
|
||||
} else {
|
||||
$r = md5($app . $appkey . $arg . $app . $appkey);
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
protected function argSort($request)
|
||||
{
|
||||
ksort($request);
|
||||
reset($request);
|
||||
return $request;
|
||||
}
|
||||
|
||||
public function getTimestamp()
|
||||
{
|
||||
$api = $this->base_url . 'service/timestamp.json';
|
||||
$ch = curl_init($api);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
|
||||
$output = curl_exec($ch);
|
||||
$timestamp = json_decode($output, true);
|
||||
|
||||
return $timestamp['timestamp'];
|
||||
}
|
||||
|
||||
protected function APIHttpRequestCURL($api, $post_data, $method = 'post')
|
||||
{
|
||||
if ($method != 'get') {
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, array(
|
||||
CURLOPT_URL => $api,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POSTFIELDS => http_build_query($post_data),
|
||||
CURLOPT_CUSTOMREQUEST => strtoupper($method),
|
||||
CURLOPT_HTTPHEADER => array("Content-Type: application/x-www-form-urlencoded")
|
||||
));
|
||||
} else {
|
||||
$url = $api . '?' . http_build_query($post_data);
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
|
||||
}
|
||||
$output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$output = trim($output, "\xEF\xBB\xBF");
|
||||
return json_decode($output, true);
|
||||
}
|
||||
|
||||
|
||||
public function send($request)
|
||||
{
|
||||
$api = $this->base_url . 'mail/send.json';
|
||||
$request['appid'] = $this->mail_configs['appid'];
|
||||
$request['timestamp'] = $this->getTimestamp();
|
||||
if (empty($this->mail_configs['sign_type'])
|
||||
&& $this->mail_configs['sign_type'] == ""
|
||||
&& $this->mail_configs['sign_type'] != "normal"
|
||||
&& $this->mail_configs['sign_type'] != "md5"
|
||||
&& $this->mail_configs['sign_type'] != "sha1"
|
||||
) {
|
||||
$this->signType = 'normal';
|
||||
} else {
|
||||
$this->signType = $this->mail_configs['sign_type'];
|
||||
$request['sign_type'] = $this->mail_configs['sign_type'];
|
||||
}
|
||||
$request['signature'] = $this->createSignature($request);
|
||||
$send = $this->APIHttpRequestCURL($api, $request);
|
||||
|
||||
return $send;
|
||||
}
|
||||
|
||||
public function xsend($request)
|
||||
{
|
||||
$api = $this->base_url . 'mail/xsend.json';
|
||||
$request['appid'] = $this->mail_configs['appid'];
|
||||
$request['timestamp'] = $this->getTimestamp();
|
||||
if (empty($this->mail_configs['sign_type'])
|
||||
&& $this->mail_configs['sign_type'] == ""
|
||||
&& $this->mail_configs['sign_type'] != "normal"
|
||||
&& $this->mail_configs['sign_type'] != "md5"
|
||||
&& $this->mail_configs['sign_type'] != "sha1"
|
||||
) {
|
||||
$this->signType = 'normal';
|
||||
} else {
|
||||
$this->signType = $this->mail_configs['sign_type'];
|
||||
$request['sign_type'] = $this->mail_configs['sign_type'];
|
||||
}
|
||||
$request['signature'] = $this->createSignature($request);
|
||||
$xsend = $this->APIHttpRequestCURL($api, $request);
|
||||
return $xsend;
|
||||
}
|
||||
|
||||
public function subscribe($request)
|
||||
{
|
||||
$api = $this->base_url . 'addressbook/mail/subscribe.json';
|
||||
$request['appid'] = $this->mail_configs['appid'];
|
||||
$request['timestamp'] = $this->getTimestamp();
|
||||
if (empty($this->mail_configs['sign_type'])
|
||||
&& $this->mail_configs['sign_type'] == ""
|
||||
&& $this->mail_configs['sign_type'] != "normal"
|
||||
&& $this->mail_configs['sign_type'] != "md5"
|
||||
&& $this->mail_configs['sign_type'] != "sha1"
|
||||
) {
|
||||
$this->signType = 'normal';
|
||||
} else {
|
||||
$this->signType = $this->mail_configs['sign_type'];
|
||||
$request['sign_type'] = $this->mail_configs['sign_type'];
|
||||
}
|
||||
$request['signature'] = $this->createSignature($request);
|
||||
$subscribe = $this->APIHttpRequestCURL($api, $request);
|
||||
return $subscribe;
|
||||
}
|
||||
|
||||
public function unsubscribe($request)
|
||||
{
|
||||
$api = $this->base_url . 'addressbook/mail/unsubscribe.json';
|
||||
$request['appid'] = $this->mail_configs['appid'];
|
||||
$request['timestamp'] = $this->getTimestamp();
|
||||
if (empty($this->mail_configs['sign_type'])
|
||||
&& $this->mail_configs['sign_type'] == ""
|
||||
&& $this->mail_configs['sign_type'] != "normal"
|
||||
&& $this->mail_configs['sign_type'] != "md5"
|
||||
&& $this->mail_configs['sign_type'] != "sha1"
|
||||
) {
|
||||
$this->signType = 'normal';
|
||||
} else {
|
||||
$this->signType = $this->mail_configs['sign_type'];
|
||||
$request['sign_type'] = $this->mail_configs['sign_type'];
|
||||
}
|
||||
$request['signature'] = $this->createSignature($request);
|
||||
$unsubscribe = $this->APIHttpRequestCURL($api, $request);
|
||||
return $unsubscribe;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Kewail\Sms\Demo;
|
||||
|
||||
require_once "SmsSingleSender.php";
|
||||
|
||||
use Kewail\Sms\SmsSingleSender;
|
||||
|
||||
try {
|
||||
// 请根据实际 accesskey 和 secretkey 进行开发,以下只作为演示 sdk 使用
|
||||
$accesskey = "";
|
||||
$secretkey = "";
|
||||
$phoneNumber = "";
|
||||
|
||||
$singleSender = new SmsSingleSender($accesskey, $secretkey);
|
||||
|
||||
// 普通单发
|
||||
$result = $singleSender->send(0, "86", $phoneNumber , "【Kewail科技】您注册的验证码:128128有效时间30分钟。", "", "");
|
||||
$rsp = json_decode($result);
|
||||
echo $result;
|
||||
echo "<br>";
|
||||
|
||||
} catch (\Exception $e) {
|
||||
echo var_dump($e);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
// Works well with php5.3 and php5.6.
|
||||
|
||||
namespace App\DAO\Moducloud;
|
||||
|
||||
class SmsSenderUtil {
|
||||
function getRandom() {
|
||||
return rand(100000, 999999);
|
||||
}
|
||||
|
||||
function calculateSig($secretkey, $random, $curTime, $phoneNumbers) {
|
||||
$phoneNumbersString = $phoneNumbers[0];
|
||||
for ($i = 1; $i < count($phoneNumbers); $i++) {
|
||||
$phoneNumbersString .= ("," . $phoneNumbers[$i]);
|
||||
}
|
||||
return hash("sha256", "secretkey=".$secretkey."&random=".$random
|
||||
."&time=".$curTime."&mobile=".$phoneNumbersString);
|
||||
}
|
||||
|
||||
function calculateSigForTemplAndPhoneNumbers($secretkey, $random, $curTime, $phoneNumbers) {
|
||||
$phoneNumbersString = $phoneNumbers[0];
|
||||
for ($i = 1; $i < count($phoneNumbers); $i++) {
|
||||
$phoneNumbersString .= ("," . $phoneNumbers[$i]);
|
||||
}
|
||||
return hash("sha256", "secretkey=".$secretkey."&random=".$random
|
||||
."&time=".$curTime."&mobile=".$phoneNumbersString);
|
||||
}
|
||||
|
||||
function phoneNumbersToArray($nationCode, $phoneNumbers) {
|
||||
$i = 0;
|
||||
$tel = array();
|
||||
do {
|
||||
$telElement = new \stdClass();
|
||||
$telElement->nationcode = $nationCode;
|
||||
$telElement->mobile = $phoneNumbers[$i];
|
||||
array_push($tel, $telElement);
|
||||
} while (++$i < count($phoneNumbers));
|
||||
return $tel;
|
||||
}
|
||||
|
||||
function calculateSigForTempl($secretkey, $random, $curTime, $phoneNumber) {
|
||||
$phoneNumbers = array($phoneNumber);
|
||||
return $this->calculateSigForTemplAndPhoneNumbers($secretkey, $random, $curTime, $phoneNumbers);
|
||||
}
|
||||
|
||||
function sendCurlPost($url, $dataObj) {
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HEADER, 0);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($dataObj));
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen(json_encode($dataObj))));
|
||||
$ret = curl_exec($curl);
|
||||
if (false == $ret) {
|
||||
// curl_exec failed
|
||||
$result = "{ \"result\":" . -2 . ",\"errmsg\":\"" . curl_error($curl) . "\"}";
|
||||
} else {
|
||||
$rsp = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if (200 != $rsp) {
|
||||
$result = "{ \"result\":" . -1 . ",\"errmsg\":\"". $rsp . " " . curl_error($curl) ."\"}";
|
||||
} else {
|
||||
$result = $ret;
|
||||
}
|
||||
}
|
||||
curl_close($curl);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,302 @@
|
||||
<?php
|
||||
|
||||
// Works well with php5.3 and php5.6.
|
||||
|
||||
namespace App\DAO\Moducloud;
|
||||
|
||||
require_once('SmsSenderUtil.php');
|
||||
|
||||
class SmsSingleSender {
|
||||
var $url;
|
||||
var $accesskey;
|
||||
var $secretkey;
|
||||
var $util;
|
||||
|
||||
function __construct($accesskey, $secretkey) {
|
||||
$this->url = "https://live.kewail.com/sms/v1/sendsinglesms";
|
||||
$this->accesskey = $accesskey;
|
||||
$this->secretkey = $secretkey;
|
||||
$this->util = new SmsSenderUtil();
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通单发,明确指定内容,如果有多个签名,请在内容中以【】的方式添加到信息内容中,否则系统将使用默认签名
|
||||
* @param int $type 短信类型,0 为普通短信,1 营销短信
|
||||
* @param string $nationCode 国家码,如 86 为中国
|
||||
* @param string $phoneNumber 不带国家码的手机号
|
||||
* @param string $msg 信息内容,必须与申请的模板格式一致,否则将返回错误
|
||||
* @param string $extend 扩展码,可填空串
|
||||
* @param string $ext 服务端原样返回的参数,可填空串
|
||||
* @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的内容参见协议文档
|
||||
*/
|
||||
function send($type, $nationCode, $phoneNumber, $msg, $extend = "", $ext = "") {
|
||||
/*
|
||||
请求包体
|
||||
{
|
||||
"tel": {
|
||||
"nationcode": "86",
|
||||
"mobile": "13788888888"
|
||||
},
|
||||
"type": 0,
|
||||
"msg": "你的验证码是1234",
|
||||
"sig": "fdba654e05bc0d15796713a1a1a2318c",
|
||||
"time": 1479888540,
|
||||
"extend": "",
|
||||
"ext": ""
|
||||
}
|
||||
应答包体
|
||||
{
|
||||
"result": 0,
|
||||
"errmsg": "OK",
|
||||
"ext": "",
|
||||
"sid": "xxxxxxx",
|
||||
"fee": 1
|
||||
}
|
||||
*/
|
||||
$random = $this->util->getRandom();
|
||||
$curTime = time();
|
||||
$wholeUrl = $this->url . "?accesskey=" . $this->accesskey . "&random=" . $random;
|
||||
|
||||
// 按照协议组织 post 包体
|
||||
$data = new \stdClass();
|
||||
$tel = new \stdClass();
|
||||
$tel->nationcode = "".$nationCode;
|
||||
$tel->mobile = "".$phoneNumber;
|
||||
|
||||
$data->tel = $tel;
|
||||
$data->type = (int)$type;
|
||||
$data->msg = $msg;
|
||||
$data->sig = hash("sha256",
|
||||
"secretkey=".$this->secretkey."&random=".$random."&time=".$curTime."&mobile=".$phoneNumber, FALSE);
|
||||
$data->time = $curTime;
|
||||
$data->extend = $extend;
|
||||
$data->ext = $ext;
|
||||
return $this->util->sendCurlPost($wholeUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定模板单发
|
||||
* @param string $nationCode 国家码,如 86 为中国
|
||||
* @param string $phoneNumber 不带国家码的手机号
|
||||
* @param int $templId 模板 id
|
||||
* @param array $params 模板参数列表,如模板 {1}...{2}...{3},那么需要带三个参数
|
||||
* @param string $sign 签名,如果填空串,系统会使用默认签名
|
||||
* @param string $extend 扩展码,可填空串
|
||||
* @param string $ext 服务端原样返回的参数,可填空串
|
||||
* @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的内容参见协议文档
|
||||
*/
|
||||
function sendWithParam($nationCode, $phoneNumber, $templId = 0, $params, $sign = "", $extend = "", $ext = "") {
|
||||
/*
|
||||
请求包体
|
||||
{
|
||||
"tel": {
|
||||
"nationcode": "86",
|
||||
"mobile": "13788888888"
|
||||
},
|
||||
"sign": "Kewail",
|
||||
"tpl_id": 19,
|
||||
"params": [
|
||||
"验证码",
|
||||
"1234",
|
||||
"4"
|
||||
],
|
||||
"sig": "fdba654e05bc0d15796713a1a1a2318c",
|
||||
"time": 1479888540,
|
||||
"extend": "",
|
||||
"ext": ""
|
||||
}
|
||||
应答包体
|
||||
{
|
||||
"result": 0,
|
||||
"errmsg": "OK",
|
||||
"ext": "",
|
||||
"sid": "xxxxxxx",
|
||||
"fee": 1
|
||||
}
|
||||
*/
|
||||
$random = $this->util->getRandom();
|
||||
$curTime = time();
|
||||
$wholeUrl = $this->url . "?sdkaccesskey=" . $this->accesskey . "&random=" . $random;
|
||||
|
||||
// 按照协议组织 post 包体
|
||||
$data = new \stdClass();
|
||||
$tel = new \stdClass();
|
||||
$tel->nationcode = "".$nationCode;
|
||||
$tel->mobile = "".$phoneNumber;
|
||||
|
||||
$data->tel = $tel;
|
||||
$data->sig = $this->util->calculateSigForTempl($this->secretkey, $random, $curTime, $phoneNumber);
|
||||
$data->tpl_id = $templId;
|
||||
$data->params = $params;
|
||||
$data->sign = $sign;
|
||||
$data->time = $curTime;
|
||||
$data->extend = $extend;
|
||||
$data->ext = $ext;
|
||||
return $this->util->sendCurlPost($wholeUrl, $data);
|
||||
}
|
||||
}
|
||||
|
||||
class SmsMultiSender {
|
||||
var $url;
|
||||
var $accesskey;
|
||||
var $secretkey;
|
||||
var $util;
|
||||
|
||||
function __construct($accesskey, $secretkey) {
|
||||
$this->url = "https://live.kewail.com/sms/v1/sendsinglesms";
|
||||
$this->accesskey = $accesskey;
|
||||
$this->secretkey = $secretkey;
|
||||
$this->util = new SmsSenderUtil();
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通群发,明确指定内容,如果有多个签名,请在内容中以【】的方式添加到信息内容中,否则系统将使用默认签名
|
||||
* 【注意】海外短信无群发功能
|
||||
* @param int $type 短信类型,0 为普通短信,1 营销短信
|
||||
* @param string $nationCode 国家码,如 86 为中国
|
||||
* @param string $phoneNumbers 不带国家码的手机号列表
|
||||
* @param string $msg 信息内容,必须与申请的模板格式一致,否则将返回错误
|
||||
* @param string $extend 扩展码,可填空串
|
||||
* @param string $ext 服务端原样返回的参数,可填空串
|
||||
* @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的内容参见协议文档
|
||||
*/
|
||||
function send($type, $nationCode, $phoneNumbers, $msg, $extend = "", $ext = "") {
|
||||
/*
|
||||
请求包体
|
||||
{
|
||||
"tel": [
|
||||
{
|
||||
"nationcode": "86",
|
||||
"mobile": "13788888888"
|
||||
},
|
||||
{
|
||||
"nationcode": "86",
|
||||
"mobile": "13788888889"
|
||||
}
|
||||
],
|
||||
"type": 0,
|
||||
"msg": "你的验证码是1234",
|
||||
"sig": "fdba654e05bc0d15796713a1a1a2318c",
|
||||
"time": 1479888540,
|
||||
"extend": "",
|
||||
"ext": ""
|
||||
}
|
||||
应答包体
|
||||
{
|
||||
"result": 0,
|
||||
"errmsg": "OK",
|
||||
"ext": "",
|
||||
"detail": [
|
||||
{
|
||||
"result": 0,
|
||||
"errmsg": "OK",
|
||||
"mobile": "13788888888",
|
||||
"nationcode": "86",
|
||||
"sid": "xxxxxxx",
|
||||
"fee": 1
|
||||
},
|
||||
{
|
||||
"result": 0,
|
||||
"errmsg": "OK",
|
||||
"mobile": "13788888889",
|
||||
"nationcode": "86",
|
||||
"sid": "xxxxxxx",
|
||||
"fee": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
$random = $this->util->getRandom();
|
||||
$curTime = time();
|
||||
$wholeUrl = $this->url . "?accesskey=" . $this->accesskey . "&random=" . $random;
|
||||
$data = new \stdClass();
|
||||
$data->tel = $this->util->phoneNumbersToArray($nationCode, $phoneNumbers);
|
||||
$data->type = $type;
|
||||
$data->msg = $msg;
|
||||
$data->sig = $this->util->calculateSig($this->secretkey, $random, $curTime, $phoneNumbers);
|
||||
$data->time = $curTime;
|
||||
$data->extend = $extend;
|
||||
$data->ext = $ext;
|
||||
return $this->util->sendCurlPost($wholeUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定模板群发
|
||||
* 【注意】海外短信无群发功能
|
||||
* @param string $nationCode 国家码,如 86 为中国
|
||||
* @param array $phoneNumbers 不带国家码的手机号列表
|
||||
* @param int $templId 模板 id
|
||||
* @param array $params 模板参数列表,如模板 {1}...{2}...{3},那么需要带三个参数
|
||||
* @param string $sign 签名,如果填空串,系统会使用默认签名
|
||||
* @param string $extend 扩展码,可填空串
|
||||
* @param string $ext 服务端原样返回的参数,可填空串
|
||||
* @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的内容参见协议文档
|
||||
*/
|
||||
function sendWithParam($nationCode, $phoneNumbers, $templId, $params, $sign = "", $extend ="", $ext = "") {
|
||||
/*
|
||||
请求包体
|
||||
{
|
||||
"tel": [
|
||||
{
|
||||
"nationcode": "86",
|
||||
"mobile": "13788888888"
|
||||
},
|
||||
{
|
||||
"nationcode": "86",
|
||||
"mobile": "13788888889"
|
||||
}
|
||||
],
|
||||
"sign": "Kewail",
|
||||
"tpl_id": 19,
|
||||
"params": [
|
||||
"验证码",
|
||||
"1234",
|
||||
"4"
|
||||
],
|
||||
"sig": "fdba654e05bc0d15796713a1a1a2318c",
|
||||
"time": 1479888540,
|
||||
"extend": "",
|
||||
"ext": ""
|
||||
}
|
||||
应答包体
|
||||
{
|
||||
"result": 0,
|
||||
"errmsg": "OK",
|
||||
"ext": "",
|
||||
"detail": [
|
||||
{
|
||||
"result": 0,
|
||||
"errmsg": "OK",
|
||||
"mobile": "13788888888",
|
||||
"nationcode": "86",
|
||||
"sid": "xxxxxxx",
|
||||
"fee": 1
|
||||
},
|
||||
{
|
||||
"result": 0,
|
||||
"errmsg": "OK",
|
||||
"mobile": "13788888889",
|
||||
"nationcode": "86",
|
||||
"sid": "xxxxxxx",
|
||||
"fee": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
$random = $this->util->getRandom();
|
||||
$curTime = time();
|
||||
$wholeUrl = $this->url . "?accesskey=" . $this->accesskey . "&random=" . $random;
|
||||
$data = new \stdClass();
|
||||
$data->tel = $this->util->phoneNumbersToArray($nationCode, $phoneNumbers);
|
||||
$data->sign = $sign;
|
||||
$data->tpl_id = $templId;
|
||||
$data->params = $params;
|
||||
$data->sig = $this->util->calculateSigForTemplAndPhoneNumbers(
|
||||
$this->secretkey, $random, $curTime, $phoneNumbers);
|
||||
$data->time = $curTime;
|
||||
$data->extend = $extend;
|
||||
$data->ext = $ext;
|
||||
return $this->util->sendCurlPost($wholeUrl, $data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace App\DAO\PrizePool;
|
||||
|
||||
use App\PrizePool as PrizePoolModel;
|
||||
use App\Setting;
|
||||
|
||||
class CandyCalculator implements PrizeCalculator
|
||||
{
|
||||
protected $reward_type = PrizePoolModel::REWARD_CANDY;
|
||||
protected $reward_currency = PrizePoolModel::CURRENCY_NONE;
|
||||
protected $currency_type = PrizePoolModel::CURRENCY_NONE;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function calculate($scene, $reward_qty, $to_user, $from_user = null, $memo = '', $attach_data = [])
|
||||
{
|
||||
$fasten_data = [
|
||||
'reward_type' => $this->reward_type,
|
||||
'reward_currency' => $this->reward_currency,
|
||||
'create_time' => time(), //发奖时间
|
||||
];
|
||||
$origin_reward_qty = $reward_qty; //原始奖励数量
|
||||
$candy_tousdt = Setting::getValueByKey('candy_tousdt', 100);
|
||||
$candy_tousdt = bc_div($candy_tousdt, 100);
|
||||
$reward_qty = bc_div($reward_qty, $candy_tousdt, 4);
|
||||
$extra_data = $attach_data['extra_data'];
|
||||
if (is_string($extra_data) && !empty($extra_data)) {
|
||||
$extra_data = unserialize($extra_data);
|
||||
}
|
||||
$extra_data['origin_reward_qty '] = $origin_reward_qty;
|
||||
$extra_data['candy_tousdt'] = $candy_tousdt;
|
||||
$attach_data['extra_data'] = serialize($extra_data);
|
||||
try {
|
||||
PrizePoolModel::unguard();
|
||||
$data = [
|
||||
'scene' => $scene,
|
||||
'reward_qty' => $reward_qty,
|
||||
'to_user_id' => $to_user->id,
|
||||
'from_user_id' => $from_user ? $from_user->id : $to_user->id,
|
||||
'memo' => $memo,
|
||||
];
|
||||
$data = array_merge($data, $attach_data, $fasten_data);
|
||||
$prize_pool = PrizePoolModel::create($data);
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
} finally {
|
||||
PrizePoolModel::reguard();
|
||||
}
|
||||
return isset($prize_pool->id) ? $prize_pool : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace App\DAO\PrizePool;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\PrizePool;
|
||||
use App\{Users, AccountLog};
|
||||
|
||||
class CandySender implements PrizeSender
|
||||
{
|
||||
public function send(\App\PrizePool &$prize) : bool
|
||||
{
|
||||
try {
|
||||
$prize->refresh();
|
||||
if ($prize->status != 0) {
|
||||
throw new \Exception('奖励发放异常');
|
||||
}
|
||||
if ($prize->reward_type != PrizePool::REWARD_CANDY) {
|
||||
throw new \Exception('奖励发放类型不匹配');
|
||||
}
|
||||
DB::transaction(function () use (&$prize) {
|
||||
$user = Users::lockForUpdate()->find($prize->to_user_id);
|
||||
$change_result = change_user_candy($user, $prize->reward_qty, AccountLog::REWARD_CANDY, $prize->memo);
|
||||
if ($change_result !== true) {
|
||||
throw new \Exception($change_result);
|
||||
}
|
||||
$prize->receive_time = time();
|
||||
$prize->status = 1;
|
||||
$result = $prize->save();
|
||||
if (!$result) {
|
||||
throw new \Exception('奖励通证发放失败');
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$error_info = serialize([
|
||||
'time' => time(),
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
$prize->error_info = $error_info;
|
||||
$prize->save();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\DAO\PrizePool;
|
||||
|
||||
use App\PrizePool as PrizePoolModel;
|
||||
|
||||
class CurrencyCalculator implements PrizeCalculator
|
||||
{
|
||||
protected $reward_type = PrizePoolModel::REWARD_CURRENCY;
|
||||
protected $reward_currency;
|
||||
protected $currency_type;
|
||||
|
||||
public function __construct($reward_currency, $currency_type)
|
||||
{
|
||||
$this->reward_currency = $reward_currency;
|
||||
$this->currency_type = $currency_type;
|
||||
}
|
||||
|
||||
public function calculate($scene, $reward_qty, $to_user, $from_user = null, $memo = '', $attach_data = [])
|
||||
{
|
||||
$fasten_data = [
|
||||
'reward_type' => $this->reward_type,
|
||||
'reward_currency' => $this->reward_currency,
|
||||
'create_time' => time(), //发奖时间
|
||||
];
|
||||
try {
|
||||
PrizePoolModel::unguard();
|
||||
$data = [
|
||||
'scene' => $scene,
|
||||
'reward_qty' => $reward_qty,
|
||||
'to_user_id' => $to_user->id,
|
||||
'from_user_id' => $from_user ? $from_user->id : $to_user->id,
|
||||
'memo' => $memo,
|
||||
];
|
||||
$data = array_merge($data, $attach_data, $fasten_data);
|
||||
$prize_pool = PrizePoolModel::create($data);
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
} finally {
|
||||
PrizePoolModel::reguard();
|
||||
}
|
||||
return isset($prize_pool->id) ? $prize_pool : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace App\DAO\PrizePool;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\{Users, AccountLog, UsersWallet, PrizePool};
|
||||
|
||||
class CurrencySender implements PrizeSender
|
||||
{
|
||||
public function send(\App\PrizePool &$prize) : bool
|
||||
{
|
||||
try {
|
||||
$prize->refresh();
|
||||
if ($prize->status != 0) {
|
||||
throw new \Exception('奖励发放异常');
|
||||
}
|
||||
if ($prize->reward_type != PrizePool::REWARD_CURRENCY) {
|
||||
throw new \Exception('奖励发放类型不匹配');
|
||||
}
|
||||
if (!in_array($prize->currency_type, [1, 2, 3])) {
|
||||
throw new \Exception('币种类型不正确');
|
||||
}
|
||||
DB::transaction(function () use (&$prize) {
|
||||
$user_wallet = UsersWallet::where('user_id', $prize->to_user_id)
|
||||
->where('currency', $prize->reward_currency)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
if (!$user_wallet) {
|
||||
throw new \Exception('用户钱包不存在');
|
||||
}
|
||||
$change_result = change_wallet_balance($user_wallet, $prize->currency_type, $prize->reward_qty, AccountLog::REWARD_CURRENCY, $prize->memo, false, $prize->from_user_id, $prize->sign, $extra_data);
|
||||
if ($change_result !== true) {
|
||||
throw new \Exception($change_result);
|
||||
}
|
||||
$prize->receive_time = time();
|
||||
$prize->status = 1;
|
||||
$result = $prize->save();
|
||||
if (!$result) {
|
||||
throw new \Exception('奖励通证发放失败');
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$error_info = serialize([
|
||||
'time' => time(),
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
$prize->error_info = $error_info;
|
||||
$prize->save();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\DAO\PrizePool;
|
||||
|
||||
interface PrizeCalculator
|
||||
{
|
||||
/**
|
||||
* 计算奖励
|
||||
*
|
||||
* @param integer $scene 奖励场景
|
||||
* @param float $reward_qty 奖励数量
|
||||
* @param \App\Users $to_user 被奖励者
|
||||
* @param \App\Users $from_user 触发用户
|
||||
* @param string $memo 备注
|
||||
* @param array $attach_data 附加数据
|
||||
* @return \App\PrizePool 返回奖池记录
|
||||
*/
|
||||
public function calculate($scene, $reward_qty, $to_user, $from_user = null, $memo = '', $attach_data = []);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace App\DAO\PrizePool;
|
||||
|
||||
interface PrizeSender
|
||||
{
|
||||
/**
|
||||
* 发放奖励
|
||||
*
|
||||
* @param \App\PrizePool $prize
|
||||
* @return boolean
|
||||
*/
|
||||
public function send(\App\PrizePool &$prize) : bool;
|
||||
}
|
||||
@@ -0,0 +1,557 @@
|
||||
<?php
|
||||
namespace App\DAO;
|
||||
|
||||
use Illuminate\Support\Facades\{DB, Log};
|
||||
use App\{AccountLog, LeverTransaction, PrizePool, Setting, Users};
|
||||
use App\DAO\PrizePool\{CandySender, CandyCalculator};
|
||||
|
||||
class RewardDAO
|
||||
{
|
||||
/**
|
||||
* 向用户直属工作室发放奖励
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function rewardLeverFeeToAtelier($lever_trade)
|
||||
{
|
||||
$today = strtotime(date('Y-m-d'));
|
||||
$candy_tousdt = Setting::getValueByKey('candy_tousdt', 100);
|
||||
$candy_tousdt = bc_div($candy_tousdt, 100);
|
||||
$atelier_reward_day_must_trade = Setting::getValueByKey('atelier_reward_day_must_trade', 0); //工作室每日最低交易量
|
||||
$atelier_reward_day_limit = Setting::getValueByKey('atelier_reward_day_limit', 0); //工作室每日奖励上限
|
||||
$atelier_reward_ratio = Setting::getValueByKey('atelier_reward_ratio', 0); //工作室奖励比例百分比
|
||||
$atelier_reward_ratio = bc_div($atelier_reward_ratio, 100, 4); //工作室奖励比例转化小数
|
||||
$can_reward_qty = 0;
|
||||
|
||||
$user_id = $lever_trade->user_id;
|
||||
$trade_id = $lever_trade->trade_id;
|
||||
$trade_fee = $lever_trade->trade_fee;
|
||||
$origin_reward_qty = bc_mul($trade_fee, $atelier_reward_ratio, 4); //奖励数量
|
||||
$convert_reward_qty = bc_div($origin_reward_qty, $candy_tousdt, 4); //换算成与usdt等值糖果
|
||||
$fact_convert_reward_qty = $convert_reward_qty;
|
||||
|
||||
$user = Users::find($user_id);
|
||||
$parents_path = UserDAO::getParentsPathDesc($user);
|
||||
$ateliers = UserDAO::getParentsAtelier($user);
|
||||
|
||||
if (count($ateliers) <= 0) {
|
||||
return;
|
||||
}
|
||||
$atelier = $ateliers->first();
|
||||
if (!$atelier) {
|
||||
return;
|
||||
}
|
||||
$key = array_search($atelier->id, $parents_path);
|
||||
$current_level = $key + 1;
|
||||
//每日已开仓交易量
|
||||
$today_has_trades = LeverTransaction::where('user_id', $atelier->user_id)
|
||||
->where('status', LeverTransaction::TRANSACTION)
|
||||
->where('create_time', '>=', $today)
|
||||
->count();
|
||||
if ($today_has_trades < $atelier_reward_day_must_trade) {
|
||||
return;
|
||||
}
|
||||
//每日已奖励数量
|
||||
$rewarded_qty = PrizePool::where('scene', PrizePool::LEVER_TRADE_FEE_ATELIER)
|
||||
->where('sign', 0)
|
||||
->where('status', 1)
|
||||
->where('create_time', '>=', $today)
|
||||
->sum('reward_qty');
|
||||
//奖励是否已达上限
|
||||
if (bc_comp($atelier_reward_day_limit, 0) > 0) {
|
||||
if (bc_comp($rewarded_qty, $atelier_reward_day_limit) >= 0) {
|
||||
return;
|
||||
}
|
||||
//计算还有多少才达到封顶
|
||||
$can_reward_qty = bc_sub($atelier_reward_day_limit, $rewarded_qty);
|
||||
//如果即将奖励的值超过封顶,就抹去多余的奖励,以保证奖励不会超过封顶
|
||||
bc_comp($convert_reward_qty, $can_reward_qty) > 0 && $fact_convert_reward_qty = $can_reward_qty;
|
||||
}
|
||||
|
||||
$fact_reward_qty = bc_mul($fact_convert_reward_qty, $candy_tousdt, 4); //未折合usdt的糖果数量
|
||||
|
||||
$prize_calculator = new CandyCalculator();
|
||||
$prize_sender = new CandySender();
|
||||
$attach_data = [
|
||||
'sign' => $current_level,
|
||||
'extra_data' => serialize([
|
||||
'trade_id' => $trade_id, //交易id
|
||||
'level' => $current_level, //用户是第几级
|
||||
'trade_fee' => $trade_fee, //交易手续费
|
||||
'atelier_reward_day_limit' => $atelier_reward_day_limit, //工作室日奖励上限
|
||||
'atelier_reward_ratio' => $atelier_reward_ratio, //奖励比例
|
||||
'rewarded_qty' => $rewarded_qty, //已奖励数量
|
||||
'can_reward_qty' => $can_reward_qty, //还能拿的奖励数量
|
||||
'convert_reward_qty' => $convert_reward_qty,
|
||||
'fact_convert_reward_qty' => $fact_convert_reward_qty,
|
||||
'fact_reward_qty' => $fact_reward_qty,
|
||||
]),
|
||||
];
|
||||
try {
|
||||
//插入奖励记录到奖池
|
||||
$prize_pool = PrizePool::calculate(
|
||||
$prize_calculator,
|
||||
PrizePool::LEVER_TRADE_FEE_ATELIER,
|
||||
$fact_reward_qty,
|
||||
$atelier,
|
||||
$user,
|
||||
'工作室' . $current_level . '级用户杠杆交易手续费结算',
|
||||
$attach_data
|
||||
);
|
||||
if (!$prize_pool) {
|
||||
throw new \Exception('交易id:' . $trade_id . ',向第' . $current_level . '级上级(id:' . $atelier->id . ')触发奖励失败');
|
||||
}
|
||||
//发放奖励
|
||||
$receive_result = PrizePool::send($prize_sender, $prize_pool);
|
||||
if (!$receive_result) {
|
||||
throw new \Exception('交易id:' . $trade_id . ',向第' . $current_level . '级上级(id:' . $atelier->id . ')发放奖励失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$path = base_path() . '/storage/logs/reward/lever_trade/atelier/';
|
||||
$filename = date('Ymd') . '.log';
|
||||
file_exists($path) || @mkdir($path);
|
||||
error_log(
|
||||
date('Y-m-d H:i:s') . PHP_EOL . $e->getMessage() . PHP_EOL,
|
||||
3,
|
||||
$path . $filename
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 奖励杠杆交易手续费
|
||||
* @param App\LeverTransaction $lever_trade 杠杆交易
|
||||
* @return void
|
||||
*/
|
||||
public static function rewardLeverTransationFee($lever_trade)
|
||||
{
|
||||
$lever_fee_options = Setting::getValueByKey('lever_fee_options');
|
||||
$lever_fee_options = empty($lever_fee_options) ? [] : unserialize($lever_fee_options);
|
||||
|
||||
//如果没有取到参数直接返回
|
||||
if (count($lever_fee_options) <= 0) {
|
||||
return ;
|
||||
}
|
||||
|
||||
$generations = array_column($lever_fee_options, 'generation');
|
||||
$reward_ratio = array_column($lever_fee_options, 'reward_ratio');
|
||||
$need_has_trades_list = array_column($lever_fee_options, 'need_has_trades');
|
||||
array_multisort($generations, SORT_ASC, SORT_NUMERIC, $lever_fee_options);
|
||||
|
||||
$max_generation = max($generations);
|
||||
|
||||
$from_user_id = $lever_trade->user_id;
|
||||
$trade_fee = $lever_trade->trade_fee;
|
||||
$trade_id = $lever_trade->id;
|
||||
|
||||
$from_user = Users::find($from_user_id);
|
||||
$parents = UserDAO::getParentsPathDesc($from_user, $max_generation);
|
||||
|
||||
$prize_calculator = new CandyCalculator();
|
||||
$prize_sender = new CandySender();
|
||||
|
||||
foreach ($parents as $key => $value) {
|
||||
try {
|
||||
$current_level = $key + 1; //当前用户是受奖励用户的第几级
|
||||
$has_trade_num = 0; //当前用户交易笔数
|
||||
$need_has_trades = 0; //当前用户需要交易的笔数
|
||||
if (!in_array($current_level, $generations)) {
|
||||
continue;
|
||||
}
|
||||
$v_key = array_search($current_level, $generations); //查询键值
|
||||
|
||||
$need_has_trades = $need_has_trades_list[$v_key];
|
||||
$current_rebate_ratio = $reward_ratio[$v_key];
|
||||
$current_user = Users::find($value);
|
||||
if (!$current_user) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$candy_number = bc_div(bc_mul($trade_fee, $current_rebate_ratio), 100, 4);
|
||||
$attach_data = [
|
||||
'sign' => $current_level,
|
||||
'extra_data' => serialize([
|
||||
'trade_id' => $trade_id, //交易id
|
||||
'level' => $current_level, //用户是第几级
|
||||
'trade_fee' => $trade_fee, //交易手续费
|
||||
'current_rebate_ratio' => $current_rebate_ratio, //奖励比例
|
||||
]),
|
||||
];
|
||||
//检测当前用户有没有自行体验X笔
|
||||
$has_trade_num = LeverTransaction::where('user_id', $value)
|
||||
->whereIn('status', [1, 2, 3])
|
||||
->count();
|
||||
if ($has_trade_num < $need_has_trades) {
|
||||
continue;
|
||||
}
|
||||
//插入奖励记录到奖池
|
||||
$prize_pool = PrizePool::calculate(
|
||||
$prize_calculator,
|
||||
PrizePool::LEVER_TRADE_FEE,
|
||||
$candy_number,
|
||||
$current_user,
|
||||
$from_user,
|
||||
$current_level . '级用户杠杆交易手续费结算',
|
||||
$attach_data
|
||||
);
|
||||
if (!$prize_pool) {
|
||||
throw new \Exception('交易id:' . $trade_id . ',向第' . $current_level . '级上级(id:' . $current_user->id . ')触发奖励失败');
|
||||
}
|
||||
//发放奖励
|
||||
$receive_result = PrizePool::send($prize_sender, $prize_pool);
|
||||
if (!$receive_result) {
|
||||
throw new \Exception('交易id:' . $trade_id . ',向第' . $current_level . '级上级(id:' . $current_user->id . ')发放奖励失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$path = base_path() . '/storage/logs/reward/lever_trade/';
|
||||
$filename = date('Ymd') . '.log';
|
||||
file_exists($path) || @mkdir($path);
|
||||
error_log(
|
||||
date('Y-m-d H:i:s') . PHP_EOL . $e->getMessage() . PHP_EOL,
|
||||
3,
|
||||
$path . $filename
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取转账次数对应的积分奖励比例
|
||||
*
|
||||
* @param integer $transfer_out_times
|
||||
* @return float 返回奖励比例(百分比,需要自己除以100)
|
||||
*/
|
||||
public static function getRatioByTurnsOutTimes($transfer_out_times)
|
||||
{
|
||||
$times_ratio = Setting::getValueByKey('transfer_out_ratio');
|
||||
empty($times_ratio) || $times_ratio = unserialize($times_ratio);
|
||||
$fact_ratio = self::getDataByRangeValue($times_ratio, $transfer_out_times);
|
||||
return $fact_ratio;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取范围内对应的值
|
||||
*
|
||||
* @param array $ratio_array 比例数组
|
||||
* @param float $compare_value 要比较的值
|
||||
* @return float
|
||||
*/
|
||||
public static function getDataByRangeValue($ratio_array, $compare_value)
|
||||
{
|
||||
$fact_data = reset($ratio_array); //先给个默认值
|
||||
krsort($ratio_array);
|
||||
foreach ($ratio_array as $key => $value) {
|
||||
if ($compare_value >= $key) {
|
||||
$fact_data = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $fact_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 静态奖
|
||||
*
|
||||
* @param App\Users $user 用户模型实例
|
||||
* @return bool 成功返回真,失败返回假
|
||||
*/
|
||||
public static function staticReward($user)
|
||||
{
|
||||
$today = strtotime(date('Y-m-d'));
|
||||
$static_day_release_ratio = Setting::getValueByKey('static_day_release_ratio');
|
||||
//先通过时间戳判断用户是否领取过
|
||||
if ($user->static_time > $today) {
|
||||
return false;
|
||||
}
|
||||
//再通过记录判断用户是否领取过
|
||||
$count = AccountLog::where('type', AccountLog::DAY_STATIC_RELEASE)
|
||||
->where('created_time', '>=', $today)
|
||||
->where('user_id', $user->id)
|
||||
->count();
|
||||
$count || $count = 0;
|
||||
if ($count > 0) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
DB::transaction(function () use ($user, $static_day_release_ratio) {
|
||||
$release_balance = round($user->integral * $static_day_release_ratio / 100, 5);
|
||||
$result = release_user_integral($user, $release_balance, AccountLog::DAY_STATIC_RELEASE, '每日静态释放奖励');
|
||||
if (!$result) {
|
||||
throw new \Exception('释放积分失败');
|
||||
}
|
||||
$user->static_time = time();
|
||||
$user->save(); //更新用户的静态奖领取时间
|
||||
});
|
||||
return true;
|
||||
} catch(\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额转出级差奖
|
||||
*
|
||||
* @param app\Users $user 用户模型
|
||||
* @param float $transfer_out_qty 转出数量
|
||||
* @return bool
|
||||
*/
|
||||
public static function levelDifferenceReward($user, $transfer_out_qty)
|
||||
{
|
||||
$parents = UserDAO::getParentsPathDesc($user);
|
||||
$times_ratio = Setting::getValueByKey('transfer_out_ratio');
|
||||
$times_ratio = empty($times_ratio) ? [] : unserialize($times_ratio);
|
||||
krsort($times_ratio);
|
||||
$max_ratio = reset($times_ratio);
|
||||
$current_max = self::getRatioByTurnsOutTimes($user->transfer_out_times); //取转账人的比例
|
||||
rsort($parents);
|
||||
$param = compact('times_ratio', 'max_ratio', 'current_max');
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
foreach ($parents as $key => $value) {
|
||||
$parent = Users::find($value);
|
||||
if (!$parent) {
|
||||
abort(400, '用户id:' . $user->id . '的上级(id:' . $value . ')不存在');
|
||||
return false;
|
||||
}
|
||||
$transfer_out_times = $parent->transfer_out_times; //转出次数
|
||||
$current_ratio = self::getRatioByTurnsOutTimes($transfer_out_times); //根据转出次数算出比例
|
||||
if ($current_max >= $current_ratio) {
|
||||
continue;
|
||||
}
|
||||
$fact_ratio = $current_ratio - $current_max; //比例差
|
||||
$param = compact('current_max', 'current_ratio', 'transfer_out_times', 'fact_ratio');
|
||||
$fact_reward_qty = $transfer_out_qty * $fact_ratio / 100; //应奖励的积分
|
||||
//向当前用户的钱包返比例差的积分
|
||||
$result = change_user_money($parent, 2, $fact_reward_qty, AccountLog::TRANSFER_OUT_LEVEL_DIFFERENCE_REWARD_INTEGRAL,'转出级差奖励积分');
|
||||
if ($result !== true) {
|
||||
throw new \Exception('释放积分到余额失败:' . $result);
|
||||
}
|
||||
$current_max = $current_ratio; //改变指针
|
||||
if ($current_max == $max_ratio) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
echo '<pre>';
|
||||
echo '错误:' . $e->getMessage() . PHP_EOL . ',文件:' . $e->getFile() . PHP_EOL . '行号:'. $e->getLine();
|
||||
DB::rollBack();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额兑换积分奖励(加速释放)
|
||||
*
|
||||
* @param app\common\model\User $user 用户模型
|
||||
* @param float $exchange_qty 兑换数量
|
||||
*/
|
||||
public static function exchangeReward($user, $exchange_qty)
|
||||
{
|
||||
$path = UserDAO::getParentsPathDesc($user, 20);
|
||||
//array_shift($path); //删除直推上级
|
||||
if (count($path) < 1) {
|
||||
return false;
|
||||
}
|
||||
DB::beginTransaction();
|
||||
foreach ($path as $key => $value) {
|
||||
$fact_ratio = 0;
|
||||
$current_generations = $key + 1; //因为key从0开始所以加1;
|
||||
$parent = Users::find($value);
|
||||
//取当前被触发用户的级别
|
||||
$parent_level = $parent->level->code;
|
||||
if ($parent_level <= 1) {
|
||||
//普通会员不享受动态奖
|
||||
continue;
|
||||
}
|
||||
//根据代数来决定比例
|
||||
$can_generations = $parent->level->generations['exchange'];
|
||||
if ($can_generations < $current_generations) {
|
||||
//当前被触发人级别不能拿超过自己级别对应的代数
|
||||
continue;
|
||||
}
|
||||
if ($parent_level == 2 && $current_generations == 1) {
|
||||
//直推奖:根据直推人数来决定比例
|
||||
$children_qty = Users::where('parent_id', $value)->count();
|
||||
$children_qty || $children_qty = 0;
|
||||
$exchange_recommend_ratio = Setting::getValueByKey('exchange_recommend_ratio');
|
||||
$exchange_recommend_ratio = empty($exchange_recommend_ratio) ? [] : unserialize($exchange_recommend_ratio);
|
||||
$fact_ratio = self::getDataByRangeValue($exchange_recommend_ratio, $children_qty);
|
||||
} else {
|
||||
$ratio = Setting::getValueByKey('exchange_generations_ratio'); //取每一代对应的比例
|
||||
$ratio = empty($ratio) ? [] : unserialize($ratio);
|
||||
$fact_ratio = self::getDataByRangeValue($ratio, $current_generations);
|
||||
}
|
||||
$fact_reward_qty = round($exchange_qty * $fact_ratio / 100, 5);
|
||||
//奖励不能超过积分
|
||||
$before_integral = $parent->integral;
|
||||
$before_integral < $fact_reward_qty && $fact_reward_qty = $parent->integral;
|
||||
if ($fact_reward_qty == 0) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$result = release_user_integral($parent, $fact_reward_qty, AccountLog::BALANCE_EXCHANGE_INTEGRAL_REWARD, '余额兑换积分奖励:');
|
||||
if (!$result) {
|
||||
throw new \Exception('释放积分到余额失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
echo '<pre>';
|
||||
echo '错误:' . $e->getMessage() . PHP_EOL . ',文件:' . $e->getFile() . PHP_EOL . '行号:'. $e->getLine();
|
||||
DB::rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额增加奖励(转入加速释放)
|
||||
*
|
||||
* @param app\common\model\User $user 用户模型
|
||||
* @param float $add_qty 兑换数量
|
||||
* @return bool 成功返回真,否则假
|
||||
*/
|
||||
public static function balanceAddReward($user, $add_qty)
|
||||
{
|
||||
$path = UserDAO::getParentsPathDesc($user, 20);
|
||||
if (count($path) < 1) {
|
||||
return false;
|
||||
}
|
||||
DB::beginTransaction();
|
||||
foreach ($path as $key => $value) {
|
||||
$fact_ratio = 0;
|
||||
$current_generations = $key + 1; //因为key从0开始所以加1;
|
||||
$parent = Users::find($value);
|
||||
//取当前被触发用户的级别
|
||||
$parent_level = $parent->level->code;
|
||||
if ($parent_level <= 1) {
|
||||
//普通会员不享受动态奖
|
||||
continue;
|
||||
}
|
||||
$can_generations = $parent->level->generations['balance_add'];
|
||||
if ($can_generations < $current_generations) {
|
||||
//当前被触发人级别不能拿超过自己级别对应的代数
|
||||
continue;
|
||||
}
|
||||
if ($parent_level == 2 && $current_generations == 1) {
|
||||
//直推奖:根据直推人数来决定比例
|
||||
$children_qty = Users::where('parent_id', $value)->count();
|
||||
$children_qty || $children_qty = 0;
|
||||
$balanceadd_recommend_ratio = Setting::getValueByKey('balanceadd_recommend_ratio');
|
||||
$balanceadd_recommend_ratio = empty($balanceadd_recommend_ratio) ? [] : unserialize($balanceadd_recommend_ratio);
|
||||
$fact_ratio = self::getDataByRangeValue($balanceadd_recommend_ratio, $children_qty);
|
||||
} else {
|
||||
//根据代数来决定比例
|
||||
$ratio = Setting::getValueByKey('balanceadd_generations_ratio'); //取每一代对应的比例
|
||||
$ratio = empty($ratio) ? [] : unserialize($ratio);
|
||||
$fact_ratio = self::getDataByRangeValue($ratio, $current_generations);
|
||||
}
|
||||
$fact_reward_qty = round($add_qty * $fact_ratio / 100, 5);
|
||||
//奖励不能超过积分
|
||||
$before_integral = $parent->integral;
|
||||
$before_integral < $fact_reward_qty && $fact_reward_qty = $parent->integral;
|
||||
if ($fact_reward_qty == 0) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$result = release_user_integral($parent, $fact_reward_qty, AccountLog::TRANSFER_IN_PARENTS_REWARD_INTEGRAL, '余额转入奖励:');
|
||||
if (!$result) {
|
||||
throw new \Exception('释放积分到余额失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
echo '<pre>';
|
||||
echo '错误:' . $e->getMessage() . PHP_EOL . ',文件:' . $e->getFile() . PHP_EOL . '行号:'. $e->getLine();
|
||||
DB::rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额减少奖励(转出加速释放)
|
||||
*
|
||||
* @param app\common\model\User $user 用户模型
|
||||
* @param float $sub_qty 兑换数量
|
||||
* @return bool 成功返回真,否则假
|
||||
*/
|
||||
public static function balanceSubReward($user, $sub_qty)
|
||||
{
|
||||
$parents = UserDAO::getParentsPathDesc($user, 15);//查询用户的指定代数的上级(根据parents_path信息),$qty 要取的上级代数,不传或传null则取全部
|
||||
if (count($parents) < 1) {
|
||||
return false;
|
||||
}
|
||||
$fact_ratio = Setting::getValueByKey('balance_sub_ratio');
|
||||
DB::beginTransaction();
|
||||
foreach ($parents as $key => $value) {
|
||||
$current_generations = $key + 1; //因为key从0开始所以加1;
|
||||
$parent = Users::find($value);
|
||||
//取当前被触发用户的级别
|
||||
$parent_level = $parent->level->code;
|
||||
$can_generations = $parent->level->generations['balance_sub'];
|
||||
if ($parent_level <= 1 || $can_generations < $current_generations) {
|
||||
//普通会员不享受动态奖
|
||||
continue;
|
||||
}
|
||||
$fact_reward_qty = round($sub_qty * $fact_ratio / 100, 5);
|
||||
if ($fact_reward_qty == 0) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$result = change_user_money($parent, 2, $fact_reward_qty, AccountLog::TRANSFER_OUT_PARENTS_REWARD_INTEGRAL, '余额减少上级奖励-增加积分');
|
||||
if ($result !== true) {
|
||||
throw new \Exception('奖励积分失败(余额转出上级奖励)'. $result);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平级余额减少奖励积分(暂且只有转出)
|
||||
*
|
||||
* @param app\common\model\User $user 转出用户模型
|
||||
* @param float $qty 数量
|
||||
*/
|
||||
public static function equalLevelReward($user, $qty)
|
||||
{
|
||||
$parents = UserDAO::getParentsPathDesc($user);
|
||||
if (count($parents) < 1) {
|
||||
return false;
|
||||
}
|
||||
$userlevel = $user->level->code;
|
||||
$fact_ratio = Setting::getValueByKey('equal_level_ratio');
|
||||
DB::beginTransaction();
|
||||
foreach ($parents as $key => $value) {
|
||||
$current_generations = $key + 1;
|
||||
//取当前被触发用户的级别
|
||||
$parent = Users::find($value);
|
||||
$parent_level = $parent->level->code;
|
||||
$can_generations = $parent->level->generations['equal_level'];
|
||||
if ($parent_level <= 1 || $can_generations < $current_generations || $userlevel != $parent_level) {
|
||||
//当前被触发人级别不能拿超过自己级别对应的代数,或者不是平级
|
||||
continue;
|
||||
}
|
||||
$fact_reward_qty = round($qty * $fact_ratio / 100, 4);
|
||||
try {
|
||||
$result = change_user_money($parent, 2, $fact_reward_qty, AccountLog::TRANSFER_OUT_EQUALLEVEL_REWARD_INTEGRAL, '余额减少平级奖励-增加积分');
|
||||
if ($result !== true) {
|
||||
throw new \Exception('奖励积分失败(余额转出平级奖励):' . $result);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
namespace App\DAO;
|
||||
|
||||
|
||||
use App\DAO\Lib\mail;
|
||||
|
||||
class SubmailMailSend
|
||||
{
|
||||
|
||||
protected $configs;
|
||||
|
||||
protected $To = array();
|
||||
|
||||
protected $Addressbook = array();
|
||||
|
||||
protected $From = '';
|
||||
|
||||
protected $From_name = '';
|
||||
|
||||
protected $Reply = '';
|
||||
|
||||
protected $Cc = array();
|
||||
|
||||
protected $Bcc = array();
|
||||
|
||||
protected $Subject = '';
|
||||
|
||||
protected $Text = '';
|
||||
|
||||
protected $Html = '';
|
||||
|
||||
protected $Vars = array();
|
||||
|
||||
protected $Links = array();
|
||||
|
||||
protected $Attachments = array();
|
||||
|
||||
protected $Headers = array();
|
||||
|
||||
protected $asynchronous = "false";
|
||||
|
||||
|
||||
function __construct($configs)
|
||||
{
|
||||
$this->configs = $configs;
|
||||
}
|
||||
|
||||
public function AddTo($address, $name = '')
|
||||
{
|
||||
array_push($this->To, array('address' => $address, 'name' => $name));
|
||||
}
|
||||
|
||||
public function AddAddressbook($addressbook)
|
||||
{
|
||||
array_push($this->Addressbook, $addressbook);
|
||||
}
|
||||
|
||||
public function SetSender($sender, $name = '')
|
||||
{
|
||||
$this->From = $sender;
|
||||
$this->From_name = $name;
|
||||
}
|
||||
|
||||
public function SetReply($reply)
|
||||
{
|
||||
$this->Reply = $reply;
|
||||
}
|
||||
|
||||
public function AddCc($address, $name = '')
|
||||
{
|
||||
array_push($this->Cc, array('address' => $address, 'name' => $name));
|
||||
}
|
||||
|
||||
public function AddBcc($address, $name = '')
|
||||
{
|
||||
array_push($this->Bcc, array('address' => $address, 'name' => $name));
|
||||
}
|
||||
|
||||
public function SetSubject($subject)
|
||||
{
|
||||
$this->Subject = $subject;
|
||||
}
|
||||
|
||||
public function SetText($text)
|
||||
{
|
||||
$this->Text = $text;
|
||||
}
|
||||
|
||||
public function SetHtml($html)
|
||||
{
|
||||
$this->Html = $html;
|
||||
}
|
||||
|
||||
public function AddVar($key, $val)
|
||||
{
|
||||
$this->Vars[$key] = $val;
|
||||
}
|
||||
|
||||
public function AddLink($key, $val)
|
||||
{
|
||||
$this->Links[$key] = $val;
|
||||
}
|
||||
|
||||
public function AddAttachment($attachment)
|
||||
{
|
||||
array_push($this->Attachments, $attachment);
|
||||
}
|
||||
|
||||
public function AddHeaders($key, $val)
|
||||
{
|
||||
$this->Headers[$key] = $val;
|
||||
}
|
||||
|
||||
public function setAsynchronous($asynchronous)
|
||||
{
|
||||
if ($asynchronous == true) {
|
||||
$this->asynchronous = true;
|
||||
} else {
|
||||
$this->asynchronous = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected function buildRequest()
|
||||
{
|
||||
$request = array();
|
||||
if (!empty($this->To)) {
|
||||
$request['to'] = '';
|
||||
foreach ($this->To as $tmp) {
|
||||
$request['to'] .= $tmp['name'] . '<' . $tmp['address'] . '>,';
|
||||
}
|
||||
$request['to'] = substr($request['to'], 0, strlen($request['to']) - 1);
|
||||
//dd($request['to']);
|
||||
}
|
||||
if (!empty($this->Addressbook)) {
|
||||
$request['addressbook'] = '';
|
||||
foreach ($this->Addressbook as $tmp) {
|
||||
$request['addressbook'] .= $tmp . ',';
|
||||
}
|
||||
$request['addressbook'] = substr($request['addressbook'], 0, strlen($request['addressbook']) - 1);
|
||||
}
|
||||
$request['from'] = $this->From;
|
||||
if ($this->From_name != '') {
|
||||
$request['from_name'] = $this->From_name;
|
||||
}
|
||||
if ($this->Reply != '') {
|
||||
$request['reply'] = $this->Reply;
|
||||
}
|
||||
if (!empty($this->Cc)) {
|
||||
$request['cc'] = '';
|
||||
foreach ($this->Cc as $tmp) {
|
||||
$request['cc'] .= $tmp['name'] . '<' . $tmp['address'] . '>,';
|
||||
}
|
||||
$request['cc'] = substr($request['cc'], 0, strlen($request['cc']) - 1);
|
||||
}
|
||||
if (!empty($this->Bcc)) {
|
||||
$request['bcc'] = '';
|
||||
foreach ($this->Bcc as $tmp) {
|
||||
$request['bcc'] .= $tmp['name'] . '<' . $tmp['address'] . '>,';
|
||||
}
|
||||
$request['bcc'] = substr($request['bcc'], 0, strlen($request['bcc']) - 1);
|
||||
}
|
||||
$request['subject'] = $this->Subject;
|
||||
if ($this->Text != '') {
|
||||
$request['text'] = $this->Text;
|
||||
}
|
||||
|
||||
if ($this->Html != '') {
|
||||
$request['html'] = $this->Html;
|
||||
}
|
||||
|
||||
if (!empty($this->Vars)) {
|
||||
$request['vars'] = json_encode($this->Vars);
|
||||
}
|
||||
|
||||
if (!empty($this->Links)) {
|
||||
$request['links'] = json_encode($this->Links);
|
||||
}
|
||||
|
||||
if (!empty($this->Attachments)) {
|
||||
for ($i = 0; $i < count($this->Attachments); $i++) {
|
||||
//$request['attachments['.$i.']']="@".$this->Attachments[$i];
|
||||
$request['attachments[' . $i . ']'] = curl_file_create($this->Attachments[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->asynchronous)) {
|
||||
$request['asynchronous'] = $this->asynchronous;
|
||||
}
|
||||
|
||||
if (!empty($this->Headers)) {
|
||||
$request['headers'] = json_encode($this->Headers);
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
public function send()
|
||||
{
|
||||
$mail = new mail($this->configs);
|
||||
return $mail->send($this->buildRequest());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace App\DAO;
|
||||
|
||||
use Qiniu\Storage\UploadManager;
|
||||
use Qiniu\Auth;
|
||||
use App\Setting;
|
||||
|
||||
class UploaderDAO
|
||||
{
|
||||
|
||||
private static $stateMap = [ //上传状态映射表,国际化用户需考虑此处数据的国际化
|
||||
"SUCCESS", //上传成功标记,在UEditor中内不可改变,否则flash判断会出错
|
||||
"文件大小超出 upload_max_filesize 限制",
|
||||
"文件大小超出 MAX_FILE_SIZE 限制",
|
||||
"文件未被完整上传",
|
||||
"没有文件被上传",
|
||||
"上传文件为空",
|
||||
"ERROR_TMP_FILE" => "临时文件错误",
|
||||
"ERROR_TMP_FILE_NOT_FOUND" => "找不到临时文件",
|
||||
"ERROR_SIZE_EXCEED" => "文件大小超出网站限制",
|
||||
"ERROR_TYPE_NOT_ALLOWED" => "文件类型不允许",
|
||||
"ERROR_CREATE_DIR" => "目录创建失败",
|
||||
"ERROR_DIR_NOT_WRITEABLE" => "目录没有写权限",
|
||||
"ERROR_FILE_MOVE" => "文件保存时出错",
|
||||
"ERROR_FILE_NOT_FOUND" => "找不到上传文件",
|
||||
"ERROR_WRITE_CONTENT" => "写入文件内容错误",
|
||||
"ERROR_UNKNOWN" => "未知错误",
|
||||
"ERROR_DEAD_LINK" => "链接不可用",
|
||||
"ERROR_HTTP_LINK" => "链接不是http链接",
|
||||
"ERROR_HTTP_CONTENTTYPE" => "链接contentType不正确",
|
||||
"INVALID_URL" => "非法 URL",
|
||||
"INVALID_IP" => "非法 IP"
|
||||
];
|
||||
|
||||
/**
|
||||
* 上传错误检查
|
||||
* @param string $errCode
|
||||
* @return string
|
||||
*/
|
||||
public static function getStateInfo($errCode)
|
||||
{
|
||||
return !self::$stateMap[$errCode] ? self::$stateMap["ERROR_UNKNOWN"] : self::$stateMap[$errCode];
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
* @param \Illuminate\Http\UploadedFile $file
|
||||
* @return array
|
||||
*/
|
||||
public static function fileUpload($file, $scene = '')
|
||||
{
|
||||
//读取上传参数
|
||||
$upload_file_size = intval(Setting::getValueByKey('upload_file_size', 0));
|
||||
$upload_file_ext_list = Setting::getValueByKey('upload_file_ext_list');
|
||||
$upload_file_ext_list == '' && $upload_file_ext_list = 'png,jpg,jpeg,gif,bmp';
|
||||
//文件大小判断
|
||||
$upload_file_size *= 1048576; //文件上传最大
|
||||
$filesize = $file->getSize();
|
||||
$filename = $file->getFilename();
|
||||
$origin = $file->getClientOriginalName();
|
||||
$ext = $file->guessExtension();
|
||||
empty($scene) || $scene .= '/';
|
||||
|
||||
//文件扩展名判断
|
||||
$upload_file_ext_list = explode(',', strtolower(str_replace(' ', '', $upload_file_ext_list)));
|
||||
|
||||
if (!in_array($ext, $upload_file_ext_list)) {
|
||||
return [
|
||||
'state' => self::getStateInfo('ERROR_TYPE_NOT_ALLOWED'),
|
||||
'url' => '',
|
||||
'title' => $filename,
|
||||
'original' => $origin,
|
||||
'type' => '.' . $ext,
|
||||
'size' => $filesize,
|
||||
];
|
||||
}
|
||||
//文件大小校验
|
||||
if ($upload_file_size > 0 && $filesize > $upload_file_size) {
|
||||
return [
|
||||
'state' => self::getStateInfo('ERROR_SIZE_EXCEED'),
|
||||
'url' => '',
|
||||
'title' => $filename,
|
||||
'original' => $origin,
|
||||
'type' => '.' . $ext,
|
||||
'size' => $filesize,
|
||||
];
|
||||
}
|
||||
//读取存储参数
|
||||
$use_qiniu_storage = Setting::getValueByKey('use_qiniu_storage', 0);
|
||||
$qiniu_url = Setting::getValueByKey('qiniu_url', '');
|
||||
$access_key = Setting::getValueByKey('qiniu_access_key', '');
|
||||
$secret_key = Setting::getValueByKey('qiniu_secret_key', '');
|
||||
$bucket_name = Setting::getValueByKey('qiniu_bucket_name', '');
|
||||
|
||||
$url = $use_qiniu_storage ? $qiniu_url : url('');
|
||||
|
||||
if ($use_qiniu_storage) {
|
||||
$file_obj = new \SplFileObject($file->getPathname());
|
||||
$file_content = $file_obj->fread($file->getSize());
|
||||
$upManager = new UploadManager();
|
||||
$auth = new Auth($access_key, $secret_key);
|
||||
$token = $auth->uploadToken($bucket_name);
|
||||
list($ret, $error) = $upManager->put($token, $filename, $file_content);
|
||||
if ($error) {
|
||||
return [
|
||||
'state' => is_string($error) ? $error : $error->message(),
|
||||
'url' => '',
|
||||
'title' => $filename,
|
||||
'original' => $origin,
|
||||
'type' => '.' . $ext,
|
||||
'size' => $filesize,
|
||||
];
|
||||
}
|
||||
$file_url = $url . '/' . $ret['key'];
|
||||
} else {
|
||||
$path = '/upload/' . $scene . date('Ymd') . '/';
|
||||
$full_path = public_path() . $path;
|
||||
file_exists($path) || @mkdir($full_path, 0777, true);
|
||||
$file->move($full_path);
|
||||
|
||||
if($scene =='admin/'){
|
||||
$file_url =$path . $filename;
|
||||
}else{
|
||||
$file_url = $url . $path . $filename;
|
||||
}
|
||||
|
||||
}
|
||||
return [
|
||||
'state' => self::getStateInfo(0),
|
||||
'url' => $file_url,
|
||||
'title' => $filename,
|
||||
'original' => $origin,
|
||||
'type' => '.' . $ext,
|
||||
'size' => $filesize,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,424 @@
|
||||
<?php
|
||||
namespace App\DAO;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\{Users, PrizePool, Setting};
|
||||
use App\DAO\PrizePool\CandySender;
|
||||
use App\Events\RealNameEvent;
|
||||
|
||||
class UserDAO
|
||||
{
|
||||
/**
|
||||
* 检查是否符合升级工作室条件,若符合自动升级
|
||||
*
|
||||
* @param App\Users $user
|
||||
* @return boolean
|
||||
*/
|
||||
public static function checkUpgradeAtelierCondition(&$user) : bool
|
||||
{
|
||||
$user->refresh();
|
||||
//检查自身是否已实名或已经是工作室
|
||||
if ($user->is_realname != 2 || $user->is_atelier == 1) {
|
||||
return false;
|
||||
}
|
||||
$upgrade_atelier_must_has_son = Setting::getValueByKey('upgrade_atelier_must_has_son'); //升级工作室直推实名人数要求
|
||||
$upgrade_atelier_must_team_son = Setting::getValueByKey('upgrade_atelier_must_team_son'); //升级工作室团队实名人数要求
|
||||
$upgrade_atelier_must_team_recharge = Setting::getValueByKey('upgrade_atelier_must_team_recharge'); //升级工作室团队充值金额
|
||||
//检查直推实名人数
|
||||
if ($user->zhitui_real_number < $upgrade_atelier_must_has_son) {
|
||||
return false;
|
||||
}
|
||||
//检查团队实名人数
|
||||
if ($user->real_teamnumber < $upgrade_atelier_must_team_son) {
|
||||
return false;
|
||||
}
|
||||
//检查团队充值金额
|
||||
if ($user->top_upnumber < $upgrade_atelier_must_team_recharge) {
|
||||
return false;
|
||||
}
|
||||
$user->is_atelier = 1;
|
||||
return $user->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户的上级是否有通证变动
|
||||
* @param App\Users $user 用户查询的对象
|
||||
*/
|
||||
public static function addCandyNumber($user)
|
||||
{
|
||||
$parents = self::getParentsPathDesc($user);
|
||||
foreach ($parents as $key => $user_id) {
|
||||
$current_user = Users::find($user_id);//检查该上级是否实名认证过
|
||||
if ($current_user->is_realname == 2) {
|
||||
//该上级实名认证过
|
||||
self::checkUserRealNameReward($current_user); //检查是否符合发奖条件,符合就发放奖励
|
||||
self::checkUpgradeAtelierCondition($current_user); //检查是否符合升级工作室条件
|
||||
} else {
|
||||
//该上级还没实名认证
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测用户是否符合实名奖励
|
||||
*
|
||||
* @param App\Users $user
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkUserRealNameReward(&$user)
|
||||
{
|
||||
if (!$user) {
|
||||
return false;
|
||||
}
|
||||
//获取setting值
|
||||
$real_name_candy = Setting::getValueByKey('real_name_candy', '');
|
||||
$zhitui2_number = Setting::getValueByKey('zhitui2_number', '');
|
||||
$zhitui2_candy = Setting::getValueByKey('zhitui2_candy', '');
|
||||
$zhitui3_number = Setting::getValueByKey('zhitui3_number', '');
|
||||
$zhitui3_real_teamnumber = Setting::getValueByKey('zhitui3_real_teamnumber', '');
|
||||
$zhitui3_top_upnumber = Setting::getValueByKey('zhitui3_top_upnumber', '');
|
||||
$zhitui3_candy = Setting::getValueByKey('zhitui3_candy', '');
|
||||
$zhitui4_number = Setting::getValueByKey('zhitui4_number', '');
|
||||
$zhitui4_real_teamnumber = Setting::getValueByKey('zhitui4_real_teamnumber', '');
|
||||
$zhitui4_top_upnumber = Setting::getValueByKey('zhitui4_top_upnumber', '');
|
||||
$zhitui4_candy = Setting::getValueByKey('zhitui4_candy', '');
|
||||
$zhitui5_number = Setting::getValueByKey('zhitui5_number', '');
|
||||
$zhitui5_real_teamnumber = Setting::getValueByKey('zhitui5_real_teamnumber', '');
|
||||
$zhitui5_top_upnumber = Setting::getValueByKey('zhitui5_top_upnumber', '');
|
||||
$zhitui5_candy = Setting::getValueByKey('zhitui5_candy', '');
|
||||
$zhitui6_number = Setting::getValueByKey('zhitui6_number', '');
|
||||
$zhitui6_real_teamnumber = Setting::getValueByKey('zhitui6_real_teamnumber', '');
|
||||
$zhitui6_top_upnumber = Setting::getValueByKey('zhitui6_top_upnumber', '');
|
||||
$zhitui6_candy = Setting::getValueByKey('zhitui6_candy', '');
|
||||
|
||||
$only = 1;
|
||||
$user->refresh();
|
||||
$push_status = $user->push_status;
|
||||
|
||||
//实名认证过的有效直推人数
|
||||
$real_zhitui = Users::where("is_realname", 2)
|
||||
->where("parent_id", $user->id)
|
||||
->count();
|
||||
|
||||
$user->zhitui_real_number = $real_zhitui ?: 0; //更新直推实名人数
|
||||
$user->real_teamnumber += 1;
|
||||
|
||||
if ($push_status == 1) {
|
||||
if ($real_zhitui >= $zhitui2_number) {
|
||||
$user->candy_number += $zhitui2_candy;
|
||||
$user->push_status = 2;
|
||||
$log_candy_number = $zhitui2_candy;
|
||||
$only = 2;
|
||||
}
|
||||
} elseif ($push_status == 2) {
|
||||
if ($real_zhitui >= $zhitui3_number && $user->real_teamnumber >= $zhitui3_real_teamnumber && $user->top_upnumber >= $zhitui3_top_upnumber) {
|
||||
$user->candy_number += $zhitui3_candy;
|
||||
$user->push_status = 3;
|
||||
$log_candy_number = $zhitui3_candy;
|
||||
$only = 2;
|
||||
}
|
||||
} elseif ($push_status == 3) {
|
||||
if ($real_zhitui >= $zhitui4_number && $user->real_teamnumber >= $zhitui4_real_teamnumber && $user->top_upnumber >= $zhitui4_top_upnumber) {
|
||||
$user->candy_number += $zhitui4_candy;
|
||||
$user->push_status = 4;
|
||||
$log_candy_number = $zhitui4_candy;
|
||||
$only = 2;
|
||||
}
|
||||
} elseif ($push_status == 4) {
|
||||
if ($real_zhitui >= $zhitui5_number && $user->real_teamnumber >= $zhitui5_real_teamnumber && $user->top_upnumber >= $zhitui5_top_upnumber) {
|
||||
$user->candy_number += $zhitui5_candy;
|
||||
$user->push_status = 5;
|
||||
$log_candy_number = $zhitui5_candy;
|
||||
$only = 2;
|
||||
}
|
||||
} elseif ($push_status == 5) {
|
||||
if ($real_zhitui >= $zhitui6_number && $user->real_teamnumber >= $zhitui6_real_teamnumber && $user->top_upnumber >= $zhitui6_top_upnumber) {
|
||||
$user->candy_number += $zhitui6_candy;
|
||||
$user->push_status = 6;
|
||||
$log_candy_number = $zhitui6_candy;
|
||||
$only = 2;
|
||||
}
|
||||
}
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
//当天新增实名认证团队人数
|
||||
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
|
||||
if($user->new_isreal_time<$beginToday)
|
||||
{
|
||||
$user->today_real_teamnumber=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$user->today_real_teamnumber=$user->today_real_teamnumber+1;
|
||||
}
|
||||
$user->new_isreal_time=time();
|
||||
|
||||
|
||||
|
||||
$result = $user->save();
|
||||
if (!$result) {
|
||||
throw new \Exception('用户' . $user->account_number . '更新信息失败');
|
||||
}
|
||||
//开始记录日志
|
||||
if ($only == 2) {
|
||||
$prize_pool = new PrizePool();
|
||||
$prize_pool->scene = PrizePool::CERTIFICATION;//const CERTIFICATION = 1; //实名认证奖励
|
||||
$prize_pool->reward_type = PrizePool::REWARD_CANDY;//const REWARD_CANDY = 0; //奖励通证
|
||||
$prize_pool->reward_qty = $log_candy_number;
|
||||
$prize_pool->from_user_id = $user->id;
|
||||
$prize_pool->to_user_id = $user->id;
|
||||
$prize_pool->status = 1;
|
||||
$prize_pool->memo = '下级直推' . $real_zhitui . '人,实名认证团队' . $user->real_teamnumber . '人,充值金额' . $user->top_upnumber . '美金,触发通证奖励' . $log_candy_number;
|
||||
$prize_pool->create_time = time();
|
||||
$prize_pool->receive_time = time();
|
||||
$result = $prize_pool->save();
|
||||
if (!$result) {
|
||||
throw new \Exception('用户' . $user->account_number . '奖励记录失败');
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取用户的上级工作室
|
||||
*
|
||||
* @param App\Users $user
|
||||
* @return App\Users||null
|
||||
*/
|
||||
public static function getParentsAtelier($user)
|
||||
{
|
||||
$parents = UserDAO::getParentsPathDesc($user);
|
||||
//将所有上级工作室查出来
|
||||
$parent_atelier = Users::where('is_atelier', 1)
|
||||
->whereIn('id', $parents)
|
||||
->get();
|
||||
if (count($parent_atelier) <= 0) {
|
||||
return $parent_atelier;
|
||||
}
|
||||
$parents_sort = array_flip($parents);
|
||||
//检测有没有达到封页
|
||||
$sorted = $parent_atelier->sortBy(function ($item, $key) use ($parents_sort) {
|
||||
$sort = $parents_sort[$item->id];
|
||||
return $sort;
|
||||
});
|
||||
$sorted = $sorted->values();
|
||||
return $sorted;
|
||||
}
|
||||
|
||||
//递归查询用户下级所有人数
|
||||
public function GetTeamMember($members, $mid)
|
||||
{
|
||||
$Teams = array();//最终结果
|
||||
$mids = array($mid);//第一次执行时候的用户id
|
||||
do {
|
||||
$othermids = array();
|
||||
$state = false;
|
||||
foreach ($mids as $valueone) {
|
||||
foreach ($members as $key => $valuetwo) {
|
||||
if ($valuetwo['parent_id'] == $valueone && $valuetwo['is_realname'] == 2) //实名认证通过的团队人数
|
||||
{
|
||||
$Teams[] = $valuetwo['id'];//找到我的下级立即添加到最终结果中
|
||||
$othermids[] = $valuetwo['id'];//将我的下级id保存起来用来下轮循环他的下级
|
||||
// array_splice($members,$key,1);//从所有会员中删除他
|
||||
$state = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
$mids = $othermids;//foreach中找到的我的下级集合,用来下次循环
|
||||
} while ($state == true);
|
||||
$Teams = Users::whereIn("id", $Teams)->where("is_realname", "=", 2)->count();
|
||||
|
||||
return $Teams;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户团队充值业绩金额
|
||||
* @param integer $id 用户的id值,用于查询更新该用户上级的团队充值金额
|
||||
* @return $number 充值金额值
|
||||
* * @param integer $qty 要取的上级代数,不传或传null则取全部
|
||||
*/
|
||||
public static function updateTopUpnumber($id, $number, $qty = null)
|
||||
{
|
||||
$user = Users::find($id);
|
||||
$parents = self::getParentsPathDesc($user, $qty);
|
||||
$result = Users::whereIn('id', $parents)->increment('top_upnumber', $number);
|
||||
//此处应再遍历检查一下$parents是否符合升级条件
|
||||
foreach ($parents as $key => $current_user_id) {
|
||||
$current_user = Users::find($current_user_id);
|
||||
if (!$current_user) {
|
||||
continue;
|
||||
}
|
||||
self::checkUserRealNameReward($current_user);
|
||||
self::checkUpgradeAtelierCondition($current_user);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询用户的指定代数的上级(根据parents_path信息)
|
||||
*
|
||||
* @param App\Users $user 用户模型实例
|
||||
* @param integer $qty 要取的上级代数,不传或传null则取全部
|
||||
* @return array 返回包含上级id的数组
|
||||
*/
|
||||
public static function getParentsPathDesc($user, $qty = null)
|
||||
{
|
||||
$path = $user->parents_path;
|
||||
if ($path == null || empty($path)) {
|
||||
return [];
|
||||
}
|
||||
$parents = explode(',', $path);
|
||||
$parents = array_filter($parents);
|
||||
krsort($parents);
|
||||
$parents = array_slice($parents, 0, $qty);
|
||||
return $parents;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归查询上级
|
||||
*
|
||||
* @param App\Users $user 用户模型实例
|
||||
* @return array
|
||||
*/
|
||||
public static function getRealParents($user)
|
||||
{
|
||||
$found_parent_node = [];
|
||||
$parents = self::findParent($user, $found_parent_node);
|
||||
return $parents;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归查询上级(字符串)
|
||||
*
|
||||
* @param App\Users $user 用户模型实例
|
||||
* @return string 返回逗号间隔的path
|
||||
*/
|
||||
public static function getRealParentsPath($user)
|
||||
{
|
||||
$parents = self::getRealParents($user);
|
||||
if (count($parents) > 0) {
|
||||
return implode(',', $parents);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
private static function findParent($user, &$found_parent_node)
|
||||
{
|
||||
$parent_id = $user->parent_id;
|
||||
|
||||
if ($parent_id) {
|
||||
//检测节点关系是否有死循环
|
||||
if (in_array($parent_id, $found_parent_node)) {
|
||||
$context = [
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $parent_id,
|
||||
'found_parent_node' => $found_parent_node,
|
||||
];
|
||||
//记录错误日志
|
||||
Log::useDailyFiles(base_path('storage/logs/user/'), 7);
|
||||
Log::critical('id:' . $user->id . '的用户,上级关系存在死循环', $context);
|
||||
return [];
|
||||
}
|
||||
array_unshift($found_parent_node, $parent_id);
|
||||
$parent = Users::find($parent_id);
|
||||
$result = self::findParent($parent, $found_parent_node);
|
||||
unset($parent);
|
||||
array_push($result, $parent_id);
|
||||
return $result;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否符合对应级别的升级,若符合就升级(不降级)
|
||||
*
|
||||
* @param App\Users $user 要升级的用户模型实例
|
||||
* @param App\Users $from_user 触发者用户模型实例
|
||||
* @return void 无返回值
|
||||
*/
|
||||
public static function upgradeCheck($user)
|
||||
{
|
||||
$before_level = $user->level_id;
|
||||
$new_level = 2;
|
||||
if ($user->is_disable == 1) {
|
||||
$new_level = 1;
|
||||
} else if ($user->total_integral >= 1000000) {
|
||||
$new_level = 5;
|
||||
} else if ($user->total_topup >= 10000) {
|
||||
$new_level = 4;
|
||||
} else if ($user->total_topup >= 300) {
|
||||
$new_level = 3;
|
||||
}
|
||||
|
||||
//查询等级对应的id
|
||||
$level = Level::where('code', $new_level)->first();
|
||||
//不掉级处理
|
||||
if ($before_level < $new_level) {
|
||||
try {
|
||||
DB::transaction(function () use ($user, $level, $before_level, $new_level) {
|
||||
$user_upgrade_log = new UserUpgradeLog();
|
||||
$user_upgrade_log->user_id = $user->id;
|
||||
$user_upgrade_log->from_user_id = $user->id;
|
||||
$user_upgrade_log->before_level = $before_level;
|
||||
$user_upgrade_log->after_level = $new_level;
|
||||
$user_upgrade_log->memo = '用户等级变更:由[' . self::get_level_name($before_level) . ']升级到[' . self::get_level_name($new_level) . ']';
|
||||
$user_upgrade_log->created_time = time();
|
||||
$result = $user_upgrade_log->save();
|
||||
if (!$result) {
|
||||
throw new \Exception('记录用户升级日志失败');
|
||||
}
|
||||
$user->level_id = $level->id;
|
||||
$result = $user->save();
|
||||
if (!$result) {
|
||||
throw new \Exception('变更用户等级失败');
|
||||
}
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
echo '<pre>';
|
||||
echo '错误:' . $e->getMessage() . PHP_EOL . ',文件:' . $e->getFile() . PHP_EOL . '行号:' . $e->getLine();
|
||||
return;
|
||||
}
|
||||
// $parent = Users::find($user->parent_id);
|
||||
// if ($parent) {
|
||||
// self::upgradeCheck($parent, $user);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function get_level_name($id = 2)
|
||||
{
|
||||
|
||||
$name = '';
|
||||
switch ($id) {
|
||||
case 1:
|
||||
$name = '限制会员';
|
||||
break;
|
||||
case 2:
|
||||
$name = '临时会员';
|
||||
break;
|
||||
case 3:
|
||||
$name = '正式会员';
|
||||
break;
|
||||
case 4:
|
||||
$name = '五星会员';
|
||||
break;
|
||||
case 5:
|
||||
$name = 'VIP会员';
|
||||
break;
|
||||
default:
|
||||
$name = '临时会员';
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\BaseModel;
|
||||
|
||||
class Defi extends Model
|
||||
{
|
||||
|
||||
protected $table = "defi";
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\BaseModel;
|
||||
|
||||
class DefiOrder extends Model
|
||||
{
|
||||
|
||||
protected $table = "defi_order";
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DualCurrency extends Model
|
||||
{
|
||||
protected $table = 'dual_currency';
|
||||
public $timestamps = false;
|
||||
protected $appends = ['currency_name'];
|
||||
|
||||
|
||||
public function getCurrencyNameAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Currency', 'id', 'currency_id')->value('name');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\BaseModel;
|
||||
|
||||
class DualList extends Model
|
||||
{
|
||||
|
||||
protected $table = "dual_list";
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DualOrder extends Model
|
||||
{
|
||||
protected $table = 'dual_order';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $appends = ['currency_name','dual_name'];
|
||||
|
||||
|
||||
public function getCurrencyNameAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Currency', 'id', 'currency_id')->value('name');
|
||||
}
|
||||
|
||||
public function getDualNameAttribute()
|
||||
{
|
||||
return $this->hasOne('App\DualCurrency', 'id', 'dual_id')->value('name');
|
||||
}
|
||||
|
||||
public static function random_float($min, $max) {
|
||||
return $min + mt_rand() / mt_getrandmax() * ($max - $min);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class LeverSubmitOrder
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
protected $leverOrder;
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($lever_order)
|
||||
{
|
||||
$this->leverOrder = $lever_order;
|
||||
}
|
||||
|
||||
public function getLeverOrder()
|
||||
{
|
||||
return $this->leverOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return \Illuminate\Broadcasting\Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use App\Users;
|
||||
use App\UserReal;
|
||||
|
||||
class RealNameEvent
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
protected $user;
|
||||
protected $userReal;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Users $user, UserReal $user_real)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->userReal = $user_real;
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function getUserReal()
|
||||
{
|
||||
return $this->userReal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return \Illuminate\Broadcasting\Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class RechargeEvent
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
protected $userId; //用户id
|
||||
|
||||
protected $scene; //充值场景
|
||||
|
||||
protected $number; //充值数量
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($user_id, $scene, $number)
|
||||
{
|
||||
$this->userId = $user_id;
|
||||
$this->scene = $scene;
|
||||
$this->number = $number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取事件参数
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEventParam() : array
|
||||
{
|
||||
$param = [
|
||||
'user_id' => $this->userId,
|
||||
'scene' => $this->scene,
|
||||
'number' => $this->number,
|
||||
];
|
||||
return $param;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return \Illuminate\Broadcasting\Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: swl
|
||||
* Date: 2018/7/3
|
||||
* Time: 10:23
|
||||
*/
|
||||
|
||||
namespace App;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Excate extends Model
|
||||
{
|
||||
protected $table = 'excate';
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of the exception types that are not reported.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontReport = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of the inputs that are never flashed for validation exceptions.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
||||
*
|
||||
* @param \Exception $exception
|
||||
* @return void
|
||||
*/
|
||||
public function report(Exception $exception)
|
||||
{
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Exception $exception
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function render($request, Exception $exception)
|
||||
{
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Users;
|
||||
class FeedBack extends Model
|
||||
{
|
||||
protected $table = 'feedback';
|
||||
public $timestamps = false;
|
||||
protected $appends = ['account_number'];
|
||||
|
||||
public function getCreateTimeAttribute()
|
||||
{
|
||||
return date('Y-m-d H:i:s', $this->attributes['create_time']);
|
||||
}
|
||||
public function getReplyTimeAttribute()
|
||||
{
|
||||
if($this->attributes['reply_time']){
|
||||
return date('Y-m-d H:i:s', $this->attributes['reply_time']);
|
||||
}
|
||||
|
||||
}
|
||||
public static function getNameById($currency_id)
|
||||
{
|
||||
$currency = self::find($currency_id);
|
||||
return $currency->name;
|
||||
}
|
||||
public function getAccountNumberAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Users', 'id', 'user_id')->value('account_number');
|
||||
}
|
||||
// public function getImgAttribute($value)
|
||||
// {
|
||||
// return unserialize($value);
|
||||
// }
|
||||
|
||||
// public function setImgAttribute($value)
|
||||
// {
|
||||
// if (empty($value)) {
|
||||
// $this->attributes['discuss_img'] = "0";
|
||||
// } else {
|
||||
// $this->attributes['discuss_img'] = serialize($value);
|
||||
// }
|
||||
|
||||
// }
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Users', 'user_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class FlashAgainst extends Model
|
||||
{
|
||||
protected $table = 'flash_against';
|
||||
public $timestamps = false;
|
||||
protected $appends = ['status_name','mobile','l_currency','r_currency'];
|
||||
|
||||
public function getMobileAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Users', 'id', 'user_id')->value('account_number');
|
||||
}
|
||||
public function getLCurrencyAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Currency', 'id', 'left_currency_id')->value('name');
|
||||
}
|
||||
public function getRCurrencyAttribute()
|
||||
{
|
||||
return $this->hasOne('App\Currency', 'id', 'right_currency_id')->value('name');
|
||||
}
|
||||
|
||||
protected function getStatusNameAttribute()
|
||||
{
|
||||
$value=$this->attributes['status'];
|
||||
if ($value==0){
|
||||
$str='闪兑中';
|
||||
}elseif ($value==1) {
|
||||
$str='已通过';
|
||||
}elseif ($value==2){
|
||||
$str='已驳回';
|
||||
}else{
|
||||
$str="";
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
public function getCreateTimeAttribute()
|
||||
{
|
||||
return date('Y-m-d H:i:s', $this->attributes['create_time']);
|
||||
}
|
||||
public function getReviewTimeAttribute()
|
||||
{
|
||||
return date('Y-m-d H:i:s', $this->attributes['create_time']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Follow extends Model
|
||||
{
|
||||
protected $table = 'follow';
|
||||
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class HistoricalData extends Model
|
||||
{
|
||||
protected $table = 'historical_data';
|
||||
public $timestamps = false;
|
||||
|
||||
public function getDataAttribute()
|
||||
{
|
||||
$data = $this->attributes['data'];
|
||||
if(!empty($data)){
|
||||
return json_decode($data,true);
|
||||
}else{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
public static function insertData($start,$end,$type = "day"){
|
||||
if(empty($start) || empty($end)) return false;
|
||||
|
||||
$open = 0;
|
||||
$hight = 0;
|
||||
$low = 0;
|
||||
$close = 0;
|
||||
$volume = 0;
|
||||
|
||||
$opend_data = TransactionComplete::where("create_time",">",$start)->where("create_time","<",$end)->orderBy('create_time','asc')->first();
|
||||
if(!empty($opend_data)) $open = $opend_data->price;
|
||||
|
||||
$hight_data = TransactionComplete::where("create_time",">",$start)->where("create_time","<",$end)->orderBy('price','desc')->first();
|
||||
if(!empty($hight_data)) $hight = $hight_data->price;
|
||||
|
||||
$low_data = TransactionComplete::where("create_time",">",$start)->where("create_time","<",$end)->orderBy('price','asc')->first();
|
||||
if(!empty($low_data)) $low = $low_data->price;
|
||||
|
||||
$close_data = TransactionComplete::where("create_time",">",$start)->where("create_time","<",$end)->orderBy('create_time','desc')->first();
|
||||
if(!empty($close_data)) $close = $close_data->price;
|
||||
|
||||
$volume = TransactionComplete::where("create_time",">",$start)->where("create_time","<",$end)->orderBy('create_time','desc')->count();
|
||||
|
||||
$data = array(
|
||||
"timestamp"=>$start,
|
||||
"open"=>$open,
|
||||
"hight"=>$hight,
|
||||
"low"=>$low,
|
||||
"close"=>$close,
|
||||
"volume"=>$volume,
|
||||
);
|
||||
$historical_data = new self();
|
||||
$historical_data->type = $type;
|
||||
$historical_data->start_time = $start;
|
||||
$historical_data->end_time = $end;
|
||||
$historical_data->data = json_encode($data);
|
||||
if($historical_data->save()){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: YSX
|
||||
* Date: 2018/12/4
|
||||
* Time: 19:04
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
|
||||
use App\AgentMoneylog;
|
||||
use App\Users;
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
|
||||
/**结算流水
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function moneyLog()
|
||||
{
|
||||
$start = request()->input('start', '');
|
||||
$end = request()->input('end', '');
|
||||
|
||||
$agentMoneyLog = new AgentMoneylog();
|
||||
|
||||
if ($start && $end) {
|
||||
$start = strtotime($start);
|
||||
$end = strtotime($end);
|
||||
$agentMoneyLog = $agentMoneyLog->whereBetween('created_time', [$start, $end]);
|
||||
}
|
||||
|
||||
$user = Users::find(Users::getUserId());
|
||||
|
||||
$list = $agentMoneyLog->where('agent_id', $user->agent_id)->paginate();
|
||||
return $this->layuiData($list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use App\Agent;
|
||||
use App\AgentAdmin;
|
||||
use App\AgentRole;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Validator;
|
||||
use App\Users;
|
||||
|
||||
|
||||
|
||||
class AgentAdminController extends Controller{
|
||||
|
||||
public function list1(Request $request)
|
||||
{
|
||||
// if(session()->get('admin_is_super') != '1') {
|
||||
// abort(403);
|
||||
// }
|
||||
// var_dump(5436254635);die;
|
||||
$access_token = $request->get('access_token', 0);
|
||||
$adminUses = AgentAdmin::all();
|
||||
return response()->json(['code'=>0,'data'=>$adminUses]);
|
||||
}
|
||||
public function agentadmin_add_show(Request $request){
|
||||
$returnData = AgentRole::get();
|
||||
return $this->ajaxReturn($returnData);
|
||||
}
|
||||
|
||||
public function add(){
|
||||
|
||||
|
||||
if(session()->get('admin_is_super') != '1') {
|
||||
abort(404);
|
||||
}
|
||||
$id = Input::get('id',null);
|
||||
|
||||
if(empty($id)){
|
||||
$adminRole = New AgentAdmin();
|
||||
$adminRole -> is_super = 0;
|
||||
}else{
|
||||
$adminRole = AgentAdmin::find($id);
|
||||
if($adminRole == null) {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
return view('agent.manager.role_add', ['admin_role' => $adminRole]);
|
||||
}
|
||||
|
||||
public function postAdd(){//添加代理商管理员
|
||||
|
||||
$gent_id = Agent::getAgent()->id;
|
||||
// var_dump($gent_id);die;
|
||||
// if(session()->get('admin_is_super') != '1') {
|
||||
// abort(403);
|
||||
// }
|
||||
$id = Input::get('id', null);
|
||||
// var_dump($id);die;
|
||||
$validator = Validator::make(Input::all(), [
|
||||
'username' => 'required',
|
||||
], [
|
||||
'name.required' => '角色名称必须填写',
|
||||
]);
|
||||
|
||||
if(empty($id)) {
|
||||
$adminRole = new AgentAdmin();
|
||||
}else{
|
||||
$adminRole = AgentAdmin::find($id);
|
||||
if($adminRole == null) {
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
$adminRole->username = Input::get('username', '');
|
||||
// $adminRole->is_super = Input::get('is_super', '');
|
||||
$password = Input::get('password', '');
|
||||
$adminRole->role_id = Input::get('role_id', '0');
|
||||
if(Input::get('password', '') != '') {
|
||||
$adminRole->password = Users::MakePassword($password);
|
||||
}
|
||||
$adminRole->agent_id = $gent_id;
|
||||
|
||||
if($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
try {
|
||||
$adminRole->save();
|
||||
}catch (\Exception $ex){
|
||||
$validator->errors()->add('error', $ex->getMessage());
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
return $this->success('添加成功');
|
||||
}
|
||||
|
||||
public function del(Request $request){
|
||||
$id = $request->get('id');
|
||||
$admin_role = AgentAdmin::find($id);
|
||||
$bool = $admin_role->delete();
|
||||
if($bool){
|
||||
return $this->success('删除成功');
|
||||
}else{
|
||||
return $this->error('删除失败');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: YSX
|
||||
* Date: 2018/12/4
|
||||
* Time: 19:08
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
|
||||
use App\Agent;
|
||||
use App\Users;
|
||||
|
||||
class AgentController extends Controller
|
||||
{
|
||||
|
||||
/**代理商信息
|
||||
* 可以传用户id也可以传代理商id
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function info()
|
||||
{
|
||||
$agent_id = request('agent_id', 0);
|
||||
$user_id = request('user_id', Users::getUserId());
|
||||
|
||||
if (!$agent_id && !$user_id) {
|
||||
return $this->error('参数错误');
|
||||
}
|
||||
|
||||
$agent = new Agent();
|
||||
|
||||
if ($agent_id) {
|
||||
$agent = $agent->where('id', $agent_id);
|
||||
}
|
||||
|
||||
if ($user_id) {
|
||||
$user = Users::find($user_id);
|
||||
$agent = $agent->where('id', 0);
|
||||
}
|
||||
|
||||
$agent = $agent->first();
|
||||
|
||||
return $this->success($agent);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: YSX
|
||||
* Date: 2018/12/4
|
||||
* Time: 19:08
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
|
||||
use App\Agent;
|
||||
use App\Users;
|
||||
|
||||
class AgentController extends Controller
|
||||
{
|
||||
|
||||
/**代理商信息
|
||||
* 可以传用户id也可以传代理商id
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function info()
|
||||
{
|
||||
$agent_id = request('agent_id', 0);
|
||||
$user_id = request('user_id', Users::getUserId());
|
||||
|
||||
if (!$agent_id && !$user_id) {
|
||||
return $this->error('参数错误');
|
||||
}
|
||||
|
||||
$agent = new Agent();
|
||||
|
||||
if ($agent_id) {
|
||||
$agent = $agent->where('id', $agent_id);
|
||||
}
|
||||
|
||||
if ($user_id) {
|
||||
$user = Users::find($user_id);
|
||||
$agent = $agent->where('id', 0);
|
||||
}
|
||||
|
||||
$agent = $agent->first();
|
||||
|
||||
return $this->success($agent);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use App\Agent;
|
||||
use App\Users;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
|
||||
class AgentIndexController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* 首页获取统计数据
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getStatistics(Request $request){
|
||||
$access_token = $request->get('access_token', 0);
|
||||
$agent = Agent::getAgentById(session($access_token));
|
||||
|
||||
$agent_id =$agent['id'];
|
||||
$user_id = $agent['user_id'];
|
||||
$data['settlement'] = DB::table('lever_transaction')->where('status' , 2)->where('settled' , 1)->count();//结算订单数量
|
||||
$data['subordinate_agent_num'] = Agent::where('parent_agent_id', $agent_id)->count();//下级代理商数量
|
||||
$data['subordinate_user_num'] = Users::where('parent_id', $user_id)->count();//下级用户数量
|
||||
|
||||
return $this->ajaxReturn($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use App\Agent;
|
||||
use App\AgentRole;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Validator;
|
||||
|
||||
|
||||
|
||||
|
||||
class AgentRoleController extends Controller{
|
||||
|
||||
public function users(Request $request)
|
||||
{
|
||||
// if(session()->get('admin_is_super') != '1') {
|
||||
// abort(403);
|
||||
// }
|
||||
$access_token = $request->get('access_token', 0);
|
||||
$adminUses = AgentRole::all();
|
||||
return response()->json(['code'=>0,'data'=>$adminUses]);
|
||||
}
|
||||
public function show(Request $request){
|
||||
$id = $request->get('id');
|
||||
$returnData = AgentRole::find($id);
|
||||
return $this->ajaxReturn($returnData);
|
||||
}
|
||||
|
||||
public function add(){
|
||||
|
||||
|
||||
if(session()->get('admin_is_super') != '1') {
|
||||
abort(404);
|
||||
}
|
||||
$id = Input::get('id',null);
|
||||
|
||||
if(empty($id)){
|
||||
$adminRole = New AgentRole();
|
||||
$adminRole -> is_super = 0;
|
||||
}else{
|
||||
$adminRole = AgentRole::find($id);
|
||||
if($adminRole == null) {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
return view('agent.manager.role_add', ['admin_role' => $adminRole]);
|
||||
}
|
||||
|
||||
public function postAdd(){
|
||||
|
||||
$gent_id = Agent::getAgent()->id;
|
||||
// var_dump($gent_id);die;
|
||||
// if(session()->get('admin_is_super') != '1') {
|
||||
// abort(403);
|
||||
// }
|
||||
$id = Input::get('id', null);
|
||||
// var_dump($id);die;
|
||||
$validator = Validator::make(Input::all(), [
|
||||
'name' => 'required',
|
||||
], [
|
||||
'name.required' => '角色名称必须填写',
|
||||
]);
|
||||
|
||||
if(empty($id)) {
|
||||
$adminRole = new AgentRole();
|
||||
}else{
|
||||
$adminRole = AgentRole::find($id);
|
||||
if($adminRole == null) {
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
$adminRole->name = Input::get('name', '');
|
||||
$adminRole->is_super = Input::get('is_super', '');
|
||||
$adminRole->agent_id = $gent_id;
|
||||
|
||||
if($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
try {
|
||||
$adminRole->save();
|
||||
}catch (\Exception $ex){
|
||||
$validator->errors()->add('error', $ex->getMessage());
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
return $this->success('添加成功');
|
||||
}
|
||||
|
||||
public function del(Request $request){
|
||||
$id = $request->get('id');
|
||||
$admin_role = AgentRole::find($id);
|
||||
$bool = $admin_role->delete();
|
||||
if($bool){
|
||||
return $this->success('删除成功');
|
||||
}else{
|
||||
return $this->error('删除失败');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,231 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\{AccountLog, Agent, Users, UsersWalletOut, Currency, LeverTransaction, UsersWallet, AgentMoneylog};
|
||||
|
||||
class CapitalController extends Controller
|
||||
{
|
||||
|
||||
//充币
|
||||
public function rechargeIndex()
|
||||
{
|
||||
//币币
|
||||
$legal_currencies = Currency::get();
|
||||
//下级代理
|
||||
$son_agents = Agent::getAllChildAgent(Agent::getAgentId());
|
||||
return view("agent.capital.recharge", [
|
||||
'legal_currencies' => $legal_currencies,
|
||||
'son_agents' => $son_agents,
|
||||
]);
|
||||
}
|
||||
|
||||
//提币
|
||||
public function withdrawIndex()
|
||||
{
|
||||
//币币
|
||||
$legal_currencies = Currency::get();
|
||||
//下级代理
|
||||
$son_agents = Agent::getAllChildAgent(Agent::getAgentId());
|
||||
return view("agent.capital.withdraw", [
|
||||
'legal_currencies' => $legal_currencies,
|
||||
'son_agents' => $son_agents,
|
||||
]);
|
||||
}
|
||||
|
||||
public function rechargeList(Request $request)
|
||||
{
|
||||
$limit = $request->input('limit', 20);
|
||||
// $agent = Agent::getAgent();
|
||||
// $child_agents = Agent::getAllChildAgent($agent->id);
|
||||
// $agents = $child_agents->pluck('id')->all();
|
||||
// $child_users = Users::whereIn('agent_note_id', $agents)->get();
|
||||
$agent_id = Agent::getAgentId();
|
||||
$node_users = Users::whereRaw("FIND_IN_SET($agent_id,`agent_path`)")->pluck('id')->all();
|
||||
$lists = AccountLog::whereIn('type', [AccountLog::CHAIN_RECHARGE,AccountLog::WALLET_CURRENCY_IN])
|
||||
//->whereIn('user_id', $child_users->pluck('id')->all())
|
||||
->whereIn('user_id', $node_users)
|
||||
->where(function ($query) use ($request) {
|
||||
|
||||
$account_number = $request->input('account_number', '');
|
||||
$belong_agent = $request->input('belong_agent', '');
|
||||
$currency_id = $request->input('currency_id', -1);
|
||||
|
||||
$query->when($account_number != '', function ($query) use ($account_number) {
|
||||
$query->whereHas('user', function ($query) use ($account_number) {
|
||||
$query->where('account_number', $account_number);
|
||||
});
|
||||
})->when($belong_agent != '', function ($query) use ($belong_agent) {
|
||||
$query->whereHas('user', function ($query) use ($belong_agent) {
|
||||
$query->whereHas('belongAgent', function ($query) use ($belong_agent) {
|
||||
$query->where('username', $belong_agent);
|
||||
});
|
||||
});
|
||||
})->when($currency_id > 0, function ($query) use ($currency_id) {
|
||||
$query->where('currency', $currency_id);
|
||||
});
|
||||
})
|
||||
->orderBy('id', 'desc')
|
||||
->paginate($limit);
|
||||
|
||||
$items = $lists->getCollection();
|
||||
$items->transform(function ($item, $key) {
|
||||
// 设置上级代理商信息
|
||||
$item->setAttribute('belong_agent_name', $item->user->belongAgent->username ?? '');
|
||||
return $item;
|
||||
});
|
||||
$lists->setCollection($items);
|
||||
return $this->layuiData($lists);
|
||||
}
|
||||
|
||||
//提币
|
||||
public function withdrawList(Request $request)
|
||||
{
|
||||
$limit = $request->input('limit', 20);
|
||||
// $agent = Agent::getAgent();
|
||||
// $child_agents = Agent::getAllChildAgent($agent->id);
|
||||
// $agents = $child_agents->pluck('id')->all();
|
||||
// $child_users = Users::whereIn('agent_note_id', $agents)->get();
|
||||
$agent_id = Agent::getAgentId();
|
||||
$node_users = Users::whereRaw("FIND_IN_SET($agent_id,`agent_path`)")->pluck('id')->all();
|
||||
$lists = UsersWalletOut::where('status', 2)
|
||||
//->whereIn('user_id', $child_users->pluck('id')->all())
|
||||
->whereIn('user_id', $node_users)
|
||||
->where(function ($query) use ($request) {
|
||||
|
||||
$account_number = $request->input('account_number', '');
|
||||
$belong_agent = $request->input('belong_agent', '');
|
||||
$currency_id = $request->input('currency_id', -1);
|
||||
|
||||
$query->when($account_number != '', function ($query) use ($account_number) {
|
||||
$query->whereHas('user', function ($query) use ($account_number) {
|
||||
$query->where('account_number', $account_number);
|
||||
});
|
||||
})->when($belong_agent != '', function ($query) use ($belong_agent) {
|
||||
$query->whereHas('user', function ($query) use ($belong_agent) {
|
||||
$query->whereHas('belongAgent', function ($query) use ($belong_agent) {
|
||||
$query->where('username', $belong_agent);
|
||||
});
|
||||
});
|
||||
})->when($currency_id > 0, function ($query) use ($currency_id) {
|
||||
$query->where('currency', $currency_id);
|
||||
});
|
||||
})
|
||||
->orderBy('id', 'desc')
|
||||
->paginate($limit);
|
||||
|
||||
$items = $lists->getCollection();
|
||||
$items->transform(function ($item, $key) {
|
||||
// 设置上级代理商信息
|
||||
if ($item->notes == '') {
|
||||
$item->notes = '用户提币';
|
||||
}
|
||||
$item->setAttribute('belong_agent_name', $item->user->belongAgent->username ?? '');
|
||||
return $item;
|
||||
});
|
||||
$lists->setCollection($items);
|
||||
return $this->layuiData($lists);
|
||||
}
|
||||
|
||||
//用户资金
|
||||
public function wallet(Request $request)
|
||||
{
|
||||
$id = $request->get('id', null);
|
||||
if (empty($id)) {
|
||||
return $this->error('参数错误');
|
||||
}
|
||||
|
||||
return view("agent.capital.wallet", ['user_id' => $id]);
|
||||
}
|
||||
|
||||
public function wallettotalList(Request $request)
|
||||
{
|
||||
$limit = $request->get('limit', 10);
|
||||
$user_id = $request->get('user_id', null);
|
||||
if (empty($user_id)) {
|
||||
return $this->error('参数错误');
|
||||
}
|
||||
|
||||
$list = Currency::orderBy('id', 'asc')->select(['id', 'name'])->paginate($limit);
|
||||
|
||||
foreach ($list->items() as &$value) {
|
||||
$value->_ru = AccountLog::whereIn('type', [AccountLog::CHAIN_RECHARGE,AccountLog::WALLET_CURRENCY_IN])
|
||||
->where('user_id', $user_id)
|
||||
->where('currency', $value->id)
|
||||
->sum('value');
|
||||
|
||||
$value->_chu = UsersWalletOut::where('status', 2)
|
||||
->where('user_id', $user_id)
|
||||
->where('currency', $value->id)
|
||||
->sum('real_number');
|
||||
$change_balance=UsersWallet::where(['user_id'=>$user_id,'currency'=>$value->id])->sum('change_balance');
|
||||
$lock_change_balance=UsersWallet::where(['user_id'=>$user_id,'currency'=>$value->id])->sum('lock_change_balance');
|
||||
$legal_balance=UsersWallet::where(['user_id'=>$user_id,'currency'=>$value->id])->sum('legal_balance');
|
||||
$lock_legal_balance=UsersWallet::where(['user_id'=>$user_id,'currency'=>$value->id])->sum('lock_legal_balance');
|
||||
$lever_balance=UsersWallet::where(['user_id'=>$user_id,'currency'=>$value->id])->sum('lever_balance');
|
||||
$lock_lever_balance=UsersWallet::where(['user_id'=>$user_id,'currency'=>$value->id])->sum('lock_lever_balance');
|
||||
$micro_balance=UsersWallet::where(['user_id'=>$user_id,'currency'=>$value->id])->sum('micro_balance');
|
||||
$lock_micro_balance=UsersWallet::where(['user_id'=>$user_id,'currency'=>$value->id])->sum('lock_micro_balance');
|
||||
$value->_zongyue=$change_balance*1+$lock_change_balance*1+$legal_balance*1+$lock_legal_balance*1+$lever_balance*1+$lock_lever_balance*1+$micro_balance*1+$lock_micro_balance*1;
|
||||
$value->_caution_money = LeverTransaction::where('user_id', $user_id)->whereIn('status', [0, 1, 2])->where('legal', $value->id)->sum('caution_money');
|
||||
}
|
||||
|
||||
return $this->layuiData($list);
|
||||
}
|
||||
|
||||
//结算 提现到账
|
||||
public function walletOut(Request $request)
|
||||
{
|
||||
$id = $request->get('id', '');
|
||||
|
||||
if (!$id) {
|
||||
return $this->error('参数错误');
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$agent_log = AgentMoneylog::lockForUpdate()->find($id);
|
||||
if (empty($agent_log)) {
|
||||
throw new \Exception('操作失败:信息有误');
|
||||
}
|
||||
if ($agent_log->status != 0) {
|
||||
throw new \Exception('操作失败:该账单已提现,请勿重复操作或刷新后重试');
|
||||
}
|
||||
$agent = Agent::find($agent_log->agent_id);
|
||||
if ($agent->is_admin != 1) {
|
||||
$wallet = UsersWallet::where('user_id', $agent->user_id)->where('currency', $agent_log->legal_id)->first();
|
||||
if (empty($wallet)) {
|
||||
throw new \Exception('用户钱包不存在');
|
||||
}
|
||||
if ($agent_log->type == 1) {
|
||||
|
||||
$account_type = AccountLog::AGENT_JIE_TC_MONEY;
|
||||
$account_info = '代理商结算头寸收益 划转到账';
|
||||
} else {
|
||||
$account_type = AccountLog::AGENT_JIE_SX_MONEY;
|
||||
$account_info = '代理商结算手续费收益 划转到账';
|
||||
}
|
||||
$change_result = change_wallet_balance($wallet, 1, $agent_log->change, $account_type, $account_info);
|
||||
if ($change_result !== true) {
|
||||
throw new \Exception($change_result);
|
||||
}
|
||||
} else {
|
||||
throw new \Exception('超级代理商无法提现');
|
||||
}
|
||||
|
||||
|
||||
$agent_log->status = 1; //
|
||||
$agent_log->updated_time = time(); //
|
||||
|
||||
$agent_log->save();
|
||||
|
||||
DB::commit();
|
||||
return $this->success('操作成功:)');
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
return $this->error($ex->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Currency;
|
||||
|
||||
class CommonController extends Controller
|
||||
{
|
||||
public function legalCurrency()
|
||||
{
|
||||
$currencies = Currency::where('is_legal', 1)->get();
|
||||
return $this->ajaxReturn($currencies);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController {
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param string $msg
|
||||
* @param int $code
|
||||
*/
|
||||
public function ajaxReturn( $data = [] , $msg = '' , $code = 0){
|
||||
$result = array(
|
||||
'code' => $code, //0成功,1失败,1001未登录
|
||||
'msg' => $msg, //提示信息
|
||||
'data' => $data //数据或其它信息
|
||||
);
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
* @param string $info
|
||||
* @param int $status
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function success($msg = ''){
|
||||
$result = array(
|
||||
'code' => 0, //0成功,1失败,1001未登录
|
||||
'msg' => $msg, //提示信息
|
||||
'data' => [] //数据或其它信息
|
||||
);
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function error($msg) {
|
||||
$result = array(
|
||||
'code' => 1, //0成功,1失败,1001未登录
|
||||
'msg' => $msg, //提示信息
|
||||
'data' => [] //数据或其它信息
|
||||
);
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param 警告提示。⚠️
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function notice($msg) {
|
||||
$result = array(
|
||||
'code' => 2, //0成功,1失败,1001未登录
|
||||
'msg' => $msg, //提示信息
|
||||
'data' => [] //数据或其它信息
|
||||
);
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
* @param string $info
|
||||
* @param int $status
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function outmsg($msg = ''){
|
||||
$result = array(
|
||||
'code' => 1001, //0成功,1失败,1001未登录
|
||||
'msg' => $msg, //提示信息
|
||||
'data' => [] //数据或其它信息
|
||||
);
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $paginateObj
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function layuiData($paginateObj,$extra_data = ''){
|
||||
if ($paginateObj->total() >=1){
|
||||
return response()->json(['code'=>0,'msg'=>'','count'=>$paginateObj->total(),'data'=>$paginateObj->items(),'extra_data' => $extra_data]);
|
||||
}else{
|
||||
return response()->json(['code'=>1,'msg'=>'暂无数据','count'=>0,'data'=>[],'extra_data' => $extra_data]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController {
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param string $msg
|
||||
* @param int $code
|
||||
*/
|
||||
public function ajaxReturn( $data = [] , $msg = '' , $code = 0){
|
||||
$result = array(
|
||||
'code' => $code, //0成功,1失败,1001未登录
|
||||
'msg' => $msg, //提示信息
|
||||
'data' => $data //数据或其它信息
|
||||
);
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
* @param string $info
|
||||
* @param int $status
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function success($msg = ''){
|
||||
$result = array(
|
||||
'code' => 0, //0成功,1失败,1001未登录
|
||||
'msg' => $msg, //提示信息
|
||||
'data' => [] //数据或其它信息
|
||||
);
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function error($msg) {
|
||||
$result = array(
|
||||
'code' => 1, //0成功,1失败,1001未登录
|
||||
'msg' => $msg, //提示信息
|
||||
'data' => [] //数据或其它信息
|
||||
);
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param 警告提示。⚠️
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function notice($msg) {
|
||||
$result = array(
|
||||
'code' => 2, //0成功,1失败,1001未登录
|
||||
'msg' => $msg, //提示信息
|
||||
'data' => [] //数据或其它信息
|
||||
);
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
* @param string $info
|
||||
* @param int $status
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function outmsg($msg = ''){
|
||||
$result = array(
|
||||
'code' => 1001, //0成功,1失败,1001未登录
|
||||
'msg' => $msg, //提示信息
|
||||
'data' => [] //数据或其它信息
|
||||
);
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $paginateObj
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function layuiData($paginateObj,$extra_data = ''){
|
||||
if ($paginateObj->total() >=1){
|
||||
return response()->json(['code'=>0,'msg'=>'','count'=>$paginateObj->total(),'data'=>$paginateObj->items(),'extra_data' => $extra_data,]);
|
||||
}else{
|
||||
return response()->json(['code'=>1,'msg'=>'暂无数据','count'=>0,'data'=>[],'extra_data' => $extra_data,]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: YSX
|
||||
* Date: 2018/12/4
|
||||
* Time: 17:17
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
|
||||
use App\LeverTransaction;
|
||||
|
||||
class LeverTransactionController extends Controller
|
||||
{
|
||||
|
||||
public function lists()
|
||||
{
|
||||
$user_id = request()->input('user_id', 0);
|
||||
$status = request()->input('status', -1);
|
||||
$type = request()->input('type', -1);
|
||||
|
||||
$where = [];
|
||||
|
||||
$where[] = ['user_id',$user_id];
|
||||
if ($status!=-1) $where[] = ['status', $status];
|
||||
if ($type!=-1) $where[] = ['type', $type];
|
||||
|
||||
$list = LeverTransaction::where($where)->orderBy('id', 'DESC')->paginate();
|
||||
return $this->layuiData($list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,805 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\{Agent, Setting, Users};
|
||||
|
||||
/**
|
||||
* 该类处理所有的代理商添加修改等操作
|
||||
* Class MemberController
|
||||
* @package App\Http\Controllers\Agent
|
||||
*/
|
||||
class MemberController extends Controller
|
||||
{
|
||||
|
||||
private $agent_max_level = 4;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->agent_max_level = Setting::getValueByKey('agent_max_level',4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function login(Request $request)
|
||||
{
|
||||
if ($request->isMethod('post')) {
|
||||
|
||||
$username = $request->input("username", "");
|
||||
$password = $request->input("password", "");
|
||||
|
||||
if (empty($username) || empty($password)) return $this->error("参数错误");
|
||||
$agent = DB::table('agent')->where("username", $username)->first();
|
||||
|
||||
if ($agent == null || empty($agent)) return $this->error("代理商未找到");
|
||||
if ($agent->is_lock == 1) return $this->error("账号被锁定,禁止登录");
|
||||
if (Users::MakePassword($password) != $agent->password) {
|
||||
return $this->error("密码错误");
|
||||
}
|
||||
session()->put('agent_username', $agent->username);
|
||||
|
||||
session()->put('agent_id', $agent->id);
|
||||
|
||||
return $this->success('登录成功!');
|
||||
} else {
|
||||
return $this->error('非法操作!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function logout(Request $request)
|
||||
{
|
||||
$res = Agent::delSession($request);
|
||||
if ($res) {
|
||||
return $this->success('退出成功');
|
||||
} else {
|
||||
return $this->error('退出登录失败,请重试');
|
||||
}
|
||||
}
|
||||
|
||||
//修改密码页面
|
||||
public function setPas()
|
||||
{
|
||||
return view("agent.set.password");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function changePWD(Request $request)
|
||||
{
|
||||
$post = $request->post();
|
||||
|
||||
$oldPassword = $post['oldPassword'];
|
||||
$password = $post['password'];
|
||||
$repassword = $post['repassword'];
|
||||
$is_tong = $post['is_tong'];//是否同步用户密码
|
||||
$agent=Agent::getAgent();
|
||||
|
||||
if(empty($agent)){
|
||||
return $this->error('代理商不存在');
|
||||
}
|
||||
if (mb_strlen($password) < 6 || mb_strlen($password) > 16) {
|
||||
return $this->error('密码只能在6-16位之间');
|
||||
}
|
||||
$now_password = $agent->getOriginal('password');
|
||||
|
||||
$encrypted_password = Users::MakePassword($password);
|
||||
|
||||
if (Users::MakePassword($oldPassword) != $now_password) {
|
||||
return $this->error("老密码错误");
|
||||
}
|
||||
|
||||
if($password !== $repassword) return $this->error('两次密码不一致');
|
||||
if($now_password == $encrypted_password) return $this->error('不能和原密码一致');
|
||||
|
||||
$agent->password = $encrypted_password;
|
||||
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$agent->save();
|
||||
|
||||
if($is_tong ==1){
|
||||
if($agent->is_admin !=1){
|
||||
//同步用户密码
|
||||
$user=Users::find($agent->user_id);
|
||||
if($user){
|
||||
$user->password = $encrypted_password;
|
||||
$user->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
return $this->success('修改成功!');
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
return $this->error($ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
//修改代理商基本信息
|
||||
public function setInfo()
|
||||
{
|
||||
$agent=Agent::getAgent();
|
||||
if(empty($agent)){
|
||||
return $this->error('代理商不存在');
|
||||
}
|
||||
// if($agent->is_admin == 1){
|
||||
// abort(403, '超管无需修改');
|
||||
|
||||
// }
|
||||
return view("agent.set.info",['agent'=>$agent]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取代理用户信息
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getUserInfo(Request $request)
|
||||
{
|
||||
$access_token = $request->get('access_token', 0);
|
||||
|
||||
$agent = Agent::with('user')->where('id', session($access_token))->first();
|
||||
|
||||
if (!$agent) return $this->error('非法参数!');
|
||||
|
||||
return $this->ajaxReturn($agent);
|
||||
}
|
||||
|
||||
|
||||
public function saveUserInfo(Request $request)
|
||||
{
|
||||
$post = $request->post();
|
||||
|
||||
|
||||
$nickname = $post['nickname'];
|
||||
$phone = $post['phone'];
|
||||
$email = $post['email'];
|
||||
$agent=Agent::getAgent();
|
||||
if($agent->is_admin == 1){
|
||||
return $this->error('超级代理商不用设置');
|
||||
|
||||
}
|
||||
$user_id=$agent->user_id;
|
||||
$user = Users::where('id', $user_id)->first();
|
||||
$user->nickname = $nickname;
|
||||
$user->phone = $phone;
|
||||
$user->email = $email;
|
||||
|
||||
try {
|
||||
$user->save();
|
||||
return $this->success('修改成功!');
|
||||
} catch (\Exception $exception) {
|
||||
return $this->error($exception->getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**代理商列表
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function lists(Request $request)
|
||||
{
|
||||
|
||||
$username = $request->input("username", "");
|
||||
$id = $request->input("id", 0);
|
||||
$is_lock = $request->input("is_lock", 2);
|
||||
$is_addson = $request->input("is_addson", 2);
|
||||
$parent_agent_id = $request->input("parent_agent_id", 0);
|
||||
$limit = $request->input("limit", 10);
|
||||
$_self = Agent::getAgent();
|
||||
|
||||
if ($_self === null) {
|
||||
return $this->outmsg('发生错误!请重新登录');
|
||||
}
|
||||
|
||||
$where = [];
|
||||
if (!empty($username)) {
|
||||
$where[] = ['username', '=', $username];
|
||||
|
||||
$_search_us = Agent::getUserByUsername($username);
|
||||
|
||||
if ($_search_us == null) {
|
||||
return $this->error('该代理商不存在');
|
||||
} else {
|
||||
$level_path_Arr = explode(',', $_search_us->agent_path);
|
||||
if (!in_array($_self->id, $level_path_Arr)) {
|
||||
return $this->error('该代理商并不属于您的团队');
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($id > 0) {
|
||||
$where[] = ['id', '=', $id];
|
||||
|
||||
$_search_us = Agent::getAgentById($id);
|
||||
if ($_search_us === null) {
|
||||
return $this->error('该代理商不存在');
|
||||
} else {
|
||||
$level_path_Arr = explode(',', $_search_us->agent_path);
|
||||
if (!in_array($_self->id, $level_path_Arr)) {
|
||||
return $this->error('该代理商并不属于您的团队');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (in_array($is_lock, [0, 1])) {
|
||||
$where[] = ['is_lock', '=', $is_lock];
|
||||
}
|
||||
if (in_array($is_addson, [0, 1])) {
|
||||
$where[] = ['is_addson', '=', $is_addson];
|
||||
}
|
||||
|
||||
if ($parent_agent_id > 0) {
|
||||
$where[] = ['parent_agent_id', '=', $parent_agent_id];
|
||||
} else {
|
||||
$where[] = ['parent_agent_id', '=', $_self->id];
|
||||
}
|
||||
|
||||
$result = Agent::where('status', 1)->where($where)->paginate($limit);
|
||||
|
||||
return $this->layuiData($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加下级代理商时,查询该用户是否存在,是否已经是代理商等
|
||||
*/
|
||||
public function searchuser(Request $request)
|
||||
{
|
||||
|
||||
if ($request->isMethod('post')) {
|
||||
$username = $request->input("username", "");
|
||||
|
||||
$_self = Agent::getAgent();
|
||||
|
||||
if ($_self === null) {
|
||||
return $this->outmsg('发生错误!请重新登录');
|
||||
}
|
||||
|
||||
if (!empty($username) && $_self != null && !empty($_self)) {
|
||||
|
||||
$user = Users::getByAccountNumber($username);
|
||||
if ($user != null) {
|
||||
|
||||
$agent = Agent::getUserByUsername($username);
|
||||
if ($agent === null) {
|
||||
$agent_max_level = Setting::getValueByKey('agent_max_level',4);
|
||||
if (($_self->level == $agent_max_level && $_self->is_admin == 0)) {
|
||||
return $this->notice("您是{$agent_max_level}级代理商,不能添加下级代理商");
|
||||
} else if (($_self->is_addson == 0)) {
|
||||
return $this->notice('您尚未拥有添加下级代理商的权限');
|
||||
} else if (($_self->is_lock == 1)) {
|
||||
return $this->notice('您的代理商帐号被锁定');
|
||||
} else {
|
||||
$returnData = [];
|
||||
$returnData['user_id'] = $user->id;
|
||||
$returnData['username'] = $user->account_number;
|
||||
$returnData['son_level'] = 0;
|
||||
|
||||
if ($_self->level == 0 && $_self->is_admin == 1) {
|
||||
$returnData['son_level'] = 1;
|
||||
} else {
|
||||
$returnData['son_level'] = $_self->level+1;
|
||||
}
|
||||
|
||||
$returnData['max_pro_loss'] = $_self->pro_loss;
|
||||
$returnData['max_pro_ser'] = $_self->pro_ser;
|
||||
|
||||
return $this->ajaxReturn($returnData);
|
||||
}
|
||||
} else {
|
||||
return $this->notice('该用户已经是代理商');
|
||||
}
|
||||
} else {
|
||||
return $this->error('该用户不存在');
|
||||
}
|
||||
} else {
|
||||
return $this->error('该用户不存在');
|
||||
}
|
||||
} else {
|
||||
return $this->error('非法操作!');
|
||||
}
|
||||
}
|
||||
|
||||
//验证下级代理商
|
||||
public function search_agent_son (Request $request) {
|
||||
|
||||
if ($request->isMethod('post')) {
|
||||
$id = $request->input("id", 0);
|
||||
$username = $request->input("username", '');
|
||||
|
||||
if($id <= 0 || $username==''){
|
||||
return $this->error('参数错误');
|
||||
}
|
||||
|
||||
$_self = Agent::getAgent();
|
||||
|
||||
$_son = Agent::getAgentById($id);
|
||||
|
||||
if (empty($_self) || empty($_son)) {
|
||||
return $this->outmsg('发生错误!请重新登录');
|
||||
}
|
||||
$level_path_Arr = explode(',', $_son->agent_path);
|
||||
if (!in_array($_self->id, $level_path_Arr)) {
|
||||
return $this->error('该代理商并不属于您的团队');
|
||||
}
|
||||
|
||||
|
||||
if (($_self->level == $this->agent_max_level && $_self->is_admin == 0)) {
|
||||
return $this->notice("您是{$this->agent_max_level}级代理商,不能添加下级代理商");
|
||||
} else if (($_self->is_addson == 0)) {
|
||||
return $this->notice('您尚未拥有添加下级代理商的权限');
|
||||
} else if (($_self->is_lock == 1)) {
|
||||
return $this->notice('您的代理商帐号被锁定');
|
||||
}
|
||||
if ($_son->level == $this->agent_max_level){
|
||||
return $this->notice("该用户是{$this->agent_max_level}级代理商,不能添加下级代理商");
|
||||
}
|
||||
|
||||
if ($_son != null && !empty($id) && !empty($username) && $_self != null && !empty($_self)) {
|
||||
|
||||
$user = Users::getByAccountNumber($username);
|
||||
if ($user != null) {
|
||||
|
||||
$agent = Agent::getUserByUsername($username);
|
||||
if ($agent === null) {
|
||||
|
||||
$returnData = [];
|
||||
$returnData['user_id'] = $user->id;
|
||||
$returnData['username'] = $user->account_number;
|
||||
$returnData['son_level'] = 0;
|
||||
|
||||
if ($_son->level == 0 && $_son->is_admin == 1) {
|
||||
$returnData['son_level'] = 1;
|
||||
} else{
|
||||
$returnData['son_level'] = $_son->level + 1;
|
||||
}
|
||||
|
||||
$returnData['max_pro_loss'] = $_son->pro_loss;
|
||||
$returnData['max_pro_ser'] = $_son->pro_ser;
|
||||
|
||||
return $this->ajaxReturn($returnData);
|
||||
|
||||
} else {
|
||||
return $this->notice('该用户已经是代理商');
|
||||
}
|
||||
} else {
|
||||
return $this->error('该用户不存在');
|
||||
}
|
||||
} else {
|
||||
return $this->error('该用户不存在');
|
||||
}
|
||||
} else {
|
||||
return $this->error('非法操作!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加下级的代理商
|
||||
* @param Request $request
|
||||
*/
|
||||
public function addSonAgent(Request $request)
|
||||
{
|
||||
|
||||
$_self = Agent::getAgent();
|
||||
|
||||
|
||||
$id = $request->input('agent_id', 0);//下级代理商id
|
||||
$_son = Agent::getAgentById($id);
|
||||
|
||||
if ($_self === null) {
|
||||
return $this->outmsg('发生错误!请重新登录');
|
||||
}
|
||||
|
||||
if ($_son->level == $this->agent_max_level){
|
||||
return $this->notice("该用户是{$this->agent_max_level}级代理商,不能添加下级代理商");
|
||||
}
|
||||
|
||||
if ($_self->level == $this->agent_max_level){
|
||||
return $this->notice("您是{$this->agent_max_level}级代理商,不能添加下级代理商");
|
||||
} else if (($_self->is_addson == 0)) {
|
||||
return $this->notice('您尚未拥有添加下级代理商的权限');
|
||||
} else if (($_self->is_lock == 1)) {
|
||||
return $this->notice('您的代理商帐号被锁定');
|
||||
}
|
||||
|
||||
//判断下级
|
||||
$username = $request->input('username', 0);
|
||||
$user_id = $request->input('user_id', 0);
|
||||
|
||||
$id = $request->input('id', 0);
|
||||
if (DB::table('users')->where('account_number', $username)->where('id', $user_id)->first() === null) {
|
||||
return $this->error("该用户不存在!请重新核对用户信息");
|
||||
}
|
||||
$ag = Agent::getUserByUsername($username);
|
||||
if ($ag !== null && $id == 0) {
|
||||
return $this->error("该用户已经是代理商!");
|
||||
}
|
||||
|
||||
|
||||
$rules = [
|
||||
'pro_loss' => 'required|numeric|min:0.01|max:' . $_son->pro_loss, //验证下级代理商的头寸比例是否正确
|
||||
'pro_ser' => 'required|numeric|min:0.01|max:' . $_son->pro_ser, // //验证下级代理商的手续费比例是否正确
|
||||
'is_lock' => 'required|in:1,0',
|
||||
'is_addson' => 'required|in:1,0',
|
||||
'user_id' => 'required|integer|min:0',
|
||||
'id' => 'required|integer|min:0'
|
||||
];
|
||||
|
||||
$messages = [
|
||||
'pro_loss.required' => '头寸比例不能为空',
|
||||
'pro_loss.numeric' => '头寸比例只能为数字',
|
||||
'pro_loss.min' => '头寸比例最小值为0.01',
|
||||
'pro_loss.max' => '头寸比例最大值为' . $_son->pro_loss,
|
||||
'pro_ser.required' => '手续费比例不能为空',
|
||||
'pro_ser.numeric' => '手续费比例只能为数字',
|
||||
'pro_ser.min' => '手续费比例最小值为0.01',
|
||||
'pro_ser.max' => '手续费比例最大值为' . $_son->pro_ser,
|
||||
'is_lock.required' => '是否锁定不能为空',
|
||||
'is_lock.in' => '是否锁定参数错误',
|
||||
'is_addson.required' => '是否填新不能为空',
|
||||
'is_addson.in' => '是否填新参数错误',
|
||||
'user_id.required' => '参数类型错误',
|
||||
'user_id.integer' => '参数类型错误',
|
||||
'user_id.min' => '非法操作',
|
||||
'id.required' => '参数类型错误',
|
||||
'id.integer' => '参数类型错误',
|
||||
'id.min' => '非法操作'
|
||||
];
|
||||
|
||||
//创建验证器
|
||||
$validator = Validator::make($request->all(), $rules, $messages);
|
||||
//以上验证通过后 继续验证 . 测试用的~ :)
|
||||
$validator->after(function ($validator) use ($request) {
|
||||
$user = Users::getById($request->get('user_id'));
|
||||
if (empty($user)) {
|
||||
return $validator->errors()->add('isUser', '没有此用户');
|
||||
}
|
||||
});
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
|
||||
$user = Users::getById($request->get('user_id'));
|
||||
//判断添加下级的代理商的等级
|
||||
if ($_son->level == 0 && $_son->is_admin == 1) {
|
||||
$level = 1;
|
||||
} else {
|
||||
$level = $_son->level + 1;
|
||||
}
|
||||
|
||||
if ($id > 0) {
|
||||
$agent = Agent::find($id);
|
||||
} else {
|
||||
|
||||
//添加代理商时 用户授权码
|
||||
// $authorization_code = $request->input('authorization_code', '');
|
||||
|
||||
// if(!Cache::has('authorization_code_'.$user->id)){
|
||||
// return $this->error('用户授权码已失效,请重新生成');
|
||||
// }
|
||||
// $user_code=Cache::get('authorization_code_'.$user->id);
|
||||
|
||||
|
||||
// if(!$authorization_code || ($authorization_code != $user_code) ){
|
||||
// return $this->error('用户授权码不正确');
|
||||
// }
|
||||
$agent = new Agent();
|
||||
$agent->reg_time = time();
|
||||
}
|
||||
$agent->user_id = $user_id;
|
||||
$agent->username = $username;
|
||||
$agent->password = $user->password;
|
||||
$agent->parent_agent_id = $_son->id; //上级代理商id,有别于user表中的parent_id。 这个id取的是agent产生的id,并不是users表中的id。特别要注意!
|
||||
$agent->level = $level;
|
||||
$agent->is_admin = 0;
|
||||
$agent->is_lock = $request->input('is_lock', 0);
|
||||
$agent->is_addson = $request->input('is_addson', 1);
|
||||
$agent->pro_loss = $request->input('pro_loss', 0.00);
|
||||
$agent->pro_ser = $request->input('pro_ser', 0.00);
|
||||
$agent->status = 1;
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
if (!$agent->save()) {
|
||||
DB::rollBack();
|
||||
return $this->error("操作失败!请重试");
|
||||
}
|
||||
if ($_son->is_admin == 1) {
|
||||
$agent->agent_path = $agent->id . ',' . $_son->id;
|
||||
} else {
|
||||
$agent->agent_path = $agent->id . ',' . $_son->agent_path; //上级代理商id的字符串拼接,这个id取的是agent产生的id,并不是users表中的id。特别要注意!
|
||||
}
|
||||
if ($agent->save()) {
|
||||
|
||||
//更新该用户的代理商id
|
||||
$_users = Users::lockForUpdate()->find($user_id);
|
||||
$_users->agent_id = $agent->id;
|
||||
$_users->save();
|
||||
|
||||
DB::commit();
|
||||
return $this->success("操作成功");
|
||||
} else {
|
||||
DB::rollBack();
|
||||
return $this->error("操作失败!请重试");
|
||||
}
|
||||
} catch (\Exception $ex) { //\Exception 捕获所有异常
|
||||
DB::rollBack();
|
||||
return $this->error($ex->getMessage()); // getMessage() 异常信息
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 添加 编辑代理商
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function addAgent(Request $request)
|
||||
{
|
||||
|
||||
$_self = Agent::getAgent();
|
||||
|
||||
if ($_self === null) {
|
||||
return $this->outmsg('发生错误!请重新登录');
|
||||
}
|
||||
//判断下级
|
||||
$username = $request->input('username', 0);
|
||||
$user_id = $request->input('user_id', 0);
|
||||
|
||||
$id = $request->input('id', 0);//编辑
|
||||
if (DB::table('users')->where('account_number', $username)->where('id', $user_id)->first() === null) {
|
||||
return $this->error("该用户不存在!请重新核对用户信息");
|
||||
}
|
||||
$ag = Agent::getUserByUsername($username);
|
||||
if ($ag !== null && $id == 0) {
|
||||
return $this->error("该用户已经是代理商!");
|
||||
}
|
||||
|
||||
//判断自己
|
||||
if (($_self->level == $this->agent_max_level && $_self->is_admin == 0 && $id == 0)) {
|
||||
return $this->notice("您是{$this->agent_max_level}级代理商,不能添加下级代理商");
|
||||
} else if (($_self->is_addson == 0)) {
|
||||
return $this->notice('您尚未拥有添加下级代理商的权限');
|
||||
} else if (($_self->is_lock == 1)) {
|
||||
return $this->notice('您的代理商帐号被锁定');
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'pro_loss' => 'required|numeric|min:0.00|max:' . $_self->pro_loss, //验证下级代理商的头寸比例是否正确
|
||||
'pro_ser' => 'required|numeric|min:0.00|max:' . $_self->pro_ser, // //验证下级代理商的手续费比例是否正确
|
||||
'is_lock' => 'required|in:1,0',
|
||||
'is_addson' => 'required|in:1,0',
|
||||
'user_id' => 'required|integer|min:0',
|
||||
'id' => 'required|integer|min:0'
|
||||
];
|
||||
|
||||
$messages = [
|
||||
'pro_loss.required' => '头寸比例不能为空',
|
||||
'pro_loss.numeric' => '头寸比例只能为数字',
|
||||
'pro_loss.min' => '头寸比例最小值为0.01',
|
||||
'pro_loss.max' => '头寸比例最大值为' . $_self->pro_loss,
|
||||
'pro_ser.required' => '手续费比例不能为空',
|
||||
'pro_ser.numeric' => '手续费比例只能为数字',
|
||||
'pro_ser.min' => '手续费比例最小值为0.01',
|
||||
'pro_ser.max' => '手续费比例最大值为' . $_self->pro_ser,
|
||||
'is_lock.required' => '是否锁定不能为空',
|
||||
'is_lock.in' => '是否锁定参数错误',
|
||||
'is_addson.required' => '是否填新不能为空',
|
||||
'is_addson.in' => '是否填新参数错误',
|
||||
'user_id.required' => '参数类型错误',
|
||||
'user_id.integer' => '参数类型错误',
|
||||
'user_id.min' => '非法操作',
|
||||
'id.required' => '参数类型错误',
|
||||
'id.integer' => '参数类型错误',
|
||||
'id.min' => '非法操作'
|
||||
];
|
||||
|
||||
//创建验证器
|
||||
$validator = Validator::make($request->all(), $rules, $messages);
|
||||
//以上验证通过后 继续验证 . 测试用的~ :)
|
||||
$validator->after(function ($validator) use ($request) {
|
||||
$user = Users::getById($request->get('user_id'));
|
||||
if (empty($user)) {
|
||||
return $validator->errors()->add('isUser', '没有此用户');
|
||||
}
|
||||
});
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
|
||||
$user = Users::getById($request->get('user_id'));
|
||||
if ($id > 0) {
|
||||
$agent = Agent::find($id);
|
||||
//编辑下一级代理商密码
|
||||
if($agent->parent_agent_id == $_self->id){
|
||||
$agent_password = $request->input('agent_password', '');
|
||||
if($agent_password){
|
||||
$agent->password = Users::MakePassword($agent_password);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
//添加代理商时 用户授权码
|
||||
// $authorization_code = $request->input('authorization_code', '');
|
||||
|
||||
// if(!Cache::has('authorization_code_'.$user->id)){
|
||||
// return $this->error('用户授权码已失效,请重新生成');
|
||||
// }
|
||||
// $user_code=Cache::get('authorization_code_'.$user->id);
|
||||
|
||||
|
||||
// if(!$authorization_code || ($authorization_code != $user_code) ){
|
||||
// return $this->error('用户授权码不正确');
|
||||
// }
|
||||
|
||||
$agent = new Agent();
|
||||
$agent->reg_time = time();
|
||||
$agent->parent_agent_id = $_self->id; //上级代理商id,有别于user表中的parent_id。 这个id取的是agent产生的id,并不是users表中的id。特别要注意!
|
||||
|
||||
//判断添加下级的代理商的等级
|
||||
if ($_self->level == 0 && $_self->is_admin == 1) {
|
||||
$level = 1;
|
||||
} else{
|
||||
$level =$_self->level +1;
|
||||
}
|
||||
$agent->level = $level;
|
||||
$agent->password = $user->password;
|
||||
}
|
||||
|
||||
$agent->user_id = $user_id;
|
||||
$agent->username = $username;
|
||||
|
||||
$agent->is_admin = 0;
|
||||
$agent->is_lock = $request->input('is_lock', 0);
|
||||
$agent->is_addson = $request->input('is_addson', 1);
|
||||
$agent->pro_loss = $request->input('pro_loss', 0.00);
|
||||
$agent->pro_ser = $request->input('pro_ser', 0.00);
|
||||
$agent->status = 1;
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
if (!$agent->save()) {
|
||||
DB::rollBack();
|
||||
return $this->error("操作失败!请重试");
|
||||
}
|
||||
if ($_self->is_admin == 1) {
|
||||
$agent->agent_path = $agent->id . ',' . $_self->id;
|
||||
} else {
|
||||
$agent->agent_path = $agent->id . ',' . $_self->agent_path; //上级代理商id的字符串拼接,这个id取的是agent产生的id,并不是users表中的id。特别要注意!
|
||||
}
|
||||
if ($agent->save()) {
|
||||
|
||||
//更新该用户的代理商id
|
||||
$_users = Users::lockForUpdate()->find($user_id);
|
||||
$_users->agent_id = $agent->id;
|
||||
$_users->save();
|
||||
|
||||
DB::commit();
|
||||
return $this->success("操作成功");
|
||||
} else {
|
||||
DB::rollBack();
|
||||
return $this->error("操作失败!请重试");
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack(); //\Exception 捕获所有异常
|
||||
return $this->error($ex->getMessage()); // getMessage() 异常信息
|
||||
}
|
||||
}
|
||||
|
||||
public function updateAgent(Request $request)
|
||||
{
|
||||
//判断下级
|
||||
$agentid = $request->input('agentid', 0);
|
||||
$_h = Agent::getAgentById($agentid);
|
||||
if ($_h == null || $_h->id <= 0) {
|
||||
return $this->error("该用户不存在!请重新核对用户信息");
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'agentid' => 'required|numeric|min:1|max:999999999', //id必须是数字
|
||||
'name' => 'required|in:is_lock,is_addson', //必须是指定的字段
|
||||
'value' => 'required|in:1,0' //必须是指定的值
|
||||
];
|
||||
|
||||
$messages = [
|
||||
'agentid.required' => '用户id不能为空',
|
||||
'agentid.numeric' => '用户id只能为数字',
|
||||
'agentid.min' => '用户id最小值为1',
|
||||
'agentid.max' => '用户id最大值为999999999',
|
||||
'name.required' => '修改属性不能为空',
|
||||
'name.in' => '修改属性参数错误',
|
||||
'value.required' => '修改属性值不能为空',
|
||||
'value.in' => '修改属性值参数错误'
|
||||
];
|
||||
|
||||
//创建验证器
|
||||
$validator = Validator::make($request->all(), $rules, $messages);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
|
||||
$agent = new Agent();
|
||||
$name = $request->input('name', 0);
|
||||
$value = $request->input('value', 0);
|
||||
|
||||
if ($name == 'is_lock' && $value == 1) {
|
||||
$lock = time();
|
||||
} else {
|
||||
$lock = 0;
|
||||
}
|
||||
|
||||
$res = $agent->where('id', $agentid)->update([$name => $value, 'lock_time' => $lock]);
|
||||
|
||||
if ($res) {
|
||||
return $this->success('更新成功');
|
||||
} else {
|
||||
return $this->error('更新失败,请重新尝试');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $san_user
|
||||
*
|
||||
*/
|
||||
public function sel_arr($arr = array())
|
||||
{
|
||||
if (!empty($arr)) {
|
||||
$new_arr = [];
|
||||
foreach ($arr as $k => $val) {
|
||||
$new_arr[] = $val->user_id;
|
||||
}
|
||||
return $new_arr;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $san_user
|
||||
*
|
||||
*/
|
||||
public function sel_agent_arr($arr = array())
|
||||
{
|
||||
if (!empty($arr)) {
|
||||
$new_arr = [];
|
||||
foreach ($arr as $k => $val) {
|
||||
$new_arr[] = $val->id;
|
||||
}
|
||||
return $new_arr;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function allChildAgent()
|
||||
{
|
||||
$agents = Agent::getAllChildAgent(Agent::getAgentId());
|
||||
return $this->ajaxReturn($agents);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,845 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\{Agent, AgentMoneylog, Currency, LeverTransaction, TransactionComplete, TransactionOrder, Users,UsersWallet,CurrencyMatch,MicroOrder};
|
||||
|
||||
/**
|
||||
* 该类处理所有的订单与结算。
|
||||
* Class ReportController
|
||||
* @package App\Http\Controllers\Agent
|
||||
*/
|
||||
class OrderController extends Controller
|
||||
{
|
||||
|
||||
//杠杆订单管理
|
||||
public function leverIndex()
|
||||
{
|
||||
$legal_currencies = Currency::where('is_legal', 1)->get();
|
||||
return view("agent.order.leverlist",[
|
||||
'legal_currencies' => $legal_currencies,
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
//撮合单
|
||||
public function transactionIndex()
|
||||
{
|
||||
$legal_currencies = Currency::where('is_legal', 1)->get();
|
||||
$currencies = Currency::get();
|
||||
return view("agent.order.transaction", [
|
||||
'legal_currencies' => $legal_currencies,
|
||||
'currencies' => $currencies,
|
||||
]);
|
||||
}
|
||||
|
||||
//撮合订单
|
||||
public function transactionList(Request $request)
|
||||
{
|
||||
$limit = $request->get('limit', 10);
|
||||
//当前代理商信息
|
||||
$agent_id = Agent::getAgentId();
|
||||
$node_users = Users::whereRaw("FIND_IN_SET($agent_id,`agent_path`)")->pluck('id')->all();
|
||||
|
||||
$account_number = $request->get('account_number', '');
|
||||
|
||||
|
||||
$result = TransactionComplete::when($account_number != '', function ($query) use ($account_number) {
|
||||
|
||||
$query->whereHas('user', function ($query) use ($account_number) {
|
||||
$query->where('account_number', 'like', '%' . $account_number . '%');
|
||||
})->orWhereHas('fromUser', function ($query) use ($account_number) {
|
||||
$query->where('account_number', 'like', '%' . $account_number . '%');
|
||||
});
|
||||
})->where(function ($query) use ($request) {
|
||||
$legal = $request->input('legal', -1);
|
||||
$currency = $request->input('currency', -1);
|
||||
$legal != -1 && $query->where('legal', $legal);
|
||||
$currency != -1 && $query->where('currency', $currency);
|
||||
$start_time = $request->input('start_time', '');
|
||||
$end_time = $request->input('end_time', '');
|
||||
if (!empty($start_time)) {
|
||||
$start_time = strtotime($start_time);
|
||||
$query->where('create_time', '>=', $start_time);
|
||||
}
|
||||
if (!empty($end_time)) {
|
||||
$end_time = strtotime($end_time);
|
||||
$query->where('create_time', '<=', $end_time);
|
||||
}
|
||||
})->where(function ($query) use ($node_users) {
|
||||
$query->where(function ($query) use ($node_users) {
|
||||
$query->whereIn('user_id', $node_users);
|
||||
})->orwhere(function ($query) use ($node_users) {
|
||||
$query->whereIn('from_user_id', $node_users);
|
||||
});
|
||||
//})->orderBy('id', 'desc')->toSql();
|
||||
//dd($result);
|
||||
})->orderBy('id', 'desc')->paginate($limit);
|
||||
$sum = $result->sum('number');
|
||||
return $this->layuiData($result, $sum);
|
||||
}
|
||||
|
||||
|
||||
//杠杆
|
||||
public function order_list(Request $request)
|
||||
{
|
||||
|
||||
$limit = $request->input("limit", 10);
|
||||
$id = $request->input("id", 0);
|
||||
$username = $request->input("username", '');
|
||||
$agentusername = $request->input("agentusername", '');
|
||||
$status = $request->input("status", 10);
|
||||
$type = $request->input("type", 0);
|
||||
|
||||
$start = $request->input("start", '');
|
||||
$end = $request->input("end", '');
|
||||
$legal_id = $request->input("legal_id",-1);
|
||||
|
||||
|
||||
//当前代理商信息
|
||||
$agent_id = Agent::getAgentId();
|
||||
|
||||
|
||||
if ($agentusername != '') {
|
||||
|
||||
$search_agent = Agent::where('username', $agentusername)->first();
|
||||
if (!$search_agent) {
|
||||
return $this->error('代理商不存在');
|
||||
}
|
||||
|
||||
$parent_agent = explode(',', $search_agent->agent_path);
|
||||
|
||||
if (!in_array($agent_id, $parent_agent)) {
|
||||
return $this->error('该代理商并不属于您的团队');
|
||||
}
|
||||
|
||||
$now_agent_id = $search_agent->id;
|
||||
} else {
|
||||
$now_agent_id = $agent_id;
|
||||
}
|
||||
|
||||
$query = TransactionOrder::whereHas('user', function ($query) use ($username) {
|
||||
|
||||
$username != '' && $query->where('account_number', $username)->orWhere('phone', $username);
|
||||
})->where(function ($query) use ($id, $status, $type) {
|
||||
|
||||
$id != 0 && $query->where('id', $id);
|
||||
|
||||
$status != 10 && in_array($status, [LeverTransaction::ENTRUST, LeverTransaction::TRANSACTION, LeverTransaction::CLOSED, LeverTransaction::CANCEL, LeverTransaction::CLOSING]) && $query->where('status', $status);
|
||||
|
||||
$type > 0 && in_array($type, [1, 2]) && $query->where('type', $type);
|
||||
})->where(function ($query) use ($start, $end) {
|
||||
|
||||
!empty($start) && $query->where('create_time', '>=', strtotime($start . ' 0:0:0'));
|
||||
|
||||
!empty($end) && $query->where('create_time', '<=', strtotime($end . ' 23:59:59'));
|
||||
})->where(function ($query) use ($now_agent_id) {
|
||||
|
||||
$now_agent_id > 0 && $query->whereRaw("FIND_IN_SET($now_agent_id,`agent_path`)");
|
||||
})->when($legal_id > 0, function ($query) use ($legal_id) {
|
||||
|
||||
$query->where('legal',$legal_id);
|
||||
|
||||
});
|
||||
|
||||
$order_list = $query->orderBy('id', 'desc')->paginate($limit);
|
||||
|
||||
|
||||
return $this->layuiData($order_list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*获取杠杆统计数据
|
||||
*/
|
||||
public function get_order_account(Request $request)
|
||||
{
|
||||
|
||||
$id = $request->input("id", 0);
|
||||
$username = $request->input("username", '');
|
||||
$agentusername = $request->input("agentusername", '');
|
||||
$status = $request->input("status", 10);
|
||||
$type = $request->input("type", 0);
|
||||
|
||||
$start = $request->input("start", '');
|
||||
$end = $request->input("end", '');
|
||||
|
||||
$legal_id = $request->input("legal_id",-1);
|
||||
|
||||
//当前代理商信息
|
||||
$agent_id = Agent::getAgentId();
|
||||
|
||||
|
||||
if ($agentusername != '') {
|
||||
|
||||
$search_agent = Agent::where('username', $agentusername)->first();
|
||||
if (!$search_agent) {
|
||||
return $this->error('代理商不存在');
|
||||
}
|
||||
|
||||
$parent_agent = explode(',', $search_agent->agent_path);
|
||||
|
||||
if (!in_array($agent_id, $parent_agent)) {
|
||||
return $this->error('该代理商并不属于您的团队');
|
||||
}
|
||||
|
||||
$now_agent_id = $search_agent->id;
|
||||
} else {
|
||||
$now_agent_id = $agent_id;
|
||||
}
|
||||
|
||||
$query1 = TransactionOrder::whereHas('user', function ($query) use ($username) {
|
||||
|
||||
$username != '' && $query->where('account_number', $username)->orWhere('phone', $username);
|
||||
})->where(function ($query) use ($id, $status, $type) {
|
||||
|
||||
$id != 0 && $query->where('id', $id);
|
||||
|
||||
$status != 10 && in_array($status, [LeverTransaction::ENTRUST, LeverTransaction::TRANSACTION, LeverTransaction::CLOSED, LeverTransaction::CANCEL, LeverTransaction::CLOSING]) && $query->where('status', $status);
|
||||
|
||||
$type > 0 && in_array($type, [1, 2]) && $query->where('type', $type);
|
||||
})->where(function ($query) use ($start, $end) {
|
||||
|
||||
!empty($start) && $query->where('create_time', '>=', strtotime($start . ' 0:0:0'));
|
||||
|
||||
!empty($end) && $query->where('create_time', '<=', strtotime($end . ' 23:59:59'));
|
||||
})->where(function ($query) use ($now_agent_id) {
|
||||
|
||||
$now_agent_id > 0 && $query->whereRaw("FIND_IN_SET($now_agent_id,`agent_path`)");
|
||||
})->when($legal_id > 0, function ($query) use ($legal_id) {
|
||||
|
||||
$query->where('legal',$legal_id);
|
||||
|
||||
});
|
||||
|
||||
//可用保证金 未平仓
|
||||
$_lock = $query1->selectRaw('sum(if(status <= 2,caution_money,0)) as caution_money')->value('caution_money') ?? 0;
|
||||
|
||||
//总订单数
|
||||
$_count = $query1->count();
|
||||
|
||||
//头寸收益(平仓最终盈亏)
|
||||
$_toucun =$query1->whereIn('status', [LeverTransaction::CLOSED])->sum('fact_profits');
|
||||
//手续费收益(已平仓手续费)
|
||||
$_shouxu = $query1->whereIn('status', [LeverTransaction::CLOSED])->sum('trade_fee');
|
||||
|
||||
//查询当前代理商的头寸 手续费百分比
|
||||
$now_agent=Agent::getAgentById($now_agent_id);
|
||||
|
||||
$data = [];
|
||||
$data['_num'] = $_count;
|
||||
$data['_toucun'] = bc_mul(bc_mul($_toucun,$now_agent->pro_loss/100),-1);// 乘以代理商头寸百分比 取负数
|
||||
$data['_shouxu'] =bc_mul($_shouxu,$now_agent->pro_ser/100);// 乘以代理商手续费百分比
|
||||
|
||||
$_all = bc_add($data['_toucun'], $data['_shouxu']);
|
||||
|
||||
$data['_all'] = $_all;
|
||||
//可用保证金
|
||||
$data['_lock'] = $_lock;
|
||||
|
||||
|
||||
|
||||
return $this->ajaxReturn($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
|
||||
//导出订单记录Excel
|
||||
public function order_excel(Request $request)
|
||||
{
|
||||
$limit = $request->input("limit", 10);
|
||||
$id = $request->input("id", 0);
|
||||
$username = $request->input("username", '');
|
||||
$agentusername = $request->input("agentusername", '');
|
||||
$status = $request->input("status", 10);
|
||||
$type = $request->input("type", 0);
|
||||
|
||||
$start = $request->input("start", '');
|
||||
$end = $request->input("end", '');
|
||||
$legal_id = $request->input("legal_id",-1);
|
||||
//echo $id.'-'.$username.'-'.$agentusername.'-'.$status.'-'. $type.'-'.$start.'-'.$end;exit;
|
||||
|
||||
/*
|
||||
$where = [];
|
||||
if ($id > 0){
|
||||
$where[] = ['id' , '=' , $id];
|
||||
}
|
||||
if (!empty($username)){
|
||||
$s = DB::table('users')->where('account_number' , $username)->first();
|
||||
if ($s !== null){
|
||||
$where[] = ['user_id' , '=' , $s->id];
|
||||
}
|
||||
}
|
||||
if ($status != 10 && in_array($status , [LeverTransaction::ENTRUST,LeverTransaction::TRANSACTION,LeverTransaction::CLOSED,LeverTransaction::CANCEL,LeverTransaction::CLOSING])){
|
||||
$where[] = ['status' , '=' , $status];
|
||||
}
|
||||
if ($type > 0 && in_array($type , [1,2])){
|
||||
$where[] = ['type' , '=' , $type];
|
||||
}
|
||||
if (!empty($start) && !empty($end)) {
|
||||
$where[] = ['create_time' , '>' , strtotime($start . ' 0:0:0')];
|
||||
$where[] = ['create_time' , '<' , strtotime($end . ' 23:59:59')];
|
||||
}
|
||||
|
||||
$_self = Agent::getAgent();
|
||||
if ($_self === null){
|
||||
return $this->outmsg('发生错误!请重新登录');
|
||||
}
|
||||
$sons = $this->get_my_sons();
|
||||
|
||||
if (!empty($agentusername)){
|
||||
$s = DB::table('agent')->where('username' , $agentusername)->first();
|
||||
|
||||
if (!in_array($s->id , $sons['all'])){
|
||||
return $this->error('该代理商并不属于您的团队');
|
||||
}else{
|
||||
|
||||
$p_s_s = $this->get_my_sons($s->id);
|
||||
|
||||
if (!empty($p_s_s)){
|
||||
$order_list = TransactionOrder::whereIn('status' , [LeverTransaction::ENTRUST,LeverTransaction::TRANSACTION,LeverTransaction::CLOSED,LeverTransaction::CANCEL,LeverTransaction::CLOSING])->whereIn('user_id' , $p_s_s['all'])->where($where)->get()->toArray();
|
||||
}else{
|
||||
|
||||
$order_list = TransactionOrder::whereIn('status' , [LeverTransaction::ENTRUST,LeverTransaction::TRANSACTION,LeverTransaction::CLOSED,LeverTransaction::CANCEL,LeverTransaction::CLOSING])->whereIn('user_id' , $sons['all'])->where($where)->get()->toArray();
|
||||
|
||||
}
|
||||
}
|
||||
}else{
|
||||
|
||||
$order_list = TransactionOrder::whereIn('status' , [LeverTransaction::ENTRUST,LeverTransaction::TRANSACTION,LeverTransaction::CLOSED,LeverTransaction::CANCEL,LeverTransaction::CLOSING])->whereIn('user_id' , $sons['all'])->where($where)->get()->toArray();
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
//当前代理商信息
|
||||
$agent_id = Agent::getAgentId();
|
||||
|
||||
|
||||
if ($agentusername != '') {
|
||||
|
||||
$search_agent = Agent::where('username', $agentusername)->first();
|
||||
if (!$search_agent) {
|
||||
return $this->error('代理商不存在');
|
||||
}
|
||||
|
||||
$parent_agent = explode(',', $search_agent->agent_path);
|
||||
|
||||
if (!in_array($agent_id, $parent_agent)) {
|
||||
return $this->error('该代理商并不属于您的团队');
|
||||
}
|
||||
|
||||
$now_agent_id = $search_agent->id;
|
||||
} else {
|
||||
$now_agent_id = $agent_id;
|
||||
}
|
||||
|
||||
$query = TransactionOrder::whereHas('user', function ($query) use ($username) {
|
||||
|
||||
$username != '' && $query->where('account_number', $username)->orWhere('phone', $username);
|
||||
})->where(function ($query) use ($id, $status, $type) {
|
||||
|
||||
$id != 0 && $query->where('id', $id);
|
||||
|
||||
$status != 10 && in_array($status, [LeverTransaction::ENTRUST, LeverTransaction::TRANSACTION, LeverTransaction::CLOSED, LeverTransaction::CANCEL, LeverTransaction::CLOSING]) && $query->where('status', $status);
|
||||
|
||||
$type > 0 && in_array($type, [1, 2]) && $query->where('type', $type);
|
||||
})->where(function ($query) use ($start, $end) {
|
||||
|
||||
!empty($start) && $query->where('create_time', '>=', strtotime($start . ' 0:0:0'));
|
||||
|
||||
!empty($end) && $query->where('create_time', '<=', strtotime($end . ' 23:59:59'));
|
||||
})->where(function ($query) use ($now_agent_id) {
|
||||
|
||||
$now_agent_id > 0 && $query->whereRaw("FIND_IN_SET($now_agent_id,`agent_path`)");
|
||||
})->when($legal_id > 0, function ($query) use ($legal_id) {
|
||||
|
||||
$query->where('legal',$legal_id);
|
||||
|
||||
});
|
||||
|
||||
|
||||
$order_list = $query->orderBy('id', 'desc')->get()->toArray();
|
||||
|
||||
$data = $order_list;
|
||||
//dd($data);
|
||||
return Excel::create('订单数据', function ($excel) use ($data) {
|
||||
$excel->sheet('订单数据', function ($sheet) use ($data) {
|
||||
$sheet->cell('A1', function ($cell) {
|
||||
$cell->setValue('ID');
|
||||
});
|
||||
$sheet->cell('B1', function ($cell) {
|
||||
$cell->setValue('用户名');
|
||||
});
|
||||
$sheet->cell('C1', function ($cell) {
|
||||
$cell->setValue('所属代理商');
|
||||
});
|
||||
$sheet->cell('D1', function ($cell) {
|
||||
$cell->setValue('用户等级');
|
||||
});
|
||||
$sheet->cell('E1', function ($cell) {
|
||||
$cell->setValue('交易类型');
|
||||
});
|
||||
$sheet->cell('F1', function ($cell) {
|
||||
$cell->setValue('交易对');
|
||||
});
|
||||
$sheet->cell('G1', function ($cell) {
|
||||
$cell->setValue('当前状态');
|
||||
});
|
||||
$sheet->cell('H1', function ($cell) {
|
||||
$cell->setValue('原始价格');
|
||||
});
|
||||
$sheet->cell('I1', function ($cell) {
|
||||
$cell->setValue('开仓价格');
|
||||
});
|
||||
$sheet->cell('J1', function ($cell) {
|
||||
$cell->setValue('当前价格');
|
||||
});
|
||||
$sheet->cell('K1', function ($cell) {
|
||||
$cell->setValue('最终盈亏');
|
||||
});
|
||||
$sheet->cell('L1', function ($cell) {
|
||||
$cell->setValue('手数');
|
||||
});
|
||||
$sheet->cell('M1', function ($cell) {
|
||||
$cell->setValue('倍数');
|
||||
});
|
||||
$sheet->cell('N1', function ($cell) {
|
||||
$cell->setValue('初始保证金');
|
||||
});
|
||||
$sheet->cell('O1', function ($cell) {
|
||||
$cell->setValue('当前可用保证金');
|
||||
});
|
||||
$sheet->cell('P1', function ($cell) {
|
||||
$cell->setValue('创建时间');
|
||||
});
|
||||
$sheet->cell('Q1', function ($cell) {
|
||||
$cell->setValue('完成时间');
|
||||
});
|
||||
if (!empty($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
if ($value['type'] == 1) {
|
||||
$value['type'] = "买入";
|
||||
} else {
|
||||
$value['type'] = "卖出";
|
||||
}
|
||||
if ($value['status'] == 0) {
|
||||
$value['status'] = "挂单中";
|
||||
} elseif ($value['status'] == 1) {
|
||||
$value['status'] = "交易中";
|
||||
} elseif ($value['status'] == 2) {
|
||||
$value['status'] = "平仓中";
|
||||
} elseif ($value['status'] == 3) {
|
||||
$value['status'] = "已平仓";
|
||||
} elseif ($value['status'] == 4) {
|
||||
$value['status'] = "已撤单";
|
||||
}
|
||||
|
||||
$i = $key + 2;
|
||||
$sheet->cell('A' . $i, $value['id']);
|
||||
$sheet->cell('B' . $i, $value['user_name']);
|
||||
$sheet->cell('C' . $i, $value['parent_agent_name']);
|
||||
$sheet->cell('D' . $i, $value['agent_level']);
|
||||
$sheet->cell('E' . $i, $value['type']);
|
||||
$sheet->cell('F' . $i, $value['symbol']);
|
||||
|
||||
$sheet->cell('G' . $i, $value['status']);
|
||||
$sheet->cell('H' . $i, $value['origin_price']);
|
||||
$sheet->cell('I' . $i, $value['price']);
|
||||
$sheet->cell('J' . $i, $value['update_price']); //当前价格
|
||||
$sheet->cell('K' . $i, $value['fact_profits']);
|
||||
|
||||
$sheet->cell('L' . $i, $value['share']); //手数
|
||||
$sheet->cell('M' . $i, $value['multiple']);
|
||||
$sheet->cell('N' . $i, $value['origin_caution_money']); //初始保证金
|
||||
$sheet->cell('O' . $i, $value['caution_money']);
|
||||
$sheet->cell('P' . $i, $value['create_time']); //创建时间
|
||||
|
||||
$sheet->cell('Q' . $i, $value['complete_time']);
|
||||
}
|
||||
}
|
||||
ob_end_clean();
|
||||
});
|
||||
})->download('xlsx');
|
||||
}
|
||||
|
||||
|
||||
//导出用户记录Excel
|
||||
public function user_excel(Request $request)
|
||||
{
|
||||
|
||||
$id = request()->input('id', 0);
|
||||
$parent_id = request()->input('parent_id', 0);
|
||||
$account_number = request()->input('account_number', '');
|
||||
$start = request()->input('start', '');
|
||||
$end = request()->input('end', '');
|
||||
|
||||
$users = new Users();
|
||||
|
||||
if ($id) {
|
||||
$users = $users->where('id', $id);
|
||||
}
|
||||
if ($parent_id > 0) {
|
||||
$users = $users->where('agent_note_id', $parent_id);
|
||||
}
|
||||
if ($account_number) {
|
||||
$users = $users->where('account_number', $account_number);
|
||||
}
|
||||
if (!empty($start) && !empty($end)) {
|
||||
$users->whereBetween('time', [strtotime($start . ' 0:0:0'), strtotime($end . ' 23:59:59')]);
|
||||
}
|
||||
|
||||
// $my_agent_list = Agent::getLevel4AgentId(Agent::getAgentId(), [Agent::getAgentId()]);
|
||||
|
||||
// $users = $users->whereIn('agent_note_id', $my_agent_list);
|
||||
|
||||
$agent_id = Agent::getAgentId();
|
||||
$users = $users->whereRaw("FIND_IN_SET($agent_id,`agent_path`)");
|
||||
|
||||
$data = $users->get()->toArray();
|
||||
//dd($data);
|
||||
return Excel::create('用户列表', function ($excel) use ($data) {
|
||||
$excel->sheet('用户列表', function ($sheet) use ($data) {
|
||||
$sheet->cell('A1', function ($cell) {
|
||||
$cell->setValue('ID');
|
||||
});
|
||||
$sheet->cell('B1', function ($cell) {
|
||||
$cell->setValue('用户名');
|
||||
});
|
||||
$sheet->cell('C1', function ($cell) {
|
||||
$cell->setValue('用户身份');
|
||||
});
|
||||
$sheet->cell('D1', function ($cell) {
|
||||
$cell->setValue('上级代理商');
|
||||
});
|
||||
$sheet->cell('E1', function ($cell) {
|
||||
$cell->setValue('USDT余额');
|
||||
});
|
||||
$sheet->cell('F1', function ($cell) {
|
||||
$cell->setValue('邮箱');
|
||||
});
|
||||
$sheet->cell('G1', function ($cell) {
|
||||
$cell->setValue('邀请码');
|
||||
});
|
||||
$sheet->cell('H1', function ($cell) {
|
||||
$cell->setValue('加入时间');
|
||||
});
|
||||
|
||||
|
||||
if (!empty($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
|
||||
$i = $key + 2;
|
||||
$sheet->cell('A' . $i, $value['id']);
|
||||
$sheet->cell('B' . $i, $value['account_number']);
|
||||
$sheet->cell('C' . $i, $value['my_agent_level']);
|
||||
$sheet->cell('D' . $i, $value['parent_name']);
|
||||
$sheet->cell('E' . $i, $value['usdt']);
|
||||
$sheet->cell('F' . $i, $value['email']);
|
||||
$sheet->cell('G' . $i, $value['extension_code']);
|
||||
$sheet->cell('H' . $i, $value['create_date']);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
ob_end_clean();
|
||||
});
|
||||
})->download('xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* 结算列表首页
|
||||
*/
|
||||
public function jieIndex(Request $request){
|
||||
//法币
|
||||
$legal_currencies = Currency::where('is_legal', 1)->get();
|
||||
//下级代理
|
||||
$son_agents = Agent::getAllChildAgent(Agent::getAgentId());
|
||||
$self=Agent::getAgent();
|
||||
$is_admin=$self?$self->is_admin:0;
|
||||
return view('agent.order.jie_index',[
|
||||
'legal_currencies' => $legal_currencies,
|
||||
'son_agents' => $son_agents,
|
||||
'is_admin'=>$is_admin
|
||||
]);
|
||||
}
|
||||
|
||||
public function jie_list(Request $request)
|
||||
{
|
||||
|
||||
$limit = $request->input("limit", 10);
|
||||
$start = $request->input("start", '');
|
||||
$end = $request->input("end", '');
|
||||
|
||||
$agent_id = Agent::getAgentId();
|
||||
//$node_users = Users::whereRaw("FIND_IN_SET($agent_id,`agent_path`)")->pluck('id')->all();
|
||||
$child_agents = Agent::getAllChildAgent($agent_id);
|
||||
$son_agents = $child_agents->pluck('id')->all();
|
||||
|
||||
$lists = AgentMoneylog::whereIn('agent_id', $son_agents)
|
||||
->where(function ($query) use ($request) {
|
||||
|
||||
$id = $request->input("id", 0);
|
||||
$username = $request->input("username", '');
|
||||
$belong_agent = $request->input('belong_agent', '');
|
||||
$legal_id = $request->input('legal_id', -1);
|
||||
|
||||
$type = $request->input("type", -1);//1 头寸 2手续费
|
||||
|
||||
$query->when($id > 0,function($query) use ($id){
|
||||
$query->where('id',$id);
|
||||
})->when($username != '', function ($query) use ($username) {
|
||||
$query->whereHas('user', function ($query) use ($username) {
|
||||
$query->where('account_number', $username);
|
||||
});
|
||||
})->when($belong_agent != '', function ($query) use ($belong_agent) {
|
||||
$query->whereHas('agent', function ($query) use ($belong_agent) {
|
||||
$query->where('username', $belong_agent);
|
||||
});
|
||||
})->when($legal_id > 0, function ($query) use ($legal_id) {
|
||||
$query->where('legal_id', $legal_id);
|
||||
})->when($type > 0, function ($query) use ($type) {
|
||||
$query->where('type', $type);
|
||||
});
|
||||
})->where(function ($query) use ($start, $end) {
|
||||
|
||||
!empty($start) && $query->where('created_time', '>=', strtotime($start . ' 0:0:0'));
|
||||
|
||||
!empty($end) && $query->where('created_time', '<=', strtotime($end . ' 23:59:59'));
|
||||
})
|
||||
->orderBy('id', 'desc')
|
||||
->paginate($limit);
|
||||
|
||||
return $this->layuiData($lists);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订单详情
|
||||
*/
|
||||
public function order_info(Request $request)
|
||||
{
|
||||
$order_id = $request->input("order_id", 0);
|
||||
|
||||
if ($order_id > 0) {
|
||||
// $sons = $this->get_my_sons();
|
||||
|
||||
//$orderinfo = TransactionOrder::where('id', $order_id)->whereIn('user_id', $sons['all'])->first();
|
||||
$orderinfo = LeverTransaction::where('id', $order_id)->first();
|
||||
|
||||
if (empty($orderinfo)) {
|
||||
return $this->error('订单编号错误或者您无权查看订单详情');
|
||||
} else {
|
||||
//dd($orderinfo);
|
||||
return view("agent.order.info", ['info' => $orderinfo]);
|
||||
// $data['info'] = $orderinfo;
|
||||
// return $this->ajaxReturn($data);
|
||||
}
|
||||
} else {
|
||||
return $this->error('非法参数');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $san_user
|
||||
*
|
||||
*/
|
||||
public function sel_arr($arr = array())
|
||||
{
|
||||
if (!empty($arr)) {
|
||||
$new_arr = [];
|
||||
foreach ($arr as $k => $val) {
|
||||
$new_arr[] = $val->user_id;
|
||||
}
|
||||
return $new_arr;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $san_user
|
||||
*
|
||||
*/
|
||||
public function sel_agent_arr($arr = array())
|
||||
{
|
||||
if (!empty($arr)) {
|
||||
$new_arr = [];
|
||||
foreach ($arr as $k => $val) {
|
||||
$new_arr[] = $val->id;
|
||||
}
|
||||
return $new_arr;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
//我的杠杆订单
|
||||
public function userLeverIndex(Request $request)
|
||||
{
|
||||
$id = $request->get('id', null);
|
||||
if (empty($id)) {
|
||||
return $this->error('参数错误');
|
||||
}
|
||||
|
||||
return view("agent.user.leverlist", ['user_id' => $id]);
|
||||
}
|
||||
|
||||
public function userLeverList(Request $request)
|
||||
{
|
||||
|
||||
$limit = $request->input("limit", 10);
|
||||
|
||||
$status = $request->input("status", 10);
|
||||
$type = $request->input("type", 0);
|
||||
|
||||
$start = $request->input("start", '');
|
||||
$end = $request->input("end", '');
|
||||
$user_id = $request->input("user_id", '');
|
||||
|
||||
|
||||
$query = TransactionOrder::where('user_id', $user_id)->where(function ($query) use ($status, $type) {
|
||||
|
||||
|
||||
$status != 10 && in_array($status, [LeverTransaction::ENTRUST, LeverTransaction::TRANSACTION, LeverTransaction::CLOSED, LeverTransaction::CANCEL, LeverTransaction::CLOSING]) && $query->where('status', $status);
|
||||
|
||||
$type > 0 && in_array($type, [1, 2]) && $query->where('type', $type);
|
||||
})->where(function ($query) use ($start, $end) {
|
||||
|
||||
!empty($start) && $query->where('create_time', '>=', strtotime($start . ' 0:0:0'));
|
||||
|
||||
!empty($end) && $query->where('create_time', '<=', strtotime($end . ' 23:59:59'));
|
||||
});
|
||||
|
||||
|
||||
$order_list = $query->orderBy('id', 'desc')->paginate($limit);
|
||||
|
||||
return $this->layuiData($order_list);
|
||||
}
|
||||
|
||||
public function microIndex(){
|
||||
$currencies = Currency::where('is_micro', 1)->get();
|
||||
$currency_matches = CurrencyMatch::where('open_microtrade', 1)->get();
|
||||
|
||||
return view("agent.order.microlist",[
|
||||
'currencies' => $currencies,
|
||||
'currency_matches'=>$currency_matches
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
//获取交易对和支付币种
|
||||
public function microCurrency()
|
||||
{
|
||||
$currencies = Currency::where('is_micro', 1)->get();
|
||||
$currency_matches = CurrencyMatch::where('open_microtrade', 1)->get();
|
||||
$data = [];
|
||||
$data['currencies'] = $currencies;
|
||||
$data['currency_matches'] = $currency_matches;
|
||||
|
||||
return $this->ajaxReturn($data);
|
||||
}
|
||||
//期权订单
|
||||
public function microList(Request $request)
|
||||
{
|
||||
$currency_id = $request->input('currency_id', -1);
|
||||
$match_id = $request->input('match_id', -1);
|
||||
|
||||
$type = $request->input('type', -1);
|
||||
$account = $request->input('account', '');
|
||||
$name = $request->input('name', '');
|
||||
$limit = $request->input('limit', 10);
|
||||
$status = $request->input('status', -1);
|
||||
$start = $request->input("start_time", '');
|
||||
$end = $request->input("end_time", '');
|
||||
$pre_profit_result = $request->input('pre_profit_result', -2);
|
||||
$profit_result = $request->input('profit_result', -2);
|
||||
$id = $request->input('id', '');
|
||||
$agentusername = $request->input('agentusername', '');
|
||||
|
||||
$_self = Agent::getAgent(); //获取当前登录代理商平台用户
|
||||
$agent_id = Agent::getAgentId();
|
||||
if ($agentusername != '') {
|
||||
|
||||
$search_agent = Agent::where('username', $agentusername)->first();
|
||||
if (!$search_agent) {
|
||||
return $this->error('代理商不存在');
|
||||
}
|
||||
|
||||
$parent_agent = explode(',', $search_agent->agent_path);
|
||||
|
||||
if (!in_array($agent_id, $parent_agent)) {
|
||||
return $this->error('该代理商并不属于您的团队');
|
||||
}
|
||||
|
||||
$now_agent_id = $search_agent->id;
|
||||
} else {
|
||||
$now_agent_id = $agent_id;
|
||||
}
|
||||
|
||||
|
||||
$querys = MicroOrder::with(['currency', 'currencyMatch', 'user'])
|
||||
->when($currency_id != -1, function ($query) use ($currency_id) {
|
||||
$query->where('currency_id', $currency_id);
|
||||
})->when($match_id != -1, function ($query) use ($match_id) {
|
||||
$query->where('match_id', $match_id);
|
||||
})->when($type != -1, function ($query) use ($type) {
|
||||
$query->where('type', $type);
|
||||
})->when($status != -1, function ($query) use ($status) {
|
||||
$query->where('status', $status);
|
||||
})->when($pre_profit_result != -2, function ($query) use ($pre_profit_result) {
|
||||
$query->where('pre_profit_result', $pre_profit_result);
|
||||
})->when($profit_result != -2, function ($query) use ($profit_result) {
|
||||
$query->where('profit_result', $profit_result);
|
||||
})->when($account != '' || $name != '', function ($query) use ($account, $name) {
|
||||
$query->whereHas('user', function ($query) use ($account, $name) {
|
||||
$account != '' && $query->where("phone", 'like', '%' . $account . '%')->orwhere('email', 'like', '%' . $account . '%');
|
||||
$query->when($name != '', function ($query) use ($name) {
|
||||
$query->whereHas('userProfile', function ($query) use ($name) {
|
||||
$query->where("name", 'like', '%' . $name . '%');
|
||||
});
|
||||
});
|
||||
});
|
||||
})->when($start != '', function ($query) use ($start) {
|
||||
$query->where('created_at', '>=', $start);
|
||||
})->when($end != '', function ($query) use ($end) {
|
||||
$query->where('created_at', '<=', $end);
|
||||
})->when($id != '', function ($query) use ($id) {
|
||||
$query->where('id', $id);
|
||||
})->where(function ($query) use ($now_agent_id) {
|
||||
|
||||
$now_agent_id > 0 && $query->whereRaw("FIND_IN_SET($now_agent_id,`agent_path`)");
|
||||
});
|
||||
|
||||
$query_total = clone $querys;
|
||||
$total = $query_total->select([
|
||||
DB::raw('*'),
|
||||
DB::raw('sum(fee) as total_fee'),
|
||||
DB::raw('sum(fact_profits) as total_fact_profits'),
|
||||
|
||||
])->first()->setVisible(['total_fee', 'total_fact_profits']);
|
||||
|
||||
//$total='';
|
||||
|
||||
$results = $querys->orderBy('id', 'desc')->paginate($limit);
|
||||
$items = $results->getCollection();
|
||||
$items->transform(function ($item, $key) {
|
||||
return $item->append('pre_profit_result_name')->makeVisible('pre_profit_result');
|
||||
});
|
||||
$results->setCollection($items);
|
||||
return $this->layuiData($results, ['total' => $total]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,643 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Jobs\NewDoJie;
|
||||
use App\{Users, Agent, Setting, LeverTransaction,TransactionOrder,AgentMoneylog};
|
||||
|
||||
/**
|
||||
* 该类处理所有的统计报表数据。
|
||||
* Class ReportController
|
||||
* @package App\Http\Controllers\Agent
|
||||
*/
|
||||
class ReportController extends Controller
|
||||
{
|
||||
|
||||
//主页
|
||||
public function home()
|
||||
{
|
||||
//统计信息
|
||||
|
||||
//当前代理商信息
|
||||
$agent_id = Agent::getAgentId();
|
||||
|
||||
|
||||
$settlement = LeverTransaction::whereIn('status', [2, 3])->where('settled', 1)->whereRaw("FIND_IN_SET($agent_id,`agent_path`)")->count(); //结算订单数量
|
||||
|
||||
$subordinate_agent_num = Agent::where('parent_agent_id', $agent_id)->count(); //下级代理商数量
|
||||
|
||||
$subordinate_user_num = Users::whereRaw("FIND_IN_SET($agent_id,`agent_path`)")->count(); //伞下用户数量
|
||||
|
||||
return view("agent.home", ['settlement' => $settlement, 'subordinate_agent_num' => $subordinate_agent_num, 'subordinate_user_num' => $subordinate_user_num]);
|
||||
}
|
||||
|
||||
//订单统计
|
||||
public function orderSt()
|
||||
{
|
||||
return view("agent.statistics.order");
|
||||
}
|
||||
|
||||
//用户统计
|
||||
public function userSt()
|
||||
{
|
||||
return view("agent.statistics.user");
|
||||
}
|
||||
|
||||
//收益统计
|
||||
public function moneySt()
|
||||
{
|
||||
return view("agent.statistics.money");
|
||||
}
|
||||
|
||||
//日订单量
|
||||
public function day()
|
||||
{
|
||||
|
||||
$agent_id = Agent::getAgentId();
|
||||
|
||||
$day = [];
|
||||
$info = [];
|
||||
|
||||
for ($i = 0; $i < 24; $i++) {
|
||||
$day[] = $i . '点';
|
||||
|
||||
$start = strtotime(date('Y-m-d') . ' ' . $i . ':0:0');
|
||||
$end = strtotime(date('Y-m-d') . ' ' . $i . ':59:59');
|
||||
|
||||
$info[] = LeverTransaction::whereIn('status', [LeverTransaction::TRANSACTION, LeverTransaction::CLOSING, LeverTransaction::CLOSED])->whereRaw("FIND_IN_SET($agent_id,`agent_path`)")->whereBetween('create_time', [$start, $end])->count();
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['day'] = $day;
|
||||
$data['info'] = $info;
|
||||
|
||||
return $this->ajaxReturn($data);
|
||||
}
|
||||
|
||||
|
||||
public function jie(Request $request)
|
||||
{
|
||||
|
||||
$type = $request->input('type', '');
|
||||
if (!empty($type) && in_array($type, ['all', 'search'])) {
|
||||
|
||||
$returnData = [];
|
||||
|
||||
//以周为单位获取每天的时间戳
|
||||
$a = Agent::get_weeks(date("Y-m-d", strtotime("-1 year")), date('Y-m-d'));
|
||||
|
||||
$b = [];
|
||||
$c = [];
|
||||
for ($i = 0; $i < count($a); $i++) {
|
||||
$jo = explode('/', $a[$i]);
|
||||
$start = strtotime($jo[0] . ' 0:0:0');
|
||||
$end = strtotime($jo[1] . ' 23:59:59');
|
||||
$b[] = DB::table('lever_transaction')->where('status', LeverTransaction::CLOSED)->where('settled', 0)->whereBetween('complete_time', [$start, $end])->count();
|
||||
$_z = count($a) - 1 - $i;
|
||||
if ($_z == 0) {
|
||||
$c[] = '本周';
|
||||
} else {
|
||||
$c[] = $_z . '周前';
|
||||
}
|
||||
}
|
||||
$returnData['series'] = $b;
|
||||
$returnData['xAxis'] = $c;
|
||||
|
||||
return $this->ajaxReturn($returnData);
|
||||
} else {
|
||||
return $this->error('非法操作');
|
||||
}
|
||||
}
|
||||
|
||||
//杠杆订单结算(对账)
|
||||
public function dojie(Request $request)
|
||||
{
|
||||
|
||||
$start = $request->input("start", '');
|
||||
$end = $request->input("end", '');
|
||||
$id = $request->input("id", 0);
|
||||
$username = $request->input("username", '');
|
||||
$belong_agent = $request->input('belong_agent', '');
|
||||
$legal_id = $request->input('legal_id', -1);
|
||||
|
||||
//超级代理 有权限
|
||||
$self=Agent::getAgent();
|
||||
if($self->is_admin != 1){
|
||||
return $this->error('只有超级代理才有权限');
|
||||
}
|
||||
$agent_id =$self->id;
|
||||
|
||||
if ($belong_agent != '') {
|
||||
|
||||
$search_agent = Agent::where('username', $belong_agent)->first();
|
||||
if (!$search_agent) {
|
||||
return $this->error('代理商不存在');
|
||||
}
|
||||
|
||||
$parent_agent = explode(',', $search_agent->agent_path);
|
||||
|
||||
if (!in_array($agent_id, $parent_agent)) {
|
||||
return $this->error('该代理商并不属于您的团队');
|
||||
}
|
||||
|
||||
$now_agent_id = $search_agent->id;
|
||||
} else {
|
||||
$now_agent_id = $agent_id;
|
||||
}
|
||||
|
||||
$lever_ids = TransactionOrder::whereHas('user', function ($query) use ($username) {
|
||||
|
||||
$username != '' && $query->where('account_number', $username)->orWhere('phone', $username);
|
||||
})->where(function ($query) use ($start, $end) {
|
||||
//平仓时间
|
||||
!empty($start) && $query->where('complete_time', '>=', strtotime($start . ' 0:0:0'));
|
||||
|
||||
!empty($end) && $query->where('complete_time', '<=', strtotime($end . ' 23:59:59'));
|
||||
})->where(function ($query) use ($now_agent_id) {
|
||||
|
||||
$now_agent_id > 0 && $query->whereRaw("FIND_IN_SET($now_agent_id,`agent_path`)");
|
||||
})->when($legal_id > 0, function ($query) use ($legal_id) {
|
||||
|
||||
$query->where('legal',$legal_id);
|
||||
|
||||
})->when($id > 0 ,function($query) use ($id){
|
||||
$query->where('id',$id);
|
||||
})->where('status',LeverTransaction::CLOSED)
|
||||
->where('settled',0)
|
||||
->get()->pluck('id')->all();
|
||||
|
||||
//var_dump($lever_ids);
|
||||
|
||||
if(!empty($lever_ids)){
|
||||
|
||||
NewDoJie::dispatch($lever_ids)->onQueue('dojie');
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $this->success('正在结算~请稍后刷新页面');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function order(Request $request)
|
||||
{
|
||||
|
||||
$_self = Agent::getAgent();
|
||||
if ($_self === null) {
|
||||
return $this->outmsg('发生错误!请重新登录');
|
||||
}
|
||||
|
||||
//$sons = $this->get_my_sons();
|
||||
|
||||
//获取伞下用户
|
||||
$node_users=Users::whereRaw("FIND_IN_SET($_self->id,`agent_path`)")->pluck('id')->all();
|
||||
|
||||
$type = $request->input('type', '');
|
||||
if (!empty($type) && in_array($type, ['all', 'search'])) {
|
||||
|
||||
$returnData = [];
|
||||
|
||||
//以周为单位获取每天的时间戳
|
||||
$a = Agent::get_weeks(date("Y-m-d", strtotime("-1 year")), date('Y-m-d'));
|
||||
|
||||
$b = [];
|
||||
$c = [];
|
||||
for ($i = 0; $i < count($a); $i++) {
|
||||
$jo = explode('/', $a[$i]);
|
||||
$start = strtotime($jo[0] . ' 0:0:0');
|
||||
$end = strtotime($jo[1] . ' 23:59:59');
|
||||
$b[] = DB::table('lever_transaction')->where('status', LeverTransaction::CLOSED)->whereBetween('complete_time', [$start, $end])->whereIn('user_id',$node_users)->count();
|
||||
$d[] = DB::table('lever_transaction')->whereIn('status',[LeverTransaction::TRANSACTION, LeverTransaction::CLOSING])->whereBetween('create_time', [$start, $end])->whereIn('user_id', $node_users)->count();
|
||||
$_z = count($a) - 1 - $i;
|
||||
if ($_z == 0) {
|
||||
$c[] = '本周';
|
||||
} else {
|
||||
$c[] = $_z . '周前';
|
||||
}
|
||||
}
|
||||
$returnData['series'] = $b;
|
||||
$returnData['selling'] = $d;
|
||||
$returnData['xAxis'] = $c;
|
||||
|
||||
return $this->ajaxReturn($returnData);
|
||||
} else {
|
||||
return $this->error('非法操作');
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
public function order_num()
|
||||
{
|
||||
|
||||
$_self = Agent::getAgent();
|
||||
if ($_self === null) {
|
||||
return $this->outmsg('发生错误!请重新登录');
|
||||
}
|
||||
|
||||
// $sons = $this->get_my_sons();
|
||||
//获取伞下用户
|
||||
$node_users=Users::whereRaw("FIND_IN_SET($_self->id,`agent_path`)")->pluck('id')->all();
|
||||
|
||||
//交易中的订单数量
|
||||
$a = DB::table('lever_transaction')->where('status', LeverTransaction::TRANSACTION)->whereIn('user_id', $node_users)->count();
|
||||
//平仓中的订单数量
|
||||
$b = DB::table('lever_transaction')->where('status', LeverTransaction::CLOSING)->whereIn('user_id', $node_users)->count();
|
||||
//已平仓的订单数量
|
||||
$c = DB::table('lever_transaction')->where('status', LeverTransaction::CLOSED)->whereIn('user_id', $node_users)->count();
|
||||
|
||||
$data = [];
|
||||
$data['a'] = $a;
|
||||
$data['b'] = $b;
|
||||
$data['c'] = $c;
|
||||
|
||||
return $this->ajaxReturn($data);
|
||||
}
|
||||
|
||||
|
||||
//统计有问题?? 待优化
|
||||
public function order_money()
|
||||
{
|
||||
|
||||
$_self = Agent::getAgent();
|
||||
if ($_self === null) {
|
||||
return $this->outmsg('发生错误!请重新登录');
|
||||
}
|
||||
|
||||
//$sons = $this->get_my_sons();
|
||||
//获取伞下用户
|
||||
$node_users=Users::whereRaw("FIND_IN_SET($_self->id,`agent_path`)")->pluck('id')->all();
|
||||
|
||||
//交易中
|
||||
$a = DB::table('lever_transaction')->where('status', LeverTransaction::BUY)->whereIn('user_id', $node_users)->sum('price');
|
||||
//平仓中
|
||||
$b = DB::table('lever_transaction')->where('status', LeverTransaction::CLOSING)->whereIn('user_id', $node_users)->sum('price');
|
||||
//已平仓
|
||||
$c = DB::table('lever_transaction')->where('status', LeverTransaction::CLOSED)->whereIn('user_id', $node_users)->sum('price');
|
||||
|
||||
$data = [];
|
||||
$data['a'] = $a;
|
||||
$data['b'] = $b;
|
||||
$data['c'] = $c;
|
||||
|
||||
return $this->ajaxReturn($data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
|
||||
$_self = Agent::getAgent();
|
||||
if ($_self === null) {
|
||||
return $this->outmsg('发生错误!请重新登录');
|
||||
}
|
||||
|
||||
//$sons = $this->get_my_sons();
|
||||
|
||||
//伞下代理商及用户id
|
||||
$agent_id = $_self->id;
|
||||
$node_users = Users::whereRaw("FIND_IN_SET($agent_id,`agent_path`)")->pluck('id')->all();
|
||||
|
||||
$returnData = [];
|
||||
|
||||
//以周为单位获取每天的时间戳
|
||||
$a = Agent::get_weeks(date("Y-m-d", strtotime("-1 year")), date('Y-m-d'));
|
||||
|
||||
$b = [];
|
||||
$c = [];
|
||||
$d = [];
|
||||
for ($i = 0; $i < count($a); $i++) {
|
||||
$jo = explode('/', $a[$i]);
|
||||
$start = strtotime($jo[0] . ' 0:0:0');
|
||||
$end = strtotime($jo[1] . ' 23:59:59');
|
||||
//活跃用户
|
||||
$count= LeverTransaction::whereIn('status', [LeverTransaction::TRANSACTION, LeverTransaction::CLOSING, LeverTransaction::CLOSED])->whereBetween('create_time', [$start, $end])->whereIn('user_id', $node_users)->select("user_id")->groupBy('user_id')->get()->toArray();
|
||||
$b[]=count($count);
|
||||
|
||||
//注册用户
|
||||
$d[] = DB::table('users')->whereBetween('time', [$start, $end])->whereIn('id', $node_users)->count();
|
||||
$_z = count($a) - 1 - $i;
|
||||
if ($_z == 0) {
|
||||
$c[] = '本周';
|
||||
} else {
|
||||
$c[] = $_z . '周前';
|
||||
}
|
||||
}
|
||||
$returnData['huoyue'] = $b;
|
||||
$returnData['reg'] = $d;
|
||||
$returnData['xAxis'] = $c;
|
||||
|
||||
return $this->ajaxReturn($returnData);
|
||||
}
|
||||
|
||||
|
||||
//统计用户 代理商数据 待优化
|
||||
public function user_num()
|
||||
{
|
||||
$_self = Agent::getAgent();
|
||||
if ($_self === null) {
|
||||
return $this->outmsg('发生错误!请重新登录');
|
||||
}
|
||||
|
||||
$sons = $this->get_my_sons();
|
||||
|
||||
$data = [];
|
||||
$data['san'] = count($sons['san']);
|
||||
$data['one'] = count($sons['one']);
|
||||
$data['two'] = count($sons['two']);
|
||||
$data['three'] = count($sons['three']);
|
||||
$data['four'] = count($sons['four']);
|
||||
|
||||
return $this->ajaxReturn($data);
|
||||
//$son=Users::where('agent_id',0)->whereRaw("FIND_IN_SET($_self->id,`agent_path`)")->count();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//统计收益 待优化
|
||||
public function user_money()
|
||||
{
|
||||
|
||||
$_self = Agent::getAgent();
|
||||
if ($_self === null) {
|
||||
return $this->outmsg('发生错误!请重新登录');
|
||||
}
|
||||
|
||||
$sons = $this->get_my_sons();
|
||||
|
||||
$data = [];
|
||||
$data['san'] = DB::table('lever_transaction')->whereIn('status', [LeverTransaction::BUY, LeverTransaction::CLOSING, LeverTransaction::CLOSED])->whereIn('user_id', $sons['san'])->sum('price');
|
||||
$data['one'] = DB::table('lever_transaction')->whereIn('status', [LeverTransaction::BUY, LeverTransaction::CLOSING, LeverTransaction::CLOSED])->whereIn('user_id', $sons['one'])->sum('price');
|
||||
$data['two'] = DB::table('lever_transaction')->whereIn('status', [LeverTransaction::BUY, LeverTransaction::CLOSING, LeverTransaction::CLOSED])->whereIn('user_id', $sons['two'])->sum('price');
|
||||
$data['three'] = DB::table('lever_transaction')->whereIn('status', [LeverTransaction::BUY, LeverTransaction::CLOSING, LeverTransaction::CLOSED])->whereIn('user_id', $sons['three'])->sum('price');
|
||||
$data['four'] = DB::table('lever_transaction')->whereIn('status', [LeverTransaction::BUY, LeverTransaction::CLOSING, LeverTransaction::CLOSED])->whereIn('user_id', $sons['four'])->sum('price');
|
||||
|
||||
return $this->ajaxReturn($data);
|
||||
}
|
||||
|
||||
|
||||
/** 代理商及其下级代理商的头寸 手续费收益
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function agental(Request $request)
|
||||
{
|
||||
|
||||
|
||||
$_self = Agent::getAgent();
|
||||
if ($_self === null) {
|
||||
return $this->outmsg('发生错误!请重新登录');
|
||||
}
|
||||
|
||||
//$sons = $this->get_my_sons();
|
||||
|
||||
$child_agents = Agent::getAllChildAgent($_self->id);
|
||||
$son_agents = $child_agents->pluck('id')->all();
|
||||
|
||||
$returnData = [];
|
||||
|
||||
//以周为单位获取每天的时间戳
|
||||
$a = Agent::get_weeks(date("Y-m-d", strtotime("-1 year")), date('Y-m-d'));
|
||||
|
||||
$b = [];
|
||||
$c = [];
|
||||
$d = [];
|
||||
for ($i = 0; $i < count($a); $i++) {
|
||||
$jo = explode('/', $a[$i]);
|
||||
$start = strtotime($jo[0] . ' 0:0:0');
|
||||
$end = strtotime($jo[1] . ' 23:59:59');
|
||||
//头寸收益
|
||||
$b[] = AgentMoneylog::whereIn('agent_id', $son_agents)->whereBetween('created_time', [$start, $end])->where('type', 1)->sum('change');
|
||||
//手续费收益
|
||||
$d[] =AgentMoneylog::whereIn('agent_id', $son_agents)->whereBetween('created_time', [$start, $end])->where('type', 2)->sum('change');
|
||||
$_z = count($a) - 1 - $i;
|
||||
if ($_z == 0) {
|
||||
$c[] = '本周';
|
||||
} else {
|
||||
$c[] = $_z . '周前';
|
||||
}
|
||||
}
|
||||
$returnData['tocufy'] = $b;
|
||||
$returnData['sxuf'] = $d;
|
||||
$returnData['xAxis'] = $c;
|
||||
|
||||
return $this->ajaxReturn($returnData);
|
||||
}
|
||||
|
||||
//待优化
|
||||
public function agental_t()
|
||||
{
|
||||
|
||||
$_self = Agent::getAgent();
|
||||
if ($_self === null) {
|
||||
return $this->outmsg('发生错误!请重新登录');
|
||||
}
|
||||
|
||||
$sons = $this->get_my_sons();
|
||||
|
||||
$data = [];
|
||||
$data['san'] =0; //DB::table('agent_money_log')->where('agent_id' , $_self->id)->where('type' , 2)->whereIn('son_user_id' , $sons['san'])->sum('change');
|
||||
$data['one'] = 61; //DB::table('agent_money_log')->where('agent_id' , $_self->id)->where('type' , 2)->whereIn('son_user_id' , $sons['one'])->sum('change');
|
||||
$data['two'] = 19; //DB::table('agent_money_log')->where('agent_id' , $_self->id)->where('type' , 2)->whereIn('son_user_id' , $sons['two'])->sum('change');
|
||||
$data['three'] = DB::table('agent_money_log')->where('agent_id', $_self->id)->where('type', 2)->whereIn('son_user_id', $sons['three'])->sum('change');
|
||||
$data['four'] = DB::table('agent_money_log')->where('agent_id', $_self->id)->where('type', 2)->whereIn('son_user_id', $sons['four'])->sum('change');
|
||||
|
||||
return $this->ajaxReturn($data);
|
||||
}
|
||||
|
||||
//待优化
|
||||
public function agental_s()
|
||||
{
|
||||
|
||||
$_self = Agent::getAgent();
|
||||
if ($_self === null) {
|
||||
return $this->outmsg('发生错误!请重新登录');
|
||||
}
|
||||
|
||||
$sons = $this->get_my_sons();
|
||||
|
||||
$data = [];
|
||||
$data['san'] = 0; //DB::table('agent_money_log')->where('agent_id' , $_self->id)->where('type' , 1)->whereIn('son_user_id' , $sons['san'])->sum('change');
|
||||
$data['one'] = DB::table('agent_money_log')->where('agent_id', $_self->id)->where('type', 1)->whereIn('son_user_id', $sons['one'])->sum('change');
|
||||
$data['two'] = 8; //DB::table('agent_money_log')->where('agent_id' , $_self->id)->where('type' , 1)->whereIn('son_user_id' , $sons['two'])->sum('change');
|
||||
$data['three'] = DB::table('agent_money_log')->where('agent_id', $_self->id)->where('type', 1)->whereIn('son_user_id', $sons['three'])->sum('change');
|
||||
$data['four'] = DB::table('agent_money_log')->where('agent_id', $_self->id)->where('type', 1)->whereIn('son_user_id', $sons['four'])->sum('change');
|
||||
|
||||
return $this->ajaxReturn($data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取我的所有的下级。包括所有的散户和各级代理商
|
||||
*/
|
||||
public function get_my_sons($agent_id = 0)
|
||||
{
|
||||
|
||||
if ($agent_id === 0) {
|
||||
$_self = Agent::getAgent();
|
||||
} else {
|
||||
$_self = Agent::getAgentById($agent_id);
|
||||
}
|
||||
|
||||
$_one = [];
|
||||
$_one_sons = [];
|
||||
$_two = [];
|
||||
$_two_sons = [];
|
||||
$_three = [];
|
||||
$_three_sons = [];
|
||||
$_four = [];
|
||||
$_four_sons = [];
|
||||
switch ($_self->level) {
|
||||
case 0:
|
||||
$_one = DB::table('agent')->where('level', 1)->select('user_id', 'id')->get()->toArray();
|
||||
$_two = DB::table('agent')->where('level', 2)->select('user_id', 'id')->get()->toArray();
|
||||
$_three = DB::table('agent')->where('level', 3)->select('user_id', 'id')->get()->toArray();
|
||||
$_four = DB::table('agent')->where('level', 4)->select('user_id', 'id')->get()->toArray();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$_two = DB::table('agent')->where('parent_agent_id', $_self->id)->get()->toArray();
|
||||
$_one_sons = DB::table('users')->where('agent_id', 0)->where('agent_note_id', $_self->id)->get()->toArray();
|
||||
|
||||
if (!empty($_two)) {
|
||||
foreach ($_two as $key => $value) {
|
||||
$_a = DB::table('agent')->where('parent_agent_id', $value->id)->get()->toArray();
|
||||
$_b = DB::table('users')->where('agent_id', 0)->where('agent_note_id', $value->id)->get()->toArray();
|
||||
$_three = array_merge($_three, $_a);
|
||||
$_two_sons = array_merge($_two_sons, $_b);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_three)) {
|
||||
foreach ($_three as $key => $value) {
|
||||
$_a = DB::table('agent')->where('parent_agent_id', $value->id)->get()->toArray();
|
||||
$_b = DB::table('users')->where('agent_id', 0)->where('agent_note_id', $value->id)->get()->toArray();
|
||||
$_four = array_merge($_four, $_a);
|
||||
$_three_sons = array_merge($_three_sons, $_b);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_four)) {
|
||||
foreach ($_four as $key => $value) {
|
||||
$_b = DB::table('users')->where('agent_id', 0)->where('agent_note_id', $value->id)->get()->toArray();
|
||||
$_three_sons = array_merge($_three_sons, $_b);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
$_three = DB::table('agent')->where('parent_agent_id', $_self->id)->get()->toArray();
|
||||
$_two_sons = DB::table('users')->where('agent_id', 0)->where('agent_note_id', $_self->id)->get()->toArray();
|
||||
if (!empty($_two)) {
|
||||
foreach ($_two as $key => $value) {
|
||||
$_a = DB::table('agent')->where('parent_agent_id', $value->id)->get()->toArray();
|
||||
$_b = DB::table('users')->where('agent_id', 0)->where('agent_note_id', $value->id)->get()->toArray();
|
||||
$_four = array_merge($_four, $_a);
|
||||
$_three_sons = array_merge($_three_sons, $_b);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_four)) {
|
||||
foreach ($_four as $key => $value) {
|
||||
$_b = DB::table('users')->where('agent_id', 0)->where('agent_note_id', $value->id)->get()->toArray();
|
||||
$_four_sons = array_merge($_four_sons, $_b);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
$_four = DB::table('agent')->where('parent_agent_id', $_self->id)->get()->toArray();
|
||||
$_three_sons = DB::table('users')->where('agent_id', 0)->where('agent_note_id', $_self->id)->get()->toArray();
|
||||
|
||||
if (!empty($_four)) {
|
||||
foreach ($_four as $key => $value) {
|
||||
$_b = DB::table('users')->where('agent_id', 0)->where('agent_note_id', $value->id)->get()->toArray();
|
||||
$_four_sons = array_merge($_four_sons, $_b);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
$_four_sons = DB::table('users')->where('agent_id', 0)->where('agent_note_id', $_self->id)->get()->toArray();
|
||||
break;
|
||||
}
|
||||
|
||||
if ($_self->level == 0 && $_self->is_admin == 1) {
|
||||
$san_user = DB::table('users')->where('agent_id', 0)->get()->toArray(); //所有的散户
|
||||
$san_user = $this->sel_agent_arr($san_user);
|
||||
} else {
|
||||
$a = $this->sel_agent_arr($_one_sons);
|
||||
$b = $this->sel_agent_arr($_two_sons);
|
||||
$c = $this->sel_agent_arr($_three_sons);
|
||||
$d = $this->sel_agent_arr($_four_sons);
|
||||
$san_user = array_merge($a, $b, $c, $d);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['san'] = $san_user;
|
||||
$data['one'] = $this->sel_arr($_one);
|
||||
$data['one_agent'] = $this->sel_agent_arr($_one);
|
||||
$data['two'] = $this->sel_arr($_two);
|
||||
$data['two_agent'] = $this->sel_agent_arr($_two);
|
||||
$data['three'] = $this->sel_arr($_three);
|
||||
$data['three_agent'] = $this->sel_agent_arr($_three);
|
||||
$data['four'] = $this->sel_arr($_four);
|
||||
$data['four_agent'] = $this->sel_agent_arr($_four);
|
||||
$all = array_merge($data['san'], $data['one'], $data['two'], $data['three'], $data['four']);
|
||||
$data['all'] = !empty($all) ? $all : [0];
|
||||
|
||||
$all_agent = array_merge($data['one_agent'], $data['two_agent'], $data['three_agent'], $data['four_agent']);
|
||||
$data['all_agent'] = !empty($all_agent) ? $all_agent : [0];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $san_user
|
||||
*
|
||||
*/
|
||||
public function sel_arr($arr = array())
|
||||
{
|
||||
if (!empty($arr)) {
|
||||
$new_arr = [];
|
||||
foreach ($arr as $k => $val) {
|
||||
$new_arr[] = $val->user_id;
|
||||
}
|
||||
return $new_arr;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $san_user
|
||||
*
|
||||
*/
|
||||
public function sel_agent_arr($arr = array())
|
||||
{
|
||||
if (!empty($arr)) {
|
||||
$new_arr = [];
|
||||
foreach ($arr as $k => $val) {
|
||||
$new_arr[] = $val->id;
|
||||
}
|
||||
return $new_arr;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: YSX
|
||||
* Date: 2018/12/4
|
||||
* Time: 16:36
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\{AccountLog, Agent, Currency, Users, UsersWalletOut, Setting};
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
|
||||
//用户管理
|
||||
public function index()
|
||||
{
|
||||
//某代理商下用户时
|
||||
$parent_id = request()->get('parent_id', 0);
|
||||
//币币
|
||||
$legal_currencies = Currency::get();
|
||||
return view("agent.user.index", ['parent_id' => $parent_id, 'legal_currencies' => $legal_currencies]);
|
||||
}
|
||||
|
||||
//用户列表
|
||||
public function lists(Request $request)
|
||||
{
|
||||
$limit = $request->get('limit', 10);
|
||||
$id = request()->input('id', 0);
|
||||
$parent_id = request()->input('parent_id', 0);
|
||||
$account_number = request()->input('account_number', '');
|
||||
$start = request()->input('start', '');
|
||||
$end = request()->input('end', '');
|
||||
|
||||
$users = new Users();
|
||||
|
||||
$users = $users->leftjoin("user_real", "users.id", "=", "user_real.user_id");
|
||||
|
||||
if ($id) {
|
||||
$users = $users->where('users.id', $id);
|
||||
}
|
||||
if ($parent_id > 0) {
|
||||
$users = $users->where('users.agent_note_id', $parent_id);
|
||||
}
|
||||
if ($account_number) {
|
||||
$users = $users->where('users.account_number', $account_number);
|
||||
}
|
||||
if (!empty($start) && !empty($end)) {
|
||||
$users->whereBetween('users.time', [strtotime($start . ' 0:0:0'), strtotime($end . ' 23:59:59')]);
|
||||
}
|
||||
|
||||
$agent_id = Agent::getAgentId();
|
||||
// var_dump($agent_id);
|
||||
$users = $users->whereRaw("FIND_IN_SET($agent_id,users.agent_path)");
|
||||
|
||||
$list = $users->select("users.*", "user_real.card_id")->paginate($limit);
|
||||
|
||||
return $this->layuiData($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户管理的统计
|
||||
* @param Request $r
|
||||
*/
|
||||
public function get_user_num(Request $request)
|
||||
{
|
||||
|
||||
$id = request()->input('id', 0);
|
||||
$account_number = request()->input('account_number', '');
|
||||
$parent_id = request()->input('parent_id', 0);//代理商id
|
||||
$start = request()->input('start', '');
|
||||
$end = request()->input('end', '');
|
||||
$currency_id = request()->input('currency_id', '');
|
||||
|
||||
$users = new Users();
|
||||
|
||||
if ($id) {
|
||||
$users = $users->where('id', $id);
|
||||
}
|
||||
if ($parent_id > 0) {
|
||||
$users = $users->where('agent_note_id', $parent_id);
|
||||
}
|
||||
if ($account_number) {
|
||||
$users = $users->where('account_number', $account_number);
|
||||
}
|
||||
if (!empty($start) && !empty($end)) {
|
||||
$users->whereBetween('time', [strtotime($start . ' 0:0:0'), strtotime($end . ' 23:59:59')]);
|
||||
}
|
||||
|
||||
$agent_id = Agent::getAgentId();
|
||||
$users = $users->whereRaw("FIND_IN_SET($agent_id,`agent_path`)");
|
||||
$users_id = $users->get()->pluck('id')->all();
|
||||
$_daili = 0;
|
||||
$_ru = 0.00;
|
||||
$_chu = 0.00;
|
||||
$_num = 0;
|
||||
|
||||
$_num = $users->count();
|
||||
|
||||
$_daili = $users->where('agent_id', '>', 0)->count();
|
||||
|
||||
|
||||
$_ru = AccountLog::where('type', AccountLog::CHAIN_RECHARGE)
|
||||
->whereIn('user_id', $users_id)
|
||||
->when($currency_id > 0, function ($query) use ($currency_id) {
|
||||
$query->where('currency', $currency_id);
|
||||
})->sum('value');
|
||||
|
||||
$_chu = UsersWalletOut::where('status', 2)
|
||||
->whereIn('user_id', $users_id)
|
||||
->when($currency_id > 0, function ($query) use ($currency_id) {
|
||||
$query->where('currency', $currency_id);
|
||||
})->sum('real_number');
|
||||
|
||||
$data = [];
|
||||
$data['_num'] = $_num;
|
||||
$data['_daili'] = $_daili;
|
||||
$data['_ru'] = $_ru;
|
||||
$data['_chu'] = $_chu;
|
||||
|
||||
|
||||
return $this->ajaxReturn($data);
|
||||
}
|
||||
|
||||
//我的邀请二维码
|
||||
public function get_my_invite_code()
|
||||
{
|
||||
|
||||
$_self = Agent::getAgent();
|
||||
|
||||
if ($_self == null) {
|
||||
$this->outmsg('超时');
|
||||
}
|
||||
|
||||
$use = Users::getById($_self->user_id);
|
||||
$moblie_h5_url = Setting::getValueByKey('moblie_h5_url', 0);
|
||||
|
||||
return $this->ajaxReturn(['invite_code' => $use->extension_code, 'is_admin' => $_self->is_admin,'moblie_h5_url' => $moblie_h5_url]);
|
||||
}
|
||||
|
||||
//代理商管理
|
||||
public function salesmenIndex()
|
||||
{
|
||||
return view("agent.salesmen.index");
|
||||
}
|
||||
|
||||
//添加代理商页面
|
||||
public function salesmenAdd()
|
||||
{
|
||||
$data = request()->all();
|
||||
|
||||
return view("agent.salesmen.add", ['d' => $data]);
|
||||
}
|
||||
|
||||
public function salesmenEdit()
|
||||
{
|
||||
$data = request()->all();
|
||||
return view("agent.salesmen.add", ['d' => $data]);
|
||||
}
|
||||
//出入金管理
|
||||
public function transferIndex()
|
||||
{
|
||||
return view("agent.user.transfer");
|
||||
}
|
||||
|
||||
//用户点控
|
||||
public function risk()
|
||||
{
|
||||
|
||||
$user_id = request()->get('id', 0);
|
||||
$user=Users::find($user_id);
|
||||
|
||||
return view("agent.user.risk", ['result' => $user]);
|
||||
}
|
||||
|
||||
public function postRisk()
|
||||
{
|
||||
|
||||
$user_id = request()->get('id', 0);
|
||||
$risk = request()->get('risk', 0);
|
||||
$user=Users::find($user_id);
|
||||
$agent_id = Agent::getAgentId();
|
||||
$parent_agent = explode(',', $user->agent_path);
|
||||
|
||||
if (!in_array($agent_id, $parent_agent)) {
|
||||
return $this->error('不是您的伞下用户,不可操作');
|
||||
}
|
||||
try {
|
||||
//code...
|
||||
$user->risk=$risk;
|
||||
$user->save();
|
||||
return $this->success("操作成功");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
//throw $th;
|
||||
return $this->error($th->getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset emails and
|
||||
| includes a trait which assists in sending these notifications from
|
||||
| your application to your users. Feel free to explore this trait.
|
||||
|
|
||||
*/
|
||||
|
||||
use SendsPasswordResetEmails;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles authenticating users for the application and
|
||||
| redirecting them to your home screen. The controller uses a trait
|
||||
| to conveniently provide its functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/home';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest')->except('logout');
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user