GuanYiCloud.php
9.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<?php
/**
* Created by PhpStorm.
* User: 86132
* Date: 2020/12/1
* Time: 14:03
*/
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
/**
* 管易云API
*/
class GuanYiCloud extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
//获取店铺信息
function getShops()
{
$data = array();
$data['appkey'] = APPKEY;
$data['sessionkey'] = SESSIONKEY;
$data['method'] = 'gy.erp.shop.get';
$data['page_no'] = '1';
$data['page_size'] = '100';
$data['sign'] = $this->sign($data, SECRET);
$this->success('成功', json_decode($this->mycurl(URL, $data)));
}
// 会员查询
function getVip($code)
{
$data = array();
$data['appkey'] = APPKEY;
$data['sessionkey'] = SESSIONKEY;
$data['method'] = 'gy.erp.vip.get';
$data['code'] = $code;
$data['sign'] = $this->sign($data, SECRET);
$Rult = json_decode(json_encode(json_decode($this->mycurl(URL, $data))), true);
return $Rult['total'];
}
// 会员新增
function addVip($UnionID, $Nickname)
{
$data = array();
$data['appkey'] = APPKEY;
$data['sessionkey'] = SESSIONKEY;
$data['method'] = 'gy.erp.vip.add';
//会员代码
$data['code'] = $UnionID;
//会员名称
$data['name'] = $Nickname;
//所属店铺
$data['shop_code'] = 'ZCZXCX';
//地址列表
$receive_infos = array();
$receive_infos[] = array(
//名称
'name' => '地址',
//收货人
'receiver' => $Nickname,
//收获手机
'mobile' => 18888888888,
//收货详细地址
'address' => '中国'
);
$data['receive_infos'] = $receive_infos;
$data['sign'] = $this->sign($data, SECRET);
$Rult = json_decode(json_encode(json_decode($this->mycurl(URL, $data))), true);
if ($Rult['success'] == false) {
$this->error('授权网络超时');
}
}
//获取仓库信息
function getWarehouses()
{
$data = array();
$data['appkey'] = APPKEY;
$data['sessionkey'] = SESSIONKEY;
$data['method'] = 'gy.erp.warehouse.get';
$data['page_no'] = '1';
$data['page_size'] = '10';
// $data['code'] = '001';
$data['sign'] = $this->sign($data, SECRET);
$this->success('成功', json_decode($this->mycurl(URL, $data)));
}
// 商品查询
function getGoods()
{
$data = array();
$data['appkey'] = APPKEY;
$data['sessionkey'] = SESSIONKEY;
$data['method'] = 'gy.erp.items.get';
$data['page_no'] = '1';
$data['page_size'] = '10';
// $data['code'] = 'ZZLN000005';
$data['sign'] = $this->sign($data, SECRET);
$this->success('成功', json_decode($this->mycurl(URL, $data)));
}
//获取订单 $OrderSn 平台单号
public function getOrders($OrderSn)
{
$data = array();
$data['appkey'] = APPKEY;
$data['sessionkey'] = SESSIONKEY;
$data['method'] = 'gy.erp.trade.get';
$data['platform_code'] = $OrderSn;
// $date['receiver_mobile']='15928552965';
$data['sign'] = $this->sign($data, SECRET);
$Array = json_decode(json_encode(json_decode($this->mycurl(URL, $data))), true);
//验证
if (empty($Array['orders'])) {
$this->error('获取订单失败:平台单号' . $OrderSn);
}
$delivery_state = $Array['orders'][0]['delivery_state'];
$refund = $Array['orders'][0]['details'][0]['refund'];
$platform_code = $Array['orders'][0]['platform_code'];
if (!empty($Array['orders'][0]['deliverys'])) {
$express_name = $Array['orders'][0]['deliverys'][0]['express_name'];
$express_code = $Array['orders'][0]['deliverys'][0]['express_code'];
$mail_no = $Array['orders'][0]['deliverys'][0]['mail_no'];
} else {
$express_name = '';
$express_code = '';
$mail_no = '';
}
$Return = [
//发货状态 0-未发货//1-部分发货//2-全部发货
'delivery_state' => $delivery_state,
//平台单号
'platform_code' => $platform_code,
//快递公司名称
'express_name' => $express_name,
//快递公司代码
'express_code' => $express_code,
//快递单号
'mail_no' => $mail_no
];
$Json = json_encode($Return);
return $Json;
}
//新增订单
function addOrder($OrderSn, $OrderTime, $PayTime, $UnionID, $Name, $Mobile, $Address, $Province, $City, $District, $details, $Money, $PayOrder)
{
$data = array();
$data['appkey'] = APPKEY;
$data['sessionkey'] = SESSIONKEY;
$data['method'] = 'gy.erp.trade.add';
//订单类型 //Sales-销售订单//Return-换货订单//Charge-费用订单//Delivery-补发货订单//Invoice-补发票订单
$data['order_type_code'] = 'Sales';
//退款状态 //0:未退款//1:退款完成//2:退款中
$data['refund'] = 0;
$data['oid'] = $OrderSn;
//店铺代码
$data['shop_code'] = 'ZCZXCX';
//平台单号
$data['platform_code'] = $OrderSn;
//下单时间
$data['deal_datetime'] = $OrderTime;
//支付时间
$data['pay_datetime'] = $PayTime;
//会员代码
$data['vip_code'] = $UnionID;
//买家留言
$data['buyer_memo'] = '';
//收货人
$data['receiver_name'] = $Name;
$data['receiver_mobile'] = $Mobile;
$data['receiver_address'] = $Address;
$data['receiver_province'] = $Province;
$data['receiver_city'] = $City;
$data['receiver_district'] = $District;
$data['details'] = $details;
$payments = array();
$payments[] = array(
//支付放视
'pay_type_code' => 'WechatPay',
//支付金额
'payment' => $Money,
//交易号
'pay_code' => $PayOrder,
//支付时间
'paytime' => $PayTime
);
$data['payments'] = $payments;
$invoices = array();
$invoices[] = array(
//发票部分
'invoice_type' => 1,
'invoice_title' => '个人',
);
$data['invoices'] = $invoices;
$data['sign'] = $this->sign($data, SECRET);
$Rult = json_decode(json_encode(json_decode($this->mycurl(URL, $data))), true);
if ($Rult['success'] == false) {
$this->error('失败');
}
}
/*Config*/
function mycurl($url, $data)
{
$data_string = $this->json_encode_ch($data);
$data_string = urlencode($data_string);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type:text/json;charset=utf-8',
'Content-Length:' . strlen($data_string)
));
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
function sign($data, $secret)
{
if (empty($data)) {
return "";
}
unset($data['sign']); //可选,具体看传参
$data = $this->json_encode_ch($data);
$sign = strtoupper(md5($secret . $data . $secret));
return $sign;
}
function json_encode_ch($arr)
{
return urldecode(json_encode($this->url_encode_arr($arr)));
}
function url_encode_arr($arr)
{
if (is_array($arr)) {
foreach ($arr as $k => $v) {
$arr[$k] = $this->url_encode_arr($v);
}
} elseif (!is_numeric($arr) && !is_bool($arr)) {
$arr = urlencode($arr);
}
return $arr;
}
//获取订单oid
public function GetOrderOid($OrderSn)
{
$data = array();
$data['appkey'] = APPKEY;
$data['sessionkey'] = SESSIONKEY;
$data['method'] = 'gy.erp.trade.get';
$data['platform_code'] = $OrderSn;
// $date['receiver_mobile']='15928552965';
$data['sign'] = $this->sign($data, SECRET);
$Array = json_decode(json_encode(json_decode($this->mycurl(URL, $data))), true);
//验证
if (empty($Array['orders'])) {
$this->error('获取订单失败:平台单号' . $OrderSn);
}
return $Array['orders'];
}
//获取订单oid
public function OrderUpdate($OrderSn,$Oid)
{
$data = array();
$data['appkey'] = APPKEY;
$data['sessionkey'] = SESSIONKEY;
$data['method'] = 'gy.erp.trade.refund.update';
$data['tid'] = $OrderSn;
$data['oid'] = $Oid;
$data['refund_state'] = 2;
// $date['receiver_mobile']='15928552965';
$data['sign'] = $this->sign($data, SECRET);
$Array = json_decode(json_encode(json_decode($this->mycurl(URL, $data))), true);
if ($Array['success'] == false) {
$this->error('订单推送失败');
}
}
}