您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AppletService.cs 20 KiB

1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
11 个月前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
11 个月前
1年前
1年前
1年前
11 个月前
1年前
11 个月前
1年前
11 个月前
1年前
11 个月前
1年前
11 个月前
1年前
11 个月前
1年前
1年前
11 个月前
1年前
11 个月前
1年前
11 个月前
1年前
11 个月前
1年前
11 个月前
1年前
11 个月前
1年前
11 个月前
1年前
11 个月前
1年前
1年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. using BPA.KitChen.GroupMeal.Application.BaseDto;
  2. using BPA.KitChen.GroupMeal.Application.Service.Applet.Dtos;
  3. using BPA.KitChen.GroupMeal.Application.Service.OneCard.StoredValueCard;
  4. using BPA.KitChen.GroupMeal.Core.Common.Const;
  5. using BPA.KitChen.GroupMeal.Core.Entity;
  6. using BPA.KitChen.GroupMeal.SqlSugar;
  7. using Furion;
  8. using Furion.DependencyInjection;
  9. using Furion.DynamicApiController;
  10. using Furion.FriendlyException;
  11. using Mapster;
  12. using Microsoft.AspNetCore.Authorization;
  13. using Microsoft.AspNetCore.Mvc;
  14. using SqlSugar;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Security.Claims;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. namespace BPA.KitChen.GroupMeal.Application.Service.Applet
  22. {
  23. [ApiDescriptionSettings("小程序管理", Tag = "页面管理", SplitCamelCase = false)]
  24. public class AppletService : SupperRepository, IDynamicApiController, IAppletService, ITransient
  25. {
  26. private readonly SqlSugarScope db;
  27. public AppletService()
  28. {
  29. db = SqlSugarDb.Db; ; // 推荐操作
  30. }
  31. #region 页面管理
  32. /// <summary>
  33. /// 增加小程序页面
  34. /// </summary>
  35. /// <param name="input"></param>
  36. [HttpPost("/api/AppletService/add")]
  37. public async Task Add(AddMiniStorePageInput input)
  38. {
  39. MiniStorePage data = input.Adapt<MiniStorePage>();
  40. //var res = await db.Queryable<MiniStorePage>().FirstAsync(x => x.PageRoute == input.PageRoute);
  41. //if (res !=null)
  42. //{
  43. // throw Oops.Bah("页面路由地址相同");
  44. //}
  45. data.FranchiseeId = App.User?.FindFirstValue(ClaimConst.GroupId);
  46. await db.Insertable(data).ExecuteCommandAsync();
  47. }
  48. /// <summary>
  49. /// 小程序页面分页查询
  50. /// </summary>
  51. /// <param name="input"></param>
  52. /// <returns></returns>
  53. [HttpPost("/api/AppletService/page")]
  54. public async Task<SqlSugarPagedList<MiniStorePageOutput>> Page(QueryMiniStorePageInput input)
  55. {
  56. var datas = await db.Queryable<MiniStorePage>().Where(x => x.StoreId == input.StoreId).Select(o =>
  57. new MiniStorePageOutput
  58. {
  59. StoreId = o.StoreId,
  60. FranchiseeId = o.FranchiseeId,
  61. PageName = o.PageName,
  62. PageRoute = o.PageRoute,
  63. Id = o.Id
  64. }).ToPagedListAsync(input.Current, input.PageSize);
  65. return datas;
  66. }
  67. /// <summary>
  68. /// 删除小程序页面
  69. /// </summary>
  70. [HttpPost("/api/AppletService/del")]
  71. public async Task Del(DelMiniStorePageInput input)
  72. {
  73. var data = await db.Queryable<MiniStorePage>().FirstAsync(x => x.Id == input.Id);
  74. if (data == null)
  75. {
  76. throw Oops.Bah("没有找到数据");
  77. }
  78. db.Deleteable<MiniStorePage>().Where(x => x.Id == input.Id).ExecuteCommand();
  79. }
  80. /// <summary>
  81. /// 小程序页面下拉列表
  82. /// </summary>
  83. /// <exception cref="System.NotImplementedException"></exception>
  84. [HttpGet("/api/AppletService/list")]
  85. public async Task<List<MiniStoreSelection>> List(QueryMiniStorePageInput input)
  86. {
  87. var datas = await db.Queryable<MiniStorePage>().WhereIF(!string.IsNullOrEmpty(input.StoreId), x => x.StoreId == input.StoreId).ToListAsync();
  88. var res = datas.Select(x => new MiniStoreSelection
  89. {
  90. Key = x.Id,
  91. Value = x.PageName
  92. }).ToList();
  93. return res;
  94. }
  95. /// <summary>
  96. /// 更新小程序页面
  97. /// </summary>
  98. /// <param name="input"></param>
  99. [HttpPost("/api/AppletService/update")]
  100. public async Task Update(UpdateMiniStorePageInput input)
  101. {
  102. var data = await db.Queryable<MiniStorePage>().FirstAsync(x => x.Id == input.Id);
  103. if (data == null)
  104. {
  105. throw Oops.Bah("没有找到数据");
  106. }
  107. data.PageName = input.PageName;
  108. data.PageRoute = input.PageRoute;
  109. data.StoreId = input.StoreId;
  110. db.Updateable(data).Where(x => x.Id == input.Id).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
  111. }
  112. #endregion
  113. #region 素材管理
  114. /// <summary>
  115. /// 页面素材添加
  116. /// </summary>
  117. /// <param name="input"></param>
  118. /// <returns></returns>
  119. /// <exception cref="System.NotImplementedException"></exception>
  120. [HttpPost("/api/AppletService/MaterialAdd")]
  121. public async Task MaterialAdd(AddMiniStorePageMaterialInput input)
  122. {
  123. var res = await db.Queryable<MiniStorePageConfig>().FirstAsync(x => x.MaterialCode == input.MaterialCode && x.PageId == input.PageId);
  124. if (res != null)
  125. {
  126. throw Oops.Bah("素材编码重复");
  127. }
  128. MiniStorePageConfig data = input.Adapt<MiniStorePageConfig>();
  129. await db.Insertable(data).ExecuteCommandAsync();
  130. }
  131. /// <summary>
  132. /// 页面素材删除
  133. /// </summary>
  134. /// <param name="input"></param>
  135. /// <returns></returns>
  136. /// <exception cref="System.NotImplementedException"></exception>
  137. [HttpPost("/api/AppletService/MaterialDel")]
  138. public async Task MaterialDel(DelMiniStorePageMaterialInput input)
  139. {
  140. var data = await db.Queryable<MiniStorePageConfig>().FirstAsync(x => x.Id == input.Id);
  141. if (data == null)
  142. {
  143. throw Oops.Bah("没有找到数据");
  144. }
  145. db.Deleteable<MiniStorePageConfig>().Where(x => x.Id == input.Id).ExecuteCommand();
  146. }
  147. /// <summary>
  148. /// 页面素材下拉列表
  149. /// </summary>
  150. /// <returns></returns>
  151. /// <exception cref="System.NotImplementedException"></exception>
  152. [HttpGet("/api/AppletService/MaterialList")]
  153. public async Task<List<MiniStoreSelection>> MaterialList()
  154. {
  155. var datas = await db.Queryable<MiniStorePageConfig>().ToListAsync();
  156. var res = datas.Select(x => new MiniStoreSelection
  157. {
  158. Key = x.Id,
  159. Value = x.MaterialName
  160. }).ToList();
  161. return res;
  162. }
  163. /// <summary>
  164. /// 页面素材分页
  165. /// </summary>
  166. /// <param name="input"></param>
  167. /// <returns></returns>
  168. /// <exception cref="System.NotImplementedException"></exception>
  169. [HttpPost("/api/AppletService/MaterialPage")]
  170. public async Task<SqlSugarPagedList<MiniStorePageMaterialOutput>> MaterialPage(QueryMiniStorePageMaterialInput input)
  171. {
  172. var datas = await db.Queryable<MiniStorePageConfig>().Where(x => x.PageId == input.PageId).Select(o =>
  173. new MiniStorePageMaterialOutput
  174. {
  175. MaterialCode = o.MaterialCode,
  176. MaterialName = o.MaterialName,
  177. MaterialPath = o.MaterialPath,
  178. PageId = o.PageId,
  179. Id = o.Id
  180. }).ToPagedListAsync(input.Current, input.PageSize);
  181. return datas;
  182. }
  183. /// <summary>
  184. /// 页面素材更新
  185. /// </summary>
  186. /// <param name="input"></param>
  187. /// <returns></returns>
  188. /// <exception cref="System.NotImplementedException"></exception>
  189. [HttpPost("/api/AppletService/MaterialUpdate")]
  190. public async Task MaterialUpdate(UpdateMiniStorePageMaterialInput input)
  191. {
  192. var data = await db.Queryable<MiniStorePageConfig>().FirstAsync(x => x.Id == input.Id);
  193. if (data == null)
  194. {
  195. throw Oops.Bah("没有找到数据");
  196. }
  197. //判断编码重复
  198. var data1 = await db.Queryable<MiniStorePageConfig>().FirstAsync(x => x.Id != input.Id && x.MaterialCode == input.MaterialCode && x.PageId == input.PageId);
  199. if (data1 != null)
  200. {
  201. throw Oops.Bah("编码重复");
  202. }
  203. data.MaterialName = input.MaterialName;
  204. data.MaterialPath = input.MaterialPath;
  205. data.PageId = input.PageId;
  206. data.MaterialCode = input.MaterialCode;
  207. db.Updateable(data).Where(x => x.Id == input.Id).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
  208. }
  209. /// <summary>
  210. /// 根据店铺id查询页面布局素材
  211. /// </summary>
  212. /// <returns></returns>
  213. [HttpPost("/api/AppletService/MiniStoreMaterial")]
  214. [AllowAnonymous]
  215. public async Task<SqlSugarPagedList<MiniStorePageConfigOutput>> MiniStoreMaterial(QueryMiniStorePageInput input)
  216. {
  217. List<MiniStorePageConfigOutput> outputs = new();
  218. var datas = await db.Queryable<MiniStorePage>().Where(x => x.StoreId == input.StoreId && x.Id == input.PageId).ToListAsync();
  219. if (datas.Count > 0)
  220. {
  221. var ids = datas.Select(x => x.Id);
  222. var pageList = await db.Queryable<MiniStorePageConfig>().Where(x => ids.Contains(x.PageId))
  223. .OrderBy(x => x.Id)
  224. .ToPagedListAsync(input.Current, input.PageSize);
  225. MiniStorePageConfigOutput output = new();
  226. output.PageName = datas[0]?.PageName ?? "";
  227. output.PageRoute = datas[0]?.PageRoute ?? "";
  228. foreach (var materialItem in pageList.Items)
  229. {
  230. MiniStorePageMaterialOutput material = new();
  231. material.MaterialName = materialItem.MaterialName;
  232. material.MaterialPath = materialItem.MaterialPath;
  233. material.PageId = materialItem.PageId;
  234. material.MaterialCode = materialItem.MaterialCode;
  235. material.Id = materialItem.Id;
  236. output.List.Add(material);
  237. }
  238. outputs.Add(output);
  239. return new SqlSugarPagedList<MiniStorePageConfigOutput>()
  240. {
  241. Items = outputs,
  242. PageIndex = pageList.PageIndex,
  243. PageSize = pageList.PageSize,
  244. TotalCount = pageList.TotalCount,
  245. TotalPages = pageList.TotalPages,
  246. };
  247. }
  248. return new SqlSugarPagedList<MiniStorePageConfigOutput>()
  249. {
  250. Items = new List<MiniStorePageConfigOutput>()
  251. };
  252. }
  253. #endregion
  254. #region 支付管理
  255. [HttpPost("/api/paytemplate/add")]
  256. public async Task<bool> Add(PayTemplateCreateOrUpdateInputDto inputDto)
  257. {
  258. try
  259. {
  260. db.Ado.BeginTran();
  261. var payTemplate = db.Queryable<BPA_PayTemplate>().First(x => x.IsDeleted == 0 && x.Name == inputDto.Name);
  262. if (payTemplate != null)
  263. {
  264. throw Oops.Bah("名称重复");
  265. }
  266. payTemplate = await db.Insertable(new BPA_PayTemplate()
  267. {
  268. Name = inputDto.Name,
  269. }).CallEntityMethod(t => t.Create()).ExecuteReturnEntityAsync();
  270. var payTemplateIdInfo = new List<BPA_PayTemplateInfo>()
  271. {
  272. new BPA_PayTemplateInfo()
  273. {
  274. AppId=inputDto.WXAppId,
  275. Key=inputDto.WXKey,
  276. PayTemplateId=payTemplate.Id,
  277. PayType=1,
  278. PrivateKey=inputDto.WXPrivateKey,
  279. PubLicKey=inputDto.WXPubLicKey,
  280. PId=inputDto.WXPId,
  281. },
  282. new BPA_PayTemplateInfo()
  283. {
  284. AppId=inputDto.ZFBAppId,
  285. Key=inputDto.ZFBKey,
  286. PayTemplateId=payTemplate.Id,
  287. PayType=2,
  288. PrivateKey=inputDto.ZFBPrivateKey,
  289. PubLicKey=inputDto.ZFBPubLicKey,
  290. PId=inputDto.ZFBPId,
  291. }
  292. };
  293. var result = await db.Insertable(payTemplateIdInfo).CallEntityMethod(t => t.Create()).ExecuteCommandAsync() > 0;
  294. db.Ado.CommitTran();
  295. return result;
  296. }
  297. catch (Exception e)
  298. {
  299. db.Ado.RollbackTran();
  300. throw Oops.Bah(e.Message);
  301. return false;
  302. }
  303. }
  304. [HttpPost("/api/paytemplate/delete")]
  305. public async Task<bool> Delete(List<string> Ids)
  306. {
  307. var data = db.Queryable<BPA_PayTemplate>().Where(x => Ids.Contains(x.Id) && x.IsDeleted == 0).ToList();
  308. foreach (var item in data)
  309. {
  310. item.IsDeleted = 1;
  311. }
  312. var data2 = db.Queryable<BPA_PayTemplateInfo>().Where(x => data.Select(x => x.Id).ToList().Contains(x.PayTemplateId)).ToList();
  313. foreach (var item in data2)
  314. {
  315. item.IsDeleted = 1;
  316. }
  317. try
  318. {
  319. db.Ado.BeginTran();
  320. var result = await db.Updateable(data).CallEntityMethod(t => t.Delete()).ExecuteCommandHasChangeAsync();
  321. if (data2.Count > 0)
  322. {
  323. await db.Updateable(data2).CallEntityMethod(t => t.Delete()).ExecuteCommandHasChangeAsync();
  324. }
  325. db.Ado.CommitTran();
  326. return result;
  327. }
  328. catch (Exception)
  329. {
  330. db.Ado.RollbackTran();
  331. return false;
  332. }
  333. }
  334. [HttpPost("/api/paytemplate/getPayTemplatePageList")]
  335. public async Task<PageUtil> GetPayTemplatePageList(PayTemplatePageInputDto inputDto)
  336. {
  337. int total = 0;
  338. var res = db.Queryable<BPA_PayTemplate>()
  339. .Where(x => x.IsDeleted == 0)
  340. .WhereIF(!string.IsNullOrEmpty(inputDto.Name), x => x.Name.Contains(inputDto.Name))
  341. .Select(t => new PayTemplateOutDto
  342. {
  343. Id = t.Id.SelectAll(),
  344. }).ToPageList(inputDto.Current, inputDto.PageSize, ref total);
  345. var data = db.Queryable<BPA_PayTemplateInfo>().Where(x => res.Select(x => x.Id).ToList().Contains(x.PayTemplateId)).ToList();
  346. foreach (var item in res)
  347. {
  348. item.PayTemplateOutDtoInfo = new List<PayTemplateOutDtoInfo>();
  349. foreach (var item2 in data)
  350. {
  351. if (item.Id == item2.PayTemplateId)
  352. {
  353. item.PayTemplateOutDtoInfo.Add(new PayTemplateOutDtoInfo()
  354. {
  355. AppId = item2.AppId,
  356. Id = item2.Id,
  357. Key = item2.Key,
  358. PayType = item2.PayType,
  359. PId = item2.PId,
  360. PrivateKey = item2.PrivateKey,
  361. PubLicKey = item2.PubLicKey,
  362. });
  363. }
  364. }
  365. }
  366. PageUtil util = new PageUtil()
  367. {
  368. Total = total,
  369. Data = res
  370. };
  371. return util;
  372. }
  373. [HttpPost("/api/paytemplate/update")]
  374. public async Task<bool> Update(PayTemplateCreateOrUpdateInputDto inputDto)
  375. {
  376. var payTemplate = db.Queryable<BPA_PayTemplate>().First(x => x.Id != inputDto.Id && x.IsDeleted == 0 && x.Name == inputDto.Name);
  377. if (payTemplate != null)
  378. {
  379. throw Oops.Bah("名称重复");
  380. }
  381. payTemplate = db.Queryable<BPA_PayTemplate>().First(x => x.Id == inputDto.Id && x.IsDeleted == 0);
  382. if (payTemplate == null) return false;
  383. payTemplate.Name = inputDto.Name;
  384. var payTemplateInfo = db.Queryable<BPA_PayTemplateInfo>().Where(x => x.PayTemplateId == inputDto.Id).ToList();
  385. foreach (var item in payTemplateInfo)
  386. {
  387. if (item.PayType == 1)
  388. {
  389. item.AppId = inputDto.WXAppId;
  390. item.Key = inputDto.WXKey;
  391. item.PrivateKey = inputDto.WXPrivateKey;
  392. item.PubLicKey = inputDto.WXPubLicKey;
  393. item.PId = inputDto.WXPId;
  394. }
  395. else
  396. {
  397. item.AppId = inputDto.ZFBAppId;
  398. item.Key = inputDto.ZFBKey;
  399. item.PrivateKey = inputDto.ZFBPrivateKey;
  400. item.PubLicKey = inputDto.ZFBPubLicKey;
  401. item.PId = inputDto.ZFBPId;
  402. }
  403. }
  404. try
  405. {
  406. db.Ado.BeginTran();
  407. var result = await db.Updateable(payTemplate).CallEntityMethod(t => t.Modify()).ExecuteCommandHasChangeAsync();
  408. await db.Updateable(payTemplateInfo).CallEntityMethod(t => t.Modify()).ExecuteCommandHasChangeAsync();
  409. db.Ado.CommitTran();
  410. return result;
  411. }
  412. catch (Exception)
  413. {
  414. db.Ado.RollbackTran();
  415. return false;
  416. }
  417. }
  418. #endregion
  419. #region appId
  420. [HttpPost("/api/appid/add")]
  421. public async Task<bool> AppidAdd(BPA_AppIdConfig inputDto)
  422. {
  423. var data = db.Queryable<BPA_AppIdConfig>().First(x => x.IsDeleted == 0 && x.AppId == inputDto.AppId);
  424. if (data != null)
  425. {
  426. throw Oops.Bah("AppId重复");
  427. }
  428. try
  429. {
  430. var result = await db.Insertable(inputDto).CallEntityMethod(t => t.Create()).ExecuteCommandAsync() > 0;
  431. return result;
  432. }
  433. catch (Exception)
  434. {
  435. return false;
  436. }
  437. }
  438. [HttpPost("/api/appid/delete")]
  439. public async Task<bool> AppidDelete(List<string> Ids)
  440. {
  441. var data = db.Queryable<BPA_AppIdConfig>().Where(x => Ids.Contains(x.Id) && x.IsDeleted == 0).ToList();
  442. foreach (var item in data)
  443. {
  444. item.IsDeleted = 1;
  445. }
  446. try
  447. {
  448. db.Ado.BeginTran();
  449. var result = await db.Updateable(data).CallEntityMethod(t => t.Delete()).ExecuteCommandHasChangeAsync();
  450. db.Ado.CommitTran();
  451. return result;
  452. }
  453. catch (Exception)
  454. {
  455. db.Ado.RollbackTran();
  456. return false;
  457. }
  458. }
  459. [HttpPost("/api/appid/getappidpage")]
  460. public async Task<PageUtil> GetAppIdPage(PageInputBase inputDto)
  461. {
  462. int total = 0;
  463. var res = db.Queryable<BPA_AppIdConfig>()
  464. .Where(x => x.IsDeleted == 0)
  465. .Select(t => new BPA_AppIdConfig
  466. {
  467. Id = t.Id.SelectAll(),
  468. }).ToPageList(inputDto.Current, inputDto.PageSize, ref total);
  469. PageUtil util = new PageUtil()
  470. {
  471. Total = total,
  472. Data = res
  473. };
  474. return util;
  475. }
  476. [HttpPost("/api/appid/update")]
  477. public async Task<bool> AppidUpdate(BPA_AppIdConfig inputDto)
  478. {
  479. var data= db.Queryable<BPA_AppIdConfig>().First(x => x.Id != inputDto.Id && x.IsDeleted == 0&&x.AppId==inputDto.AppId);
  480. if (data != null)
  481. {
  482. throw Oops.Bah("AppId重复");
  483. }
  484. data = db.Queryable<BPA_AppIdConfig>().First(x => x.Id == inputDto.Id && x.IsDeleted == 0);
  485. if (data == null) return false;
  486. data.AppId = inputDto.AppId;
  487. try
  488. {
  489. var result = await db.Updateable(data).CallEntityMethod(t => t.Modify()).ExecuteCommandHasChangeAsync();
  490. return result;
  491. }
  492. catch (Exception)
  493. {
  494. db.Ado.RollbackTran();
  495. return false;
  496. }
  497. }
  498. #endregion
  499. }
  500. }