MerchantForMobileService.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 MerchantForMobileService
  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 = 30, 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("Mobile"); //手机号
  33. fields.Add("Areas"); //所在地区
  34. fields.Add("Address"); //详细地址
  35. fields.Add("IsAuth"); //是否认证
  36. fields.Add("TotalAmount"); //平台总收益
  37. fields.Add("TotalOrder"); //累计订单
  38. fields.Add("TotalCustomer"); //累计客户
  39. fields.Add("TotalUser"); //会员数
  40. fields.Add("TotalActual"); //营收总额
  41. fields.Add("LastAddConsumerDate"); //最后加入会员时间
  42. fields.Add("TotalConsumeCount"); //累计消费次数
  43. fields.Add("LastConsumeDate"); //最后消费时间
  44. fields.Add("UserId"); //所属创客
  45. fields.Add("ActivationStatus"); //激活状态
  46. fields.Add("ActivationDate"); //激活时间
  47. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantForMobile", 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("Mobile"); //手机号
  60. fields.Add("Areas"); //所在地区
  61. fields.Add("Address"); //详细地址
  62. fields.Add("IsAuth"); //是否认证
  63. fields.Add("TotalAmount"); //平台总收益
  64. fields.Add("TotalOrder"); //累计订单
  65. fields.Add("TotalCustomer"); //累计客户
  66. fields.Add("TotalUser"); //会员数
  67. fields.Add("TotalActual"); //营收总额
  68. fields.Add("LastAddConsumerDate"); //最后加入会员时间
  69. fields.Add("TotalConsumeCount"); //累计消费次数
  70. fields.Add("LastConsumeDate"); //最后消费时间
  71. fields.Add("UserId"); //所属创客
  72. fields.Add("ActivationStatus"); //激活状态
  73. fields.Add("ActivationDate"); //激活时间
  74. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantForMobile", 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="Mobile">手机号</param>
  82. /// <returns></returns>
  83. public static MerchantForMobile Query(string Mobile)
  84. {
  85. WebCMSEntities db = new WebCMSEntities();
  86. MerchantForMobile editData = db.MerchantForMobile.FirstOrDefault(m => m.Mobile == Mobile) ?? new MerchantForMobile();
  87. db.Dispose();
  88. return editData;
  89. }
  90. public static MerchantForMobile Query(string condition, string fields = "*")
  91. {
  92. var MerchantForMobile = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "MerchantForMobile", condition);
  93. if (MerchantForMobile.Count > 0)
  94. {
  95. return Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantForMobile>(Newtonsoft.Json.JsonConvert.SerializeObject(MerchantForMobile));
  96. }
  97. return new MerchantForMobile();
  98. }
  99. public static decimal Sum(string condition, string field)
  100. {
  101. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Sum(" + field + ") " + field, "MerchantForMobile", condition);
  102. decimal amount = 0;
  103. if (dt.Count > 0)
  104. {
  105. amount = decimal.Parse(dt[field].ToString());
  106. }
  107. return amount;
  108. }
  109. /// <summary>
  110. /// 查询记录数
  111. /// </summary>
  112. /// <param name="Id">主键Id</param>
  113. /// <returns></returns>
  114. public static int Count(string condition = "", string field = "Id")
  115. {
  116. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "MerchantForMobile", condition);
  117. int result = 0;
  118. if (dt.Count > 0)
  119. {
  120. result = int.Parse(dt[field].ToString());
  121. }
  122. return result;
  123. }
  124. /// <summary>
  125. /// 查询是否存在
  126. /// </summary>
  127. /// <param name="Id">主键Id</param>
  128. /// <returns></returns>
  129. public static bool Exist(int Id)
  130. {
  131. WebCMSEntities db = new WebCMSEntities();
  132. bool check = db.MerchantForMobile.Any(m => m.MerchantId == Id);
  133. db.Dispose();
  134. return check;
  135. }
  136. /// <summary>
  137. /// 添加数据
  138. /// </summary>
  139. /// <param name="Fields">要设置的字段</param>
  140. /// <returns></returns>
  141. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  142. {
  143. if (check)
  144. {
  145. if (string.IsNullOrEmpty(fields["Name"].ToString()))
  146. {
  147. return new AppResultJson() { Status = "-1", Info = "请填写名称" };
  148. }
  149. if (string.IsNullOrEmpty(fields["Mobile"].ToString()))
  150. {
  151. return new AppResultJson() { Status = "-1", Info = "请填写手机号" };
  152. }
  153. }
  154. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("MerchantForMobile", fields, 0);
  155. return new AppResultJson() { Status = "1", Data = Id };
  156. }
  157. /// <summary>
  158. /// 修改数据
  159. /// </summary>
  160. /// <param name="Fields">要设置的字段</param>
  161. /// <param name="Id">主键Id</param>
  162. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  163. {
  164. if (check)
  165. {
  166. if (string.IsNullOrEmpty(fields["Name"].ToString()))
  167. {
  168. return new AppResultJson() { Status = "-1", Info = "请填写名称" };
  169. }
  170. if (string.IsNullOrEmpty(fields["Mobile"].ToString()))
  171. {
  172. return new AppResultJson() { Status = "-1", Info = "请填写手机号" };
  173. }
  174. }
  175. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantForMobile", fields, Id);
  176. return new AppResultJson() { Status = "1", Data = Id };
  177. }
  178. /// <summary>
  179. /// 逻辑删除
  180. /// </summary>
  181. /// <param name="Id">主键Id</param>
  182. public static void Remove(int Id)
  183. {
  184. Dictionary<string, object> fields = new Dictionary<string, object>();
  185. fields.Add("Status", -1);
  186. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantForMobile", fields, Id);
  187. }
  188. /// <summary>
  189. /// 删除数据
  190. /// </summary>
  191. /// <param name="Id">主键Id</param>
  192. public static void Delete(int Id)
  193. {
  194. new DbService(AppConfig.Base.mainTables, _conn).Delete("MerchantForMobile", Id);
  195. }
  196. /// <summary>
  197. /// 排序
  198. /// </summary>
  199. /// <param name="Id">主键Id</param>
  200. /// <param name="Sort">排序序号</param>
  201. public static void Sort(int Id, int Sort)
  202. {
  203. new DbService(AppConfig.Base.mainTables, _conn).Sort("MerchantForMobile", Sort, Id);
  204. }
  205. // /// <summary>
  206. // /// 导入数据
  207. // /// </summary>
  208. // /// <param name="ExcelData">json数据</param>
  209. // public static void Import(string ExcelData)
  210. // {
  211. // WebCMSEntities db = new WebCMSEntities();
  212. // JsonData list = JsonMapper.ToObject(ExcelData);
  213. // for (int i = 1; i < list.Count; i++)
  214. // {
  215. // JsonData dr = list[i];
  216. // db.MerchantForMobile.Add(new MerchantForMobile()
  217. // {
  218. // CreateDate = DateTime.Now,
  219. // UpdateDate = DateTime.Now,
  220. // });
  221. // db.SaveChanges();
  222. // }
  223. // db.Dispose();
  224. // }
  225. /// <summary>
  226. /// 导出excel表格
  227. /// </summary>
  228. /// <param name="fields">查询条件(单个字段)</param>
  229. /// <param name="condition">查询条件(sql语句)</param>
  230. /// <returns></returns>
  231. // public static void ExportExcel(List<RelationData> relationData, string condition)
  232. // {
  233. // }
  234. }
  235. }