<?php


namespace App\Http\logic\admin;


use Illuminate\Support\Facades\DB;

class AccountsRecordLogic
{
    /**
     * 添加操作记录 - 提现 / 充值
     * @param int $id 订单ID
     * @param int $before_state 提现前状态
     * @param int $after_state 提现后状态
     * @param string $remarks 备注
     * @param int $admin_id 操作人ID
     * @param int $type 类型 1提现 2充值
     * @return bool
     */
    public function create_record($id, $before_state, $after_state, $remarks, $admin_id, $type)
    {
        $first = DB::table('QPAccountsDB.dbo.AccountsRecord')->where('RecordID',$id)->first();
        $data = [
            'RecordID' => $id,
            'before_state' => $before_state,
            'after_state' => $after_state,
            'admin_id' => $admin_id,
            'create_at' => date('Y-m-d H:i:s'),
            'update_at' => date('Y-m-d H:i:s'),
            'type' => $type,
        ];
        !empty($remarks) && $data['remarks'] = $remarks;

        $bool = DB::connection('write')->table('QPAccountsDB.dbo.AccountsRecord')->updateOrInsert(['RecordID' => $id, 'type' => $type], $data);

    }
}
