KqProductsService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * 产品库
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.Models.Main;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service.Main
  12. {
  13. public class KqProductsService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  16. /// <summary>
  17. /// 查询列表
  18. /// </summary>
  19. /// <param name="relationData">关联表</param>
  20. /// <param name="condition">查询条件(sql语句)</param>
  21. /// <param name="count">总数(输出)</param>
  22. /// <param name="page">页码</param>
  23. /// <param name="limit">每页条数</param>
  24. /// <returns></returns>
  25. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, out int count, int page = 1, int limit = 300, string orderBy = "Sort desc,Id desc")
  26. {
  27. List<string> fields = new List<string>(); //要显示的列
  28. fields.Add("Id");
  29. fields.Add("CreateDate"); //添加时间
  30. fields.Add("Status"); //状态
  31. fields.Add("Name"); //名称
  32. fields.Add("Kind"); //类型
  33. fields.Add("MinStock"); //最低库存数
  34. fields.Add("CountOfBox"); //每箱机具台数
  35. fields.Add("ReqMoneyUnit"); //请求支付公司金额单位
  36. fields.Add("NoticeMoneyUnit"); //接收支付公司金额单位
  37. fields.Add("AdColId"); //广告分类
  38. fields.Add("DefaultDeposit"); //默认押金
  39. fields.Add("MerNameWithStar"); //商户姓名是否带星号
  40. fields.Add("SingleDepositApi"); //单独押金推送接口
  41. fields.Add("ActTradeAmount"); //激活交易额
  42. fields.Add("PosPrice"); //机具单价
  43. fields.Add("MainStoreId"); //总仓
  44. fields.Add("SpProductType"); //原始数据品牌
  45. fields.Add("FluxAmount"); //流量费
  46. fields.Add("FluxProfit"); //流量费分佣
  47. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("KqProducts", relationData, orderBy, page, limit, condition, fields);
  48. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  49. count = int.Parse(obj["count"].ToString());
  50. return diclist;
  51. }
  52. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  53. {
  54. List<string> fields = new List<string>(); //要显示的列
  55. fields.Add("Id");
  56. fields.Add("CreateDate"); //添加时间
  57. fields.Add("Status"); //状态
  58. fields.Add("Name"); //名称
  59. fields.Add("Kind"); //类型
  60. fields.Add("MinStock"); //最低库存数
  61. fields.Add("CountOfBox"); //每箱机具台数
  62. fields.Add("ReqMoneyUnit"); //请求支付公司金额单位
  63. fields.Add("NoticeMoneyUnit"); //接收支付公司金额单位
  64. fields.Add("AdColId"); //广告分类
  65. fields.Add("DefaultDeposit"); //默认押金
  66. fields.Add("MerNameWithStar"); //商户姓名是否带星号
  67. fields.Add("SingleDepositApi"); //单独押金推送接口
  68. fields.Add("ActTradeAmount"); //激活交易额
  69. fields.Add("PosPrice"); //机具单价
  70. fields.Add("MainStoreId"); //总仓
  71. fields.Add("SpProductType"); //原始数据品牌
  72. fields.Add("FluxAmount"); //流量费
  73. fields.Add("FluxProfit"); //流量费分佣
  74. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("KqProducts", relationData, orderBy, page, limit, condition, fields);
  75. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  76. return diclist;
  77. }
  78. /// <summary>
  79. /// 查询一条记录
  80. /// </summary>
  81. /// <param name="Id">主键Id</param>
  82. /// <returns></returns>
  83. public static KqProducts Query(int Id)
  84. {
  85. WebCMSEntities db = new WebCMSEntities();
  86. KqProducts editData = db.KqProducts.FirstOrDefault(m => m.Id == Id) ?? new KqProducts();
  87. db.Dispose();
  88. return editData;
  89. }
  90. /// <summary>
  91. /// 根据指定条件查询数据
  92. /// </summary>
  93. /// <param name="condition"></param>
  94. /// <returns></returns>
  95. public static KqProducts Query(string condition)
  96. {
  97. DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("*", "KqProducts", condition);
  98. if (dt.Rows.Count > 0)
  99. {
  100. Dictionary<string, object> row = new Dictionary<string, object>();
  101. foreach (DataColumn dc in dt.Columns)
  102. {
  103. row.Add(dc.ColumnName, dt.Rows[0][dc.ColumnName].ToString());
  104. }
  105. return Newtonsoft.Json.JsonConvert.DeserializeObject<KqProducts>(Newtonsoft.Json.JsonConvert.SerializeObject(row));
  106. }
  107. return new KqProducts();
  108. }
  109. /// <summary>
  110. /// 查询返回所有可用品牌
  111. /// </summary>
  112. /// <returns></returns>
  113. public static List<int> QueryBrandId()
  114. {
  115. WebCMSEntities db = new WebCMSEntities();
  116. List<int> BrandIds = new List<int>();
  117. var brandList = db.KqProducts.Where(m => m.Status == 1).ToList();
  118. foreach (var item in brandList)
  119. {
  120. BrandIds.Add(item.Id);
  121. }
  122. db.Dispose();
  123. return BrandIds;
  124. }
  125. /// <summary>
  126. /// 查询记录数
  127. /// </summary>
  128. /// <param name="Id">主键Id</param>
  129. /// <returns></returns>
  130. public static int Count(string condition = "")
  131. {
  132. int result = 0;
  133. DataTable dt = CustomerSqlConn.dtable("select count(Id) from KqProducts where 1=1" + condition, _conn);
  134. if (dt.Rows.Count > 0)
  135. {
  136. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  137. }
  138. return result;
  139. }
  140. /// <summary>
  141. /// 查询是否存在
  142. /// </summary>
  143. /// <param name="Id">主键Id</param>
  144. /// <returns></returns>
  145. public static bool Exist(int Id)
  146. {
  147. WebCMSEntities db = new WebCMSEntities();
  148. bool check = db.KqProducts.Any(m => m.Id == Id);
  149. db.Dispose();
  150. return check;
  151. }
  152. /// <summary>
  153. /// 添加数据
  154. /// </summary>
  155. /// <param name="Fields">要设置的字段</param>
  156. /// <returns></returns>
  157. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  158. {
  159. if (check)
  160. {
  161. if (string.IsNullOrEmpty(fields["Name"].ToString()))
  162. {
  163. return new AppResultJson() { Status = "-1", Info = "请填写名称" };
  164. }
  165. if (string.IsNullOrEmpty(fields["Kind"].ToString()))
  166. {
  167. return new AppResultJson() { Status = "-1", Info = "请填写类型" };
  168. }
  169. if (string.IsNullOrEmpty(fields["MinStock"].ToString()))
  170. {
  171. return new AppResultJson() { Status = "-1", Info = "请填写最低库存数" };
  172. }
  173. if (string.IsNullOrEmpty(fields["CountOfBox"].ToString()))
  174. {
  175. return new AppResultJson() { Status = "-1", Info = "请填写每箱机具台数" };
  176. }
  177. }
  178. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("KqProducts", fields, 0);
  179. return new AppResultJson() { Status = "1", Data = Id };
  180. }
  181. /// <summary>
  182. /// 修改数据
  183. /// </summary>
  184. /// <param name="Fields">要设置的字段</param>
  185. /// <param name="Id">主键Id</param>
  186. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  187. {
  188. if (check)
  189. {
  190. if (string.IsNullOrEmpty(fields["Name"].ToString()))
  191. {
  192. return new AppResultJson() { Status = "-1", Info = "请填写名称" };
  193. }
  194. if (string.IsNullOrEmpty(fields["Kind"].ToString()))
  195. {
  196. return new AppResultJson() { Status = "-1", Info = "请填写类型" };
  197. }
  198. if (string.IsNullOrEmpty(fields["MinStock"].ToString()))
  199. {
  200. return new AppResultJson() { Status = "-1", Info = "请填写最低库存数" };
  201. }
  202. if (string.IsNullOrEmpty(fields["CountOfBox"].ToString()))
  203. {
  204. return new AppResultJson() { Status = "-1", Info = "请填写每箱机具台数" };
  205. }
  206. }
  207. new DbService(AppConfig.Base.mainTables, _conn).Edit("KqProducts", fields, Id);
  208. return new AppResultJson() { Status = "1", Data = Id };
  209. }
  210. /// <summary>
  211. /// 逻辑删除
  212. /// </summary>
  213. /// <param name="Id">主键Id</param>
  214. public static void Remove(int Id)
  215. {
  216. Dictionary<string, object> fields = new Dictionary<string, object>();
  217. fields.Add("Status", -1);
  218. new DbService(AppConfig.Base.mainTables, _conn).Edit("KqProducts", fields, Id);
  219. }
  220. /// <summary>
  221. /// 删除数据
  222. /// </summary>
  223. /// <param name="Id">主键Id</param>
  224. public static void Delete(int Id)
  225. {
  226. new DbService(AppConfig.Base.mainTables, _conn).Delete("KqProducts", Id);
  227. }
  228. /// <summary>
  229. /// 排序
  230. /// </summary>
  231. /// <param name="Id">主键Id</param>
  232. /// <param name="Sort">排序序号</param>
  233. public static void Sort(int Id, int Sort)
  234. {
  235. new DbService(AppConfig.Base.mainTables, _conn).Sort("KqProducts", Sort, Id);
  236. }
  237. /// <summary>
  238. /// 导入数据
  239. /// </summary>
  240. /// <param name="ExcelData">json数据</param>
  241. public static void Import(string ExcelData)
  242. {
  243. WebCMSEntities db = new WebCMSEntities();
  244. JsonData list = JsonMapper.ToObject(ExcelData);
  245. for (int i = 1; i < list.Count; i++)
  246. {
  247. JsonData dr = list[i];
  248. db.KqProducts.Add(new KqProducts()
  249. {
  250. CreateDate = DateTime.Now,
  251. UpdateDate = DateTime.Now,
  252. });
  253. db.SaveChanges();
  254. }
  255. db.Dispose();
  256. }
  257. /// <summary>
  258. /// 导出excel表格
  259. /// </summary>
  260. /// <param name="fields">查询条件(单个字段)</param>
  261. /// <param name="condition">查询条件(sql语句)</param>
  262. /// <returns></returns>
  263. // public static void ExportExcel(List<RelationData> relationData, string condition)
  264. // {
  265. // }
  266. }
  267. }