common.php
6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?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;
}