|
@@ -11,59 +11,17 @@ use Carbon\Carbon;
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
use Illuminate\Pagination\Paginator;
|
|
use Illuminate\Pagination\Paginator;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
|
|
|
|
|
|
|
|
|
|
|
class OrderIssuePerformanceService
|
|
class OrderIssuePerformanceService
|
|
|
{
|
|
{
|
|
|
- public function getQuery(array $queryParam)
|
|
|
|
|
- {
|
|
|
|
|
- $user_id = $queryParam['user_id'] ?? '';
|
|
|
|
|
- $owner_id = $queryParam['owner_id'] ?? '';
|
|
|
|
|
- $timeFrame = $queryParam['timeFrame'] ?? '';
|
|
|
|
|
- unset($queryParam['owner_id'], $queryParam['user_id'], $queryParam['timeFrame'],$queryParam['_token']);
|
|
|
|
|
- $user = Auth::user();
|
|
|
|
|
- $owner_ids = $user ? $user->getPermittingOwnerIdsAttribute() : [];
|
|
|
|
|
- $orderIssueProcessLog = OrderIssueProcessLog::query()->with(['user' => function ($query) use ($user_id) {
|
|
|
|
|
- if ($user_id) {
|
|
|
|
|
- $query->where('id', $user_id);
|
|
|
|
|
- }
|
|
|
|
|
- }, 'orderIssue.order.owner' => function ($query) use ($owner_id,$owner_ids) {
|
|
|
|
|
- if ($owner_id && in_array($owner_id,$owner_ids) ) {
|
|
|
|
|
- $query->where('id', $owner_id);
|
|
|
|
|
- }else{
|
|
|
|
|
- $query->whereIn('id',$owner_ids);
|
|
|
|
|
- }
|
|
|
|
|
- }]);
|
|
|
|
|
- $columnQueryRules = [
|
|
|
|
|
- 'create_start' => ['alias' => 'created_at', 'startDate' => ' 00:00:00'],
|
|
|
|
|
- 'create_end' => ['alias' => 'created_at', 'endDate' => ' 23:59:59'],
|
|
|
|
|
- ];
|
|
|
|
|
- if ($timeFrame ?? false) {
|
|
|
|
|
- if ($timeFrame == 'day') {
|
|
|
|
|
- $queryParam['create_start'] = date('Y-m-d');
|
|
|
|
|
- $queryParam['create_end'] = date('Y-m-d');
|
|
|
|
|
- } else if ($timeFrame == 'yesterday') {
|
|
|
|
|
- $queryParam['create_start'] = date('Y-m-d', strtotime('-1 day'));
|
|
|
|
|
- $queryParam['create_end'] = date('Y-m-d', strtotime('-1 day'));
|
|
|
|
|
- } else if ($timeFrame) {
|
|
|
|
|
- $date = date('Y-m-d', strtotime('-1 weeks', strtotime('Monday')));
|
|
|
|
|
- $queryParam['create_start'] = $date;
|
|
|
|
|
- $queryParam['create_end'] = date('Y-m-d');
|
|
|
|
|
- } else if ($timeFrame == 'month') {
|
|
|
|
|
- $queryParam['create_start'] = date('Y-m-1');
|
|
|
|
|
- $queryParam['create_end'] = date('Y-m-d');
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- $orderIssueProcessLog = app(QueryService::class)->query($queryParam, $orderIssueProcessLog, $columnQueryRules);
|
|
|
|
|
- return $orderIssueProcessLog;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public function paginate(array $params)
|
|
public function paginate(array $params)
|
|
|
{
|
|
{
|
|
|
$paginate = $params['paginate'] ?? 50;
|
|
$paginate = $params['paginate'] ?? 50;
|
|
|
$page = $params['page'] ?? 1;
|
|
$page = $params['page'] ?? 1;
|
|
|
- $data = $this->getAll($params);
|
|
|
|
|
|
|
+ $data = $this->queryAll($params);
|
|
|
$collection = collect($data);
|
|
$collection = collect($data);
|
|
|
$list = $collection->slice(($page - 1) * $paginate, $paginate)->all();
|
|
$list = $collection->slice(($page - 1) * $paginate, $paginate)->all();
|
|
|
$option = ['path' => Paginator::resolveCurrentPath()];
|
|
$option = ['path' => Paginator::resolveCurrentPath()];
|
|
@@ -71,36 +29,42 @@ class OrderIssuePerformanceService
|
|
|
return $paginate;
|
|
return $paginate;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function getAll($params)
|
|
|
|
|
|
|
+ public function queryAll($params)
|
|
|
{
|
|
{
|
|
|
- $query = OrderIssueProcessLog::query()->selectRaw('user_id')->groupBy('user_id')->get();
|
|
|
|
|
- $user_ids = $query->map(function($value){
|
|
|
|
|
- return $value->user_id;
|
|
|
|
|
- });
|
|
|
|
|
- $owners = Owner::query()->with('order.issue')->whereHas('order.issue')->get();
|
|
|
|
|
- $data = [];
|
|
|
|
|
- $total = 0;
|
|
|
|
|
- foreach ($user_ids as $key => $user_id) {
|
|
|
|
|
- $params['user_id'] = $user_id;
|
|
|
|
|
- $user = User::query()->find($user_id);
|
|
|
|
|
- $orderIssueProcessLog = $this->getQuery($params)->get();
|
|
|
|
|
- foreach ($owners as $owner) {
|
|
|
|
|
- $createCount = $orderIssueProcessLog->where('user_id', $user_id)->where('orderIssue.order.owner.id', $owner['id'])->where('type', '创建')->count(); //创建
|
|
|
|
|
- $endCount = $orderIssueProcessLog->where('user_id', $user_id)->where('orderIssue.order.owner.id', $owner['id'])->where('type', '结束')->count(); //结束
|
|
|
|
|
- $treatmentCount = $orderIssueProcessLog->where('user_id', $user_id)->where('orderIssue.order.owner.id', $owner['id'])->where('type', '处理')->count(); //处理
|
|
|
|
|
- $sum = $createCount + $endCount + $treatmentCount;
|
|
|
|
|
- if ($sum == 0) {continue;}
|
|
|
|
|
- $total++;
|
|
|
|
|
- $data[] = ['id'=>$total,'user' => $user['name'], 'owner' => $owner['name'], 'createCount' => $createCount, 'endCount' => $endCount, 'treatmentCount' => $treatmentCount, 'sum' => $sum];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return $data;
|
|
|
|
|
|
|
+ $sql = $this->getSql($params);
|
|
|
|
|
+ return $result = DB::select($sql);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function exportPerformance(array $params)
|
|
|
|
|
- {
|
|
|
|
|
- $performance = $this->getAll($params);
|
|
|
|
|
- $row = [['user'=>'客服','owner'=>'客户','createCount'=>'创建数','treatmentCount' =>'处理数','endCount'=>'完结数','sum'=>'总数']];
|
|
|
|
|
- return Excel::download(new Export($row,$performance),date('YmdHis', time()).'-客服绩效.xlsx');
|
|
|
|
|
|
|
+ public function getSql($params){
|
|
|
|
|
+ $sql =" select users.name as userName,owners.name as ownerName,count(case order_issue_process_logs.type WHEN '创建' THEN 1 end ) as created, count(case order_issue_process_logs.type WHEN '处理' THEN 1 end ) as processed, count(case order_issue_process_logs.type WHEN '结束' THEN 1 end ) as end,count(1) as sumNumber ";
|
|
|
|
|
+ $sql.=" from order_issue_process_logs left join users on order_issue_process_logs.user_id = users.id left join order_issues on order_issue_process_logs.order_issue_id = order_issues.id left join orders on order_issues.order_id = orders.id left join owners on orders.owner_id = owners.id ";
|
|
|
|
|
+ $sql.=" where 1=1 ";
|
|
|
|
|
+ if(isset($params['create_start'])){
|
|
|
|
|
+ $sql.= " and order_issue_process_logs.created_at >= ".$params['create_start'].' 00:00:00 ';
|
|
|
|
|
+ }
|
|
|
|
|
+ if(isset($params['create_end'])){
|
|
|
|
|
+ $sql.= " and order_issue_process_logs.created_at <= ".$params['create_end'].' 23:59:59 ';
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isset($params['timeFrame'])) {
|
|
|
|
|
+ $create_start ='';$create_end ='';
|
|
|
|
|
+ if ($params['timeFrame'] == 'day') {
|
|
|
|
|
+ $create_start = date('Y-m-d');
|
|
|
|
|
+ $create_end = date('Y-m-d');
|
|
|
|
|
+ } else if ($params['timeFrame'] == 'yesterday') {
|
|
|
|
|
+ $create_start = date('Y-m-d', strtotime('-1 day'));
|
|
|
|
|
+ $create_end = date('Y-m-d', strtotime('-1 day'));
|
|
|
|
|
+ } else if ($params['timeFrame']) {
|
|
|
|
|
+ $date = date('Y-m-d', strtotime('-1 weeks', strtotime('Monday')));
|
|
|
|
|
+ $create_start = $date;
|
|
|
|
|
+ $create_end = date('Y-m-d');
|
|
|
|
|
+ } else if ($params['timeFrame'] == 'month') {
|
|
|
|
|
+ $create_start = date('Y-m-1');
|
|
|
|
|
+ $create_end = date('Y-m-d');
|
|
|
|
|
+ }
|
|
|
|
|
+ $sql.= " and order_issue_process_logs.created_at >= '".$create_start." 00:00:00' ";
|
|
|
|
|
+ $sql.= " and order_issue_process_logs.created_at <= '".$create_end." 23:59:59' ";
|
|
|
|
|
+ }
|
|
|
|
|
+ $sql.= "group by users.name, owners.name;";
|
|
|
|
|
+ return $sql;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|