| | |
| | | package com.stylefeng.guns.modular.api; |
| | | |
| | | |
| | | import com.stylefeng.guns.modular.system.service.IUserInfoService; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.stylefeng.guns.modular.system.model.*; |
| | | import com.stylefeng.guns.modular.system.service.*; |
| | | //import com.stylefeng.guns.modular.system.util.ICBCPayUtil; |
| | | import com.stylefeng.guns.modular.system.util.PayMoneyUtil; |
| | | import com.stylefeng.guns.modular.system.service.impl.UserServiceImpl; |
| | | import com.stylefeng.guns.modular.system.util.*; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.PrintWriter; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | |
| | |
| | | @Autowired |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | @Autowired |
| | | private ALiSendSms aLiSendSms; |
| | | |
| | | @Autowired |
| | | private IUserService userService; |
| | | @Autowired |
| | | private ITActivityGeneralizationService activityGeneralizationService; |
| | | |
| | | @Autowired |
| | | private IUserCouponRecordService userCouponRecordService; |
| | | |
| | | @Autowired |
| | | private ISysCouponRecordService sysCouponRecordService; |
| | | |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/get/coupon") |
| | | @ApiOperation(value = "获取优惠卷", tags = {"线下推广页面"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "电话", name = "phone", required = true, dataType = "String"), |
| | | @ApiImplicitParam(value = "验证码", name = "code", required = true, dataType = "String") |
| | | }) |
| | | public ResultUtil coupon(String phone,String code,Integer acId){ |
| | | //判断验证码是否正确 |
| | | |
| | | //判断该手机号是否注册 |
| | | UserInfo byAccount = userInfoService.selectList(new EntityWrapper<UserInfo>().ne("flag",3)).get(0); |
| | | //已注册直接添加优惠卷 |
| | | TActivityGeneralization tActivityGeneralization = activityGeneralizationService.selectById(acId); |
| | | SysCouponRecord sysCouponRecord = sysCouponRecordService.selectById(tActivityGeneralization.getCouponId()); |
| | | if (byAccount != null){ |
| | | //判断该账号是否领取 |
| | | List<UserCouponRecord> userCouponRecords = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>().eq("activityType", 5).eq("couponActivityId", acId)); |
| | | if (!userCouponRecords.isEmpty()){ |
| | | return ResultUtil.error("当前用户已领取"); |
| | | } |
| | | Date date = new Date(); |
| | | UserCouponRecord userCouponRecord = new UserCouponRecord(); |
| | | userCouponRecord.setActivityType(5); |
| | | userCouponRecord.setCouponActivityId(acId); |
| | | userCouponRecord.setCouponId(tActivityGeneralization.getCouponId()); |
| | | userCouponRecord.setState(1); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(date); |
| | | calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + sysCouponRecord.getEffective()); |
| | | userCouponRecord.setExpirationTime(calendar.getTime()); |
| | | userCouponRecord.setCouponType(Integer.valueOf(String.valueOf(sysCouponRecord.getCouponType()))); |
| | | userCouponRecord.setCouponUseType(sysCouponRecord.getCouponUseType()); |
| | | userCouponRecord.setInsertTime(date); |
| | | userCouponRecord.setFullMoney(Double.valueOf(String.valueOf(sysCouponRecord.getFullMoney()))); |
| | | userCouponRecord.setMoney(Double.valueOf(String.valueOf(sysCouponRecord.getMoney()))); |
| | | userCouponRecord.setCompanyId(byAccount.getCompanyId()); |
| | | userCouponRecord.setUserId(byAccount.getId()); |
| | | |
| | | Integer userGrantCount = tActivityGeneralization.getUserGrantCount(); |
| | | // userCouponRecordService.insert(userCouponRecord); |
| | | if (userGrantCount != null && userGrantCount > 0) { |
| | | for (int i = 0; i < userGrantCount; i++) {// ... |
| | | userCouponRecordService.insert(userCouponRecord); |
| | | } |
| | | } |
| | | }else { |
| | | //判断当前用户是否领取 |
| | | String value = redisUtil.getValue("counpon:" + phone); |
| | | if (value!=null){ |
| | | return ResultUtil.error("当前用户已领取"); |
| | | } |
| | | //未注册将优惠卷信息存入缓存,待用户注册时调用来添加优惠卷 |
| | | redisUtil.setStrValue("counpon:"+phone, String.valueOf(acId)); |
| | | } |
| | | |
| | | |
| | | |
| | | return ResultUtil.success(tActivityGeneralization.getUserGrantCount()); |
| | | |
| | | |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/get/code") |
| | | @ApiOperation(value = "获取验证码", tags = {"线下推广页面"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "电话", name = "phone", required = true, dataType = "String") |
| | | }) |
| | | public ResultUtil coupon(String phone) { |
| | | if (StringUtils.hasLength(phone)) { |
| | | String code = String.valueOf((int) (Math.random() * 1000000)); |
| | | redisUtil.setStrValue(phone, code, 15 * 60 * 1000); |
| | | AliSms aliSms = new AliSms(); |
| | | aliSms.setCode(code); |
| | | String json = JSONObject.toJSONString(aliSms); |
| | | try { |
| | | aLiSendSms.sendSms(phone, "SMS_467580138", json); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | // msgUtils.sendMsg(dto.getPhone(), code); |
| | | return ResultUtil.success("发送短信验证码成功!"); |
| | | } |
| | | return ResultUtil.error("请输入手机号"); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/get/coupon/info") |
| | | @ApiOperation(value = "使用说明", tags = {"线下推广页面"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | |
| | | }) |
| | | public ResultUtil coupon(Integer acId){ |
| | | TActivityGeneralization tActivityGeneralization = activityGeneralizationService.selectById(acId); |
| | | |
| | | return ResultUtil.success(tActivityGeneralization.getUseExplain()); |
| | | } |
| | | |
| | | @Autowired |
| | | private WeChatUtil weChatUtil; |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/get/coupon/toWe") |
| | | @ApiOperation(value = "获取微信链接", tags = {"线下推广页面"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | |
| | | }) |
| | | public ResultUtil toWe(){ |
| | | try { |
| | | String urlLink = weChatUtil.getUrlLink(null, null); |
| | | return ResultUtil.success(urlLink); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | return ResultUtil.error("请稍后再试"); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |