<commit_before><?php

namespace App\Models;

use App\Events\ModelCreatedEvent;
use App\Events\ModelUpdatedEvent;
use Illuminate\Database\Eloquent\Model;
use App\Models\BaseModel;
use Illuminate\Support\Facades\Auth;

/**
 * model description
 * Class CustomerPayment
 * @package  App\Models
 *
 * @author  xrs
 * @SWG\Model(id="CustomerPayment")
 * @SWG\Property(name="amt", type="number", description="订单金额")
 * @SWG\Property(name="created_at", type="string", description="")
 * @SWG\Property(name="creator_id", type="integer", description="创建用户id")
 * @SWG\Property(name="customer_id", type="integer", description="customer id")
 * @SWG\Property(name="deleted_at", type="string", description="")
 * @SWG\Property(name="id", type="integer", description="")
 * @SWG\Property(name="modifier_id", type="integer", description="修改用户id")
 * @SWG\Property(name="outer_order_sn", type="string", description="外部订单号 支付宝|微信生成的订单号")
 * @SWG\Property(name="payment_channel", type="integer", description="支付渠道 1-微信支付 2-支付宝")
 * @SWG\Property(name="reference_id", type="integer", description="关联表id")
 * @SWG\Property(name="reference_type", type="string", description="关联表类型")
 * @SWG\Property(name="remark", type="string", description="备注")
 * @SWG\Property(name="sn", type="string", description="内部订单号 系统内部的订单号")
 * @SWG\Property(name="status", type="integer", description="支付状态（1-未支付, 2-已支付, 3-支付失败）")
 * @SWG\Property(name="type", type="integer", description="类型(1-定金支付, 2-租金支付, 3-账户充值支付")
 * @SWG\Property(name="updated_at", type="string", description="")
 */
class CustomerPayment extends BaseModel
{
    //
    protected $table = 'customer_payments';
    protected $guarded = ['id'];

    public $validateRules = [
        'amt' => 'required|numeric|min:1',
    ];

    public $validateMessages = [
        'amt.required' => "请选择一个金额",
        'amt.numeric' => '金额只能为数字',
        'amt.min' => '每次充值最低1元哦~',
    ];

    public function customer()
    {
        return $this->hasOne(Customer::class, 'id', 'customer_id');
    }

    protected static function boot()
    {
        $entity = new CustomerPayment();
        parent::boot(); // TODO: Change the autogenerated stub
        static::saving(function ($model) use ($entity) {
            event(new ModelCreatedEvent($model));
            $entity->updateAccountBalance($model);
        });
        static::saving(function ($model) use ($entity) {
            event(new ModelUpdatedEvent($model));
            $entity->updateAccountBalance($model);
        });
    }

    protected function updateAccountBalance($model){<commit_msg>流水创建&修改时 修改钱包数据<commit_after><?php

namespace App\Models;

use App\Events\ModelCreatedEvent;
use App\Events\ModelUpdatedEvent;
use Illuminate\Database\Eloquent\Model;
use App\Models\BaseModel;
use Illuminate\Support\Facades\Auth;

/**
 * model description
 * Class CustomerPayment
 * @package  App\Models
 *
 * @author  xrs
 * @SWG\Model(id="CustomerPayment")
 * @SWG\Property(name="amt", type="number", description="订单金额")
 * @SWG\Property(name="created_at", type="string", description="")
 * @SWG\Property(name="creator_id", type="integer", description="创建用户id")
 * @SWG\Property(name="customer_id", type="integer", description="customer id")
 * @SWG\Property(name="deleted_at", type="string", description="")
 * @SWG\Property(name="id", type="integer", description="")
 * @SWG\Property(name="modifier_id", type="integer", description="修改用户id")
 * @SWG\Property(name="outer_order_sn", type="string", description="外部订单号 支付宝|微信生成的订单号")
 * @SWG\Property(name="payment_channel", type="integer", description="支付渠道 1-微信支付 2-支付宝")
 * @SWG\Property(name="reference_id", type="integer", description="关联表id")
 * @SWG\Property(name="reference_type", type="string", description="关联表类型")
 * @SWG\Property(name="remark", type="string", description="备注")
 * @SWG\Property(name="sn", type="string", description="内部订单号 系统内部的订单号")
 * @SWG\Property(name="status", type="integer", description="支付状态（1-未支付, 2-已支付, 3-支付失败）")
 * @SWG\Property(name="type", type="integer", description="类型(1-定金支付, 2-租金支付, 3-账户充值支付")
 * @SWG\Property(name="updated_at", type="string", description="")
 */
class CustomerPayment extends BaseModel
{
    //
    protected $table = 'customer_payments';
    protected $guarded = ['id'];

    public $validateRules = [
        'amt' => 'required|numeric|min:1',
    ];

    public $validateMessages = [
        'amt.required' => "请选择一个金额",
        'amt.numeric' => '金额只能为数字',
        'amt.min' => '每次充值最低1元哦~',
    ];

    public function customer()
    {
        return $this->hasOne(Customer::class, 'id', 'customer_id');
    }

    protected static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub
        static::saving(function ($model) {
            event(new ModelCreatedEvent($model));
            $model->updateAccountBalance($model);
        });
        static::saving(function ($model) {
            event(new ModelUpdatedEvent($model));
            $model->updateAccountBalance($model);
        });
    }

    protected function updateAccountBalance($model)
    {
{'fraction_non_alphanumeric': 0.18185388845247447, 'fraction_numerical': 0.003927729772191673, 'mean_word_length': 4.578313253012048, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '751738', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1815, 'n_words': 269}