<?php

namespace app\models\user;

use crmeb\basic\BaseModel;
use crmeb\traits\ModelTrait;

/**
 * TODO 会员等级Model
 * Class UserLevel
 * @package app\models\user
 */
class UserTransfer extends BaseModel
{
    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';
    use ModelTrait;
    /**
     * 生成订单唯一id
     * @param $uid 用户uid
     * @return string
     */
    public static function getNewOrderId()
    {
        list($msec, $sec) = explode(' ', microtime());
        $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
        $orderId = 'wx' . $msectime . mt_rand(10000, 99999);
        if (self::be(['order_id' => $orderId])) $orderId = 'wx' . $msectime . mt_rand(10000, 99999);
        return $orderId;
    }
    /**
     * 获取转账订单
     */
    public static function orderlist($where)
    {
        $model = new self;
        if(isset($where['data']) && $where['data'] !='') $model = $model->getModelTime($where,$model,"addtime");
        if(isset($where['paid']) && $where['paid'] >-1)  $model = $model->where('paid',$where['paid']);
        if(isset($where['key']) && $where['key'] !='') $model = $model->where('order_id','like',"%".$where['key']."%");
        if(isset($where['type']) && $where['type'] >-1)  $model = $model->where('type',$where['type']);
        $model = $model->order('id desc');
        return self::page($model, function ($v) {
            $v['user'] = User::where('uid',$v['uid'])->field('nickname,avatar')->find();
            $v['touser'] = User::where('uid',$v['touid'])->field('nickname,avatar')->find();
        }, $where);
    }
}