<?php

// 应用公共文件
use think\facade\Db;

if (!function_exists('getNewOrderId')) {
    /**
     * 生成订单唯一id
     * @param $uid 用户uid
     * @return string
     */
    function getNewOrderId()
    {
        list($msec, $sec) = explode(' ', microtime());
        $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
        $orderId = 'wx' . $msectime . mt_rand(10000, 99999);
        if (\app\models\auction\AuctionOrder::where('order_id', $orderId)) $orderId = 'wx' . $msectime . mt_rand(10000, 99999);
        return $orderId;
    }
}

function getDataFind($table,$where=[]){
    $data = Db::name($table)->where($where)->find();
    return $data;
}
//查找所有上级
function getParent($uid){
    //当前用户
    static $arr=[];
    //当前用户
    $member = getDataFind('user',array('uid'=>$uid));
    if ($member['spread_uid'] > 0){
        $parent = getDataFind('user',array('uid'=>$member['spread_uid']));

        $arr[]= $parent['uid'];

        getParent($parent['uid']);
    }
    return $arr;

}