...
|
...
|
@@ -40,30 +40,36 @@ class Goods extends Api |
|
|
"price": "4499.00", 价格
|
|
|
"line_price": "0.00", 划线价
|
|
|
"images_text": [
|
|
|
轮播图
|
|
|
轮播图
|
|
|
],
|
|
|
"down_image_text": "底部图",
|
|
|
"four_image_text": [
|
|
|
四宫格图
|
|
|
四宫格图
|
|
|
]
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function goodsDetail()
|
|
|
{
|
|
|
$goods_id = $this->request->post('goods_id');
|
|
|
$goods_id = $this->request->post('goods_id');
|
|
|
$goodsmodel = new \app\api\model\Goods();
|
|
|
if (!is_numeric($goods_id)){
|
|
|
if (!is_numeric($goods_id)) {
|
|
|
$this->error('商品id不合法');
|
|
|
}
|
|
|
$goods = $goodsmodel::get($goods_id);
|
|
|
$goods_spec = Db::name('litestore_goods_spec')->where('goods_id',$goods['goods_id'])->find();
|
|
|
$goods['price'] = $goods_spec['goods_price'];
|
|
|
$goods = $goodsmodel::get($goods_id);
|
|
|
$goods_spec = Db::name('litestore_goods_spec')->where('goods_id', $goods['goods_id'])->find();
|
|
|
$goods['price'] = $goods_spec['goods_price'];
|
|
|
$goods['line_price'] = $goods_spec['line_price'];
|
|
|
//判断是否打折
|
|
|
$goods['is_discount'] = 'is';
|
|
|
if ($goods_spec['goods_price'] == $goods_spec['line_price']) {
|
|
|
$goods['is_discount'] = 'no';
|
|
|
}
|
|
|
$goods['discount'] = $goods_spec['discount'];
|
|
|
// 产地
|
|
|
$makerfor_list = ['1' => '国产','2' => '进口'];
|
|
|
$makerfor_list = ['1' => '国产', '2' => '进口'];
|
|
|
$goods['makefor'] = isset($makerfor_list[$goods['makefor']]) ? $makerfor_list[$goods['makefor']] : '未知';
|
|
|
$this->success('商品详情',$goods);
|
|
|
$this->success('商品详情', $goods);
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -118,36 +124,42 @@ class Goods extends Api |
|
|
*/
|
|
|
public function goodsSku()
|
|
|
{
|
|
|
$goods_id = $this->request->post('goods_id');
|
|
|
$goods_id = $this->request->param('goods_id');
|
|
|
$goodsspecrelmodel = new GoodsSpecRel();
|
|
|
$list = $goodsspecrelmodel
|
|
|
->where('goods_id',$goods_id)
|
|
|
$list = $goodsspecrelmodel
|
|
|
->where('goods_id', $goods_id)
|
|
|
->select();
|
|
|
$array = [];
|
|
|
$goods = \app\api\model\Goods::get($goods_id);
|
|
|
if ($goods['spec_type'] == 20){
|
|
|
foreach ($list as $key => $value){
|
|
|
if (!isset($array[$value['spec_id']])){
|
|
|
$array = [];
|
|
|
$goods = \app\api\model\Goods::get($goods_id);
|
|
|
if ($goods['spec_type'] == 20) {
|
|
|
foreach ($list as $key => $value) {
|
|
|
if (!isset($array[$value['spec_id']])) {
|
|
|
$array[$value['spec_id']]['name'] = Db::name('litestore_spec')
|
|
|
->where('id',$value['spec_id'])
|
|
|
->where('id', $value['spec_id'])
|
|
|
->value('spec_name');
|
|
|
}
|
|
|
$spec_value =Db::name('litestore_spec_value')
|
|
|
->where('id',$value['spec_value_id'])
|
|
|
$spec_value = Db::name('litestore_spec_value')
|
|
|
->where('id', $value['spec_value_id'])
|
|
|
->value('spec_value');
|
|
|
$array[$value['spec_id']]['second'][] = [
|
|
|
'id' => $value['spec_value_id'],
|
|
|
'name' => $spec_value
|
|
|
'id' => $value['spec_value_id'],
|
|
|
'name' => $spec_value,
|
|
|
];
|
|
|
}
|
|
|
$array = array_values($array);
|
|
|
}
|
|
|
$goods_spec = GoodsSpec::all(['goods_id'=>$goods_id]);
|
|
|
$this->success('商品规格',['list'=>$goods_spec,'sku'=>$array]);
|
|
|
$goods_spec = GoodsSpec::all(['goods_id' => $goods_id]);
|
|
|
foreach ($goods_spec as &$value) {
|
|
|
//判断是否打折
|
|
|
$value['is_discount'] = 'is';
|
|
|
if ($value['goods_price'] == $value['line_price']) {
|
|
|
$value['is_discount'] = 'no';
|
|
|
}
|
|
|
}
|
|
|
$this->success('商品规格', ['list' => $goods_spec, 'sku' => $array]);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (商品详情页评价)
|
|
|
* @ApiMethod (POST)
|
...
|
...
|
@@ -158,23 +170,23 @@ class Goods extends Api |
|
|
'data':{
|
|
|
"comment_number": 1, 评价数量
|
|
|
"comment": {
|
|
|
"id": 1,
|
|
|
"user_id": null,
|
|
|
"goods_id": 22,
|
|
|
"comment": "12121212", 评论内容
|
|
|
"images": "1asdasd",
|
|
|
"score": null,
|
|
|
"createtime": null,
|
|
|
"status": "normal",
|
|
|
"images_text": [
|
|
|
评价图片数组
|
|
|
"http://temporaryfood.com1asdasd"
|
|
|
]
|
|
|
"id": 1,
|
|
|
"user_id": null,
|
|
|
"goods_id": 22,
|
|
|
"comment": "12121212", 评论内容
|
|
|
"images": "1asdasd",
|
|
|
"score": null,
|
|
|
"createtime": null,
|
|
|
"status": "normal",
|
|
|
"images_text": [
|
|
|
评价图片数组
|
|
|
"http://temporaryfood.com1asdasd"
|
|
|
]
|
|
|
}
|
|
|
"user": {
|
|
|
"id": 1,
|
|
|
"nickname": "admin",
|
|
|
"avatar_text": "用户头像",
|
|
|
"id": 1,
|
|
|
"nickname": "admin",
|
|
|
"avatar_text": "用户头像",
|
|
|
}
|
|
|
}
|
|
|
})
|
...
|
...
|
@@ -182,21 +194,21 @@ class Goods extends Api |
|
|
public function goodsDetailComment()
|
|
|
{
|
|
|
$goods_id = $this->request->post('goods_id');
|
|
|
if (!is_numeric($goods_id)){
|
|
|
if (!is_numeric($goods_id)) {
|
|
|
$this->error('商品id不合法');
|
|
|
}
|
|
|
$model = new GoodsComment();
|
|
|
$goods = [];
|
|
|
$goods['comment_number'] = $model->where('goods_id',$goods_id)->where('status','normal')->count();
|
|
|
$table_name = $model->getTable();
|
|
|
$goods['comment'] = $model
|
|
|
->with(['user'])
|
|
|
->where($table_name.'.goods_id',$goods_id)
|
|
|
->where($table_name.'.status','normal')
|
|
|
->order($table_name.'.id','desc')
|
|
|
->find()??[];
|
|
|
if ($goods['comment'])$goods['comment']->getRelation('user')->visible(['id','nickname']);
|
|
|
$this->success('商品详情页评价',$goods);
|
|
|
$model = new GoodsComment();
|
|
|
$goods = [];
|
|
|
$goods['comment_number'] = $model->where('goods_id', $goods_id)->where('status', 'normal')->count();
|
|
|
$table_name = $model->getTable();
|
|
|
$goods['comment'] = $model
|
|
|
->with(['user'])
|
|
|
->where($table_name . '.goods_id', $goods_id)
|
|
|
->where($table_name . '.status', 'normal')
|
|
|
->order($table_name . '.id', 'desc')
|
|
|
->find() ?? [];
|
|
|
if ($goods['comment']) $goods['comment']->getRelation('user')->visible(['id', 'nickname']);
|
|
|
$this->success('商品详情页评价', $goods);
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -209,50 +221,50 @@ class Goods extends Api |
|
|
'code':'1',
|
|
|
'msg':'返回成功'
|
|
|
'data':{
|
|
|
"total": 1,
|
|
|
"per_page": 10,
|
|
|
"current_page": 1,
|
|
|
"last_page": 1,
|
|
|
"data": [
|
|
|
{
|
|
|
"id": 1,
|
|
|
"user_id": 1,
|
|
|
"goods_id": 22,
|
|
|
"comment": "12121212",
|
|
|
"images": "1asdasd",
|
|
|
"score": null,
|
|
|
"createtime": null,
|
|
|
"status": "normal",
|
|
|
"user": {
|
|
|
"id": 1,
|
|
|
"nickname": "admin",
|
|
|
"avatar_text": ""
|
|
|
},
|
|
|
"images_text": [
|
|
|
"http://temporaryfood.com1asdasd"
|
|
|
],
|
|
|
"createtime_text": ""
|
|
|
}
|
|
|
]
|
|
|
"total": 1,
|
|
|
"per_page": 10,
|
|
|
"current_page": 1,
|
|
|
"last_page": 1,
|
|
|
"data": [
|
|
|
{
|
|
|
"id": 1,
|
|
|
"user_id": 1,
|
|
|
"goods_id": 22,
|
|
|
"comment": "12121212",
|
|
|
"images": "1asdasd",
|
|
|
"score": null,
|
|
|
"createtime": null,
|
|
|
"status": "normal",
|
|
|
"user": {
|
|
|
"id": 1,
|
|
|
"nickname": "admin",
|
|
|
"avatar_text": ""
|
|
|
},
|
|
|
"images_text": [
|
|
|
"http://temporaryfood.com1asdasd"
|
|
|
],
|
|
|
"createtime_text": ""
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function goodsComment()
|
|
|
{
|
|
|
$goods_id = $this->request->post('goods_id');
|
|
|
$page = $this->request->post('page');
|
|
|
$model = new \app\api\model\GoodsComment();
|
|
|
if (!is_numeric($goods_id)){
|
|
|
$page = $this->request->post('page');
|
|
|
$model = new \app\api\model\GoodsComment();
|
|
|
if (!is_numeric($goods_id)) {
|
|
|
$this->error('商品id不合法');
|
|
|
}
|
|
|
$lists = $model
|
|
|
->with(['user'])
|
|
|
->where('goods_id',$goods_id)
|
|
|
->order('id','desc')
|
|
|
->paginate(10,false,['page'=>$page])
|
|
|
->each(function ($item,$key){
|
|
|
$item->getRelation('user')->visible(['id','nickname']);
|
|
|
->where('goods_id', $goods_id)
|
|
|
->order('id', 'desc')
|
|
|
->paginate(10, false, ['page' => $page])
|
|
|
->each(function ($item, $key) {
|
|
|
$item->getRelation('user')->visible(['id', 'nickname']);
|
|
|
});
|
|
|
$this->success('商品规格',$lists);
|
|
|
$this->success('商品规格', $lists);
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|