审查视图

application/api/common.php 6.2 KB
王晓刚 authored
1
<?php
耿培杰 authored
2 3 4
/*
 * 获取会员默认价格
 */
耿培杰 authored
5 6
function get_vip_price_default($money)
{
耿培杰 authored
7
    return $money * config('site.vip_price_default');
耿培杰 authored
8 9 10
}

/*
耿培杰 authored
11
 * 获取员工默认价格
耿培杰 authored
12
 */
耿培杰 authored
13 14
function get_staff_price_default($money)
{
耿培杰 authored
15
    return $money * config('site.staff_price_default');
耿培杰 authored
16 17 18 19 20 21 22
}

/*
 * 获取代理默认价格
 */
function get_agency_price_default($money)
{
耿培杰 authored
23
    return $money * config('site.agency_price_default');
耿培杰 authored
24 25 26 27 28 29 30
}

/*
 * 获取会员返利
 */
function get_vip_rebate($money)
{
耿培杰 authored
31
    return floor(($money * config('site.vip_rebate'))*10)/10;
耿培杰 authored
32 33 34 35 36 37 38
}

/*
 * 获取员工返利
 */
function get_staff_rebate($money)
{
耿培杰 authored
39
    return floor(($money * config('site.staff_rebate'))*10)/10;
耿培杰 authored
40 41 42 43 44 45 46
}

/*
 * 获取代理返利
 */
function get_agency_rebate($money)
{
耿培杰 authored
47
    return floor(($money * config('site.agency_rebate'))*10)/10;
耿培杰 authored
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
}

/*
 * 获取返利
 */
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;
耿培杰 authored
67 68 69 70 71
}

/*
 * 根据商品状态和用户身份获取最终价格
 */
耿培杰 authored
72 73
function get_price($arr)
{
耿培杰 authored
74
    //会员特价
耿培杰 authored
75
    if (!empty($arr['is_vip_price']) && $arr['is_vip_price'] == 1 && $arr['user_type'] == 2) return $arr['vip_price'];
耿培杰 authored
76
    //团购价格
耿培杰 authored
77
    if (!empty($arr['is_group']) && $arr['is_group'] == 1 && $arr['user_type'] == 1) return $arr['group_price'];
耿培杰 authored
78 79 80 81
    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']);
耿培杰 authored
82 83 84 85 86
    //代理基础价
    if ($arr['user_type'] == 4) {
        return get_agency_price_default($arr['goods_price']);
    } elseif ($arr['user_type'] == 3) {
        //员工基础价
耿培杰 authored
87
        return get_staff_price_default($arr['goods_price']);
耿培杰 authored
88 89
    } elseif ($arr['user_type'] == 2) {
        //会员基础价
耿培杰 authored
90 91 92 93 94
        return get_vip_price_default($arr['goods_price']);
    }
    //原价
    return $arr['goods_price'];
}
耿培杰 authored
95
耿培杰 authored
96 97 98
/*
 * 根据商品状态和用户身份获取折扣价
 */
耿培杰 authored
99 100
function get_discount_price($arr)
{
耿培杰 authored
101
    //会员特价
耿培杰 authored
102
    if (!empty($arr['is_vip_price']) && $arr['is_vip_price'] == 1 && $arr['user_type'] == 2) return $arr['goods_price'] - $arr['vip_price'];
耿培杰 authored
103 104 105 106
    //团购价格
    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']);
耿培杰 authored
107 108
    //代理基础价折扣
    if ($arr['user_type'] == 4) {
耿培杰 authored
109
        return $arr['goods_price'] - get_agency_price_default($arr['goods_price']);
耿培杰 authored
110 111
    } elseif ($arr['user_type'] == 3) {
        //员工基础价折扣
耿培杰 authored
112
        return $arr['goods_price'] - get_staff_price_default($arr['goods_price']);
耿培杰 authored
113 114
    } elseif ($arr['user_type'] == 2) {
        //会员基础价折扣
耿培杰 authored
115 116 117 118 119 120 121 122 123 124 125 126
        return $arr['goods_price'] - get_vip_price_default($arr['goods_price']);
    }
    //原价
    return 0;
}

/**
 * 期间日期
 * @param $startDate
 * @param $endDate
 * @return array
 */
耿培杰 authored
127 128
function period_date($startDate, $endDate)
{
耿培杰 authored
129 130 131 132
    $startTime = strtotime($startDate);
    $endTime = strtotime($endDate);
    $arr = array();
    $i = 0;
耿培杰 authored
133 134
    while ($startTime <= $endTime) {
        $arr[$i]['date'] = date('m-d', $startTime) . '/' . get_week(date('Y-m-d', $startTime));
耿培杰 authored
135 136
        $arr[$i]['week'] = date('w', $startTime);
        $startTime = strtotime('+1 day', $startTime);
耿培杰 authored
137
        $i += 1;
耿培杰 authored
138 139 140 141 142 143 144 145 146
    }
    return $arr;
}

/**
 * 根据日期返回星期
 * @param $date string 2020-4-22
 * @return  string
 */
耿培杰 authored
147 148 149 150
function get_week($date)
{
    $weekArr = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
    return $weekArr[date("w", strtotime($date))];
耿培杰 authored
151 152 153 154 155 156 157 158 159
}

/**
 * 获取惟一订单号
 * @return string
 */
function get_order_num()
{
    return date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
耿培杰 authored
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
}


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;
耿培杰 authored
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
}

/**
 * 快递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);
    }
耿培杰 authored
205 206
}
耿培杰 authored
207 208 209
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);
耿培杰 authored
210 211 212 213 214 215 216 217 218 219 220 221 222
}

    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;
    }