ZjCartController.php
1.6 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
<?php
/**
* Created by PhpStorm.
* User: wz
* Date: 2018/9/28
* Time: 18:05
*/
namespace app\cart\controller;
use cmf\controller\HomeBaseController;
use think\Db;
class ZjCartController extends HomeBaseController
{
/**
* 购物车
*/
public function cart(){
// $id=session('user.id');
$id=8;
$all=Db::name('zj_cart')->alias('c')->join('zj_goods g','c.gid=g.id')->join('zj_category ca','g.cid=ca.id')
->where('c.uid',$id)->field('c.id as cartid,c.gid,c.num,g.*,ca.cid as caid')->select();
if (empty($all[0])){
$you=1;
}else{
$you=2;
}
$this->assign('you',$you);
$this->assign('all',$all);
return $this->fetch();
}
/**
* 商品数量更改
*/
public function num(){
if ($this->request->isAjax()){
$param=input('param.');
if ($param['state']==1){
$jia=Db::name('zj_cart')->where('id',$param['id'])->setDec('num','1');
}else{
$jia=Db::name('zj_cart')->where('id',$param['id'])->setInc('num','1');
}
if (empty($jia)){
$this->error('NO');
}else{
$this->success('OK');
}
}
}
/**
* 删除选中商品
*/
public function del(){
if ($this->request->isAjax()){
$param=input('param.');
$del=Db::name('zj_cart')->where('id','in',$param['id'])->delete();
if (empty($del)){
$this->error('NO');
}else{
$this->success('OK');
}
}
}
}