ShopgoodsController.php
4.1 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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/11/12
* Time: 17:17
*/
namespace api\index\controller;
use api\index\model\ShoptypeModel;
use api\index\model\ShopgoodsModel;
use api\index\model\ShoppicModel;
use cmf\controller\RestBaseController;
/**
* @title 积分商城首页
* @description
*/
class ShopgoodsController extends RestBaseController
{
/**
* @title 商品类型
* @description
* @author GuoSheng
* @url /index/Shopgoods/index
* @method GET
*
* @return id:ID
* @return type_name:类型名称
*
*/
public function index()
{
$where['delete_time'] = ['eq',0];
$shopTypeModel = new ShoptypeModel();
$data = $shopTypeModel->selectData($where);
$this->success('SUCCESS',$data);
}
/**
* @title 商品列表
* @description
* @author GuoSheng
* @url /index/Shopgoods/goods
* @method GET
*
* @param name:shoptype_id type:int require:0 other: desc:商品类型ID
*
* @return id:商品ID
* @return shoptype_id:所属类型ID
* @return goods_name:商品名称
* @return price:所需积分
*
*/
public function goods(){
$shoptype_id = $this->request->param('shoptype_id');
if(empty($shoptype_id)){
$shopGoodsModel = new ShopgoodsModel();
$where['delete_time'] = ['eq',0];
$data['goods'] = $shopGoodsModel->selectData($where);
$this->success('SUCCESS',$data);
}else{
$shopGoodsModel = new ShopgoodsModel();
$where['delete_time'] = ['eq',0];
$where['shoptype_id'] = ['eq',$shoptype_id];
$data = $shopGoodsModel->selectData($where);
$this->success('SUCCESS',$data);
}
}
/**
* @title 商城首页轮播图
* @description
* @author GuoSheng
* @url /index/Shopgoods/photo
* @method GET
*
* @return id:ID
* @return thumbnail:图片
* @return url:链接地址
*
*/
public function photo(){
$where['delete_time'] = ['eq',0];
$shopPicModel = new ShoppicModel();
$data = $shopPicModel->selectData($where);
$this->success('SUCCESS',$data);
}
/**
* @title 商品搜索页
* @description
* @author GuoSheng
* @url /index/Shopgoods/search
* @method GET
*
* @param name:keyword type:string require:1 other: desc:商品关键字
*
* @return id:商品ID
* @return shoptype_id:所属类型ID
* @return goods_name:商品名称
* @return price:所需积分
*
*/
public function search(){
$keyword = $this->request->param('keyword');
if(empty($keyword)){
$this -> error(['code'=>40005,'msg'=>'缺少必要参数']);
}
$where['goods_name'] = ['like',"%$keyword%"];
$shopGoodsModel = new ShopgoodsModel();
$data = $shopGoodsModel->selectData($where);
$this->success('SUCCESS',$data);
}
/**
* @title 商品详情页
* @description
* @author GuoSheng
* @url /index/Shopgoods/goodsDetail
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:0 other: desc:商品ID
*
* @return id:商品ID
* @return shoptype_id:所属类型ID
* @return goods_name:商品名称
* @return price:所需积分
* @return thumbnail:商品缩略图
* @return images:商品轮播图
* @return freight:运费
* @return content:详情
*
*
*/
public function goodsDetail(){
$user_id = $this->getUserId();
$goods_id = $this->request->param('id',0,'intval');
if(empty($goods_id)){
$this -> error(['code'=>40005,'msg'=>'缺少必要参数']);
}
$where['id'] = ['eq',$goods_id];
$shopGoodsModel = new ShopgoodsModel();
$data = $shopGoodsModel->findData($where);
$data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);
$data['update_time'] = date('Y-m-d H:i:s',$data['update_time']);
$this->success('SUCCESS',$data);
}
}