HomeService.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. <?php
  2. /**
  3. * 首页服务类
  4. * @copyright 引擎力
  5. * @author lc
  6. * @since 2021-06-23
  7. */
  8. namespace App\Http\Services;
  9. use App\Http\Models\Role;
  10. use App\Http\Models\Site;
  11. use App\Http\Models\SitesStatus;
  12. use App\Http\Models\User;
  13. use App\Http\Models\WeekTaskInfo;
  14. use Illuminate\Database\Eloquent\Builder;
  15. use Illuminate\Support\Facades\DB;
  16. class HomeService
  17. {
  18. //逾期任务列表,默认前端,设计27
  19. public function getTaskList($role = Role::TYPE_WEB)
  20. {
  21. $taskInfo = WeekTaskInfo::query();
  22. $userIds = User::query()
  23. ->where('status', 1)
  24. ->whereIn('role_id', [$role])
  25. ->pluck('id');
  26. $taskInfo->whereIn('user_type', $userIds);
  27. $taskList = $taskInfo
  28. ->where('type', 'now')
  29. ->where('status', '!=', 'ok')
  30. ->orderBy('deadline', 'asc')
  31. ->limit(7)->get() ?? [];
  32. return $taskList;
  33. }
  34. //折线任务图
  35. public function getTaskByWeek($role = Role::TYPE_WEB)
  36. {
  37. $userList = User::query()
  38. ->where('status', 1)
  39. ->where('role_id', $role)
  40. ->select('id', 'nickname')
  41. ->get();
  42. $ids = array_column($userList->toArray(), 'id');
  43. $taskList = WeekTaskInfo::query()
  44. ->whereIn('user_type', $ids)
  45. ->where('status', '!=', 'ok')
  46. ->where('deadline', '<', date('Y-m-d'))
  47. ->selectRaw("user_type,count(id) as count")
  48. ->groupBy('user_type')
  49. ->get();
  50. foreach ($userList as $item) {
  51. $item->count = 0;
  52. foreach ($taskList as $value) {
  53. if ($item->id == $value->user_type) {
  54. $item->count = $value->count;
  55. }
  56. }
  57. }
  58. $data = [
  59. 'name' => array_column($userList->toArray(), 'nickname'),
  60. 'list' => array_column($userList->toArray(), 'count'),
  61. ];
  62. return $data;
  63. }
  64. //项目总揽
  65. public function getProjectOverview()
  66. {
  67. $sitesStatusList = SitesStatus::query()
  68. ->where('status', 404)
  69. ->where('is_handle', 0)
  70. ->where('url', 'NOT LIKE', '%javascript:%')
  71. ->where('url', 'NOT LIKE', '%tel:%')
  72. ->where('url', 'NOT LIKE', '%mailto:%')
  73. ->where('url', 'NOT LIKE', '%$%')
  74. ->where('url', 'NOT LIKE', '%skype%')
  75. ->where('url', 'NOT LIKE', '%whatsapp%')
  76. ->selectRaw('count(*) as count,site_id')
  77. ->groupBy('site_id')
  78. ->orderBy('count', 'desc')
  79. ->get();
  80. $siteIds = array_column($sitesStatusList->toArray(), 'site_id');
  81. $siteList = Site::query()->with(['users'])->select('id', 'cn_title')->whereIn('id', $siteIds)->get();
  82. foreach ($siteList as $value) {
  83. $value->userId = $value->users->where('role_id', Role::TYPE_OPTIMIZATION_EDITING)->first()->id ?? '';
  84. $value->name = $value->users->where('role_id', Role::TYPE_OPTIMIZATION_EDITING)->first()->nickname ?? '';
  85. }
  86. $list = [];
  87. foreach ($siteList as $value) {
  88. $list[] = [
  89. 'id' => $value->id,
  90. 'cn_title' => $value->cn_title,
  91. 'name' => $value->name,
  92. 'user_id' => $value->userId,
  93. ];
  94. }
  95. $user = User::query()->where('status', 1)->pluck('username', 'id');
  96. $array = [];
  97. $list = $this->arrayGroupBy($list, 'user_id');
  98. foreach ($list as $key => $value) {
  99. $array[] = [
  100. 'userId' => $user[$key] ?? '',
  101. 'count' => count($value)
  102. ];
  103. }
  104. $list = [
  105. 'user' => array_column($array, 'userId'),
  106. 'count' => array_column($array, 'count'),
  107. ];
  108. $thisMonth = [date('Y-m-01 00:00:00'), date('Y-m-t 23:59:59')];
  109. $lastMonth = [date('Y-m-01 00:00:00', strtotime('first day of -1 month')),date('Y-m-t 23:59:59', strtotime('first day of -1 month'))];
  110. //这个月上线的项目总数
  111. $thisMonthOnlineSite = Site::query()->whereBetween('online_at', $thisMonth)->count() ?? 0;
  112. //上月上线的项目总数
  113. $lastMonthOnlineSite = Site::query()->whereBetween('online_at', $lastMonth)->count() ?? 0;
  114. $ratioOnlineSite = $this->compareAdd($thisMonthOnlineSite, $lastMonthOnlineSite);
  115. //这个月签单的项目总数
  116. $thisMonthOrderSite = Site::query()->whereBetween('sign_at', $thisMonth)->count() ?? 0;
  117. //上月下签的项目总数
  118. $lastMonthOrderSite = Site::query()->whereBetween('sign_at', $lastMonth)->count() ?? 0;
  119. $ratioOrderSite = $this->compareAdd($thisMonthOrderSite, $lastMonthOrderSite);
  120. //这个月达标的项目总数
  121. $thisMonthQualifiedSite = Site::query()->whereBetween('reach_at', $thisMonth)->count() ?? 0;
  122. //上月达标的项目总数
  123. $lastMonthQualifiedSite = Site::query()->whereBetween('reach_at', $lastMonth)->count() ?? 0;
  124. $ratioQualifiedSite = $this->compareAdd($thisMonthQualifiedSite, $lastMonthQualifiedSite);
  125. //这个月下单的项目总数
  126. $thisMonthAssignSite = Site::query()->whereBetween('order_at', $thisMonth)->count() ?? 0;
  127. //上月下单的项目总数
  128. $lastMonthAssignSite = Site::query()->whereBetween('order_at', $lastMonth)->count() ?? 0;
  129. $ratioAssignSite = $this->compareAdd($thisMonthAssignSite, $lastMonthAssignSite);
  130. return [$list, $thisMonthOnlineSite, $ratioOnlineSite, $thisMonthOrderSite, $ratioOrderSite, $thisMonthQualifiedSite, $ratioQualifiedSite, $thisMonthAssignSite, $ratioAssignSite];
  131. }
  132. //环比计算
  133. function compareAdd($a, $b)
  134. {
  135. $a = (int)$a;
  136. $b = (int)$b;
  137. if ($a == $b) {
  138. return "无变动";
  139. } elseif ($b == 0 && $a > 0) {
  140. return 100;
  141. } elseif ($a == 0 && $b > 0) {
  142. return -100;
  143. } elseif ($a > $b) {
  144. $c = round(($a - $b) / $b, 2);
  145. $c = $c * 100;
  146. return $c;
  147. } elseif ($a < $b) {
  148. $c = round(($a - $b) / $b, 2);
  149. $c = $c * 100;
  150. return $c;
  151. } else {
  152. return "系统错误";
  153. }
  154. }
  155. public static function getMonth($time = '', $format = 'Y-m-d')
  156. {
  157. $time = $time != '' ? $time : time();
  158. //获取当前周几
  159. $week = date('d', $time);
  160. $date = [];
  161. for ($i = 1; $i <= date('t', $time); $i++) {
  162. $date[$i] = date($format, strtotime('+' . $i - $week . ' days', $time));
  163. }
  164. return $date;
  165. }
  166. public function getProjectStatusList($role = Role::TYPE_WEB)
  167. {
  168. $userIds = User::query()->where('role_id', $role)->pluck('id')->toArray() ?? [];
  169. if ($role == Role::TYPE_WEB) {
  170. $userIds[] = 'wfp-web';
  171. } else {
  172. $userIds[] = 'wfp-design';
  173. }
  174. //逾期
  175. $task1 = WeekTaskInfo::query()
  176. ->whereIn('user_type', $userIds)
  177. ->where('status', '!=', 'ok')
  178. ->where('deadline', '<', date('Y-m-d'))
  179. ->selectRaw("day,count(id) as ids")
  180. ->groupBy('day')
  181. ->orderBy('day', 'asc')->pluck('ids', 'day')->toArray();
  182. foreach ($task1 as $key => $item) {
  183. if ($key == 0) {
  184. $task1[7] = $item;
  185. unset($task1[$key]);
  186. }
  187. }
  188. //进行中
  189. $task2 = WeekTaskInfo::query()
  190. ->whereIn('user_type', $userIds)
  191. ->where('status', '!=', 'ok')
  192. ->where('deadline', '>', date('Y-m-d'))
  193. ->selectRaw("day,count(id) as ids")
  194. ->groupBy('day')
  195. ->orderBy('day', 'asc')->pluck('ids', 'day')->toArray();
  196. foreach ($task2 as $key => $item) {
  197. if ($key == 0) {
  198. $task2[7] = $item;
  199. unset($task2[$key]);
  200. }
  201. }
  202. //完成
  203. $task3 = WeekTaskInfo::query()
  204. ->whereIn('user_type', $userIds)
  205. ->where('status', '=', 'ok')
  206. ->selectRaw("day,count(id) as ids")
  207. ->groupBy('day')
  208. ->orderBy('day', 'asc')->pluck('ids', 'day')->toArray();
  209. foreach ($task3 as $key => $item) {
  210. if ($key == 0) {
  211. $task3[7] = $item;
  212. unset($task3[$key]);
  213. }
  214. }
  215. $result = $this->setWeekData($task1);
  216. foreach ($result as $key => $value) {
  217. $result[$key] = '-' . $value;
  218. }
  219. $type = [
  220. 'left' => $result,
  221. 'series' => $this->setWeekData($task2),
  222. 'inside' => $this->setWeekData($task3),
  223. ];
  224. return $type;
  225. }
  226. public function setWeekData($task)
  227. {
  228. $num = [1, 2, 3, 4, 5, 6, 7];
  229. foreach ($num as $item) {
  230. if (!array_key_exists($item, $task)) {
  231. $task[$item] = 0;
  232. }
  233. }
  234. ksort($task);
  235. return array_merge($task);
  236. }
  237. public function getMonthBySiteList()
  238. {
  239. $whereBetween = [date("Y-m-d", strtotime("first day of -3 month")), date('Y-m-t')];
  240. $siteOrderList = $this->getMonthBySiteField($whereBetween, 'sign');
  241. $siteOnlineList = $this->getMonthBySiteField($whereBetween, 'online');
  242. $siteReachList = $this->getMonthBySiteField($whereBetween, 'reach');
  243. $monthList = [
  244. date("Ym"),
  245. date("Ym", strtotime("first day of -1 month")),
  246. date("Ym", strtotime("first day of -2 month")),
  247. date("Ym", strtotime("first day of -3 month")),
  248. ];
  249. foreach ($monthList as $item) {
  250. $this->getMonthSiteList($item, $siteOrderList, $siteOnlineList, $siteReachList);
  251. }
  252. ksort($siteOrderList);
  253. ksort($siteOnlineList);
  254. ksort($siteReachList);
  255. $months = ['product'];
  256. $orderList = ['签单'];
  257. $onlineList = ['上线'];
  258. $reachList = ['达标'];
  259. foreach ($siteOrderList as $key => $item) {
  260. $months[] = $key . '月';
  261. $orderList[] = $item;
  262. }
  263. foreach ($siteOnlineList as $key => $item) {
  264. $onlineList[] = $item;
  265. }
  266. foreach ($siteReachList as $key => $item) {
  267. $reachList[] = $item;
  268. }
  269. $data = [
  270. $months, $orderList, $onlineList, $reachList,
  271. ];
  272. return $data;
  273. }
  274. public function getMonthBySiteList2()
  275. {
  276. $whereBetween = [date("Y-m-d 00:00:00", strtotime("first day of -6 month")), date('Y-m-t 23:59:59')];
  277. $siteOrderList = $this->getMonthBySiteField($whereBetween, 'sign');
  278. $siteOnlineList = $this->getMonthBySiteField($whereBetween, 'online');
  279. $siteReachList = $this->getMonthBySiteField($whereBetween, 'reach');
  280. $siteRenewalList = $this->getMonthBySiteField($whereBetween, 'renewal');
  281. $siteExpiredList = $this->getMonthBySiteField($whereBetween, 'expired');
  282. $monthList = [
  283. date("Ym"),
  284. date("Ym", strtotime("first day of -1 month")),
  285. date("Ym", strtotime("first day of -2 month")),
  286. date("Ym", strtotime("first day of -3 month")),
  287. date("Ym", strtotime("first day of -4 month")),
  288. date("Ym", strtotime("first day of -5 month")),
  289. date("Ym", strtotime("first day of -6 month")),
  290. ];
  291. foreach ($monthList as $item) {
  292. $this->getMonthSiteList($item, $siteOrderList, $siteOnlineList, $siteReachList);
  293. foreach ($siteRenewalList as $key => $value) {
  294. if (!array_key_exists($item, $siteRenewalList)) {
  295. $siteRenewalList[$item] = 0;
  296. }
  297. }
  298. foreach ($siteExpiredList as $key => $value) {
  299. if (!array_key_exists($item, $siteExpiredList)) {
  300. $siteExpiredList[$item] = 0;
  301. }
  302. }
  303. }
  304. ksort($siteOrderList);
  305. ksort($siteOnlineList);
  306. ksort($siteRenewalList);
  307. ksort($siteReachList);
  308. ksort($siteExpiredList);
  309. $months = [];
  310. $orderList = [];
  311. $onlineList = [];
  312. $renewalList = [];
  313. $reachList = [];
  314. $expiredList = [];
  315. foreach ($siteOrderList as $key => $item) {
  316. $months[] = $key . '月';
  317. $orderList[] = $item;
  318. }
  319. foreach ($siteOnlineList as $key => $item) {
  320. $onlineList[] = $item;
  321. }
  322. foreach ($siteRenewalList as $key => $item) {
  323. $renewalList[] = $item;
  324. }
  325. foreach ($siteReachList as $key => $item) {
  326. $reachList[] = $item;
  327. }
  328. foreach ($siteExpiredList as $key => $item) {
  329. $expiredList[] = $item;
  330. }
  331. $data = [
  332. 'title' => ['签单', '上线', '达标', '到期', '续费'],
  333. 'months' => $months,
  334. 'orderList' => $orderList,
  335. 'onlineList' => $onlineList,
  336. 'reachList' => $reachList,
  337. 'expiredList' => $expiredList,
  338. 'renewalList' => $renewalList,
  339. ];
  340. return $data;
  341. }
  342. /**
  343. * 根据字段和条件筛选以日期分组查询分组
  344. * @param $whereBetween
  345. * @param $whereField
  346. * @return array
  347. */
  348. public function getMonthBySiteField($whereBetween, $whereField)
  349. {
  350. $siteOrderList = Site::query()
  351. ->whereNotNull("{$whereField}_at")
  352. ->whereBetween("{$whereField}_at", $whereBetween)
  353. ->selectRaw("DATE_FORMAT({$whereField}_at, '%Y%m') as {$whereField}_date,count(id) as ids")
  354. ->groupBy("{$whereField}_date")
  355. ->orderBy("{$whereField}_date", 'desc')
  356. ->pluck('ids', "{$whereField}_date")->toArray();
  357. return $siteOrderList;
  358. }
  359. /**
  360. * 测速
  361. * @return array|mixed
  362. */
  363. public function getSpeedMeasurement()
  364. {
  365. $siteList = Site::query()
  366. ->whereIn('status', [2, 3])
  367. ->select('id', 'old_id', 'domain', 'cn_title', 'speed_memo')
  368. ->whereNotNull('database')->get();
  369. $pcSpeedMeasurement = [];
  370. $mobileSpeedMeasurement = [];
  371. $speedMeasurementList = DB::table('app_speed_measurement_cache')->get();
  372. foreach ($speedMeasurementList as $key => $value) {
  373. $array = json_decode($value->cache, true);
  374. $oldId = str_replace('cache:app/Http/Controllers/SpeedMeasurementController/index:', '', $value->key);
  375. $pcSpeedMeasurement[$oldId] = $array['pc'];
  376. $mobileSpeedMeasurement[$oldId] = $array['mobile'];
  377. }
  378. foreach ($siteList as $item) {
  379. $item->pcSpeedMeasurement = $pcSpeedMeasurement[$item->old_id] ?? '';
  380. $item->mobileSpeedMeasurement = $mobileSpeedMeasurement[$item->old_id] ?? '';
  381. }
  382. foreach ($siteList as $key => $value) {
  383. if ($value->pcSpeedMeasurement > 79) {
  384. unset($siteList[$key]);
  385. }
  386. }
  387. $siteIds = array_column($siteList->toArray(), 'id');
  388. $userIds = User::query()->where('role_id', Role::TYPE_WEB)->where('status', 1)->pluck('id');
  389. $user = DB::table('user_has_sites')->whereIn('user_id', $userIds)->get()->toJson();
  390. $user = \GuzzleHttp\json_decode($user, true);
  391. foreach ($user as $key => $value) {
  392. if (!in_array($value['site_id'], $siteIds)) {
  393. unset($user[$key]);
  394. }
  395. }
  396. $list = $this->arrayGroupBy($user, 'user_id');
  397. $users = [];
  398. foreach ($list as $key => $value) {
  399. $users[] = [
  400. 'user_id' => $key,
  401. 'count' => count($value),
  402. ];
  403. }
  404. $nameList = User::query()->where('role_id', Role::TYPE_WEB)->pluck('nickname', 'id');
  405. foreach ($users as $key => $user) {
  406. $users[$key]['name'] = $nameList[$user['user_id']];
  407. }
  408. $array = [
  409. 'list' => array_column($users, 'name'),
  410. 'count' => array_column($users, 'count'),
  411. ];
  412. return $array;
  413. }
  414. public function arrayGroupBy($arr, $key)
  415. {
  416. $grouped = [];
  417. foreach ($arr as $value) {
  418. $grouped[$value[$key]][] = $value;
  419. }
  420. if (func_num_args() > 2) {
  421. $args = func_get_args();
  422. foreach ($grouped as $key => $value) {
  423. $parameter = array_merge($value, array_slice($args, 2, func_num_args()));
  424. $grouped[$key] = call_user_func_array('array_group_by', $parameter);
  425. }
  426. }
  427. return $grouped;
  428. }
  429. private function substrFormat($text, $length, $replace = '...', $encoding = 'UTF-8')
  430. {
  431. if ($text && mb_strlen($text, $encoding) > $length) {
  432. return mb_substr($text, 0, $length, $encoding) . $replace;
  433. }
  434. return $text;
  435. }
  436. private function getMonthSiteList(&$item, &$siteOrderList, &$siteOnlineList, &$siteReachList)
  437. {
  438. foreach ($siteOrderList as $key => $value) {
  439. if (!array_key_exists($item, $siteOrderList)) {
  440. $siteOrderList[$item] = 0;
  441. }
  442. }
  443. foreach ($siteOnlineList as $key => $value) {
  444. if (!array_key_exists($item, $siteOnlineList)) {
  445. $siteOnlineList[$item] = 0;
  446. }
  447. }
  448. foreach ($siteReachList as $key => $value) {
  449. if (!array_key_exists($item, $siteReachList)) {
  450. $siteReachList[$item] = 0;
  451. }
  452. }
  453. }
  454. public function getSiteListByProjectManagers()
  455. {
  456. $dateList = [];
  457. for ($i = 11; $i >= 0; $i--) {
  458. $whereBetween = [
  459. date("Y-m-d 00:00:00", strtotime("first day of -{$i} month")),
  460. date('Y-m-t 23:59:59', strtotime("first day of -{$i} month"))
  461. ];
  462. $list = User::query()
  463. ->select('id', 'role_id', 'nickname')
  464. ->where('status', 1)
  465. ->where('role_id', 25)->withCount(
  466. ['sites as relation' => function (Builder $query) use ($whereBetween) {
  467. $query->whereBetween('online_at', $whereBetween);
  468. }])->get()->toArray();
  469. $dateList[date("Y-m", strtotime("first day of -{$i} month"))] = $list;
  470. }
  471. return $this->getResult($dateList);
  472. }
  473. public function getSiteListByOptimizeEditing()
  474. {
  475. $dateList = [];
  476. for ($i = 11; $i >= 0; $i--) {
  477. $whereBetween = [
  478. date("Y-m-d 00:00:00", strtotime("first day of -{$i} month")),
  479. date('Y-m-t 23:59:59', strtotime("first day of -{$i} month"))
  480. ];
  481. $list = User::query()
  482. ->select('id', 'role_id', 'nickname')
  483. ->where('status', 1)
  484. ->where('role_id', 32)->withCount(
  485. ['sites as relation' => function (Builder $query) use ($whereBetween) {
  486. $query->whereBetween('reach_at', $whereBetween);
  487. }])->get()->toArray();
  488. $dateList[date("Y-m", strtotime("first day of -{$i} month"))] = $list;
  489. }
  490. return $this->getResult($dateList);
  491. }
  492. public function getSiteListByProjectHousekeeper()
  493. {
  494. $dateList = [];
  495. for ($i = 11; $i >= 0; $i--) {
  496. $whereBetween = [
  497. date("Y-m-d 00:00:00", strtotime("first day of -{$i} month")),
  498. date('Y-m-t 23:59:59', strtotime("first day of -{$i} month"))
  499. ];
  500. $list = User::query()
  501. ->select('id', 'role_id', 'nickname')
  502. ->where('status', 1)
  503. ->where('role_id', 7)->withCount(
  504. ['sites as relation' => function (Builder $query) use ($whereBetween) {
  505. $query->whereBetween('renewal_at', $whereBetween);
  506. }])->get()->toArray();
  507. $dateList[date("Y-m", strtotime("first day of -{$i} month"))] = $list;
  508. }
  509. return $this->getResult($dateList);
  510. }
  511. public function getSiteRenewListByProjectHousekeeper()
  512. {
  513. $dateList = [];
  514. for ($i = 11; $i >= 0; $i--) {
  515. $whereBetween = [
  516. date("Y-m-d 00:00:00", strtotime("first day of -{$i} month")),
  517. date('Y-m-t 23:59:59', strtotime("first day of -{$i} month"))
  518. ];
  519. $list = User::query()
  520. ->select('id', 'role_id', 'nickname')
  521. ->where('status', 1)
  522. ->where('role_id', 7)->withCount(
  523. ['sites as relation' => function (Builder $query) use ($whereBetween) {
  524. $query->whereBetween('renewal_at', $whereBetween);
  525. $query->select(DB::raw("sum(renewal_amount) as relation"));
  526. }])->get()->toArray();
  527. $dateList[date("Y-m", strtotime("first day of -{$i} month"))] = $list;
  528. }
  529. return $this->getResult($dateList);
  530. }
  531. public function getResult($dateList)
  532. {
  533. $title = [];
  534. $nameList = [];
  535. $result = [];
  536. foreach ($dateList as $key => $value) {
  537. $title[] = $key;
  538. $nameList = array_column($value, 'nickname');
  539. }
  540. array_push($nameList, '总数');
  541. $user = [];
  542. foreach ($nameList as $key => $value) {
  543. if ($value == '总数') {
  544. $user[$value] = true;
  545. } else {
  546. $user[$value] = false;
  547. }
  548. }
  549. foreach ($dateList as $key => $value) {
  550. foreach ($value as $kk => $vv) {
  551. foreach ($nameList as $kkk => $vvv) {
  552. if ($vvv == $vv['nickname']) {
  553. $result[$vvv][] = $vv['relation'] ?? 0;
  554. }
  555. }
  556. }
  557. }
  558. $list = [];
  559. for ($i = 0; $i < count($title); $i++) {
  560. $num = 0;
  561. foreach ($result as $key => $value) {
  562. $num += $value[$i];
  563. }
  564. $list[] = $num;
  565. }
  566. $result['总数'] = $list;
  567. $data = [
  568. 'title' => $title,
  569. 'name' => $nameList,
  570. 'list' => $result,
  571. 'user' => $user,
  572. ];
  573. $userList = [];
  574. foreach ($data['name'] as $value) {
  575. foreach ($data['list'] as $key => $vv) {
  576. if ($value == $key) {
  577. $userList[] = array_sum($vv);
  578. }
  579. }
  580. }
  581. $data['sum'] = $userList;
  582. return $data;
  583. }
  584. }