AddressController.php
3.8 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
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\portal\controller;
use app\portal\model\ShoppingModel;
use cmf\controller\HomeBaseController;
use EasyWeChat\Foundation\Application;
use think\Db;
use think\Session;
//地址
class AddressController extends CommentController
{
// 地址列表
public function index(){
$where_address['user_id'] = Session::get('uid');
$where_address['status'] = array('neq',9);
$address = Db::name('Address')->where($where_address)->order('is_check desc,create_time desc')->select()->toArray();
$this->assign('list',$address);
return $this->fetch();
}
// 添加地址
public function add(){
$data = $this->request->param();
if($this->request->isPost()){
$add = $data;
$add['user_id'] = Session::get('uid');
$add['create_time'] = time();
$add['update_time'] = time();
$res = Db::name('Address')->insertGetId($add);
if($res){
$this->apiResponse('1','添加成功');
}else{
$this->apiResponse('0','添加失败');
}
}else{
return $this->fetch();
}
}
// 修改地址
public function edit(){
$data = $this->request->param();
$where_find['id'] = $data['id'];
$where_find['status'] = array('neq',9);
$address = Db::name('Address')->where($where_find)->find();
$this->assign('list',$address);
if($this->request->isPost()){
$where_up['user_id'] = Session::get('uid');
$where_up['id'] = $address['id'];
$add = $data;
$add['update_time'] = time();
$res = Db::name('Address')->where($where_up)->update($add);
if($res){
$this->apiResponse('1','修改成功');
}else{
$this->apiResponse('0','添加失败');
}
}else{
return $this->fetch();
}
}
// 默认地址
public function isCheck(){
$data = $this->request->param();
$user_id = Session::get('uid');
$where_find['user_id'] = $user_id;
$where_find['status'] = array('neq',9);
$up_find['is_check'] = 0;
$up_find['update_time'] = time();
$find = Db::name('Address')->where($where_find)->update($up_find);
if($find){
$where_check['id'] = $data['address_id'];
$where_check['user_id'] = $user_id;
$where_check['status'] = array('neq',9);
$up_check['is_check'] = 1;
$up_check['update_time'] = time();
$res = Db::name('Address')->where($where_check)->update($up_check);
if($res){
$this->apiResponse('1','成功');
}else{
$this->apiResponse('0','失败');
}
}
}
// 地址删除
public function del(){
$data = $this->request->param();
$where_find['id'] = $data['id'];
$where_find['user_id'] = Session::get('uid');
$where_find['status'] = array('neq',9);
$update['status'] = 9;
$update['update_time'] = time();
$address = Db::name('Address')->where($where_find)->update($update);
if($address){
$this->apiResponse('1','删除成功');
}else{
$this->apiResponse('0','删除失败');
}
}
}