Sign.php
13.5 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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<?php
/**
* tpshop
* ============================================================================
* * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* 2015-11-21
*/
namespace app\mobile\controller;
use app\home\logic\UsersLogic;
use app\home\model\Message;
use think\Cookie;
use think\Page;
use think\Request;
use think\Session;
use think\Verify;
use think\db;
use think\Cache;
use qcloudcos\Conf;
use qcloudcos\Myqcloudcos;
use think\Controller;
class Sign extends MobileBase
{
public $user_id = 0;
public $user = array();
/**
* 析构流函数
*/
public function __construct()
{
parent::__construct();
if (session('?user')) {
$user = session('user');
$user = M('users')->where("user_id", $user['user_id'])->find();
session('user', $user); //覆盖session 中的 user
$this->user = $user;
$this->user_id = $user['user_id'];
$this->assign('user', $user); //存储用户信息
$nologin = array(
'getstoid',
);
if ($this->user_id == 0) {
$this->error('请先登录', U('Mobile/User/login', array('stoid' => getMobileStoId())));
}
} else {
$uid = Cookie::get('user_id');
if ($uid) {
$user = M('users')->where("user_id", $uid)->where("store_id", getMobileStoId())->find();
session('user', $user); //覆盖session 中的 user
$this->user = $user;
$this->user_id = $user['user_id'];
$this->assign('user', $user); //存储用户信息
}
}
// if (!$this->user_id) {
// $this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId())));
// exit;
// }
}
//培训签到
public function index()
{
$getaccdb = strtolower(urldecode(urldecode(I('accdb'))));
$getnumber = strtolower(urldecode(urldecode(I('number'))));
$getdate = strtolower(urldecode(urldecode(I('date'))));
$getkey = strtolower(I('key'));
if (empty($getaccdb) || empty($getnumber) || empty($getdate) || empty($getkey)) {
$this->assign('msg', "签到失败,参数有误!");//
return $this->fetch();
}
$fieldstr = "accdb=" . $getaccdb . "&number=" . $getnumber . "&date=" . $getdate . "&key=" . getErpKey();
//如果key不相等,报错
if ($getkey != md5($fieldstr)) {
$this->assign('msg', "签到失败!");//
return $this->fetch();
}
$getopenid = $this->user["openid"];
$sto = tpCache('shop_info', getMobileStoId());
$store_logo = $sto['store_logo'];//商家LOGO
$head_pic = $this->user["head_pic"];//会员头像
$head_pic=str_replace('/132','/0',$head_pic);
$api_token = $sto['api_token'];
$this->assign('store_logo', $store_logo);//商家logo
$this->assign('head_pic', $head_pic);//会员头像
if ($api_token) {
$data = array(
'number' => $getnumber,//单据
'key' => $getdate,//单据日期
'openid' => $getopenid
);//新增或者编辑时存放的数据()
$vipinfo = getApiData('wxd.train.signin', $api_token, $data);
mlog($vipinfo, "signindex");
if (empty($vipinfo)) {
$this->assign('msg', "签到失败!");//
} else {
$vipinfo = json_decode($vipinfo, true);
if ($vipinfo['code'] != 1 || empty($vipinfo['data'])) {
$this->assign('msg', "签到失败!");//
$this->assign('msg1', $vipinfo['msg']);//
} else {
$this->assign('msg', "签到成功!");//
$this->assign('msg1', "谢谢您的到临!");//
}
if ($vipinfo['data'] && $vipinfo['count']) {
$opencount = $vipinfo['count'];
$openlist = "";
foreach ($vipinfo['data'] as $k => $vo) {
if ($vo['openid']) {
if ($openlist) {
$openlist .= "," . $vo['openid'];
} else {
$openlist .= $vo['openid'];
}
}
}
$where['openid'] = array('in', $openlist);
$res = M("users")->where('store_id', getMobileStoId())
->where($where)->order('reg_time desc')
->field('nickname,head_pic')->select();
$this->assign('opencount', $opencount);//openlist
$this->assign('openlist', $res);//openlist
}
}
}
return $this->fetch();
}
//员工绑定
public function staffbinding()
{
$getstoid = strtolower(urldecode(urldecode(I('stoid'))));
$getusercode = strtolower(urldecode(urldecode(I('usercode'))));
$getkey = strtolower(I('key'));
// $getstoid="1";
// $getusercode="admin";
// $getkey="a1e42219f7d651c8e8e09f331723df7e";
if (empty($getstoid) || empty($getusercode) || empty($getkey)) {
$this->assign('msg', "绑定失败!");//
return $this->fetch();
}
$fieldstr = "stoid=" . $getstoid . "&usercode=" . $getusercode . "&key=" . getErpKey();
//如果key不相等,报错
if ($getkey != md5($fieldstr)) {
$this->assign('msg', "绑定失败!");//
return $this->fetch();
}
$getopenid = $this->user["openid"];
$sto = tpCache('shop_info', $getstoid);
$store_logo = $sto['store_logo'];//商家LOGO
$head_pic = $this->user["head_pic"];//会员头像
$head_pic=str_replace('/132','/0',$head_pic);
$api_token = $sto['api_token'];
$this->assign('store_logo', $store_logo);//商家logo
$this->assign('head_pic', $head_pic);//会员头像
if ($api_token) {
$data = array(
'usercode' => $getusercode,//员工编号
'openid' => $getopenid
);//新增或者编辑时存放的数据()
$vipinfo = getApiData('wxdoa.staff.binding', $api_token, $data);
// echo $vipinfo;die;
// mlog($vipinfo, "staffbinding");
if (empty($vipinfo)) {
$this->assign('msg', "绑定失败!");//
} else {
$vipinfo = json_decode($vipinfo, true);
if ($vipinfo['code'] != 1) {
$this->assign('msg', "绑定失败!");//
$this->assign('msg1', $vipinfo['msg']);//
} else {
$this->assign('msg', "绑定成功!");//
}
}
}
return $this->fetch();
}
//OA登录
public function codelogin()
{
$getstoid = strtolower(urldecode(urldecode(I('stoid'))));
$getaccdb = strtolower(urldecode(urldecode(I('accdb'))));
$getcodekey = strtolower(I('codekey'));
$getkey = strtolower(I('key'));
//$getaccdb="1";
// $getusercode="admin";
// $getkey="a1e42219f7d651c8e8e09f331723df7e";
$this->assign('stoid', $getstoid);//
if (empty($getcodekey) || empty($getaccdb) || empty($getkey)) {
$this->assign('msg', "授权失败!");//
return $this->fetch();
}
$fieldstr = "accdb=" . $getaccdb . "&codekey=" . $getcodekey . "&key=" . getErpKey();
//如果key不相等,报错
if ($getkey != md5($fieldstr)) {
$this->assign('msg', "授权失败!");//
return $this->fetch();
}
$getopenid = $this->user["openid"];
$sto = tpCache('shop_info', $getstoid);
$store_logo = $sto['store_logo'];//商家LOGO
$head_pic = $this->user["head_pic"];//会员头像
$head_pic=str_replace('/132','/0',$head_pic);
$api_token = $sto['api_token'];
$this->assign('store_logo', $store_logo);//商家logo
$this->assign('head_pic', $head_pic);//会员头像
if ($api_token) {
$data = array(
'accdb' => $getaccdb,//账套
'codekey' => $getcodekey,//CODEKEY
'openid' => $getopenid
);//新增或者编辑时存放的数据()
$vipinfo = getApiData('wxdoa.code.login', $api_token, $data);
mlog($vipinfo, "codelogin");
if (empty($vipinfo)) {
$this->assign('msg', "授权失败!");//
} else {
$vipinfo = json_decode($vipinfo, true);
if ($vipinfo['code'] != 1) {
$this->assign('msg', "授权失败!");//
$this->assign('msg1', $vipinfo['msg']);//
} else {
$this->assign('msg', "授权成功!");//
}
}
}
return $this->fetch();
}
//万信达助手(微信端)
public function wxdzsopenid()
{
$this->redirect('http://mshop.jmhcn.com/XinDaHelper/WeiXin/wxd_index.aspx?WX_OpenId='.session('user')['openid']);
}
//商家客服微信绑定
public function store_binding()
{
$getstoid = urldecode(urldecode(I('stoid')));
$getadminid = urldecode(urldecode(I('adminid')));
$rndnum = urldecode(urldecode(I('rndnum')));
$getkey = I('bindkey');
if (empty($getstoid) || empty($getadminid) || empty($rndnum) || empty($getkey)) {
$this->assign('msg', "绑定失败1!");//
return $this->fetch();
}
$fieldstr = "stoid=" . $getstoid . "&adminid=" . $getadminid . "&rndnum=" . $rndnum . "&key=" . getErpKey();
//如果key不相等,报错
if ($getkey != md5($fieldstr)) {
$this->assign('msg', "绑定失败2!");//
return $this->fetch();
}
$getopenid = $this->user["openid"];
$sto = tpCache('shop_info', $getstoid);
$store_logo = $sto['store_logo'];//商家LOGO
$head_pic = $this->user["head_pic"];//会员头像
$head_pic=str_replace('/132','/0',$head_pic);
$nickname = $this->user["nickname"];//会员昵称
$this->assign('store_logo', $store_logo);//商家logo
$this->assign('head_pic', $head_pic);//会员头像
$this->assign('nickname', $nickname);//会员昵称
$this->assign('stoid', $getstoid);//
if ($getopenid) {
$vipinfo=M('admin')->where(array('store_id'=>$getstoid,'admin_id'=>$getadminid,'is_custom_service'=>1))->find();
if (empty($vipinfo))
{
$this->assign('msg', "绑定失败3!");//
}
else
{
$update['openid_type']=1;
$update['admin_openid']=$getopenid;
$update['openid_nick']=$nickname; //昵称也存储
M('admin')->where(array('store_id'=>$getstoid,'admin_id'=>$getadminid,'is_custom_service'=>1))->save($update);
//admin的聊天使用
$admin_login=I('admin_login');
$this->assign('admin_login', $admin_login);//
$this->assign('msg', "绑定成功!");//
}
}
return $this->fetch();
}
//商家客服微信登陆
public function store_wxlogin()
{
$getstoid = urldecode(urldecode(I('stoid')));
$getopenid = $this->user["openid"];
$sto = tpCache('shop_info', $getstoid);
$store_logo = $sto['store_logo'];//商家LOGO
$head_pic = $this->user["head_pic"];//会员头像
$head_pic=str_replace('/132','/0',$head_pic);
$this->assign('store_logo', $store_logo);//商家logo
$this->assign('head_pic', $head_pic);//会员头像
$this->assign('stoid', $getstoid);//
if ($getopenid) {
$res=M('admin')->alias('a')
->join('store b','a.store_id=b.store_id','left')
->field('a.*,b.reg_mobile')
->where(array('a.store_id'=>$getstoid,'a.admin_openid'=>$getopenid,'a.openid_type'=>1,'a.is_custom_service'=>1))->find();
if (empty($res)) {
$this->assign('msg', "登陆失败!");//
} else {
if ($res['ERPId'])
{
$fieldstr = "ERPId=" . $res['ERPId'] . "&ERPUser=" . $res['ERPUser'];
}
else{
$fieldstr = "mobile=" . $res['reg_mobile'] . "&ERPUser=" . $res['ERPUser'];
}
$gofieldstr = $fieldstr;
$fieldstr .= "&Key=" . getErpKey();
$fieldstr1 = strtolower($fieldstr);
$key = md5($fieldstr1);
$poststr = $gofieldstr . "&key=" . $key;
$poststr = urlencode($poststr);
$this->redirect("/admin/index/get_post/?url=".$poststr."&ismobile=1");
}
}
return $this->fetch();
}
}