cqpCow 1 éve
szülő
commit
a2486bcfcc
2 módosított fájl, 16 hozzáadás és 33 törlés
  1. 15 32
      app/Import/Import.php
  2. 1 1
      app/Service/FinanceService.php

+ 15 - 32
app/Import/Import.php

@@ -3,18 +3,9 @@
 
 namespace  App\Import;
 
-use App\Model\Employee;
 use App\Model\Finance;
 use App\Model\FinanceDetail;
-use App\Model\Inventory;
-use App\Model\InventoryInSub;
-use App\Model\InventoryOutSub;
-use App\Model\InventorySub;
-use App\Model\RollFilm;
-use App\Model\RollFilmCompare;
-use App\Model\RollFilmInventory;
 use App\Model\Settings;
-use App\Model\Storehouse;
 use Illuminate\Support\Facades\DB;
 use Maatwebsite\Excel\Concerns\ToArray;
 
@@ -38,6 +29,18 @@ class Import implements ToArray {
         $this->msg = $msg;
     }
 
+    function splitAmount($amount, $defaultAmount) {
+        $result = array();
+        while ($amount > $defaultAmount) {
+            $result[] = $defaultAmount;
+            $amount -= $defaultAmount;
+        }
+        if ($amount > 0) {
+            $result[] = $amount;
+        }
+        return $result;
+    }
+
     public function handleData (array $array) {
         // 去除表头
         unset($array[0]);
@@ -89,28 +92,8 @@ class Import implements ToArray {
                 'crt_time' => $crt_time
             ];
             $totalAmount = (float)$value[3];
-
-            $num = floor($totalAmount / $defaultAmount); // 拆分出来的次数
-            if((int)$num <= 1){
-                $sub[$key][] = [
-                    'amount' => $totalAmount
-                ];
-            }else{
-                $remainingAmount = $totalAmount % $defaultAmount; // 剩余的金额
-                $equalAmount = floor($totalAmount / $num); // 平均金额
-                $lastAmount = $equalAmount + $remainingAmount; // 最后金额(加上剩余的金额)
-                for ($i = 0;$i < (int)$num; $i++){
-                    if ($i == (int)$num - 1) {
-                        // 最后一次
-                        $tmp = $lastAmount;
-                    } else {
-                        $tmp = $equalAmount;
-                    }
-                    $sub[$key][] = [
-                        'amount' => $tmp
-                    ];
-                }
-            }
+            $return = $this->splitAmount($totalAmount,$defaultAmount);
+            $sub[$key] = $return;
         }
 
         try{
@@ -125,7 +108,7 @@ class Import implements ToArray {
             foreach ($sub as $key => $value){
                 foreach ($value as $v){
                     $insert_sub[] =  [
-                        'amount' => $v['amount'],
+                        'amount' => $v,
                         'finance_id' => $last_insert_id[$key],
                         'crt_time' => $crt_time
                     ];

+ 1 - 1
app/Service/FinanceService.php

@@ -46,7 +46,7 @@ class FinanceService extends Service
             ->where('a.del_time',0)
             ->where('b.del_time',0)
             ->select('a.finance_account_name','a.account','a.ifsc','a.crt_time','b.id','b.amount','b.status','b.confirm_time')
-            ->orderBy('b.id','desc');
+            ->orderBy('a.id','desc');
 
         if(! empty($data['finance_account_name'])) $model->where('a.finance_account_name', 'LIKE', '%'.$data['finance_account_name'].'%');
         if(! empty($data['account'])) $model->where('a.account', 'LIKE', '%'.$data['account'].'%');