...
|
...
|
@@ -18,51 +18,110 @@ class ZjCartController extends HomeBaseController |
|
|
/**
|
|
|
* 购物车
|
|
|
*/
|
|
|
public function cart(){
|
|
|
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)->where(['g.is_sta'=>'1','g.delete_time'=>'0'])->field('c.id as cartid,c.gid,c.num,g.*,ca.cid as caid')->select();
|
|
|
if (empty($all[0])){
|
|
|
$you=1;
|
|
|
}else{
|
|
|
$you=2;
|
|
|
$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)->where(['g.is_sta' => '1', 'g.delete_time' => '0'])->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);
|
|
|
$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');
|
|
|
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)){
|
|
|
if (empty($jia)) {
|
|
|
$this->error('NO');
|
|
|
}else{
|
|
|
} 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)){
|
|
|
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{
|
|
|
} else {
|
|
|
$this->success('OK');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//检查购物车中勾选的商品一级大分类是否相同
|
|
|
public function checkCartGoods()
|
|
|
{
|
|
|
$request = request();
|
|
|
if ($request->isAjax()) {
|
|
|
$str = $request->param('id');
|
|
|
$cid = Db::name('zj_cart')->alias('c')
|
|
|
->join('zj_goods g', 'c.gid=g.id')
|
|
|
->join('zj_category t', 't.id=g.cid')
|
|
|
->field('t.cid')
|
|
|
->where(['c.uid' => session('user.id'), 'c.id' => ['in', $str]])
|
|
|
->select()
|
|
|
->toArray();
|
|
|
$temp = $cid[0]['cid'];
|
|
|
$status = true;
|
|
|
foreach ($cid as $k => $v) {
|
|
|
if ($k != 0) {
|
|
|
if ($temp != $v['cid']) {
|
|
|
$status = false;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if ($status === true) {
|
|
|
session('cart.id', $str);
|
|
|
$this->success('成功', url('cart/ZjCart/orderConfirm'), $status);
|
|
|
} else {
|
|
|
$this->success('请购买同分类的商品', null, $status);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//订单确认页
|
|
|
public function orderConfirm()
|
|
|
{
|
|
|
$data = Db::name('zj_cart')->alias('c')
|
|
|
->join('zj_goods g', 'c.gid=g.id')
|
|
|
->join('zj_category t', 't.id=g.cid')
|
|
|
->field('c.num,g.name,g.price,g.price_num,g.price_cash,g.thumb,g.is_type,g.intro,t.cid as caid')
|
|
|
->where(['c.uid' => session('user.id'), 'c.id' => ['in', session('cart.id')]])
|
|
|
->select();
|
|
|
foreach ($data as $k => $item) {
|
|
|
if ($item['caid'] == 1) {
|
|
|
$item['integral'] = '购买可获得' . $item['price'] * 2 . '积分';
|
|
|
} else {
|
|
|
$item['integral'] = '该商品无积分奖励';
|
|
|
}
|
|
|
$data[$k] = $item;
|
|
|
}
|
|
|
return $this->fetch('order_confirm', [
|
|
|
'data' => $data
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|