vr-shopxo-source/app/index/controller/Cart.php

116 lines
3.2 KiB
PHP
Raw Normal View History

2018-12-28 10:58:37 +00:00
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
2021-03-16 02:34:52 +00:00
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
2018-12-28 10:58:37 +00:00
// +----------------------------------------------------------------------
2021-03-16 02:34:52 +00:00
// | Licensed ( https://opensource.org/licenses/mit-license.php )
2018-12-28 10:58:37 +00:00
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\index\controller;
2025-09-23 13:22:38 +00:00
use app\index\controller\Common;
use app\service\ApiService;
2019-12-24 07:18:56 +00:00
use app\service\SeoService;
use app\service\GoodsCartService;
2018-12-28 10:58:37 +00:00
/**
* 购物车
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class Cart extends Common
{
/**
* 构造方法
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-11-30
* @desc description
*/
public function __construct()
{
parent::__construct();
// 是否登录
2024-04-25 06:47:59 +00:00
IsUserLogin();
2018-12-28 10:58:37 +00:00
}
/**
* 首页
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-02-22T16:50:32+0800
*/
public function Index()
{
// 购物车列表
$cart_list = GoodsCartService::GoodsCartList(['user'=>$this->user]);
2018-12-28 10:58:37 +00:00
// 基础信息
2018-12-28 10:58:37 +00:00
$base = [
'total_price' => empty($cart_list['data']) ? 0 : array_sum(array_column($cart_list['data'], 'total_price')),
'buy_count' => empty($cart_list['data']) ? 0 : array_sum(array_column($cart_list['data'], 'stock')),
2018-12-28 10:58:37 +00:00
];
2019-12-24 07:18:56 +00:00
// 数据赋值
$assign = [
'base' => $base,
'cart_list' => $cart_list['data'],
2024-01-19 06:49:32 +00:00
'home_seo_site_title' => SeoService::BrowserSeoTitle(MyLang('cart.base_nav_title'), 1),
];
MyViewAssign($assign);
2021-07-18 15:42:10 +00:00
return MyView();
2018-12-28 10:58:37 +00:00
}
/**
* 购物车保存
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-13
* @desc description
*/
public function Save()
{
2023-08-27 08:59:15 +00:00
$params = $this->data_request;
2018-12-28 10:58:37 +00:00
$params['user'] = $this->user;
return ApiService::ApiDataReturn(GoodsCartService::GoodsCartSave($params));
2018-12-28 10:58:37 +00:00
}
/**
* 购物车删除
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-14
* @desc description
*/
public function Delete()
{
2023-08-27 08:59:15 +00:00
$params = $this->data_request;
2018-12-28 10:58:37 +00:00
$params['user'] = $this->user;
return ApiService::ApiDataReturn(GoodsCartService::GoodsCartDelete($params));
2018-12-28 10:58:37 +00:00
}
/**
* 数量保存
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-14
* @desc description
*/
public function Stock()
{
2023-08-27 08:59:15 +00:00
$params = $this->data_request;
2018-12-28 10:58:37 +00:00
$params['user'] = $this->user;
return ApiService::ApiDataReturn(GoodsCartService::GoodsCartStock($params));
2018-12-28 10:58:37 +00:00
}
}
?>