GoodsController.php
2.5 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
<?php
namespace app\goods\controller;
use app\goods\model\GoodsModel;
use cmf\controller\HomeBaseController;
use think\Db;
class GoodsController extends HomeBaseController
{
public function goodsList()
{
$request = request();
$cid = $request->param('cid');
$category = [];
if (!$request->isAjax()) {
$category = $this->getCategory($cid);
$cid = $category[0]['id'];
}
$goods = new GoodsModel;
$goodsList = $goods->getGoods(null, $cid);
if ($request->isAjax()) {
$html = '';
if (!empty($goodsList)) {
foreach ($goodsList as $item) {
$html .= '
<a href="' . url('goods/Goods/detail', ['id' => $item['id']]) . '">
<div class="container_list">
<div class="text_img">
<img src="' . $item['thumb'] . '" alt="">
</div>
<div class="container_info">
<p class="info_name">
' . $item['name'] . '
</p>
<p class="info_num">
' . $item['intro'] . '
</p>
<div class="people">
<p class="people_weight">
购买可获得40积分
</p>
<p class="people_money">¥<span class="money">' . $item['price'] . '</span></p>
</div>
</div>
</div>
</a>
';
}
} else {
$html = '<div style="width: 100%; text-align: center; font-size: small">暂无商品</div>';
}
$this->success('', '', $html);
} else {
return $this->fetch(':list', [
'category' => $category,
'goodsList' => $goodsList
]);
}
}
public function detail()
{
$id = request()->param('id');
$data = Db::name('zj_goods')->field('thumb,name,intro,price,content')->where(['id' => $id])->find();
return $this->fetch(':detail', [
'data' => $data
]);
}
private function getCategory($cid)
{
return Db::name('zj_category')->field('id,name')->where(['cid' => $cid])->select()->toArray();
}
}