OrdersService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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 OrdersService
  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("UserId"); //创客
  32. fields.Add("OrderNo"); //订单号
  33. fields.Add("RealName"); //姓名
  34. fields.Add("Mobile"); //手机号
  35. fields.Add("TotalPrice"); //总价
  36. fields.Add("Areas"); //所在地区
  37. fields.Add("Address"); //详细地址
  38. fields.Add("ErpName"); //物流名称
  39. fields.Add("ErpCode"); //运单号
  40. fields.Add("SendDate"); //发货时间
  41. fields.Add("PayDate"); //支付时间
  42. fields.Add("PayMode"); //支付方式
  43. fields.Add("TradeNo"); //支付交易号
  44. fields.Add("StoreId"); //仓库
  45. fields.Add("RefundStatus"); //退款状态
  46. fields.Add("DeliveryType"); //提货类型
  47. fields.Add("SendStatus"); //发货状态
  48. fields.Add("ProductId"); //商品名称
  49. fields.Add("StoreContact"); //仓库联系人
  50. fields.Add("StoreType"); //仓库类型
  51. fields.Add("StoreUserId"); //仓库归属创客
  52. fields.Add("TopUserId"); //顶级创客
  53. fields.Add("PayStatus"); //支付状态
  54. fields.Add("BuyCount"); //下单数量
  55. fields.Add("Remark"); //订单备注
  56. fields.Add("StoreContactMobile"); //仓库联系人电话
  57. fields.Add("ParentOrderId"); //父级订单
  58. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("Orders", relationData, orderBy, page, limit, condition, fields);
  59. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  60. count = int.Parse(obj["count"].ToString());
  61. return diclist;
  62. }
  63. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  64. {
  65. List<string> fields = new List<string>(); //要显示的列
  66. fields.Add("Id");
  67. fields.Add("CreateDate"); //添加时间
  68. fields.Add("Status"); //状态
  69. fields.Add("UserId"); //创客
  70. fields.Add("OrderNo"); //订单号
  71. fields.Add("RealName"); //姓名
  72. fields.Add("Mobile"); //手机号
  73. fields.Add("TotalPrice"); //总价
  74. fields.Add("Areas"); //所在地区
  75. fields.Add("Address"); //详细地址
  76. fields.Add("ErpName"); //物流名称
  77. fields.Add("ErpCode"); //运单号
  78. fields.Add("SendDate"); //发货时间
  79. fields.Add("PayDate"); //支付时间
  80. fields.Add("PayMode"); //支付方式
  81. fields.Add("TradeNo"); //支付交易号
  82. fields.Add("StoreId"); //仓库
  83. fields.Add("RefundStatus"); //退款状态
  84. fields.Add("DeliveryType"); //提货类型
  85. fields.Add("SendStatus"); //发货状态
  86. fields.Add("ProductId"); //商品名称
  87. fields.Add("StoreContact"); //仓库联系人
  88. fields.Add("StoreType"); //仓库类型
  89. fields.Add("StoreUserId"); //仓库归属创客
  90. fields.Add("TopUserId"); //顶级创客
  91. fields.Add("PayStatus"); //支付状态
  92. fields.Add("BuyCount"); //下单数量
  93. fields.Add("Remark"); //订单备注
  94. fields.Add("StoreContactMobile"); //仓库联系人电话
  95. fields.Add("ParentOrderId"); //父级订单
  96. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("Orders", relationData, orderBy, page, limit, condition, fields);
  97. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  98. return diclist;
  99. }
  100. /// <summary>
  101. /// 查询一条记录
  102. /// </summary>
  103. /// <param name="Id">主键Id</param>
  104. /// <returns></returns>
  105. public static Orders Query(int Id)
  106. {
  107. WebCMSEntities db = new WebCMSEntities();
  108. Orders editData = db.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
  109. db.Dispose();
  110. return editData;
  111. }
  112. public static Orders Query(string condition, string fields = "*")
  113. {
  114. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail(fields, "Orders", condition);
  115. // if (dt.Rows.Count > 0)
  116. // {
  117. // Dictionary<string, object> row = new Dictionary<string, object>();
  118. // foreach (DataColumn dc in dt.Columns)
  119. // {
  120. // row.Add(dc.ColumnName, dt.Rows[0][dc.ColumnName].ToString());
  121. // }
  122. // return Newtonsoft.Json.JsonConvert.DeserializeObject<Orders>(Newtonsoft.Json.JsonConvert.SerializeObject(row));
  123. // }
  124. // return new Orders();
  125. var orders = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "Orders", condition);
  126. if (orders.Count > 0)
  127. {
  128. return Newtonsoft.Json.JsonConvert.DeserializeObject<Orders>(Newtonsoft.Json.JsonConvert.SerializeObject(orders));
  129. }
  130. return new Orders();
  131. }
  132. public static decimal Sum(string condition, string field)
  133. {
  134. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("Sum(" + field + ")", "Orders", condition);
  135. // decimal amount = 0;
  136. // if (dt.Rows.Count > 0)
  137. // {
  138. // amount = decimal.Parse(dt.Rows[0][0].ToString());
  139. // }
  140. // return amount;
  141. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "OrderProduct", condition);
  142. decimal amount = 0;
  143. if (dt.Count > 0)
  144. {
  145. amount = decimal.Parse(dt[field].ToString());
  146. }
  147. return amount;
  148. }
  149. /// <summary>
  150. /// 查询记录数
  151. /// </summary>
  152. /// <param name="Id">主键Id</param>
  153. /// <returns></returns>
  154. public static int Count(string condition = "", string field = "Id")
  155. {
  156. // int result = 0;
  157. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("count(" + field + ")", "Orders", condition);
  158. // if (dt.Rows.Count > 0)
  159. // {
  160. // result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  161. // }
  162. // return result;
  163. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "Orders", condition);
  164. int result = 0;
  165. if (dt.Count > 0)
  166. {
  167. result = int.Parse(dt[field].ToString());
  168. }
  169. return result;
  170. }
  171. /// <summary>
  172. /// 查询是否存在
  173. /// </summary>
  174. /// <param name="Id">主键Id</param>
  175. /// <returns></returns>
  176. public static bool Exist(int Id)
  177. {
  178. WebCMSEntities db = new WebCMSEntities();
  179. bool check = db.Orders.Any(m => m.Id == Id);
  180. db.Dispose();
  181. return check;
  182. }
  183. /// <summary>
  184. /// 添加数据
  185. /// </summary>
  186. /// <param name="Fields">要设置的字段</param>
  187. /// <returns></returns>
  188. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  189. {
  190. if (check)
  191. {
  192. }
  193. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("Orders", fields, 0);
  194. return new AppResultJson() { Status = "1", Data = Id };
  195. }
  196. /// <summary>
  197. /// 修改数据
  198. /// </summary>
  199. /// <param name="Fields">要设置的字段</param>
  200. /// <param name="Id">主键Id</param>
  201. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  202. {
  203. if (check)
  204. {
  205. }
  206. new DbService(AppConfig.Base.mainTables, _conn).Edit("Orders", fields, Id);
  207. return new AppResultJson() { Status = "1", Data = Id };
  208. }
  209. /// <summary>
  210. /// 逻辑删除
  211. /// </summary>
  212. /// <param name="Id">主键Id</param>
  213. public static void Remove(int Id)
  214. {
  215. Dictionary<string, object> fields = new Dictionary<string, object>();
  216. fields.Add("Status", -1);
  217. new DbService(AppConfig.Base.mainTables, _conn).Edit("Orders", fields, Id);
  218. }
  219. /// <summary>
  220. /// 删除数据
  221. /// </summary>
  222. /// <param name="Id">主键Id</param>
  223. public static void Delete(int Id)
  224. {
  225. new DbService(AppConfig.Base.mainTables, _conn).Delete("Orders", Id);
  226. }
  227. /// <summary>
  228. /// 排序
  229. /// </summary>
  230. /// <param name="Id">主键Id</param>
  231. /// <param name="Sort">排序序号</param>
  232. public static void Sort(int Id, int Sort)
  233. {
  234. new DbService(AppConfig.Base.mainTables, _conn).Sort("Orders", Sort, Id);
  235. }
  236. /// <summary>
  237. /// 导入数据
  238. /// </summary>
  239. /// <param name="ExcelData">json数据</param>
  240. public static void Import(string ExcelData)
  241. {
  242. WebCMSEntities db = new WebCMSEntities();
  243. JsonData list = JsonMapper.ToObject(ExcelData);
  244. for (int i = 1; i < list.Count; i++)
  245. {
  246. JsonData dr = list[i];
  247. db.Orders.Add(new Orders()
  248. {
  249. CreateDate = DateTime.Now,
  250. UpdateDate = DateTime.Now,
  251. });
  252. db.SaveChanges();
  253. }
  254. db.Dispose();
  255. }
  256. /// <summary>
  257. /// 导出excel表格
  258. /// </summary>
  259. /// <param name="fields">查询条件(单个字段)</param>
  260. /// <param name="condition">查询条件(sql语句)</param>
  261. /// <returns></returns>
  262. // public static void ExportExcel(List<RelationData> relationData, string condition)
  263. // {
  264. // }
  265. }
  266. }