Shop.php
3.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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/5/20
* Time: 19:57
*/
namespace app\index\controller;
use app\common\controller\Frontend;
use app\index\model\Store;
use think\Db;
class Shop extends Frontend
{
protected $noNeedLogin = ['detail'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
$this->view->assign('is_search', 0);
$this->view->assign('is_active', 0);
$this->view->assign('title', '店铺详情');
}
public function detail(){
$province_id = $this->request->param('province_id',0,'intval');
$user_id = $this->auth->id;
$store_id = $this->request->param('store_id',0,'intval');
if(empty($store_id)){
$this->error('缺少必要参数');
}
$storeModel = new Store();
$data = $storeModel->findData(['id'=>$store_id]);
//收藏
$is_collect = "2";
$encrypt = '2';
if(!empty($user_id)){
$storecollect = Db::name('storecollect')->where(['user_id'=>$user_id,'stores_id'=>$data['id']])->find();
if(!empty($storecollect)){
$is_collect = "1";
}
$userModel = new \app\index\model\User();
$user = $userModel->findData(['id'=>$data['user_id']]);
if(!empty($user)){
$province_ids = [];
/*if($data['province_ids']) {
$province_ids = is_array($data['province_ids']) ? $data['province_ids'] : explode(',',$data['province_ids']);
}*/
$user_province = Db::name('user_province')->where(['user_id'=>$data['user_id'],'expiration_time'=>['gt',time()]])->select();
foreach($user_province as $key => $u_p){
$province_ids[] = $u_p['province_id'];
}
if($data['is_svip'] == '1' || in_array($province_id,$province_ids)){
$encrypt = '1';
}
}
}
$data['is_collect'] = $is_collect;
if(empty($user_id)){
$text = "(请您先登录)";
$data['phone'] = substr_replace($data['phone'],'****',3,4).$text;
$data['address'] = substr_replace($data['address'],'********',3).$text;
}
//当前用户若不是会员加密部分信息
if($encrypt == '2'){
$text = '';
if(empty($user_id)){
$text = "(请您先登录)";
}
$data['phone'] = substr_replace($data['phone'],'****',3,4).$text;
$data['address'] = substr_replace($data['address'],'********',3).$text;
}
$this->assign('data',$data);
// dump(collection($data)->toArray());
if($this->request->isAjax()){
$this->success('SUCCESS','',$data);
}
return $this->fetch();
}
public function collect(){
$user_id = $this->auth->id;
$store_id = $this->request->param('store_id',0,'intval');
if(empty($store_id)){
$this->error('缺少必要参数');
}
$data = Db::name('storecollect')->where(['user_id'=>$user_id,'stores_id'=>$store_id])->find();
$arr['user_id'] = $user_id;
$arr['stores_id'] = $store_id;
$arr['updatetime'] = time();
if(empty($data)){
$arr['createtime'] = time();
$result = Db::name('storecollect')->insert($arr);
}else{
$result = Db::name('storecollect')->where(['id'=>$data['id']])->update($arr);
}
if(empty($result)){
$this->error('sql执行失败');
}
$this->success('SUCCESS');
}
}