common.php 6.2 KB
<?php
/*
 * 获取会员默认价格
 */
function get_vip_price_default($money)
{
    return $money * config('site.vip_price_default');
}

/*
 * 获取员工默认价格
 */
function get_staff_price_default($money)
{
    return $money * config('site.staff_price_default');
}

/*
 * 获取代理默认价格
 */
function get_agency_price_default($money)
{
    return $money * config('site.agency_price_default');
}

/*
 * 获取会员返利
 */
function get_vip_rebate($money)
{
    return floor(($money * config('site.vip_rebate'))*10)/10;
}

/*
 * 获取员工返利
 */
function get_staff_rebate($money)
{
    return floor(($money * config('site.staff_rebate'))*10)/10;
}

/*
 * 获取代理返利
 */
function get_agency_rebate($money)
{
    return floor(($money * config('site.agency_rebate'))*10)/10;
}

/*
 * 获取返利
 */
function get_rebate($money, $user_type)
{
    switch ($user_type) {
        case 2:
            $rebate = get_vip_rebate($money);
            break;
        case 3:
            $rebate = get_staff_rebate($money);
            break;
        case 4:
            $rebate = get_agency_rebate($money);
            break;
    }
    return $rebate;
}

/*
 * 根据商品状态和用户身份获取最终价格
 */
function get_price($arr)
{
    //会员特价
    if (!empty($arr['is_vip_price']) && $arr['is_vip_price'] == 1 && $arr['user_type'] == 2) return $arr['vip_price'];
    //团购价格
    if (!empty($arr['is_group']) && $arr['is_group'] == 1 && $arr['user_type'] == 1) return $arr['group_price'];
    if (!empty($arr['is_group']) && $arr['is_group'] == 1 && $arr['user_type'] == 2) return get_vip_price_default($arr['group_price']);
    if (!empty($arr['is_group']) && $arr['is_group'] == 1 && $arr['user_type'] == 3) return get_staff_price_default($arr['group_price']);
    if (!empty($arr['is_group']) && $arr['is_group'] == 1 && $arr['user_type'] == 4) return get_agency_price_default($arr['group_price']);

    //代理基础价
    if ($arr['user_type'] == 4) {
        return get_agency_price_default($arr['goods_price']);
    } elseif ($arr['user_type'] == 3) {
        //员工基础价
        return get_staff_price_default($arr['goods_price']);
    } elseif ($arr['user_type'] == 2) {
        //会员基础价
        return get_vip_price_default($arr['goods_price']);
    }
    //原价
    return $arr['goods_price'];
}

/*
 * 根据商品状态和用户身份获取折扣价
 */
function get_discount_price($arr)
{
    //会员特价
    if (!empty($arr['is_vip_price']) && $arr['is_vip_price'] == 1 && $arr['user_type'] == 2) return $arr['goods_price'] - $arr['vip_price'];
    //团购价格
    if (!empty($arr['is_group']) && $arr['is_group'] == 1 && $arr['user_type'] == 2) return $arr['group_price'] - get_vip_price_default($arr['group_price']);
    if (!empty($arr['is_group']) && $arr['is_group'] == 1 && $arr['user_type'] == 3) return $arr['group_price'] - get_staff_price_default($arr['group_price']);
    if (!empty($arr['is_group']) && $arr['is_group'] == 1 && $arr['user_type'] == 4) return $arr['group_price'] - get_agency_price_default($arr['group_price']);
    //代理基础价折扣
    if ($arr['user_type'] == 4) {
        return $arr['goods_price'] - get_agency_price_default($arr['goods_price']);
    } elseif ($arr['user_type'] == 3) {
        //员工基础价折扣
        return $arr['goods_price'] - get_staff_price_default($arr['goods_price']);
    } elseif ($arr['user_type'] == 2) {
        //会员基础价折扣
        return $arr['goods_price'] - get_vip_price_default($arr['goods_price']);
    }
    //原价
    return 0;
}

/**
 * 期间日期
 * @param $startDate
 * @param $endDate
 * @return array
 */
function period_date($startDate, $endDate)
{
    $startTime = strtotime($startDate);
    $endTime = strtotime($endDate);
    $arr = array();
    $i = 0;
    while ($startTime <= $endTime) {
        $arr[$i]['date'] = date('m-d', $startTime) . '/' . get_week(date('Y-m-d', $startTime));
        $arr[$i]['week'] = date('w', $startTime);
        $startTime = strtotime('+1 day', $startTime);
        $i += 1;
    }
    return $arr;
}

/**
 * 根据日期返回星期
 * @param $date string 2020-4-22
 * @return  string
 */
function get_week($date)
{
    $weekArr = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
    return $weekArr[date("w", strtotime($date))];
}

/**
 * 获取惟一订单号
 * @return string
 */
function get_order_num()
{
    return date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}


function setArr($data)
{
    $goodsDepotList = [];
    foreach ($data as $k => $v) {
        foreach ($v as $key => $item) {
            $goodsDepotList[] = $item;
        }
    }
    $new_arr = [];
    foreach ($goodsDepotList as $k => $goodsDepot) {
        $tmp = $goodsDepot['area_id'];
        $new_arr[$tmp][$k] = $goodsDepot;
    }
    return $new_arr;
}

/**
 * 快递100查询物流轨迹
 * @param $code
 * @param $company
 * @return mixed
 */
function kuaidi100_query($code,$company){
    require_once EXTEND_PATH . 'kuaidi100/query.php';
    $sendAPI = new \synQuery($code,$company);
    $return = $sendAPI->query();
    return $return;
}

function wpjam_array_push($array, $data=null, $key=false){
    $data  = (array)$data;
    $offset  = ($key===false)?false:array_search($key, array_keys($array));
    $offset  = ($offset)?$offset:false;
    if($offset){
        return array_merge(
            array_slice($array, 0, $offset),
            $data,
            array_slice($array, $offset)
        );
    }else{  // 没指定 $key 或者找不到,就直接加到末尾
        return array_merge($array, $data);
    }
}

function days_in_month($month, $year) {
    // calculate number of days in a month
    return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
}

    function send_sms($data){
        //todo 短信账号密码
        require_once EXTEND_PATH . 'nsms/nsms.php';
        $url 		= "https://api.mix2.zthysms.com/v2/sendSms";
        $username 	= 'EMPmarket';
        $password 	= 'WH654XKZ';
        $sendAPI = new \sendAPI($url, $username, $password);
        $sendAPI->data = $data;/*初始化数据包*/
        $return = $sendAPI->sendSMS('POST');
        return $return;
    }