<?php

namespace app\admin\model;

use think\Model;

class UserMoneyLog extends Model
{

    // 表名
    protected $name = 'user_money_log';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;

    public static function insertData(
        $user_id,
        $money,
        $type,
        $memo = '',
        $logs_id = null,
        $order_id = null,
        $before,
        $after
    ){
        $data = array(
            'user_id' => $user_id,
            'money' => abs($money),
            'heatos' => $money >= 0 ? 1 : -1,
            'memo' => $memo,
            'createtime' => time(),
//            'create_ip' => get_client_ip(),
            'type' => $type,
            'logs_id' => $logs_id,
            'order_id' => $order_id,
            'before' => $before,
            'after' => $after,
        );
        return self::create($data)->getLastInsID();
    }
}
