| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alipay.api.domain.RechargeDetail; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.supersavedriving.user.core.common.constant.JwtConstants; |
| | |
| | | import com.supersavedriving.user.core.util.JwtTokenUtil; |
| | | import com.supersavedriving.user.core.util.ToolUtil; |
| | | import com.supersavedriving.user.modular.system.dao.AppUserMapper; |
| | | import com.supersavedriving.user.modular.system.model.AppUser; |
| | | import com.supersavedriving.user.modular.system.model.Coupon; |
| | | import com.supersavedriving.user.modular.system.model.UserToCoupon; |
| | | import com.supersavedriving.user.modular.system.service.IAppUserService; |
| | | import com.supersavedriving.user.modular.system.service.ICouponService; |
| | | import com.supersavedriving.user.modular.system.service.IUserToCouponService; |
| | | import com.supersavedriving.user.modular.system.model.*; |
| | | import com.supersavedriving.user.modular.system.service.*; |
| | | import com.supersavedriving.user.modular.system.util.PayMoneyUtil; |
| | | import com.supersavedriving.user.modular.system.util.RedisUtil; |
| | | import com.supersavedriving.user.modular.system.util.ResultUtil; |
| | | import com.supersavedriving.user.modular.system.util.UUIDUtil; |
| | | import com.supersavedriving.user.modular.system.util.weChat.WXCore; |
| | | import com.supersavedriving.user.modular.system.util.weChat.WeChatUtil; |
| | | import com.supersavedriving.user.modular.system.util.weChat.model.Code2Session; |
| | | import com.supersavedriving.user.modular.system.warpper.CouponWarpper; |
| | | import com.supersavedriving.user.modular.system.warpper.SignInToRegister; |
| | | import com.supersavedriving.user.modular.system.warpper.SignInToRegisterWarpper; |
| | | import com.supersavedriving.user.modular.system.warpper.*; |
| | | import org.apache.shiro.authc.SimpleAuthenticationInfo; |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | | import org.apache.shiro.authc.credential.HashedCredentialsMatcher; |
| | |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | @Autowired |
| | | private IUserToCouponService userToCouponService; |
| | | |
| | | @Autowired |
| | | private IRechargeRecordService rechargeRecordService; |
| | | |
| | | @Autowired |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @Autowired |
| | | private IAccountChangeDetailService accountChangeDetailService; |
| | | |
| | | |
| | | |
| | | @Override |
| | |
| | | return ResultUtil.error(code2Session.getErrmsg()); |
| | | } |
| | | String openid = code2Session.getOpenid(); |
| | | AppUser appUser = this.selectOne(new EntityWrapper<AppUser>().eq("openid", openid).ne("status", 3)); |
| | | AppUser appUser = this.selectOne(new EntityWrapper<AppUser>().eq("openid", openid).eq("status", 1)); |
| | | if(null == appUser){ |
| | | return ResultUtil.error("无效的账号"); |
| | | } |
| | | if(appUser.getStatus() == 2){ |
| | | return ResultUtil.error("账号被冻结"); |
| | | } |
| | | String token = getToken(appUser); |
| | | if(ToolUtil.isEmpty(token)){ |
| | |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 修改个人信息 |
| | | * @param userInfo |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil updateUserInfo(Integer uid, UserInfo userInfo) throws Exception { |
| | | AppUser appUser = this.selectById(uid); |
| | | if(ToolUtil.isNotEmpty(userInfo.getAvatar())){ |
| | | appUser.setAvatar(userInfo.getAvatar()); |
| | | } |
| | | if(ToolUtil.isNotEmpty(userInfo.getEmergencyContact())){ |
| | | appUser.setEmergencyContact(userInfo.getEmergencyContact()); |
| | | } |
| | | if(ToolUtil.isNotEmpty(userInfo.getEmergencyPhone())){ |
| | | appUser.setEmergencyPhone(userInfo.getEmergencyPhone()); |
| | | } |
| | | if(ToolUtil.isNotEmpty(userInfo.getNickname())){ |
| | | appUser.setNickname(userInfo.getNickname()); |
| | | } |
| | | if(ToolUtil.isNotEmpty(userInfo.getPhone())){ |
| | | if(userInfo.getPhone().equals(appUser.getPhone())){ |
| | | return ResultUtil.error("新手机不能和原手机号相同"); |
| | | } |
| | | String value = redisUtil.getValue("+86" + userInfo.getPhone()); |
| | | if(ToolUtil.isEmpty(value) || !value.equals(userInfo.getCode())){ |
| | | return ResultUtil.error("验证码无效"); |
| | | } |
| | | appUser.setPhone(userInfo.getPhone()); |
| | | } |
| | | this.updateById(appUser); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | /** |
| | | * 余额充值 |
| | | * @param uid |
| | | * @param amount |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil rechargeBalance(Integer uid, Double amount) throws Exception { |
| | | if(0 >= amount){ |
| | | return ResultUtil.error("充值金额必须大于0"); |
| | | } |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String out_trade_no = sdf.format(new Date()) + UUIDUtil.getNumberRandom(3); |
| | | AppUser appUser = this.selectById(uid); |
| | | RechargeRecord rechargeRecord = new RechargeRecord(); |
| | | rechargeRecord.setType(1); |
| | | rechargeRecord.setUserId(uid); |
| | | rechargeRecord.setCode(out_trade_no); |
| | | rechargeRecord.setAmount(amount); |
| | | rechargeRecord.setCreateTime(new Date()); |
| | | rechargeRecord.setPayStatus(1); |
| | | rechargeRecord.setPayType(1); |
| | | rechargeRecordService.insert(rechargeRecord); |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay("余额充值", "", out_trade_no, amount.toString(), "/base/appUser/rechargeBalanceCallback", "JSAPI", appUser.getOpenid()); |
| | | return weixinpay; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 余额充值回调 |
| | | * @param out_trade_no |
| | | * @param transaction_id |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public void rechargeBalanceCallback(String out_trade_no, String transaction_id) throws Exception { |
| | | RechargeRecord rechargeRecord1 = rechargeRecordService.selectOne(new EntityWrapper<RechargeRecord>().eq("code", out_trade_no)); |
| | | if(rechargeRecord1.getPayStatus() != 1){ |
| | | return; |
| | | } |
| | | AppUser appUser = this.selectById(rechargeRecord1.getUserId()); |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setUserType(1); |
| | | accountChangeDetail.setUserId(rechargeRecord1.getUserId()); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setChangeType(3); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | accountChangeDetail.setExplain("余额充值"); |
| | | accountChangeDetail.setOldData(appUser.getAccountBalance()); |
| | | appUser.setAccountBalance(appUser.getAccountBalance() + rechargeRecord1.getAmount()); |
| | | accountChangeDetail.setNewData(appUser.getAccountBalance()); |
| | | this.updateById(appUser); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | |
| | | rechargeRecord1.setPayTime(new Date()); |
| | | rechargeRecord1.setPayStatus(2); |
| | | rechargeRecord1.setOrderNumber(transaction_id); |
| | | rechargeRecordService.updateById(rechargeRecord1); |
| | | } |
| | | |
| | | /** |
| | | * 获取用户优惠券列表 |
| | | * @param uid |
| | | * @param state |
| | | * @param pageNum |
| | | * @param pageSize |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public List<CouponsWarpper> queryMyCoupons(Integer uid, Integer state, Integer pageNum, Integer pageSize) throws Exception { |
| | | return null; |
| | | } |
| | | } |