Index.php
17.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
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
<?php
/**
* tpshop
* ============================================================================
* * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: 当燃 2016-01-09
*/
namespace app\mobile\controller;
use app\home\logic\UsersLogic;
use think\Cookie;
use Think\Db;
use think\Exception;
class Index extends MobileBase
{
public function index()
{
$id = getMobileStoId();
// $rr = get_ad_position(61);top_ad_5
// if ($rr && $rr['code'] == 1) {
// $this->assign('adimg', $rr['data']);
// $this->assign('adimg_width', $rr['img_width']);
// $this->assign('adimg_height', $rr['img_height']);
// }
$data_team["pt_status"]=2;
$data_team["is_pt"]=1;
$user = session('user');
$userids=$user["user_id"];
$this->assign('userids',$userids);
/*调用拼团成功的人员 get 就不用后面的json*/
$data['storeId'] = $id;
//后台是否开启了初始化
$init_data = getApiData_mini("/api/weshop/users/grade/vip/init/get",$data,$stoid);
$isBool = 0;
if ($init_data) {
$init_data = json_decode($init_data, true);
if ($init_data['code'] === 0 && $init_data['data']) {
$isBool = $init_data['data']['isBool'];
$this->assign('isBool', $init_data['data']['isBool']);
}
}
$rm = M('store_module')->where('store_id', $id)->where('type', 0)->where('isdefault', 1)->find();
/*--更新会员的登录时间--*/
$user = session('user');
$rank_switch = tpCache('shopping.rank_switch',$id);//等级价格
$mz_switch = tpCache('shopping.is_beauty',$id);//美妆价格
$this->assign('rank_switch',$rank_switch);
$this->assign('mz_switch',$mz_switch);
if (!empty($rank_switch)){
//$this->assign('rank_field',$user['card_field']);
$rand_end= empty($user['card_expiredate'])?0:strtotime($user['card_expiredate']);
$card_field=$rand_end>time()?$user['card_field']:0;
$this->assign('rank_field',$card_field);
//----读取等级卡标签---
$all_card=get_plus_price_arr($id);
if($all_card) {
//--读取卡的分类---
$new_card_dd = null;
foreach ($all_card as $kl => $vl) {
if ($vl) {
switch ($vl['CorrPrice']) {
case "Price1":
$new_card_dd['cardprice1'] = $vl['CardName'];
break;
case "Price2":
$new_card_dd['cardprice2'] = $vl['CardName'];
break;
case "Price3":
$new_card_dd['cardprice3'] = $vl['CardName'];
break;
}
}
}
$card_label = $new_card_dd[$card_field];
$this->assign("all_card", $all_card);
$len = mb_strlen($card_label, "utf-8");
if ($len > 4)
$card_label = mb_substr($card_label, 0, 4, "utf-8");
$this->assign('card_label', $card_label);
}
}
if (!empty($mz_switch)){
$this->assign('mz_vip',$user['is_mzvip']);
}
//APP
$getylpres=getylapp_res($id,'1');
if ($getylpres)
{
$this->assign('ylpres',$getylpres);
}
//是否关闭免费使用优惠券
$switch = tpCache('shopping.switch_list',getMobileStoId());//获取开关json
$switch=json_decode($switch,true);
$is_closecoupon=$switch['is_closecoupon'];
$this->assign('is_closecoupon', $is_closecoupon);
//是否缴费
$isopen=0;
//先判断缴费记录是否有该商家的记录
$rss=M('store_module_endtime')->where('store_id='.$id)->where('type',0)->find();
if($rss){
if($rss['end_time']>time()) $isopen=1;
}else {
if ($rm) {
$tt=C('m_end_time');
if($tt>time()) $isopen=1;
}
}
if($isopen==1){
$fid=$rm['from_id'];
if($fid){
$ru=M('store_renew_module')->where('store_id='.$id)->where('module_id',$fid)->find();
if($ru){
if($ru['end_time']==0){} else{ if($ru['end_time']<time()) $isopen=0; }
}else{
$isopen==0;
}
}
}
if ($rm && file_exists(ROOT_PATH . "/public/template/feature/" . $id . '/' . $rm['template_sn'] . ".html") && $isopen==1) {
upload_ylp_log('商城首页');
$title = $rm['page_title'];
$descr = $rm['page_describe'];
$isrigth = $rm['isright'];
/*--文件路径--*/
$p = "./public/template/feature/" . $id . '/' . $rm['template_sn'] . ".html";
$bk = $rm['bkcolor'];
$this->assign('p', $p);
$this->assign('title', $title);
$this->assign('descr', $descr);
$this->assign('bk', $bk);
$this->assign('isright', $rm['isright']);
return $this->fetch('template', $id,0);
} else {
$t=time();
//新品上市
$new_goods = M('goods')
->where(['store_id'=>$id,'is_mainshow'=>1])
->where("is_new=1 and is_on_sale=1 and on_time<".$t." and (down_time>".$t." or down_time=0 or down_time='')")
->field('goods_id,goods_name,original_img,cardprice1,cardprice2,cardprice3,mz_price,prom_type,shop_price,market_price')
->order("sort")->limit(9)
->cache("new_goods_" . getMobileStoId(), TPSHOP_CACHE_TIME)->select();
$new_goods_count = count($new_goods);
$this->assign('new_goods_count', $new_goods_count);
$this->assign('new_goods', $new_goods);
//天天拼单
$fsql = "select g.goods_id,g.goods_name,g.original_img,g.prom_type,g.shop_price,g.market_price,(case when ".$t." < f.start_time then 1 else 0 end) as isyure,f.kttype,f.ct_num,f.price as tuanprice,f.goods_num,f.title,f.buy_num from __PREFIX__goods as g inner join __PREFIX__teamlist as f on g.goods_id = f.goods_id where g.store_id=" . $id . " and f.show_time<=".$t." and f.end_time>=".$t." and g.on_time<".$t." and (g.down_time>".$t." or g.down_time=0 or g.down_time='') and g.is_on_sale=1 and g.is_mainshow=1 and f.is_end=0 and f.is_show=1 order by f.ordid limit 9 ";
$team_goods = Db::query($fsql);
mlog("index:".$fsql,"index/".$id);
$this->assign('team_goods', $team_goods);
//拼团成人员功的数据
$team_sql = "SELECT a.user_id,b.nickname,b.head_pic FROM wxd_order a left join wxd_users b on a.user_id=b.user_id
WHERE a.store_id = $id and a.pt_status = 2 and a.pt_prom_id>0 and a.pay_time>0 and a.pt_prom_id>0 and a.pay_time>0 order by a.order_id desc LIMIT 0,6 ";
$team_user = Db::query($team_sql);
$this->assign('team_user', $team_user);
//倒计时
$fsql = "select g.goods_id,g.goods_name,g.original_img,g.prom_type,g.shop_price,g.market_price,(case when ".$t." < f.start_time then 1 else 0 end) as isyure,f.goods_num,f.buy_num,f.title,f.price,f.start_time,f.end_time,f.show_time from __PREFIX__goods as g inner join __PREFIX__flash_sale as f on g.goods_id = f.goods_id where g.store_id=" . $id . " and f.show_time<=".$t." and f.end_time>=".$t." and g.on_time<".$t." and (g.down_time>".$t." or g.down_time=0 or g.down_time='' ) and g.is_on_sale=1 and g.is_mainshow=1 and f.is_end=0 order by f.ordid asc,f.id desc limit 9 ";
$act_goods = Db::query($fsql);
$act_goods_count = count($act_goods);
$this->assign('act_goods_count', $act_goods_count);
$this->assign('act_goods', $act_goods);
//热销商品
$hot_goods = M('goods')->where(['store_id'=>$id,'is_mainshow'=>1])
->where("is_hot=1 and is_on_sale=1 and on_time<".$t." and (down_time>".$t." or down_time=0)")
->field('goods_id,goods_name,original_img,cardprice1,cardprice2,cardprice3,mz_price,prom_type,shop_price,market_price')
->order('sort')->limit(9)
->cache("hot_goods_" . getMobileStoId(), TPSHOP_CACHE_TIME)->select();//首页热卖商品
$hot_goods_count = count($hot_goods);
$this->assign('hot_goods_count', $hot_goods_count);
$this->assign('hot_goods', $hot_goods);
$this->assign('stoid', $id);
upload_ylp_log('商城首页');
$goods_category_tree = M('goods_category')->where(array('store_id'=>$id,'parent_id'=>0,'is_show'=>1))->order('sort_order asc')->limit(0,5)->select();
if ($goods_category_tree) {
$this->assign('service_class', $goods_category_tree);
}
return $this->fetch('', getMobileStoId());
}
}
/**
* 分类列表显示
*/
public function categoryList()
{
$id = getMobileStoId();
return $this->fetch('', getMobileStoId());
}
/**
* 模板列表
*/
public function mobanlist()
{
$arr = glob("D:/wamp/www/svn_tpshop/mobile--html/*.html");
foreach ($arr as $key => $val) {
$html = end(explode('/', $val));
echo "<a href='http://www.php.com/svn_tpshop/mobile--html/{$html}' target='_blank'>{$html}</a> <br/>";
}
}
/**
* 商品列表页
*/
public function goodsList()
{
$id = I('get.id', 0); // 当前分类id
$lists = getCatGrandson($id);
$this->assign('lists', $lists);
return $this->fetch('', getMobileStoId());
}
public function ajaxGetMore()
{
$p = I('p/d', 1);
$stoid=getMobileStoId();
$t=time();
$favourite_goods = M('goods')->where("store_id=".$stoid." and is_recommend=1 and is_on_sale=1 and on_time<".$t." and (down_time>".$t." or down_time=0) and is_mainshow=1 ")->order('sort')->page($p, 10)
->field('goods_id,goods_name,original_img,cardprice1,cardprice2,cardprice3,mz_price,prom_type,shop_price,market_price,sales_sum')
->select();//首页推荐商品
$cout = M('goods')->where("store_id=".$stoid." and is_recommend=1 and is_on_sale=1 and on_time<".$t." and (down_time>".$t." or down_time=0) and is_mainshow=1 ")->count();
// foreach ($favourite_goods as $k => $v){
// if ($v['mz_price'] == 0)
// $favourite_goods[$k]['mz_price'] = $v['shop_price'];
// }
if ($cout <= $p * 10) {
$this->assign('mshow', 0);
} else {
$this->assign('mshow', 1);
}
$this->assign('favourite_goods', $favourite_goods);
$user = session('user');
$card_field=$user['card_field'];
$rank_switch = tpCache('shopping.rank_switch',getMobileStoId());//等级价格
$mz_switch = tpCache('shopping.is_beauty',getMobileStoId());//美妆价格
$this->assign('rank_switch',$rank_switch);
$this->assign('mz_switch',$mz_switch);
if($rank_switch ) {
//----读取等级卡标签---
$all_card = get_plus_price_arr($stoid);
if($all_card) {
$new_card_dd = null;
//读取卡的分类
foreach ($all_card as $kl => $vl) {
if ($vl) {
switch ($vl['CorrPrice']) {
case "Price1":
$new_card_dd['cardprice1'] = $vl['CardName'];
break;
case "Price2":
$new_card_dd['cardprice2'] = $vl['CardName'];
break;
case "Price3":
$new_card_dd['cardprice3'] = $vl['CardName'];
break;
}
}
}
$this->assign("all_card", $all_card);
if($card_field) {
$card_label = $new_card_dd[$card_field];
$len = mb_strlen($card_label, "utf-8");
if ($len > 4)
$card_label = mb_substr($card_label, 0, 4, "utf-8");
$this->assign('card_label', $card_label);
}
}
}
if (!empty($rank_switch)){
//$this->assign('rank_field',$user['card_field']);
$rand_end= empty($user['card_expiredate'])?0:strtotime($user['card_expiredate']);
$card_field=$rand_end>time()?$user['card_field']:0;
$this->assign('rank_field',$card_field);
}
if (!empty($mz_switch)){
$this->assign('mz_vip',$user['is_mzvip']);
}
return $this->fetch('', getMobileStoId());
}
//微信Jssdk 操作类 用分享朋友圈 JS
public function ajaxGetWxConfig()
{
$askUrl = I('askUrl');//分享URL
$weixin_config = M('wx_user')->where("store_id", getMobileStoId())->find(); //获取微信配置
if (empty($weixin_config))
{
return "";
}
$jssdk = new \app\mobile\logic\Jssdk($weixin_config['appid'], $weixin_config['appsecret']);
$signPackage = $jssdk->GetSignPackage(urldecode($askUrl));
if ($signPackage) {
$this->ajaxReturn($signPackage, 'JSON');
} else {
return false;
}
}
//微信Jssdk 操作类 用分享朋友圈 JS
public function ajaxGetWxConfig_wxcard()
{
$weixin_config = M('wx_user')->where("store_id", getMobileStoId())->find(); //获取微信配置
$stoid_card=M('store_wxcard')->where(array('store_id'=>getMobileStoId(),'state'=>1))->find();
if ($stoid_card) {
$getcardid = $stoid_card['card_id'];//分享URL
$getcode = I('code');//手机号
$getopenid = I('openid');//
$jssdk = new \app\mobile\logic\Jssdk($weixin_config['appid'], $weixin_config['appsecret']);
$signPackage = $jssdk->getSignPackage_card($getcardid, $getcode, $getopenid);
if ($signPackage) {
$this->ajaxReturn($signPackage, 'JSON');
} else {
return false;
}
}else
{
return false;
}
}
public function issub()
{
if (session('?user')) {
$r = M('wx_openlist')->where("wxopenid", session('user')['openid'])
->where("store_id", getMobileStoId())->find();
if ($r['issubscribe'] == 1) {
return json(['code' => -1]);
} else {
$stoid= getMobileStoId();
$weixin_config = M('wx_user')->where('store_id=' . getMobileStoId())->field("appid,appsecret")->find(); //获取微信配置
if (empty($weixin_config))
{
return json(['code' => -1]);
}
$access_token = m_get_access_token($weixin_config);
mlog('关注开始2:','mobileindex/'.$stoid);
$url="";
$return = M('wx_ewmlist')->where(array('store_id' => $stoid, 'scene_id' =>''))->find();
if (empty($return)) {
if ($access_token) {
//获取数据的地址(微信提供)
$url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" . $access_token;
//发送给微信服务器的数据
$jsonstr = '{"expire_seconds": 1800, "action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": ""}}}';
$return = httpRequest($url, 'POST', $jsonstr);
mlog('关注二维码返回:'.$return,'mobileindex/'.$stoid);
$return = json_decode($return, 1);
if (!empty($return['ticket'])) {
$v['ticket'] = $return['ticket'];
$v['store_id'] = $stoid;
$v['scene_id'] = '';
$v['date'] = time();
$v['loadurl'] = $return['url'];
M('wx_ewmlist')->add($v);
$url="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".$v['ticket'];
mlog('关注二维码生成成功','mobileindex/'.$stoid);
} else {
mlog('关注二维码生成失败','mobileindex/'.$stoid);
}
}else{
mlog('关注access_token失败','mobileindex/'.$stoid);
}
}else{
$url="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".$return['ticket'];
}
return json(['code' => 1, 'url' =>$url]);
}
} else {
return json(['code' => -1]);
}
}
}