|
@@ -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
|
|
|
];
|