shish 1 год назад
Родитель
Сommit
e84b0e13b6
1 измененных файлов с 61 добавлено и 0 удалено
  1. 61 0
      app-ghs/controllers/ExpendController.php

+ 61 - 0
app-ghs/controllers/ExpendController.php

@@ -16,6 +16,67 @@ use Yii;
 class ExpendController extends BaseController
 {
 
+    //数据统计 ssh 20241122
+    public function actionStat()
+    {
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+
+        $get = Yii::$app->request->get();
+        $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
+
+        $startTime = $get['startTime'] ?? '';
+        $endTime = $get['endTime'] ?? '';
+        $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
+        $start = $period['startTime'];
+        $end = $period['endTime'];
+
+        $currentStartDate = date('Y-m-d', strtotime($start));
+        $currentEndDate = date('Y-m-d', strtotime($end));
+        $currentStartTime = $currentStartDate . ' 00:00:00';
+        $currentEndTime = $currentEndDate . ' 23:59:59';
+
+        $where = ['mainId' => $this->mainId];
+        $where['addTime'] = ['between', [$currentStartTime, $currentEndTime]];
+
+        $list = ExpendClass::getAllByCondition($where, null, '*', null);
+        $arr = [];
+        $totalExpend = 0;
+        if (!empty($list)) {
+            foreach ($list as $expend) {
+                $staffId = $expend['staffId'] ?? 0;
+                $amount = $expend['amount'] ?? 0;
+                $staffName = $expend['staffName'] ?? '';
+                $bx = $expend['bx'] ?? 0;
+                $currentAmount = $amount;
+                if ($bx == 0) {
+                    $hasAmount = 0;
+                    $unAmount = $amount;
+                } else {
+                    $hasAmount = $amount;
+                    $unAmount = 0;
+                }
+                if (isset($arr[$staffId])) {
+                    //总支出
+                    $arr[$staffId]['totalAmount'] = bcadd($arr[$staffId]['totalAmount'], $currentAmount);
+                    //已报销
+                    $arr[$staffId]['hasAmount'] = bcadd($arr[$staffId]['hasAmount'], $hasAmount);
+                    //待报销
+                    $arr[$staffId]['amount'] = bcadd($arr[$staffId]['amount'], $unAmount);
+                    $arr[$staffId]['num'] = bcadd($arr[$staffId]['num'], 1);
+                } else {
+                    $arr[$staffId]['totalAmount'] = $currentAmount;
+                    $arr[$staffId]['hasAmount'] = $hasAmount;
+                    $arr[$staffId]['amount'] = $unAmount;
+                    $arr[$staffId]['staffName'] = $staffName;
+                    $arr[$staffId]['num'] = 1;
+                }
+                $totalExpend = bcadd($totalExpend, $currentAmount, 2);
+            }
+        }
+        util::success(['list' => $arr, 'totalExpend' => $totalExpend]);
+    }
+
     //报销汇总统计 ssh 20240308
     public function actionUnBxList()
     {