feat: 项目基础框架+配置+Kernel

This commit is contained in:
testadmin
2026-04-29 05:35:00 +08:00
parent 6ce7adcbfb
commit 9a6151fce3
5082 changed files with 437062 additions and 0 deletions
@@ -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);
}
}
+90
View File
@@ -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());
}
}
}