119 lines
2.9 KiB
PHP
Executable File
119 lines
2.9 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Home\Controller;
|
|
|
|
use Service\BuyService;
|
|
|
|
/**
|
|
* 购物车
|
|
* @author Devil
|
|
* @blog http://gong.gg/
|
|
* @version 0.0.1
|
|
* @datetime 2016-12-01T21:51:08+0800
|
|
*/
|
|
class CartController extends CommonController
|
|
{
|
|
/**
|
|
* [_initialize 前置操作-继承公共前置方法]
|
|
* @author Devil
|
|
* @blog http://gong.gg/
|
|
* @version 0.0.1
|
|
* @datetime 2016-12-03T12:39:08+0800
|
|
*/
|
|
public function _initialize()
|
|
{
|
|
// 调用父类前置方法
|
|
parent::_initialize();
|
|
|
|
// 是否登录
|
|
$this->Is_Login();
|
|
}
|
|
|
|
/**
|
|
* [Index 首页]
|
|
* @author Devil
|
|
* @blog http://gong.gg/
|
|
* @version 0.0.1
|
|
* @datetime 2017-02-22T16:50:32+0800
|
|
*/
|
|
public function Index()
|
|
{
|
|
$cart_list = BuyService::CartList(['user'=>$this->user]);
|
|
$this->assign('cart_list', $cart_list['data']);
|
|
|
|
$base = [
|
|
'total_price' => empty($cart_list['data']) ? 0 : array_sum(array_column($cart_list['data'], 'total_price')),
|
|
'total_stock' => empty($cart_list['data']) ? 0 : array_sum(array_column($cart_list['data'], 'stock')),
|
|
'ids' => empty($cart_list['data']) ? '' : implode(',', array_column($cart_list['data'], 'id')),
|
|
];
|
|
$this->assign('base', $base);
|
|
$this->display('Index');
|
|
}
|
|
|
|
/**
|
|
* 购物车保存
|
|
* @author Devil
|
|
* @blog http://gong.gg/
|
|
* @version 1.0.0
|
|
* @date 2018-09-13
|
|
* @desc description
|
|
*/
|
|
public function Save()
|
|
{
|
|
// 是否ajax请求
|
|
if(!IS_AJAX)
|
|
{
|
|
$this->error(L('common_unauthorized_access'));
|
|
}
|
|
|
|
$params = $_POST;
|
|
$params['user'] = $this->user;
|
|
$ret = BuyService::CartAdd($params);
|
|
$this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
|
|
}
|
|
|
|
/**
|
|
* 购物车删除
|
|
* @author Devil
|
|
* @blog http://gong.gg/
|
|
* @version 1.0.0
|
|
* @date 2018-09-14
|
|
* @desc description
|
|
*/
|
|
public function Delete()
|
|
{
|
|
// 是否ajax请求
|
|
if(!IS_AJAX)
|
|
{
|
|
$this->error(L('common_unauthorized_access'));
|
|
}
|
|
|
|
$params = $_POST;
|
|
$params['user'] = $this->user;
|
|
$ret = BuyService::CartDelete($params);
|
|
$this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
|
|
}
|
|
|
|
/**
|
|
* 数量保存
|
|
* @author Devil
|
|
* @blog http://gong.gg/
|
|
* @version 1.0.0
|
|
* @date 2018-09-14
|
|
* @desc description
|
|
*/
|
|
public function Stock()
|
|
{
|
|
// 是否ajax请求
|
|
if(!IS_AJAX)
|
|
{
|
|
$this->error(L('common_unauthorized_access'));
|
|
}
|
|
|
|
$params = $_POST;
|
|
$params['user'] = $this->user;
|
|
$ret = BuyService::CartStock($params);
|
|
$this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
|
|
}
|
|
}
|
|
?>
|