UserCardForWeChatService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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 UserCardForWeChatService
  14. {
  15. string _conn = "";
  16. public UserCardForWeChatService()
  17. {
  18. _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  19. }
  20. /// <summary>
  21. /// 查询列表
  22. /// </summary>
  23. /// <param name="relationData">关联表</param>
  24. /// <param name="condition">查询条件(sql语句)</param>
  25. /// <param name="count">总数(输出)</param>
  26. /// <param name="page">页码</param>
  27. /// <param name="limit">每页条数</param>
  28. /// <returns></returns>
  29. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, out int count, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  30. {
  31. List<string> fields = new List<string>(); //要显示的列
  32. fields.Add("Id");
  33. fields.Add("CreateDate"); //添加时间
  34. fields.Add("Status"); //状态
  35. fields.Add("CardType"); //会员卡类型
  36. fields.Add("CodeType"); //展示类型
  37. fields.Add("BrandName"); //商户名字
  38. fields.Add("Title"); //卡券名
  39. fields.Add("Notice"); //卡券使用提醒
  40. fields.Add("DateType"); //使用时间类型
  41. fields.Add("MerchantId"); //商户
  42. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("UserCardForWeChat", relationData, orderBy, page, limit, condition, fields);
  43. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  44. count = int.Parse(obj["count"].ToString());
  45. return diclist;
  46. }
  47. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  48. {
  49. List<string> fields = new List<string>(); //要显示的列
  50. fields.Add("Id");
  51. fields.Add("CreateDate"); //添加时间
  52. fields.Add("Status"); //状态
  53. fields.Add("CardType"); //会员卡类型
  54. fields.Add("CodeType"); //展示类型
  55. fields.Add("BrandName"); //商户名字
  56. fields.Add("Title"); //卡券名
  57. fields.Add("Notice"); //卡券使用提醒
  58. fields.Add("DateType"); //使用时间类型
  59. fields.Add("MerchantId"); //商户
  60. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("UserCardForWeChat", relationData, orderBy, page, limit, condition, fields);
  61. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  62. return diclist;
  63. }
  64. /// <summary>
  65. /// 查询一条记录
  66. /// </summary>
  67. /// <param name="Id">主键Id</param>
  68. /// <returns></returns>
  69. public UserCardForWeChat Query(int Id)
  70. {
  71. WebCMSEntities db = new WebCMSEntities();
  72. UserCardForWeChat editData = db.UserCardForWeChat.FirstOrDefault(m => m.Id == Id) ?? new UserCardForWeChat();
  73. db.Dispose();
  74. return editData;
  75. }
  76. /// <summary>
  77. /// 查询记录数
  78. /// </summary>
  79. /// <param name="Id">主键Id</param>
  80. /// <returns></returns>
  81. public int Count(string condition = "")
  82. {
  83. int result = 0;
  84. DataTable dt = CustomerSqlConn.dtable("select count(Id) from UserCardForWeChat where 1=1" + condition, _conn);
  85. if(dt.Rows.Count > 0)
  86. {
  87. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  88. }
  89. return result;
  90. }
  91. /// <summary>
  92. /// 查询是否存在
  93. /// </summary>
  94. /// <param name="Id">主键Id</param>
  95. /// <returns></returns>
  96. public bool Exist(int Id)
  97. {
  98. WebCMSEntities db = new WebCMSEntities();
  99. bool check = db.UserCardForWeChat.Any(m => m.Id == Id);
  100. db.Dispose();
  101. return check;
  102. }
  103. /// <summary>
  104. /// 添加数据
  105. /// </summary>
  106. /// <param name="Fields">要设置的字段</param>
  107. /// <returns></returns>
  108. public AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  109. {
  110. if(check)
  111. {
  112. if (string.IsNullOrEmpty(fields["LogoUrl"].ToString()))
  113. {
  114. return new AppResultJson() { Status = "-1", Info = "请填写商户logo" };
  115. }
  116. if (string.IsNullOrEmpty(fields["CodeType"].ToString()))
  117. {
  118. return new AppResultJson() { Status = "-1", Info = "请填写展示类型" };
  119. }
  120. if (string.IsNullOrEmpty(fields["BrandName"].ToString()))
  121. {
  122. return new AppResultJson() { Status = "-1", Info = "请填写商户名字" };
  123. }
  124. if (string.IsNullOrEmpty(fields["Title"].ToString()))
  125. {
  126. return new AppResultJson() { Status = "-1", Info = "请填写卡券名" };
  127. }
  128. if (string.IsNullOrEmpty(fields["Color"].ToString()))
  129. {
  130. return new AppResultJson() { Status = "-1", Info = "请填写券颜色" };
  131. }
  132. if (string.IsNullOrEmpty(fields["Notice"].ToString()))
  133. {
  134. return new AppResultJson() { Status = "-1", Info = "请填写卡券使用提醒" };
  135. }
  136. if (string.IsNullOrEmpty(fields["Description"].ToString()))
  137. {
  138. return new AppResultJson() { Status = "-1", Info = "请填写卡券使用说明" };
  139. }
  140. if (string.IsNullOrEmpty(fields["Quantity"].ToString()))
  141. {
  142. return new AppResultJson() { Status = "-1", Info = "请填写卡券库存的数量" };
  143. }
  144. if (!function.IsInt(fields["Quantity"].ToString()))
  145. {
  146. return new AppResultJson() { Status = "-1", Info = "请填写正确的卡券库存的数量" };
  147. }
  148. if (string.IsNullOrEmpty(fields["DateType"].ToString()))
  149. {
  150. return new AppResultJson() { Status = "-1", Info = "请填写使用时间类型" };
  151. }
  152. if (string.IsNullOrEmpty(fields["SupplyBonus"].ToString()))
  153. {
  154. return new AppResultJson() { Status = "-1", Info = "请填写显示积分" };
  155. }
  156. if (string.IsNullOrEmpty(fields["SupplyBalance"].ToString()))
  157. {
  158. return new AppResultJson() { Status = "-1", Info = "请填写是否支持储值" };
  159. }
  160. if (string.IsNullOrEmpty(fields["EnterName"].ToString()))
  161. {
  162. return new AppResultJson() { Status = "-1", Info = "请填写入口名称" };
  163. }
  164. if (string.IsNullOrEmpty(fields["EnterUrl"].ToString()))
  165. {
  166. return new AppResultJson() { Status = "-1", Info = "请填写入口跳转链接" };
  167. }
  168. }
  169. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("UserCardForWeChat", fields, 0);
  170. return new AppResultJson(){ Status = "1", Data = Id };
  171. }
  172. /// <summary>
  173. /// 修改数据
  174. /// </summary>
  175. /// <param name="Fields">要设置的字段</param>
  176. /// <param name="Id">主键Id</param>
  177. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  178. {
  179. if(check)
  180. {
  181. if (string.IsNullOrEmpty(fields["LogoUrl"].ToString()))
  182. {
  183. return new AppResultJson() { Status = "-1", Info = "请填写商户logo" };
  184. }
  185. if (string.IsNullOrEmpty(fields["CodeType"].ToString()))
  186. {
  187. return new AppResultJson() { Status = "-1", Info = "请填写展示类型" };
  188. }
  189. if (string.IsNullOrEmpty(fields["BrandName"].ToString()))
  190. {
  191. return new AppResultJson() { Status = "-1", Info = "请填写商户名字" };
  192. }
  193. if (string.IsNullOrEmpty(fields["Title"].ToString()))
  194. {
  195. return new AppResultJson() { Status = "-1", Info = "请填写卡券名" };
  196. }
  197. if (string.IsNullOrEmpty(fields["Color"].ToString()))
  198. {
  199. return new AppResultJson() { Status = "-1", Info = "请填写券颜色" };
  200. }
  201. if (string.IsNullOrEmpty(fields["Notice"].ToString()))
  202. {
  203. return new AppResultJson() { Status = "-1", Info = "请填写卡券使用提醒" };
  204. }
  205. if (string.IsNullOrEmpty(fields["Description"].ToString()))
  206. {
  207. return new AppResultJson() { Status = "-1", Info = "请填写卡券使用说明" };
  208. }
  209. if (string.IsNullOrEmpty(fields["Quantity"].ToString()))
  210. {
  211. return new AppResultJson() { Status = "-1", Info = "请填写卡券库存的数量" };
  212. }
  213. if (!function.IsInt(fields["Quantity"].ToString()))
  214. {
  215. return new AppResultJson() { Status = "-1", Info = "请填写正确的卡券库存的数量" };
  216. }
  217. if (string.IsNullOrEmpty(fields["DateType"].ToString()))
  218. {
  219. return new AppResultJson() { Status = "-1", Info = "请填写使用时间类型" };
  220. }
  221. if (string.IsNullOrEmpty(fields["SupplyBonus"].ToString()))
  222. {
  223. return new AppResultJson() { Status = "-1", Info = "请填写显示积分" };
  224. }
  225. if (string.IsNullOrEmpty(fields["SupplyBalance"].ToString()))
  226. {
  227. return new AppResultJson() { Status = "-1", Info = "请填写是否支持储值" };
  228. }
  229. if (string.IsNullOrEmpty(fields["EnterName"].ToString()))
  230. {
  231. return new AppResultJson() { Status = "-1", Info = "请填写入口名称" };
  232. }
  233. if (string.IsNullOrEmpty(fields["EnterUrl"].ToString()))
  234. {
  235. return new AppResultJson() { Status = "-1", Info = "请填写入口跳转链接" };
  236. }
  237. }
  238. new DbService(AppConfig.Base.dbTables, _conn).Edit("UserCardForWeChat", fields, Id);
  239. return new AppResultJson(){ Status = "1", Data = Id };
  240. }
  241. /// <summary>
  242. /// 逻辑删除
  243. /// </summary>
  244. /// <param name="Id">主键Id</param>
  245. public void Remove(int Id)
  246. {
  247. Dictionary<string, object> fields = new Dictionary<string, object>();
  248. fields.Add("Status", -1);
  249. new DbService(AppConfig.Base.dbTables, _conn).Edit("UserCardForWeChat", fields, Id);
  250. }
  251. /// <summary>
  252. /// 删除数据
  253. /// </summary>
  254. /// <param name="Id">主键Id</param>
  255. public void Delete(int Id)
  256. {
  257. new DbService(AppConfig.Base.dbTables, _conn).Delete("UserCardForWeChat", Id);
  258. }
  259. /// <summary>
  260. /// 排序
  261. /// </summary>
  262. /// <param name="Id">主键Id</param>
  263. /// <param name="Sort">排序序号</param>
  264. public void Sort(int Id, int Sort)
  265. {
  266. new DbService(AppConfig.Base.dbTables, _conn).Sort("UserCardForWeChat", Sort, Id);
  267. }
  268. /// <summary>
  269. /// 导入数据
  270. /// </summary>
  271. /// <param name="ExcelData">json数据</param>
  272. public void Import(string ExcelData)
  273. {
  274. WebCMSEntities db = new WebCMSEntities();
  275. JsonData list = JsonMapper.ToObject(ExcelData);
  276. for (int i = 1; i < list.Count;i++ )
  277. {
  278. JsonData dr = list[i];
  279. db.UserCardForWeChat.Add(new UserCardForWeChat()
  280. {
  281. CreateDate = DateTime.Now,
  282. UpdateDate = DateTime.Now,
  283. });
  284. db.SaveChanges();
  285. }
  286. db.Dispose();
  287. }
  288. /// <summary>
  289. /// 导出excel表格
  290. /// </summary>
  291. /// <param name="fields">查询条件(单个字段)</param>
  292. /// <param name="condition">查询条件(sql语句)</param>
  293. /// <returns></returns>
  294. // public void ExportExcel(List<RelationData> relationData, string condition)
  295. // {
  296. // }
  297. }
  298. }