267 lines
14 KiB
PHP
267 lines
14 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Agency;
|
|
use App\Models\Payment;
|
|
use App\Models\Seller;
|
|
use App\Models\Withdraw;
|
|
use App\User;
|
|
use Auth;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\View;
|
|
use RuLong\Identity\Models\IdentityLog;
|
|
use RuLong\Identity\Models\UserIdentity;
|
|
use RuLong\Order\Models\Order;
|
|
use RuLong\UserAccount\Models\UserAccount;
|
|
|
|
class DataController extends Controller
|
|
{
|
|
|
|
public function __construct(Request $request)
|
|
{
|
|
parent::__construct($request);
|
|
$this->middleware('auth');
|
|
view()->share('nav', 2);
|
|
$this->todayTime = [Carbon::today()->toDateTimeString(), Carbon::today()->addSecond(86399)->toDateTimeString()];
|
|
}
|
|
|
|
public function users()
|
|
{
|
|
$today = [
|
|
'reg' => User::whereBetween('created_at', $this->todayTime)->count(),
|
|
'counselor' => UserIdentity::whereHas('user')->where('identity_id', 1)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'agency' => UserIdentity::whereHas('user')->where('identity_id', 2)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'manage' => UserIdentity::whereHas('user')->where('identity_id', 3)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'teacher' => UserIdentity::whereHas('user')->where('identity_id', 4)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'salesman' => User::whereBetween('created_at', $this->todayTime)->where('is_salesman', 1)->count(),
|
|
];
|
|
|
|
$all = [
|
|
'reg' => User::count(),
|
|
'counselor' => UserIdentity::whereHas('user')->where('identity_id', 1)->count(),
|
|
'agency' => UserIdentity::whereHas('user')->where('identity_id', 2)->count(),
|
|
'manage' => UserIdentity::whereHas('user')->where('identity_id', 3)->count(),
|
|
'teacher' => UserIdentity::whereHas('user')->where('identity_id', 4)->count(),
|
|
'salesman' => User::where('is_salesman', 1)->count(),
|
|
];
|
|
return view('data.users', compact('today', 'all'));
|
|
}
|
|
|
|
public function orders()
|
|
{
|
|
$state = [
|
|
'PAID', 'DELIVER', 'DELIVERED', 'SIGNED', 'COMPLETED', 'UNUSE', 'USED', 'UNADDRESS',
|
|
];
|
|
$today = [
|
|
'all' => Order::whereIn('state', $state)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'lesson' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'LESSON')->whereBetween('created_at', $this->todayTime)->count(),
|
|
'activity_all' => Order::whereIn('state', $state)->where('item_type', 'ACTIVITY')->whereBetween('created_at', $this->todayTime)->count(),
|
|
'activity' => [
|
|
'buy' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'ACTIVITY')->whereBetween('created_at', $this->todayTime)->count(),
|
|
'give' => Order::whereIn('state', $state)->where('type', 'lottery')->where('item_type', 'ACTIVITY')->whereBetween('created_at', $this->todayTime)->count(),
|
|
],
|
|
'gift_all' => Order::whereIn('state', $state)->where('item_type', 'GIFT')->whereBetween('created_at', $this->todayTime)->count(),
|
|
'gift' => [
|
|
'lesson' => Order::whereIn('state', $state)->where('item_type', 'GIFT')->where('type', 'lesson')->whereBetween('created_at', $this->todayTime)->count(),
|
|
'lottery' => Order::whereIn('state', $state)->where('item_type', 'GIFT')->where('type', 'lottery')->whereBetween('created_at', $this->todayTime)->count(),
|
|
],
|
|
];
|
|
|
|
$all = [
|
|
'all' => Order::whereIn('state', $state)->count(),
|
|
'lesson' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'LESSON')->count(),
|
|
'activity_all' => Order::whereIn('state', $state)->where('item_type', 'ACTIVITY')->count(),
|
|
'activity' => [
|
|
'buy' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'ACTIVITY')->count(),
|
|
'give' => Order::whereIn('state', $state)->where('type', 'lottery')->where('item_type', 'ACTIVITY')->count(),
|
|
],
|
|
'gift_all' => Order::whereIn('state', $state)->where('item_type', 'GIFT')->count(),
|
|
'gift' => [
|
|
'lesson' => Order::whereIn('state', $state)->where('item_type', 'GIFT')->where('type', 'lesson')->count(),
|
|
'lottery' => Order::whereIn('state', $state)->where('item_type', 'GIFT')->where('type', 'lottery')->count(),
|
|
],
|
|
];
|
|
return view('data.orders', compact('today', 'all'));
|
|
}
|
|
|
|
public function withdraw()
|
|
{
|
|
|
|
$all = [
|
|
//申请提现额
|
|
'withdraw' => [
|
|
'all' => Withdraw::sum('amount'),
|
|
],
|
|
|
|
//实际转账额
|
|
'cash' => [
|
|
'all' => Withdraw::whereIn('state', [0, 1])->sum('take'),
|
|
'pass' => Withdraw::where('state', 1)->sum('take'),
|
|
'no' => Withdraw::where('state', -1)->sum('take'),
|
|
],
|
|
'user' => [
|
|
'all' => Withdraw::where('state', '>=', 0)->count('user_id'),
|
|
'pass' => Withdraw::where('state', 1)->groupBy('user_id')->count('user_id'),
|
|
'no' => Withdraw::where('state', -1)->groupBy('user_id')->count('user_id'),
|
|
],
|
|
'account' => [
|
|
'all_account' => UserAccount::sum('cash'),
|
|
'user_count' => UserAccount::count(),
|
|
],
|
|
];
|
|
|
|
$today = [
|
|
//申请提现额
|
|
'withdraw' => [
|
|
'all' => Withdraw::whereBetween('created_at', $this->todayTime)->whereIn('state', [0, 1])->sum('amount'),
|
|
'pass' => Withdraw::where('state', 1)->whereBetween('created_at', $this->todayTime)->sum('amount'),
|
|
'no' => Withdraw::where('state', -1)->whereBetween('created_at', $this->todayTime)->sum('amount'),
|
|
],
|
|
|
|
//实际转账额
|
|
'cash' => [
|
|
'all' => Withdraw::whereBetween('created_at', $this->todayTime)->whereIn('state', [0, 1])->sum('take'),
|
|
'pass' => Withdraw::where('state', 1)->whereBetween('created_at', $this->todayTime)->sum('take'),
|
|
'no' => Withdraw::where('state', -1)->whereBetween('created_at', $this->todayTime)->sum('take'),
|
|
],
|
|
'user' => [
|
|
'all' => Withdraw::whereBetween('created_at', $this->todayTime)->where('state', '>=', 0)->count('user_id'),
|
|
'pass' => Withdraw::where('state', 1)->groupBy('user_id')->whereBetween('created_at', $this->todayTime)->count('user_id'),
|
|
'no' => Withdraw::where('state', -1)->groupBy('user_id')->whereBetween('created_at', $this->todayTime)->count('user_id'),
|
|
],
|
|
'account' => [
|
|
'all_account' => UserAccount::whereBetween('created_at', $this->todayTime)->sum('cash'),
|
|
'user_count' => UserAccount::whereBetween('created_at', $this->todayTime)->count(),
|
|
],
|
|
];
|
|
|
|
return view('data.withdraw', compact('today', 'all', 'nav'));
|
|
}
|
|
|
|
public function upgrade()
|
|
{
|
|
$today = [
|
|
'counselor_all' => IdentityLog::where('after', 1)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'agency' => IdentityLog::where('after', 2)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'manage' => IdentityLog::where('after', 3)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'teacher' => IdentityLog::where('after', 4)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'counselor' => [
|
|
'auto' => IdentityLog::where('after', 1)->where('channel', 'AutoUp')->whereBetween('created_at', $this->todayTime)->count(),
|
|
'empty' => IdentityLog::where('after', 1)->where('channel', 'AdminUp')->whereBetween('created_at', $this->todayTime)->count(),
|
|
],
|
|
];
|
|
|
|
$all = [
|
|
'all' => IdentityLog::whereIn('after', [1, 2, 3, 4])->count(),
|
|
'counselor_all' => IdentityLog::where('after', 1)->count(),
|
|
'agency' => IdentityLog::where('after', 2)->count(),
|
|
'manage' => IdentityLog::where('after', 3)->count(),
|
|
'teacher' => IdentityLog::where('after', 4)->count(),
|
|
'counselor' => [
|
|
'auto' => IdentityLog::where('after', 1)->where('channel', 'AutoUp')->count(),
|
|
'empty' => IdentityLog::where('after', 1)->where('channel', 'AdminUp')->count(),
|
|
],
|
|
];
|
|
return view('data.upgrade', compact('today', 'all'));
|
|
}
|
|
|
|
public function account()
|
|
{
|
|
$all = [
|
|
'all' => Payment::where('state', 'SUCCESS')->sum('amount'),
|
|
'lesson' => Payment::whereHas('order', function ($query) {$query->where('item_type', 'LESSON')->where('type', 'order');})->where('state', 'SUCCESS')->sum('amount'),
|
|
'activity' => Payment::whereHas('order', function ($query) {$query->where('item_type', 'ACTIVITY')->where('type', 'order');})->where('state', 'SUCCESS')->sum('amount'),
|
|
];
|
|
|
|
$today = [
|
|
'all' => Payment::where('state', 'SUCCESS')->whereBetween('created_at', $this->todayTime)->sum('amount'),
|
|
'lesson' => Payment::whereHas('order', function ($query) {$query->where('item_type', 'LESSON')->where('type', 'order');})->where('state', 'SUCCESS')->whereBetween('created_at', $this->todayTime)->sum('amount'),
|
|
'activity' => Payment::whereHas('order', function ($query) {$query->where('item_type', 'ACTIVITY')->where('type', 'order');})->where('state', 'SUCCESS')->whereBetween('created_at', $this->todayTime)->sum('amount'),
|
|
];
|
|
return view('data.account', compact('all', 'today'));
|
|
}
|
|
|
|
public function index(Request $request)
|
|
{
|
|
$state = [
|
|
'PAID', 'DELIVER', 'DELIVERED', 'SIGNED', 'COMPLETED', 'UNUSE', 'USED', 'UNADDRESS',
|
|
];
|
|
|
|
$today = [
|
|
'user' => [
|
|
'reg' => User::whereBetween('created_at', $this->todayTime)->count(),
|
|
'counselor' => UserIdentity::where('identity_id', 1)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'agency' => UserIdentity::where('identity_id', 2)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'manage' => UserIdentity::where('identity_id', 3)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'teacher' => UserIdentity::where('identity_id', 4)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'salesman' => User::whereBetween('created_at', $this->todayTime)->where('is_salesman', 1)->count(),
|
|
],
|
|
'order' => [
|
|
'all' => Order::whereIn('state', $state)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'lesson' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'LESSON')->whereBetween('created_at', $this->todayTime)->count(),
|
|
'activity' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'ACTIVITY')->whereBetween('created_at', $this->todayTime)->count(),
|
|
'lesson_gift' => Order::whereIn('state', $state)->where('type', 'lesson')->where('item_type', 'GIFT')->whereBetween('created_at', $this->todayTime)->count(),
|
|
'lottery_gift' => Order::whereIn('state', $state)->where('type', 'lottery')->where('item_type', 'GIFT')->whereBetween('created_at', $this->todayTime)->count(),
|
|
],
|
|
];
|
|
|
|
$all = [
|
|
'user' => [
|
|
'reg' => User::count(),
|
|
'counselor' => UserIdentity::where('identity_id', 1)->count(),
|
|
'agency' => UserIdentity::where('identity_id', 2)->count(),
|
|
'manage' => UserIdentity::where('identity_id', 3)->count(),
|
|
'teacher' => UserIdentity::where('identity_id', 4)->count(),
|
|
'salesman' => User::where('is_salesman', 1)->count(),
|
|
],
|
|
'order' => [
|
|
'all' => Order::whereIn('state', $state)->count(),
|
|
'lesson' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'LESSON')->count(),
|
|
'activity' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'ACTIVITY')->count(),
|
|
'lesson_gift' => Order::whereIn('state', $state)->where('type', 'lesson')->where('item_type', 'GIFT')->count(),
|
|
'lottery_gift' => Order::whereIn('state', $state)->where('type', 'lottery')->where('item_type', 'GIFT')->count(),
|
|
],
|
|
];
|
|
return view('data.index', compact('today', 'all'));
|
|
}
|
|
|
|
public function salesman(Request $request)
|
|
{
|
|
$user = Auth::user();
|
|
|
|
if (!$user->is_salesman) {
|
|
return redirect()->route('user.index');
|
|
}
|
|
|
|
$today = [
|
|
'agency' => Agency::where('salesman_id', $user->id)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'organ' => Seller::where('type', 'organ')->where('salesman_id', $user->id)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'seller' => Seller::where('type', 'seller')->where('salesman_id', $user->id)->whereBetween('created_at', $this->todayTime)->count(),
|
|
'agency_organ' => Seller::whereHas('agency', function ($query) use ($user) {
|
|
$query->where('salesman_id', $user->id);
|
|
})->whereBetween('created_at', $this->todayTime)->count(),
|
|
];
|
|
|
|
$all = [
|
|
'agency' => Agency::where('salesman_id', $user->id)->count(),
|
|
'organ' => Seller::where('type', 'organ')->where('salesman_id', $user->id)->count(),
|
|
'seller' => Seller::where('type', 'seller')->where('salesman_id', $user->id)->count(),
|
|
'agency_organ' => Seller::whereHas('agency', function ($query) use ($user) {
|
|
$query->where('salesman_id', $user->id);
|
|
})->count(),
|
|
];
|
|
|
|
$organs = Seller::whereHas('agency', function ($query) use ($user) {
|
|
$query->where('salesman_id', $user->id);
|
|
})
|
|
->distinct('id')
|
|
->orWhere('salesman_id', $user->id)
|
|
->get();
|
|
|
|
return view('data.salesman', compact('today', 'all', 'organs'));
|
|
}
|
|
|
|
}
|