Userapi.php
17.7 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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
<?php
/**
* tpshop
* ============================================================================
* * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: IT宇宙人 2015-08-10 $
*/
namespace app\mobile\controller;
use think\Controller;
use think\Session;
use think\Db;
use think\Cookie;
use think\Page;
class Userapi extends Controller
{
public $user_id = 0;
public $user = array();
public function __construct()
{
parent::_initialize();
$sid = I('stoid');
if (session('?user')) {
$user = session('user');
unset($_SESSION['user']);
$user0 = M('users')->where("user_id", $user['user_id'])->where("store_id", $sid)->find();
session('user', $user0); //覆盖session 中的 user
$this->user = $user0;
$this->user_id = $user0['user_id'];
} else {
$usrid = Cookie::get('user_id');
if ($usrid) {
$user0 = M('users')->where("user_id", $usrid)->where("store_id", $sid)->find();
session('user', $user0); //覆盖session 中的 user
$this->user = $user0;
$this->user_id = $user0['user_id'];
}
}
}
//批量取消收藏
public function batchcancel_collect()
{
$sellist = I('sellist');
$getstoid = I('stoid');
if (empty($getstoid)) {
return json(array('code' => -1, 'msg' => '参数有误!'));
}
$user_id = $this->user_id;
if (empty($user_id)) {
return json(array('code' => -1, 'msg' => '用户异常!'));
}
$where = 'collect_id in (' . $sellist . ')';
$delinfo = M('goods_collect')->where("store_id", $getstoid)->where($where)->where(array('user_id' => $user_id))->delete();
if (empty($delinfo)) {
return json(['code' => -1, 'msg' => '删除成功!']);
}
return json(['code' => 0, 'msg' => '删除成功!']);
}
//修改默认物流
public function modi_def_exp_code()
{
$getshipping_code = I('shipping_code');
$getstoid = I('stoid');
if (empty($getstoid)) {
return json(array('code' => -1, 'msg' => '参数有误!'));
}
if (empty($getshipping_code)) {
return json(array('code' => -1, 'msg' => '请选择要设置的物流'));
}
$user_id = $this->user_id;
if (empty($user_id)) {
return json(array('code' => -1, 'msg' => '用户异常!'));
}
$shippinfo = M('store_shipping')->alias('a')->join('shipping b', 'a.shipping_id=b.shipping_id', 'left')->where(array('a.store_id' => $getstoid, 'b.shipping_code' => $getshipping_code, 'a.status' => 1))->find();
if (empty($shippinfo)) {
return json(array('code' => -1, 'msg' => '设置失败,该记录不存在!'));
}
$updatadata['def_exp_code'] = $getshipping_code;
$updateinfo = M('users')->where(array('store_id' => $getstoid, 'user_id' => $user_id))->save($updatadata);
return json(array('code' => 0, 'msg' => '设置成功!'));
}
//新人礼广告
public function new_people()
{
$user_id = I('user_id/d', 0);
$stoid = I('stoid/d', 0);
if (empty($user_id) || empty($stoid)) {
return json(array('code' => -1, 'msg' => '非法参数'));
}
$data["userId"] = $user_id;
$data["storeId"] = $stoid;
$newpeople = getApiData_mini("/api/weshop/marketing/newpeople/act/judge", $data, $stoid, 'GET', null, 1, 10);
$newpeoples = json_decode($newpeople, true);
if (empty($newpeoples))
{
return json(array('code' => -1, 'msg' => '网络繁忙'));
}
if ($newpeoples ['code'] != 0) {
return json(array('code' => -1, 'msg' => $newpeoples ['msg']));
}
return json($newpeoples );
}
/*新人弹窗*/
public function new_peolep_layui()
{
/* 判断新人礼包活动 海报弹窗接口判断*/
$user_id = I('user_id');
$stoid = I('stoid');
if (empty($user_id) || empty($stoid)) {
return json(array('code' => -1, 'msg' => '非法参数'));
}
$data["userId"] = $user_id;
$data["storeId"] = $stoid;
$poster_newpeople = getApiData_mini("/api/weshop/marketing/newpeople/act/bound/judge", $data, $stoid, 'GET', null, 1, 10);
if (empty($poster_newpeople))
{
return json(array('code' => -1, 'msg' => '网络繁忙'));
}
return json_decode($poster_newpeople);
}
/* 生日营销图片显示*/
public function birthday_activities()
{
$user_id = I('user_id');
$id = I('stro_id');
$data["storeId"] = $id;
$data['userId'] = $user_id;
$birthday = getApiData_mini("/api/weshop/marketing/birthday/act/judge", $data, $id);
$birthday_s = json_decode($birthday, true);
if ($birthday_s['code'] != -1) {
$data = $birthday_s['data'];
$giftbagid = $data["giftbagid"];
$actId = $data['id'];
$actImg=QCLOUD_IMGURL.$data['actImg'];
return json(array('code' => 0, 'giftbagid' => $giftbagid, 'user_id' => $user_id, 'actId' => $actId, 'actType' => 4,'actImg'=>$actImg));
} else {
return json(array('code' => -1,));
}
}
/* 节日营销*/
public function festival_activity (){
$user_id = I('user_id');
$id = I('stro_id');
if (empty($user_id) || empty($id)) {
return json(array('code' => -1, 'msg' => '非法参数'));
}
$data["storeId"] = $id;
$data['userId'] = $user_id;
$birthday = getApiData_mini("/api/weshop/marketing/holiday/act/judge", $data, $id);
$birthday_s = json_decode($birthday, true);
if ($birthday_s['code'] != -1) {
$data_festival = $birthday_s['data'];
$giftbagid = $data_festival["gifBagId"];
$actId = $data_festival['id'];
$actBoundImg=QCLOUD_IMGURL.$data_festival['actBoundImg'];
$actImg=QCLOUD_IMGURL.$data_festival['actImg'];
return json(array('code' => 0, 'giftbagid' => $giftbagid, 'user_id' => $user_id, 'actId' => $actId, 'actType' => 3,'actBoundImg'=>$actBoundImg,"actImg"=>$actImg));
} else {
return json(array('code' => -1,));
}
}
//获取当个门店的线下库存
public function get_one_store()
{
$goods_id = I("goods_id");
$pick_id = I("pick_id");
$good = M("goods")->where("goods_id", $goods_id)->find(); //获取商品
$pick = M("pick_up")->where("pickup_id", $pick_id)->find(); //获取门店
$stoid = $good['store_id'];
$wdata['WareIds'] = urlencode($good['erpwareid']);
$wdata['StorageNos'] = urlencode($pick['pickup_no']);
$accdb = tpCache("shop_info.ERPId", $stoid);
mlog("获取线下库存:" . json_encode($wdata), "get_one_store/" . $stoid);
$rs = getApiData_java_p("api/erp/sto/storages/page", $accdb, $wdata, 1, 1);
mlog("获取线下库存:" . $rs, "get_one_store/" . $stoid);
if ($rs) {
$data = json_decode($rs, true);
$dt = $data['data'];
if (!empty($dt)) {
if ($dt['pageData']) {
//---线下库存判断预存是多少,组装map数组,快速查找---
$strq = 'select sum(out_qty) as sum0 from __PREFIX__erp_yqty where goods_id='
. $goods_id . ' and store_id=' . $stoid . ' and pickup_id=' . $pick_id;
$dd = Db::query($strq);
$allnum = $dt['pageData'][0]['CanOutQty'];
if ($dd) {
$yc_num = $dd[0]['sum0'];
$allnum = $allnum - $yc_num;
}
return json(["code" => 0, "data" => $allnum]);
}
}
return json(["code" => -1, "msg" => '未找到门店']);
} else {
return json(["code" => -1, "msg" => '未找到门店']);
}
}
//显示点击领取礼品
public function click_gift(){
$user_id = I('user_id');
$stoid = I('stoid');
$orderNumber=I('orderNumber');
//$data['orderNumber'] = $order_goods['order_id'];//商品订单号
$data['orderType'] =2;//评价类型 1=商城订单评价 2=美容师评价
$data['storeId'] = $stoid;//商家id
$data['userId'] = $user_id;//用户id
$data['orderNumber']=$orderNumber;
$is_ceremony = getApiData_mini("/api/weshop/marketing/comment/act/judge", $data, getMobileStoId, 'GET');
$ceremony_data = json_decode($is_ceremony, true);
$data_s=$ceremony_data ['data'];
if($ceremony_data['code']==0){
return json(array('code' => 0,'gifbagid'=>$data_s['gifbagid'],'id'=>$data_s['id']));
}else{
return json(array('code' => -1));
}
}
public function storespage()
{
mlog("1","storespage/".$id);
$pagenum = 10;//C('PAGESIZE'); //每页显示数
$p = I('p/d', 1);
$id = getMobileStoId();
$lx = I('lx');
$ly = I('ly');
$where = "";
$getkey = I('key');
$storetype = I('storetype');
if ($getkey) {
$where['pickup_name'] = array('like', '%' . htmlspecialchars($getkey) . '%');
}
if ($storetype) {
$where['category_id'] = $storetype;
}
$count = M('pick_up')->where($where)->count();
$Page = $pager = new Page($count,$pagenum);
$list = M('pick_up')
->where("store_id=" . $id . " and isstop=0 ")
->where($where)
->field('*,st_distance (POINT (lat,lon),POINT('.$ly.','.$lx.')) * 111195 AS distance')
->order('distance asc,pickup_id asc')
->limit($Page->firstRow.','.$Page->listRows)->select();
$list_str = M('pick_up')
->where("store_id=" . $id . " and isstop=0 ")
->where($where)
->field('*,st_distance (POINT (lat,lon),POINT('.$ly.','.$lx.')) * 111195 AS distance')
->order('distance asc,pickup_id asc')->fetchSql(true)
->limit($Page->firstRow.','.$Page->listRows)->select();
mlog($list_str,"storespage/".$id);
if (empty($list)) {
$jsonlist['state'] = "0";
$jsonlist['msg'] = '找不到相数据';
return json($jsonlist);
}
foreach ($list as $k => $v) {
$list[$k]['address'] = $v['fulladdress'];
}
$jsonlist['state'] = "1";
$jsonlist['msg'] = '成功';
$jsonlist['item'] = $list;
return json($jsonlist);
}
//绑定选择门店
public function get_the_Store()
{
try {
$stoid = I('stoid');
mlog("1", "get_the_Store/" . $stoid);
$lx = I('lx');
$ly = I('ly');
$uid = session('user')['user_id'];
if ($lx != 0 || $ly != 0) {
session('ulx', $lx);
session('uly', $ly);
}
$mindate = [];
/*--剔除不显示门店分类底下的门店--*/
$res0 = M("storage_category")->where('store_id', $stoid)->where('is_show', 0)->field("cat_id")->select();
$count0 = M("storage_category")->where('store_id', $stoid)->count();
$res0 = get_arr_column($res0, 'cat_id');
$wh = "1=1";
if (!empty($res0))
$wh = "category_id not in(" . implode(',', $res0) . ")";
// $result0=M("pick_up")->where('store_id',$stoid)->where('isstop<>1')->where($wh)->select();
$result0 = M("pick_up")->where('store_id', $stoid)->where('isstop<>1')->where($wh)->select();
$count = count($result0);
if ($count == 0) {
return json(['code' => -2, 'msg' => '未找到门店', 'is_bline' => 0]);
}
/*--当数量小于5--*/
if ($count <= 5 || $count0 <= 0) {
foreach ($result0 as $kk => $vv) {
$x1 = $vv['lon'];
$y1 = $vv['lat'];
$distance = sqrt(($x1 - $lx) * ($x1 - $lx) + ($y1 - $ly) * ($y1 - $ly));
$result0[$kk]['distance'] = round($distance, 2); //和定位点的距离
$dos[$kk] = $result0[$kk]['distance'];
}
if ($lx != 0 || $ly != 0) {
array_multisort($dos, SORT_ASC, $result0);
unset($dos);
}
return json(['code' => 1, 'msg' => 'ok', 'mini' => $result0, 'type' => 1]);
} else {
/*----选择门店-----*/
$res1 = M("storage_category")->where('store_id', $stoid)->where('is_show', 1)
->order('sort asc')->cache("storage_category_" . $stoid, TPSHOP_CACHE_TIME)->select();
foreach ($res1 as $k1 => $v1) {
$result = [];
foreach ($result0 as $k => $v) {
if ($v1['cat_id'] == $v['category_id']) {
$result[] = $v;
}
}
if (empty($result)) {
unset($res1[$k1]);
} else {
foreach ($result as $kk => $vv) {
$x1 = $vv['lon'];
$y1 = $vv['lat'];
$distance = sqrt(($x1 - $lx) * ($x1 - $lx) + ($y1 - $ly) * ($y1 - $ly));
$result[$kk]['distance'] = round($distance, 2); //和定位点的距离
$dos[$kk] = $result[$kk]['distance'];
}
if ($lx != 0 || $ly != 0) {
array_multisort($dos, SORT_ASC, $result);
unset($dos);
/*--取出最小值--*/
if (empty($mindata)) {
$mindata = $result[0];
} else {
$ele = $result[0];
if ($mindata['distance'] > $ele['distance']) {
$mindata = $ele;
}
}
}
$res1[$k1]['list'] = $result;
}
}
return json(['code' => 1, 'msg' => 'ok', 'store' => $res1, 'min' => $mindata, 'type' => 0]);
}
} catch (\Exception $e) {
insert_errlog($stoid, "会员绑定", "获取门店列表", "异常出错返回:" . $e->getMessage());
return json(['code' => -2, 'msg' => $e->getMessage()]);
}
}
//获取权益的相关内容
public function get_qy_user(){
$stoid=getMobileStoId();
$data['storeId']=$stoid;
$data['userId']=$this->user_id;
$qy_list=null;$qy_user=null;$backClass=null;$g_qy_list=null;
$res=getApiData_mini("/api/weshop/users/grade/aftervipinfo/get",$data,$stoid);
if(empty($res)) return json(['code'=>-1,'msg'=>'访问失败']);
$u_data=json_decode($res,true);
if($u_data && $u_data['code']===0){
$qy_user=$u_data['data'];
//获取所有的券列表
$adata['storeId']=$stoid;
$res=getApiData_mini("/api/weshop/users/grade/vipprivilegeinfo/page",$adata,$stoid);
if(empty($res)) return json(['code'=>-1,'msg'=>'访问权益列表失败']);
$qy_list=json_decode($res,true);
if(empty($qy_list) && $qy_list['code']!=0 && !$qy_list['data'] & !$qy_list['data']['pageData'])
return json(['code'=>-1,'msg'=>'访问权益列表失败']);
$qy_list=$qy_list['data']['pageData'];
//--获取卡类列表--
$res=getApiData_mini("/api/weshop/users/grade/vipgradeinfo/page",$adata,$stoid);
if(empty($res)) json(['code'=>-1,'msg'=>'访问权益卡类失败']);
$backClass=json_decode($res,true);
if(empty($backClass) && $backClass['code']!=0 && !$backClass['data'] & !$backClass['data']['pageData'])
return json(['code'=>-1,'msg'=>'访问权益列表失败']);
$backClass=$backClass['data']['pageData'];
//--获取会员已有的权益列表--
$adata['userId']=$this->user_id;
$adata['GradeId']=$qy_user['GradeId'];
$res=getApiData_mini("/api/weshop/users/grade/privilegeform/list/page",$adata,$stoid);
if(empty($res)) json(['code'=>-1,'msg'=>'访问会员的权益失败']);
$g_qy_list=json_decode($res,true);
if(empty($g_qy_list) && $g_qy_list['code']!=0 && !$g_qy_list['data'] & !$g_qy_list['data']['pageData'])
return json(['code'=>-1,'msg'=>'访问会员权益列表失败']);
$g_qy_list=$g_qy_list['data']['pageData'];
$data['qy_user']=$qy_user;
$data['qy_list']=$qy_list;
$data['backClass']=$backClass;
$data['g_qy_list']=$g_qy_list;
return json(['code=0','data'=>$data]);
}else{
if(empty($res)) return json(['code'=>-1,'msg'=>'获取会员权益失败']);
}
}
}