| @@ -1,6 +1,7 @@ | |||
| package com.iformall.controller; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.Result; | |||
| @@ -52,6 +53,9 @@ public class WxPayController extends BaseController { | |||
| @Autowired | |||
| SysConfigService sysConfigService; | |||
| @Autowired | |||
| WxProductService wxProductService; | |||
| @Autowired | |||
| @Qualifier("objectCommonRedisTemplate") | |||
| RedisTemplate<String, Object> redisTemplate; | |||
| @@ -67,7 +71,7 @@ public class WxPayController extends BaseController { | |||
| public ResultData createPayOrder(@RequestBody Map<String, String> paramMap) { | |||
| WxCUser wxCUser = this.getCUser(); | |||
| String appId = paramMap.get("appId"); | |||
| //String carNumber = paramMap.get("carNumber"); | |||
| String productId = paramMap.get("productId"); | |||
| try { | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(appId); | |||
| if(cAppInfo == null){ | |||
| @@ -78,21 +82,40 @@ public class WxPayController extends BaseController { | |||
| throw new MallinkException(ErrorCode.APPINFO_NOFUND.getCode(),"未查询到payAccount."); | |||
| } | |||
| //判断是否传入的首充产品 | |||
| WxProduct product = wxProductService.getCFirstProduct(wxCUser); | |||
| long pid = Long.parseLong(productId); | |||
| if (null != product && product.getId().longValue() == pid) { | |||
| WxPayOrder payOrder = new WxPayOrder(); | |||
| payOrder.updateTenantInfo(wxCUser); | |||
| payOrder.setcUserId(wxCUser.getId()); | |||
| PageInfo<WxPayOrder> page = wxPayService.listPayOrderAsPage(payOrder, 1, 1); | |||
| if (null != page && null != page.getList() && page.getList().size() > 0 ) { | |||
| throw new MallinkException(ErrorCode.APPINFO_NOFUND.getCode(),"当前账号不满足首充条件."); | |||
| } | |||
| }else { | |||
| product = wxProductService.getCProduct(wxCUser, pid); | |||
| } | |||
| if (null == product) { | |||
| throw new MallinkException(ErrorCode.APPINFO_NOFUND.getCode(),"未查询到product."); | |||
| } | |||
| String receiverAccount = payAccount.getSubMchId(); | |||
| String apiKey = payAccount.getMerchantApiKey(); | |||
| int rlength = receiverAccount.length(); | |||
| //最大128 cuserId,cuserPhone,carNumber,amountType,merchantAccount,parkOrderNo | |||
| StringBuffer attachSb = new StringBuffer() | |||
| .append(wxCUser.getId()).append(",") | |||
| .append(wxCUser.getPhone()); | |||
| .append(wxCUser.getPhone()).append(",") | |||
| .append(pid); | |||
| //创建微信支付订单 | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| String uniquePayOrderNo = String.valueOf(idWorker.nextId()); | |||
| String attach = attachSb.toString(); | |||
| String productPre = uniquePayOrderNo;//中文签名错误 | |||
| //String productPre = "ParkOrderId"; | |||
| SysConfig sysConfig = sysConfigService.getByKey(SysConfigConstant.sale_price, payAccount); | |||
| PayAdapterResult wxResult = wxPayService.createWxPayOrder(payAccount,cAppInfo,false,false,wxCUser.getOpenId(), receiverAccount, productPre, attach, uniquePayOrderNo, Integer.parseInt(sysConfig.getConfigItemValue()), | |||
| PayAdapterResult wxResult = wxPayService.createWxPayOrder(payAccount,cAppInfo,false,false,wxCUser.getOpenId(), receiverAccount, productPre, attach, uniquePayOrderNo, product.getSalePrice(), | |||
| "127.0.0.1", payAccount.getPayNotifyUrl(), apiKey, new Date()); | |||
| if (wxResult.isSuccess()) { | |||
| return new ResultData(wxResult); | |||
| @@ -1,39 +1,13 @@ | |||
| package com.iformall.controller; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.entity.PayAdapterResult; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.domain.po.base.BaseEntity.SortField; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.*; | |||
| import com.iformall.service.wx.WxPayService; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.SysConfigConstant; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.beans.factory.annotation.Qualifier; | |||
| import org.springframework.data.redis.core.RedisTemplate; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @RestController | |||
| @RequestMapping("/api/product") | |||
| public class WxProductController extends BaseController { | |||
| @@ -45,41 +19,15 @@ public class WxProductController extends BaseController { | |||
| @Autowired | |||
| WxProductService wxProductService; | |||
| @GetMapping("/detail") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| }) | |||
| public ResultData payOrderDetail(Long id) { | |||
| Map retMap = new HashMap(); | |||
| TenantEntity tenantEntity = getCUser(); | |||
| SysConfig salePrice = sysConfigService.getByKey(SysConfigConstant.sale_price, tenantEntity); | |||
| SysConfig price = sysConfigService.getByKey(SysConfigConstant.price, tenantEntity); | |||
| SysConfig days = sysConfigService.getByKey(SysConfigConstant.expired_days, tenantEntity); | |||
| SysConfig img = sysConfigService.getByKey(SysConfigConstant.productImg, tenantEntity); | |||
| retMap.put("price", price.getConfigItemValue()); | |||
| retMap.put("salePrice", salePrice.getConfigItemValue()); | |||
| retMap.put("days", days.getConfigItemValue()); | |||
| retMap.put("productImg", img.getConfigItemValue()); | |||
| return new ResultData(retMap); | |||
| @GetMapping("/first") | |||
| @ApiOperation(value = "首充", notes = "") | |||
| public ResultData first() { | |||
| return new ResultData(wxProductService.getCFirstProduct(getCUser())); | |||
| } | |||
| @GetMapping("/list") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | |||
| }) | |||
| public ResultData payOrderDetail() { | |||
| Map retMap = new HashMap(); | |||
| TenantEntity tenantEntity = getCUser(); | |||
| SysConfig salePrice = sysConfigService.getByKey(SysConfigConstant.sale_price, tenantEntity); | |||
| SysConfig price = sysConfigService.getByKey(SysConfigConstant.price, tenantEntity); | |||
| SysConfig days = sysConfigService.getByKey(SysConfigConstant.expired_days, tenantEntity); | |||
| SysConfig img = sysConfigService.getByKey(SysConfigConstant.productImg, tenantEntity); | |||
| retMap.put("price", price.getConfigItemValue()); | |||
| retMap.put("salePrice", salePrice.getConfigItemValue()); | |||
| retMap.put("days", days.getConfigItemValue()); | |||
| retMap.put("productImg", img.getConfigItemValue()); | |||
| return new ResultData(retMap); | |||
| public ResultData list() { | |||
| return new ResultData(wxProductService.getCProductList(getCUser())); | |||
| } | |||
| } | |||
| @@ -18,6 +18,7 @@ import com.iformall.service.cache.WxAppInfoCache; | |||
| import com.iformall.service.cache.WxCUserCache; | |||
| import com.iformall.service.wx.WxWeappService; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.IPUtil; | |||
| import com.iformall.utils.MaUtil; | |||
| import com.iformall.utils.RedisCacheUtils; | |||
| @@ -154,7 +155,7 @@ public class WxUserGrantController extends BaseController { | |||
| cUser.updateTenantInfo(wxAppinfo); | |||
| wxCUserService.saveOrUpdate(cUser); | |||
| } | |||
| WxCUserCache.cacheApp(objectCommonRedisTemplate, cUser); | |||
| WxCUserCache.cacheWxCUser(objectCommonRedisTemplate, cUser); | |||
| resultMap.put("token", String.valueOf(cUser.getId())); | |||
| return new ResultData(resultMap); | |||
| } | |||
| @@ -233,5 +234,22 @@ public class WxUserGrantController extends BaseController { | |||
| } | |||
| return new ResultData(user); | |||
| } | |||
| @ApiOperation("申请") | |||
| @GetMapping("/apply") | |||
| public ResultData apply() { | |||
| WxCUser user = getCUser(); | |||
| if (null == user.getValidStartTime() && null == user.getValidEndTime()) { | |||
| SysConfig config = sysConfigService.getByKey(SysConfigConstant.freeDays, user); | |||
| int freeDays = Integer.parseInt(config.getConfigItemValue()); | |||
| if (freeDays > 0 ) { | |||
| Date curr = new Date(); | |||
| user.setValidStartTime(curr); | |||
| user.setValidEndTime(DateUtils.getTimeAfterDays(freeDays, curr)); | |||
| wxCUserService.apply(user); | |||
| } | |||
| } | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -74,14 +74,14 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | |||
| throw new MallinkException(ErrorCode.UNLOGIN); | |||
| } | |||
| WxCUser wxCUser = WxCUserCache.getCacheAppInfo(redisTemplate, Long.parseLong(token)); | |||
| WxCUser wxCUser = WxCUserCache.getCacheWxCUser(redisTemplate, Long.parseLong(token)); | |||
| if (null == wxCUser) { | |||
| wxCUser = wxCUserService.getById(Long.parseLong(token), tenantId); | |||
| if (null == wxCUser) { | |||
| throw new MallinkException(ErrorCode.UNLOGIN); | |||
| } | |||
| WxCUserCache.cacheApp(redisTemplate, wxCUser); | |||
| WxCUserCache.cacheWxCUser(redisTemplate, wxCUser); | |||
| } | |||
| request.setAttribute(Constant.TENANT_ID, wxCUser.getTenantId()); | |||
| @@ -22,6 +22,8 @@ public class WxProduct extends TenantEntity { | |||
| private Date updateTime; | |||
| @io.swagger.annotations.ApiModelProperty(value="产品名称",name="name") | |||
| private String name; | |||
| @io.swagger.annotations.ApiModelProperty(value="产品图片",name="img") | |||
| private String img; | |||
| @io.swagger.annotations.ApiModelProperty(value="原价",name="price") | |||
| private Integer price; | |||
| @io.swagger.annotations.ApiModelProperty(value="售价",name="salePrice") | |||
| @@ -30,4 +32,6 @@ public class WxProduct extends TenantEntity { | |||
| private Integer days; | |||
| @io.swagger.annotations.ApiModelProperty(value="返佣",name="rebate") | |||
| private Integer rebate; | |||
| @io.swagger.annotations.ApiModelProperty(value="是否首充EnumYesOrNo",name="first") | |||
| private Integer first; | |||
| } | |||
| @@ -40,5 +40,8 @@ public interface WxCUserService { | |||
| * @param record | |||
| */ | |||
| int saveOrUpdate(WxCUser record); | |||
| void apply(WxCUser record); | |||
| } | |||
| @@ -1,6 +1,8 @@ | |||
| package com.iformall.service; | |||
| import com.iformall.domain.po.WxProduct; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import java.util.List; | |||
| public interface WxProductService { | |||
| @@ -15,4 +17,11 @@ public interface WxProductService { | |||
| WxProduct getById(Long id,String tenantId); | |||
| List<WxProduct> productList(WxProduct product); | |||
| List<WxProduct> getCProductList(TenantEntity tenantEntity); | |||
| WxProduct getCFirstProduct(TenantEntity tenantEntity); | |||
| WxProduct getCProduct(TenantEntity tenantEntity,Long id); | |||
| } | |||
| @@ -13,12 +13,12 @@ public class WxCUserCache { | |||
| return key; | |||
| } | |||
| public static WxCUser getCacheAppInfo(RedisTemplate<String, Object> wxAppinfoRedisTemplate,Long userId) { | |||
| public static WxCUser getCacheWxCUser(RedisTemplate<String, Object> wxAppinfoRedisTemplate,Long userId) { | |||
| String key = getKey(userId); | |||
| return RedisCacheUtils.getCacheObject(wxAppinfoRedisTemplate, key, WxCUser.class); | |||
| } | |||
| public static void cacheApp(RedisTemplate<String, Object> wxAppinfoRedisTemplate,WxCUser wxCUser) { | |||
| public static void cacheWxCUser(RedisTemplate<String, Object> wxAppinfoRedisTemplate,WxCUser wxCUser) { | |||
| String key = getKey(wxCUser.getId()); | |||
| RedisCacheUtils.cache(wxAppinfoRedisTemplate, key, wxCUser, 3600*24*7); | |||
| } | |||
| @@ -0,0 +1,75 @@ | |||
| package com.iformall.service.cache; | |||
| import java.util.List; | |||
| import org.springframework.data.redis.core.RedisTemplate; | |||
| import com.iformall.domain.po.WxProduct; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.RedisCacheUtils; | |||
| public class WxProductCache { | |||
| private static String getKey(Long productId) { | |||
| String key = Constant.productPre + productId; | |||
| return key; | |||
| } | |||
| public static WxProduct getCache(RedisTemplate<String, Object> redisTemplate,Long productId) { | |||
| String key = getKey(productId); | |||
| return RedisCacheUtils.getCacheObject(redisTemplate, key, WxProduct.class); | |||
| } | |||
| public static void cache(RedisTemplate<String, Object> redisTemplate,WxProduct wxProduct) { | |||
| String key = getKey(wxProduct.getId()); | |||
| RedisCacheUtils.cache(redisTemplate, key, wxProduct, 3600*24*7); | |||
| } | |||
| public static void removeCache(RedisTemplate<String, Object> redisTemplate,Long productId) { | |||
| String key = getKey(productId); | |||
| RedisCacheUtils.removeCache(redisTemplate, key); | |||
| } | |||
| private static String getFirstKey() { | |||
| String key = Constant.productFirstPre; | |||
| return key; | |||
| } | |||
| public static WxProduct getCacheFirst(RedisTemplate<String, Object> redisTemplate) { | |||
| String key = getFirstKey(); | |||
| return RedisCacheUtils.getCacheObject(redisTemplate, key, WxProduct.class); | |||
| } | |||
| public static void cacheFirst(RedisTemplate<String, Object> redisTemplate,WxProduct wxProduct) { | |||
| String key = getFirstKey(); | |||
| RedisCacheUtils.cache(redisTemplate, key, wxProduct, 3600*24*7); | |||
| } | |||
| public static void removeCacheFirst(RedisTemplate<String, Object> redisTemplate) { | |||
| String key = getFirstKey(); | |||
| RedisCacheUtils.removeCache(redisTemplate, key); | |||
| } | |||
| private static String getListKey() { | |||
| String key = Constant.productListPre; | |||
| return key; | |||
| } | |||
| public static List<WxProduct> getCacheList(RedisTemplate<String, Object> redisTemplate) { | |||
| String key = getListKey(); | |||
| return RedisCacheUtils.getCacheListObject(redisTemplate, key, WxProduct.class); | |||
| } | |||
| public static void cacheList(RedisTemplate<String, Object> redisTemplate,List<WxProduct> wxProductList) { | |||
| String key = getListKey(); | |||
| RedisCacheUtils.cache(redisTemplate, key, wxProductList, 3600*24*7); | |||
| } | |||
| public static void removeCacheList(RedisTemplate<String, Object> redisTemplate) { | |||
| String key = getListKey(); | |||
| RedisCacheUtils.removeCache(redisTemplate, key); | |||
| } | |||
| } | |||
| @@ -10,6 +10,7 @@ import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxCUserMapper; | |||
| import com.iformall.service.*; | |||
| import com.iformall.service.cache.WxCUserCache; | |||
| import com.iformall.utils.Constant; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpUser; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| @@ -29,6 +30,10 @@ public class WxCUserServiceImpl implements WxCUserService { | |||
| @Autowired | |||
| WxCUserMapper wxCUserMapper; | |||
| @Autowired | |||
| @Qualifier("objectCommonRedisTemplate") | |||
| RedisTemplate<String, Object> redisTemplate; | |||
| @Override | |||
| public WxCUser getById(Long id,String tenantId) { | |||
| @@ -63,4 +68,11 @@ public class WxCUserServiceImpl implements WxCUserService { | |||
| return ret; | |||
| } | |||
| @Override | |||
| public void apply(WxCUser record) { | |||
| wxCUserMapper.updateValidTime(record.getId(), record.getTenantId(), record.getValidStartTime(), record.getValidEndTime()); | |||
| WxCUser user = wxCUserMapper.selectById(record.getId(), record.getTenantId()); | |||
| WxCUserCache.cacheWxCUser(redisTemplate, user); | |||
| } | |||
| } | |||
| @@ -1,11 +1,16 @@ | |||
| package com.iformall.service.impl; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumYesOrNo; | |||
| import com.iformall.mapper.WxProductMapper; | |||
| import com.iformall.service.*; | |||
| import com.iformall.service.cache.WxProductCache; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.beans.factory.annotation.Qualifier; | |||
| import org.springframework.data.redis.core.RedisTemplate; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.List; | |||
| @@ -15,6 +20,10 @@ public class WxProductServiceImpl implements WxProductService { | |||
| @Autowired | |||
| WxProductMapper wxProductMapper; | |||
| @Autowired | |||
| @Qualifier("objectCommonRedisTemplate") | |||
| RedisTemplate<String, Object> objectCommonRedisTemplate; | |||
| @Override | |||
| public WxProduct getById(Long id, String tenantId) { | |||
| @@ -26,6 +35,50 @@ public class WxProductServiceImpl implements WxProductService { | |||
| return wxProductMapper.findList(product); | |||
| } | |||
| @Override | |||
| public List<WxProduct> getCProductList(TenantEntity tenantEntity) { | |||
| List<WxProduct> productList = WxProductCache.getCacheList(objectCommonRedisTemplate); | |||
| if (null == productList || productList.size() <= 0 ) { | |||
| WxProduct p = new WxProduct(); | |||
| p.updateTenantInfo(tenantEntity); | |||
| p.setFirst(EnumYesOrNo.NO.getCode()); | |||
| List<WxProduct> plist = productList(p); | |||
| if (null != plist && plist.size() > 0 ) { | |||
| WxProductCache.cacheList(objectCommonRedisTemplate, plist); | |||
| return plist; | |||
| } | |||
| } | |||
| return productList; | |||
| } | |||
| @Override | |||
| public WxProduct getCFirstProduct(TenantEntity tenantEntity) { | |||
| WxProduct _product = WxProductCache.getCacheFirst(objectCommonRedisTemplate); | |||
| if (null == _product) { | |||
| WxProduct p = new WxProduct(); | |||
| p.updateTenantInfo(tenantEntity); | |||
| p.setFirst(EnumYesOrNo.YES.getCode()); | |||
| List<WxProduct> productList = productList(p); | |||
| if (null != productList && productList.size() > 0 ) { | |||
| _product = productList.get(0); | |||
| WxProductCache.cacheFirst(objectCommonRedisTemplate, _product); | |||
| } | |||
| } | |||
| return _product; | |||
| } | |||
| @Override | |||
| public WxProduct getCProduct(TenantEntity tenantEntity,Long id) { | |||
| WxProduct _product = WxProductCache.getCache(objectCommonRedisTemplate,id); | |||
| if (null == _product) { | |||
| _product = getById(id, tenantEntity.getTenantId()); | |||
| if (null != _product) { | |||
| WxProductCache.cache(objectCommonRedisTemplate, _product); | |||
| } | |||
| } | |||
| return _product; | |||
| } | |||
| } | |||
| @@ -18,7 +18,7 @@ public interface WxPayService { | |||
| public String handlePaidCallBack(String tenantId,Map<String, String> paramMap); | |||
| public void handlePaidSuccess(String tenantId,Long orderId,Long cUserId,Integer fee,Date paidTime,String transcationId, | |||
| public void handlePaidSuccess(Long productId,String tenantId,Long orderId,Long cUserId,Integer fee,Date paidTime,String transcationId, | |||
| String userPhone) throws Exception; | |||
| public WxPayOrder detailPayOrder(Long id,String tenantId); | |||
| @@ -10,6 +10,7 @@ import com.iformall.domain.po.SysConfig; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.domain.po.WxProduct; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.exception.MallinkException; | |||
| @@ -20,6 +21,7 @@ import com.iformall.mapper.WxPayAccountMapper; | |||
| import com.iformall.service.SysConfigService; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.WxPayAccountService; | |||
| import com.iformall.service.WxProductService; | |||
| import com.iformall.service.cache.WxCUserCache; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.RedisLock; | |||
| @@ -75,6 +77,10 @@ public class WxPayServiceImpl implements WxPayService { | |||
| @Autowired | |||
| WxCUserMapper wxCUserMapper; | |||
| @Lazy | |||
| @Autowired | |||
| WxProductService wxProductService; | |||
| @Autowired | |||
| @Qualifier("objectCommonRedisTemplate") | |||
| RedisTemplate<String, Object> wxPayRedisTemplate; | |||
| @@ -126,20 +132,22 @@ public class WxPayServiceImpl implements WxPayService { | |||
| String attach = paramMap.get("attach"); | |||
| Long cUserId = null; | |||
| String userPhone = null; | |||
| Long productId = null; | |||
| if (!StringUtils.isBlank(attach)) { | |||
| String[] attrs = attach.split(","); | |||
| if (attrs.length == 2) { | |||
| if (attrs.length == 3) { | |||
| cUserId = Long.parseLong(attrs[0]); | |||
| userPhone = attrs[1]; | |||
| productId = Long.parseLong(attrs[2]); | |||
| } | |||
| } | |||
| String payOrderNo = paramMap.get("out_trade_no"); | |||
| handlePaidSuccess(tenantId,Long.parseLong(payOrderNo),cUserId,Integer.parseInt(cashFeeStr), | |||
| handlePaidSuccess(productId,tenantId,Long.parseLong(payOrderNo),cUserId,Integer.parseInt(cashFeeStr), | |||
| DateUtils.string2Date(time_end, DateUtils.DATE_PATTERN_ALL_NOSPACE).getTime(),transcationId, | |||
| userPhone); | |||
| WxCUser cUser = wxCUserMapper.selectById(cUserId, tenantId); | |||
| WxCUserCache.cacheApp(wxPayRedisTemplate, cUser); | |||
| WxCUserCache.cacheWxCUser(wxPayRedisTemplate, cUser); | |||
| } catch (Exception e) { | |||
| logger.error("handlePaidCallBackError.",e); | |||
| return notifyErrorResult(e.getMessage()); | |||
| @@ -158,7 +166,7 @@ public class WxPayServiceImpl implements WxPayService { | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| @Override | |||
| public void handlePaidSuccess(String tenantId,Long orderId,Long cUserId,Integer fee,Date paidTime,String transcationId, | |||
| public void handlePaidSuccess(Long productId,String tenantId,Long orderId,Long cUserId,Integer fee,Date paidTime,String transcationId, | |||
| String userPhone) throws Exception{ | |||
| //查询该笔订单是否已经存在 | |||
| WxPayOrder payOrder = wxPayOrderMapper.findOneByIdOrTranscationId(orderId,transcationId, tenantId); | |||
| @@ -197,20 +205,25 @@ public class WxPayServiceImpl implements WxPayService { | |||
| payOrder.setPayTime(paidTime); | |||
| payOrder.setTransactionId(transcationId); | |||
| payOrder.setcUserPhone(userPhone); | |||
| SysConfig config = sysConfigService.getByKey(SysConfigConstant.expired_days, payOrder); | |||
| WxProduct product = wxProductService.getCProduct(wxCUser, productId); | |||
| int days = 0; | |||
| if (null != product) { | |||
| days = product.getDays(); | |||
| } | |||
| payOrder.setCreateTime(curr); | |||
| payOrder.setUpdateTime(curr); | |||
| payOrder.setValidStartTime(curr); | |||
| Date endtime = null; | |||
| if (isNew) { | |||
| endtime = DateUtils.getTimeAfterDays(Integer.parseInt(config.getConfigItemValue()), curr); | |||
| endtime = DateUtils.getTimeAfterDays(days, curr); | |||
| payOrder.setRemark("首次缴费"); | |||
| }else { | |||
| if (isExpired) { | |||
| endtime = DateUtils.getTimeAfterDays(Integer.parseInt(config.getConfigItemValue()), curr); | |||
| endtime = DateUtils.getTimeAfterDays(days, curr); | |||
| payOrder.setRemark("过期缴费"); | |||
| }else { | |||
| endtime = DateUtils.getTimeAfterDays(Integer.parseInt(config.getConfigItemValue()), wxCUser.getValidEndTime()); | |||
| endtime = DateUtils.getTimeAfterDays(days, wxCUser.getValidEndTime()); | |||
| payOrder.setRemark("未过期续费"); | |||
| } | |||
| } | |||
| @@ -74,21 +74,10 @@ public class WxWeappService { | |||
| updateUser.updateTenantInfo(cUser); | |||
| updateUser.setPhone(phoneNoInfo.getPhoneNumber()); | |||
| updateUser.setUpdateDate(new Date()); | |||
| if (null == updateUser.getValidStartTime() && null == updateUser.getValidEndTime()) { | |||
| SysConfig config = sysConfigService.getByKey(SysConfigConstant.freeDays, cUser); | |||
| int freeDays = Integer.parseInt(config.getConfigItemValue()); | |||
| if (freeDays > 0 ) { | |||
| Date curr = new Date(); | |||
| updateUser.setValidStartTime(curr); | |||
| updateUser.setValidEndTime(DateUtils.getTimeAfterDays(freeDays, curr)); | |||
| cUser.setValidStartTime(updateUser.getValidStartTime()); | |||
| cUser.setValidEndTime(updateUser.getValidEndTime()); | |||
| } | |||
| } | |||
| wxCUserMapper.updateById(updateUser); | |||
| cUser.setPhone(updateUser.getPhone()); | |||
| WxCUserCache.cacheApp(redisTemplate, cUser); | |||
| WxCUserCache.cacheWxCUser(redisTemplate, cUser); | |||
| return updateUser.getPhone(); | |||
| } else { | |||
| throw new MallinkException(ErrorCode.PHONE_DECRYPTED_FAILD); | |||
| @@ -5,6 +5,9 @@ public class Constant { | |||
| public static final int H_EXPIRE = 3600000;//1个小时 | |||
| public static final String appinfoPrev = "gpt:appinfo:"; | |||
| public static final String cuserPre = "gpt:wxCUser:"; | |||
| public static final String productPre = "gpt:wxProduct:"; | |||
| public static final String productFirstPre = "gpt:wxProductFirst"; | |||
| public static final String productListPre = "gpt:wxProductList"; | |||
| public static final String payaccountPrev = "gpt:payAccount:"; | |||
| public static final String currentUser = "currentUser"; | |||
| public static final String TENANT_ID = "tenantId"; | |||
| @@ -2,10 +2,6 @@ package com.iformall.utils; | |||
| public class SysConfigConstant { | |||
| public static final String sale_price="salePrice"; | |||
| public static final String price="price"; | |||
| public static final String productImg="productImg"; | |||
| public static final String expired_days = "expiredDays"; | |||
| public static final String says_content_length = "saysContentLength"; | |||
| public static final String freeDays="freeDays"; | |||
| public static final String promotContentCount="promotContentCount"; | |||
| @@ -8,15 +8,17 @@ | |||
| <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/> | |||
| <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/> | |||
| <result column="name" jdbcType="VARCHAR" property="name"/> | |||
| <result column="img" jdbcType="VARCHAR" property="img"/> | |||
| <result column="price" jdbcType="INTEGER" property="price"/> | |||
| <result column="salePrice" jdbcType="INTEGER" property="sale_price"/> | |||
| <result column="days" jdbcType="INTEGER" property="days"/> | |||
| <result column="rebate" jdbcType="INTEGER" property="rebate"/> | |||
| <result column="first" jdbcType="INTEGER" property="first"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`parent_tenant_id`,`create_time`,`update_time`,`name`,`price`,`salePrice`, | |||
| `days`,`rebate` | |||
| `id`,`tenant_id`,`parent_tenant_id`,`create_time`,`update_time`,`name`,`img`,`price`,`salePrice`, | |||
| `days`,`rebate`,`first` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -41,6 +43,10 @@ | |||
| <if test=" null != name "> | |||
| and `name` like concat('%', #{name},'%') | |||
| </if> | |||
| <if test=" null != first "> | |||
| and `first` = #{first} | |||
| </if> | |||
| <if test=" null != userIds "> | |||
| and c_user_id in | |||