yz_server/Server/Controllers/FinancialManagement/ShopController.cs

141 lines
4.4 KiB
C#

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
{
/// <summary>
/// 获取商户信息信息
/// </summary>
/// <returns></returns>
[HttpPost, ErrorFilter]
public WebResult GetShops()
{
var PageIndex = GetInt("PageIndex");
var PageSize = GetInt("PageSize");
var tNumber = 0;
var Keyword = GetString("Keyword");
var exp = Expressionable.Create<Shop>();
if (!string.IsNullOrEmpty(Keyword))
{
exp.And(f => f.Remark.Contains(Keyword));
}
var DataList = Db.Queryable<Shop>().Where(exp.ToExpression())
.ToPageList(PageIndex, PageSize, ref tNumber);
var res = new PageResult<Shop>(DataList, tNumber, PageSize, PageIndex);
return PutData(res);
}
/// <summary>
/// 新增商户
/// </summary>
/// <returns></returns>
[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>("ShopType", true);
bool isExist = false;
if (shopType == ShopType.)
{
PartnerId = GetString("PartnerId", true);
isExist = Db.Queryable<Shop>().Any(x => x.PartnerId == PartnerId);
}
else
{
isExist = Db.Queryable<Shop>().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;
}
/// <summary>
/// 编辑商户
/// </summary>
/// <returns></returns>
[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>("ShopType", true);
var shop = Db.Queryable<Shop>().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;
}
/// <summary>
/// 删除商户
/// </summary>
/// <returns></returns>
[HttpPost, ErrorFilter]
public WebResult DelShop()
{
var Id = GetInt("Id", true);
var shop = Db.Queryable<Shop>().First(x => x.Id == Id);
if (shop == null)
{
return PutData("目标商户ID不存在");
}
Db.Deleteable(shop).ExecuteCommand();
return PutSuccess;
}
}
}