内勤仪表盘
This commit is contained in:
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
namespace app\admin\controller\dashboard;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use support\Db;
|
||||
use support\Request;
|
||||
|
||||
class OfficeClerkController extends BaseController
|
||||
{
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{}
|
||||
|
||||
// 卡片
|
||||
public function card(Request $request)
|
||||
{
|
||||
$approved = Db::table('approval_records')
|
||||
->where('approver_id', $request->user->uid)
|
||||
->where('status', 'approved')
|
||||
->count('id');
|
||||
|
||||
$pending = Db::table('approval_records')
|
||||
->where('approver_id', $request->user->uid)
|
||||
->where('status', 'pending')
|
||||
->count('id');
|
||||
|
||||
$unclaimed = Db::table('fin_payment_apply')
|
||||
->where('doc_user_id', $request->user->uid)
|
||||
->where('receipt_id', 0)
|
||||
->count('id');
|
||||
|
||||
$claimed = Db::table('fin_payment_apply')
|
||||
->where('doc_user_id', $request->user->uid)
|
||||
->where('receipt_id', '>', 0)
|
||||
->count('id');
|
||||
|
||||
$twentyFourHoursAgo = time() - (24 * 3600);
|
||||
$timeout = Db::table('fin_payment_apply')
|
||||
->where('doc_user_id', $request->user->uid)
|
||||
->whereNotNull('submit_files')
|
||||
->whereJsonLength('submit_files', '>', 0)
|
||||
->where('receipt_id', '>', 0)
|
||||
->where('claimed_at', '<', $twentyFourHoursAgo)
|
||||
->count('id');
|
||||
|
||||
return $this->success([
|
||||
'approved' => $approved,
|
||||
'pending' => $pending,
|
||||
'unclaimed' => $unclaimed,
|
||||
'claimed' => $claimed,
|
||||
'timeout' => $timeout
|
||||
]);
|
||||
}
|
||||
|
||||
// 曲线
|
||||
public function curve()
|
||||
{
|
||||
$groupIds = Db::table('user_group')
|
||||
->where('scenario_code', 'stock_orders')
|
||||
->pluck('id');
|
||||
$userIds = Db::table('user_group_members')
|
||||
->whereIn('group_id', $groupIds)
|
||||
->pluck('user_id');
|
||||
$list = Db::table('stock_orders')
|
||||
->join('user', 'stock_orders.salesperson_id', '=', 'user.id')
|
||||
->whereIn('stock_orders.salesperson_id', $userIds)
|
||||
->whereIn('stock_orders.approval_status', [0, 1, 2])
|
||||
->whereNull('stock_orders.deleted_at')
|
||||
->groupBy('stock_orders.salesperson_id', 'user.name')
|
||||
->selectRaw('user.name, count(*) as count')
|
||||
->pluck('count', 'name')
|
||||
->toArray();
|
||||
$optionType = [];
|
||||
$counts = [];
|
||||
foreach ($list as $key=>$val) {
|
||||
$optionType[] = $key;
|
||||
$counts[] = $val;
|
||||
}
|
||||
$arr = [
|
||||
"optionType" => $optionType,
|
||||
"counts" => $counts
|
||||
];
|
||||
return $this->success($arr);
|
||||
}
|
||||
|
||||
// 审批
|
||||
public function approval(Request $request)
|
||||
{
|
||||
$list = Db::table('approval_records as ar')
|
||||
->join('approval_instances as ai', 'ar.instance_id', '=', 'ai.id')
|
||||
->join('stock_orders as so', 'ai.biz_id', '=', 'so.id')
|
||||
->where('ar.approver_id', $request->user->uid)
|
||||
->where('ar.status', 'pending')
|
||||
->where('ai.flow_type', 'stock_orders')
|
||||
->where('ai.biz_type', 'stock_orders')
|
||||
->where('ai.status', 'processing')
|
||||
->whereNull('so.deleted_at')
|
||||
->select(
|
||||
'so.order_no',
|
||||
'ai.created_at as approval_created_at',
|
||||
'so.salesperson_snapshot as salesperson_name'
|
||||
)
|
||||
->get()
|
||||
->map(function($item) {
|
||||
return [
|
||||
'order_no' => $item->order_no,
|
||||
'approval_created_at' => date('Y-m-d H:i:s', strtotime($item->approval_created_at)), // 格式化时间
|
||||
'salesperson_name' => $item->salesperson_name
|
||||
];
|
||||
})
|
||||
->toArray();
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
// 认领
|
||||
public function claim(Request $request)
|
||||
{
|
||||
$type = $request->get('type');
|
||||
if ($type == 'unclaimed') {
|
||||
$list = Db::table('fin_payment_apply')
|
||||
->where('doc_user_id', $request->user->uid)
|
||||
->where('receipt_id', 0)
|
||||
->select(
|
||||
'apply_no',
|
||||
'amount',
|
||||
'created_at'
|
||||
)
|
||||
->get()
|
||||
->map(function($item) {
|
||||
return [
|
||||
'apply_no' => $item->apply_no,
|
||||
'amount' => $item->amount,
|
||||
'created_at' => date('Y-m-d H:i:s', $item->created_at)
|
||||
];
|
||||
})
|
||||
->toArray();
|
||||
} else {
|
||||
$twentyFourHoursAgo = time() - (24 * 3600);
|
||||
$list = Db::table('fin_payment_apply')
|
||||
->where('doc_user_id', $request->user->uid)
|
||||
->whereNotNull('submit_files')
|
||||
->whereJsonLength('submit_files', '>', 0)
|
||||
->where('receipt_id', '>', 0)
|
||||
->where('claimed_at', '<', $twentyFourHoursAgo)
|
||||
->select(
|
||||
'apply_no',
|
||||
'amount',
|
||||
'created_at'
|
||||
)
|
||||
->get()
|
||||
->map(function($item) {
|
||||
return [
|
||||
'apply_no' => $item->apply_no,
|
||||
'amount' => $item->amount,
|
||||
'created_at' => date('Y-m-d H:i:s', $item->created_at)
|
||||
];
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
return $this->success($list);
|
||||
}
|
||||
}
|
||||
@@ -422,6 +422,17 @@ Route::group('/admin', function () {
|
||||
Route::any('/update', [app\common\controller\SysUpdateLogController::class, 'update']);
|
||||
Route::any('/destroy', [app\common\controller\SysUpdateLogController::class, 'destroy']);
|
||||
});
|
||||
|
||||
// 仪表盘
|
||||
Route::group('/dashboard', function () {
|
||||
// 内勤
|
||||
Route::group('/officeclerk', function () {
|
||||
Route::any('/card', [app\admin\controller\dashboard\OfficeClerkController::class, 'card']);
|
||||
Route::any('/curve', [app\admin\controller\dashboard\OfficeClerkController::class, 'curve']);
|
||||
Route::any('/approval', [app\admin\controller\dashboard\OfficeClerkController::class, 'approval']);
|
||||
Route::any('/claim', [app\admin\controller\dashboard\OfficeClerkController::class, 'claim']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user