/
home
/
corsairdevelopme
/
public_html
/
amplivo-console
/
app
/
Models
/
Upload File
HOME
<?php namespace App\Models; use Carbon\Carbon; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class WalletLog extends Model { const STATUS_DONE = 'done'; const STATUS_PENDING = 'pending'; const STATUS_FAILED = 'failed'; const STATUS_LOCKED = 'locked'; const GROUP_BY_ALL = 0; const GROUP_BY_DAILY = 1; const GROUP_BY_WEEKLY = 2; const ACTION_INITIAL = 1; const ACTION_DEPOSIT = 2; const ACTION_WITHDRAW = 3; const ACTION_TRANSFER_IN = 4; const ACTION_TRANSFER_OUT = 5; const ACTION_PURCHASE = 6; const ACTION_CREDIT = 7; const ACTION_EARNING = 8; const ACTION_COMMISSION = 9; const ACTION_MATCHING_BONUS = 10; const ACTION_EXCHANGE_IN = 11; const ACTION_EXCHANGE_OUT = 12; const ACTION_DEBIT = 13; // const ACTION_BERGMAN_PURCHASE = 13; const ACTION_BERGMAN_DEPOSIT = 14; const ACTION_BERGMAN_EARNING = 15; const ACTION_TRANSFER_TO_CCW = 16; const ACTION_PURCHASE_COUPON_REDEEM = 17; const ACTION_REWARD = 18; const ACTION_EXTERNAL_PURCHASE = 19; const ACTION_BONUS_EARNING = 20; const ACTION_INFINITY_STAR_BONUS = 21; const ACTION_INFINITY_STAR_BONUS_EARNING = 22; const ACTION_ORT_PURCHASE = 23; const ACTION_ORTP_PURCHASE = 24; const ACTION_TRANSFER_FROM_CCW = 25; const ACTION_CUSTOMER_ACQUISITION_BONUS = 26; const ACTION_CUSTOMER_ACQUISITION_BONUS_EARNING = 27; const ACTION_WITHDRAW_MASTERCARD = 28; const ACTION_REFUND = 29; const ACTION_FINE = 30; const ACTION_RESTART_DEBIT = 31; const ACTION_ISF_PURCHASE = 32; const ACTION_ECOVO_POINT_REDEEM = 33; const ACTION_ISF_PURCHASE_FEE = 34; const ACTION_CRYPTO_TOKEN_TRANFER_IN = 35; const ACTION_FAST_START_RANK_BONUS = 36; const ACTION_FAST_START_PGV_BONUS = 37; const ACTION_TRANSFER_FROM_ECOVO = 38; const ACTION_TRANSFER_TO_ECOVO = 39; const ACTION_CSR_PURCHASE = 40; const ACTION_CSR_PURCHASE_FEE = 41; const ACTION_EXPIRED = 42; const ACTION_RESET = 43; const ACTION_CWMEUR_PURCHASE = 44; const ACTION_CSR_POOL = 45; const ACTION_CHARGE = 46; const ACTION_TRANSFER_BALANCE_FROM_ECOVO = 47; const ACTION_CONVERT_BALANCE = 48; const ACTION_CSR_EARNING = 49; const ACTION_CWMEUR_REVERSAL = 50; const ACTION_WITHDRAW_FEE = 51; const UNILEVEL_COMMISSION = 9; const UNILEVEL_EARNING = 8; const STAR_RANK = 8; const MATCHING_BONUS = 10; const MATCHING_EARNING = 20; const INFINITY_STAR_BONUS = 21; const INFINITY_STAR_EARNING = 22; const CUSTOMER_ACQUISITION_BONUS = 26; const CUSTOMER_ACQUISITION_EARNING = 27; const ACTION_GROUP_DEFAULT = 'default'; const ACTION_GROUP_LEGACY = 'legacy'; const ACTION_GROUP_OTHER = 'other'; use HasFactory; public $timestamps = false; protected $table = 'wallet_log'; protected $fillable = [ 'wallet_id', 'action', 'data', 'value', 'balance', 'created_at', 'updated_at', 'status', 'unique_id', 'transaction_id', ]; protected $dates = ['created_at', 'updated_at',]; protected $walletName = [ 4 => "Transfer In", 6 => "Purchase", 8 => "Uni-level commission", 9 => "Uni-level commission", 10 => "Matching bonus", 20 => "Matching bonus", 21 => "Infinity star bonus", 22 => "Infinity star bonus", 26 => "Customer Acquisition Bonus", 27 => "Customer Acquisition Bonus", 49 => "FLP redemptions for CSR", ]; const actionName = [ 6 => "Purchase", // --- Purchase 7 => "Credit", 13 => "Debit", 40 => "CSR Purchase", 42 => "Expired", 46 => "Charge", 45 => "Bonus Purchase Pool", 9 => "Uni-level commission", 21 => "Infinity star bonus", 8 => "Star Rank", // --- Star Rank 10 => "Matching bonus", // -- Matching Bounce 26 => "Customer Acquisition Bonus", 20 => "Bonus Earning", 2 => "Deposit", 3 => "Withdraw", 51 => "Withdraw Fee", 4 => "Transfer In", 5 => "Transfer Out", ]; protected $appends = ['wallet_name', 'action_name', 'tax']; protected static function boot() { parent::boot(); // When a record is created, this will be triggered static::creating(function ($model) { if (empty($model->transaction_id)) { // Generate or fetch the unique transaction ID $model->transaction_id = getLastTransactionUniqueId(); } }); } public function getTaxAttribute() { $data = json_decode($this->attributes['data'], true); return $data['tax_data']['total_amount'] ?? 0; } public static function safeActions() { return [ self::ACTION_INITIAL, self::ACTION_CREDIT, self::ACTION_EXPIRED, self::ACTION_CSR_PURCHASE, ]; } public function afterSave() { $prevLog = $this->previous(); $balance = $this->value + ($prevLog->balance ?? 0); $this->balance ? ($prevLog->balance ?? 0) : $this->balance; if ($balance != $this->balance) { $this->balance = $balance; $this->save(); } } public function previous() { $this->created_at ?? Carbon::now(); $id = $this->id; return WalletLog::where( 'wallet_id', $this->wallet_id )->whereIn('status', [WalletLog::STATUS_DONE, WalletLog::STATUS_LOCKED])->where('id', '<', $id) ->orderBy('created_at', 'DESC') ->orderBy('id', 'DESC') ->first(); } public function updateFutureBalances($amount) { $this->created_at ?? ''; $id = $this->id ?? 0; WalletLog::where( 'wallet_id', $this->wallet_id )->where('id', '<', $id)->increment('balance', $amount); } public function wallet() { return $this->belongsTo(Wallet::class)->with('wallet_list'); } public function WalletName(): Attribute { return Attribute::make( function ($value) { return $this->walletName[$this->attributes['action']] ?? "-"; } ); } public function ActionName(): Attribute { return Attribute::make( function ($value) { return self::actionName[$this->attributes['action']] ?? "-"; } ); } public function purchase() { return $this->hasMany(Purchase::class, 'transaction_id'); } }