商城礼券查询条件
Inheritance: QueryModel
Example #1
0
        /// <summary>
        /// 获取礼券列表(购买)
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public BasePageList<CouponViewModel> GetMallCouponPageList(CouponMallQuery query)
        {
            const string spName = "sp_common_pager";
            const string tableName = @"coupon_card as a
                                        left join coupon_shop as s on a.shopid=s.innerid
                                        left join base_county as sc on s.countyid=sc.innerid
                                        left join base_code as bc on a.cardtype=bc.codevalue and bc.typekey='coupon_type'
                                        left join coupon_card_product as p on a.innerid=p.cardid";
            const string fields =
                @"a.innerid, a.title, a.titlesub, a.amount,a.buyprice, a.logourl, a.vtype, a.vstart, a.vend, a.value1, a.value2, a.maxcount, a.count,a.codetype, a.createdtime,sc.countyname as ShopArea, s.address as ShopAddress,s.shopname as Shopname,bc.codename as cardtypename,bc.remark as cardtyperemark,p.productid as ProductUrl,
                    (select count(1) from coupon_code where cardid=a.innerid and sourceid = 1) as SoldedNum";
            var orderField = string.IsNullOrWhiteSpace(query.Order) ? "a.createdtime desc" : query.Order;
            //查询条件
            var sqlWhere = new StringBuilder("a.isenabled=1");

            if (!string.IsNullOrWhiteSpace(query.Shopid))
            {
                sqlWhere.Append($" and a.shopid='{query.Shopid}'");
            }

            if (query.Countyid != null)
            {
                sqlWhere.Append($" and s.countyid={query.Countyid}");
            }

            if (query.Cityid != null)
            {
                sqlWhere.Append($" and s.cityid={query.Cityid}");
            }

            if (query.Provid != null)
            {
                sqlWhere.Append($" and s.provid={query.Provid}");
            }

            if (!string.IsNullOrWhiteSpace(query.CardTypes))
            {
                sqlWhere.Append($" and a.cardtype in ({query.CardTypes})");
            }

            if (!string.IsNullOrWhiteSpace(query.Title))
            {
                sqlWhere.Append($" and a.title like '%{query.Title}%'");
            }
            var model = new PagingModel(spName, tableName, fields, orderField, sqlWhere.ToString(), query.PageSize, query.PageIndex);
            var list = Helper.ExecutePaging<CouponViewModel>(model, query.Echo);
            return list;
        }