GroupGoodsController.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. package com.tzy.controller.group;
  2. import com.github.pagehelper.PageInfo;
  3. import com.tzy.annotation.ApiLimitRule;
  4. import com.tzy.annotation.ApiLog;
  5. import com.tzy.annotation.RequireRoles;
  6. import com.tzy.app.dto.OpenCardParam;
  7. import com.tzy.common.annotation.SensitiveData;
  8. import com.tzy.common.config.handle.ApiVersion;
  9. import com.tzy.common.constant.MsgConstants;
  10. import com.tzy.common.dto.GoodsQuery;
  11. import com.tzy.common.dto.InDto;
  12. import com.tzy.common.dto.OutDTO;
  13. import com.tzy.common.dto.UserInfo;
  14. import com.tzy.common.enums.BusinessType;
  15. import com.tzy.common.exception.AppAssert;
  16. import com.tzy.common.utils.StringUtils;
  17. import com.tzy.common.utils.UserType;
  18. import com.tzy.common.utils.UserUtils;
  19. import com.tzy.framework.web.domain.LimitRule;
  20. import com.tzy.pojo.card.CardGroupGoods;
  21. import com.tzy.pojo.card.CardGroupInfo;
  22. import com.tzy.sportcard.api.bean.goods.PaniniCheckList;
  23. import com.tzy.sportcard.api.bean.param.GoodsCheckParam;
  24. import com.tzy.sportcard.api.bean.param.GroupPublicParam;
  25. import com.tzy.sportcard.api.bean.param.PublicReportDTO;
  26. import com.tzy.sportcard.api.domain.AppUserInfoDto;
  27. import com.tzy.sportcard.api.domain.GoodsSerialDto;
  28. import com.tzy.sportcard.api.service.*;
  29. import com.tzy.sportcard.group.domain.AppUserWinCard;
  30. import com.tzy.sportcard.group.domain.MerchantActGoods;
  31. import com.tzy.sportcard.group.dto.MerchantCardInfoDTO;
  32. import com.tzy.sportcard.group.dto.MerchantCardQuery;
  33. import com.tzy.sportcard.group.dto.OpenCardDTO;
  34. import com.tzy.sportcard.group.mapper.AppUserWinCardMapper;
  35. import com.tzy.sportcard.group.service.ICardGroupGoodsService;
  36. import com.tzy.sportcard.group.service.ICardGroupOrderReviewService;
  37. import com.tzy.sportcard.group.service.impl.MerchantActGoodsService;
  38. import io.swagger.annotations.Api;
  39. import io.swagger.annotations.ApiOperation;
  40. import lombok.extern.slf4j.Slf4j;
  41. import org.springframework.beans.factory.annotation.Autowired;
  42. import org.springframework.context.annotation.Lazy;
  43. import org.springframework.web.bind.annotation.*;
  44. import org.teasoft.bee.osql.Condition;
  45. import org.teasoft.bee.osql.Op;
  46. import org.teasoft.bee.osql.SuidRich;
  47. import org.teasoft.honey.osql.core.ConditionImpl;
  48. import javax.annotation.Resource;
  49. import java.util.ArrayList;
  50. import java.util.List;
  51. import java.util.Objects;
  52. /**
  53. * @author by po'yi
  54. * @Classname GroupControllerNew
  55. * @Description
  56. * @Date 2022/12/15 13:24
  57. */
  58. @Api(value = "卡密相关新接口")
  59. @RestController
  60. @RequestMapping("/api/goods")
  61. @Slf4j
  62. public class GroupGoodsController {
  63. @Autowired
  64. @Lazy
  65. private GroupApiService groupApiService;
  66. @Autowired
  67. private ICardGroupOrderReviewService cardGroupOrderReviewService;
  68. @Autowired
  69. private SuidRich suidRich;
  70. @Autowired
  71. private ICardGroupGoodsService cardGroupGoodsService;
  72. @Resource
  73. @Lazy
  74. private IAllocateGoodsService allocateGoodsService;
  75. @Autowired
  76. private MineApiService mineApiService;
  77. @Resource
  78. private MerchantActGoodsService merchantActGoodsService;
  79. @Resource
  80. private IAppUserWinCardService appUserWinCardService;
  81. @Resource
  82. private ICardReportService cardReportService;
  83. @Resource
  84. private AppUserWinCardMapper appUserWinCardMapper;
  85. /**
  86. * 查询组团卡密
  87. *
  88. * @param inDto
  89. * @return
  90. */
  91. @ApiLog(title = "查询组团卡密", businessType = BusinessType.SEARCH, indto = "{{inDto}}")
  92. @ResponseBody
  93. @ApiVersion(1.0)
  94. @PostMapping(value = "/{version}/public/list")
  95. public OutDTO getPublicGroupGoods(@RequestBody InDto inDto) {
  96. return groupApiService.searchPublicGoods(inDto);
  97. }
  98. /**
  99. * 新版公示,兼容新旧版本
  100. */
  101. @ApiLog(title = "填写公示结果", businessType = BusinessType.INSERT, indto = "{{inDto}}")
  102. @ResponseBody
  103. @PostMapping(value = "/{version}/merchant/publicity")
  104. @RequireRoles(value = {UserType.USER_ROLE_SHIPPING, UserType.USER_ROLE_ADMIN})
  105. public OutDTO publicityResult(@RequestBody PublicReportDTO param) {
  106. if (param==null){
  107. return OutDTO.error500("参数不能为空");
  108. }
  109. GroupPublicParam publicParam = param.getPublicParam();
  110. groupApiService.publicityResult(publicParam);
  111. return OutDTO.ok();
  112. }
  113. @ApiLog(title = "卡片审核", businessType = BusinessType.SEARCH)
  114. @PostMapping(value = "/{version}/merchant/check/card")
  115. @RequireRoles(value = {UserType.USER_ROLE_SHIPPING, UserType.USER_ROLE_ADMIN})
  116. public OutDTO checkCardOrPass(@RequestBody InDto inDto) {
  117. GoodsCheckParam checkParam = inDto.buildParam(new GoodsCheckParam());
  118. if (checkParam.getGroupInfoId() == null || checkParam.getReviewStatus() == null) {
  119. return OutDTO.error(10090, "参数错误!");
  120. }
  121. if (StringUtils.isEmpty( checkParam.getIds()) && checkParam.getReviewStatus() == 3) {
  122. return OutDTO.error(10090, "请选中条目驳回!");
  123. }
  124. Long infoStatus=cardGroupOrderReviewService.checkGoods(checkParam);
  125. return OutDTO.ok().put("infoStatus", infoStatus);
  126. }
  127. @ApiLog(title = "清除新版卡密公示信息", businessType = BusinessType.SEARCH)
  128. @PostMapping(value = "/{version}/merchant/publicity/del")
  129. @RequireRoles(value = {UserType.USER_ROLE_SHIPPING, UserType.USER_ROLE_ADMIN})
  130. @ApiOperation("清除新版卡密公示信息,参数id(卡密id),goodsType")
  131. public OutDTO delGoodsPublicity(@RequestBody InDto inDto) {
  132. groupApiService.delGoodsPublicity(Long.valueOf(inDto.getString("id")),Integer.valueOf(inDto.getString("goodsType")));
  133. return OutDTO.ok();
  134. }
  135. @ApiLog(title = "删除卡密子条目", businessType = BusinessType.SEARCH)
  136. @PostMapping(value = "/{version}/merchant/publicity/del/sub")
  137. @RequireRoles(value = {UserType.USER_ROLE_SHIPPING, UserType.USER_ROLE_ADMIN})
  138. @ApiOperation("删除卡密子条目,参数id(卡密id),goodsType,paniniListId")
  139. public OutDTO delSubGoodsPublicity(@RequestBody InDto inDto) {
  140. groupApiService.delSubGoodsPublicity(Long.valueOf(inDto.getString("id")),Integer.valueOf(inDto.getString("goodsType")),
  141. Long.valueOf(inDto.getString("paniniListId")));
  142. return OutDTO.ok();
  143. }
  144. /**
  145. * 球队,球队帅选条件
  146. *
  147. * @param inDto
  148. * @return
  149. */
  150. @ApiLog(title = "球队,球队帅选条件", businessType = BusinessType.SEARCH, indto = "{{inDto}}")
  151. @ResponseBody
  152. @PostMapping(value = "/selected/param/type")
  153. public OutDTO searchParamByType(@RequestBody InDto inDto) {
  154. Integer paniniListId = (Integer) inDto.get("paniniListId");
  155. if(paniniListId==null){
  156. return OutDTO.error500("参数为空!");
  157. }
  158. String title = inDto.getString("title");
  159. if(StringUtils.isEmpty(title)){
  160. return OutDTO.error500("参数为空!");
  161. }
  162. String team = inDto.getString("team");
  163. String playerName = inDto.getString("playerName");
  164. if(StringUtils.isEmpty(team)&&StringUtils.isEmpty(playerName)){
  165. return OutDTO.error500("参数为空!");
  166. }
  167. return groupApiService.searchParamByType(title,paniniListId,team,playerName);
  168. }
  169. @ApiLog(title = "修改拆卡报告图片", businessType = BusinessType.UPDATE)
  170. @PostMapping(value = "/{version}/change/publicity/image")
  171. @RequireRoles(value = {UserType.USER_ROLE_SHIPPING, UserType.USER_ROLE_ADMIN})
  172. @ApiOperation("修改拆卡报告图片,参数:groupInfoId,reportFlag(1:新,0:,旧)")
  173. @ApiVersion(1.0)
  174. public OutDTO changePublicityImage(@RequestBody InDto inDto) {
  175. Long groupInfoId = Long.valueOf(inDto.getString("groupInfoId"));
  176. Long cardGoodsId = Long.valueOf(inDto.getString("cardGoodsId"));
  177. String img = inDto.getString("imageStr");
  178. CardGroupGoods goods = new CardGroupGoods();
  179. goods.setGroupInfoId(groupInfoId);
  180. goods.setId(cardGoodsId);
  181. goods.setImg(img);
  182. suidRich.update(goods);
  183. AppUserWinCard appUserWinCard = new AppUserWinCard();
  184. List<Integer> ids = new ArrayList<>();
  185. ids.add(cardGoodsId.intValue());
  186. List<Long> cardids = appUserWinCardMapper.selectUserWindCardByGoodsId(ids);
  187. if(cardids!=null&&cardids.size()>0){
  188. appUserWinCard.setId(cardids.get(0));
  189. }
  190. appUserWinCard.setRefInfoId(groupInfoId);
  191. appUserWinCard.setGroupGoodsId(cardGoodsId);
  192. appUserWinCard.setImgUrl(img);
  193. appUserWinCardService.updateAppUserWinCard(appUserWinCard);
  194. List<Long> idList=new ArrayList<>();
  195. idList.add(cardGoodsId);
  196. cardReportService.syncCardWithGoodsId(idList);
  197. return OutDTO.ok();
  198. }
  199. @ApiLog(title = "切换拆卡报告版本", businessType = BusinessType.SEARCH)
  200. @PostMapping(value = "/{version}/change/publicity/type")
  201. @RequireRoles(value = {UserType.USER_ROLE_SHIPPING, UserType.USER_ROLE_ADMIN})
  202. @ApiOperation("切换拆卡报告版本,参数:groupInfoId,reportFlag(1:新,0:,旧)")
  203. @ApiVersion(1.0)
  204. public OutDTO changePublicityType(@RequestBody InDto inDto) {
  205. Integer reportFlag=Integer.valueOf(inDto.getString("reportFlag"));
  206. Long groupInfoId=Long.valueOf(inDto.getString("groupInfoId"));
  207. CardGroupInfo groupInfo = new CardGroupInfo();
  208. groupInfo.setId(groupInfoId);
  209. CardGroupInfo cardGroupInfo = suidRich.selectOne(groupInfo);
  210. if(cardGroupInfo==null||cardGroupInfo.getStatus()!=205){
  211. return OutDTO.error500("待公示的组队不存在");
  212. }
  213. if(cardGroupInfo.getPaniniListId()==null&&reportFlag==1){
  214. return OutDTO.error500("此组队不支持新版公示报告");
  215. }
  216. Integer[] statusArr=new Integer[]{100,3,2,1};
  217. CardGroupGoods goods = new CardGroupGoods();
  218. goods.setGroupInfoId(groupInfoId);
  219. Condition beeCondition = new ConditionImpl();
  220. beeCondition.op("status", Op.in,statusArr);
  221. beeCondition.start(0).size(1);
  222. List<CardGroupGoods> existGoods = suidRich.select(goods, beeCondition);
  223. if(!existGoods.isEmpty()){
  224. return OutDTO.error500("此组队已存在公示信息,暂不支持切换!");
  225. }
  226. groupInfo.setReportFlag(reportFlag);
  227. suidRich.update(groupInfo);
  228. return OutDTO.ok().put("reportFlag",reportFlag);
  229. }
  230. @ApiLog(title = "根据条件查询卡密信息", businessType = BusinessType.SEARCH, indto = "{{inDto}}")
  231. @ResponseBody
  232. @ApiVersion(1.0)
  233. @RequestMapping(value = "/{version}/team/id", method = RequestMethod.POST)
  234. public OutDTO getGroupGoods(@RequestBody InDto inDto) {
  235. String team = inDto.getString("team");
  236. Integer groupInfoId = (Integer) inDto.get("groupInfoId");
  237. String idxStr = inDto.getString("idx");
  238. if (StringUtils.isEmpty(team) && StringUtils.isEmpty(idxStr) && groupInfoId == null) {
  239. return OutDTO.error500("参数为空");
  240. }
  241. CardGroupInfo cardGroupInfo = getCardGroupInfo(groupInfoId);
  242. if(cardGroupInfo==null){
  243. return OutDTO.error500("组队不存在");
  244. }
  245. boolean isNewGoods = cardGroupInfo.getGoodsType() == 1;
  246. GoodsQuery query = new GoodsQuery().setGroupInfoId(cardGroupInfo.getId()).setTeam(team).setIdStr(idxStr);
  247. List<GoodsSerialDto> goods = cardGroupGoodsService.selectGoods(isNewGoods, query);
  248. return OutDTO.ok().put("goods", goods);
  249. }
  250. private CardGroupInfo getCardGroupInfo(Integer groupInfoId) {
  251. CardGroupInfo info = new CardGroupInfo();
  252. info.setId(groupInfoId.longValue());
  253. CardGroupInfo cardGroupInfo = suidRich.selectOne(info);
  254. return cardGroupInfo;
  255. }
  256. @ApiLog(title = "预售订单获取卡密", businessType = BusinessType.SEARCH, indto = "{{inDto}}")
  257. @ApiOperation("预售订单获取卡密,参数:OpenCardParam")
  258. @ResponseBody
  259. @ApiVersion(1.0)
  260. @ApiLimitRule(seconds = 2,limitCount=20,type= LimitRule.ACT,msg="抱歉,开卡人数太多,请稍后再试!")
  261. @PostMapping("/{version}/order/open")
  262. public OutDTO openGoodsByOrder(@RequestBody InDto inDto) {
  263. AppUserInfoDto user = mineApiService.checkUserNew(inDto);
  264. OpenCardParam param = inDto.buildParam(new OpenCardParam());
  265. if(param.getNum()==null||param.getNum()<1||param.getOrderId()==null){
  266. return OutDTO.error500("参数不符合要求");
  267. }
  268. param.setUser(user);
  269. OpenCardDTO openCardDTO = allocateGoodsService.allocateUserGoodsByOrder(param);
  270. return OutDTO.ok().put("openCardDTO",openCardDTO);
  271. }
  272. @ApiLog(title = "查询panini卡密", businessType = BusinessType.SEARCH, indto = "{{inDto}}")
  273. @ApiOperation("查询panini卡密,参数:GoodsQuery")
  274. @ResponseBody
  275. @ApiVersion(2.0)
  276. @PostMapping("/{version}/panini/list")
  277. public OutDTO getMineGoodsByCond(@RequestBody InDto inDto) {
  278. GoodsQuery query = inDto.buildParam(new GoodsQuery());
  279. query.setPageNo(inDto.getPageNo()).setPageSize(inDto.getPageSize());
  280. List<PaniniCheckList> goods = groupApiService.selectPaniniList(query);
  281. return OutDTO.ok().put("goods",goods);
  282. }
  283. @ApiLog(title = "商家好卡查询", businessType = BusinessType.SEARCH, indto = "{{inDto}}")
  284. @ApiOperation("商家好卡查询")
  285. @ResponseBody
  286. @ApiVersion(2.0)
  287. @SensitiveData
  288. @PostMapping("/{version}/top")
  289. public OutDTO getMerchantTopCard(@RequestBody InDto inDto) {
  290. MerchantCardQuery cardQuery = inDto.buildParam(new MerchantCardQuery());
  291. if (cardQuery.getMerchantId() == null && cardQuery.getPaniniListId() == null) {
  292. return OutDTO.error500(MsgConstants.PARAM_EMPTY);
  293. }
  294. UserInfo user = UserUtils.getSimpleUserInfo();
  295. if (user == null && cardQuery.getPaniniListId() == null) {
  296. return OutDTO.error500(MsgConstants.NEED_LOGIN);
  297. }
  298. boolean isMerchantOwner=false;
  299. if (user != null) {
  300. cardQuery.setUserId(user.getId());
  301. isMerchantOwner = Objects.equals(user.getMerchantId(), cardQuery.getMerchantId());
  302. if (!isMerchantOwner && cardQuery.getStatus() == null) {
  303. cardQuery.setStatus(1);
  304. }
  305. }
  306. if (cardQuery.getPaniniListId() != null) {
  307. cardQuery.setStatus(1);
  308. }
  309. cardQuery.setPageNo(inDto.getPageNo());
  310. cardQuery.setPageSize(inDto.getPageSize());
  311. PageInfo<MerchantCardInfoDTO> cards = merchantActGoodsService.getMerchantTopCards(cardQuery);
  312. if (!isMerchantOwner && cardQuery.getMerchantId() != null && Objects.equals(cardQuery.getStatus(), 1)) {
  313. cards.setTotal(Math.min(cards.getTotal(), 100));
  314. }
  315. return OutDTO.ok().put("cards", cards);
  316. }
  317. @ApiLog(title = "商家编辑好卡展示和排序", businessType = BusinessType.SEARCH, indto = "{{inDto}}")
  318. @ApiOperation("商家编辑好卡展示和排序")
  319. @ApiLimitRule(seconds = 1, limitCount = 1, type = LimitRule.USER, msg = "操作太频繁,请稍后再试!")
  320. @ResponseBody
  321. @ApiVersion(2.0)
  322. @SensitiveData
  323. @PostMapping("/{version}/top/edit")
  324. @RequireRoles(value = {UserType.USER_ROLE_SHIPPING})
  325. public OutDTO editCardShow(@RequestBody InDto inDto) {
  326. UserInfo user = UserUtils.getSimpleUserInfo(true);
  327. AppAssert.notNull(user, MsgConstants.NEED_LOGIN);
  328. Integer id = inDto.getIntegerParam("id");
  329. Integer sortValue = inDto.getIntegerParam("sortValue");
  330. Integer status = inDto.getIntegerParam("status");
  331. if (id == null || (status == null && sortValue == null)) {
  332. return OutDTO.error500(MsgConstants.PARAM_EMPTY);
  333. }
  334. MerchantActGoods editGoods = new MerchantActGoods().setId(id.longValue()).setMerchantId(user.getMerchantId()).setSortValue(sortValue).setStatus(status);
  335. merchantActGoodsService.updateMerchantActGoods(editGoods);
  336. return OutDTO.ok();
  337. }
  338. @ApiLog(title = "商家选择或者取消好卡", businessType = BusinessType.SEARCH, indto = "{{inDto}}")
  339. @ApiOperation("商家选择或者取消好卡")
  340. @ApiLimitRule(seconds = 1, limitCount = 1, type = LimitRule.USER, msg = "操作太频繁,请稍后再试!")
  341. @ResponseBody
  342. @ApiVersion(2.0)
  343. @SensitiveData
  344. @PostMapping("/{version}/top/show")
  345. @RequireRoles(value = {UserType.USER_ROLE_SHIPPING})
  346. public OutDTO editGoodsTopShow(@RequestBody InDto inDto) {
  347. UserInfo user = UserUtils.getSimpleUserInfo(true);
  348. AppAssert.notNull(user, MsgConstants.NEED_LOGIN);
  349. Integer id = inDto.getIntegerParam("id");
  350. Integer topSort = inDto.getIntegerParam("topSort");
  351. if (id == null || topSort == null) {
  352. return OutDTO.error500(MsgConstants.PARAM_EMPTY);
  353. }
  354. Long infoId = cardGroupGoodsService.editGoodsTopShow(id, topSort, user.getMerchantId());
  355. if (infoId != null) {
  356. merchantActGoodsService.syncTopGoodsRecord(infoId);
  357. }
  358. return OutDTO.ok();
  359. }
  360. }