BIService.php 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. <?php
  2. namespace App\Service;
  3. use App\Model\DailyDwOrder;
  4. use App\Model\DailyDwOrderDetails;
  5. use App\Model\DailyPwOrder;
  6. use App\Model\DailyPwOrderDetails;
  7. use App\Model\Employee;
  8. use App\Model\ExpenseClaims;
  9. use App\Model\ExpenseClaimsDetails;
  10. use App\Model\Fee;
  11. use App\Model\Item;
  12. use App\Model\ItemNode;
  13. use App\Model\ItemNodeMission;
  14. use App\Model\ItemNodeMissionContent;
  15. use App\Model\MonthlyDdOrder;
  16. use App\Model\MonthlyDdOrderDetails;
  17. use App\Model\MonthlyPsOrder;
  18. use App\Model\MonthlyPsOrderDetails;
  19. use App\Model\PLeaveOverOrder;
  20. use App\Model\PLeaveOverOrderDetails;
  21. use App\Model\WorkFlowInstances;
  22. use App\Model\WorkFlowInstancesNodes;
  23. use Carbon\Carbon;
  24. use Illuminate\Support\Facades\DB;
  25. class BIService extends Service
  26. {
  27. private function commonRule($data)
  28. {
  29. if (isset($data['time']) && !empty($data['time'])) {
  30. $start = $this->changeDateToDate($data['time'][0]);
  31. $end = $this->changeDateToDate($data['time'][1], true);
  32. $data['month_start'] = date("Y-m-d", $start);
  33. $data['month_end'] = date("Y-m-d", $end);
  34. }
  35. if (!isset($data['month_start'])) $month_start = date('Y-01-01', strtotime('-1 year'));
  36. else $month_start = date('Y-m-01', strtotime($data['month_start']));
  37. if (!isset($data['month_end'])) $month_end = date('Y-01-01', strtotime('+1 year', strtotime($month_start)));
  38. else {
  39. $start_year = date('Y', strtotime($month_start));
  40. $end_year = date('Y', strtotime($data['month_end']));
  41. if ($start_year != $end_year) return [false, "查询不得跨年!", ""];
  42. $month_end = date('Y-m-01', strtotime($data['month_end'] . ' +1 month'));
  43. }
  44. return [true, strtotime($month_start), strtotime($month_end)];
  45. }
  46. public function homePageData($data, $user)
  47. {
  48. // mark 存在需求冲突 如果补录的项目 比如 2015年 那么一开始展示的年份就是2015 和2026年6月10号需求冲突
  49. // 先注释原逻辑 换新
  50. // $model = Item::TopClear($user,$data);
  51. // $start_time = $model->where('del_time',0)
  52. // ->orderby('id', 'desc')->value("start_time");
  53. if(isset($data['year'])){
  54. $start_time = strtotime($data['year']. '-01-01');
  55. }else{
  56. $start_time = time();
  57. }
  58. $year = date('Y-01-01', $start_time);
  59. $data['month_start'] = $year;
  60. list($status, $month_start, $month_end) = $this->commonRule($data);
  61. if (!$status) return [false, $month_start];
  62. //当年项目总数
  63. $model = Item::TopClear($user,$data);
  64. $intersectCount = $model->where('start_time', '<=', $month_end) // 项目开始时间 <= 区间结束时间
  65. ->where('end_time', '>=', $month_start) // 项目结束时间 >= 区间开始时间
  66. ->count();
  67. //人员费用
  68. list($total_man, $salary_map) = $this->getEmployeeSalary($month_start, $month_end, $data, $user);
  69. //折旧费用
  70. list($total_zj, $zj_map) = $this->getDeviceSalary($month_start, $month_end, $data, $user);
  71. //费用报销
  72. list($total_other, $other_map, $return_fee) = $this->getFeeItemSalary($month_start, $month_end, $data, $user);
  73. //研发费用总额
  74. $total = bcadd(bcadd($total_man, $total_zj,3), $total_other,3);
  75. //研发费用结构
  76. $rd = [
  77. 0 => [
  78. 'title' => '人工费用',
  79. 'rate' => $total == 0 ? 0 : bcmul(bcdiv($total_man,$total,4),100,2),
  80. 'rate_unit' => '%',
  81. 'total' => $total_man,
  82. 'total_unit' => '¥',
  83. ],
  84. 1 => [
  85. 'title' => '折旧费用',
  86. 'rate' => $total == 0 ? 0 :bcmul(bcdiv($total_zj,$total,4),100,2),
  87. 'rate_unit' => '%',
  88. 'total' => $total_zj,
  89. 'total_unit' => '¥',
  90. ],
  91. 2 => [
  92. 'title' => '费用报销',
  93. 'rate' => $total == 0 ? 0 :bcmul(bcdiv($total_other,$total,4),100,2),
  94. 'rate_unit' => '%',
  95. 'total' => $total_other,
  96. 'total_unit' => '¥',
  97. ],
  98. ];
  99. //研发费用趋势
  100. $rd_trend = $this->makeTrend($month_start, $salary_map, $zj_map, $other_map);
  101. //研发费用报销占比
  102. $rd_rate = $return_fee;
  103. //加班 请假 总时长
  104. list($over_time, $leave_time) = $this->overLeave($month_start, $month_end, $data, $user);
  105. // 项目人员工时汇总
  106. $man_work = $this->manWork($month_start, $month_end, $data, $user);
  107. //加计扣除金额
  108. $statisticService = new StatisticService();
  109. $attendance = $statisticService->employeeAttendanceMonthStatistic(["year"=>$year, "s" => "/api/employeeAttendanceMonthStatistic"],$user);
  110. $discount = 0;
  111. foreach ($attendance[1]['list'] as $v){
  112. $discount += $v['jj_total_amount']*100;
  113. }
  114. return [true, [
  115. 'rd_total' => $total,
  116. 'rd_unit' => '¥',
  117. 'rd_title' => '研发费用总额', //-----
  118. 'discount_total' => round($discount/100,2),
  119. 'discount_unit' => '¥',
  120. 'discount_title' => '加计扣除金额', //------
  121. 'over_time' => $over_time, // 加班
  122. 'leave_time' => $leave_time, // 请假
  123. 'rd' => $rd, //研发费用结构
  124. 'rd_trend' => $rd_trend, //研发费用趋势
  125. 'rd_rate' => $rd_rate, // 研发费用报销占比
  126. 'man_work' => $man_work, //项目人员工时汇总
  127. 'year' => date('Y',strtotime($year)),
  128. 'item_num' => $intersectCount,
  129. 'start_year' => date('Y',time())
  130. ]];
  131. }
  132. private function getEmployeeSalary($month_start, $month_end, $data, $user)
  133. {
  134. $monthly_ps_order = MonthlyPsOrder::Clear($user, $data)
  135. ->where('del_time', 0)
  136. ->where("month", ">=", $month_start)
  137. ->where("month", "<", $month_end)
  138. ->pluck('month','id')
  139. ->toArray();
  140. $monthly_ps_order_ids = array_keys($monthly_ps_order);
  141. $month_employee_salary = MonthlyPsOrderDetails::whereIn('main_id', $monthly_ps_order_ids)
  142. ->select("base_salary","performance_salary","other","bonus", "main_id")
  143. ->get()
  144. ->toArray();
  145. $total = 0;
  146. $salary_map = [];
  147. foreach ($month_employee_salary as $value) {
  148. $currentAmount = bcadd($value['base_salary'], $value['performance_salary'],3);
  149. $currentAmount = bcadd($currentAmount, $value['other'],3);
  150. $currentAmount = bcadd($currentAmount, $value['bonus'],3);
  151. if(isset($monthly_ps_order[$value['main_id']])){
  152. $month = $monthly_ps_order[$value['main_id']];
  153. if(isset($salary_map[$month])){
  154. $salary_map[$month] = bcadd($salary_map[$month], $currentAmount,3);
  155. }else{
  156. $salary_map[$month] = $currentAmount;
  157. }
  158. }
  159. $total = bcadd($total, $currentAmount,3);
  160. }
  161. return [$total, $salary_map];
  162. }
  163. private function getDeviceSalary($month_start, $month_end, $data, $user)
  164. {
  165. $monthly_dd_order= MonthlyDdOrder::Clear($user, $data)
  166. ->where('del_time', 0)
  167. ->where("month", ">=", $month_start)
  168. ->where("month", "<", $month_end)
  169. ->pluck('month','id')
  170. ->toArray();
  171. $monthly_dd_order_ids = array_keys($monthly_dd_order);
  172. $month_device_salary = MonthlyDdOrderDetails::whereIn('main_id', $monthly_dd_order_ids)
  173. ->select("depreciation_amount as amount", "main_id")
  174. ->get()
  175. ->toArray();
  176. $total = 0;
  177. $amount_map = [];
  178. foreach ($month_device_salary as $value) {
  179. $currentAmount = (string)$value['amount'];
  180. if(isset($monthly_dd_order[$value['main_id']])){
  181. $month = $monthly_dd_order[$value['main_id']];
  182. if(isset($amount_map[$month])){
  183. $amount_map[$month] = bcadd($amount_map[$month], $currentAmount,3);
  184. }else{
  185. $amount_map[$month] = $currentAmount;
  186. }
  187. }
  188. $total = bcadd($total, $currentAmount,3);
  189. }
  190. return [$total, $amount_map];
  191. }
  192. private function getFeeItemSalary($month_start, $month_end, $data, $user)
  193. {
  194. $e_order = ExpenseClaims::Clear($user, $data)
  195. ->where('del_time', 0)
  196. ->where("month", ">=", $month_start)
  197. ->where("month", "<", $month_end)
  198. ->pluck('month','id')
  199. ->toArray();
  200. $e_order_ids = array_keys($e_order);
  201. $e_order_detail = ExpenseClaimsDetails::whereIn('expense_claims_id', $e_order_ids)
  202. ->select("amount", "expense_claims_id as main_id", "fee_id")
  203. ->get()
  204. ->toArray();
  205. $fee = Fee::TopClear($user, $data);
  206. $fee_map = $fee->whereIn('id', array_unique(array_column($e_order_detail,'fee_id')))->pluck('title','id')->toArray();
  207. $total = 0;
  208. $amount_map = [];
  209. $fee_amount_map = [];
  210. foreach ($e_order_detail as $value) {
  211. $currentAmount = (string)$value['amount'];
  212. if(isset($e_order[$value['main_id']])){
  213. $month = $e_order[$value['main_id']];
  214. if(isset($amount_map[$month])){
  215. $amount_map[$month] = bcadd($amount_map[$month], $currentAmount,3);
  216. }else{
  217. $amount_map[$month] = $currentAmount;
  218. }
  219. }
  220. $fee_tmp = $fee_map[$value['fee_id']] ?? "";
  221. if(! empty($fee_tmp)){
  222. if(isset($fee_amount_map[$fee_tmp])){
  223. $fee_amount_map[$fee_tmp] = bcadd($fee_amount_map[$fee_tmp], $currentAmount,3);
  224. }else{
  225. $fee_amount_map[$fee_tmp] = $currentAmount;
  226. }
  227. }
  228. $total = bcadd($total, $currentAmount,3);
  229. }
  230. $return_fee = [];
  231. foreach ($fee_amount_map as $key => $value){
  232. $amount = (string)$value;
  233. $return_fee[] = [
  234. "title" => $key,
  235. "total" => $amount,
  236. "total_unit" => "元",
  237. "rate" => bcmul(bcdiv($amount,$total,4),100,2),
  238. "rate_unit" => "%"
  239. ];
  240. }unset($fee_amount_map);
  241. return [$total, $amount_map, $return_fee];
  242. }
  243. private function makeTrend($month_start, $salary_map, $zj_map, $other_map)
  244. {
  245. $trend = [];
  246. for ($i = 0; $i < 12; $i++) {
  247. // 计算每个月第一天的时间戳作为 Key
  248. $timestamp = strtotime("+$i month", $month_start);
  249. $monthName = ($i + 1) . '月';
  250. $trend[$timestamp] = [
  251. 'month' => $monthName,
  252. // 'salary' => "0.000",
  253. // 'zj' => "0.000",
  254. // 'other' => "0.000",
  255. 'total' => "0.000",
  256. ];
  257. }
  258. // 2. 将传入的 Map 数据填充进去
  259. foreach ($trend as $timestamp => &$item) {
  260. // 使用 ?? "0" 容错,并强制转为 string 保证 bcadd 精度
  261. $s = $salary_map[$timestamp] ?? "0";
  262. $z = $zj_map[$timestamp] ?? "0";
  263. $o = $other_map[$timestamp] ?? "0";
  264. // $item['salary'] = bcadd($s, "0", 3);
  265. // $item['zj'] = bcadd($z, "0", 3);
  266. // $item['other'] = bcadd($o, "0", 3);
  267. // 计算该月总计
  268. $item['total'] = bcadd(bcadd($s, $z, 3), $o, 3);
  269. }
  270. return array_values($trend);
  271. }
  272. private function overLeave($month_start, $month_end, $data, $user)
  273. {
  274. $id = PLeaveOverOrder::Clear($user, $data)
  275. ->where('del_time', 0)
  276. ->where("order_time", ">=", $month_start)
  277. ->where("order_time", "<", $month_end)
  278. ->pluck('id')
  279. ->toArray();
  280. $p = PLeaveOverOrderDetails::whereIn('main_id', $id)
  281. ->select("type", "total_min")
  282. ->get()
  283. ->toArray();
  284. $total = $total_1 = 0;
  285. foreach ($p as $value) {
  286. $total_min = (string)$value['total_min'];
  287. if($value['type'] == PLeaveOverOrderDetails::TYPE_ONE){
  288. $total = bcadd($total, $total_min,2);
  289. }else{
  290. $total_1 = bcadd($total_1, $total_min,2);
  291. }
  292. }
  293. // 最终返回或输出前转换
  294. $total_hours = bcdiv($total, 60, 2);
  295. $total_1_hours = bcdiv($total_1, 60, 2);
  296. return [$total_1_hours, $total_hours];
  297. }
  298. private function manWork($month_start, $month_end, $data, $user)
  299. {
  300. $daily_pw = DailyPwOrder::Clear($user, $data)
  301. ->where('del_time', 0)
  302. ->where("order_time", ">=", $month_start)
  303. ->where("order_time", "<", $month_end)
  304. ->select('id','item_id')
  305. ->get()->toArray();
  306. $item_map = Item::whereIn('id',array_unique(array_column($daily_pw,'item_id')))
  307. ->pluck('title','id')
  308. ->toArray();
  309. $p = DailyPwOrderDetails::whereIn('main_id', array_column($daily_pw,'id'))
  310. ->select("item_id", "total_work_min")
  311. ->get()
  312. ->toArray();
  313. $total = 0;
  314. $map = [];
  315. foreach ($p as $value) {
  316. $total_min = (string)$value['total_work_min'];
  317. if(isset($map[$value['item_id']])){
  318. $map[$value['item_id']] = bcadd($map[$value['item_id']], $total_min,2);
  319. }else{
  320. $map[$value['item_id']] = $total_min;
  321. }
  322. $total = bcadd($total, $total_min,2);
  323. }
  324. $return = [];
  325. foreach ($map as $key => $value){
  326. $rate = bcmul(bcdiv($value, $total,4),100,2);
  327. $total_hours = bcdiv($value, 60, 2);
  328. $return[] = [
  329. 'title' => $item_map[$key] ?? "",
  330. 'total_work_hour' => $total_hours,
  331. 'total_work_hour_unit' => "小时",
  332. "rate" => $rate,
  333. "rate_unit" => "%",
  334. ];
  335. }
  336. return $return;
  337. }
  338. public function cockpit($data, $user)
  339. {
  340. // 1. 声明时区对象
  341. $utcZone = new \DateTimeZone('UTC');
  342. $localZone = new \DateTimeZone('Asia/Shanghai'); // 你的数据库/服务器本地时区(北京时间)
  343. if (!empty($data['time'][0]) && !empty($data['time'][1])) {
  344. // 【A. 满足 employeeSalarySummary 的 UTC 干净时间】
  345. // 提取前端 ISO 串中的纯日期,强制转为 UTC 视角的开始和结束
  346. $rawStartUtc = new \DateTime($data['time'][0], $utcZone);
  347. $rawEndUtc = new \DateTime($data['time'][1], $utcZone);
  348. $startDateTimeUtc = new \DateTime($rawStartUtc->format('Y-m-d') . ' 00:00:00', $utcZone);
  349. $endDateTimeUtc = new \DateTime($rawEndUtc->format('Y-m-d') . ' 23:59:59', $utcZone);
  350. // 【B. 满足 getManWork 的本地 00点和23点 时间戳】
  351. $startTimestampLocal = (new \DateTime($rawStartUtc->format('Y-m-d') . ' 00:00:00', $localZone))->getTimestamp();
  352. $endTimestampLocal = (new \DateTime($rawEndUtc->format('Y-m-d') . ' 23:59:59', $localZone))->getTimestamp();
  353. } else {
  354. // 【没传参时的默认兜底逻辑】
  355. // UTC 视角的当月起止
  356. $startDateTimeUtc = new \DateTime('first day of this month 00:00:00', $utcZone);
  357. $endDateTimeUtc = new \DateTime('last day of this month 23:59:59', $utcZone);
  358. // 本地视角的当月起止时间戳
  359. $startTimestampLocal = (new \DateTime('first day of this month 00:00:00', $localZone))->getTimestamp();
  360. $endTimestampLocal = (new \DateTime('last day of this month 23:59:59', $localZone))->getTimestamp();
  361. }
  362. $data['start_time'] = $startTimestampLocal;
  363. $data['end_time'] = $endTimestampLocal;
  364. $array = $this->getManWork($data, $user);
  365. // 当月设备工时信息
  366. $array2 = $this->getDeviceWork($data, $user);
  367. $array = array_merge_recursive($array, $array2);
  368. $array3 = $this->getDeviceOldWork($data, $user);
  369. $array = array_merge_recursive($array, $array3);
  370. $array3 = $this->getFeeOrder($data, $user);
  371. $array = array_merge_recursive($array, $array3);
  372. $passTime = [
  373. $startDateTimeUtc->format('Y-m-d'),
  374. $endDateTimeUtc->format('Y-m-d')
  375. ];
  376. list($status, $return) = (new StatisticService())->employeeSalarySummary(['time' => $passTime], $user);
  377. if(! $status) return [false, $return];
  378. $total = array_sum(array_column($return,'money'));
  379. $array['rd_total_money'] = $total;
  380. return [true, $array];
  381. }
  382. private function getManWork($data, $user){
  383. $model = DailyPwOrder::Clear($user, $data);
  384. $id = $model->where('del_time', 0)
  385. ->where('order_time', '>=', $data['start_time'])
  386. ->where('order_time', '<=', $data['end_time'])
  387. ->pluck('id')
  388. ->toArray();
  389. $details = DailyPwOrderDetails::where('del_time', 0)
  390. ->whereIn('main_id', $id) // 💡 避坑提示:原代码如果是数组 $id,这里建议用 whereIn
  391. ->select('employee_id', 'total_work_min')
  392. ->get()->toArray();
  393. // 1. 计算当月总工时(将二维数组中所有 'total_work_min' 字段求和)
  394. $totalWorkMin = array_sum(array_column($details, 'total_work_min'));
  395. // 2. 如果你需要把分钟数转换为“小时”,可以除以 60(保留两位小数,根据业务需要决定是否转换)
  396. $totalWorkHours = round($totalWorkMin / 60, 2);
  397. // 3. 计算参与人员总数(先提取所有员工ID,再通过 array_unique 去重,最后 count 计算数量)
  398. $employeeIds = array_column($details, 'employee_id');
  399. $uniqueEmployeeIds = array_unique($employeeIds);
  400. $totalEmployees = count($uniqueEmployeeIds);
  401. return [
  402. 'man_total_work_hours' => $totalWorkHours, // 当月总工时
  403. 'man_total_employees' => $totalEmployees, // 参与人员总数
  404. ];
  405. }
  406. private function getDeviceWork($data, $user){
  407. $model = DailyDwOrder::Clear($user, $data);
  408. $id = $model->where('del_time', 0)
  409. ->where('order_time', '>=', $data['start_time'])
  410. ->where('order_time', '<=', $data['end_time'])
  411. ->pluck('id')
  412. ->toArray();
  413. $details = DailyDwOrderDetails::where('del_time', 0)
  414. ->whereIn('main_id', $id) // 💡 避坑提示:原代码如果是数组 $id,这里建议用 whereIn
  415. ->select('device_id', 'total_work_min')
  416. ->get()->toArray();
  417. // 1. 计算当月总工时(将二维数组中所有 'total_work_min' 字段求和)
  418. $totalWorkMin = array_sum(array_column($details, 'total_work_min'));
  419. // 2. 如果你需要把分钟数转换为“小时”,可以除以 60(保留两位小数,根据业务需要决定是否转换)
  420. $totalWorkHours = round($totalWorkMin / 60, 2);
  421. $employeeIds = array_column($details, 'device_id');
  422. $uniqueEmployeeIds = array_unique($employeeIds);
  423. $totalEmployees = count($uniqueEmployeeIds);
  424. return [
  425. 'device_total_work_hours' => $totalWorkHours, // 当月总工时
  426. 'device_total_num' => $totalEmployees, // 参与人员总数
  427. ];
  428. }
  429. private function getDeviceOldWork($data, $user){
  430. $model = MonthlyDdOrder::Clear($user, $data);
  431. $id = $model->where('del_time', 0)
  432. ->where('month', '>=', $data['start_time'])
  433. ->where('month', '<=', $data['end_time'])
  434. ->pluck('id')
  435. ->toArray();
  436. $details = MonthlyDdOrderDetails::where('del_time', 0)
  437. ->whereIn('main_id', $id)
  438. ->select('device_id', 'depreciation_amount')
  439. ->get()->toArray();
  440. $totalWorkMin = array_sum(array_column($details, 'depreciation_amount'));
  441. return [
  442. 'device_total_money' => $totalWorkMin,
  443. ];
  444. }
  445. private function getFeeOrder($data, $user){
  446. $model = ExpenseClaims::Clear($user, $data);
  447. $id = $model->where('del_time', 0)
  448. ->where('month', '>=', $data['start_time'])
  449. ->where('month', '<=', $data['end_time'])
  450. ->pluck('id')
  451. ->toArray();
  452. $details = ExpenseClaimsDetails::where('del_time', 0)
  453. ->whereIn('expense_claims_id', $id)
  454. ->select('item_id', 'amount')
  455. ->get()->toArray();
  456. $totalWorkMin = array_sum(array_column($details, 'amount'));
  457. $employeeIds = array_column($details, 'item_id');
  458. $uniqueEmployeeIds = array_unique($employeeIds);
  459. $totalEmployees = count($uniqueEmployeeIds);
  460. return [
  461. 'fee_total_money' => $totalWorkMin,
  462. 'fee_total_num' => $totalEmployees,
  463. ];
  464. }
  465. public function homePageItemData($data, $user){
  466. $startOfMonth = Carbon::now()->startOfMonth()->timestamp;
  467. $endOfMonth = Carbon::now()->endOfMonth()->timestamp;
  468. $data['start_now_month'] = $startOfMonth;
  469. $data['end_now_month'] = $endOfMonth;
  470. // 进行中项目数量
  471. $item_count = $this->ItemAboutSearch($data, $user);
  472. // 进行中节点数量
  473. $item_node_count = $this->ItemNodeAboutSearch($data, $user);
  474. // 待审批数量(任务)
  475. $item_node_mission_wait_count = $this->ItemNodeMissionWaitAboutSearch($data, $user);
  476. // 超期任务数量 本月已完成任务数量 符合条件的当月任务
  477. list($num1, $num2, $mission) = $this->ItemNodeMissionAboutSearch($data, $user);
  478. // 🌟人效分析 人员工时对比(这里传入了当月筛选出的任务集)
  479. $man_about = $this->ItemNodeMissionAboutManSearch($data, $user, $mission);
  480. // 近六个月工时比较
  481. $last_six_about = $this->ItemNodeMissionAboutLastSixMonthSearch($data, $user);
  482. // 项目工时与人效排名
  483. $item_man_about = $this->ItemManSearch($data, $user);
  484. return [true, [
  485. 'item_count' => $item_count,
  486. 'item_node_count' => $item_node_count,
  487. 'item_node_mission_wait_count' => $item_node_mission_wait_count,
  488. 'cq_num' => $num1,
  489. 'wc_num' => $num2,
  490. 'rx' => $man_about['sub'],
  491. 'employee_work_list' => $man_about['employee_work_list'],
  492. 'last_six_month' => $last_six_about,
  493. 'item_man_abount' => $item_man_about
  494. ]];
  495. }
  496. private function ItemAboutSearch($data, $user){
  497. $model = Item::TopAndEmployeeClear($user, $data);
  498. return $model->where('del_time', 0)
  499. ->where('state', Item::TYPE_TWO)
  500. ->where('start_time', '<=', $data['end_now_month'])
  501. ->where('end_time', '>=', $data['start_now_month'])
  502. ->count();
  503. }
  504. private function ItemNodeAboutSearch($data, $user){
  505. $model = ItemNode::TopAndEmployeeClear($user, $data);
  506. return $model->where('del_time', 0)
  507. ->where('state', ItemNode::TYPE_TWO)
  508. ->where('start_time', '<=', $data['end_now_month'])
  509. ->where('end_time', '>=', $data['start_now_month'])
  510. // ->where('start_time', '<=', $data['start_now_month']) // 开始时间早于或等于当月结束
  511. // ->where('end_time', '>=', $data['end_now_month']) // 结束时间晚于或等于当月开始
  512. ->count();
  513. }
  514. private function ItemNodeMissionWaitAboutSearch($data, $user){
  515. // return WorkFlowInstances::where('del_time', 0)
  516. // ->where('document_type', 'item_node_mission')
  517. // ->where('crt_time', '>=', $data['start_now_month'])
  518. // ->where('crt_time', '<=', $data['end_now_month'])
  519. // ->where('status', WorkFlowInstances::status_two)
  520. // ->where('top_depart_id', $user['top_depart_id'])
  521. // ->count();
  522. return WorkFlowInstancesNodes::from('workflow_instance_nodes as nodes') // 给主表起个别名
  523. ->join('workflow_instances as instances', 'nodes.instance_id', '=', 'instances.id') // 直接连表,注意:如果你的外键不是 instance_id,请在这里修改
  524. ->where('nodes.del_time', 0)
  525. ->where('nodes.top_depart_id', $user['top_depart_id'])
  526. ->where('nodes.status', 1)
  527. ->whereRaw('JSON_CONTAINS(nodes.assignees, JSON_OBJECT("id", ?))', [$user['id']])
  528. ->whereRaw('NOT JSON_CONTAINS(nodes.assignees, JSON_OBJECT("id", ?, "is_pass", 1))', [$user['id']])
  529. ->where('instances.del_time', 0)
  530. ->where('instances.document_type', 'item_node_mission')
  531. ->where('instances.crt_time', '>=', $data['start_now_month'])
  532. ->where('instances.crt_time', '<=', $data['end_now_month'])
  533. ->where('instances.status', 'pending')
  534. ->count();
  535. }
  536. private function ItemNodeMissionAboutSearch($data, $user){
  537. $model = ItemNodeMission::TopAndEmployeeClear($user,$data);
  538. // 🌟 核心确保:不仅卡死当月区间,同时 select 出分摊所必需的 'start_time' 和 'end_time'
  539. $list = $model->where('del_time',0)
  540. ->where('start_time', '<=', $data['end_now_month'])
  541. ->where('end_time', '>=', $data['start_now_month'])
  542. ->select('state', 'end_time', 'id', 'due_work_hour', 'start_time')
  543. ->get()->toArray();
  544. $overdueCount = 0; // 已超期数量
  545. $completedCount = 0; // 已完成数量
  546. $now = time(); // 获取当前时间戳
  547. foreach ($list as $item) {
  548. if ($item['state'] == ItemNodeMission::TYPE_THREE) {
  549. $completedCount++;
  550. }
  551. if ($item['state'] == ItemNodeMission::TYPE_MINUS_TWO || $item['end_time'] < $now) {
  552. $overdueCount++;
  553. }
  554. }
  555. return [
  556. $overdueCount,
  557. $completedCount,
  558. $list
  559. ];
  560. }
  561. private function ItemNodeMissionAboutManSearch($data, $user, $mission){
  562. $mission_id = array_column($mission, 'id');
  563. // 🌟 严格限制:只查询当前月份内、且属于这批任务的实际工时单据 (防止把历史月份工时带入当前人员统计)
  564. $day_work_list = ItemNodeMissionContent::where('del_time',0)
  565. ->whereIn('item_node_mission_id', $mission_id)
  566. ->where('order_time', '>=', $data['start_now_month'])
  567. ->where('order_time', '<=', $data['end_now_month'])
  568. ->select('data_id as employee_id', 'total_work_min', 'item_id', 'item_node_mission_id')
  569. ->get()->toArray();
  570. $emp_map = Employee::whereIn('id', array_unique(array_column($day_work_list,'employee_id')))
  571. ->pluck('title','id')
  572. ->toArray();
  573. $total_work_minute = 0;
  574. $employee_keys = [];
  575. // 规整当前筛选月份的时间戳边界
  576. $start_timestamp = is_numeric($data['start_now_month']) ? (int)$data['start_now_month'] : strtotime($data['start_now_month']);
  577. $end_timestamp = is_numeric($data['end_now_month']) ? (int)$data['end_now_month'] : strtotime($data['end_now_month']);
  578. // 1. 预先计算好每个任务在【查询当月】的生命周期交集与分摊预计工时
  579. $yj_map = [];
  580. foreach ($mission as $m) {
  581. $m_id = $m['id'];
  582. // 🌟 强力兼容:不论数据库存的是 Timestamp 还是 Y-m-d 字符串,一律规整为标准时间戳计算天数
  583. $m_start = is_numeric($m['start_time']) ? (int)$m['start_time'] : strtotime($m['start_time']);
  584. $m_end = is_numeric($m['end_time']) ? (int)$m['end_time'] : strtotime($m['end_time']);
  585. if ($m_start && $m_end && $m_start <= $end_timestamp && $m_end >= $start_timestamp) {
  586. // 计算任务总天数
  587. $total_days = ceil(($m_end - $m_start) / 86400);
  588. if ($total_days <= 0) $total_days = 1;
  589. // 计算当月重叠区间
  590. $overlap_start = max($m_start, $start_timestamp);
  591. $overlap_end = min($m_end, $end_timestamp);
  592. $overlap_days = ceil(($overlap_end - $overlap_start) / 86400);
  593. if ($overlap_days < 0) $overlap_days = 0;
  594. // 算出该任务在当月应该分摊到的工时
  595. $yj_map[$m_id] = ($m['due_work_hour'] / $total_days) * $overlap_days;
  596. } else {
  597. $yj_map[$m_id] = 0;
  598. }
  599. }
  600. $employee_array = [];
  601. // 2. 第一步:纯粹统计当月实际工时,并将任务 ID 归并到人头上
  602. foreach ($day_work_list as $work) {
  603. $emp_id = $work['employee_id'];
  604. if (empty($emp_id)) continue;
  605. $total_work_minute += $work['total_work_min'];
  606. $employee_keys[$emp_id] = true;
  607. if (isset($employee_array[$emp_id])) {
  608. $employee_array[$emp_id]['actual_work'] += $work['total_work_min'];
  609. if (!in_array($work['item_node_mission_id'], $employee_array[$emp_id]['mission_id'])) {
  610. $employee_array[$emp_id]['mission_id'][] = $work['item_node_mission_id'];
  611. }
  612. } else {
  613. $employee_array[$emp_id] = [
  614. 'employee_id' => $emp_id,
  615. 'employee_title' => $emp_map[$emp_id] ?? '',
  616. 'actual_work' => $work['total_work_min'],
  617. 'mission_id' => [$work['item_node_mission_id']],
  618. 'yj_work' => 0, // 先占位
  619. ];
  620. }
  621. }
  622. // 3. 第二步:按人头独立参与的任务集合,精准分配分摊预计工时,同时记录已被触发的有效任务
  623. $valid_mission_ids = [];
  624. foreach ($employee_array as $emp_id => $emp_info) {
  625. $emp_yj_work = 0;
  626. foreach ($emp_info['mission_id'] as $m_id) {
  627. $emp_yj_work += $yj_map[$m_id] ?? 0;
  628. $valid_mission_ids[$m_id] = true; // 记录当月实际有人填报的任务
  629. }
  630. $employee_array[$emp_id]['actual_work'] = round($emp_info['actual_work'] / 60, 2);
  631. $employee_array[$emp_id]['yj_work'] = round($emp_yj_work, 2);
  632. }
  633. // 根据实际工时降序
  634. usort($employee_array, function($a, $b) {
  635. return $b['actual_work'] <=> $a['actual_work'];
  636. });
  637. $total_work_hours = round($total_work_minute / 60, 2);
  638. $employee_count = count($employee_keys);
  639. // 🌟 核心对齐:总预计工时【只计算当前出现在有效人员列表里的分摊工时总和】,确保和大盘数据指标完全对齐闭环
  640. $total_yj_work_hours = 0;
  641. foreach (array_keys($valid_mission_ids) as $m_id) {
  642. $total_yj_work_hours += $yj_map[$m_id] ?? 0;
  643. }
  644. $num = '0.00';
  645. $num_yj = '0.00';
  646. $num_rate = '0.00';
  647. $num_rate_2 = '0.00';
  648. $num_rate_3 = '0.00';
  649. $num_rate_4 = '0.00';
  650. $num_rate_5 = '0.00';
  651. if ($employee_count > 0) {
  652. $num = bcdiv($total_work_hours, $employee_count, 2);
  653. $num_yj = bcdiv($total_yj_work_hours, $employee_count, 2);
  654. }
  655. if (bccomp($num_yj, '0.00', 2) > 0) {
  656. $num_rate = bcmul(bcdiv($num, $num_yj, 4), 100, 2);
  657. }
  658. if ($total_yj_work_hours > 0 && $employee_count > 0) {
  659. $num_rate_2 = bcmul(bcdiv($total_work_hours, bcmul($total_yj_work_hours, $employee_count, 4), 4), 100, 2);
  660. }
  661. if ($total_yj_work_hours > 0) {
  662. $num_rate_3 = bcmul(bcdiv($total_work_hours, $total_yj_work_hours, 4), 100, 2);
  663. }
  664. // 成本人效比计算保持原有逻辑
  665. $total = Item::where('del_time', 0)->whereIn('id', array_unique(array_column($day_work_list, 'item_id')))->sum('budget');
  666. $monthly_ps_order = MonthlyPsOrder::Clear($user, $data)->where('del_time', 0)->where("month", ">=", $data['start_now_month'])
  667. ->where("month", "<", $data['end_now_month'])->pluck('id')->toArray();
  668. $month_employee_salary = MonthlyPsOrderDetails::whereIn('main_id', $monthly_ps_order)->select("base_salary", "performance_salary", "other", "bonus", "main_id")->get()->toArray();
  669. $man_total = 0;
  670. foreach ($month_employee_salary as $value) {
  671. $currentAmount = bcadd($value['base_salary'], $value['performance_salary'], 3);
  672. $currentAmount = bcadd($currentAmount, $value['other'], 3);
  673. $currentAmount = bcadd($currentAmount, $value['bonus'], 3);
  674. $man_total = bcadd($man_total, $currentAmount, 3);
  675. }
  676. if (bccomp($man_total, '0.000', 3) > 0) {
  677. $num_rate_4 = bcmul(bcdiv($total, $man_total, 4), 100, 2);
  678. $num_rate_5 = bcmul(bcdiv(bcdiv($total, $man_total, 4), 4, 4), 100, 2);
  679. }
  680. $man_final = round((float)$num_rate_3 * 0.6 + (float)$num_rate_4 * 0.4, 2);
  681. return [
  682. 'employee_work_list' => $employee_array,
  683. 'sub' => [
  684. 'average_actual_hours' => $num,
  685. 'average_du_hours' => $num_yj,
  686. 'average_actual_hours_rate' => $num_rate,
  687. 'load_rate' => $num_rate_2,
  688. 'achievement_rate' => $num_rate_3,
  689. 'man_rate' => $num_rate_4,
  690. 'man_rate_2' => $num_rate_5,
  691. 'man_final' => $man_final
  692. ]
  693. ];
  694. }
  695. private function ItemNodeMissionAboutLastSixMonthSearch($data, $user)
  696. {
  697. // 1. 先计算出近 6 个月的大总区间(最远月份的月初 到 当月的月末)
  698. $oldestMonthStart = date('Y-m-01 00:00:00', strtotime("-5 month"));
  699. $currentMonthEnd = date('Y-m-t 23:59:59'); // 当月月末
  700. $all_start_timestamp = strtotime($oldestMonthStart);
  701. $all_end_timestamp = strtotime($currentMonthEnd);
  702. // 2. 一次性捞出近 6 个月内所有可能相交的任务
  703. $mission_model = ItemNodeMission::TopAndEmployeeClear($user, $data);
  704. $all_missions = $mission_model->where('del_time', 0)
  705. ->where('start_time', '<=', $all_end_timestamp)
  706. ->where('end_time', '>=', $all_start_timestamp)
  707. ->select('id', 'due_work_hour', 'start_time', 'end_time')
  708. ->get()
  709. ->toArray();
  710. $all_mission_ids = array_column($all_missions, 'id');
  711. // 3. 一次性查出这些任务所有的实际工时记录(把 crt_time 换成你表里的 order_time)
  712. $all_work_contents = [];
  713. if (!empty($all_mission_ids)) {
  714. $all_work_contents = ItemNodeMissionContent::where('del_time', 0)
  715. ->whereIn('item_node_mission_id', $all_mission_ids)
  716. ->select('item_node_mission_id', 'total_work_min', 'order_time') // 👈 查出单据日期
  717. ->get()
  718. ->toArray();
  719. }
  720. $result = [];
  721. // 4. 以时间为驱动循环 6 次
  722. for ($i = 5; $i >= 0; $i--) {
  723. $monthStart = date('Y-m-01 00:00:00', strtotime("-$i month"));
  724. $monthEnd = date('Y-m-t 23:59:59', strtotime("-$i month"));
  725. $start_timestamp = strtotime($monthStart);
  726. $end_timestamp = strtotime($monthEnd);
  727. $month_name = date('Y-m', $start_timestamp);
  728. $month_due_hours = 0;
  729. $month_actual_mins = 0;
  730. // 5. 计算预计工时:按任务生命周期交集 + 天数均摊
  731. if (!empty($all_missions)) {
  732. foreach ($all_missions as $mission) {
  733. // 判断当前任务是否与当前月份有交集
  734. if ($mission['start_time'] <= $end_timestamp && $mission['end_time'] >= $start_timestamp) {
  735. // A. 计算任务总生命周期的总天数
  736. $total_days = ceil(($mission['end_time'] - $mission['start_time']) / 86400);
  737. if ($total_days <= 0) $total_days = 1;
  738. // B. 计算当前月份与该任务的【重叠区间】
  739. $overlap_start = max($mission['start_time'], $start_timestamp);
  740. $overlap_end = min($mission['end_time'], $end_timestamp);
  741. // C. 计算这个月里,该任务占用了多少天
  742. $overlap_days = ceil(($overlap_end - $overlap_start) / 86400);
  743. if ($overlap_days < 0) $overlap_days = 0;
  744. // D. 按比例分摊预计工时,并累加到当前月份
  745. $share_due_hour = ($mission['due_work_hour'] / $total_days) * $overlap_days;
  746. $month_due_hours += $share_due_hour;
  747. }
  748. }
  749. }
  750. // 6. ✨ 计算实际工时:严格根据单据日期 (order_time) 划归到具体的自然月
  751. if (!empty($all_work_contents)) {
  752. foreach ($all_work_contents as $work) {
  753. // 只有当工时记录的单据日期在当前月份区间内,才计入该月
  754. if ($work['order_time'] >= $start_timestamp && $work['order_time'] <= $end_timestamp) {
  755. $month_actual_mins += $work['total_work_min'];
  756. }
  757. }
  758. }
  759. // 7. 组装当前月份的数据结果
  760. $result[] = [
  761. 'month' => $month_name,
  762. 'total_due_hours' => round($month_due_hours, 2),
  763. 'total_actual_hours' => round($month_actual_mins / 60, 2)
  764. ];
  765. }
  766. return $result;
  767. }
  768. private function ItemManSearch($data, $user)
  769. {
  770. // 1. 获取当月进行中的项目
  771. $model = Item::TopAndEmployeeClear($user, $data);
  772. $item_list = $model->where('del_time', 0)
  773. ->whereIn('state', [Item::TYPE_TWO, Item::TYPE_THREE])
  774. ->where('start_time', '<=', $data['end_now_month'])
  775. ->where('end_time', '>=', $data['start_now_month'])
  776. ->select('id', 'title', 'budget') // 👈 增加选出项目总金额 budget 用于计算产值/成本
  777. ->get()->toArray();
  778. if (empty($item_list)) {
  779. return [];
  780. }
  781. $item_ids = array_column($item_list, 'id');
  782. $start_timestamp = (int)$data['start_now_month'];
  783. $end_timestamp = (int)$data['end_now_month'];
  784. // ==========================================
  785. // 🛠️ 核心步骤一:计算本月全员总实际工时与总工资
  786. // ==========================================
  787. // A. 本月全员总实际工时 (分钟)
  788. $all_employee_actual_mins = ItemNodeMissionContent::where('del_time', 0)
  789. ->where('order_time', '>=', $start_timestamp)
  790. ->where('order_time', '<=', $end_timestamp)
  791. ->sum('total_work_min');
  792. $all_employee_actual_hours = round($all_employee_actual_mins / 60, 2);
  793. // B. 本月全员总工资额
  794. $monthly_ps_order = MonthlyPsOrder::Clear($user, $data)->where('del_time', 0)
  795. ->where("month", ">=", $data['start_now_month'])
  796. ->where("month", "<", $data['end_now_month'])
  797. ->pluck('id')->toArray();
  798. $month_employee_salary = MonthlyPsOrderDetails::whereIn('main_id', $monthly_ps_order)
  799. ->select("base_salary", "performance_salary", "other", "bonus")
  800. ->get()->toArray();
  801. $total_salary = 0;
  802. foreach ($month_employee_salary as $value) {
  803. $currentAmount = bcadd($value['base_salary'], $value['performance_salary'], 3);
  804. $currentAmount = bcadd($currentAmount, $value['other'], 3);
  805. $currentAmount = bcadd($currentAmount, $value['bonus'], 3);
  806. $total_salary = bcadd($total_salary, $currentAmount, 3);
  807. }
  808. // ==========================================
  809. // 🛠️ 核心步骤二:获取项目下当月的任务并均摊预计工时
  810. // ==========================================
  811. // 获取这批项目下的所有任务
  812. $missions = ItemNodeMission::where('del_time', 0)
  813. ->whereIn('item_id', $item_ids)
  814. ->where('start_time', '<=', $end_timestamp)
  815. ->where('end_time', '>=', $start_timestamp)
  816. ->select('id', 'item_id', 'due_work_hour', 'start_time', 'end_time')
  817. ->get()->toArray();
  818. // 按项目归总分摊后的预计工时
  819. $item_yj_work_map = [];
  820. foreach ($missions as $m) {
  821. $proj_id = $m['item_id'];
  822. $m_start = is_numeric($m['start_time']) ? (int)$m['start_time'] : strtotime($m['start_time']);
  823. $m_end = is_numeric($m['end_time']) ? (int)$m['end_time'] : strtotime($m['end_time']);
  824. if ($m_start && $m_end && $m_start <= $end_timestamp && $m_end >= $start_timestamp) {
  825. // 任务总寿命天数
  826. $total_days = ceil(($m_end - $m_start) / 86400);
  827. if ($total_days <= 0) $total_days = 1;
  828. // 当月重叠天数
  829. $overlap_start = max($m_start, $start_timestamp);
  830. $overlap_end = min($m_end, $end_timestamp);
  831. $overlap_days = ceil(($overlap_end - $overlap_start) / 86400);
  832. if ($overlap_days < 0) $overlap_days = 0;
  833. // 分摊到当月的预计工时
  834. $share_yj_hour = ($m['due_work_hour'] / $total_days) * $overlap_days;
  835. if (!isset($item_yj_work_map[$proj_id])) {
  836. $item_yj_work_map[$proj_id] = 0;
  837. }
  838. $item_yj_work_map[$proj_id] += $share_yj_hour;
  839. }
  840. }
  841. // ==========================================
  842. // 🛠️ 核心步骤三:获取项目下当月的实际工时
  843. // ==========================================
  844. $work_contents = ItemNodeMissionContent::where('del_time', 0)
  845. ->whereIn('item_id', $item_ids)
  846. ->where('order_time', '>=', $start_timestamp)
  847. ->where('order_time', '<=', $end_timestamp)
  848. ->select('item_id', 'total_work_min')
  849. ->get()->toArray();
  850. // 按项目归总实际工时(分钟转换为小时)
  851. $item_actual_work_map = [];
  852. foreach ($work_contents as $work) {
  853. $proj_id = $work['item_id'];
  854. if (!isset($item_actual_work_map[$proj_id])) {
  855. $item_actual_work_map[$proj_id] = 0;
  856. }
  857. $item_actual_work_map[$proj_id] += $work['total_work_min'];
  858. }
  859. // ==========================================
  860. // 🛠️ 核心步骤四:组装数据并计算各项人效指标
  861. // ==========================================
  862. foreach ($item_list as &$item) {
  863. $id = $item['id'];
  864. // 1. 预计工时与实际工时
  865. $yj_work = isset($item_yj_work_map[$id]) ? round($item_yj_work_map[$id], 2) : 0.00;
  866. $actual_work = isset($item_actual_work_map[$id]) ? round($item_actual_work_map[$id] / 60, 2) : 0.00;
  867. $item['yj_work'] = $yj_work;
  868. $item['actual_work'] = $actual_work;
  869. // 2. 计算工时达成率 = 实际 ÷ 预计 × 100%
  870. $item['achievement_rate'] = '0.00';
  871. if ($yj_work > 0) {
  872. $item['achievement_rate'] = bcmul(bcdiv($actual_work, $yj_work, 4), 100, 2);
  873. }
  874. // 3. 计算项目人力成本 = 项目实际工时 × (本月工资总额 ÷ 本月全员实际工时)
  875. $item_cost = '0.00';
  876. if ($all_employee_actual_hours > 0) {
  877. // 平均时薪 = 工资总额 ÷ 全员实际工时
  878. $hourly_wage = bcdiv($total_salary, $all_employee_actual_hours, 4);
  879. // 项目人力成本 = 项目实际工时 × 平均时薪
  880. $item_cost = bcmul($actual_work, $hourly_wage, 2);
  881. }
  882. $item['item_cost'] = $item_cost;
  883. // 4. 计算产值/成本 = 项目总金额 ÷ 项目人力成本
  884. $item['production_cost_rate'] = '0.00';
  885. if (bccomp($item_cost, '0.00', 2) > 0) {
  886. $item['production_cost_rate'] = bcdiv($item['budget'], $item_cost, 2);
  887. }
  888. }
  889. return $item_list;
  890. }
  891. }