移动系统liao
2025-02-17 557c2711a3e103ebc3d0492344eca9730d5e92b2
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
76
77
78
79
/***********************************************************************
 *            Project: baifenBinfa
 *        ProjectName: 百分兵法管理系统                               
 *                Web: http://chuanyin.com                     
 *             Author:                                        
 *              Email:                               
 *         CreateTime: 202403/02   
 *        Description: 暂无
 ***********************************************************************/
 
using System.Threading.Tasks;
using CoreCms.Net.Configuration;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.Entities;
using SqlSugar;
 
namespace CoreCms.Net.Repository
{
    /// <summary>
    ///     购物车表 接口实现
    /// </summary>
    public class CoreCmsCartRepository : BaseRepository<CoreCmsCart>, ICoreCmsCartRepository
    {
        public CoreCmsCartRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
        {
        }
 
 
        #region 获取购物车用户数据总数
 
        /// <summary>
        ///     获取购物车用户数据总数
        /// </summary>
        /// <returns></returns>
        public async Task<int> GetCountAsync(int userId)
        {
            var count = await DbClient.Queryable<CoreCmsCart, CoreCmsProducts, CoreCmsGoods>((cart, products, goods) =>
                    new object[]
                    {
                        JoinType.Inner, cart.productId == products.id,
                        JoinType.Inner, products.goodsId == goods.id
                    })
                .Where((cart, products, goods) => cart.type == (int)GlobalEnumVars.OrderType.Common)
                .Select((cart, products, goods) => new { cart.id, cart.userId, goodId = goods.id })
                .MergeTable()
                .CountAsync(p => p.userId == userId);
            return count;
        }
 
        #endregion
 
 
        #region 获取购物车商品总价格
 
        /// <summary>
        ///     获取购物车商品总价格
        /// </summary>
        /// <returns></returns>
        public async Task<decimal> GetMoneyAsync(int userId)
        {
            var count = await DbClient.Queryable<CoreCmsCart, CoreCmsProducts, CoreCmsGoods>((cart, products, goods) =>
                    new object[]
                    {
                        JoinType.Inner, cart.productId == products.id,
                        JoinType.Inner, products.goodsId == goods.id
                    })
                .Where((cart, products, goods) => cart.type == (int)GlobalEnumVars.OrderType.Common && cart.userId == userId)
                .Select((cart, products, goods) => new { cart.nums, products.price, sunMoney = cart.nums * products.price })
                .MergeTable()
                .SumAsync(p => p.sunMoney);
            return count;
        }
 
        #endregion
 
 
    }
}