delete duplicated 1688 bank account

This commit is contained in:
Jia Sheng
2024-07-14 11:00:33 +08:00
parent f533810e42
commit 63118efc0b
4 changed files with 94 additions and 7 deletions
@@ -8,7 +8,7 @@ final class BankAccountType {
public const EXTERNAL = 2;
public const ALIPAY= 3;
public const ALIPAY_1688 = 3;
public const ALIPAY_RECIPIENT = 4;
@@ -0,0 +1,75 @@
<?php
namespace App\Console\Commands;
use App\Models\Bank;
use App\Models\Booking;
use Illuminate\Console\Command;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
class DeleteDuplicate1688BankAccount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'banks:deleteDuplicate1688Account';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete duplicate 1688 account in banks table';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
// account_no: 1688 LOGIN ID/EMAIL/PHONE
// holder_name: password
// bank_branch: 6-digit pin
$records = Bank::where('type', 3)->get();
$groupedBanks = $records->groupBy(function($item, $key) {
return $item['company_id'] . '-' . $item['account_no'];
});
foreach ($groupedBanks as $key => $banksWithSameUserAndAccountNo) {
// Sort banks by created_at or updated_at to find the latest one
$sortedBanks = $banksWithSameUserAndAccountNo->sortByDesc('created_at');
// Retain the latest bank
$latestBank = $sortedBanks->first();
// Get all IDs except the latest one
$idsToDelete = $sortedBanks->pluck('id')->slice(1);
foreach ($idsToDelete as $id) {
Booking::where('bank_id', $id)->update([
'bank_id' => $latestBank->id
]);
}
$this->info('for company id: ' . $latestBank->company_id . ', account no: ' . $latestBank->account_no . ', duplicated id: ' . $idsToDelete);
// Delete the rest
Bank::whereIn('id', $idsToDelete)->delete();
}
}
}
+1 -1
View File
@@ -56,7 +56,7 @@ class CompanyResource extends JsonResource
'last_payment' => $lastPayment ? $lastPayment->created_at->diffForHumans() : 'No Payments',
'personal_banks' => BankResource::collection($this->banks->where('type', BankAccountType::PERSONAL)),
'recipient_banks' => [
'accounts' => BankResource::collection($this->banks->whereIn('type', [BankAccountType::EXTERNAL, BankAccountType::ALIPAY_RECIPIENT])),
'accounts' => BankResource::collection($this->banks->whereIn('type', [BankAccountType::EXTERNAL, BankAccountType::ALIPAY_1688, BankAccountType::ALIPAY_RECIPIENT])),
'default' => new BankResource($this->banks->where('type', BankAccountType::EXTERNAL)->where('default', true)->first())
],
'segments' => SegmentResource::collection($this->segments),
@@ -100,7 +100,7 @@
</div>
</div>
</div>
<div class="row" v-show="!createBank">
<div class="row" v-show="!createBank && !existingBank">
<div class="col-7 p-r-0">
<div class="row" id="select-list" name="select-list">
<div class="col">
@@ -144,13 +144,13 @@
</div>
</div>
<div class="col-auto p-l-0" v-show="!createBank && account_no && !Object.keys(parameters.bankAccount).length">
<button class="btn btn-sm h-100 btn-primary b-rad-none all-caps" @click="createBank = !createBank; dropdownStatus = false">
<button class="btn btn-sm h-100 btn-primary b-rad-none all-caps" @click="createBank = true; existingBank = false; dropdownStatus = false">
<i class="fa fa-plus m-r-5"></i>
Create New
</button>
</div>
</div>
<div class="row" v-show="createBank">
<div class="row" v-show="createBank || existingBank">
<div class="col">
<bank-account-form-component v-if="!isOneSizEightEightOrder && !isAlipayOrder" section="customerProfileSection" :disabled="formDisabled" :data="Object.keys(parameters.bankAccount).length ? parameters.bankAccount : {account_no: account_no, company_id: data.company.id, country_id: 2, account_type: 2}" :company_id="data.company.id" :country_id="2" :type="2" :currency="data.serviceType.selectedCurrency.short_code" v-on:createdBank="updateBank($event)" :serviceType="data.serviceType" :closable=false v-on:close="clearAccount()"></bank-account-form-component>
<phone-account-form-component v-if="isOneSizEightEightOrder" section="customerProfileSection" :disabled="formDisabled" :data="Object.keys(parameters.bankAccount).length ? parameters.bankAccount : {account_no: account_no, company_id: data.company.id, country_id: 2, account_type: 2}" :company_id="data.company.id" :country_id="2" :type="2" v-on:createdBank="updateBank($event)" :serviceType="data.serviceType" :closable=false v-on:close="clearAccount()"></phone-account-form-component>
@@ -318,6 +318,7 @@
data(){
return {
createBank: false,
existingBank: false,
recipientBanks: [],
dropdownStatus: false,
account_no: '',
@@ -326,9 +327,14 @@
oneSixEightEightServiceIds: [4, 10],
}
},
watch: {
'data.serviceType.id': function() {
this.clearAccount();
}
},
computed: {
formDisabled(){
return !!Object.keys(this.parameters.bankAccount).length;
return this.existingBank;
},
isOneSizEightEightOrder() {
return this.oneSixEightEightServiceIds.includes(this.data.serviceType.id);
@@ -341,6 +347,10 @@
return [4];
}
if (this.isOneSizEightEightOrder) {
return [3];
}
if (!this.isAlipayOrder && !this.isOneSizEightEightOrder) {
return [1, 2];
}
@@ -363,12 +373,14 @@
},
selectBank(bank){
this.account_no = bank.account_no;
this.createBank = true;
this.createBank = false;
this.existingBank = true;
this.parameters.bankAccount = bank;
this.dropdownStatus = false;
},
clearAccount(){
this.createBank = false;
this.existingBank = false;
this.account_no = '';
this.parameters.bankAccount = {};
}