using Common.DbExtends.Extends; using Common.Models.Enums; using Common.Models.UnqTables; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web.Http; namespace Server.Controllers.FinancialManagement { public class ShopController:DefaultController { /// /// 获取商户信息信息 /// /// [HttpPost, ErrorFilter] public WebResult GetShops() { var PageIndex = GetInt("PageIndex"); var PageSize = GetInt("PageSize"); var tNumber = 0; var Keyword = GetString("Keyword"); var exp = Expressionable.Create(); if (!string.IsNullOrEmpty(Keyword)) { exp.And(f => f.Remark.Contains(Keyword)); } var DataList = Db.Queryable().Where(exp.ToExpression()) .ToPageList(PageIndex, PageSize, ref tNumber); var res = new PageResult(DataList, tNumber, PageSize, PageIndex); return PutData(res); } /// /// 新增商户 /// /// [HttpPost, ErrorFilter] public WebResult AddShop() { var Remark = GetString("Remark"); var AppId = GetString("AppId", true); var AppSecret = GetString("AppSecret", true); var PartnerId = "";//GetString("PartnerId", true); var PartnerKey = GetString("PartnerKey", true); var FootTxt = GetString("FootTxt"); var CertPath = GetString("CertPath", true); var shopType = GetEnum("ShopType", true); bool isExist = false; if (shopType == ShopType.微信商户) { PartnerId = GetString("PartnerId", true); isExist = Db.Queryable().Any(x => x.PartnerId == PartnerId); } else { isExist = Db.Queryable().Any(x => x.AppId == AppId); } if (isExist) { return PutData("当前商户ID已存在"); } var shop = new Shop() { AppId = AppId, AppSecret = AppSecret, PartnerId = PartnerId, PartnerKey = PartnerKey, FootTxt = FootTxt, CertPaths = CertPath, Remark = Remark, ShopType = shopType }; Db.Insertable(shop).ExecuteCommand(); return PutSuccess; } /// /// 编辑商户 /// /// [HttpPost, ErrorFilter] public WebResult SaveShop() { var Id = GetInt("Id", true); var Remark = GetString("Remark"); var AppId = GetString("AppId", true); var AppSecret = GetString("AppSecret", true); var PartnerKey = GetString("PartnerKey", true); var FootTxt = GetString("FootTxt"); var CertPath = GetString("CertPath", true); //var shopType = GetEnum("ShopType", true); var shop = Db.Queryable().First(x => x.Id == Id); if (shop == null) { return PutData("目标商户ID不存在"); } if (shop.ShopType == ShopType.微信商户) { shop.PartnerId = GetString("PartnerId", true); } shop.AppId = AppId; shop.AppSecret = AppSecret; shop.PartnerKey = PartnerKey; shop.FootTxt = FootTxt; shop.CertPaths = CertPath; shop.Remark = Remark; Db.Saveable(shop).ExecuteCommand(); return PutSuccess; } /// /// 删除商户 /// /// [HttpPost, ErrorFilter] public WebResult DelShop() { var Id = GetInt("Id", true); var shop = Db.Queryable().First(x => x.Id == Id); if (shop == null) { return PutData("目标商户ID不存在"); } Db.Deleteable(shop).ExecuteCommand(); return PutSuccess; } } }