SubscribeController.php
5.2 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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/11/15
* Time: 14:35
*/
namespace api\index\controller;
use cmf\controller\RestBaseController;
use think\Db;
use think\Validate;
/**
* @title 回收商品预约
* @description
*/
class SubscribeController extends RestBaseController
{
public function _initialize()
{
$user_id = $this->getUserId();
$data = Db::name('integral')
->where('user_id',$user_id)
->find();
if(empty($data)){
$this->error(['code'=>40005,'msg'=>'请先注册']);
}
}
/**
* @title 回收商品类型
* @description
* @author GuoSheng
* @url /index/Subscribe/index
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @return id:类型ID
* @return recycle_type_name:类型名称
*
*/
public function index()
{
$user_id = $this->getUserId();
$data = Db::name('rtype')
->where('delete_time',0)
->field('id,recycle_type_name')
->select();
$this->success('SUCCESS',$data);
}
/**
* @title 回收商品列表以及属性
* @description
* @author GuoSheng
* @url /index/Subscribe/goods
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:rtype_id require:1 other: desc: 类型ID
*
* @return id:商品ID
* @return rtype_id:所属类型ID
* @return rgoods_name:商品名称
* @return attr_id:属性ID
* @return attr_name:属性名称
* @return rgoods_id:所属商品ID
* @return attr_price:价格
*/
public function goods()
{
// $user_id = $this->getUserId();
$rtype_id = $this->request->param('rtype_id',0,'intval');
if(empty($rtype_id)){
$this -> error(['code'=>40005,'msg'=>'缺少必要参数']);
}
$data = Db::name('rgoods')
->where('delete_time',0)
->where('rtype_id',$rtype_id)
->field('id,rtype_id,rgoods_name')
->select()
->toArray();
$res = Db::name('attr')
->field('id as attr_id,attr_name,rgoods_id,attr_price')
->select()
->toArray();
foreach ($data as &$v){
$v['child'] = [];
foreach ($res as $key =>$val){
if($val['rgoods_id'] == $v['id']){
array_push($v['child'],$val);
}
}
}
$this->success('SUCCESS',$data);
}
/**
* @title 通过属性获取商品信息
* @description
* @author GuoSheng
* @url /index/Subscribe/attr
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:attr_id require:1 other: desc: 属性ID
*
* @return id:属性ID
* @return attr_name:属性名称
* @return rgoods_name:商品名称
* @return rgoods_id:所属商品ID
* @return attr_price:价格
*/
public function attr(){
$user_id = $this->getUserId();
$attr_id = $this->request->param('attr_id');
if(empty($attr_id)){
$this->error(['code'=>40005,'msg'=>'缺少必要参数']);
}
$data = Db::name('attr')
->alias('a')
->join('rgoods r','a.rgoods_id = r.id')
->field('a.*,r.rgoods_name')
->where('a.id',$attr_id)
->find();
$this->success('SUCCESS',$data);
}
/**
* @title 回收预约订单
* @description
* @author GuoSheng
* @url /index/Subscribe/subscribe
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:recycle_id require:1 other: desc: 上门回收地址ID
* @param name:image require:1 other: desc: 回收物品图片
* @param name:attr_id require:1 other desc: 商品属性ID
* @param name:sub_time require:1 other desc: 预约时间
* @param name:content require:1 other desc: 留言备注
*
*/
public function subscribe()
{
$user_id = $this->getUserId();
$param = $this->request->param();
$param['user_id'] = $user_id;
$param['create_time'] = time();
$validate = new Validate([
'recycle_id' => 'require',
'image' => 'require',
'attr_id'=>'require',
'sub_time'=>'require',
'content'=>'require'
]);
$validate->message([
'recycle_id'=>'上门回收地址不能为空',
'image'=>'图片不能为空',
'attr_id'=>'回收商品不能为空',
'sub_time'=>'预约时间不能为空',
'content'=>'留言备注不能为空'
]);
if (!$validate->check($param)) {
$this->error(['code'=>40005,'msg'=>$validate->getError()]);
}
$fee = Db::name('recyclefee')
->where('id',1)
->find();
$param['fee_money'] = $fee['fee'];
$param['num'] = cmf_get_order_sn();
$data = Db::name('subscribe')
->insert($param);
if(empty($data)){
$this->error(['code'=>40006,'msg'=>'sql执行失败']);
}
$this->success('SUCCESS');
}
}