ShopgoodsController.php
2.7 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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/11/9
* Time: 14:19
*/
namespace app\index\controller;
use app\index\model\ShopgoodsModel;
use app\index\model\ShoppicModel;
use app\index\model\ShoptypeModel;
use cmf\controller\HomeBaseController;
use cmf\controller\WeChatBaseController;
use think\Db;
class ShopgoodsController extends WeChatBaseController
{
function _initialize()
{
parent::_initialize();
$this->checkWeChatUserLogin();
}
//商品分类列表
public function index()
{
$where['delete_time'] = ['eq',0];
$shopTypeModel = new ShoptypeModel();
$data = $shopTypeModel->selectData($where)->toArray();
return $data;
}
//商品类表
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)->toArray();
$data['type'] = $this->index();
$data['photo'] = $this->photo();
$this->assign('data',$data);
return $this->fetch();
}else{
$shopGoodsModel = new ShopgoodsModel();
$where['delete_time'] = ['eq',0];
$where['shoptype_id'] = ['eq',$shoptype_id];
$data['goods'] = $shopGoodsModel->selectData($where)->toArray();
$data['type'] = $this->index();
$data['photo'] = $this->photo();
$this->assign('data',$data);
return $this->fetch();
}
}
//商城轮播图
public function photo(){
$where['delete_time'] = ['eq',0];
$shopPicModel = new ShoppicModel();
$data = $shopPicModel->selectData($where)->toArray();
return $data;
}
//商城搜索页
public function search(){
$keyword = $this->request->param('keyword');
if(empty($keyword)){
$this->error('请输入要搜索的内容');
}
$where['goods_name'] = ['like',"%$keyword%"];
$shopGoodsModel = new ShopgoodsModel();
$data = $shopGoodsModel->selectData($where)->toArray();
$this->assign('data',$data);
return $this->fetch();
}
//商品详情页
public function goodsDetail(){
$goods_id = $this->request->param('id',0,'intval');
if(empty($goods_id)){
$this->error('404');
}
$where['id'] = ['eq',$goods_id];
$shopGoodsModel = new ShopgoodsModel();
$data = $shopGoodsModel->findData($where)->toArray();
$this->assign('data',$data);
return $this->fetch();
}
}