Stores.php
5.91 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
<?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\Page;
class Stores extends MobileBase
{
//门店信息20170522
public function storeslist()
{
$id = getMobileStoId();
$lx = I('lx');
$ly = I('ly');
mlog($lx . '-' . $ly, "storeslist/" . $id);
if ($lx != 0 || $ly != 0) {
session('ulx' . session('user')['user_id'], $lx);
session('uly' . session('user')['user_id'], $ly);
}
$rglist = get_region_list();
$where = "";
$getkey = I('key');
$storetype = I('storetype');
if ($getkey) {
$where['pickup_name'] = array('like', '%' . htmlspecialchars($getkey) . '%');
}
if ($storetype) {
$where['category_id'] = $storetype;
}
$list = M('pick_up')
->where("store_id=" . $id . " and isstop=0 ")
->where($where)
->order('pickup_id desc')
->select();
if ($list) {
$count = count($list);
$dos = null;
foreach ($list as $k => $v) {
$x1 = $v['lon'];
$y1 = $v['lat'];
$distance = sqrt(($x1 - $lx) * ($x1 - $lx) + ($y1 - $ly) * ($y1 - $ly));
$list[$k]['distance'] = round($distance, 2); //和定位点的距离
$v['province'] = $rglist[$v['province_id']]['name'];
$v['city'] = $rglist[$v['city_id']]['name'];
$v['district'] = $rglist[$v['district_id']]['name'];
$list[$k]['address'] = $v['province'] . $v['city'] . $v['district'] . $v['pickup_address'];
$dos[$k] = $list[$k]['distance'];
}
array_multisort($dos, SORT_ASC, $list);
$pagesize = 10;//C('PAGESIZE'); //每页显示数
$p = I('p/d', 1);
$fir = ($p - 1) * $pagesize;
$end = $p * $pagesize;
if ($end > $count) {
$end = $count;
}
$returnlist = null;
if ($fir < $count) {
for ($i = $fir; $i < $end; $i++) {
$returnlist[] = $list[$i];
}
}
}
if (empty($returnlist)) {
$jsonlist['state'] = "0";
$jsonlist['msg'] = '找不到相数据';
} else {
$jsonlist['state'] = "1";
$jsonlist['msg'] = '成功';
}
$jsonlist['item'] = $returnlist;
//门店分类
$storetype = M('storage_category')->where(array('store_id' => $id, 'is_show' => 1))->order('sort asc')->select();
$this->assign('storetype', $storetype);
$this->assign('list', $returnlist);
if (I('is_ajax')) {
return json($jsonlist);
}
upload_ylp_log('门店列表');
return $this->fetch('', getMobileStoId());
}
public function storesinfo()
{
$getstoid = getMobileStoId();
$getid = I('id/d');
if ($getid) {
$infolist = DB::name('pick_up')
->field(['a.*', 'b.name' => 'province', 'c.name' => 'city', 'd.name' => 'district'])
->alias('a')
->join('wxd_region b', 'a.province_id=b.id', 'left')
->join('wxd_region c', 'a.city_id=c.id', 'left')
->join('wxd_region d', 'a.district_id=d.id', 'left')
->where(" store_id=" . $getstoid . " and isstop=0 and pickup_id=" . $getid)
->find();
}
$this->assign('infolist', $infolist);
upload_ylp_log('门店详细');
return $this->fetch('', getMobileStoId());
}
//门店搜索
public function searchstores()
{
//门店分类
$getstoid=getMobileStoId();
$storetype = M('storage_category')->where(array('store_id' => $getstoid, 'is_show' => 1))->order('sort asc')->select();
$this->assign('storetype', $storetype);
return $this->fetch('', getMobileStoId());
}
public function storespage()
{
$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();
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);
}
}