<?php
/**
 * Created by PhpStorm.
 * User: pc
 * Date: 2021/11/23
 * Time: 11:06
 */

namespace app\api\model;
use think\Model;
use think\Request;


class UsersDetailMoneyModel extends Model{



    // 表名
    protected $name = 'user_detail_money';


    public static function insertData(
        $user_id,
        $money,
        $type,
        $detail_type = 0,
        $intro = '',
        $logs_id = null,
        $order_type = null,
        $pay_way = null,
        $order_id = null,
        $status = 0,
        $remark = '',
        $admin_id = null,
        $create_time = '',
        $monthtime = ''
    ) {
        $user = UsersModel::getUserById($user_id);
        switch ($type) {
            case 1:
                $surplus_money = $user['commission'];
                break;
            case 2:
                $surplus_money = $user['agent_money'];
                break;
            default:
                $surplus_money = $user['money'];
                break;
        }
        $data = array(
            'user_id' => $user_id,
            'money' => abs($money),
            'heatos' => $money >= 0 ? 1 : -1,
            'intro' => $intro,
            'mothtime' => $monthtime ? $monthtime : date("Y-m", time()),
            'create_time' => $create_time ? $create_time : time(),
            'create_ip' => request()->ip(),
            'type' => $type,
            'detail_type' => $detail_type,
            'logs_id' => $logs_id,
            'order_type' => $order_type,
            'pay_way'   => $pay_way,
            'order_id' => $order_id,
            'status' => $status,
            'surplus_money' => $surplus_money,
            'recorded_time' =>   $status == 0 ? date('Y-m-d H:i:s', $create_time ? $create_time : time()) : null,
            'remark' => $remark,
            'admin_id' => $admin_id
        );
        return self::create($data);
    }
}