You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
824 B
PHTML
34 lines
824 B
PHTML
1 year ago
|
<?php
|
||
|
|
||
|
namespace App\Imports;
|
||
|
|
||
|
use App\Models\Customer;
|
||
|
use App\Models\CustomerPoint;
|
||
|
use Maatwebsite\Excel\Concerns\ToModel;
|
||
|
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||
|
|
||
|
class CustomerPointsImport implements ToModel, WithHeadingRow
|
||
|
{
|
||
|
/**
|
||
|
* @param array $row
|
||
|
*
|
||
|
* @return \Illuminate\Database\Eloquent\Model|null
|
||
|
*/
|
||
|
public function model(array $row)
|
||
|
{
|
||
|
$customer = Customer::where('code', $row['code'])->first();
|
||
|
|
||
|
if ($customer != null) {
|
||
|
$customer->update([
|
||
|
'last_point' => $customer->last_point + $row['point']
|
||
|
]);
|
||
|
|
||
|
return new CustomerPoint([
|
||
|
'customer_id' => $customer->id,
|
||
|
'description' => $row['description'],
|
||
|
'point' => $row['point'],
|
||
|
]);
|
||
|
}
|
||
|
}
|
||
|
}
|