| @@ -14,16 +14,20 @@ import com.iformall.enums.EnumUserAdmin; | |||
| import com.iformall.service.*; | |||
| import com.iformall.shiro.PasswordHelper; | |||
| import com.iformall.sms.EnumSMSChannel; | |||
| import com.iformall.utils.Constant; | |||
| import io.swagger.annotations.Api; | |||
| 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.util.Assert; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.util.*; | |||
| import java.util.concurrent.TimeUnit; | |||
| @RestController | |||
| @Api(description = "初始化相关接口") | |||
| @@ -85,6 +89,10 @@ public class WxProjectConfigController extends BaseController { | |||
| @Autowired | |||
| MallUserInfoService mallUserInfoService; | |||
| @Autowired | |||
| @Qualifier("openRedisTemplate") | |||
| RedisTemplate<String, String> openRedisTemplate; | |||
| @ApiOperation("添加商场基础数据") | |||
| @GetMapping(value = "/init/{id}") | |||
| @@ -577,5 +585,44 @@ public class WxProjectConfigController extends BaseController { | |||
| } | |||
| } | |||
| @ApiOperation("刷集团商场历史数据(五分钟内只能掉一次)") | |||
| @PostMapping("/init/after/group") | |||
| @SystemControllerLog(description = "商场-数据更新") | |||
| public ResultData initAfterGroup(@RequestBody WxMall wxMall) { | |||
| logger.debug("[" + getIpAddr() + "] WxProjectConfigController::initAfterGroup"); | |||
| try { | |||
| if(StringUtils.isBlank(wxMall.getTenantId())){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| if(StringUtils.isBlank(wxMall.getParentTenantId())){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| TenantEntity TenantEntity = new TenantEntity(){{ | |||
| setTenantId(wxMall.getParentTenantId()); | |||
| }}; | |||
| WxMall parentWxMall = wxMallService.getByTenantInfo(TenantEntity); | |||
| if(parentWxMall == null || parentWxMall.getSaleType() != 100 | |||
| || !parentWxMall.getGroupSupport().equals(EnumGroupSupport.SUPPORT.getCode()) | |||
| || StringUtils.isNotBlank(parentWxMall.getParentTenantId())){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| StringBuilder sb = new StringBuilder(); | |||
| sb.append(Constant.INTERFACE_VISIT_LIMIT_KEY).append("initAfterGroup"); | |||
| String key = sb.toString(); | |||
| boolean hasKey = openRedisTemplate.hasKey(key); | |||
| if(hasKey){ | |||
| return new ResultData(ErrorCode.TOO_MANY_REQUEST); | |||
| }else{ | |||
| openRedisTemplate.opsForValue().set(key,"1",3000, TimeUnit.SECONDS); | |||
| } | |||
| wxProjectConfigService.initAfterGroup(wxMall.getParentTenantId(),wxMall.getTenantId()); | |||
| return new ResultData(); | |||
| }catch (Exception e){ | |||
| logger.error(e.getMessage(),e); | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR); | |||
| } | |||
| } | |||
| } | |||
| @@ -8,6 +8,7 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.dto.OrderSaveDto; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| import com.iformall.domain.po.WxOrder; | |||
| @@ -16,8 +17,10 @@ import com.iformall.domain.vo.WxMerchantSubsidyVo; | |||
| import com.iformall.domain.vo.WxOrderQueryVo; | |||
| import com.iformall.enums.EnumCouponChannelStatus; | |||
| import com.iformall.enums.EnumCouponChannelType; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.enums.EnumUserType; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxCUserBasicInfoService; | |||
| import com.iformall.service.WxCUserService; | |||
| import com.iformall.service.WxCouponChannelService; | |||
| import com.iformall.service.WxCouponService; | |||
| @@ -56,6 +59,9 @@ public class WxOrderController extends BaseController { | |||
| @Autowired | |||
| private WxCouponService wxCouponService; | |||
| @Autowired | |||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @@ -165,7 +171,11 @@ public class WxOrderController extends BaseController { | |||
| } | |||
| try { | |||
| WxCUser user = wxCUserService.getById(orderSaveDto.getUserId()); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoService.getById(orderSaveDto.getUserId()); | |||
| if(null == user) { | |||
| logger.error("wxcuser未找到:"+orderSaveDto.getUserId()); | |||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | |||
| } | |||
| //用于标记当前操作人为A端用户 | |||
| user.setOperatorType(EnumUserType.MALLUSER.getCode()); | |||
| user.setOperatorId(getUserId()); | |||
| @@ -178,7 +188,7 @@ public class WxOrderController extends BaseController { | |||
| return new ResultData(ErrorCode.COUPON_IS_NOT_FREE); | |||
| } | |||
| // 免费券 | |||
| order = wxOrderService.saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId(), null); | |||
| order = wxOrderService.saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId(), null,EnumPayWay.PAY_WAY_NOT_UNPAY_CREDIT); | |||
| return new ResultData(order); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| @@ -35,29 +35,29 @@ public class WxSubsidyController extends BaseController { | |||
| @Autowired | |||
| private WxSubsidyService wxSubsidyService; | |||
| @ApiOperation("补贴扫码支付发起") | |||
| @GetMapping("prePay") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "amount", value = "金额", dataType = "String", paramType = "query", required = true)}) | |||
| @SystemControllerLog(description = "商城补贴-补贴扫码支付发起") | |||
| public void subsidyPrepay(String amount, HttpServletResponse response) throws Exception { | |||
| String ipStr = getIpAddr(); | |||
| logger.info("subsidyPrepay: " + ipStr + "-" + amount); | |||
| MallUserInfo userInfo = getUser(); | |||
| ResultData resultData = wxSubsidyService.createSubsidy(userInfo, ipStr, amount); | |||
| if (resultData.code == 200) { | |||
| String codeUrl = ((Map<String, String>) resultData.data).get("code_url"); | |||
| BufferedImage image = PayUtil.getQRCodeImge(codeUrl); | |||
| response.setContentType("image/jpeg"); | |||
| response.setHeader("Pragma", "no-cache"); | |||
| response.setHeader("Cache-Control", "no-cache"); | |||
| response.setIntHeader("Expires", -1); | |||
| ImageIO.write(image, "JPEG", response.getOutputStream()); | |||
| } else { | |||
| throw new MallinkException(resultData.code, resultData.message); | |||
| } | |||
| } | |||
| // @ApiOperation("补贴扫码支付发起") | |||
| // @GetMapping("prePay") | |||
| // @ApiImplicitParams({ | |||
| // @ApiImplicitParam(name = "amount", value = "金额", dataType = "String", paramType = "query", required = true)}) | |||
| // @SystemControllerLog(description = "商城补贴-补贴扫码支付发起") | |||
| // public void subsidyPrepay(String amount, HttpServletResponse response) throws Exception { | |||
| // String ipStr = getIpAddr(); | |||
| // logger.info("subsidyPrepay: " + ipStr + "-" + amount); | |||
| // MallUserInfo userInfo = getUser(); | |||
| // ResultData resultData = wxSubsidyService.createSubsidy(userInfo, ipStr, amount); | |||
| // if (resultData.code == 200) { | |||
| // String codeUrl = ((Map<String, String>) resultData.data).get("code_url"); | |||
| // BufferedImage image = PayUtil.getQRCodeImge(codeUrl); | |||
| // | |||
| // response.setContentType("image/jpeg"); | |||
| // response.setHeader("Pragma", "no-cache"); | |||
| // response.setHeader("Cache-Control", "no-cache"); | |||
| // response.setIntHeader("Expires", -1); | |||
| // ImageIO.write(image, "JPEG", response.getOutputStream()); | |||
| // } else { | |||
| // throw new MallinkException(resultData.code, resultData.message); | |||
| // } | |||
| // } | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @@ -54,7 +54,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkadmin | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-cn-beijing.aliyuncs.com | |||
| mail: | |||
| host: smtp.exmail.qq.com | |||
| @@ -11,7 +11,7 @@ ALTER TABLE `wx_user_visit` | |||
| ADD COLUMN `parent_tenant_id` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '父租户ID' AFTER `tenant_id`; | |||
| CREATE OR REPLACE ALGORITHM = UNDEFINED DEFINER = `root`@`%` SQL SECURITY DEFINER VIEW `mallink`.`view_touch_user` AS SELECT | |||
| CREATE OR REPLACE VIEW `mallink`.`view_touch_user` AS SELECT | |||
| date_format( `u`.`day_date`, '%Y-%m-%d' ) AS `xTime`, | |||
| `u`.`tenant_id` AS `tenant_id`, | |||
| `u`.`parent_tenant_id` AS `parent_tenant_id`, | |||
| @@ -58,7 +58,7 @@ GROUP BY | |||
| ) | |||
| ); | |||
| CREATE OR REPLACE ALGORITHM = UNDEFINED DEFINER = `root`@`%` SQL SECURITY DEFINER VIEW `mallink`.`view_coupon_data` AS SELECT | |||
| CREATE OR REPLACE VIEW `mallink`.`view_coupon_data` AS SELECT | |||
| `baseInfo`.`createTime` AS `createTime`, | |||
| `baseInfo`.`couponId` AS `couponId`, | |||
| `baseInfo`.`couponUserCount` AS `couponUserCount`, | |||
| @@ -0,0 +1,34 @@ | |||
| update mall_sale_type set menus = '[1, 2, 5, 6, 8, 10, 50, 101, 102, 104, 105, 106, 108, 203, 204, 206, 207, 501, 502, 503, 504, 509, 591, 595, 601, 621, 622, 623, 624, 625, 626, 627, 901, 902]' where id=100 | |||
| CREATE DEFINER=`root`@`%` PROCEDURE `init_after_group`(IN tenantId VARCHAR(25),IN subTenantIds VARCHAR(250)) | |||
| BEGIN | |||
| DECLARE tableName VARCHAR(50); | |||
| DECLARE end_flag INT DEFAULT FALSE; | |||
| DECLARE err_flag INT DEFAULT FALSE; | |||
| DECLARE table_cursor CURSOR FOR SELECT DISTINCT TABLE_NAME FROM information_schema.COLUMNS WHERE COLUMN_NAME = 'parent_tenant_id' AND TABLE_NAME NOT LIKE 'view%' AND TABLE_NAME != 'wx_mall'; | |||
| DECLARE CONTINUE HANDLER FOR NOT FOUND SET end_flag = TRUE; | |||
| DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET err_flag = TRUE; | |||
| START TRANSACTION; | |||
| OPEN table_cursor; | |||
| read_loop: LOOP | |||
| FETCH table_cursor INTO tableName; | |||
| IF end_flag THEN | |||
| LEAVE read_loop; | |||
| END IF; | |||
| SET @old_data_sql = CONCAT("UPDATE ",tableName," SET parent_tenant_id = NULL WHERE parent_tenant_id = '",tenantId,"';"); | |||
| PREPARE stmt_old FROM @old_data_sql; | |||
| EXECUTE stmt_old; | |||
| DEALLOCATE PREPARE stmt_old; | |||
| SET @new_data_sql = CONCAT("UPDATE ",tableName," SET parent_tenant_id = '",tenantId,"' WHERE FIND_IN_SET(tenant_id ,'",subTenantIds,"');"); | |||
| PREPARE stmt_new FROM @new_data_sql; | |||
| EXECUTE stmt_new; | |||
| DEALLOCATE PREPARE stmt_new; | |||
| END LOOP; | |||
| CLOSE table_cursor; | |||
| IF err_flag THEN | |||
| ROLLBACK; | |||
| ELSE | |||
| COMMIT; | |||
| END IF; | |||
| END; | |||
| @@ -0,0 +1,35 @@ | |||
| ALTER TABLE `wx_c_user` | |||
| ADD COLUMN `user_id` bigint(11) COMMENT '用户ID' AFTER `active_time`; | |||
| update `wx_c_user` set user_id = id where id in (select id from wx_c_user_basic_info); | |||
| ALTER TABLE `wx_c_user_basic_info` | |||
| ADD COLUMN `final_tenant_id` varchar(5) NOT NULL COMMENT '归属租户ID' AFTER `parent_tenant_id`; | |||
| DROP INDEX `PHONE_UNIQUE`, | |||
| ADD UNIQUE INDEX `PHONE_UNIQUE`(`final_tenant_id`, `phone`) USING BTREE; | |||
| update wx_c_user_basic_info set final_tenant_id = parent_tenant_id; | |||
| update wx_c_user_basic_info set final_tenant_id = tenant_id where (parent_tenant_id is null or trim(parent_tenant_id) = ""); | |||
| ALTER TABLE `wx_c_user_basic_info` | |||
| ADD COLUMN `login_count` int(11) DEFAULT 0 COMMENT '登陆次数' AFTER `active_time`; | |||
| update wx_c_user_basic_info wcubi set wcubi.login_count = (select wcu.login_count from wx_c_user wcu where wcu.id=wcubi.id); | |||
| ALTER TABLE `wx_c_user_basic_info` | |||
| ADD COLUMN `avatar_url` int(11) DEFAULT 0 COMMENT '头像地址' AFTER `nick_name`; | |||
| update wx_c_user_basic_info wcubi set wcubi.avatar_url = (select wcu.avatar_url from wx_c_user wcu where wcu.id=wcubi.id); | |||
| ALTER TABLE `wx_coupon_order` | |||
| ADD COLUMN `pay_vendor` SMALLINT(3) NOT NULL DEFAULT 1 COMMENT '订单渠道,EnumPayWay.class'; | |||
| UPDATE wx_coupon_order o INNER JOIN wx_pay_order po ON po.order_id = o.`id` SET o.pay_vendor = po.pay_vendor; | |||
| ALTER TABLE `wx_card_spend` | |||
| ADD COLUMN `remark` VARCHAR(30) DEFAULT NULL COMMENT '备注'; | |||
| @@ -95,12 +95,13 @@ public class WxCUserController extends BaseController { | |||
| if (wxCUserFromB == null) { | |||
| //TODO phone可能为空 | |||
| String phone = wxCUser.getPhone(); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.findInfoByPhone(bUser, phone); | |||
| //查询会员信息 | |||
| List<WxCUserBasicInfo> byPhone = wxCUserBasicInfoService.findByPhone(bUser, phone); | |||
| //List<WxCUserBasicInfo> byPhone = wxCUserBasicInfoService.findByPhone(bUser, phone); | |||
| //存在会员信息 | |||
| if (!byPhone.isEmpty()) { | |||
| if (wxCUserBasicInfo != null) { | |||
| //更新会员信息 | |||
| WxCUserBasicInfo wxCUserBasicInfo = byPhone.get(0); | |||
| if (!StringUtils.isEmpty(wxCUserFromBDto.getName())) { | |||
| wxCUserBasicInfo.setName(wxCUserFromBDto.getName()); | |||
| } | |||
| @@ -133,7 +134,7 @@ public class WxCUserController extends BaseController { | |||
| } else { | |||
| //新增来自B端的会员 | |||
| long cUserId = idWorker.nextId(); | |||
| WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo(); | |||
| wxCUserBasicInfo = new WxCUserBasicInfo(); | |||
| wxCUserBasicInfo.setId(cUserId); | |||
| if (!StringUtils.isEmpty(wxCUserFromBDto.getName())) { | |||
| wxCUserBasicInfo.setName(wxCUserFromBDto.getName()); | |||
| @@ -10,6 +10,7 @@ import com.iformall.domain.vo.WxCouponActionLogVo; | |||
| import com.iformall.domain.vo.WxCouponSendVo; | |||
| import com.iformall.enums.EnumCouponSendSendType; | |||
| import com.iformall.enums.EnumCouponSendStatus; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxCUserMapper; | |||
| import com.iformall.service.WxCouponActionLogService; | |||
| @@ -101,7 +102,7 @@ public class WxCouponSendController extends BaseController { | |||
| wxCouponSend.setSendType(EnumCouponSendSendType.MERCHANT.getCode()); | |||
| wxCouponSend.setStatus(EnumCouponSendStatus.VALID.getCode()); | |||
| try { | |||
| wxCouponSendService.handSel(wxCouponSend, Long.parseLong(cUserId)); | |||
| wxCouponSendService.handSel(wxCouponSend, Long.parseLong(cUserId),EnumPayWay.PAY_WAY_NOT_UNPAY_MERCHANT); | |||
| } catch (MallinkException e) { | |||
| logger.error("注券异常: ", e); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| @@ -67,25 +67,25 @@ public class WxMemController extends BaseController { | |||
| WxMerchantBUser bUser = getUser(); | |||
| WxCUser cUser = userService.getById(id); | |||
| if(cUser == null) { | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| // WxCUser cUser = userService.getById(id); | |||
| // if(cUser == null) { | |||
| // return new ResultData(ErrorCode.USER_IS_EMPTY); | |||
| // } | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(cUser.getId()); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(id); | |||
| if (null != wxCUserBasicInfo && EnumCreditLockedStatus.CLOSE.getCode().equals(wxCUserBasicInfo.getStatus())) { | |||
| return new ResultData(ErrorCode.MEMBER_IS_LOCKED); | |||
| } | |||
| WxCUserVo userVo = new WxCUserVo(); | |||
| org.springframework.beans.BeanUtils.copyProperties(cUser, userVo); | |||
| if (wxCUserBasicInfo != null) { | |||
| userVo.setName(wxCUserBasicInfo.getName()); | |||
| userVo.setBirthdate(wxCUserBasicInfo.getBirthdate()); | |||
| userVo.setSex(wxCUserBasicInfo.getSex()); | |||
| userVo.setAddress(wxCUserBasicInfo.getAddress()); | |||
| } | |||
| org.springframework.beans.BeanUtils.copyProperties(wxCUserBasicInfo, userVo); | |||
| // if (wxCUserBasicInfo != null) { | |||
| // userVo.setName(wxCUserBasicInfo.getName()); | |||
| // userVo.setBirthdate(wxCUserBasicInfo.getBirthdate()); | |||
| // userVo.setSex(wxCUserBasicInfo.getSex()); | |||
| // userVo.setAddress(wxCUserBasicInfo.getAddress()); | |||
| // } | |||
| userVo.setLevelName(WxLevelConfigService.DEFAULT_LEVEL); | |||
| userVo.setDiscountRate(WxLevelConfigService.DEFAULT_MERCHANT_DISCOUNT); | |||
| @@ -58,12 +58,6 @@ public class WxMicroPayController extends BaseController { | |||
| @Autowired | |||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| @Autowired | |||
| private WxCUserService wxCUserService; | |||
| @Autowired | |||
| private PosCouponOrderVerifyService posCouponOrderVerifyService; | |||
| @ApiOperation(value = "付款码支付订单", notes = "params:{\"authCode\":\"String\",\"totalFee\":\"支付金额\"},\n" + | |||
| "注意:\n" + | |||
| "提醒1:提交支付请求后微信会同步返回支付结果。当返回结果为“系统错误”时,商户系统等待5秒后调用【查询订单API】,查询支付实际交易结果;当返回结果为“USERPAYING”时,商户系统可设置间隔时间(建议10秒)重新查询支付结果,直到支付成功或超时(建议30秒);\n" + | |||
| @@ -75,27 +69,30 @@ public class WxMicroPayController extends BaseController { | |||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||
| String authCode = paramMap.get("authCode"); | |||
| String totalFeeStr = paramMap.get("totalFee"); | |||
| return saveMicopayOrder(authCode, totalFeeStr, EnumPayWay.PAY_WAY_WECHAT_MA, request); | |||
| } | |||
| if (StringUtils.isBlank(authCode)) { | |||
| private ResultData saveMicopayOrder(String authCode,String totalFeeStr,EnumPayWay payWay,HttpServletRequest request) { | |||
| if (StringUtils.isBlank(authCode)) { | |||
| logger.error("authCode不能为空"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "authCode不能为空"); | |||
| } | |||
| if (StringUtils.isBlank(totalFeeStr)) { | |||
| logger.error("totalFee不能为空"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "totalFee不能为空"); | |||
| } | |||
| if (!checkAuthCode(authCode)) { | |||
| logger.error("authCode不符合规则"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "authCode不符合规则"); | |||
| } | |||
| String ipStr = IPUtil.getIpAddr(request); | |||
| if (StringUtils.isBlank(totalFeeStr)) { | |||
| logger.error("totalFee不能为空"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "totalFee不能为空"); | |||
| } | |||
| String ipStr = IPUtil.getIpAddr(request); | |||
| WxMerchantBUser user = getUser(); | |||
| WxOrder order = null; | |||
| try { | |||
| order = wxOrderService.saveMicroPayOrder(user, totalFeeStr); | |||
| order = wxOrderService.saveMicroPayOrder(user, totalFeeStr,payWay); | |||
| } catch (MallinkException e) { | |||
| logger.error("saveMicopayOrder 1" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| @@ -110,9 +107,8 @@ public class WxMicroPayController extends BaseController { | |||
| record.setAuthCode(authCode); | |||
| record.setPayAmount(order.getPayment()); | |||
| record.setIp(ipStr); | |||
| try { | |||
| return wxPayOrderService.createMicroPayOrder(user, record, EnumPayWay.PAY_WAY_WECHAT); | |||
| return wxPayOrderService.createMicroPayOrder(user, record, payWay, null); | |||
| } catch (MallinkException e) { | |||
| logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| @@ -121,16 +117,19 @@ public class WxMicroPayController extends BaseController { | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, e.getMessage()); | |||
| } | |||
| } | |||
| @ApiOperation(value = "查询付款码支付订单", notes = "{\"payOrderId\":\"String\",\"orderId\":\"String\"}") | |||
| @PostMapping("order_query") | |||
| public ResultData queryMicopayOrder(@RequestBody Map<String, String> paramMap) { | |||
| logger.info("queryMicopayOrder: " + paramMap.toString()); | |||
| WxMerchantBUser user = getUser(); | |||
| String payOrderIdStr = paramMap.get("payOrderId"); | |||
| String orderIdStr = paramMap.get("orderId"); | |||
| return queryMicopayOrder(payOrderIdStr,orderIdStr,EnumPayWay.PAY_WAY_WECHAT_MA); | |||
| } | |||
| private ResultData queryMicopayOrder(String payOrderIdStr,String orderIdStr,EnumPayWay payWay) { | |||
| WxMerchantBUser user = getUser(); | |||
| if (StringUtils.isBlank(payOrderIdStr)) { | |||
| logger.error("payOrderId不能为空"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "payOrderId不能为空"); | |||
| @@ -146,14 +145,14 @@ public class WxMicroPayController extends BaseController { | |||
| payOrderId = Long.valueOf(payOrderIdStr); | |||
| } catch (NumberFormatException e) { | |||
| payOrderId = 0L; | |||
| logger.error("payOrderId参数不正确: " + paramMap.toString()); | |||
| logger.error("payOrderId参数不正确: " + payOrderIdStr); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| try { | |||
| orderId = Long.valueOf(orderIdStr); | |||
| } catch (NumberFormatException e) { | |||
| orderId = 0L; | |||
| logger.error("orderId参数不正确: " + paramMap.toString()); | |||
| logger.error("orderId参数不正确: " + orderIdStr); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| @@ -164,7 +163,7 @@ public class WxMicroPayController extends BaseController { | |||
| record.setOrderId(orderId); | |||
| try { | |||
| ResultData resultData = wxPayOrderService.payOrderQuery(user, record); | |||
| ResultData resultData = wxPayOrderService.payOrderQuery(user, record, payWay); | |||
| return resultData; | |||
| } catch (MallinkException e) { | |||
| logger.error("payment wechat, order query error, req 2: " + record.toString() + ", e:" + e.getMessage()); | |||
| @@ -174,6 +173,7 @@ public class WxMicroPayController extends BaseController { | |||
| return new ResultData(ErrorCode.PAY_ORDER_QUERY_ERROR, e.getMessage()); | |||
| } | |||
| } | |||
| @ApiOperation(value = "撤销付款码支付订单", notes = "{\"payOrderId\":\"String\",\"orderId\":\"String\"}") | |||
| @PostMapping("order_reverse") | |||
| @@ -311,7 +311,7 @@ public class WxMicroPayController extends BaseController { | |||
| } | |||
| // 获取C用户 | |||
| WxCUser cUser = null; | |||
| WxCUserBasicInfo cUser = null; | |||
| if (StringUtils.isNotBlank(cUserIdStr)) { | |||
| Long cUserId = 0L; | |||
| try { | |||
| @@ -321,12 +321,9 @@ public class WxMicroPayController extends BaseController { | |||
| logger.error("cUserId参数不正确: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_CLASSCAST_ERROR); | |||
| } | |||
| cUser = wxCUserService.getById(cUserId); | |||
| cUser = wxCUserBasicInfoService.getById(cUserId); | |||
| } else { | |||
| WxCUser userQ = new WxCUser(); | |||
| userQ.updateTenantInfo(user); | |||
| userQ.setPhone(phone); | |||
| cUser = wxCUserService.getByObject(userQ); | |||
| cUser = wxCUserBasicInfoService.findInfoByPhone(user,phone); | |||
| } | |||
| if (cUser == null) { | |||
| logger.error("cUser不存在: " + cUserIdStr); | |||
| @@ -342,6 +339,7 @@ public class WxMicroPayController extends BaseController { | |||
| WxOrder order = null; | |||
| try { | |||
| order = wxOrderService.saveMicroPayOrderV2(user, cUser, payment); | |||
| } catch (MallinkException e) { | |||
| logger.error("saveMicopayOrder 1" + e.getMessage()); | |||
| @@ -372,12 +370,16 @@ public class WxMicroPayController extends BaseController { | |||
| @PostMapping("pay_order_create_v2") | |||
| public ResultData saveMicopayPayOrder(@RequestBody Map<String, String> paramMap, HttpServletRequest request) { | |||
| logger.info("saveMicopayPayOrder: " + paramMap.toString()); | |||
| WxMerchantBUser user = getUser(); | |||
| String orderIdStr = paramMap.get("orderId"); | |||
| String couponOrderIdStr = paramMap.get("couponOrderId"); | |||
| String authCode = paramMap.get("authCode"); | |||
| String payPriceStr = paramMap.get("payPrice"); | |||
| return saveMicopayPayOrder(orderIdStr, couponOrderIdStr, authCode, payPriceStr, EnumPayWay.PAY_WAY_WECHAT_MA, request); | |||
| } | |||
| private ResultData saveMicopayPayOrder(String orderIdStr,String couponOrderIdStr,String authCode,String payPriceStr, | |||
| EnumPayWay payWay, HttpServletRequest request) { | |||
| WxMerchantBUser user = getUser(); | |||
| if (StringUtils.isBlank(orderIdStr)) { | |||
| logger.error("orderId不能为空"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||
| @@ -413,7 +415,7 @@ public class WxMicroPayController extends BaseController { | |||
| orderId = Long.valueOf(orderIdStr); | |||
| } catch (NumberFormatException e) { | |||
| orderId = 0L; | |||
| logger.error("orderId参数不正确: " + paramMap.toString()); | |||
| logger.error("orderId参数不正确: " + orderIdStr); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| @@ -428,7 +430,7 @@ public class WxMicroPayController extends BaseController { | |||
| couponOrderId = Long.valueOf(couponOrderIdStr); | |||
| } catch (NumberFormatException e) { | |||
| couponOrderId = 0L; | |||
| logger.error("couponOrderId参数不正确: " + paramMap.toString()); | |||
| logger.error("couponOrderId参数不正确: " + couponOrderIdStr); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| wxCouponOrder = wxCouponOrderService.getById(couponOrderId); | |||
| @@ -438,7 +440,7 @@ public class WxMicroPayController extends BaseController { | |||
| Integer remainPrice = payPrice; | |||
| if (wxCouponOrder != null) { | |||
| try { | |||
| couponPayOrder = wxCouponOrderService.microPayPreVerify(microOrder, wxCouponOrder, wxMerchantBUser, payPrice); | |||
| couponPayOrder = wxCouponOrderService.microPayPreVerify(microOrder, wxCouponOrder, wxMerchantBUser, payPrice,payWay); | |||
| remainPrice = microOrder.getPayment() - couponPayOrder.getPayAmount(); | |||
| // 更新实际支付金额 | |||
| WxOrder updateOrder = new WxOrder(); | |||
| @@ -473,7 +475,7 @@ public class WxMicroPayController extends BaseController { | |||
| record.setIp(ipStr); | |||
| try { | |||
| return wxPayOrderService.createMicroPayOrder(user, record, EnumPayWay.PAY_WAY_WECHAT); | |||
| return wxPayOrderService.createMicroPayOrder(user, record, payWay, null); | |||
| } catch (MallinkException e) { | |||
| logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| @@ -485,7 +487,7 @@ public class WxMicroPayController extends BaseController { | |||
| // 支付完成 | |||
| couponPayOrder.setIp(ipStr); | |||
| try { | |||
| wxPayOrderService.handleMicroOrderPaySuccessForVerify(user, couponPayOrder); | |||
| wxPayOrderService.handleMicroOrderPaySuccessForVerify(user, couponPayOrder,payWay); | |||
| Map map = new HashMap(); | |||
| map.put("end", "1"); | |||
| return new ResultData(map); | |||
| @@ -498,7 +500,7 @@ public class WxMicroPayController extends BaseController { | |||
| } | |||
| } | |||
| } | |||
| private Boolean checkAuthCode(String authCode) { | |||
| if (authCode.length() == 18) { | |||
| String head = authCode.substring(0, 2); | |||
| @@ -106,6 +106,23 @@ public class RedisConfig extends CachingConfigurerSupport { | |||
| template.setConnectionFactory(connectionFactory); | |||
| return template; | |||
| } | |||
| @Bean("cUserBasicInfoRedisTemplate") | |||
| public RedisTemplate<String, WxCUserBasicInfo> getCUserBasicInfoRedisTemplate(RedisConnectionFactory connectionFactory) { | |||
| RedisTemplate<String, WxCUserBasicInfo> template = new RedisTemplate<String, WxCUserBasicInfo>(); | |||
| Jackson2JsonRedisSerializer<WxCUserBasicInfo> j = new Jackson2JsonRedisSerializer<WxCUserBasicInfo>(WxCUserBasicInfo.class); | |||
| // value值的序列化 | |||
| template.setValueSerializer(j); | |||
| template.setHashKeySerializer(j); | |||
| // key的序列化 | |||
| template.setKeySerializer(new StringRedisSerializer()); | |||
| template.setHashKeySerializer(new StringRedisSerializer()); | |||
| template.setConnectionFactory(connectionFactory); | |||
| return template; | |||
| } | |||
| @Bean("mallRedisTemplate") | |||
| public RedisTemplate<String, WxMall> getMallRedisTemplate(RedisConnectionFactory connectionFactory) { | |||
| @@ -93,6 +93,15 @@ public class BaseController { | |||
| return cUserId; | |||
| } | |||
| public Long getMemberId() { | |||
| HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | |||
| Long memberId = (Long) request.getAttribute(Constant.LOGIN_MEMBER_KEY); | |||
| if(memberId == null){ | |||
| throw new MallinkException(ErrorCode.USER_IS_NOT_MEMBER); | |||
| } | |||
| return memberId; | |||
| } | |||
| /** | |||
| * 请尽量多用getTenantId, getUserId | |||
| */ | |||
| @@ -112,6 +121,18 @@ public class BaseController { | |||
| return user; | |||
| } | |||
| /** | |||
| * | |||
| */ | |||
| public WxCUserBasicInfo getMember() { | |||
| Long memberId = getMemberId(); | |||
| WxCUserBasicInfo member = wxCUserBasicInfoService.getById(memberId); | |||
| if (member == null) { | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| return member; | |||
| } | |||
| public WxAppinfo getAppInfo(String appId) { | |||
| return wxAppinfoService.getByAppId(appId); | |||
| } | |||
| @@ -148,39 +169,59 @@ public class BaseController { | |||
| if (StringUtils.isBlank(phone)) | |||
| return; | |||
| List<WxCUserBasicInfo> list = wxCUserBasicInfoService.findByPhone(tenantEntity, phone); | |||
| if (list.size() > 0) { | |||
| WxCUserBasicInfo basicInfo = list.get(0); | |||
| WxCUserBasicInfo byId = null; | |||
| if(user.isBasicInfo()){ | |||
| byId = wxCUserBasicInfoService.getById(user.getUserId()); | |||
| } | |||
| // List<WxCUserBasicInfo> list = wxCUserBasicInfoService.findByPhone(tenantEntity, phone); | |||
| WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(tenantEntity, phone); | |||
| if (basicInfo != null) { | |||
| // WxCUserBasicInfo basicInfo = list.get(0); | |||
| // 微信名称,统一成微信昵称 | |||
| if (!Objects.equals(basicInfo.getNickName(), user.getNickName())) { | |||
| basicInfo.setNickName(user.getNickName()); | |||
| } | |||
| // 性别 | |||
| if (basicInfo.getSex() == null) { | |||
| basicInfo.setSex(user.getGender()); | |||
| } | |||
| // 成长值 | |||
| if (Objects.nonNull(user.getScore())) { | |||
| basicInfo.setPoins(user.getScore()); | |||
| } | |||
| // 积分 | |||
| if (Objects.nonNull(user.getCredit())) { | |||
| basicInfo.setCredit(user.getCredit()); | |||
| } | |||
| wxCUserBasicInfoService.updateObj(basicInfo, user); | |||
| } else { | |||
| // if (!Objects.equals(basicInfo.getNickName(), user.getNickName())) { | |||
| // basicInfo.setNickName(user.getNickName()); | |||
| // } | |||
| // // 性别 | |||
| // if (basicInfo.getSex() == null) { | |||
| // basicInfo.setSex(user.getGender()); | |||
| // } | |||
| // // 成长值 | |||
| // if (Objects.nonNull(user.getScore())) { | |||
| // basicInfo.setPoins(user.getScore()); | |||
| // } | |||
| // // 积分 | |||
| // if (Objects.nonNull(user.getCredit())) { | |||
| // basicInfo.setCredit(user.getCredit()); | |||
| // } | |||
| user.setUserId(basicInfo.getId()); | |||
| wxCUserService.updateUserId(user); | |||
| //wxCUserBasicInfoService.updateObj(basicInfo, user); | |||
| } else if(byId != null){ | |||
| byId.setPhone(phone); | |||
| byId.setNickName(user.getNickName()); | |||
| byId.setAvatarUrl(user.getAvatarUrl()); | |||
| wxCUserBasicInfoService.update(byId); | |||
| }else{ | |||
| Date cur = new Date(); | |||
| WxCUserBasicInfo basicInfo = new WxCUserBasicInfo(); | |||
| basicInfo = new WxCUserBasicInfo(); | |||
| basicInfo.setId(user.getId()); | |||
| basicInfo.updateTenantInfo(tenantEntity); | |||
| basicInfo.setPhone(phone); | |||
| basicInfo.setNickName(user.getNickName()); | |||
| basicInfo.setAvatarUrl(user.getAvatarUrl()); | |||
| basicInfo.setSex(user.getGender()); | |||
| basicInfo.setPoins(user.getScore()); | |||
| basicInfo.setLoginCount(1); | |||
| basicInfo.setActiveTime(cur); | |||
| basicInfo.setCreateDate(cur); | |||
| basicInfo.setUpdateDate(cur); | |||
| basicInfo.setCredit(user.getCredit()); | |||
| wxCUserBasicInfoService.save(basicInfo); | |||
| user.setUserId(basicInfo.getId()); | |||
| wxCUserService.updateUserId(user); | |||
| } | |||
| } | |||
| @@ -189,4 +230,6 @@ public class BaseController { | |||
| String ipaddress = IPUtil.getIpAddr(request); | |||
| return ipaddress; | |||
| } | |||
| } | |||
| @@ -35,7 +35,7 @@ public class WxActivityController extends BaseController { | |||
| @GetMapping("/queryStatus") | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| public ResultData queryStatus(Long id) { | |||
| return new ResultData(wxActivityService.queryStatus(id, getUserId())); | |||
| return new ResultData(wxActivityService.queryStatus(id, getMemberId())); | |||
| } | |||
| @ApiOperation("根据id查询接口") | |||
| @@ -43,7 +43,7 @@ public class WxActivityController extends BaseController { | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| public ResultData findById(Long id) { | |||
| WxActivity wxActivity = wxActivityService.getById(id); | |||
| Integer status = wxActivityService.queryStatus(id, getUserId()); | |||
| Integer status = wxActivityService.queryStatus(id, getMemberId()); | |||
| Map<String, Object> data = new HashMap<>(); | |||
| data.put("activity", wxActivity); | |||
| data.put("status", status); | |||
| @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.domain.po.WxActivity; | |||
| import com.iformall.domain.po.WxActivityJoin; | |||
| @@ -41,9 +42,11 @@ public class WxActivityJoinController extends BaseController { | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||
| public ResultData list(@ModelAttribute WxActivityJoin wxActivityJoin, Integer pageNum, Integer pageSize) { | |||
| if (null == wxActivityJoin) wxActivityJoin = new WxActivityJoin(); | |||
| if (null == wxActivityJoin) { | |||
| wxActivityJoin = new WxActivityJoin(); | |||
| } | |||
| wxActivityJoin.updateTenantInfo(getTenantInfo()); | |||
| wxActivityJoin.setUserId(getUserId()); | |||
| wxActivityJoin.setUserId(getMemberId()); | |||
| wxActivityJoin.setSortColumns(BaseEntity.SortField.CreateTime_DESC); | |||
| final PageInfo<WxActivity> page = wxActivityJoinService.clistAsPage(wxActivityJoin, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| @@ -55,9 +58,10 @@ public class WxActivityJoinController extends BaseController { | |||
| if (wxActivityJoin.getActivityId() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "activityId不能为空"); | |||
| } | |||
| WxCUserBasicInfo member = getMember(); | |||
| wxActivityJoin.updateTenantInfo(getTenantInfo()); | |||
| wxActivityJoin.setUserId(getUserId()); | |||
| wxActivityJoin.setNickName(getUser().getNickName()); | |||
| wxActivityJoin.setUserId(member.getId()); | |||
| wxActivityJoin.setNickName(member.getNickName()); | |||
| if (StringUtils.isNotEmpty(wxActivityJoin.getAnswer())) { | |||
| List<WxActivityJoinQuestionAnswer> wxActivityJoinQuestionAnswers = JSONArray.parseArray(wxActivityJoin.getAnswer(), WxActivityJoinQuestionAnswer.class); | |||
| List<WxActivityJoinQuestionAnswer> collect = wxActivityJoinQuestionAnswers.stream().filter(answer -> answer != null).collect(Collectors.toList()); | |||
| @@ -78,7 +82,7 @@ public class WxActivityJoinController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "activityId不能为空"); | |||
| } | |||
| wxActivityJoin.updateTenantInfo(getTenantInfo()); | |||
| wxActivityJoin.setUserId(getUserId()); | |||
| wxActivityJoin.setUserId(getMemberId()); | |||
| return wxActivityJoinService.sign(wxActivityJoin); | |||
| } | |||
| @@ -70,6 +70,9 @@ public class WxCarController extends BaseController { | |||
| @Autowired | |||
| WxCreditHistoryService wxCreditHistoryService; | |||
| @Autowired | |||
| WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| private WxPark getCurrentPark(TenantEntity tenantEntity) { | |||
| WxPark parkQ = new WxPark(); | |||
| parkQ.updateTenantInfo(tenantEntity); | |||
| @@ -98,12 +101,11 @@ public class WxCarController extends BaseController { | |||
| @ApiOperation(value = "初始化/etcp共同登录", notes = "{\"phone\":\"string\"}") | |||
| @PostMapping("/init") | |||
| public ResultData init(@RequestBody Map<String, String> paramMap) { | |||
| WxCUser user = getUser(); | |||
| // 1, get mall's park | |||
| WxPark park = getCurrentPark(getTenantInfo()); | |||
| // 2. get vendor params | |||
| if (park.getVendorType().equals(EnumCarVendor.CAR_ETCP.getCode())) { | |||
| return initForEtcp(paramMap, user, park); | |||
| return initForEtcp(paramMap, getMemberId(), park); | |||
| } else if (park.getVendorType().equals(EnumCarVendor.CAR_TJD.getCode()) || | |||
| park.getVendorType().equals(EnumCarVendor.CAR_DAHUA.getCode()) || | |||
| park.getVendorType().equals(EnumCarVendor.CAR_SHANGAN.getCode()) || | |||
| @@ -115,16 +117,15 @@ public class WxCarController extends BaseController { | |||
| return new ResultData(ErrorCode.CAR_VENDOR_NOT_SUPPORT.getCode(), "登录失败"); | |||
| } | |||
| private ResultData initForEtcp(Map<String, String> paramMap, WxCUser user, WxPark park) { | |||
| private ResultData initForEtcp(Map<String, String> paramMap, Long userId, WxPark park) { | |||
| String phone = paramMap.get("phone"); | |||
| if (StringUtils.isBlank(phone) && StringUtils.isBlank(user.getPhone()) && StringUtils.isBlank(user.getVerifyCodePhone())) { | |||
| logger.error("手机号为空,请授权手机号"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "手机号为空,请授权手机号"); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoService.getById(userId); | |||
| if (StringUtils.isBlank(phone) && StringUtils.isBlank(user.getPhone())) { | |||
| logger.error("暂未成为会员,请授权手机号"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "暂未成为会员,请授权手机号"); | |||
| } | |||
| if (!StringUtils.isBlank(user.getPhone()) && !user.getPhone().contains("*")) { | |||
| phone = user.getPhone(); | |||
| } else { | |||
| phone = user.getVerifyCodePhone(); | |||
| } | |||
| String params = park.getVendorParams(); | |||
| JSONObject objParams = JSON.parseObject(params); | |||
| @@ -255,16 +256,17 @@ public class WxCarController extends BaseController { | |||
| @ApiOperation(value = "绑车牌", notes = "ETCP:={\"etcpToken\":\"string\",\"carNumber\":\"string\"}, TJD:={\"carNumber\":\"string\"}") | |||
| @PostMapping("/bindCar") | |||
| public ResultData bindCar(@RequestBody Map<String, String> paramMap) { | |||
| WxCUserBasicInfo member = getMember(); | |||
| // 1, get mall's park | |||
| WxPark park = getCurrentPark(getTenantInfo()); | |||
| // 2. get vendor params | |||
| if (park.getVendorType() == EnumCarVendor.CAR_ETCP.getCode()) { | |||
| return etcpBindCar(paramMap, park, getUserId()); | |||
| return etcpBindCar(paramMap, park, member.getId()); | |||
| } else if (park.getVendorType() == EnumCarVendor.CAE_CYF.getCode()){ | |||
| return cyfBindCar(paramMap,park,getUser()); | |||
| return cyfBindCar(paramMap,park,member); | |||
| } else { | |||
| // 内部操作 | |||
| return bindCar(paramMap, park, getUserId()); | |||
| return bindCar(paramMap, park, member.getId()); | |||
| } | |||
| } | |||
| @@ -326,7 +328,7 @@ public class WxCarController extends BaseController { | |||
| // 插入车牌 | |||
| Date curr = new Date(); | |||
| WxCUserCar userCar = new WxCUserCar(); | |||
| userCar.setCUserId(getUserId()); | |||
| userCar.setCUserId(cuUserId); | |||
| userCar.updateTenantInfo(park); | |||
| userCar.setCarNumber(carNumber); | |||
| userCar.setVendorType(carVendor.getCode()); | |||
| @@ -338,7 +340,7 @@ public class WxCarController extends BaseController { | |||
| wxScoreRulesService.addScore(EnumScoreType.BIND_CAR, userCar); | |||
| //增加积分 | |||
| addCredit(park, cuUserId); | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_CAR,getUserId()); | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_CAR,cuUserId); | |||
| } | |||
| private ResultData tjdBindCar(@RequestBody Map<String, String> paramMap, WxPark park, Long cuUserId) { | |||
| @@ -385,7 +387,7 @@ public class WxCarController extends BaseController { | |||
| * @Author furunxin | |||
| * @Date 2020/7/8 下午10:23 | |||
| **/ | |||
| private ResultData cyfBindCar(@RequestBody Map<String, String> paramMap, WxPark park,WxCUser wxCUser) { | |||
| private ResultData cyfBindCar(@RequestBody Map<String, String> paramMap, WxPark park,WxCUserBasicInfo member) { | |||
| String carNumber = paramMap.get("carNumber"); | |||
| if (StringUtils.isBlank(carNumber)) { | |||
| logger.error("carNumber为空"); | |||
| @@ -395,10 +397,10 @@ public class WxCarController extends BaseController { | |||
| JSONObject objParams = JSON.parseObject(params); | |||
| String token = objParams.getString("token"); | |||
| int feeGroupId = objParams.getIntValue("feeGroupId"); | |||
| String ret = cyf.registerCar(token,park.getNumber(),feeGroupId,park.getParkingId(),carNumber,wxCUser.getId(),wxCUser.getNickName()); | |||
| String ret = cyf.registerCar(token,park.getNumber(),feeGroupId,park.getParkingId(),carNumber,member.getId(),member.getNickName()); | |||
| JSONObject retObj = JSON.parseObject(ret); | |||
| if (retObj.getIntValue("result") == 1){ | |||
| addCarInfoToDB(carNumber, EnumCarVendor.getEnum(park.getVendorType()), park, wxCUser.getId()); | |||
| addCarInfoToDB(carNumber, EnumCarVendor.getEnum(park.getVendorType()), park, member.getId()); | |||
| }else { | |||
| return new ResultData(ErrorCode.CAR_BIND_FAIL.getCode(), "绑车牌失败", retObj); | |||
| } | |||
| @@ -430,7 +432,7 @@ public class WxCarController extends BaseController { | |||
| return new ResultData(ErrorCode.DB_FAIL.getCode(), "TJD保存车牌失败, e:" + e.getMessage()); | |||
| } | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_CAR, getUserId()); | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_CAR, cuUserId); | |||
| return null; | |||
| } | |||
| @@ -463,9 +465,9 @@ public class WxCarController extends BaseController { | |||
| // 1, get mall's park | |||
| WxPark park = getCurrentPark(getTenantInfo()); | |||
| if (park.getVendorType().equals(EnumCarVendor.CAR_ETCP.getCode())) { | |||
| return etcpUnbindCar(paramMap, park, getUserId()); | |||
| return etcpUnbindCar(paramMap, park, getMemberId()); | |||
| } else { | |||
| return unbindCar(paramMap, park, getUserId()); | |||
| return unbindCar(paramMap, park, getMemberId()); | |||
| } | |||
| } | |||
| @@ -536,7 +538,7 @@ public class WxCarController extends BaseController { | |||
| return new ResultData(); | |||
| } | |||
| private ResultData tjdUnbindCar(@RequestBody Map<String, String> paramMap, WxPark park) { | |||
| private ResultData tjdUnbindCar(@RequestBody Map<String, String> paramMap, WxPark park, Long userId) { | |||
| String carNumber = paramMap.get("carNumber"); | |||
| if (StringUtils.isBlank(carNumber)) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "carNumber为空"); | |||
| @@ -544,7 +546,7 @@ public class WxCarController extends BaseController { | |||
| WxCUserCar queryOne = new WxCUserCar(); | |||
| queryOne.setCarNumber(carNumber); | |||
| queryOne.updateTenantInfo(park); | |||
| queryOne.setCUserId(getUserId()); | |||
| queryOne.setCUserId(userId); | |||
| WxCUserCar userCar = wxCUserCarService.getOne(queryOne); | |||
| if (userCar != null) { | |||
| String params = userCar.getVendorParams(); | |||
| @@ -802,7 +804,7 @@ public class WxCarController extends BaseController { | |||
| WxCouponOrderCarCVo userCar = null; | |||
| WxCouponOrder userCarQ = new WxCouponOrder(); | |||
| userCarQ.updateTenantInfo(park); | |||
| userCarQ.setCUserId(getUserId()); | |||
| userCarQ.setCUserId(getMemberId()); | |||
| userCarQ.setId(couponOrderId); | |||
| userCarQ.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||
| List<WxCouponOrderCarCVo> list = wxCouponOrderService.carListCUserVo(userCarQ); | |||
| @@ -975,13 +977,12 @@ public class WxCarController extends BaseController { | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | |||
| }) | |||
| public ResultData list(@ModelAttribute WxCouponOrder wxCouponOrder, Integer pageNum, Integer pageSize) { | |||
| if (pageNum == null || pageSize == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| if (wxCouponOrder == null) wxCouponOrder = new WxCouponOrderCarCVo(); | |||
| wxCouponOrder.updateTenantInfo(getTenantInfo()); | |||
| wxCouponOrder.setCUserId(getUserId()); | |||
| wxCouponOrder.setCUserId(getMemberId()); | |||
| if (wxCouponOrder.getCouponOrderStatus() == null) | |||
| wxCouponOrder.setSortColumns(BaseEntity.SortField.CreateDate_DESC); | |||
| else if (wxCouponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()) | |||
| @@ -1,30 +1,51 @@ | |||
| package com.iformall.controller; | |||
| import java.math.BigDecimal; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.GetMapping; | |||
| import org.springframework.web.bind.annotation.ModelAttribute; | |||
| import org.springframework.web.bind.annotation.PostMapping; | |||
| import org.springframework.web.bind.annotation.RequestBody; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxCardInfo; | |||
| import com.iformall.domain.po.WxCardSpend; | |||
| import com.iformall.domain.po.WxCouponMerchant; | |||
| import com.iformall.domain.po.WxCouponOrder; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.vo.WxCardSpendVo; | |||
| import com.iformall.enums.EnumCreditLockedStatus; | |||
| import com.iformall.enums.EnumMerchantStatus; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.*; | |||
| import com.iformall.service.WxCUserBasicInfoService; | |||
| import com.iformall.service.WxCardInfoService; | |||
| import com.iformall.service.WxCardSpendService; | |||
| import com.iformall.service.WxCouponOrderService; | |||
| import com.iformall.service.WxMerchantService; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.utils.Constant; | |||
| 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.web.bind.annotation.*; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.math.BigDecimal; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| /** | |||
| * @author Stormeye Wu wuguoqiang@iformall.com | |||
| @@ -53,23 +74,23 @@ public class WxCardPayController extends BaseController { | |||
| @Autowired | |||
| WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| @ApiOperation(value = "C端扫B端储值卡支付订单", notes = "params:{\"cardId\":\"String\",\"merchantId\":\"String\",\"totalFee\":\"String(元)\"}") | |||
| @ApiOperation(value = "微信C端扫B端储值卡支付订单", notes = "params:{\"cardId\":\"String\",\"merchantId\":\"String\",\"totalFee\":\"String(元)\"}") | |||
| @PostMapping("order_create") | |||
| public ResultData saveCardPayOrder(@RequestBody Map<String, String> paramMap, HttpServletRequest request) { | |||
| String ipStr = getIpAddr(); | |||
| logger.info("saveCardPayOrder: " + ipStr + " :" + paramMap.toString()); | |||
| String cardIdStr = paramMap.get("cardId"); | |||
| String merchantStr = paramMap.get("merchantId"); | |||
| String totalFeeStr = paramMap.get("totalFee"); | |||
| return saveCardPayOrder(getMemberId(),cardIdStr,merchantStr,totalFeeStr,EnumPayWay.PAY_WAY_WECHAT); | |||
| } | |||
| WxCUser user = getUser(); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(user.getId()); | |||
| private ResultData saveCardPayOrder(Long cUserId,String cardIdStr,String merchantStr,String totalFeeStr,EnumPayWay payWay) { | |||
| String ipStr = getIpAddr(); | |||
| logger.info("saveCardPayOrder: " + ipStr + " : cUserId:{} , cardIdStr:{},merchantStr:{},totalFeeStr:{}",cUserId,cardIdStr,cardIdStr,cardIdStr); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(cUserId); | |||
| if (null != wxCUserBasicInfo && EnumCreditLockedStatus.CLOSE.getCode().equals(wxCUserBasicInfo.getStatus())) { | |||
| logger.error(ErrorCode.MEMBER_IS_LOCKED.getMessage()); | |||
| return new ResultData(ErrorCode.MEMBER_IS_LOCKED); | |||
| } | |||
| String cardIdStr = paramMap.get("cardId"); | |||
| String merchantStr = paramMap.get("merchantId"); | |||
| String totalFeeStr = paramMap.get("totalFee"); | |||
| if (StringUtils.isBlank(cardIdStr) || cardIdStr.equalsIgnoreCase(Constant.UNDEFINED)) { | |||
| logger.error("cardId不能为空"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "cardId不能为空"); | |||
| @@ -115,7 +136,7 @@ public class WxCardPayController extends BaseController { | |||
| //查看所有者与扫码者是否为一致 | |||
| WxCouponOrder couponOrder = wxCouponOrderService.getById(cardId); | |||
| if (!couponOrder.getOwnerId().equals(getUserId())) { | |||
| if (!couponOrder.getOwnerId().equals(cUserId)) { | |||
| logger.error("卡已被领取: " + cardIdStr); | |||
| return new ResultData(ErrorCode.CARD_TRANSFERED); | |||
| } | |||
| @@ -134,7 +155,7 @@ public class WxCardPayController extends BaseController { | |||
| WxOrder order = null; | |||
| try { | |||
| order = wxOrderService.saveCardPayOrder(merchant, getUserId(), totalFeeStr, payment); | |||
| order = wxOrderService.saveCardPayOrder(merchant, cUserId, totalFeeStr, payment,payWay); | |||
| } catch (MallinkException e) { | |||
| logger.error("saveCardPayOrder 1" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| @@ -146,14 +167,15 @@ public class WxCardPayController extends BaseController { | |||
| WxCardSpend record = new WxCardSpend(); | |||
| record.updateTenantInfo(merchant); | |||
| record.setCardId(cardId); | |||
| record.setOwnerId(getUserId()); | |||
| record.setOwnerId(cUserId); | |||
| record.setMerchantId(merchantId); | |||
| record.setOrderId(order.getId()); | |||
| record.setIp(ipStr); | |||
| record.setDeductionAmount(payment); | |||
| record.setRemark("操作于["+payWay.getMessage()+"("+payWay.getCode()+")]"); | |||
| try { | |||
| return wxCardSpendService.createCardSpend(record, order, couponMerchant); | |||
| return wxCardSpendService.createCardSpend(record, order, couponMerchant,payWay); | |||
| } catch (MallinkException e) { | |||
| logger.error("card spend error, req 2: " + record.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| @@ -162,7 +184,8 @@ public class WxCardPayController extends BaseController { | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, e.getMessage()); | |||
| } | |||
| } | |||
| @ApiOperation("C端扫B端储值卡交易流水列表接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @@ -171,9 +194,13 @@ public class WxCardPayController extends BaseController { | |||
| public ResultData cardSpendList(@ModelAttribute WxCardSpendVo wxCardSpend, Integer pageNum, Integer pageSize) { | |||
| String ipStr = getIpAddr(); | |||
| logger.info("list: " + ipStr + " :" + wxCardSpend.toString()); | |||
| if (wxCardSpend == null) wxCardSpend = new WxCardSpendVo(); | |||
| return cardSpendList(wxCardSpend,getMemberId(), pageNum, pageSize); | |||
| } | |||
| private ResultData cardSpendList(WxCardSpendVo wxCardSpend,Long cUserId,Integer pageNum, Integer pageSize) { | |||
| if (wxCardSpend == null) wxCardSpend = new WxCardSpendVo(); | |||
| wxCardSpend.updateTenantInfo(getTenantInfo()); | |||
| wxCardSpend.setOwnerId(getUserId()); | |||
| wxCardSpend.setOwnerId(cUserId); | |||
| final PageInfo<WxCardSpendVo> page = wxCardSpendService.listAsPage(wxCardSpend, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| @@ -183,9 +210,13 @@ public class WxCardPayController extends BaseController { | |||
| public ResultData sumCardSpendList(@ModelAttribute WxCardSpendVo wxCardSpend) { | |||
| String ipStr = getIpAddr(); | |||
| logger.info("sumCardSpendList: " + ipStr + " :" + wxCardSpend.toString()); | |||
| if (wxCardSpend == null) wxCardSpend = new WxCardSpendVo(); | |||
| return sumCardSpendList(wxCardSpend, getMemberId()); | |||
| } | |||
| private ResultData sumCardSpendList(WxCardSpendVo wxCardSpend,Long cUserId) { | |||
| if (wxCardSpend == null) wxCardSpend = new WxCardSpendVo(); | |||
| wxCardSpend.updateTenantInfo(getTenantInfo()); | |||
| wxCardSpend.setOwnerId(getUserId()); | |||
| wxCardSpend.setOwnerId(cUserId); | |||
| final List<Map<String, Object>> mapList = wxCardSpendService.sumCardSpendForOwner(wxCardSpend); | |||
| return new ResultData(mapList); | |||
| } | |||
| @@ -5,6 +5,7 @@ import com.iformall.annotation.RedisCache; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.domain.po.WxCouponOrder; | |||
| @@ -65,12 +66,11 @@ public class WxCouponOrderController extends BaseController { | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | |||
| }) | |||
| public ResultData list(@ModelAttribute WxCouponOrder wxCouponOrder, Integer pageNum, Integer pageSize) { | |||
| if (pageNum == null || pageSize == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| if (wxCouponOrder == null) wxCouponOrder = new WxCouponOrderCVo(); | |||
| wxCouponOrder.setCUserId(getUserId()); | |||
| wxCouponOrder.setCUserId(getMemberId()); | |||
| if (wxCouponOrder.getCouponOrderStatus() == null) | |||
| wxCouponOrder.setSortColumns(BaseEntity.SortField.CreateDate_DESC, BaseEntity.SortField.Id_DESC); | |||
| else if (wxCouponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()) | |||
| @@ -112,7 +112,7 @@ public class WxCouponOrderController extends BaseController { | |||
| if (wxCouponOrderCVo == null) { | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); | |||
| } | |||
| if (!wxCouponOrderCVo.getCUserId().equals(getUserId())) { | |||
| if (!wxCouponOrderCVo.getCUserId().equals(getMemberId())) { | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); | |||
| } | |||
| WxCouponCVo wxCouponCVo = null; | |||
| @@ -245,7 +245,7 @@ public class WxCouponOrderController extends BaseController { | |||
| cardCVo = new WxCardCVo(); | |||
| } | |||
| cardCVo.updateTenantInfo(getTenantInfo()); | |||
| cardCVo.setOwnerId(getUserId()); | |||
| cardCVo.setOwnerId(getMemberId()); | |||
| if(StringUtils.isNotBlank(cardCVo.getStatusStr())) { | |||
| String [] statusAttr = cardCVo.getStatusStr().split(","); | |||
| List<Integer> tmpList = new ArrayList<Integer>(); | |||
| @@ -272,12 +272,11 @@ public class WxCouponOrderController extends BaseController { | |||
| @ApiImplicitParam(name = "couponOrderId", value = "券ID", dataType = "string", paramType = "query", required = true) | |||
| }) | |||
| public ResultData cardDetail(String couponOrderId) { | |||
| if (couponOrderId == null || couponOrderId.equalsIgnoreCase(Constant.UNDEFINED) ) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| return wxCouponOrderService.cardDetailCUserVo(getUserId(), couponOrderId); | |||
| return wxCouponOrderService.cardDetailCUserVo(getMemberId(), couponOrderId); | |||
| } | |||
| @ApiOperation(value = "卡转赠领取") | |||
| @@ -298,7 +297,7 @@ public class WxCouponOrderController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "cUserId不能为空"); | |||
| } | |||
| //当前领取人 | |||
| wxCouponOrder.setOwnerId(getUserId()); | |||
| wxCouponOrder.setOwnerId(getMemberId()); | |||
| //转赠者与当前领取人是否为同一个 | |||
| if (cUserId.equals(wxCouponOrder.getOwnerId())) { | |||
| logger.info("转赠人与卡所有者相同"); | |||
| @@ -316,7 +315,6 @@ public class WxCouponOrderController extends BaseController { | |||
| @ApiImplicitParam(name = "cUserId", value = "转赠者", dataType = "Long", paramType = "query", required = true), | |||
| }) | |||
| public ResultData queryCardStatus(@ModelAttribute WxCouponOrder wxCouponOrder) { | |||
| //coupon_order_id判断 | |||
| Long id = wxCouponOrder.getId(); | |||
| if (id == null) { | |||
| @@ -332,7 +330,7 @@ public class WxCouponOrderController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "updateDate不能为空"); | |||
| } | |||
| //当前领取人 | |||
| wxCouponOrder.setOwnerId(getUserId()); | |||
| wxCouponOrder.setOwnerId(getMemberId()); | |||
| return wxCouponOrderService.queryCardStatus(wxCouponOrder); | |||
| } | |||
| @@ -340,8 +338,8 @@ public class WxCouponOrderController extends BaseController { | |||
| @GetMapping("checkH5CouponOrder") | |||
| public ResultData checkH5CouponOrder() { | |||
| TenantEntity tenantEntity = getTenantInfo(); | |||
| WxCUser user = getUser(); | |||
| memCouponFromDspService.couponOrderFromDsp(tenantEntity, user.getPhone()); | |||
| WxCUserBasicInfo member = getMember(); | |||
| memCouponFromDspService.couponOrderFromDsp(tenantEntity, member.getPhone()); | |||
| return new ResultData(); | |||
| } | |||
| @@ -32,6 +32,9 @@ public class WxCouponPasswordController extends BaseController { | |||
| @Autowired | |||
| private WxOrderService orderService; | |||
| @Autowired | |||
| private WxCUserBasicInfoService userService; | |||
| @ApiOperation(value = "根据卡密领卡", notes = "{\"password\":\"String\",\"formId\":\"String\"}") | |||
| @PostMapping("getCouponOrderByPassword") | |||
| @@ -39,6 +42,11 @@ public class WxCouponPasswordController extends BaseController { | |||
| logger.info("getCouponOrderByPassword: " + getIpAddr() + params.toString()); | |||
| String password = params.get("password"); | |||
| String formId = params.get("formId"); | |||
| return getCouponOrderByPassword(password, formId, getMemberId(),EnumPayWay.PAY_WAY_NOT_UNPAY_PASSWD); | |||
| } | |||
| private ResultData getCouponOrderByPassword(String password,String formId,Long memberId,EnumPayWay payWay) { | |||
| if (StringUtils.isBlank(password) || password.equalsIgnoreCase(Constant.UNDEFINED)) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "password不能为空"); | |||
| } | |||
| @@ -58,7 +66,13 @@ public class WxCouponPasswordController extends BaseController { | |||
| return new ResultData(500, e.getMessage()); | |||
| } | |||
| WxCUser cuUser = getUser(); | |||
| WxCUserBasicInfo member = userService.getById(memberId); | |||
| if(member == null) { | |||
| logger.error("会员用户未找到: " + memberId); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), "会员用户未找到" + memberId); | |||
| } | |||
| WxCoupon coupon = couponService.getById(couponPassword.getCouponId()); | |||
| if (coupon == null) { | |||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | |||
| @@ -75,7 +89,7 @@ public class WxCouponPasswordController extends BaseController { | |||
| // 3. 领取free coupon | |||
| try { | |||
| WxOrder order = orderService.saveFreeOrderForCoupon(cuUser, coupon, null, formId, couponPassword.getId()); | |||
| WxOrder order = orderService.saveFreeOrderForCoupon(member, coupon, null, formId, couponPassword.getId(),payWay); | |||
| } catch (MallinkException e) { | |||
| setCouponPasswordStatus(couponPassword, EnumCouponPasswordStatus.getEnum(pwdStatus)); | |||
| logger.error(e.getMessage()); | |||
| @@ -1,7 +1,9 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.domain.po.WxCreditHistory; | |||
| import com.iformall.service.WxCreditHistoryService; | |||
| @@ -10,6 +12,8 @@ import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| @@ -19,6 +23,8 @@ import org.springframework.web.bind.annotation.*; | |||
| @Slf4j | |||
| public class WxCreditHistoryController extends BaseController{ | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxCreditHistoryService wxCreditHistoryService; | |||
| @@ -29,8 +35,10 @@ public class WxCreditHistoryController extends BaseController{ | |||
| @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | |||
| public ResultData list(@ModelAttribute WxCreditHistory wxCreditHistory, Integer pageNum, Integer pageSize) { | |||
| log.debug("[" + getIpAddr() + "] WxCreditHistoryController::list"); | |||
| if (null == wxCreditHistory) wxCreditHistory = new WxCreditHistory(); | |||
| wxCreditHistory.setCUserId(getUserId()); | |||
| if (null == wxCreditHistory){ | |||
| wxCreditHistory = new WxCreditHistory(); | |||
| } | |||
| wxCreditHistory.setCUserId(getMemberId()); | |||
| wxCreditHistory.setSortColumns(BaseEntity.SortField.CreateDate_DESC,BaseEntity.SortField.Id_DESC); | |||
| final PageInfo<WxCreditHistory> page = wxCreditHistoryService.listAsPage(wxCreditHistory, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| @@ -4,10 +4,7 @@ import com.github.pagehelper.Page; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCouponOrder; | |||
| import com.iformall.domain.po.WxGame; | |||
| import com.iformall.domain.po.WxGameActionLog; | |||
| import com.iformall.domain.po.WxGameTemplate; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.EnumGameStatus; | |||
| import com.iformall.service.WxCouponOrderService; | |||
| import com.iformall.service.WxGameService; | |||
| @@ -72,17 +69,14 @@ public class WxGameController extends BaseController { | |||
| @ApiImplicitParam(name = "gameId", value = "游戏ID", dataType = "String", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "orderId", value = "券订单ID", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData addActionLog(@RequestBody Map<String,String> paramMap) { | |||
| Long gameIdL = null; | |||
| Long orderIdL = null; | |||
| try { | |||
| gameIdL = Long.valueOf(paramMap.get("gameId")); | |||
| orderIdL = Long.valueOf(paramMap.get("orderId")); | |||
| Long gameIdL = Long.valueOf(paramMap.get("gameId")); | |||
| Long orderIdL = Long.valueOf(paramMap.get("orderId")); | |||
| return wxGameService.addActionLog(getMemberId(), gameIdL, orderIdL); | |||
| } catch (Exception e){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| return wxGameService.addActionLog(getUserId(), gameIdL, orderIdL); | |||
| } | |||
| @ApiOperation("添加游戏参与记录") | |||
| @@ -90,13 +84,12 @@ public class WxGameController extends BaseController { | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "gameId", value = "游戏ID", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData getCount(String gameId) { | |||
| Long gameIdL = null; | |||
| try { | |||
| gameIdL = Long.valueOf(gameId); | |||
| Long gameIdL = Long.valueOf(gameId); | |||
| return wxGameService.getCount(gameIdL,getMemberId()); | |||
| } catch (Exception e){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| return wxGameService.getCount(gameIdL,getUserId()); | |||
| } | |||
| } | |||
| @@ -65,7 +65,11 @@ public class WxOrderController extends BaseController { | |||
| @ApiOperation(value = "下订单", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"press\":\"String\",\"orderGroupId\":\"String\",\"formId\":\"String\"}") | |||
| @PostMapping("save") | |||
| public ResultData saveOrder(@RequestBody OrderSaveDto orderSaveDto) { | |||
| logger.info("OrderSave: " + orderSaveDto); | |||
| return saveOrder(orderSaveDto,getMemberId(),EnumPayWay.PAY_WAY_WECHAT); | |||
| } | |||
| private ResultData saveOrder(OrderSaveDto orderSaveDto,Long cUserId,EnumPayWay payWay) { | |||
| logger.info("OrderSave: " + orderSaveDto); | |||
| if (orderSaveDto.getCouponChannelId() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId不能为空"); | |||
| } | |||
| @@ -77,10 +81,9 @@ public class WxOrderController extends BaseController { | |||
| ResultData resultData = couponChannelCheck(orderSaveDto, wxCouponChannel); | |||
| if (resultData != null) return resultData; | |||
| WxCUser user = getUser(); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(user.getId()); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(cUserId); | |||
| if (wxCUserBasicInfo != null && wxCUserBasicInfo.getStatus().equals(EnumCUserBasicInfoStatus.LOCKED.getCode())) { | |||
| logger.info("会员权益被锁定:cUserId:" + user.getId()); | |||
| logger.info("会员权益被锁定:cUserId:" + cUserId); | |||
| return new ResultData(ErrorCode.MEMBER_IS_LOCKED); | |||
| } | |||
| @@ -93,7 +96,7 @@ public class WxOrderController extends BaseController { | |||
| } | |||
| //判断是否是拼团订单,如果是拼团订单,判断现在进行中的,和已完成的数量是否超出券的限制 | |||
| if (coupon.getType().equals(EnumCouponType.COUPON_GROUP.getCode())) { | |||
| int ordercount = wxOrderService.countUserCouponGroupOrder(user.getId(),coupon.getId()); | |||
| int ordercount = wxOrderService.countUserCouponGroupOrder(cUserId,coupon.getId()); | |||
| if (ordercount>=coupon.getUseLimitQuantity()) { | |||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF.getCode(),"您当前此券的有效拼团数量达到券的限购次数。"); | |||
| } | |||
| @@ -141,7 +144,7 @@ public class WxOrderController extends BaseController { | |||
| } | |||
| } | |||
| resultData = couponUserCheck(user, wxCouponCVo); | |||
| resultData = couponUserCheck(wxCUserBasicInfo, wxCouponCVo); | |||
| if (resultData != null) return resultData; | |||
| Long couponId = orderSaveDto.getCouponId() == null ? wxCouponChannel.getCouponId() : orderSaveDto.getCouponId(); | |||
| @@ -153,7 +156,7 @@ public class WxOrderController extends BaseController { | |||
| boolean isPress = orderSaveDto.getPress() != null ? orderSaveDto.getPress() : false; | |||
| try { | |||
| WxOrder order = wxOrderService.saveOrderForCoupon(user, coupon, orderSaveDto, isPress); | |||
| WxOrder order = wxOrderService.saveOrderForCoupon(wxCUserBasicInfo, coupon, orderSaveDto, isPress,payWay); | |||
| return new ResultData(order); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| @@ -163,8 +166,8 @@ public class WxOrderController extends BaseController { | |||
| return new ResultData(ErrorCode.ORDER_IS_FAIL, e.getMessage()); | |||
| } | |||
| } | |||
| private ResultData couponUserCheck(WxCUser user, WxCouponCVo coupon) { | |||
| private ResultData couponUserCheck(WxCUserBasicInfo user, WxCouponCVo coupon) { | |||
| if (coupon.getConditions() == null) return null; | |||
| JSONObject jo = null; | |||
| try { | |||
| @@ -174,8 +177,8 @@ public class WxOrderController extends BaseController { | |||
| } | |||
| if (jo != null) { | |||
| if (jo.getIntValue("type") == EnumCouponConditionType.NEW_MEMBER.getCode()){ | |||
| WxCUserBasicInfo cUserBasicInfo = wxCUserBasicInfoService.getById(user.getId()); | |||
| if (cUserBasicInfo != null && cUserBasicInfo.getActRecord() > 0) | |||
| if (user != null && user.getActRecord() > 0) | |||
| return new ResultData(ErrorCode.COUPON_ONLY_FOR_NEW_MEMBER); | |||
| if (wxOrderService.countCouponConditionType1(user) > 0) | |||
| return new ResultData(ErrorCode.COUPON_ALREADY_IN_NEW_MEMBER); | |||
| @@ -183,13 +186,13 @@ public class WxOrderController extends BaseController { | |||
| int max = jo.getIntValue("max"); | |||
| int min = jo.getIntValue("min"); | |||
| if (max!=0 && min ==0 && user.getScore() > max) { | |||
| if (max!=0 && min ==0 && user.getPoins() > max) { | |||
| return new ResultData(ErrorCode.COUPON_SCORE_NOT_IN_RANGE); | |||
| } | |||
| if (max==0 && min !=0 && user.getScore() < min) { | |||
| if (max==0 && min !=0 && user.getPoins() < min) { | |||
| return new ResultData(ErrorCode.COUPON_SCORE_NOT_IN_RANGE); | |||
| } | |||
| if (max!=0 && min !=0 && (user.getScore() < min || user.getScore() > max)) { | |||
| if (max!=0 && min !=0 && (user.getPoins() < min || user.getPoins() > max)) { | |||
| return new ResultData(ErrorCode.COUPON_SCORE_NOT_IN_RANGE); | |||
| } | |||
| } | |||
| @@ -283,8 +286,10 @@ public class WxOrderController extends BaseController { | |||
| }) | |||
| public ResultData list(@ModelAttribute WxOrder wxOrder, Integer pageNum, Integer pageSize) { | |||
| // c端用户应该只能看到自己的订单 | |||
| if (wxOrder == null) wxOrder = new WxOrder(); | |||
| wxOrder.setCUserId(getUserId()); | |||
| if (wxOrder == null){ | |||
| wxOrder = new WxOrder(); | |||
| } | |||
| wxOrder.setCUserId(getMemberId()); | |||
| wxOrder.setSortColumns(BaseEntity.SortField.UpdateDate_DESC); | |||
| final PageInfo<WxOrderCouponVo> page = wxOrderService.listCUserVoAsPage(wxOrder, pageNum, pageSize); | |||
| @@ -324,7 +329,7 @@ public class WxOrderController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "订单ID转换异常"); | |||
| } | |||
| wxOrder.setId(id); | |||
| wxOrder.setCUserId(getUserId()); | |||
| wxOrder.setCUserId(getMemberId()); | |||
| WxOrderCouponVo wxOrderCVo = wxOrderService.detailCUserVo(wxOrder); | |||
| if (wxOrderCVo == null) | |||
| return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); | |||
| @@ -404,7 +409,12 @@ public class WxOrderController extends BaseController { | |||
| WxOrder order = null; | |||
| try { | |||
| order = wxOrderService.getUnPaidOrder(getUser(), wxCoupon); | |||
| WxCUserBasicInfo member = wxCUserBasicInfoService.getById(getMemberId()); | |||
| if(member == null) { | |||
| logger.error("会员用户未找到: " + getMemberId()); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), "会员用户未找到" + getMemberId()); | |||
| } | |||
| order = wxOrderService.getUnPaidOrder(member, wxCoupon); | |||
| if (order != null) { | |||
| return new ResultData(Result.SUCCESS, "查询成功", order); | |||
| } else { | |||
| @@ -424,7 +434,7 @@ public class WxOrderController extends BaseController { | |||
| public ResultData pressOrderList(@ModelAttribute WxOrder wxOrder, Integer pageNum, Integer pageSize) { | |||
| // c端用户应该只能看到自己的订单 | |||
| if (wxOrder == null) wxOrder = new WxOrder(); | |||
| wxOrder.setCUserId(getUserId()); | |||
| wxOrder.setCUserId(getMemberId()); | |||
| wxOrder.setSortColumns(BaseEntity.SortField.CreateDate_DESC); | |||
| final PageInfo<WxOrderCouponPressVo> page = wxOrderService.listPressVoAsPage(wxOrder, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| @@ -3,6 +3,7 @@ package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxOrderGroup; | |||
| import com.iformall.domain.vo.WxOrderGroupMarketing; | |||
| @@ -49,7 +50,7 @@ public class WxOrderGroupController extends BaseController { | |||
| wxOrderGroup.setRemainPeople(1); | |||
| wxOrderGroup.setStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING.getCode()); | |||
| wxOrderGroup.updateTenantInfo(getTenantInfo()); | |||
| return wxOrderGroupService.queryRemainOne(wxOrderGroup, getUserId()); | |||
| return wxOrderGroupService.queryRemainOne(wxOrderGroup, getMemberId()); | |||
| } | |||
| @@ -61,7 +62,7 @@ public class WxOrderGroupController extends BaseController { | |||
| }) | |||
| public ResultData queryOrderGroup(Integer pageNum, Integer pageSize) { | |||
| WxOrder wxOrder = new WxOrder(); | |||
| wxOrder.setCUserId(getUserId()); | |||
| wxOrder.setCUserId(getMemberId()); | |||
| wxOrder.updateTenantInfo(getTenantInfo()); | |||
| final PageInfo<Map<String, Object>> page = wxOrderGroupService.queryOrderGroup(wxOrder, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| @@ -118,7 +119,7 @@ public class WxOrderGroupController extends BaseController { | |||
| if (wxOrderGroup.getId() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "id不能为空"); | |||
| } | |||
| wxOrderGroup.setUserId(getUserId()); | |||
| wxOrderGroup.setUserId(getMemberId()); | |||
| wxOrderGroup.updateTenantInfo(getTenantInfo()); | |||
| return wxOrderGroupService.queryAttendStatus(wxOrderGroup); | |||
| } | |||
| @@ -38,6 +38,7 @@ import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.service.WxPayAccountService; | |||
| import com.iformall.service.WxPayOrderService; | |||
| import com.iformall.service.pay.entity.PayExtraParam; | |||
| import com.iformall.utils.IPUtil; | |||
| import io.swagger.annotations.Api; | |||
| @@ -66,7 +67,13 @@ public class WxPayOrderController extends BaseController { | |||
| @Autowired | |||
| private WxCouponService wxCouponService; | |||
| /** | |||
| * 微信支付 | |||
| * @param paramMap | |||
| * @param request | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| //@ApiOperation(value = "发起微信小程序支付订单", notes = "{\"orderId\":\"string\"}") | |||
| @RequestMapping(value = "/create", method = RequestMethod.POST) | |||
| public ResultData _create(@RequestBody Map<String, String> paramMap, HttpServletRequest request) throws Exception { | |||
| @@ -78,15 +85,27 @@ public class WxPayOrderController extends BaseController { | |||
| } | |||
| WxCUser user = getUser(); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(user.getId()); | |||
| if (!user.isBasicInfo()) { | |||
| logger.error("暂未成为会员,请授权手机号"); | |||
| return new ResultData(ErrorCode.USER_IS_NOT_MEMBER.getCode(), "暂未成为会员,请授权手机号"); | |||
| } | |||
| return _create(orderIdStr,user.getUserId(),EnumPayWay.PAY_WAY_WECHAT,user.getAppId(),new PayExtraParam("openId",user.getOpenId()),request); | |||
| } | |||
| private ResultData _create(String orderIdStr,Long userId, EnumPayWay payWay,String appId,PayExtraParam parm,HttpServletRequest request) { | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(userId); | |||
| if ( null == wxCUserBasicInfo) { | |||
| logger.error("会员用户不存在."+userId); | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY.getCode(),"会员用户不存在."+userId); | |||
| } | |||
| if (null != wxCUserBasicInfo && EnumCreditLockedStatus.CLOSE.getCode().equals(wxCUserBasicInfo.getStatus())) { | |||
| return new ResultData(ErrorCode.MEMBER_IS_LOCKED); | |||
| } | |||
| WxAppinfo appInfo = getAppInfo(user.getAppId()); | |||
| WxAppinfo appInfo = getAppInfo(appId); | |||
| if(appInfo == null) { | |||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| Long orderId = 0L; | |||
| try { | |||
| orderId = Long.valueOf(orderIdStr); | |||
| @@ -97,7 +116,7 @@ public class WxPayOrderController extends BaseController { | |||
| record.setOrderId(orderId); | |||
| try { | |||
| record.setIp(IPUtil.getIpAddr(request)); | |||
| return wxPayOrderService.createPayOrder(appInfo, user, record, EnumPayWay.PAY_WAY_WECHAT); | |||
| return wxPayOrderService.createPayOrder(appInfo, wxCUserBasicInfo, record, payWay,parm); | |||
| } catch (MallinkException e) { | |||
| logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| @@ -2,6 +2,7 @@ package com.iformall.controller; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxOrderPress; | |||
| import com.iformall.domain.vo.WxCouponCVo; | |||
| @@ -153,10 +154,8 @@ public class WxPressOrderController extends BaseController { | |||
| logger.error("此砍价订单被锁定, orderId: " + orderIdStr); | |||
| return new ResultData(ErrorCode.TOO_MANY_REQUEST); | |||
| } | |||
| Long cUserId = getUserId(); | |||
| // 检查此人是否已参与砍价 | |||
| boolean hadJoin = wxOrderPressService.checkCUserHasJoin(order, cUserId); | |||
| boolean hadJoin = wxOrderPressService.checkCUserHasJoin(order, getMemberId()); | |||
| if (hadJoin) { | |||
| redisLock.unlock(orderIdStr, timeStr); | |||
| logger.error("用户已参与砍价"); | |||
| @@ -164,7 +163,7 @@ public class WxPressOrderController extends BaseController { | |||
| } | |||
| try { | |||
| WxOrderPress orderPress = wxOrderPressService.pressCouponJoin(order, wxCouponCVo, cUserId); | |||
| WxOrderPress orderPress = wxOrderPressService.pressCouponJoin(order, wxCouponCVo, getMemberId()); | |||
| if (orderPress != null) { | |||
| // 更新砍价信息 | |||
| Integer index = order.getPressCurrentNum() + 1; | |||
| @@ -242,11 +241,11 @@ public class WxPressOrderController extends BaseController { | |||
| logger.error("订单不存在:" + orderId); | |||
| return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); | |||
| } | |||
| if(order.getCUserId().equals(getUserId())) { | |||
| if(order.getCUserId().equals(getMemberId())) { | |||
| ret.put("status", EnumOrderPressStatus.FIRST.getCode()); | |||
| return new ResultData(ret); | |||
| } | |||
| int status = wxOrderPressService.pressCouponStatus(order, getUserId()); | |||
| int status = wxOrderPressService.pressCouponStatus(order, getMemberId()); | |||
| ret.put("status", status); | |||
| return new ResultData(ret); | |||
| } | |||
| @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxQuestion; | |||
| import com.iformall.domain.po.WxQuestionConfig; | |||
| import com.iformall.domain.po.WxQuestionLog; | |||
| @@ -67,7 +68,7 @@ public class WxQuestionController extends BaseController { | |||
| while(q.hasNext()){ | |||
| WxQuestion x = q.next(); | |||
| wxQuestionLog.setQuestionId(x.getId()); | |||
| wxQuestionLog.setUserId(getUserId()); | |||
| wxQuestionLog.setUserId(getMemberId()); | |||
| wxQuestionLog.updateTenantInfo(wxQuestionConfig); | |||
| if(wxQuestionService.findLogList(wxQuestionLog).size()>0){ | |||
| @@ -104,10 +105,10 @@ public class WxQuestionController extends BaseController { | |||
| } | |||
| wxQuestionLog.setAnswer(JSONObject.toJSONString(as)); | |||
| wxCUserTagsService.assignTags(as, wxCUserBasicInfoService.getById(getUserId())); | |||
| wxCUserTagsService.assignTags(as, wxCUserBasicInfoService.getById(getMemberId())); | |||
| } | |||
| wxQuestionLog.setUserId(getUserId()); | |||
| wxQuestionLog.setUserId(getMemberId()); | |||
| wxQuestionService.saveOrUpdateLog(wxQuestionLog); | |||
| return new ResultData(); | |||
| @@ -1,7 +1,9 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.domain.po.WxScoreHistory; | |||
| import com.iformall.service.WxScoreHistoryService; | |||
| @@ -29,7 +31,7 @@ public class WxScoreHistoryController extends BaseController { | |||
| public ResultData list(Integer pageNum, Integer pageSize) { | |||
| WxScoreHistory wxScoreHistory = new WxScoreHistory(); | |||
| wxScoreHistory.updateTenantInfo(getTenantInfo()); | |||
| wxScoreHistory.setCUserId(getUserId()); | |||
| wxScoreHistory.setCUserId(getMemberId()); | |||
| wxScoreHistory.setSortColumns(BaseEntity.SortField.CreateDate_DESC); | |||
| final PageInfo<WxScoreHistory> page = wxScoreHistoryService.listAsPage(wxScoreHistory, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| @@ -267,11 +267,13 @@ public class WxUserGrantController extends BaseController { | |||
| resultMap.put("token", token); | |||
| request.setAttribute(Constant.LOGIN_USER_KEY, oldUser.getId()); | |||
| request.setAttribute(Constant.TENANT_ID, wxAuthorizerInfo.getTenantId()); | |||
| request.setAttribute(Constant.TENANT_ID, oldUser.getTenantId()); | |||
| if(StringUtils.isBlank(oldUser.getParentTenantId()) && StringUtils.isNotBlank(wxMall.getParentTenantId())){ | |||
| oldUser.setParentTenantId(wxMall.getParentTenantId()); | |||
| request.setAttribute(Constant.PARENT_TENANT_ID, wxMall.getParentTenantId()); | |||
| } | |||
| if(StringUtils.isNotBlank(oldUser.getParentTenantId())){ | |||
| request.setAttribute(Constant.PARENT_TENANT_ID, oldUser.getParentTenantId()); | |||
| } | |||
| // 老用户,给出来已选中的mall | |||
| @@ -291,9 +293,9 @@ public class WxUserGrantController extends BaseController { | |||
| } | |||
| } | |||
| if (selectedMall != null) { | |||
| request.setAttribute(Constant.PARENT_TENANT_ID, selectedMall.getParentTenantId()); | |||
| request.setAttribute(Constant.TENANT_ID, selectedMall.getTenantId()); | |||
| resultMap.put("selectedMall", selectedMall.getTenantId()); | |||
| oldUser.setParentTenantId(selectedMall.getParentTenantId()); | |||
| // oldUser.setParentTenantId(selectedMall.getParentTenantId()); | |||
| } | |||
| } | |||
| @@ -364,18 +366,21 @@ public class WxUserGrantController extends BaseController { | |||
| extraInfo.put("systemInfo", JSONObject.parseObject(systemInfo)); | |||
| newUser.setExtraInfo(extraInfo.toJSONString()); | |||
| } | |||
| newUser.setLoginCount(0); | |||
| newUser.setLoginCount(1); | |||
| userTokenService.saveOrUpdate(newUser); | |||
| resultMap.put("token", token); | |||
| request.setAttribute(Constant.LOGIN_USER_KEY, newUser.getId()); | |||
| request.setAttribute(Constant.TENANT_ID, newUser.getTenantId()); | |||
| if(StringUtils.isNotBlank(newUser.getParentTenantId())){ | |||
| request.setAttribute(Constant.PARENT_TENANT_ID, newUser.getParentTenantId()); | |||
| } | |||
| if (mallList != null) { | |||
| WxMall firstMall = mallList.get(0); | |||
| if (firstMall != null) { | |||
| // 默认选中第一个mall, 或者经纬度最近的那个 | |||
| request.setAttribute(Constant.PARENT_TENANT_ID, firstMall.getTenantId()); | |||
| request.setAttribute(Constant.TENANT_ID, firstMall.getTenantId()); | |||
| resultMap.put("selectedMall", firstMall.getTenantId()); | |||
| newUser.setParentTenantId(firstMall.getTenantId()); | |||
| } | |||
| @@ -405,11 +410,11 @@ public class WxUserGrantController extends BaseController { | |||
| } | |||
| WxCUser user = getUser(); | |||
| if (user.getTenantId().equalsIgnoreCase(tenantId)) { | |||
| if (user.getParentTenantId().equalsIgnoreCase(parentTenantId)) { | |||
| HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | |||
| request.setAttribute(Constant.TENANT_ID, tenantId); | |||
| request.setAttribute(Constant.PARENT_TENANT_ID, parentTenantId); | |||
| user.setParentTenantId(parentTenantId); | |||
| user.setTenantId(tenantId); | |||
| userTokenService.saveOrUpdate(user); | |||
| } | |||
| @@ -623,22 +628,28 @@ public class WxUserGrantController extends BaseController { | |||
| user.setCountryCode(phoneNoInfo.getCountryCode()); | |||
| if (isFirstPhone) { | |||
| //检查是否存在会员信息 如果有 赋值积分 | |||
| WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(tenantEntity, user.getPhone()); | |||
| if (basicInfo != null ) { | |||
| int credit = user.getCredit() == null ? 0 : user.getCredit(); | |||
| int score = user.getScore() == null ? 0 : user.getScore(); | |||
| int memScore = basicInfo.getPoins() == null ? 0 : basicInfo.getPoins(); | |||
| int memCredit = basicInfo.getCredit() == null ? 0 : basicInfo.getCredit(); | |||
| user.setCredit(memCredit + credit); | |||
| user.setScore(memScore + score); | |||
| } | |||
| // WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(tenantEntity, user.getPhone()); | |||
| // if (basicInfo != null ) { | |||
| // int credit = user.getCredit() == null ? 0 : user.getCredit(); | |||
| // int score = user.getScore() == null ? 0 : user.getScore(); | |||
| // int memScore = basicInfo.getPoins() == null ? 0 : basicInfo.getPoins(); | |||
| // int memCredit = basicInfo.getCredit() == null ? 0 : basicInfo.getCredit(); | |||
| // user.setCredit(memCredit + credit); | |||
| // user.setScore(memScore + score); | |||
| // } | |||
| } | |||
| wxCUserService.saveOrUpdate(user); | |||
| if (!user.getPhone().contains("*")) { // 用户手机非加密 | |||
| // 更新到basicinfo | |||
| saveToBasicInfo(user); | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_PHONE, user); | |||
| } | |||
| if(isFirstPhone) { | |||
| // 首次授权, 增加成长值及积分 | |||
| // 成长值 | |||
| user.setScore(user.getScore() + wxScoreRulesService.addScore(EnumScoreType.WECHAT_PHONE, user)); | |||
| wxScoreRulesService.addScore(EnumScoreType.WECHAT_PHONE, user); | |||
| // 增加积分 | |||
| wxCUserService.addCredit(user, EnumScoreType.WECHAT_PHONE); | |||
| // 外部注券 | |||
| @@ -655,12 +666,6 @@ public class WxUserGrantController extends BaseController { | |||
| return new ResultData(ErrorCode.DB_FAIL.getCode(), "解密并保存出错", resultMap); | |||
| } | |||
| if (!user.getPhone().contains("*")) { // 用户手机非加密 | |||
| // 更新到basicinfo | |||
| saveToBasicInfo(user); | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_PHONE, user); | |||
| } | |||
| return new ResultData(resultMap); | |||
| } | |||
| @@ -746,12 +751,27 @@ public class WxUserGrantController extends BaseController { | |||
| WxCUser user = getUser(); | |||
| WxCUserVo userVo = new WxCUserVo(); | |||
| org.springframework.beans.BeanUtils.copyProperties(user, userVo); | |||
| userVo.setScore(0); | |||
| userVo.setCredit(0); | |||
| if(user.isBasicInfo()){ | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(user.getUserId()); | |||
| if (wxCUserBasicInfo != null) { | |||
| userVo.setScore(wxCUserBasicInfo.getPoins()); | |||
| userVo.setCredit(wxCUserBasicInfo.getCredit()); | |||
| userVo.setName(wxCUserBasicInfo.getName()); | |||
| userVo.setBirthdate(wxCUserBasicInfo.getBirthdate()); | |||
| userVo.setSex(wxCUserBasicInfo.getSex()); | |||
| userVo.setAddress(wxCUserBasicInfo.getAddress()); | |||
| userVo.setStatus(wxCUserBasicInfo.getStatus()); | |||
| } | |||
| } | |||
| if (userVo.getScore() == null) | |||
| userVo.setScore(0); | |||
| Integer levelScore = 0; | |||
| Integer levelTarget= 0; | |||
| userVo.setLevelName(WxLevelConfigService.DEFAULT_LEVEL); | |||
| List<WxLevelConfig> levelList = wxLevelConfigService.getByTenantId(user.getTenantId()); | |||
| List<WxLevelConfig> levelList = wxLevelConfigService.getByTenantId(getTenantInfo().getTenantId()); | |||
| if (levelList.size() > 0) | |||
| levelTarget = levelList.get(0).getPoints(); | |||
| for (int i = 0; i<levelList.size(); i++) { | |||
| @@ -776,31 +796,19 @@ public class WxUserGrantController extends BaseController { | |||
| userVo.setUpgradeScore(levelTarget-userVo.getScore()); | |||
| } | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(user.getId()); | |||
| if (wxCUserBasicInfo != null) { | |||
| userVo.setName(wxCUserBasicInfo.getName()); | |||
| userVo.setBirthdate(wxCUserBasicInfo.getBirthdate()); | |||
| userVo.setSex(wxCUserBasicInfo.getSex()); | |||
| userVo.setAddress(wxCUserBasicInfo.getAddress()); | |||
| userVo.setStatus(wxCUserBasicInfo.getStatus()); | |||
| } | |||
| return new ResultData(userVo); | |||
| } | |||
| @ApiOperation("当前用户名下是否有车") | |||
| @GetMapping("/carCount") | |||
| public ResultData carCount() { | |||
| WxCUser user = getUser(); | |||
| WxCUserBasicInfo member = getMember(); | |||
| WxCUserCar userCar = new WxCUserCar(); | |||
| userCar.updateTenantInfo(user); | |||
| userCar.setCUserId(user.getId()); | |||
| userCar.setCUserId(member.getId()); | |||
| Integer count = wxCUserCarService.countUserCar(userCar); | |||
| if (count > 0) { | |||
| Map returnMap = new HashMap(); | |||
| String phone = user.getPhone(); | |||
| if (phone.contains("*")) | |||
| phone = user.getVerifyCodePhone(); | |||
| String phone = member.getPhone(); | |||
| returnMap.put("phone", phone); | |||
| returnMap.put("count", count); | |||
| return new ResultData(Result.SUCCESS, "count获取成功", returnMap); | |||
| @@ -815,8 +823,7 @@ public class WxUserGrantController extends BaseController { | |||
| @GetMapping("/carList") | |||
| public ResultData getCarList() { | |||
| WxCUserCar userCar = new WxCUserCar(); | |||
| userCar.updateTenantInfo(getTenantInfo()); | |||
| userCar.setCUserId(getUserId()); | |||
| userCar.setCUserId(getMemberId()); | |||
| List<WxCUserCar> list = wxCUserCarService.getList(userCar); | |||
| return new ResultData(Result.SUCCESS, "获取查询成功", list); | |||
| } | |||
| @@ -870,8 +877,6 @@ public class WxUserGrantController extends BaseController { | |||
| public ResultData updateUserInfo(@RequestBody WxCUserBasicInfo wxCUserBasicInfo) { | |||
| if (wxCUserBasicInfo == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| if (wxCUserBasicInfoService.getById(getUserId()) == null) | |||
| return new ResultData(ErrorCode.USER_IS_NOT_MEMBER); | |||
| TenantEntity tenantEntity = getTenantInfo(); | |||
| @@ -880,12 +885,13 @@ public class WxUserGrantController extends BaseController { | |||
| wxCUserBasicInfo.getSex() != null || | |||
| wxCUserBasicInfo.getAddress() != null) { | |||
| WxCUserBasicInfo record = new WxCUserBasicInfo(); | |||
| record.setId(getMemberId()); | |||
| record.updateTenantInfo(tenantEntity); | |||
| record.setName(wxCUserBasicInfo.getName()); | |||
| record.setAvatarUrl(wxCUserBasicInfo.getAvatarUrl()); | |||
| record.setBirthdate(wxCUserBasicInfo.getBirthdate()); | |||
| record.setSex(wxCUserBasicInfo.getSex()); | |||
| record.setAddress(wxCUserBasicInfo.getAddress()); | |||
| record.setId(getUserId()); | |||
| record.setUpdateDate(new Date()); | |||
| wxCUserBasicInfoService.update(record); | |||
| wxScoreRulesService.addScore(EnumScoreType.COMPLETE_INFO, record); | |||
| @@ -896,7 +902,7 @@ public class WxUserGrantController extends BaseController { | |||
| wxCreditHistory.setCreateDate(new Date()); | |||
| wxCreditHistory.setCreditType(EnumScoreType.COMPLETE_INFO.getCode()); | |||
| wxCreditHistory.setOperatorType(EnumUserType.CUSER.getCode()); | |||
| wxCreditHistory.setOperatorId(getUserId()); | |||
| wxCreditHistory.setOperatorId(getMemberId()); | |||
| wxCreditHistoryService.saveOrUpdate(wxCreditHistory); | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_IMPORT, record); | |||
| } | |||
| @@ -911,14 +917,13 @@ public class WxUserGrantController extends BaseController { | |||
| @RequestMapping("/getDiscountInfo") | |||
| @ApiOperation(value = "获取用户折扣率", notes = "") | |||
| public ResultData getDiscountInfo() { | |||
| WxCUser user = getUser(); | |||
| List<WxLevelConfig> levelList = wxLevelConfigService.getByTenantId(user.getTenantId()); | |||
| WxCUserBasicInfo member = getMember(); | |||
| List<WxLevelConfig> levelList = wxLevelConfigService.getByTenantId(getTenantInfo().getTenantId()); | |||
| String level = WxLevelConfigService.DEFAULT_LEVEL; | |||
| Long levelId = 0L; | |||
| for (WxLevelConfig levelConfig : levelList) { | |||
| if (user.getScore() >= levelConfig.getPoints()) { | |||
| if (member.getPoins() >= levelConfig.getPoints()) { | |||
| if (levelConfig.getDiscountEnable().equals(EnumLevelConfigDiscountStatus.ENABLE.getCode())) | |||
| levelId = levelConfig.getId(); | |||
| level = levelConfig.getLevel(); | |||
| @@ -930,7 +935,7 @@ public class WxUserGrantController extends BaseController { | |||
| List<WxLevelMerchantCVo> levelMerchantList = wxLevelConfigService.findListCVo(levelMerchant); | |||
| Map<String, Object> result = new HashMap(); | |||
| result.put("id", user.getId()); | |||
| result.put("id", member.getId()); | |||
| result.put("level", level); | |||
| result.put("levelMerchantList", levelMerchantList); | |||
| return new ResultData(result); | |||
| @@ -70,6 +70,9 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | |||
| if (StringUtils.isNotBlank(wxCUser.getParentTenantId())) { | |||
| request.setAttribute(Constant.PARENT_TENANT_ID, wxCUser.getParentTenantId()); | |||
| } | |||
| if(wxCUser.isBasicInfo()){ | |||
| request.setAttribute(Constant.LOGIN_MEMBER_KEY, wxCUser.getUserId()); | |||
| } | |||
| //如果是要不需要自动设置tenantI信息 | |||
| @@ -9,6 +9,7 @@ import com.iformall.domain.vo.WxCarCYFVo; | |||
| import com.iformall.enums.EnumCarCmd; | |||
| import com.iformall.enums.EnumCarVendor; | |||
| import com.iformall.enums.EnumCouponSendSendType; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.car.CYFUtil; | |||
| import com.iformall.utils.car.TJDUtil; | |||
| @@ -55,6 +56,9 @@ public class WxCarCYFCallBackController extends BaseController { | |||
| @Autowired | |||
| WxCarPayRecordService wxCarPayRecordService; | |||
| @Autowired | |||
| WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| /** | |||
| * @description 车易付 车辆入场通知 | |||
| * @Params [paramMap] | |||
| @@ -113,8 +117,8 @@ public class WxCarCYFCallBackController extends BaseController { | |||
| boolean bFirst = true; | |||
| for (WxCUserCar userCar : userCarList) { | |||
| userCar.setParentTenantId(park.getParentTenantId()); | |||
| wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.CAR_STOP, userCar); | |||
| WxCUser cUser = wxCUserService.getById(userCar.getCUserId()); | |||
| wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.CAR_STOP, userCar,EnumPayWay.PAY_WAY_NOT_UNPAY_CAR_STOP); | |||
| WxCUserBasicInfo cUser = wxCUserBasicInfoService.getById(userCar.getCUserId()); | |||
| if(cUser != null){ | |||
| if(bFirst) { | |||
| phoneStrs = cUser.getPhone(); | |||
| @@ -10,6 +10,7 @@ import com.iformall.enums.EnumCarCmd; | |||
| import com.iformall.enums.EnumCarVendor; | |||
| import com.iformall.enums.EnumCouponSendSendType; | |||
| import com.iformall.enums.EnumETCPCode; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.car.ETCPUtil; | |||
| @@ -56,6 +57,9 @@ public class WxCarETCPCallBackController extends BaseController { | |||
| @Autowired | |||
| WxCUserService wxCUserService; | |||
| @Autowired | |||
| WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
| /** | |||
| @@ -358,8 +362,8 @@ public class WxCarETCPCallBackController extends BaseController { | |||
| boolean bFirst = true; | |||
| for (WxCUserCar userCar : userCarList) { | |||
| userCar.setParentTenantId(park.getParentTenantId()); | |||
| wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.CAR_STOP, userCar); | |||
| WxCUser cUser = wxCUserService.getById(userCar.getCUserId()); | |||
| wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.CAR_STOP, userCar,EnumPayWay.PAY_WAY_NOT_UNPAY_CAR_STOP); | |||
| WxCUserBasicInfo cUser = wxCUserBasicInfoService.getById(userCar.getCUserId()); | |||
| if(cUser != null){ | |||
| if(bFirst) { | |||
| phoneStrs = cUser.getPhone(); | |||
| @@ -7,6 +7,7 @@ import com.iformall.domain.po.*; | |||
| import com.iformall.enums.EnumCarCmd; | |||
| import com.iformall.enums.EnumCarVendor; | |||
| import com.iformall.enums.EnumCouponSendSendType; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.car.TJDUtil; | |||
| @@ -51,6 +52,9 @@ public class WxCarTJDCallBackController extends BaseController { | |||
| @Autowired | |||
| WxCUserService wxCUserService; | |||
| @Autowired | |||
| WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| /** | |||
| * 注册车牌 | |||
| * @param paramMap | |||
| @@ -165,8 +169,8 @@ public class WxCarTJDCallBackController extends BaseController { | |||
| boolean bFirst = true; | |||
| for (WxCUserCar userCar : userCarList) { | |||
| userCar.setParentTenantId(park.getParentTenantId()); | |||
| wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.CAR_STOP, userCar); | |||
| WxCUser cUser = wxCUserService.getById(userCar.getCUserId()); | |||
| wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.CAR_STOP, userCar,EnumPayWay.PAY_WAY_NOT_UNPAY_CAR_STOP); | |||
| WxCUserBasicInfo cUser = wxCUserBasicInfoService.getById(userCar.getCUserId()); | |||
| if(cUser != null){ | |||
| if(bFirst) { | |||
| phoneStrs = cUser.getPhone(); | |||
| @@ -68,7 +68,7 @@ public class WxPayBillController extends BaseController { | |||
| try { | |||
| paramMap = WxPayment.xmlToMap(resultxml); | |||
| logger.info("微信支付回调, notify, param: " + paramMap.toString() ); | |||
| String response = wxPayBillService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | |||
| String response = wxPayBillService.notify(paramMap, EnumPayWay.PAY_WAY_WECHAT); | |||
| logger.info("微信支付回调, notify success, req : " + resultxml + ", resp: " + response.toString()); | |||
| return response; | |||
| } catch (BizMessageException e) { | |||
| @@ -120,7 +120,7 @@ public class WxPayBillController extends BaseController { | |||
| xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8")); | |||
| logger.info(xml); | |||
| paramMap = WxPayment.xmlToMap(xml); | |||
| response = wxRefundOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | |||
| response = wxRefundOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WECHAT); | |||
| logger.info("refund wxpay, notify success, req : " + xml + ", resp: " + response.toString()); | |||
| return response; | |||
| } catch (BizMessageException e) { | |||
| @@ -159,7 +159,7 @@ public class WxPayBillController extends BaseController { | |||
| xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8")); | |||
| paramMap = WxPayment.xmlToMap(xml); | |||
| logger.info("share wxpay, notify, param: " + xml ); | |||
| response = wxPayBillService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | |||
| response = wxPayBillService.notify(paramMap, EnumPayWay.PAY_WAY_WECHAT); | |||
| logger.info("share wxpay, notify success, req : " + xml + ", resp: " + response.toString()); | |||
| return response; | |||
| } catch (BizMessageException e) { | |||
| @@ -136,7 +136,7 @@ public class WxPayController extends BaseController { | |||
| FmInsideNotifyRefundSuccessMsg refundSuccessMsg = new FmInsideNotifyRefundSuccessMsg(); | |||
| refundSuccessMsg.setMsgType(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode()); | |||
| refundSuccessMsg.setDelayTimeLevel(3); | |||
| refundSuccessMsg.setPayWay(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||
| refundSuccessMsg.setPayWay(EnumPayWay.PAY_WAY_WECHAT.getCode()); | |||
| refundSuccessMsg.setJsonMsg(jsonMsg); | |||
| // response = wxRefundOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | |||
| @@ -180,7 +180,7 @@ public class WxPayController extends BaseController { | |||
| xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8")); | |||
| paramMap = WxPayment.xmlToMap(xml); | |||
| logger.info("share wxpay, notify, param: " + xml ); | |||
| response = wxPayOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | |||
| response = wxPayOrderService.shareNotify(paramMap, EnumPayWay.PAY_WAY_WECHAT); | |||
| logger.info("share wxpay, notify success, req : " + xml + ", resp: " + response.toString()); | |||
| return response; | |||
| } catch (BizMessageException e) { | |||
| @@ -209,62 +209,62 @@ public class WxPayController extends BaseController { | |||
| * @return 接收微信异步通知 | |||
| * @throws Exception 可能产生的任何异常 | |||
| */ | |||
| @RequestMapping(value = "/subsidyPay", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | |||
| @ResponseBody | |||
| public String _subsidyPayNotify(HttpServletRequest request) throws IOException, JDOMException { | |||
| logger.info("[" +getIpAddr() + "] 补贴微信支付回调"); | |||
| InputStream inStream = request.getInputStream(); | |||
| ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); | |||
| byte[] buffer = new byte[1024]; | |||
| int len = 0; | |||
| while ((len = inStream.read(buffer)) != -1) { | |||
| outSteam.write(buffer, 0, len); | |||
| } | |||
| String resultxml = new String(outSteam.toByteArray(), Charset.forName("UTF-8")); | |||
| logger.info(resultxml); | |||
| outSteam.close(); | |||
| inStream.close(); | |||
| Map<String, String> paramMap = null; | |||
| try { | |||
| paramMap = WxPayment.xmlToMap(resultxml); | |||
| logger.info("微信支付回调, notify, param: " + paramMap.toString() ); | |||
| String response = wxSubsidyService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | |||
| logger.info("微信支付回调, notify success, req : " + resultxml + ", resp: " + response.toString()); | |||
| return response; | |||
| } catch (BizMessageException e) { | |||
| if (paramMap == null) { | |||
| logger.error("微信支付回调, order create error, e: " + e.getMessage()); | |||
| } else { | |||
| logger.error("微信支付回调, order create error, req: " + resultxml + ", e: " + e.getMessage()); | |||
| } | |||
| SortedMap resultMap = new TreeMap<>(); | |||
| resultMap.put("return_code", "FAIL"); | |||
| resultMap.put("return_msg", e.getMessage()); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } catch (MallinkException e) { | |||
| if (paramMap == null) { | |||
| logger.error("微信支付回调, order create error, e: " + e.getMessage()); | |||
| } else { | |||
| logger.error("微信支付回调, order create error, req: " + resultxml + ", e: " + e.getMessage()); | |||
| } | |||
| SortedMap resultMap = new TreeMap<>(); | |||
| resultMap.put("return_code", "FAIL"); | |||
| resultMap.put("return_msg", e.getMessage()); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } catch (Exception e) { | |||
| if (paramMap == null) { | |||
| logger.error("微信支付回调, order create error, e: " + e.getMessage()); | |||
| } else { | |||
| logger.error("微信支付回调, order create error, req: " + resultxml + ", e: " + e.getMessage()); | |||
| } | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "FAIL"); | |||
| resultMap.put("return_msg", e.getMessage()); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } | |||
| } | |||
| // @RequestMapping(value = "/subsidyPay", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | |||
| // @ResponseBody | |||
| // public String _subsidyPayNotify(HttpServletRequest request) throws IOException, JDOMException { | |||
| // logger.info("[" +getIpAddr() + "] 补贴微信支付回调"); | |||
| // InputStream inStream = request.getInputStream(); | |||
| // ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); | |||
| // byte[] buffer = new byte[1024]; | |||
| // int len = 0; | |||
| // while ((len = inStream.read(buffer)) != -1) { | |||
| // outSteam.write(buffer, 0, len); | |||
| // } | |||
| // String resultxml = new String(outSteam.toByteArray(), Charset.forName("UTF-8")); | |||
| // logger.info(resultxml); | |||
| // | |||
| // outSteam.close(); | |||
| // inStream.close(); | |||
| // | |||
| // Map<String, String> paramMap = null; | |||
| // | |||
| // try { | |||
| // paramMap = WxPayment.xmlToMap(resultxml); | |||
| // logger.info("微信支付回调, notify, param: " + paramMap.toString() ); | |||
| // String response = wxSubsidyService.notify(paramMap, EnumPayWay.PAY_WAY_WECHAT); | |||
| // logger.info("微信支付回调, notify success, req : " + resultxml + ", resp: " + response.toString()); | |||
| // return response; | |||
| // } catch (BizMessageException e) { | |||
| // if (paramMap == null) { | |||
| // logger.error("微信支付回调, order create error, e: " + e.getMessage()); | |||
| // } else { | |||
| // logger.error("微信支付回调, order create error, req: " + resultxml + ", e: " + e.getMessage()); | |||
| // } | |||
| // SortedMap resultMap = new TreeMap<>(); | |||
| // resultMap.put("return_code", "FAIL"); | |||
| // resultMap.put("return_msg", e.getMessage()); | |||
| // return XmlUtil.getRequestXml(resultMap); | |||
| // } catch (MallinkException e) { | |||
| // if (paramMap == null) { | |||
| // logger.error("微信支付回调, order create error, e: " + e.getMessage()); | |||
| // } else { | |||
| // logger.error("微信支付回调, order create error, req: " + resultxml + ", e: " + e.getMessage()); | |||
| // } | |||
| // SortedMap resultMap = new TreeMap<>(); | |||
| // resultMap.put("return_code", "FAIL"); | |||
| // resultMap.put("return_msg", e.getMessage()); | |||
| // return XmlUtil.getRequestXml(resultMap); | |||
| // } catch (Exception e) { | |||
| // if (paramMap == null) { | |||
| // logger.error("微信支付回调, order create error, e: " + e.getMessage()); | |||
| // } else { | |||
| // logger.error("微信支付回调, order create error, req: " + resultxml + ", e: " + e.getMessage()); | |||
| // } | |||
| // SortedMap resultMap = new TreeMap(); | |||
| // resultMap.put("return_code", "FAIL"); | |||
| // resultMap.put("return_msg", e.getMessage()); | |||
| // return XmlUtil.getRequestXml(resultMap); | |||
| // } | |||
| // } | |||
| } | |||
| @@ -37,8 +37,8 @@ public class MqBaseConsumer { | |||
| @Autowired | |||
| private MqBaseProducer mqBaseProducer; | |||
| @Autowired | |||
| private FmInsideNotifyPaySuccessMsgServiceImpl fmInsideNotifyPaySuccessMsgService; | |||
| //@Autowired | |||
| //private FmInsideNotifyPaySuccessMsgServiceImpl fmInsideNotifyPaySuccessMsgService; | |||
| @Autowired | |||
| private FmInsideNotifyRefundSuccessMsgServiceImpl fmInsideNotifyRefundSuccessMsgService; | |||
| @Autowired | |||
| @@ -89,11 +89,13 @@ public class MqBaseConsumer { | |||
| // 内部消息 - c端登录 | |||
| FmInsideCLoginMsg msg = (FmInsideCLoginMsg)JsonUtil.readValue(message,FmInsideCLoginMsg.class); | |||
| fmInsideCouponVerifyMsgService.send(msg); | |||
| } else if(EnumMsgRecordType.INSIDE_NOTIFY_PAY_SUCCESS.getCode().equals(baseMsg.getMsgType())) { | |||
| } | |||
| //else if(EnumMsgRecordType.INSIDE_NOTIFY_PAY_SUCCESS.getCode().equals(baseMsg.getMsgType())) { | |||
| // 内部消息 - 微信支付通知 | |||
| FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg)JsonUtil.readValue(message,FmInsideNotifyPaySuccessMsg.class); | |||
| fmInsideNotifyPaySuccessMsgService.send(msg); | |||
| } else if(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode().equals(baseMsg.getMsgType())) { | |||
| //FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg)JsonUtil.readValue(message,FmInsideNotifyPaySuccessMsg.class); | |||
| //fmInsideNotifyPaySuccessMsgService.send(msg); | |||
| //} | |||
| else if(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode().equals(baseMsg.getMsgType())) { | |||
| // 内部消息 - 微信退款通知 | |||
| FmInsideNotifyRefundSuccessMsg msg = (FmInsideNotifyRefundSuccessMsg)JsonUtil.readValue(message,FmInsideNotifyRefundSuccessMsg.class); | |||
| fmInsideNotifyRefundSuccessMsgService.send(msg); | |||
| @@ -41,7 +41,7 @@ public class PosServiceImpl implements PosService { | |||
| private final WxMallService mallService; | |||
| private final PosMallConfigService posMallConfigService; | |||
| private final WxCUserService cUserService; | |||
| private final WxCUserBasicInfoService cUserBasicInfoService; | |||
| private final WxLevelConfigService levelConfigService; | |||
| private final WxCouponOrderService couponOrderService; | |||
| private final WxMerchantService merchantService; | |||
| @@ -286,7 +286,7 @@ public class PosServiceImpl implements PosService { | |||
| dataMap.put(WxPayConstant.ORDER_AMOUNT_LEFT, orderAmountLeftStr); | |||
| } | |||
| WxCUser user = null; | |||
| WxCUserBasicInfo user = null; | |||
| if (StringUtils.isNotBlank(cardIdStr)) { | |||
| Long cardId; | |||
| try { | |||
| @@ -299,7 +299,7 @@ public class PosServiceImpl implements PosService { | |||
| if (couponOrder == null) { | |||
| throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); | |||
| } | |||
| user = cUserService.getById(couponOrder.getOwnerId()); | |||
| user = cUserBasicInfoService.getById(couponOrder.getOwnerId()); | |||
| } else { | |||
| if (StringUtils.isBlank(memIdStr) && StringUtils.isBlank(memPhoneStr)) { | |||
| errParam2(WxPayConstant.MEM_ID, WxPayConstant.MEM_PHONE); | |||
| @@ -687,8 +687,8 @@ public class PosServiceImpl implements PosService { | |||
| return couponOrderCVo; | |||
| } | |||
| private WxCUser getMemUser(TenantEntity tenantEntity, String memIdStr, String memPhoneStr) { | |||
| WxCUser user = null; | |||
| private WxCUserBasicInfo getMemUser(TenantEntity tenantEntity, String memIdStr, String memPhoneStr) { | |||
| WxCUserBasicInfo user = null; | |||
| if (StringUtils.isNotBlank(memIdStr)) { | |||
| Long memId; | |||
| try { | |||
| @@ -697,14 +697,10 @@ public class PosServiceImpl implements PosService { | |||
| logger.error(e.getMessage()); | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); | |||
| } | |||
| user = cUserService.getById(memId); | |||
| user = cUserBasicInfoService.getById(memId); | |||
| } | |||
| if (StringUtils.isNotBlank(memPhoneStr)) { | |||
| WxCUser q = new WxCUser(); | |||
| q.updateTenantInfo(tenantEntity); | |||
| q.setPhone(memPhoneStr); | |||
| user = cUserService.getByObject(q); | |||
| user = cUserBasicInfoService.findInfoByPhone(tenantEntity,memPhoneStr); | |||
| } | |||
| return user; | |||
| } | |||
| @@ -718,7 +714,8 @@ public class PosServiceImpl implements PosService { | |||
| * @param merchantId | |||
| * @return | |||
| */ | |||
| private JSONObject getMemLevelDiscount(PromotionCalc promotionCalc, Integer discountConfig, TenantEntity tenantEntity, WxCUser user, Long merchantId) { | |||
| private JSONObject getMemLevelDiscount(PromotionCalc promotionCalc, Integer discountConfig, | |||
| TenantEntity tenantEntity, WxCUserBasicInfo user, Long merchantId) { | |||
| JSONObject discountObj = new JSONObject(); | |||
| Integer discount = 100; | |||
| if (discountConfig.equals(EnumPosEnableType.Enable.getCode())) { | |||
| @@ -727,7 +724,7 @@ public class PosServiceImpl implements PosService { | |||
| List<WxLevelConfig> levelList = levelConfigService.getByTenantId(tenantEntity.getTenantId()); | |||
| Long levelId = 0L; | |||
| for (WxLevelConfig levelConfig : levelList) { | |||
| if (user.getScore() >= levelConfig.getPoints()) { | |||
| if (user.getPoins() >= levelConfig.getPoints()) { | |||
| if (levelConfig.getDiscountEnable().equals(EnumLevelConfigDiscountStatus.ENABLE.getCode())) | |||
| levelId = levelConfig.getId(); | |||
| level = levelConfig.getLevel(); | |||
| @@ -912,7 +909,7 @@ public class PosServiceImpl implements PosService { | |||
| errParam2(WxPayConstant.MEM_ID, WxPayConstant.MEM_PHONE); | |||
| } | |||
| // 10. 获取会员信息 | |||
| WxCUser user = getMemUser(merchant, memIdStr, memPhoneStr); | |||
| WxCUserBasicInfo user = getMemUser(merchant, memIdStr, memPhoneStr); | |||
| if (user == null) { | |||
| logger.error(ErrorCode.USER_NOT_MEMBER.getMessage()); | |||
| throw new MallinkException(ErrorCode.USER_NOT_MEMBER); | |||
| @@ -1179,7 +1176,7 @@ public class PosServiceImpl implements PosService { | |||
| throw new MallinkException(ErrorCode.POS_COUPON_REFUND_ERROR.getCode(), errMesg); | |||
| } | |||
| // 10. 获取会员信息 | |||
| WxCUser user = getMemUser(merchant, memIdStr, memPhoneStr); | |||
| WxCUserBasicInfo user = getMemUser(merchant, memIdStr, memPhoneStr); | |||
| if (user == null) { | |||
| logger.error(ErrorCode.USER_NOT_MEMBER.getMessage()); | |||
| throw new MallinkException(ErrorCode.USER_NOT_MEMBER); | |||
| @@ -1600,7 +1597,7 @@ public class PosServiceImpl implements PosService { | |||
| throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); | |||
| } | |||
| if (StringUtils.isNotBlank(memIdStr) || StringUtils.isNotBlank(memPhoneStr)) { | |||
| WxCUser cuUser = getMemUser(merchant, memIdStr, memPhoneStr); | |||
| WxCUserBasicInfo cuUser = getMemUser(merchant, memIdStr, memPhoneStr); | |||
| if (cuUser == null) { | |||
| logger.error(ErrorCode.USER_NOT_MEMBER.getMessage()); | |||
| throw new MallinkException(ErrorCode.USER_NOT_MEMBER); | |||
| @@ -2172,6 +2169,7 @@ public class PosServiceImpl implements PosService { | |||
| WxCouponOrder updateCO = new WxCouponOrder(); | |||
| updateCO.setId(couponOrderId); | |||
| updateCO.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); | |||
| updateCO.setPayVendor(EnumPayWay.PAY_WAY_POS_NEU.getCode()); | |||
| couponOrderMapper.updateById(updateCO); | |||
| } | |||
| WxCouponOrderCVo couponOrderCVo = couponOrderService.detailCUserVo(posPayOrderNo); | |||
| @@ -2272,7 +2270,7 @@ public class PosServiceImpl implements PosService { | |||
| WxCardSpend cardSpend = cardSpendService.getById(cardSpendId); | |||
| if (cardSpend != null) { | |||
| cardSpend.setOrderId(order.getId()); | |||
| cardSpendService.cardSpendForPosPay(scoreCreditCalc, cardSpend, merchant, buUser); | |||
| cardSpendService.cardSpendForPosPay(scoreCreditCalc, cardSpend, merchant, buUser,payOrder.getPayVendor()); | |||
| } else { | |||
| logger.error("卡支付ID未发现: " + cardSpendId); | |||
| throw new MallinkException(ErrorCode.POS_CARD_ORDER_NOT_FOUND); | |||
| @@ -166,7 +166,7 @@ public class CouponOrderExpiringSchedule { | |||
| // 未设置通道费差 | |||
| wxSharingOrderDto.setShareAmount(wxPayOrder.getShareAmount()); | |||
| } | |||
| wxProfitSharingOrderService.finishSharingOrder(wxSharingOrderDto); | |||
| wxProfitSharingOrderService.finishSharingOrder(wxSharingOrderDto,wxPayOrder.getPayVendor()); | |||
| } | |||
| } catch (MallinkException e) { | |||
| @@ -189,7 +189,7 @@ public class CouponSendSchedule { | |||
| // 发放免费券 | |||
| try { | |||
| WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cu.getId(), cs.getCouponId(), null); | |||
| WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cu.getId(), cs.getCouponId(), null,EnumPayWay.PAY_WAY_NOT_UNPAY_SYSTEM_SEND); | |||
| wxCouponActionLogService.addOne(tenantEntity, cs.getCouponId(), couponOrder.getId(), cs.getSendType(), cs.getId()); | |||
| } catch (Exception e) { | |||
| logger.error("定时发券:发券失败 levelId=" + l.getId() + " couponId=" + cs.getCouponId() + " userId=" + cu.getId() + e.getMessage()); | |||
| @@ -319,7 +319,7 @@ public class CouponSendSchedule { | |||
| for (WxCUserBasicInfo cu : newUserList) { | |||
| // 发放生日券 | |||
| try { | |||
| WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cu.getId(), cs.getCouponId(), null); | |||
| WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cu.getId(), cs.getCouponId(), null,EnumPayWay.PAY_WAY_NOT_UNPAY_SYSTEM_SEND); | |||
| wxCouponActionLogService.addOne(tenantEntity, cs.getCouponId(), couponOrder.getId(), cs.getSendType(), cs.getId()); | |||
| couponSendedUsers.add(cu); | |||
| } catch (Exception e) { | |||
| @@ -25,56 +25,56 @@ public class MsgReSendSchedule { | |||
| @Autowired | |||
| private MqBaseProducer mqBaseProducer; | |||
| @Scheduled(cron = "0 */5 * * * *?") // 每5分钟检查一次 | |||
| //@Scheduled(cron = "0 */5 * * * *?") // 每5分钟检查一次 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void msgReSend() { | |||
| logger.info("消息重发开始..."); | |||
| //消息重发 | |||
| WxMsgRecord msgRecord = new WxMsgRecord(); | |||
| msgRecord.setMsgStatus(EnumMsgRecordStatus.SEND_FAIL.getCode()); | |||
| List<WxMsgRecord> recordList = wxMsgRecordService.findList(msgRecord); | |||
| for (WxMsgRecord wxMsgRecord:recordList) { | |||
| logger.info("消息重发:{}",wxMsgRecord.getMsgJson()); | |||
| TenantEntity tenantEntity = wxMsgRecord.getTenantInfo(); | |||
| try { | |||
| if(EnumMsgRecordType.INSIDE_ORDER_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){ | |||
| //内部消息 - 下订单成功 | |||
| FmInsideOrderSuccessMsg msg = (FmInsideOrderSuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideOrderSuccessMsg.class); | |||
| msg.setMsgType(wxMsgRecord.getMsgType()); | |||
| msg.setReceiver(wxMsgRecord.getReceiver()); | |||
| msg.updateTenantInfo(tenantEntity); | |||
| mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| }else if(EnumMsgRecordType.INSIDE_COUPON_VERIFY.getCode().equals(wxMsgRecord.getMsgType())){ | |||
| FmInsideCouponVerifyMsg msg = (FmInsideCouponVerifyMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideCouponVerifyMsg.class); | |||
| msg.setMsgType(wxMsgRecord.getMsgType()); | |||
| msg.setReceiver(wxMsgRecord.getReceiver()); | |||
| msg.updateTenantInfo(tenantEntity); | |||
| mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| }else if(EnumMsgRecordType.INSIDE_C_LOGIN.getCode().equals(wxMsgRecord.getMsgType())){ | |||
| FmInsideCLoginMsg msg = (FmInsideCLoginMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideCLoginMsg.class); | |||
| msg.setMsgType(wxMsgRecord.getMsgType()); | |||
| msg.setReceiver(wxMsgRecord.getReceiver()); | |||
| msg.updateTenantInfo(tenantEntity); | |||
| mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| }else if(EnumMsgRecordType.INSIDE_NOTIFY_PAY_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){ | |||
| FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideNotifyPaySuccessMsg.class); | |||
| msg.setMsgType(wxMsgRecord.getMsgType()); | |||
| msg.setReceiver(wxMsgRecord.getReceiver()); | |||
| msg.updateTenantInfo(tenantEntity); | |||
| mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| }else if(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){ | |||
| FmInsideNotifyRefundSuccessMsg msg = (FmInsideNotifyRefundSuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideNotifyRefundSuccessMsg.class); | |||
| msg.setMsgType(wxMsgRecord.getMsgType()); | |||
| msg.setReceiver(wxMsgRecord.getReceiver()); | |||
| msg.updateTenantInfo(tenantEntity); | |||
| mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| } | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| logger.error("消息重发错误:" + e.getMessage()); | |||
| } | |||
| } | |||
| logger.info("消息重发结束..."); | |||
| // logger.info("消息重发开始..."); | |||
| // //消息重发 | |||
| // WxMsgRecord msgRecord = new WxMsgRecord(); | |||
| // msgRecord.setMsgStatus(EnumMsgRecordStatus.SEND_FAIL.getCode()); | |||
| // List<WxMsgRecord> recordList = wxMsgRecordService.findList(msgRecord); | |||
| // for (WxMsgRecord wxMsgRecord:recordList) { | |||
| // logger.info("消息重发:{}",wxMsgRecord.getMsgJson()); | |||
| // TenantEntity tenantEntity = wxMsgRecord.getTenantInfo(); | |||
| // try { | |||
| // if(EnumMsgRecordType.INSIDE_ORDER_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){ | |||
| // //内部消息 - 下订单成功 | |||
| // FmInsideOrderSuccessMsg msg = (FmInsideOrderSuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideOrderSuccessMsg.class); | |||
| // msg.setMsgType(wxMsgRecord.getMsgType()); | |||
| // msg.setReceiver(wxMsgRecord.getReceiver()); | |||
| // msg.updateTenantInfo(tenantEntity); | |||
| // mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| // }else if(EnumMsgRecordType.INSIDE_COUPON_VERIFY.getCode().equals(wxMsgRecord.getMsgType())){ | |||
| // FmInsideCouponVerifyMsg msg = (FmInsideCouponVerifyMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideCouponVerifyMsg.class); | |||
| // msg.setMsgType(wxMsgRecord.getMsgType()); | |||
| // msg.setReceiver(wxMsgRecord.getReceiver()); | |||
| // msg.updateTenantInfo(tenantEntity); | |||
| // mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| // }else if(EnumMsgRecordType.INSIDE_C_LOGIN.getCode().equals(wxMsgRecord.getMsgType())){ | |||
| // FmInsideCLoginMsg msg = (FmInsideCLoginMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideCLoginMsg.class); | |||
| // msg.setMsgType(wxMsgRecord.getMsgType()); | |||
| // msg.setReceiver(wxMsgRecord.getReceiver()); | |||
| // msg.updateTenantInfo(tenantEntity); | |||
| // mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| // }else if(EnumMsgRecordType.INSIDE_NOTIFY_PAY_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){ | |||
| // FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideNotifyPaySuccessMsg.class); | |||
| // msg.setMsgType(wxMsgRecord.getMsgType()); | |||
| // msg.setReceiver(wxMsgRecord.getReceiver()); | |||
| // msg.updateTenantInfo(tenantEntity); | |||
| // mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| // }else if(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){ | |||
| // FmInsideNotifyRefundSuccessMsg msg = (FmInsideNotifyRefundSuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideNotifyRefundSuccessMsg.class); | |||
| // msg.setMsgType(wxMsgRecord.getMsgType()); | |||
| // msg.setReceiver(wxMsgRecord.getReceiver()); | |||
| // msg.updateTenantInfo(tenantEntity); | |||
| // mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| // } | |||
| // } catch (Exception e) { | |||
| // e.printStackTrace(); | |||
| // logger.error("消息重发错误:" + e.getMessage()); | |||
| // } | |||
| // } | |||
| // logger.info("消息重发结束..."); | |||
| } | |||
| @@ -5,6 +5,8 @@ import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.mapper.*; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.aop.framework.AopContext; | |||
| @@ -16,29 +18,19 @@ import org.springframework.transaction.annotation.Transactional; | |||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.enums.EnumAppType; | |||
| import com.iformall.enums.EnumOrderStatus; | |||
| import com.iformall.enums.EnumOrderType; | |||
| import com.iformall.enums.EnumPayStatus; | |||
| import com.iformall.enums.EnumRefundStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxAppinfoMapper; | |||
| import com.iformall.mapper.WxCUserMapper; | |||
| import com.iformall.mapper.WxCouponMapper; | |||
| import com.iformall.mapper.WxOrderGroupMapper; | |||
| import com.iformall.mapper.WxOrderMapper; | |||
| import com.iformall.mapper.WxPayAccountMapper; | |||
| import com.iformall.mapper.WxPayOrderMapper; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.service.WxPayOrderService; | |||
| import com.iformall.service.WxRefundOrderService; | |||
| import com.iformall.service.helper.WxPayOrderServiceHelper; | |||
| import com.iformall.service.pay.PayServiceFactory; | |||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
| import com.iformall.utils.DateUtils; | |||
| @Component | |||
| @@ -68,9 +60,12 @@ public class OrderExpiringSchedule { | |||
| @Autowired | |||
| WxPayOrderMapper wxPayOrderMapper; | |||
| @Autowired | |||
| WxCUserMapper wxCUserMapper; | |||
| @Autowired | |||
| WxCUserBasicInfoMapper wxCUserBasicInfoMapper; | |||
| @Autowired | |||
| WxAppinfoService wxAppinfoService; | |||
| @@ -81,6 +76,9 @@ public class OrderExpiringSchedule { | |||
| @Autowired | |||
| WxPayOrderService wxPayOrderService; | |||
| @Autowired | |||
| PayServiceFactory payServiceFactory; | |||
| @Scheduled(cron = "0 */5 * * * *?") // 每5分钟检查一次 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void orderExpireSchedule() { | |||
| @@ -188,13 +186,13 @@ public class OrderExpiringSchedule { | |||
| } | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void expiredAndReturnMoney(WxOrder wxOrder,boolean checkRealPay) { | |||
| public void expiredAndReturnMoney(WxOrder wxOrder,boolean checkRealPay) throws MallinkException, Exception { | |||
| orderGroupExpired(wxOrder,checkRealPay,false); | |||
| returnMoney(wxOrder); | |||
| } | |||
| public boolean wxPaySuccess(WxOrder order,boolean autoReHandle) { | |||
| public boolean wxPaySuccess(WxOrder order,boolean autoReHandle) throws MallinkException, Exception { | |||
| WxPayOrder payOrderq = new WxPayOrder(); | |||
| payOrderq.setOrderId(order.getId()); | |||
| List<WxPayOrder> payorderlist = wxPayOrderMapper.findList(payOrderq); | |||
| @@ -205,12 +203,20 @@ public class OrderExpiringSchedule { | |||
| if (null == wxpayOrder) { | |||
| return false; | |||
| } | |||
| WxCUser user = wxCUserMapper.selectById(wxpayOrder.getCUserId()); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectById(wxpayOrder.getCUserId()); | |||
| //找不到用户,问题单,不能删 | |||
| if (null == user) { | |||
| return true; | |||
| } | |||
| WxAppinfo appInfo = wxAppinfoService.getByAppId(user.getAppId()); | |||
| WxCUser cuUser = new WxCUser(); | |||
| cuUser.updateTenantInfo(order); | |||
| cuUser.setUserId(user.getId()); | |||
| WxCUser cUser = wxCUserMapper.selectOne(new QueryWrapper(cuUser)); | |||
| //找不到用户,问题单,不能删 | |||
| if (null == cUser) { | |||
| return true; | |||
| } | |||
| WxAppinfo appInfo = wxAppinfoService.getByAppId(cUser.getAppId()); | |||
| //找不到appInfo,问题单,不能删 | |||
| if(appInfo == null) { | |||
| return true; | |||
| @@ -220,12 +226,13 @@ public class OrderExpiringSchedule { | |||
| if (null == payAccount) { | |||
| return true; | |||
| } | |||
| Map<String, String> retMap = WxPayOrderServiceHelper.wxOrderPayStatusMap(wxpayOrder, order, appInfo, payAccount); | |||
| int status = WxPayOrderServiceHelper.getPayStatusFromMap(retMap, wxpayOrder.getPayOrderNo()); | |||
| //Map<String, String> retMap = WxPayOrderServiceHelper.wxOrderPayStatusMap(wxpayOrder, order, appInfo, payAccount); | |||
| //int status = WxPayOrderServiceHelper.getPayStatusFromMap(retMap, wxpayOrder.getPayOrderNo()); | |||
| PayQueryAdapterResult payResult = payServiceFactory.getPayAdapterService(wxpayOrder.getPayVendor()).queryPayStatus(wxpayOrder, order, appInfo, payAccount); | |||
| //如果是支付成功,并且需要重试成功流程, | |||
| if (EnumPayStatus.PAY_STATUS_SUCCESS.getCode() == status) { | |||
| if (EnumPayStatus.PAY_STATUS_SUCCESS.getCode().intValue() == payResult.getCode()) { | |||
| if (autoReHandle) { | |||
| wxPayOrderService.handleSuccessOrder(wxpayOrder, order, retMap,true); | |||
| wxPayOrderService.handleSuccessOrder(wxpayOrder, order, payResult,true); | |||
| } | |||
| return true; | |||
| } | |||
| @@ -234,7 +241,7 @@ public class OrderExpiringSchedule { | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void orderExpired(WxOrder order,boolean checkRealPay) { | |||
| public void orderExpired(WxOrder order,boolean checkRealPay) throws MallinkException, Exception { | |||
| if (checkRealPay) { | |||
| if (wxPaySuccess(order,true)) { | |||
| return; | |||
| @@ -257,7 +264,7 @@ public class OrderExpiringSchedule { | |||
| } | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void orderPressExpired(WxOrder order, boolean payExpired,boolean checkRealPay) { | |||
| public void orderPressExpired(WxOrder order, boolean payExpired,boolean checkRealPay) throws MallinkException, Exception { | |||
| if (checkRealPay) { | |||
| if (wxPaySuccess(order,true)) { | |||
| return; | |||
| @@ -283,7 +290,7 @@ public class OrderExpiringSchedule { | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void orderGroupExpired(WxOrder order,boolean checkRealPay,boolean stockBack) { | |||
| public void orderGroupExpired(WxOrder order,boolean checkRealPay,boolean stockBack) throws MallinkException, Exception { | |||
| if (checkRealPay) { | |||
| if (wxPaySuccess(order,true)) { | |||
| return; | |||
| @@ -320,9 +327,11 @@ public class OrderExpiringSchedule { | |||
| /** | |||
| * 回调会再次扣减库存 | |||
| * @param order | |||
| * @throws Exception | |||
| * @throws MallinkException | |||
| */ | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void returnMoney(WxOrder order) { | |||
| public void returnMoney(WxOrder order) throws MallinkException, Exception { | |||
| //支付成功的才退款 | |||
| if (!wxPaySuccess(order,false)) { | |||
| return; | |||
| @@ -7,6 +7,8 @@ import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.domain.po.base.BaseTenantEntity; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.UserUtil; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| @@ -26,6 +28,8 @@ public class WxCUser extends TenantEntity { | |||
| protected Long id; | |||
| @io.swagger.annotations.ApiModelProperty(value="userId",name="userId") | |||
| private Long userId; | |||
| @io.swagger.annotations.ApiModelProperty(value="微信openId",name="openId") | |||
| private String openId; | |||
| @io.swagger.annotations.ApiModelProperty(value="微信unionId",name="unionId") | |||
| @@ -153,4 +157,12 @@ public class WxCUser extends TenantEntity { | |||
| } | |||
| return this.token; | |||
| } | |||
| /** | |||
| * 是否是会员 | |||
| * @return | |||
| */ | |||
| public boolean isBasicInfo() { | |||
| return UserUtil.CuserIsBasicInfo(this.getUserId()); | |||
| } | |||
| } | |||
| @@ -11,6 +11,7 @@ import com.iformall.domain.po.base.TenantEntity; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import javax.validation.constraints.NotNull; | |||
| import java.util.Date; | |||
| @@ -28,6 +29,8 @@ public class WxCUserBasicInfo extends TenantEntity { | |||
| @JsonIgnore | |||
| protected Date scoreDate; | |||
| private String finalTenantId; | |||
| @Excel(name="姓名",width = 20,orderNum = "1") | |||
| @NotNull | |||
| @io.swagger.annotations.ApiModelProperty(value="用户姓名",name="name") | |||
| @@ -46,6 +49,9 @@ public class WxCUserBasicInfo extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="用户昵称",name="nickName") | |||
| private String nickName; | |||
| @io.swagger.annotations.ApiModelProperty(value="用户头像地址",name="avatarUrl") | |||
| private String avatarUrl; | |||
| @Excel(name="学历",width = 20,orderNum = "5") | |||
| @NotNull | |||
| @io.swagger.annotations.ApiModelProperty(value="学历",name="education") | |||
| @@ -71,6 +77,9 @@ public class WxCUserBasicInfo extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||
| private Date createDate; | |||
| @io.swagger.annotations.ApiModelProperty(value="登录次数",name="loginCount") | |||
| private Integer loginCount; | |||
| @Excel(name="成长值",width = 20, orderNum = "11") | |||
| @io.swagger.annotations.ApiModelProperty(value="成长值",name="poins") | |||
| private Integer poins; | |||
| @@ -120,6 +129,14 @@ public class WxCUserBasicInfo extends TenantEntity { | |||
| @TableField(exist = false) | |||
| private Date endTime; | |||
| @TableField(exist = false) | |||
| @io.swagger.annotations.ApiModelProperty(value="操作人类型 枚举:EnumUserType",name="operatorType") | |||
| private Integer operatorType; | |||
| @TableField(exist = false) | |||
| @io.swagger.annotations.ApiModelProperty(value="操作人ID",name="operatorId") | |||
| private Long operatorId; | |||
| public String getAddressStr() { | |||
| if (address == null) | |||
| return null; | |||
| @@ -151,5 +168,19 @@ public class WxCUserBasicInfo extends TenantEntity { | |||
| public int hashCode() { | |||
| return Objects.hash(this.phone); | |||
| } | |||
| public void undateFinalTenantId(){ | |||
| setFinalTenantId(getTenantId()); | |||
| if(StringUtils.isNotBlank(getParentTenantId())){ | |||
| setFinalTenantId(getParentTenantId()); | |||
| } | |||
| } | |||
| public void undateFinalTenantId(TenantEntity tenantEntity){ | |||
| setFinalTenantId(tenantEntity.getTenantId()); | |||
| if(StringUtils.isNotBlank(tenantEntity.getParentTenantId())){ | |||
| setFinalTenantId(tenantEntity.getParentTenantId()); | |||
| } | |||
| } | |||
| } | |||
| @@ -61,6 +61,9 @@ public class WxCardSpend extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="来源(0:C端小程序扫一扫, 1:POS支付)",name="payFrom") | |||
| private Integer payFrom; | |||
| @io.swagger.annotations.ApiModelProperty(value="说明",name="remark") | |||
| private String remark; | |||
| @TableField(exist = false) | |||
| @Excel(name = "消费金额(元)", width = 20, orderNum = "7") | |||
| @@ -42,7 +42,8 @@ public class WxCouponOrder extends TenantEntity { | |||
| private Date updateDate; | |||
| @io.swagger.annotations.ApiModelProperty(value = "单券实际购买价格", name = "couponPrice") | |||
| private Integer couponPrice; | |||
| @io.swagger.annotations.ApiModelProperty(value = "支付渠道EnumPayWay", name = "pay_vendor") | |||
| private Integer payVendor; | |||
| @io.swagger.annotations.ApiModelProperty(value="过期退款(0:正常,1不退)",name="autoRefund") | |||
| private Integer autoRefund; | |||
| @@ -4,12 +4,14 @@ import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| import java.util.*; | |||
| @TableName(value = "wx_pay_order") | |||
| @Data | |||
| @EqualsAndHashCode(callSuper = true) | |||
| @ToString | |||
| public class WxPayOrder extends TenantEntity { | |||
| protected Long id; | |||
| @@ -4,12 +4,14 @@ import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| import java.util.*; | |||
| @TableName(value = "wx_refund_order") | |||
| @Data | |||
| @EqualsAndHashCode(callSuper = true) | |||
| @ToString | |||
| public class WxRefundOrder extends TenantEntity { | |||
| protected Long id; | |||
| @@ -32,4 +32,12 @@ public class TenantEntity extends BaseEntity { | |||
| setParentTenantId(info.getParentTenantId()); | |||
| } | |||
| } | |||
| public void updateFinalTenantInfo(TenantEntity info){ | |||
| if (StringUtils.isNotBlank(info.getParentTenantId())) { | |||
| setParentTenantId(info.getParentTenantId()); | |||
| }else{ | |||
| setTenantId(info.getTenantId()); | |||
| } | |||
| } | |||
| } | |||
| @@ -15,7 +15,7 @@ public enum EnumMsgRecordType { | |||
| INSIDE_ORDER_SUCCESS(100, "下订单成功"), | |||
| INSIDE_COUPON_VERIFY(101, "券核销"), | |||
| INSIDE_C_LOGIN(102, "C端用户登录"), | |||
| INSIDE_NOTIFY_PAY_SUCCESS(103, "微信支付回调"), | |||
| //INSIDE_NOTIFY_PAY_SUCCESS(103, "微信支付回调"), | |||
| INSIDE_NOTIFY_REFUND_SUCCESS(104, "微信退款回调"), | |||
| COUPON_STOCK(105, "券库存更新"), | |||
| ; | |||
| @@ -5,8 +5,8 @@ package com.iformall.enums; | |||
| */ | |||
| public enum EnumPayMode { | |||
| MCH(0, "普通商户模式"), | |||
| MCH_S(1, "服务商模式"); | |||
| MCH(0, "微信普通商户模式"), | |||
| MCH_S(1, "微信服务商模式"); | |||
| public static EnumPayMode getEnum(Integer code) { | |||
| for (EnumPayMode value : values()) { | |||
| @@ -15,7 +15,8 @@ public enum EnumPayStatus { | |||
| PAY_STATUS_CLOSE_FAIL(6,"关闭支付订单失败"), | |||
| PAY_STATUS_REVERSE(7, "撤销支付订单"), | |||
| PAY_STATUS_REVERSE_FAIL(8,"撤销支付订单失败"), | |||
| PAY_STATUS_REFUND(9,"支付转退款") | |||
| PAY_STATUS_REFUND(9,"支付转退款"), | |||
| PAY_STATUS_ORDER_NOT_EXISTS(10,"支付单不存在") | |||
| ; | |||
| public static EnumPayStatus getEnum(Integer code) { | |||
| @@ -5,30 +5,41 @@ package com.iformall.enums; | |||
| */ | |||
| public enum EnumPayWay { | |||
| PAY_WAY_WEAPP(0, "微信小程序"), | |||
| PAY_WAY_WECHAT(1, "微信支付"), | |||
| PAY_WAY_WECHAT_WAP(2, "微信H5"), | |||
| PAY_WAY_ALIPAY(3, "支付宝"), | |||
| PAY_WAY_ALIPAY_WAP(4, "支付宝H5"), | |||
| PAY_WAY_POS_B(10, "POS B端"), | |||
| PAY_WAY_POS_NEU(11, "POS 东软"), | |||
| PAY_WAY_WECHAT(1, "微信小程序支付",EnumPayWayType.WX_MINIPAY), | |||
| PAY_WAY_WECHAT_MA(12, "微信小程序B端扫码支付",EnumPayWayType.WX_MINIPAY), | |||
| PAY_WAY_WECHAT_WAP(2, "微信H5",EnumPayWayType.WX_H5PAY), | |||
| PAY_WAY_ALIPAY(3, "支付宝",EnumPayWayType.ALI_MINIPAY), | |||
| PAY_WAY_ALIPAY_WAP(4, "支付宝H5",EnumPayWayType.ALI_H5PAY), | |||
| PAY_WAY_POS_B(10, "POS B端",EnumPayWayType.POS), | |||
| PAY_WAY_POS_NEU(11, "POS 东软",EnumPayWayType.NEU_POS), | |||
| PAY_WAY_NOT_UNPAY_MERCHANT(91, "商户注券,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_VERRIFY(92, "核销发券,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_B_MA(93, "B端扫码支付发券,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_CAR_STOP(94, "停车发券,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_SYSTEM_SEND(95, "系统定时发放券,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_BATCH_SEND(96, "后台批量发券,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_TRADE(97, "交易发券,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_PASSWD(98, "根据卡密兑换卡,无需支付",null), | |||
| PAY_WAY_NOT_UNPAY_CREDIT(99, "积分兑换券,无需支付",null) | |||
| ; | |||
| public static EnumPayWay getEnum(Integer code) { | |||
| for (EnumPayWay value : values()) { | |||
| if (value.getCode().equals(code)) { | |||
| if (value.getCode().intValue()==code.intValue()) { | |||
| return value; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| private Integer code; | |||
| private String message; | |||
| private EnumPayWayType type; | |||
| EnumPayWay(Integer code, String message) { | |||
| EnumPayWay(Integer code, String message,EnumPayWayType type) { | |||
| this.code = code; | |||
| this.message = message; | |||
| this.type = type; | |||
| } | |||
| public Integer getCode() { | |||
| @@ -38,4 +49,13 @@ public enum EnumPayWay { | |||
| public String getMessage() { | |||
| return message; | |||
| } | |||
| public EnumPayWayType getType() { | |||
| return type; | |||
| } | |||
| public static enum EnumPayWayType { | |||
| WX_MINIPAY,WX_H5PAY,ALI_MINIPAY,ALI_H5PAY,NEU_POS,POS | |||
| } | |||
| } | |||
| @@ -19,6 +19,9 @@ public interface WxCUserBasicInfoMapper extends CommonMapper<WxCUserBasicInfo, S | |||
| void updateScore(WxCUserBasicInfo record); | |||
| void updateUpScore(WxCUserBasicInfo record); | |||
| void updateDownScore(WxCUserBasicInfo record); | |||
| void updateNewId(CUserBaseVo record); | |||
| long findCountBySex(WxCUserBasicInfoDto dto); | |||
| @@ -27,4 +27,6 @@ public interface WxCUserMapper extends CommonMapper<WxCUser, Long> { | |||
| long countByChannel(WxCUser wxCUser); | |||
| List<Map<String, Object>> checkCountByTenantOpenId(); | |||
| void updateUserId(WxCUser user); | |||
| } | |||
| @@ -9,7 +9,7 @@ public interface WxPayOrderMapper extends CommonMapper<WxPayOrder, Long> { | |||
| List<WxPayOrder> findList(WxPayOrder wxPayOrder); | |||
| List<WxPayOrderVo> findListOfPaidOrderByDate(Map dateMap); | |||
| //List<WxPayOrderVo> findListOfPaidOrderByDate(Map dateMap); | |||
| List<WxPayOrder> findListForUnPs(WxPayOrder wxPayOrder); | |||
| @@ -3,8 +3,10 @@ package com.iformall.mapper; | |||
| import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
| import com.iformall.domain.po.WxProjectConfig; | |||
| import org.apache.ibatis.annotations.Param; | |||
| public interface WxProjectConfigMapper extends BaseMapper<WxProjectConfig> { | |||
| void initAfterGroup(@Param(value = "tenantId")String tenantId, @Param(value = "subTenantIds")String subTenantIds); | |||
| } | |||
| @@ -151,5 +151,6 @@ public interface WxCUserBasicInfoService { | |||
| ResultData updateStatus(WxCUserBasicInfo wxCUserBasicInfo); | |||
| WxCUserBasicInfo getByObject(WxCUserBasicInfo wxCUserBasicInfo); | |||
| } | |||
| @@ -136,5 +136,7 @@ public interface WxCUserService { | |||
| * @param enumScoreType | |||
| * @return | |||
| */ | |||
| WxCreditHistory addCredit(WxCUser wxCUser, EnumScoreType enumScoreType); | |||
| int addCredit(WxCUser wxCUser, EnumScoreType enumScoreType); | |||
| void updateUserId(WxCUser user); | |||
| } | |||
| @@ -6,6 +6,7 @@ import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.vo.PromotionCalc; | |||
| import com.iformall.domain.vo.WxCardSpendVo; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.exception.MallinkException; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| @@ -27,7 +28,7 @@ public interface WxCardSpendService { | |||
| * @param order | |||
| * @return | |||
| */ | |||
| ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCouponMerchant couponMerchant); | |||
| ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCouponMerchant couponMerchant,EnumPayWay payWay); | |||
| /** | |||
| * 根据实体查询分页列表 | |||
| @@ -97,7 +98,7 @@ public interface WxCardSpendService { | |||
| * @param orderId | |||
| * @param cardSpendId | |||
| */ | |||
| void shareForCardPay(TenantEntity tenantEntity, Long cardId, Long orderId, Long cardSpendId); | |||
| void shareForCardPay(TenantEntity tenantEntity, Long cardId, Long orderId, Long cardSpendId,Integer payWay); | |||
| /** | |||
| * cardPay交易流水导出 | |||
| @@ -109,5 +110,5 @@ public interface WxCardSpendService { | |||
| */ | |||
| WxCardSpend cardSpendForPosPrePay(WxCardSpend record) throws MallinkException; | |||
| WxCardInfo cardSpendForPosPrePayCancel(WxCardInfo cardInfo, WxCardSpend record) throws MallinkException; | |||
| WxCardSpend cardSpendForPosPay(PromotionCalc scoreCreditCalc, WxCardSpend record, WxMerchant merchant, WxMerchantBUser buUser) throws MallinkException; | |||
| WxCardSpend cardSpendForPosPay(PromotionCalc scoreCreditCalc, WxCardSpend record, WxMerchant merchant, WxMerchantBUser buUser,Integer payWay) throws MallinkException; | |||
| } | |||
| @@ -6,6 +6,7 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.vo.*; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| @@ -87,7 +88,7 @@ public interface WxCouponOrderService { | |||
| * 核销分账 | |||
| * @param couponOrder | |||
| */ | |||
| void shareAfterVerify(WxCouponOrder couponOrder, Long merchantId); | |||
| void shareAfterVerify(WxCouponOrder couponOrder, Long merchantId,Integer payWay); | |||
| /** | |||
| * 核销后补贴 | |||
| @@ -203,11 +204,11 @@ public interface WxCouponOrderService { | |||
| /** | |||
| * B端-收银台-支持优惠券 | |||
| */ | |||
| JSONArray queryMicroPayCouponOrder(WxMerchantBUser user, WxCUser cUser, Integer price); | |||
| JSONArray queryMicroPayCouponOrder(WxMerchantBUser user, WxCUserBasicInfo cUser, Integer price); | |||
| WxPayOrder microPayPreVerify(WxOrder microOrder, WxCouponOrder couponOrder, WxMerchantBUser bUser, Integer price); | |||
| WxPayOrder microPayPreVerify(WxOrder microOrder, WxCouponOrder couponOrder, WxMerchantBUser bUser, Integer price, EnumPayWay payWay); | |||
| Integer microPayVerify(WxMerchantBUser bUser, Long couponOrderId); | |||
| Integer microPayVerify(WxMerchantBUser bUser, Long couponOrderId,EnumPayWay payWay); | |||
| /** | |||
| * 尚安停车 | |||
| @@ -5,6 +5,7 @@ import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.po.WxCouponSend; | |||
| import com.iformall.domain.vo.WxCouponSendVo; | |||
| import com.iformall.enums.EnumCouponSendSendType; | |||
| import com.iformall.enums.EnumPayWay; | |||
| public interface WxCouponSendService { | |||
| @@ -52,7 +53,7 @@ public interface WxCouponSendService { | |||
| * @param cUserId | |||
| * @param type 2:停车发券 3:核销发券 | |||
| */ | |||
| boolean sendCouponToUser(EnumCouponSendSendType type, Object param); | |||
| boolean sendCouponToUser(EnumCouponSendSendType type, Object param,EnumPayWay payWay); | |||
| void updateStatusByCouponId(Long couponId, TenantEntity tenantEntity, int status); | |||
| @@ -95,7 +96,7 @@ public interface WxCouponSendService { | |||
| * | |||
| * @param wxCouponSend | |||
| */ | |||
| void handSel(WxCouponSend wxCouponSend,Long cUserId) ; | |||
| void handSel(WxCouponSend wxCouponSend,Long cUserId,EnumPayWay payWay) ; | |||
| } | |||
| @@ -1,20 +1,27 @@ | |||
| package com.iformall.service; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.OrderSaveDto; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxCouponOrder; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.domain.po.WxMerchantBUser; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.vo.WxCouponSendVo; | |||
| import com.iformall.domain.vo.WxOrderCouponPressVo; | |||
| import com.iformall.domain.vo.WxOrderCouponVo; | |||
| import com.iformall.domain.vo.WxOrderQueryVo; | |||
| import com.iformall.enums.EnumOrderStatus; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import com.iformall.enums.EnumPayWay; | |||
| public interface WxOrderService { | |||
| @@ -51,7 +58,7 @@ public interface WxOrderService { | |||
| * @param totalFeeStr | |||
| * @return 订单id | |||
| */ | |||
| WxOrder saveMicroPayOrder(WxMerchantBUser user, String totalFeeStr); | |||
| WxOrder saveMicroPayOrder(WxMerchantBUser user, String totalFeeStr,EnumPayWay payWay); | |||
| /** | |||
| * 付款码支付v2 | |||
| @@ -60,7 +67,7 @@ public interface WxOrderService { | |||
| * @param payment | |||
| * @return 订单id | |||
| */ | |||
| WxOrder saveMicroPayOrderV2(WxMerchantBUser user, WxCUser cUser, Integer payment); | |||
| WxOrder saveMicroPayOrderV2(WxMerchantBUser user, WxCUserBasicInfo cUser, Integer payment); | |||
| /** | |||
| * 商户码-储值卡支付 | |||
| @@ -70,7 +77,7 @@ public interface WxOrderService { | |||
| * @param payment | |||
| * @return 订单id | |||
| */ | |||
| WxOrder saveCardPayOrder(WxMerchant merchant, Long cUserId, String totalFeeStr, Integer payment); | |||
| WxOrder saveCardPayOrder(WxMerchant merchant, Long cUserId, String totalFeeStr, Integer payment,EnumPayWay payWay); | |||
| /** | |||
| * 免费券订单接口 | |||
| @@ -79,7 +86,7 @@ public interface WxOrderService { | |||
| * @param wxCouponSendVo 商户注券时必须指定 | |||
| * @return WxCouponOrder | |||
| */ | |||
| WxCouponOrder sendFreeCouponToUser(Long userId, Long couponId, WxCouponSendVo wxCouponSendVo); | |||
| WxCouponOrder sendFreeCouponToUser(Long userId, Long couponId, WxCouponSendVo wxCouponSendVo,EnumPayWay payWay); | |||
| /** | |||
| * orderSuccess 订单已支付 | |||
| @@ -157,7 +164,7 @@ public interface WxOrderService { | |||
| * @param orderId | |||
| * @param payOrderId | |||
| */ | |||
| void shareForMicroPay(TenantEntity tenantEntity, Long orderId, Long payOrderId); | |||
| void shareForMicroPay(TenantEntity tenantEntity, Long orderId, Long payOrderId,EnumPayWay payWay); | |||
| PageInfo<WxOrder> listOrderAsPage(WxOrderQueryVo wxOrder, Integer pageNum, Integer pageSize); | |||
| @@ -185,7 +192,7 @@ public interface WxOrderService { | |||
| * @param coupon | |||
| * @return | |||
| */ | |||
| WxOrder saveOrderForCoupon(WxCUser user, WxCoupon coupon, OrderSaveDto orderSaveDto, boolean isPress); | |||
| WxOrder saveOrderForCoupon(WxCUserBasicInfo user, WxCoupon coupon, OrderSaveDto orderSaveDto, boolean isPress,EnumPayWay payWay); | |||
| void sendOrderSuccessActionMsg(WxOrder updateOrder); | |||
| /** | |||
| @@ -194,9 +201,9 @@ public interface WxOrderService { | |||
| * @param coupon | |||
| * @return | |||
| */ | |||
| WxOrder getUnPaidOrder(WxCUser cUser, WxCoupon coupon); | |||
| WxOrder getUnPaidOrder(WxCUserBasicInfo cUser, WxCoupon coupon); | |||
| int countCouponConditionType1(WxCUser user); | |||
| int countCouponConditionType1(WxCUserBasicInfo user); | |||
| /** | |||
| * 订单处理 | |||
| * 1. 检查coupon是否免费 | |||
| @@ -204,10 +211,10 @@ public interface WxOrderService { | |||
| boolean checkCouponIsFree(WxCoupon coupon); | |||
| // 2. 创建免费订单, 领取 couponOrder | |||
| WxOrder saveFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId, Long couponPasswordId); | |||
| WxOrder saveFreeOrderForCoupon(WxCUserBasicInfo user, WxCoupon coupon, Long couponChannelId, String formId, Long couponPasswordId,EnumPayWay payWay); | |||
| // 3. 创建有价订单 | |||
| WxOrder saveNoFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, boolean isPress, Long orderGroupId, String formId); | |||
| WxOrder saveNoFreeOrderForCoupon(WxCUserBasicInfo user, WxCoupon coupon, Long couponChannelId, boolean isPress, Long orderGroupId, String formId); | |||
| /** | |||
| * 下订单成功后处理 | |||
| @@ -215,7 +222,7 @@ public interface WxOrderService { | |||
| * @param coupon | |||
| * @param user | |||
| */ | |||
| void actionAfterCouponOrderSuccess(WxOrder updateOrder, WxCoupon coupon, WxCUser user); | |||
| void actionAfterCouponOrderSuccess(WxOrder updateOrder, WxCoupon coupon, WxCUserBasicInfo user); | |||
| Map<String, Long> summary(WxOrderQueryVo wxOrderQueryVo); | |||
| @@ -225,7 +232,7 @@ public interface WxOrderService { | |||
| /** | |||
| * H5支付后, 券再注入 | |||
| */ | |||
| Long saveOuterOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId, Long couponPasswordId); | |||
| Long saveOuterOrderForCoupon(WxCUserBasicInfo user, WxCoupon coupon, Long couponChannelId, String formId, Long couponPasswordId); | |||
| int countGroupOrder(Long groupId,boolean ignoreUnPay); | |||
| @@ -6,17 +6,21 @@ import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxMerchantBUser; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.enums.EnumPayShare; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.service.pay.entity.PayExtraParam; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
| public interface WxPayOrderService { | |||
| public void handleSuccessOrder(WxPayOrder oldRecord,WxOrder order,Map<String, String> retMap,boolean isScheduleTask); | |||
| public void handleSuccessOrder(WxPayOrder oldRecord,WxOrder order,PayQueryAdapterResult queryResult,boolean isScheduleTask); | |||
| public WxPayOrder handleWxOrderQuery(WxPayOrder oldRecord,WxOrder order,WxAppinfo appInfo,WxPayAccount payAccount,IdWorker idworker,boolean repeatPay); | |||
| @@ -27,7 +31,7 @@ public interface WxPayOrderService { | |||
| * @param payWay | |||
| * @return | |||
| */ | |||
| ResultData createPayOrder(WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay); | |||
| ResultData createPayOrder(WxAppinfo appInfo, WxCUserBasicInfo user, WxPayOrder record, EnumPayWay payWay,PayExtraParam params); | |||
| /** | |||
| * 刷卡支付订单 | |||
| @@ -36,13 +40,13 @@ public interface WxPayOrderService { | |||
| * @param payWay | |||
| * @return | |||
| */ | |||
| ResultData createMicroPayOrder(WxMerchantBUser user, WxPayOrder record, EnumPayWay payWay); | |||
| ResultData createMicroPayOrder(WxMerchantBUser user, WxPayOrder record, EnumPayWay payWay,PayExtraParam params); | |||
| /** | |||
| * 微信支付订单查询 | |||
| * 支付订单查询 | |||
| * @param record 支付订单 | |||
| */ | |||
| ResultData payOrderQuery(WxMerchantBUser user, WxPayOrder record); | |||
| ResultData payOrderQuery(WxMerchantBUser user, WxPayOrder record,EnumPayWay payWay); | |||
| /** | |||
| * 微信支付关闭订单 | |||
| @@ -64,7 +68,7 @@ public interface WxPayOrderService { | |||
| * @param payWay 支付方式 | |||
| * @return | |||
| */ | |||
| String notify(Map<String, String> paramMap, EnumPayWay payWay); | |||
| String shareNotify(Map<String, String> paramMap, EnumPayWay payWay); | |||
| /** | |||
| * 支付成功处理 | |||
| @@ -73,22 +77,22 @@ public interface WxPayOrderService { | |||
| * @param transactionId | |||
| * @param from | |||
| */ | |||
| void handleOrderPaySuccess(WxPayOrder record, String transactionId, Integer from); | |||
| void handleOrderPaySuccess(WxPayOrder record, String transactionId); | |||
| /** | |||
| * 刷卡支付成功处理 | |||
| * | |||
| * @param Object 支付方API返回的对象 (查询或者支付 API返回的对象) | |||
| * @param record | |||
| * @param transactionId | |||
| */ | |||
| void handleMicroOrderPaySuccess(WxMerchantBUser user, WxPayOrder record, String transactionId, String openId, String isSubscribe); | |||
| void handleMicroOrderPaySuccess(Object result,String transcationId,EnumPayWay payWay,WxPayOrder record ,WxMerchantBUser user,WxAppinfo appInfo,PayExtraParam params); | |||
| /** | |||
| * 券支付成功处理 | |||
| * @param user | |||
| * @param record | |||
| */ | |||
| void handleMicroOrderPaySuccessForVerify(WxMerchantBUser user, WxPayOrder record); | |||
| void handleMicroOrderPaySuccessForVerify(WxMerchantBUser user, WxPayOrder record,EnumPayWay payWay); | |||
| /** | |||
| * 支付状态处理 | |||
| @@ -16,7 +16,7 @@ public interface WxProfitSharingOrderService { | |||
| /** | |||
| * 创建分账订单 | |||
| */ | |||
| ResultData createSharingOrder(WxSharingOrderDto wxSharingOrderDto); | |||
| ResultData createSharingOrder(WxSharingOrderDto wxSharingOrderDto,Integer payway); | |||
| /** | |||
| * 分账重试 | |||
| @@ -31,7 +31,7 @@ public interface WxProfitSharingOrderService { | |||
| /** | |||
| * 结束分账订单 | |||
| */ | |||
| ResultData finishSharingOrder(WxSharingOrderDto sharingOrderDto); | |||
| ResultData finishSharingOrder(WxSharingOrderDto sharingOrderDto,Integer payway); | |||
| PageInfo<WxProfitSharingOrderVo> listAsPage(WxProfitSharingOrderQueryVo order, Integer pageNum, Integer pageSize); | |||
| @@ -40,4 +40,6 @@ public interface WxProjectConfigService { | |||
| void initSubmall(String parentTenantId, String[] tenantIds); | |||
| void initAfterGroup(String tenantId, String tenantIds); | |||
| } | |||
| @@ -15,7 +15,7 @@ public interface WxSubsidyService { | |||
| * @param amountStr | |||
| * @return | |||
| */ | |||
| ResultData createSubsidy(MallUserInfo user, String ip, String amountStr); | |||
| //ResultData createSubsidy(MallUserInfo user, String ip, String amountStr); | |||
| /** | |||
| * 根据实体查询分页列表 | |||
| @@ -49,7 +49,7 @@ public interface WxSubsidyService { | |||
| */ | |||
| void deleteById(Long id); | |||
| String notify(Map<String, String> paramMap, EnumPayWay payWay); | |||
| //String notify(Map<String, String> paramMap, EnumPayWay payWay); | |||
| @@ -84,6 +84,9 @@ public class WxPayOrderServiceHelper { | |||
| }else { | |||
| String errCode = returnMap.get("err_code"); | |||
| String errCodeDes = returnMap.get("err_code_des"); | |||
| if (errCode.equalsIgnoreCase("ORDERNOTEXIST")) { | |||
| return EnumPayStatus.PAY_STATUS_ORDER_NOT_EXISTS.getCode(); | |||
| } | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "订单查询微信支付状态失败["+errCode+":"+errCodeDes+"]"+payOrderNo); | |||
| } | |||
| } else { | |||
| @@ -92,6 +95,39 @@ public class WxPayOrderServiceHelper { | |||
| } | |||
| } | |||
| public static String getPayStatusMsg(Map<String, String> returnMap,String payOrderNo) { | |||
| String return_code = returnMap.get("return_code"); | |||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||
| String result_code = returnMap.get("result_code"); | |||
| if ("SUCCESS".equals(result_code)) { | |||
| String trade_state = returnMap.get("trade_state"); | |||
| if ("SUCCESS".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_SUCCESS.getMessage(); | |||
| }else if ("REFUND".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_REFUND.getMessage(); | |||
| }else if ("NOTPAY".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_NOTPAY.getMessage(); | |||
| }else if ("CLOSED".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_CLOSE.getMessage(); | |||
| }else if ("REVOKED".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_REVERSE.getMessage(); | |||
| }else if ("USERPAYING".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_WAIT.getMessage(); | |||
| }else if ("PAYERROR".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_FAIL.getMessage(); | |||
| } | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "订单查询微信支付状态非法["+trade_state+"]"+payOrderNo); | |||
| }else { | |||
| String errCode = returnMap.get("err_code"); | |||
| String errCodeDes = returnMap.get("err_code_des"); | |||
| return errCodeDes; | |||
| } | |||
| } else { | |||
| String return_msg = returnMap.get("return_msg"); | |||
| return return_msg; | |||
| } | |||
| } | |||
| public static int wxOrderPayStatus(WxPayOrder record,WxOrder order,WxAppinfo appInfo,WxPayAccount payAccount) { | |||
| Map<String, String> returnMap = wxOrderPayStatusMap(record,order,appInfo,payAccount); | |||
| return getPayStatusFromMap(returnMap,record.getPayOrderNo()); | |||
| @@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.MemCouponFromDsp; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumCouponDspStatus; | |||
| @@ -12,6 +13,7 @@ import com.iformall.enums.EnumUserType; | |||
| import com.iformall.mapper.MemCouponFromDspMapper; | |||
| import com.iformall.mapper.WxCouponMapper; | |||
| import com.iformall.service.MemCouponFromDspService; | |||
| import com.iformall.service.WxCUserBasicInfoService; | |||
| import com.iformall.service.WxCUserService; | |||
| import com.iformall.service.WxOrderService; | |||
| import org.slf4j.Logger; | |||
| @@ -37,6 +39,8 @@ public class MemCouponFromDspServiceImpl implements MemCouponFromDspService { | |||
| private WxOrderService wxOrderService; | |||
| @Autowired | |||
| private WxCUserService wxCUserService; | |||
| @Autowired | |||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| @Override | |||
| @@ -81,11 +85,9 @@ public class MemCouponFromDspServiceImpl implements MemCouponFromDspService { | |||
| @Override | |||
| public Integer couponOrder(MemCouponFromDsp record) { | |||
| // 获取C端用户 | |||
| WxCUser user = wxCUserService.getByObject(new WxCUser() {{ | |||
| updateTenantInfo(record); | |||
| setPhone(record.getPhone()); | |||
| }}); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoService.findInfoByPhone(record, record.getPhone()); | |||
| if (user == null) { | |||
| return -1; | |||
| } | |||
| @@ -8,10 +8,7 @@ import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxActivity; | |||
| import com.iformall.domain.po.WxActivityJoin; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCreditHistory; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.msg.WxMsgRecord; | |||
| import com.iformall.domain.vo.WxActivityJoinQuestionAnswer; | |||
| import com.iformall.enums.*; | |||
| @@ -175,7 +172,7 @@ public class WxActivityJoinServiceImpl implements WxActivityJoinService { | |||
| if (count > 0) { | |||
| return new ResultData(ErrorCode.ACTIVITY_JOINED); | |||
| } | |||
| WxCUser user = wxCUserMapper.selectById(wxActivityJoin.getUserId()); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectById(wxActivityJoin.getUserId()); | |||
| //查询是否消耗积分 | |||
| WxActivity wxActivity = wxActivityMapper.selectById(wxActivityJoin.getActivityId()); | |||
| Date date = new Date(); | |||
| @@ -187,7 +184,7 @@ public class WxActivityJoinServiceImpl implements WxActivityJoinService { | |||
| wxCreditHistory.setCUserId(wxActivityJoin.getUserId()); | |||
| wxCreditHistory.setCreditNum(credit); | |||
| wxCreditHistory.setCreditType(EnumScoreType.ACTIVITY_JOIN.getCode()); | |||
| wxCreditHistory.setOperatorType(EnumUserType.CUSER.getCode()); | |||
| wxCreditHistory.setOperatorType(EnumUserType.CUSERBASIC.getCode()); | |||
| wxCreditHistory.setOperatorId(wxActivityJoin.getUserId()); | |||
| wxCreditHistoryService.saveOrUpdate(wxCreditHistory); | |||
| } | |||
| @@ -568,12 +568,10 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| public WxCUserBasicInfo findInfoByPhone(TenantEntity tenantEntity, String phone) { | |||
| WxCUserBasicInfo basic = null; | |||
| WxCUserBasicInfo basicQ = new WxCUserBasicInfo(); | |||
| basicQ.updateTenantInfo(tenantEntity); | |||
| basicQ.undateFinalTenantId(tenantEntity); | |||
| basicQ.setPhone(phone); | |||
| List<WxCUserBasicInfo> basicInfos = wxCUserBasicInfoMapper.selectList(new QueryWrapper(basicQ)); | |||
| if (basicInfos.size() > 0) { | |||
| return basicInfos.get(0); | |||
| } | |||
| basic = wxCUserBasicInfoMapper.selectOne(new QueryWrapper(basicQ)); | |||
| return basic; | |||
| } | |||
| @@ -600,33 +598,33 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| @Override | |||
| public void updateObj(WxCUserBasicInfo record, WxCUser user) { | |||
| // 1. update c_user_tags | |||
| CUserTagNewIdVo userTagVo = new CUserTagNewIdVo(); | |||
| userTagVo.updateTenantInfo(record); | |||
| userTagVo.setUserId(record.getId()); | |||
| userTagVo.setNewUserId(user.getId()); | |||
| wxCUserTagsMapper.updateNewId(userTagVo); | |||
| // 2. update score history | |||
| WxScoreHistoryNewIdVo scoreHistoryNewIdVo = new WxScoreHistoryNewIdVo(); | |||
| scoreHistoryNewIdVo.updateTenantInfo(record); | |||
| scoreHistoryNewIdVo.setCUserId(record.getId()); | |||
| scoreHistoryNewIdVo.setNewUserId(user.getId()); | |||
| scoreHistoryMapper.updateNewId(scoreHistoryNewIdVo); | |||
| // 3. update credit history | |||
| WxCreditHistoryNewIdVo creditHistoryNewIdVo = new WxCreditHistoryNewIdVo(); | |||
| creditHistoryNewIdVo.updateTenantInfo(record); | |||
| creditHistoryNewIdVo.setCUserId(record.getId()); | |||
| creditHistoryNewIdVo.setNewUserId(user.getId()); | |||
| creditHistoryMapper.updateNewId(creditHistoryNewIdVo); | |||
| // 10. base info | |||
| CUserBaseVo userBaseVo = new CUserBaseVo(); | |||
| org.springframework.beans.BeanUtils.copyProperties(record, userBaseVo); | |||
| userBaseVo.setNewId(user.getId()); | |||
| //userBaseVo.setCredit(user.getCredit()); | |||
| userBaseVo.setPoins(user.getScore()); | |||
| wxCUserBasicInfoMapper.updateNewId(userBaseVo); | |||
| // CUserTagNewIdVo userTagVo = new CUserTagNewIdVo(); | |||
| // userTagVo.updateTenantInfo(record); | |||
| // userTagVo.setUserId(record.getId()); | |||
| // userTagVo.setNewUserId(user.getId()); | |||
| // wxCUserTagsMapper.updateNewId(userTagVo); | |||
| // | |||
| // // 2. update score history | |||
| // WxScoreHistoryNewIdVo scoreHistoryNewIdVo = new WxScoreHistoryNewIdVo(); | |||
| // scoreHistoryNewIdVo.updateTenantInfo(record); | |||
| // scoreHistoryNewIdVo.setCUserId(record.getId()); | |||
| // scoreHistoryNewIdVo.setNewUserId(user.getId()); | |||
| // scoreHistoryMapper.updateNewId(scoreHistoryNewIdVo); | |||
| // | |||
| // // 3. update credit history | |||
| // WxCreditHistoryNewIdVo creditHistoryNewIdVo = new WxCreditHistoryNewIdVo(); | |||
| // creditHistoryNewIdVo.updateTenantInfo(record); | |||
| // creditHistoryNewIdVo.setCUserId(record.getId()); | |||
| // creditHistoryNewIdVo.setNewUserId(user.getId()); | |||
| // creditHistoryMapper.updateNewId(creditHistoryNewIdVo); | |||
| // | |||
| // // 10. base info | |||
| // CUserBaseVo userBaseVo = new CUserBaseVo(); | |||
| // org.springframework.beans.BeanUtils.copyProperties(record, userBaseVo); | |||
| // userBaseVo.setNewId(user.getId()); | |||
| // //userBaseVo.setCredit(user.getCredit()); | |||
| // userBaseVo.setPoins(user.getScore()); | |||
| // wxCUserBasicInfoMapper.updateNewId(userBaseVo); | |||
| } | |||
| @Override | |||
| @@ -831,14 +829,16 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| } | |||
| } | |||
| WxCUserBasicInfo oldUserBase = null; | |||
| // WxCUserBasicInfo oldUserBase = null; | |||
| WxCUserBasicInfo userBaseQ = new WxCUserBasicInfo(); | |||
| userBaseQ.updateTenantInfo(mallUserInfo); | |||
| // userBaseQ.updateTenantInfo(mallUserInfo); | |||
| userBaseQ.undateFinalTenantId(mallUserInfo); | |||
| userBaseQ.setPhone(userBase.getPhone()); | |||
| List<WxCUserBasicInfo> userBList = wxCUserBasicInfoMapper.selectList(new QueryWrapper(userBaseQ)); | |||
| if (userBList.size() > 0) { | |||
| oldUserBase = userBList.get(0); | |||
| } | |||
| WxCUserBasicInfo oldUserBase = wxCUserBasicInfoMapper.selectOne(new QueryWrapper(userBaseQ)); | |||
| // List<WxCUserBasicInfo> userBList = wxCUserBasicInfoMapper.selectList(new QueryWrapper(userBaseQ)); | |||
| // if (userBList.size() > 0) { | |||
| // oldUserBase = userBList.get(0); | |||
| // } | |||
| if (oldUserBase != null) { | |||
| oldUserBase.setName(userBase.getName()); | |||
| @@ -871,6 +871,7 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| } | |||
| } | |||
| // update 昵称 | |||
| { | |||
| // check c_user 是否存在 | |||
| @@ -882,8 +883,12 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| WxCUser user = userList.get(0); | |||
| if (user != null) { | |||
| //覆盖积分 | |||
| if(credit != null) { | |||
| user.setCredit(credit); | |||
| // if(credit != null) { | |||
| // user.setCredit(credit); | |||
| // wxCUserMapper.updateById(user); | |||
| // } | |||
| if(user.getUserId() == null){ | |||
| user.setUserId(user.getId()); | |||
| wxCUserMapper.updateById(user); | |||
| } | |||
| bHaveCUser = true; | |||
| @@ -891,7 +896,7 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| if(oldUserBase != null) { | |||
| oldUserBase.setNickName(user.getNickName()); | |||
| } | |||
| userBase.setId(user.getId()); | |||
| userBase.setId(user.getUserId()); | |||
| userBase.setNickName(user.getNickName()); | |||
| } else { | |||
| userBase.setNickName(user.getNickName()); | |||
| @@ -1021,5 +1026,15 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| wxCUserBasicInfoMapper.updateById(wxCUserBasicInfo); | |||
| return new ResultData(); | |||
| } | |||
| @Override | |||
| public WxCUserBasicInfo getByObject(WxCUserBasicInfo wxCUserBasicInfo) { | |||
| try { | |||
| return wxCUserBasicInfoMapper.selectOne(new QueryWrapper(wxCUserBasicInfo)); | |||
| } catch (Exception e) { | |||
| logger.error("NOT found: " + e.getMessage()); | |||
| } | |||
| return null; | |||
| } | |||
| } | |||
| @@ -247,24 +247,22 @@ public class WxCUserServiceImpl implements WxCUserService { | |||
| } | |||
| // 积分 | |||
| try { | |||
| WxCreditHistory wxCreditHistory = addCredit(user, EnumScoreType.LOGIN); | |||
| logger.info("wxCreditHistory_id" + wxCreditHistory.getId()); | |||
| credit = wxCreditHistory.getCreditNum() == null ? 0 : wxCreditHistory.getCreditNum(); | |||
| credit = addCredit(user, EnumScoreType.LOGIN); | |||
| logger.info("user_id:" + user.getId() + " 登录新增积分:" + credit); | |||
| } catch (MallinkException e) { | |||
| logger.error("c_user 积分 " + e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error("c_user 积分 " + e.getMessage()); | |||
| } | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_LOGIN, user); | |||
| // 用户登陆后 更新最后一次活跃时间 | |||
| if (user.getId() != null) { | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(user.getId()); | |||
| if (user.getUserId() != null) { | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(user.getUserId()); | |||
| if (wxCUserBasicInfo != null) { | |||
| WxCUserBasicInfo basicInfo = new WxCUserBasicInfo(); | |||
| basicInfo.setId(user.getId()); | |||
| basicInfo.setActiveTime(new Date()); | |||
| basicInfo.setLoginCount(wxCUserBasicInfo.getLoginCount()+1); | |||
| wxCUserBasicInfoService.update(basicInfo); | |||
| } | |||
| WxCUser wxCUser = getById(user.getId()); | |||
| @@ -274,6 +272,7 @@ public class WxCUserServiceImpl implements WxCUserService { | |||
| cUser.setActiveTime(new Date()); | |||
| saveOrUpdate(cUser); | |||
| } | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_LOGIN, wxCUserBasicInfo); | |||
| } | |||
| // 用户从unionId来的,可能会有重复 | |||
| if(findByUnionId != null) { | |||
| @@ -297,18 +296,26 @@ public class WxCUserServiceImpl implements WxCUserService { | |||
| } | |||
| @Override | |||
| public WxCreditHistory addCredit(WxCUser user, EnumScoreType enumScoreType) { | |||
| public int addCredit(WxCUser user, EnumScoreType enumScoreType) { | |||
| if(user.getUserId() == null){ | |||
| return 0; | |||
| } | |||
| WxCreditHistory wxCreditHistory = new WxCreditHistory(); | |||
| wxCreditHistory.setCUserId(user.getId()); | |||
| wxCreditHistory.setCUserId(user.getUserId()); | |||
| wxCreditHistory.updateTenantInfo(user); | |||
| wxCreditHistory.setCreateDate(new Date()); | |||
| wxCreditHistory.setCreditType(enumScoreType.getCode()); | |||
| wxCreditHistory.setOperatorType(EnumUserType.CUSER.getCode()); | |||
| wxCreditHistory.setOperatorId(user.getId()); | |||
| wxCreditHistory.setOperatorType(EnumUserType.CUSERBASIC.getCode()); | |||
| wxCreditHistory.setOperatorId(user.getUserId()); | |||
| wxCreditHistory.setCreditNum(user.getCredit()); | |||
| wxCreditHistory.setCreditAmount(user.getCredit()); | |||
| WxCreditHistory record = wxCreditHistoryService.saveOrUpdate(wxCreditHistory); | |||
| user.setCredit(record.getCreditAmount()); | |||
| return record; | |||
| return record.getCreditAmount(); | |||
| } | |||
| @Override | |||
| public void updateUserId(WxCUser user) { | |||
| wxCUserMapper.updateUserId(user); | |||
| } | |||
| } | |||
| @@ -348,7 +348,7 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| } | |||
| private List<WxTags> assignTypeId14(WxCUserBasicInfo user, WxCUser param) | |||
| private List<WxTags> assignTypeId14(WxCUserBasicInfo user) | |||
| { | |||
| List<WxTags> resList = null; | |||
| Calendar endC = Calendar.getInstance(); | |||
| @@ -357,13 +357,13 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| startC.setTime(new Date()); | |||
| startC.add(Calendar.DAY_OF_YEAR, -30); | |||
| WxCouponOrder wxCouponOrder = new WxCouponOrder(); | |||
| wxCouponOrder.setCUserId(param.getId()); | |||
| wxCouponOrder.setCUserId(user.getId()); | |||
| wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); | |||
| wxCouponOrder.setStartTime(startC.getTime()); | |||
| wxCouponOrder.setEndTime(endC.getTime()); | |||
| WxCardSpend wxCardSpend = new WxCardSpend(); | |||
| wxCardSpend.setOwnerId(param.getId()); | |||
| wxCardSpend.setOwnerId(user.getId()); | |||
| wxCardSpend.setStartdate(startC.getTime()); | |||
| wxCardSpend.setEnddate(endC.getTime()); | |||
| @@ -413,7 +413,7 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| return resList; | |||
| } | |||
| private List<WxTags> assignTypeId17(WxCUserBasicInfo user, WxCUser param) | |||
| private List<WxTags> assignTypeId17(WxCUserBasicInfo user) | |||
| { | |||
| List<WxTags> resList = null; | |||
| Calendar endC = Calendar.getInstance(); | |||
| @@ -422,14 +422,14 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| startC.setTime(new Date()); | |||
| startC.add(Calendar.DAY_OF_YEAR, -30); | |||
| WxCouponOrder wxCouponOrder = new WxCouponOrder(); | |||
| wxCouponOrder.setCUserId(param.getId()); | |||
| wxCouponOrder.setCUserId(user.getId()); | |||
| wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); | |||
| wxCouponOrder.setStartTime(startC.getTime()); | |||
| wxCouponOrder.setEndTime(endC.getTime()); | |||
| wxCouponOrder.setBusinessId(EnumBusiness.BUSINESS_ID1.getCode()); | |||
| WxCardSpend wxCardSpend = new WxCardSpend(); | |||
| wxCardSpend.setOwnerId(param.getId()); | |||
| wxCardSpend.setOwnerId(user.getId()); | |||
| wxCardSpend.setStartdate(startC.getTime()); | |||
| wxCardSpend.setEnddate(endC.getTime()); | |||
| wxCardSpend.setBusinessId(EnumBusiness.BUSINESS_ID1.getCode()); | |||
| @@ -480,7 +480,7 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| return resList; | |||
| } | |||
| private List<WxTags> assignTypeId18(WxCUserBasicInfo user, WxCUser param) { | |||
| private List<WxTags> assignTypeId18(WxCUserBasicInfo user) { | |||
| List<WxTags> resList = null; | |||
| final int WORK_DAY = 0; | |||
| @@ -500,13 +500,13 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| startC.add(Calendar.DAY_OF_YEAR, -30); | |||
| WxCouponOrder wxCouponOrder = new WxCouponOrder(); | |||
| wxCouponOrder.setCUserId(param.getId()); | |||
| wxCouponOrder.setCUserId(user.getId()); | |||
| wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); | |||
| wxCouponOrder.setStartTime(startC.getTime()); | |||
| wxCouponOrder.setEndTime(endC.getTime()); | |||
| WxCardSpend wxCardSpend = new WxCardSpend(); | |||
| wxCardSpend.setOwnerId(param.getId()); | |||
| wxCardSpend.setOwnerId(user.getId()); | |||
| wxCardSpend.setStartdate(startC.getTime()); | |||
| wxCardSpend.setEnddate(endC.getTime()); | |||
| @@ -549,14 +549,14 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| return resList; | |||
| } | |||
| private List<WxTags> assignTypeId21(WxCUserBasicInfo user, WxCUser param) { | |||
| private List<WxTags> assignTypeId21(WxCUserBasicInfo user) { | |||
| List<WxTags> resList = null; | |||
| Calendar startC = Calendar.getInstance(); | |||
| startC.setTime(new Date()); | |||
| startC.add(Calendar.DAY_OF_YEAR, -30); | |||
| WxCouponOrder wxCouponOrder = new WxCouponOrder(); | |||
| wxCouponOrder.setCUserId(param.getId()); | |||
| wxCouponOrder.setCUserId(user.getId()); | |||
| wxCouponOrder.setStartTime(startC.getTime()); | |||
| wxCouponOrder.setEndTime(new Date()); | |||
| @@ -573,11 +573,11 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| return resList; | |||
| } | |||
| private List<WxTags> assignTypeId22(WxCUserBasicInfo user, WxCUser param) { | |||
| private List<WxTags> assignTypeId22(WxCUserBasicInfo user) { | |||
| List<WxTags> resList = null; | |||
| int days = (int) ((new Date().getTime() - param.getCreateDate().getTime()) / (1000*3600*24)); | |||
| int days = (int) ((new Date().getTime() - user.getCreateDate().getTime()) / (1000*3600*24)); | |||
| float loginRate = (float)param.getLoginCount()/days; | |||
| float loginRate = (float)user.getLoginCount()/days; | |||
| if (loginRate > 1F/4) | |||
| resList = assign(user, EnumTag.ID_112); | |||
| else if (loginRate > 1F/7) | |||
| @@ -646,7 +646,7 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| break; | |||
| case ASSIGN_TAGS_TRIGGER_PHONE: { | |||
| WxCUser param = (WxCUser) obj; | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectById(param.getId()); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectById(param.getUserId()); | |||
| if (user != null) { | |||
| if (param.getPhone() != null) { | |||
| //来源 | |||
| @@ -658,17 +658,16 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| } | |||
| break; | |||
| case ASSIGN_TAGS_TRIGGER_BUY:{ | |||
| WxCUser param = (WxCUser) obj; | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectById(param.getId()); | |||
| WxCUserBasicInfo user = (WxCUserBasicInfo) obj; | |||
| if (user != null) { | |||
| //消费类别 | |||
| resList = assignTypeId14(user, param); | |||
| resList = assignTypeId14(user); | |||
| //饮食偏好 | |||
| resList = assignTypeId17(user, param); | |||
| resList = assignTypeId17(user); | |||
| //消费时段 | |||
| resList = assignTypeId18(user, param); | |||
| resList = assignTypeId18(user); | |||
| //消费频度 | |||
| resList = assignTypeId22(user, param); | |||
| resList = assignTypeId22(user); | |||
| } | |||
| } | |||
| break; | |||
| @@ -677,7 +676,7 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| case ASSIGN_TAGS_TRIGGER_LOGIN: { | |||
| WxCUser param = (WxCUser) obj; | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectById(param.getId()); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectById(param.getUserId()); | |||
| if (user != null) { | |||
| if (param.getGender() != null) { | |||
| //性别 | |||
| @@ -694,13 +693,12 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| resList = assignTypeId7(user, param.getPhone()); | |||
| } | |||
| //活跃 | |||
| resList = assignTypeId21(user, param); | |||
| resList = assignTypeId21(user); | |||
| } | |||
| } | |||
| break; | |||
| case ASSIGN_TAGS_TRIGGER_SCAN: { | |||
| WxCUserBasicInfo user = (WxCUserBasicInfo) obj; | |||
| WxCUser param = wxCUserMapper.selectById(user.getId()); | |||
| if (user != null) { | |||
| if (user.getSex() != null) { | |||
| @@ -724,25 +722,23 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| resList = assignTypeId6(user, user.getEducation()); | |||
| } | |||
| if (param != null) { | |||
| //消费类别 | |||
| resList = assignTypeId14(user, param); | |||
| //饮食偏好 | |||
| resList = assignTypeId17(user, param); | |||
| //消费时段 | |||
| resList = assignTypeId18(user, param); | |||
| //消费频度 | |||
| resList = assignTypeId22(user, param); | |||
| //活跃 | |||
| resList = assignTypeId21(user, param); | |||
| //车 | |||
| WxCUserCar wxCUserCar = new WxCUserCar(); | |||
| wxCUserCar.setCUserId(param.getId()); | |||
| if (wxCUserCarMapper.countList(wxCUserCar) > 0) { | |||
| resList = assignTypeId11(user); | |||
| } | |||
| //消费类别 | |||
| resList = assignTypeId14(user); | |||
| //饮食偏好 | |||
| resList = assignTypeId17(user); | |||
| //消费时段 | |||
| resList = assignTypeId18(user); | |||
| //消费频度 | |||
| resList = assignTypeId22(user); | |||
| //活跃 | |||
| resList = assignTypeId21(user); | |||
| //车 | |||
| WxCUserCar wxCUserCar = new WxCUserCar(); | |||
| wxCUserCar.setCUserId(user.getId()); | |||
| if (wxCUserCarMapper.countList(wxCUserCar) > 0) { | |||
| resList = assignTypeId11(user); | |||
| } | |||
| } | |||
| } | |||
| @@ -92,7 +92,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCouponMerchant couponMerchant) { | |||
| public ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCouponMerchant couponMerchant,EnumPayWay payWay) { | |||
| Date curDate = new Date(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| // 1. get card info | |||
| @@ -250,7 +250,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| if (cardInfo.getSaleAmount() > 0) { | |||
| // 9. 只有有价卡才能分账 | |||
| try { | |||
| shareForCardPay(record, record.getCardId(), record.getOrderId(), record.getId()); | |||
| shareForCardPay(record, record.getCardId(), record.getOrderId(), record.getId(),payWay.getCode()); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| if (ErrorCode.PROFIT_SHARING_NUM_UP_LIMIT.getCode() == e.getErrorCode() || | |||
| @@ -291,7 +291,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| try { | |||
| //-------此处为【现金支付】记录增加积分操作------- | |||
| WxCreditHistory creditHistory = new WxCreditHistory(); | |||
| creditHistory.setOperatorType(EnumUserType.CUSER.getCode()); | |||
| creditHistory.setOperatorType(EnumUserType.CUSERBASIC.getCode()); | |||
| creditHistory.setOperatorId(record.getOwnerId()); | |||
| creditHistory.setCUserId(record.getOwnerId()); | |||
| creditHistory.setCreateDate(new Date()); | |||
| @@ -435,7 +435,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| shareOrder.updateTenantInfo(wxCardInfo); | |||
| shareOrder.setMerchantId(0L); // 卡完结,默认给0 | |||
| shareOrder.setTransactionId(cardInfo.getTransactionId()); | |||
| cardShareFinished(cardInfo, shareOrder); | |||
| cardShareFinished(cardInfo, shareOrder,couponOrder.getPayVendor()); | |||
| } catch (MallinkException e) { | |||
| logger.error("微信分账: " + e.getMessage()); | |||
| throw new MallinkException(e.getErrorCode(), e.getMessage()); | |||
| @@ -454,7 +454,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void shareForCardPay(TenantEntity tenantEntity, Long cardId, Long orderId, Long cardSpendId) { | |||
| public void shareForCardPay(TenantEntity tenantEntity, Long cardId, Long orderId, Long cardSpendId,Integer payWay) { | |||
| // 微信已分账检查次数 | |||
| int psNum = 0; | |||
| try { | |||
| @@ -508,7 +508,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| shareOrder.updateTenantInfo(tenantEntity); | |||
| shareOrder.setTransactionId(cardInfo.getTransactionId()); | |||
| shareOrder.setShareAmount(cardSpend.getRealPayment()); | |||
| ResultData resultData = profitSharingOrderService.createSharingOrder(shareOrder); | |||
| ResultData resultData = profitSharingOrderService.createSharingOrder(shareOrder,payWay); | |||
| if (resultData.code != Result.SUCCESS) { | |||
| // 分账异常 | |||
| logger.error(resultData.message); | |||
| @@ -531,7 +531,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| if (cardSpend.getCardRemainRealAmount() > 0) { | |||
| // 卡已被抵扣,但是分账还有余额 | |||
| shareOrder.setMerchantId(0L); // 卡完结,填0 | |||
| cardShareFinished(cardInfo, shareOrder); | |||
| cardShareFinished(cardInfo, shareOrder,couponOrder.getPayVendor()); | |||
| } | |||
| } | |||
| } else { | |||
| @@ -550,7 +550,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| * @param cardInfo | |||
| * @param shareOrder | |||
| */ | |||
| private void cardShareFinished(WxCardInfo cardInfo, WxSharingOrderDto shareOrder) { | |||
| private void cardShareFinished(WxCardInfo cardInfo, WxSharingOrderDto shareOrder,Integer payWay) { | |||
| Date curDate = new Date(); | |||
| // card spend 添加一条 记录] | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| @@ -597,7 +597,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| shareOrder.setShareAmount(cardInfo.getRemainingShareFeeAmount()); | |||
| } | |||
| shareOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI_FINISH.getCode()); | |||
| profitSharingOrderService.finishSharingOrder(shareOrder); | |||
| profitSharingOrderService.finishSharingOrder(shareOrder,payWay); | |||
| } | |||
| @Override | |||
| @@ -780,7 +780,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public WxCardSpend cardSpendForPosPay(PromotionCalc scoreCreditCalc, WxCardSpend record, WxMerchant merchant, WxMerchantBUser buUser) throws MallinkException { | |||
| public WxCardSpend cardSpendForPosPay(PromotionCalc scoreCreditCalc, WxCardSpend record, WxMerchant merchant, WxMerchantBUser buUser,Integer payWay) throws MallinkException { | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| Date curDate = new Date(); | |||
| // 1. update card_spend | |||
| @@ -871,7 +871,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| // 9. 分账 | |||
| try { | |||
| shareForCardPay(record, record.getCardId(), record.getOrderId(), record.getId()); | |||
| shareForCardPay(record, record.getCardId(), record.getOrderId(), record.getId(),payWay); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| if (ErrorCode.PROFIT_SHARING_NUM_UP_LIMIT.getCode() == e.getErrorCode() || | |||
| @@ -167,7 +167,7 @@ public class WxCouponInjectServiceImpl implements WxCouponInjectService { | |||
| couponInjectMapper.insert(record); | |||
| if(record.getSendType().equals(EnumCouponInjectSendType.IMMEDIATE.getCode())) { | |||
| List<WxCUser> sentUsers = sendCoupon(wxCoupon, userList, record); | |||
| List<WxCUserBasicInfo> sentUsers = sendCoupon(wxCoupon, userList, record); | |||
| if (sentUsers.size() > 0) { | |||
| record.setStatus(EnumCouponInjectStatus.HAS_SENT.getCode()); | |||
| //发送短信 | |||
| @@ -182,7 +182,7 @@ public class WxCouponInjectServiceImpl implements WxCouponInjectService { | |||
| return new ResultData(); | |||
| } | |||
| private ResultData sendMsg(WxCouponInject record, List<WxCUser> cUsers) { | |||
| private ResultData sendMsg(WxCouponInject record, List<WxCUserBasicInfo> cUsers) { | |||
| //根据模板ID查询短信信息 | |||
| WxMsgModel model = wxMsgModelService.getById(record.getModelId()); | |||
| @@ -214,7 +214,7 @@ public class WxCouponInjectServiceImpl implements WxCouponInjectService { | |||
| return new ResultData(ErrorCode.MSG_NO_VALID_PHONE); | |||
| } | |||
| StringBuilder sb=new StringBuilder(); | |||
| for(WxCUser user:cUsers){ | |||
| for(WxCUserBasicInfo user:cUsers){ | |||
| String phone = user.getPhone(); | |||
| if(null!=phone && !phone.equals("")){ | |||
| sb.append(phone).append(","); | |||
| @@ -244,16 +244,15 @@ public class WxCouponInjectServiceImpl implements WxCouponInjectService { | |||
| return new ResultData(); | |||
| } | |||
| private List<WxCUser> sendCoupon(WxCoupon wxCoupon,List<WxCUserBasicInfo> cUsers,WxCouponInject record){ | |||
| private List<WxCUserBasicInfo> sendCoupon(WxCoupon wxCoupon,List<WxCUserBasicInfo> cUsers,WxCouponInject record){ | |||
| //查询标签用户 | |||
| List<WxCUser> sentUsers = new ArrayList<WxCUser>(); | |||
| List<WxCUserBasicInfo> sentUsers = new ArrayList<WxCUserBasicInfo>(); | |||
| for (WxCUserBasicInfo tempCUserBasicInfo : cUsers) { | |||
| WxCUser tempCUser = wxCUserService.getById(tempCUserBasicInfo.getId()); | |||
| if (tempCUser != null) { | |||
| boolean bResult = sendCouponToUser(tempCUser, wxCoupon, record.getId()); | |||
| if (tempCUserBasicInfo != null) { | |||
| boolean bResult = sendCouponToUser(tempCUserBasicInfo, wxCoupon, record.getId()); | |||
| if (bResult) { | |||
| sentUsers.add(tempCUser); | |||
| sentUsers.add(tempCUserBasicInfo); | |||
| } | |||
| } | |||
| } | |||
| @@ -261,7 +260,7 @@ public class WxCouponInjectServiceImpl implements WxCouponInjectService { | |||
| } | |||
| private boolean sendCouponToUser(WxCUser tempCUser,WxCoupon wxCoupon,Long couponInjectId) { | |||
| private boolean sendCouponToUser(WxCUserBasicInfo tempCUser,WxCoupon wxCoupon,Long couponInjectId) { | |||
| boolean checkLimit = false; | |||
| // 检查疲劳度 | |||
| try { | |||
| @@ -275,7 +274,7 @@ public class WxCouponInjectServiceImpl implements WxCouponInjectService { | |||
| // 发放免费券 | |||
| WxCouponOrder couponOrder = null; | |||
| try { | |||
| couponOrder = wxOrderService.sendFreeCouponToUser(tempCUser.getId(), wxCoupon.getId(),null); | |||
| couponOrder = wxOrderService.sendFreeCouponToUser(tempCUser.getId(), wxCoupon.getId(),null,EnumPayWay.PAY_WAY_NOT_UNPAY_BATCH_SEND); | |||
| if (couponOrder != null) { | |||
| wxCouponActionLogService.addOne(couponOrder, wxCoupon.getId(), couponOrder.getId(), EnumCouponSendSendType.INJECT.getCode(), couponInjectId); | |||
| } | |||
| @@ -25,6 +25,7 @@ import com.iformall.mapper.*; | |||
| import com.iformall.mq.MqBaseProducer; | |||
| import com.iformall.pay.WxPayConstant; | |||
| import com.iformall.service.*; | |||
| import com.iformall.service.pay.PayServiceFactory; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.PayUtils; | |||
| @@ -37,7 +38,6 @@ import org.springframework.data.redis.core.RedisTemplate; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Propagation; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import org.springframework.util.CollectionUtils; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| @@ -68,6 +68,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| @Autowired | |||
| WxCUserMapper wxCUserMapper; | |||
| @Autowired | |||
| WxCUserBasicInfoMapper wxCUserBasicInfoMapper; | |||
| @Autowired | |||
| WxOrderService wxOrderService; | |||
| @@ -131,6 +134,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| @Autowired | |||
| WxPayOrderMapper payOrderMapper; | |||
| @Autowired | |||
| PayServiceFactory payServiceFactory; | |||
| @Autowired | |||
| @Qualifier("couponDetailRedisTemplate") | |||
| @@ -425,7 +431,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| } | |||
| } | |||
| private void doAfterVerify(WxCouponOrder couponOrder, WxCoupon wxCoupon, WxCUser cuUser) { | |||
| private void doAfterVerify(WxCouponOrder couponOrder, WxCoupon wxCoupon, WxCUserBasicInfo cuUser) { | |||
| // 成长值 | |||
| try { | |||
| WxOrder order = wxOrderMapper.selectById(couponOrder.getOrderId()); | |||
| @@ -438,7 +444,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| try { | |||
| //-------此处为【现金支付】记录增加积分操作------- | |||
| WxCreditHistory creditHistory = new WxCreditHistory(); | |||
| creditHistory.setOperatorType(EnumUserType.CUSER.getCode()); | |||
| creditHistory.setOperatorType(EnumUserType.CUSERBASIC.getCode()); | |||
| creditHistory.setOperatorId(cuUser.getId()); | |||
| creditHistory.setCUserId(couponOrder.getcUserId()); | |||
| creditHistory.setCreateDate(new Date()); | |||
| @@ -482,7 +488,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| } else { | |||
| try { | |||
| // 核销分账 | |||
| shareAfterVerify(couponOrder, bUser.getMerchantId()); | |||
| shareAfterVerify(couponOrder, bUser.getMerchantId(),couponOrder.getPayVendor()); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| @@ -541,7 +547,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| merchantSubsidy.setRealPayment(couponOrder.getCouponPrice()); | |||
| merchantSubsidy.setSubsidy(couponOrder.getCouponPrice()); | |||
| merchantSubsidy.setRealSubsidy(couponOrder.getCouponPrice()); | |||
| merchantSubsidy.setType(EnumMerchantSubsidyType.WECHAT.getCode()); | |||
| merchantSubsidy.setType(payServiceFactory.getPayShareAdapterService(couponOrder.getPayVendor()).getSubsidyType()); | |||
| merchantSubsidy.setCreateDate(curDate); | |||
| merchantSubsidy.setUpdateDate(curDate); | |||
| merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode()); | |||
| @@ -550,7 +556,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void shareAfterVerify(WxCouponOrder couponOrder, Long merchantId) { | |||
| public void shareAfterVerify(WxCouponOrder couponOrder, Long merchantId,Integer payWay) { | |||
| // 微信分账 | |||
| try { | |||
| WxPayOrder wxPayOrder = new WxPayOrder(); | |||
| @@ -571,7 +577,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| wxSharingOrderDto.updateTenantInfo(wxPayOrder); | |||
| wxSharingOrderDto.setTransactionId(wxPayOrder.getTransactionId()); | |||
| wxSharingOrderDto.setShareAmount(wxPayOrder.getShareAmount()); | |||
| wxProfitSharingOrderService.createSharingOrder(wxSharingOrderDto); | |||
| wxProfitSharingOrderService.createSharingOrder(wxSharingOrderDto,payWay); | |||
| } | |||
| } catch (Exception e) { | |||
| logger.error("微信分账: " + e.getMessage()); | |||
| @@ -685,7 +691,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| WxOrder wxOrder = wxOrderMapper.selectById(couponOrder.getOrderId()); | |||
| if (wxOrder != null) { | |||
| try { | |||
| return wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.COUPON_VERIFY, wxOrder); | |||
| return wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.COUPON_VERIFY, wxOrder,EnumPayWay.PAY_WAY_NOT_UNPAY_VERRIFY); | |||
| } catch (Exception e) { | |||
| logger.error("核销发券: " + e.getMessage()); | |||
| } | |||
| @@ -699,7 +705,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| WxOrder wxOrder = wxOrderMapper.selectById(orderId); | |||
| if (wxOrder != null) { | |||
| try { | |||
| return wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.B_MICROPAY, wxOrder); | |||
| return wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.B_MICROPAY, wxOrder,EnumPayWay.PAY_WAY_NOT_UNPAY_B_MA); | |||
| } catch (Exception e) { | |||
| logger.error("B端刷卡支付发券: " + e.getMessage()); | |||
| } | |||
| @@ -732,8 +738,16 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| logger.error("找不到商户信息"); | |||
| throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); | |||
| } | |||
| // 4. get user info | |||
| WxCUser user = wxCUserMapper.selectById(order.getCUserId()); | |||
| WxCUser user = null; | |||
| List<WxCUser> list = wxCUserMapper.findList(new WxCUser(){{ | |||
| updateTenantInfo(bUser); | |||
| setUserId(couponOrder.getCUserId()); | |||
| }}); | |||
| if(list != null && list.size() > 0){ | |||
| user = list.get(0); | |||
| } | |||
| if (user == null) { | |||
| logger.error("找不到C端用户"); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||
| @@ -991,8 +1005,8 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| @Override | |||
| public ResultData cardDetailCUserVo(Long ownerId, String couponOrderId) { | |||
| WxCUser wxCuser = wxCUserMapper.selectById(ownerId); | |||
| if (wxCuser == null) { | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectById(ownerId); | |||
| if (wxCUserBasicInfo == null) { | |||
| logger.error("用户不存在:" + ownerId); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| @@ -1021,8 +1035,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| } | |||
| //转赠人是否存在 | |||
| Long cUserId = record.getCUserId(); | |||
| WxCUser wxCuser = wxCUserMapper.selectById(cUserId); | |||
| if (wxCuser == null) { | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectById(cUserId); | |||
| if (wxCUserBasicInfo == null) { | |||
| logger.info("转赠人不存在:" + cUserId); | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY.getCode(), "转赠人不存在"); | |||
| } | |||
| @@ -1074,8 +1089,8 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| } | |||
| //转赠人是否存在 | |||
| Long cUserId = record.getCUserId(); | |||
| WxCUser wxCuser = wxCUserMapper.selectById(cUserId); | |||
| if (wxCuser == null) { | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectById(cUserId); | |||
| if (wxCUserBasicInfo == null) { | |||
| logger.info("转赠人不存在:" + cUserId); | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY.getCode(), "转赠人不存在"); | |||
| } | |||
| @@ -1121,7 +1136,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| } | |||
| @Override | |||
| public JSONArray queryMicroPayCouponOrder(WxMerchantBUser user, WxCUser cUser, Integer payPrice) { | |||
| public JSONArray queryMicroPayCouponOrder(WxMerchantBUser user, WxCUserBasicInfo cUser, Integer payPrice) { | |||
| // 1. 是否有核销未完成的券 | |||
| Map<String, Object> coQ = new HashMap<>(); | |||
| @@ -1229,7 +1244,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public WxPayOrder microPayPreVerify(WxOrder microOrder, WxCouponOrder couponOrder, WxMerchantBUser bUser, Integer payPrice) { | |||
| public WxPayOrder microPayPreVerify(WxOrder microOrder, WxCouponOrder couponOrder, WxMerchantBUser bUser, Integer payPrice, EnumPayWay payWay) { | |||
| // 1. 获取券信息 | |||
| WxCoupon wxCoupon = wxCouponMapper.selectById(couponOrder.getCouponId()); | |||
| if (wxCoupon == null) { | |||
| @@ -1358,7 +1373,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| } else { | |||
| setPayAmount(microOrder.getPayment()); | |||
| } | |||
| setPayVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||
| setPayVendor(payWay.getCode()); | |||
| setPayOrderStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); | |||
| setShare(EnumPayShare.NO.getCode()); | |||
| setPayFrom(EnumPayFrom.INSIDE_B.getCode()); | |||
| @@ -1376,12 +1391,13 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public Integer microPayVerify(WxMerchantBUser bUser, Long couponOrderId) { | |||
| public Integer microPayVerify(WxMerchantBUser bUser, Long couponOrderId,EnumPayWay payWay) { | |||
| WxCouponOrder updateCouponOrder = new WxCouponOrder(); | |||
| updateCouponOrder.setId(couponOrderId); | |||
| updateCouponOrder.setBUserId(bUser.getId()); | |||
| updateCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); | |||
| updateCouponOrder.setUpdateDate(new Date()); | |||
| updateCouponOrder.setPayVendor(payWay.getCode()); | |||
| // 核销状态更新 | |||
| int num = wxCouponOrderMapper.updateById(updateCouponOrder); | |||
| if (num == 1) { | |||
| @@ -1403,9 +1419,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| int num = wxCouponOrderMapper.updateById(updateCouponOrder); | |||
| if (num == 1) { | |||
| WxCouponOrder couponOrder = wxCouponOrderMapper.selectById(couponOrderId); | |||
| WxCUser cuUser = wxCUserMapper.selectById(couponOrder.getcUserId()); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectById(couponOrder.getcUserId()); | |||
| WxCoupon coupon = wxCouponMapper.selectById(couponOrder.getCouponId()); | |||
| doAfterVerify(couponOrder, coupon, cuUser); | |||
| doAfterVerify(couponOrder, coupon, wxCUserBasicInfo); | |||
| } | |||
| return 0; | |||
| } | |||
| @@ -287,7 +287,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public boolean sendCouponToUser(EnumCouponSendSendType type, Object param) { | |||
| public boolean sendCouponToUser(EnumCouponSendSendType type, Object param,EnumPayWay payWay) { | |||
| TenantEntity tenantEntity; | |||
| Long cUserId; | |||
| @@ -369,21 +369,15 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| // 发放免费券 | |||
| WxCouponOrder couponOrder = null; | |||
| try { | |||
| couponOrder = wxOrderService.sendFreeCouponToUser(cUserId, send.getCouponId(), null); | |||
| couponOrder = wxOrderService.sendFreeCouponToUser(cUserId, send.getCouponId(), null,payWay); | |||
| if (couponOrder != null) { | |||
| bRet = true; | |||
| wxCouponActionLogService.addOne(couponOrder, send.getCouponId(), couponOrder.getId(), type.getCode(), send.getId()); | |||
| // 查找cUser | |||
| WxCUser user = wxCUserMapper.selectById(cUserId); | |||
| if (user == null) { | |||
| continue; | |||
| } | |||
| // 发送消息 | |||
| if (couponOrder != null) { | |||
| sendMsgForSendCoupon(couponOrder, send, couponOrder, user); | |||
| sendMsgForSendCoupon(couponOrder, send, couponOrder, wxCUserBasicInfo); | |||
| } | |||
| bRet = true; | |||
| @@ -398,9 +392,20 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| return bRet; | |||
| } | |||
| private void sendMsgForSendCoupon(TenantEntity tenantEntity, WxCouponSend send, WxCouponOrder couponOrder, WxCUser user) { | |||
| // 发送微信模板消息(公众号模板消息/小程序统一消息/小程序模板消息) | |||
| sendMpMsgForSendCoupon(send, couponOrder, user); | |||
| private void sendMsgForSendCoupon(TenantEntity tenantEntity, WxCouponSend send, WxCouponOrder couponOrder, WxCUserBasicInfo user) { | |||
| List<WxCUser> list = wxCUserMapper.findList(new WxCUser(){{ | |||
| updateTenantInfo(tenantEntity); | |||
| setUserId(couponOrder.getCUserId()); | |||
| }}); | |||
| if(list != null && list.size() > 0){ | |||
| WxCUser cuser = list.get(0); | |||
| if(cuser != null){ | |||
| // 发送微信模板消息(公众号模板消息/小程序统一消息/小程序模板消息) | |||
| sendMpMsgForSendCoupon(send, couponOrder, cuser); | |||
| } | |||
| } | |||
| // 发送短信 | |||
| if (send.getSendSms().equals(EnumCouponSendSms.YES.getCode())) { | |||
| @@ -491,7 +496,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| // 8. 微信小程序-统一消息 | |||
| // 检查是否超限 | |||
| WxMsgLimit msgLimit = new WxMsgLimit(); | |||
| msgLimit.updateTenantInfo(user); | |||
| msgLimit.updateTenantInfo(couponOrder); | |||
| msgLimit.setType(EnumMsgLimitType.WEAPP_OPENID_SEND.getCode()); | |||
| msgLimit.setLimitId(user.getOpenId()); | |||
| if (wxMsgLimitService.checkIsLimit(msgLimit)) { | |||
| @@ -501,7 +506,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| // 获取小程序关联的服务号 | |||
| WxAuthorizerInfo authQ = new WxAuthorizerInfo(); | |||
| authQ.setAuthorizerAppid(user.getAppId()); | |||
| authQ.updateTenantInfo(user); | |||
| authQ.updateTenantInfo(couponOrder); | |||
| WxAuthorizerInfo weappInfo = authorizerInfoMapper.findMp(authQ); | |||
| if (weappInfo != null) { | |||
| AppUniformMsg appUniformMsg = new AppUniformMsg(); | |||
| @@ -610,17 +615,9 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void handSel(WxCouponSend wxCouponSend, Long cUserId) { | |||
| WxCUser cu = wxCUserMapper.selectById(cUserId); | |||
| if (Objects.isNull(cu)) { | |||
| throw new MallinkException(ErrorCode.USER_NOT_AUTH_PHONE); | |||
| } | |||
| if(StringUtils.isEmpty(cu.getPhone())) { | |||
| throw new MallinkException(ErrorCode.USER_NOT_AUTH_PHONE); | |||
| } | |||
| public void handSel(WxCouponSend wxCouponSend, Long cUserId,EnumPayWay payWay) { | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectById(cu.getId()); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectById(cUserId); | |||
| if (Objects.isNull(wxCUserBasicInfo)) { | |||
| throw new MallinkException(ErrorCode.USER_NOT_AUTH_PHONE); | |||
| } | |||
| @@ -631,10 +628,10 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| } | |||
| couponSendList.forEach(cs -> { | |||
| // 发放免费券 | |||
| WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cu.getId(), cs.getCouponId(), cs); | |||
| WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cUserId, cs.getCouponId(), cs,payWay); | |||
| if (couponOrder != null) { | |||
| wxCouponActionLogService.addOne(couponOrder, cs.getCouponId(), couponOrder.getId(), cs.getSendType(), cs.getId()); | |||
| sendMsgForSendCoupon(couponOrder, cs, couponOrder, cu); | |||
| sendMsgForSendCoupon(couponOrder, cs, couponOrder, wxCUserBasicInfo); | |||
| } else { | |||
| logger.warn("handSel couponOrder is null"); | |||
| } | |||
| @@ -125,14 +125,15 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| List<Long> cUserBasicIds = wxCreditHistoryVoList.stream().filter(a -> a.getOperatorType().equals(EnumUserType.CUSERBASIC.getCode())).map(WxCreditHistoryVo::getOperatorId).collect(Collectors.toList()); | |||
| List<Long> bUserIds = wxCreditHistoryVoList.stream().filter(a -> a.getOperatorType().equals(EnumUserType.BUSER.getCode())).map(WxCreditHistoryVo::getOperatorId).collect(Collectors.toList()); | |||
| List<Long> mallUserIds = wxCreditHistoryVoList.stream().filter(a -> a.getOperatorType().equals(EnumUserType.MALLUSER.getCode())).map(WxCreditHistoryVo::getOperatorId).collect(Collectors.toList()); | |||
| List<WxCUser> wxCUserList = Lists.newArrayList(); | |||
| List<WxCUserBasicInfo> wxCUserList = Lists.newArrayList(); | |||
| List<WxCUserBasicInfo> wxCUserBasicInfoList = Lists.newArrayList(); | |||
| List<WxMerchantBUser> wxMerchantBUserList = Lists.newArrayList(); | |||
| List<MallUserInfo> mallUserInfoList = Lists.newArrayList(); | |||
| if (cUserIds != null && cUserIds.size() > 0) { | |||
| WxCUser wxUser = new WxCUser(); | |||
| wxUser.setIds(cUserIds); | |||
| wxCUserList = wxCUserMapper.findList(wxUser); | |||
| //兼容老数据 | |||
| WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo(); | |||
| wxCUserBasicInfo.setIds(cUserIds); | |||
| wxCUserList = wxCUserBasicInfoMapper.findList(wxCUserBasicInfo); | |||
| } | |||
| if (cUserBasicIds != null && cUserBasicIds.size() > 0) { | |||
| WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo(); | |||
| @@ -191,17 +192,15 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| @Override | |||
| public void creditUsercheck(Long cUserId) { | |||
| WxCUser wxCUser = wxCUserMapper.selectById(cUserId); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectById(cUserId); | |||
| UserUtil.creditUserCheck(wxCUser, wxCUserBasicInfo); | |||
| UserUtil.creditUserCheck(wxCUserBasicInfo); | |||
| } | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public WxCreditHistory saveOrUpdate(WxCreditHistory record) { | |||
| WxCUser wxCUser = wxCUserMapper.selectById(record.getCUserId()); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectById(record.getCUserId()); | |||
| if (wxCUser == null && wxCUserBasicInfo == null) { | |||
| if (wxCUserBasicInfo == null) { | |||
| //验证此用户是否存在 | |||
| throw new MallinkException(ErrorCode.USER_NOT_AUTH_PHONE); | |||
| } | |||
| @@ -214,9 +213,7 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| } | |||
| int currentCreditAmount = 0; | |||
| //获取当前用户总积分规则:优先获取wxCUser中数据 若不存在 再获取wxCUserBasicInfo表中数据 | |||
| if (wxCUser != null && wxCUser.getCredit() != null && wxCUser.getCredit() > 0) { | |||
| currentCreditAmount = wxCUser.getCredit(); | |||
| } else if (wxCUserBasicInfo != null && wxCUserBasicInfo.getCredit() != null && wxCUserBasicInfo.getCredit() > 0) { | |||
| if (wxCUserBasicInfo != null && wxCUserBasicInfo.getCredit() != null && wxCUserBasicInfo.getCredit() > 0) { | |||
| currentCreditAmount = wxCUserBasicInfo.getCredit(); | |||
| } | |||
| if (record.getCreditAmount() == null) { | |||
| @@ -230,7 +227,7 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| if (record.getCreditType().equals(EnumScoreType.CONSUMPTION.getCode()) || record.getCreditType().equals(EnumScoreType.SPEND_CREDIT.getCode())) { | |||
| //等级积分配置 | |||
| try { | |||
| creditChangeNum = CreditUtil.calUserCredit(creditChangeNumOrigin, wxCUser, wxCUserBasicInfo, wxScoreRulesService,wxLevelConfigMapper); | |||
| creditChangeNum = CreditUtil.calUserCredit(creditChangeNumOrigin, null, wxCUserBasicInfo, wxScoreRulesService,wxLevelConfigMapper); | |||
| if (Objects.nonNull(CreditUtil.getIsBirthDayScale())) { | |||
| hasBirthDateCredit = true; | |||
| } | |||
| @@ -259,13 +256,6 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| record.setId(idWorker.nextId()); | |||
| record.setCreateDate(new Date()); | |||
| wxCreditHistoryMapper.insert(record); | |||
| //将计算出来新的总积分 更新到两张用户表里 | |||
| if (wxCUser != null) { | |||
| WxCUser wxCUserNew = new WxCUser(); | |||
| wxCUserNew.setId(wxCUser.getId()); | |||
| wxCUserNew.setCredit(record.getCreditAmount()); | |||
| wxCUserMapper.updateById(wxCUserNew); | |||
| } | |||
| if (wxCUserBasicInfo != null) { | |||
| WxCUserBasicInfo wxCUserBasicInfoNew = new WxCUserBasicInfo(); | |||
| wxCUserBasicInfoNew.setId(wxCUserBasicInfo.getId()); | |||
| @@ -306,15 +296,7 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| return 0; | |||
| } | |||
| // 2. user | |||
| WxCUser wxCUser = wxCUserMapper.selectById(record.getCUserId()); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectById(record.getCUserId()); | |||
| if (wxCUser != null) { | |||
| WxCUser wxCUserNew = new WxCUser(); | |||
| wxCUserNew.setId(wxCUser.getId()); | |||
| wxCUserNew.setCredit(wxCUser.getCredit() - wxCreditHistory.getCreditNum()); | |||
| wxCUserNew.setUpdateDate(new Date()); | |||
| wxCUserMapper.updateById(wxCUserNew); | |||
| } | |||
| if (wxCUserBasicInfo != null) { | |||
| WxCUserBasicInfo wxCUserBasicInfoNew = new WxCUserBasicInfo(); | |||
| wxCUserBasicInfoNew.setId(wxCUserBasicInfo.getId()); | |||
| @@ -344,9 +326,8 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| wxCreditHistory.setSpend(new BigDecimal(spendStr).multiply(new BigDecimal(100)).intValue()); | |||
| credit = payAddCredit(wxCreditHistory); | |||
| if (Objects.nonNull(userId)) { | |||
| WxCUser wxCUser = wxCUserMapper.selectById(userId); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectById(userId); | |||
| creditNew = CreditUtil.calUserCredit(credit, wxCUser, wxCUserBasicInfo, wxScoreRulesService,wxLevelConfigMapper); | |||
| creditNew = CreditUtil.calUserCredit(credit, null, wxCUserBasicInfo, wxScoreRulesService,wxLevelConfigMapper); | |||
| } else { | |||
| creditNew = credit; | |||
| } | |||
| @@ -434,7 +415,7 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| return wxScoreRules.getRule(EnumScoreType.WECHAT_PHONE, WxScoreRules.SCORE); | |||
| } | |||
| private int checkCompleteInfoScoreCount(WxCUser cUser) { | |||
| private int checkCompleteInfoScoreCount(WxCUserBasicInfo cUser) { | |||
| WxCreditHistory wxCreditHistory = new WxCreditHistory(); | |||
| wxCreditHistory.updateTenantInfo(cUser); | |||
| wxCreditHistory.setCUserId(cUser.getId()); | |||
| @@ -443,7 +424,7 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| } | |||
| private int infoAddCredit(WxCreditHistory record) { | |||
| WxCUser user = wxCUserMapper.selectById(record.getCUserId()); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectById(record.getCUserId()); | |||
| if (user == null || checkCompleteInfoScoreCount(user) > 0) | |||
| return 0; | |||
| // 1. 获取score rules | |||
| @@ -47,6 +47,9 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { | |||
| @Autowired | |||
| WxCUserMapper wxCUserMapper; | |||
| @Autowired | |||
| WxCUserBasicInfoMapper wxCUserBasicInfoMapper; | |||
| @Autowired | |||
| WxCouponMapper wxCouponMapper; | |||
| @@ -303,16 +306,16 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { | |||
| o.getOrderStatus().equals(EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode()); | |||
| }).sorted(Comparator.comparing(order -> order.getId())).collect(Collectors.toList()); | |||
| if (!orderList.isEmpty()) { | |||
| List<WxCUser> userList = new ArrayList<>(); | |||
| List<WxCUserBasicInfo> userList = new ArrayList<>(); | |||
| for (WxOrder order : orderList) { | |||
| WxCUser user = wxCUserMapper.selectById(order.getCUserId()); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectById(order.getCUserId()); | |||
| if (user != null) { | |||
| userList.add(user); | |||
| } | |||
| } | |||
| if (!userList.isEmpty()) { | |||
| userList = userList.parallelStream().map(u -> { | |||
| WxCUser temp = new WxCUser(); | |||
| WxCUserBasicInfo temp = new WxCUserBasicInfo(); | |||
| temp.setId(u.getId()); | |||
| temp.setNickName(u.getNickName()); | |||
| temp.setAvatarUrl(u.getAvatarUrl()); | |||
| @@ -31,6 +31,7 @@ import org.springframework.stereotype.Service; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.Calendar; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.concurrent.TimeUnit; | |||
| @Service | |||
| @@ -161,7 +162,14 @@ public class WxOrderPressServiceImpl implements WxOrderPressService { | |||
| throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | |||
| } | |||
| // 3. get user info | |||
| WxCUser user = userMapper.selectById(order.getCUserId()); | |||
| WxCUser user = null; | |||
| List<WxCUser> list = userMapper.findList(new WxCUser(){{ | |||
| updateTenantInfo(order); | |||
| setUserId(order.getCUserId()); | |||
| }}); | |||
| if(list != null && list.size() > 0){ | |||
| user = list.get(0); | |||
| } | |||
| if (user == null) { | |||
| logger.error("找不到C端用户"); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||
| @@ -38,7 +38,7 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.OrderSaveDto; | |||
| import com.iformall.domain.dto.WxSharingOrderDto; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxCardInfo; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| @@ -89,6 +89,7 @@ import com.iformall.enums.EnumOrderType; | |||
| import com.iformall.enums.EnumPayShare; | |||
| import com.iformall.enums.EnumPayStatus; | |||
| import com.iformall.enums.EnumPayType; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.enums.EnumProfitSharingOrderType; | |||
| import com.iformall.enums.EnumScoreType; | |||
| import com.iformall.enums.EnumUserType; | |||
| @@ -363,7 +364,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * @param counpon | |||
| * @return | |||
| */ | |||
| private int getUserOrderGroupCount(WxCUser user, WxCoupon counpon) { | |||
| private int getUserOrderGroupCount(WxCUserBasicInfo user, WxCoupon counpon) { | |||
| // + Order 待支付 | |||
| try { | |||
| WxOrder orderQ = new WxOrder(); | |||
| @@ -388,7 +389,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * @param counpon | |||
| * @return | |||
| */ | |||
| private int getUserOrderCount(WxCUser user, WxCoupon counpon) { | |||
| private int getUserOrderCount(WxCUserBasicInfo user, WxCoupon counpon) { | |||
| // + Order 待支付 | |||
| try { | |||
| WxOrder orderQ = new WxOrder(); | |||
| @@ -417,7 +418,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * @param counpon | |||
| * @return | |||
| */ | |||
| public WxOrder getUnPaidOrder(WxCUser user, WxCoupon counpon) { | |||
| public WxOrder getUnPaidOrder(WxCUserBasicInfo user, WxCoupon counpon) { | |||
| // + Order 待支付 | |||
| try { | |||
| WxOrder orderQ = new WxOrder(); | |||
| @@ -448,7 +449,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * @param user | |||
| * @return | |||
| */ | |||
| public int countCouponConditionType1(WxCUser user) { | |||
| public int countCouponConditionType1(WxCUserBasicInfo user) { | |||
| // + Order 待支付 | |||
| try { | |||
| WxOrder orderQ = new WxOrder(); | |||
| @@ -480,7 +481,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * @param counpon | |||
| * @return | |||
| */ | |||
| private int getUserCouponOrderCount(WxCUser user, WxCoupon counpon) { | |||
| private int getUserCouponOrderCount(WxCUserBasicInfo user, WxCoupon counpon) { | |||
| // + couponOrder ---待使用 | |||
| try { | |||
| WxCouponOrder couponOrderQ = new WxCouponOrder(); | |||
| @@ -506,7 +507,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * @param couponIdStr | |||
| * @param wxCouponSendVo | |||
| */ | |||
| private void stockMerchantReduce(WxCUser user, WxCoupon coupon, String couponIdStr, WxCouponSendVo wxCouponSendVo) { | |||
| private void stockMerchantReduce(WxCUserBasicInfo user, WxCoupon coupon, String couponIdStr, WxCouponSendVo wxCouponSendVo) { | |||
| long time = System.currentTimeMillis() + RedisLock.LONG_TIMEOUT; | |||
| String timeStr = String.valueOf(time); | |||
| // 库存加锁 | |||
| @@ -579,7 +580,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * @param coupon | |||
| * @param couponIdStr | |||
| */ | |||
| private void stockReduce(WxCUser user, WxCoupon coupon, String couponIdStr) { | |||
| private void stockReduce(WxCUserBasicInfo user, WxCoupon coupon, String couponIdStr) { | |||
| //如果缓存中不存在这个key,则从coupon中取 | |||
| if(!redisLock.hasCouponStockCache(coupon.getId())) { | |||
| //此处需要加锁,防止并发设置 | |||
| @@ -821,7 +822,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public WxOrder saveMicroPayOrder(WxMerchantBUser user, String totalFeeStr) { | |||
| public WxOrder saveMicroPayOrder(WxMerchantBUser user, String totalFeeStr,EnumPayWay payWay) { | |||
| // 检查用户 | |||
| if (user == null) { | |||
| logger.error("用户不存在"); | |||
| @@ -853,7 +854,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| // body | |||
| // tenant_id + merchant_id + title + subtitle | |||
| String bodyStr = "刷卡支付, 金额:" + totalFeeStr; | |||
| String bodyStr = "["+payWay.getMessage()+"("+payWay.getCode()+")]刷卡支付, 金额:" + totalFeeStr; | |||
| record.setId(orderNumber); | |||
| record.updateTenantInfo(user); | |||
| @@ -880,7 +881,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public WxOrder saveMicroPayOrderV2(WxMerchantBUser user, WxCUser cUser, Integer payment) { | |||
| public WxOrder saveMicroPayOrderV2(WxMerchantBUser user, WxCUserBasicInfo cUser, Integer payment) { | |||
| // 检查用户 | |||
| if (user == null) { | |||
| logger.error("用户不存在"); | |||
| @@ -937,7 +938,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public WxOrder saveCardPayOrder(WxMerchant merchant, Long cUserId, String totalFeeStr, Integer payment) { | |||
| public WxOrder saveCardPayOrder(WxMerchant merchant, Long cUserId, String totalFeeStr, Integer payment,EnumPayWay payWay) { | |||
| Date curr = new Date(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| @@ -945,7 +946,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| // body | |||
| // tenant_id + merchant_id + title + subtitle | |||
| String bodyStr = "C扫B储值卡支付, 金额:" + totalFeeStr; | |||
| String bodyStr = "["+payWay.getMessage()+"("+payWay.getCode()+")]C扫B储值卡支付, 金额:" + totalFeeStr; | |||
| WxOrder record = new WxOrder(); | |||
| record.setId(orderNumber); | |||
| @@ -979,7 +980,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * @param order | |||
| * @param coupon | |||
| */ | |||
| private WxCouponOrder createCouponOrder(WxOrder order, WxCUser user, WxCoupon coupon, Long couponPasswordId) { | |||
| private WxCouponOrder createCouponOrder(WxOrder order, WxCUserBasicInfo user, WxCoupon coupon, Long couponPasswordId,EnumPayWay payWay) { | |||
| Date curr = new Date(); | |||
| Date valid_date = null; | |||
| int limit_days = Constant.WX_LIMIT_DAYS; | |||
| @@ -1054,6 +1055,13 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| couponOrder.setAutoRefund(coupon.getAutoRefund()); | |||
| couponOrder.setOrderId(order.getOrderNumber()); | |||
| couponOrder.setExpiredTime(valid_date); | |||
| //有支付信息,从支付信息中取渠道 | |||
| if (null != payOrder) { | |||
| couponOrder.setPayVendor(payOrder.getPayVendor()); | |||
| }else { | |||
| //免费券无需支付,如商户注券,核销发券,免费券等等 | |||
| couponOrder.setPayVendor(payWay.getCode()); | |||
| } | |||
| if (!isCard) { | |||
| couponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||
| } else { | |||
| @@ -1141,7 +1149,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * @param order | |||
| * @param coupon | |||
| */ | |||
| private WxCouponOrder createCouponOrderForOuter(WxOrder order, WxCUser user, WxCoupon coupon, Long couponPasswordId) { | |||
| private WxCouponOrder createCouponOrderForOuter(WxOrder order, WxCUserBasicInfo user, WxCoupon coupon, Long couponPasswordId) { | |||
| Date curr = new Date(); | |||
| Date valid_date = null; | |||
| int limit_days = Constant.WX_LIMIT_DAYS; | |||
| @@ -1220,11 +1228,11 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.NESTED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public WxCouponOrder sendFreeCouponToUser(Long userId, Long couponId, WxCouponSendVo wxCouponSendVo) { | |||
| public WxCouponOrder sendFreeCouponToUser(Long userId, Long couponId, WxCouponSendVo wxCouponSendVo,EnumPayWay payWay) { | |||
| // check 用户状态 | |||
| WxCUser user = null; | |||
| WxCUserBasicInfo user = null; | |||
| try { | |||
| user = wxCUserMapper.selectById(userId); | |||
| user = wxCUserBasicInfoMapper.selectById(userId); | |||
| } catch (Exception e) { | |||
| logger.error("userId : " + userId + ", e: " + e.getMessage()); | |||
| } | |||
| @@ -1301,7 +1309,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| // 创建couponOrder | |||
| WxCouponOrder couponOrder = null; | |||
| try { | |||
| couponOrder = createCouponOrder(record, user, coupon, null); | |||
| couponOrder = createCouponOrder(record, user, coupon, null,payWay); | |||
| } catch (Exception e) { | |||
| logger.error("保存订单:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR.getCode(), coupon.getTitle() + ErrorCode.COUPON_ORDER_SAVE_ERR.getMessage()); | |||
| @@ -1321,7 +1329,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | |||
| } | |||
| // 检查用户 | |||
| WxCUser user = wxCUserMapper.selectById(updateOrder.getCUserId()); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectById(updateOrder.getCUserId()); | |||
| if (user == null) { | |||
| logger.error("用户不存在, userId: " + updateOrder.getCUserId()); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||
| @@ -1348,7 +1356,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| // 创建couponOrder | |||
| try { | |||
| createCouponOrder(updateOrder, user, coupon, null); | |||
| createCouponOrder(updateOrder, user, coupon, null,null); | |||
| } catch (Exception e) { | |||
| logger.error("创建券包:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | |||
| @@ -1358,7 +1366,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| return ret; | |||
| } | |||
| private void sendInsideOrderSuccessMsg(WxOrder updateOrder, WxCoupon coupon, WxCUser user) { | |||
| private void sendInsideOrderSuccessMsg(WxOrder updateOrder, WxCoupon coupon, WxCUserBasicInfo user) { | |||
| FmInsideOrderSuccessMsg orderSuccess = new FmInsideOrderSuccessMsg(); | |||
| orderSuccess.setMsgType(EnumMsgRecordType.INSIDE_ORDER_SUCCESS.getCode()); | |||
| orderSuccess.updateTenantInfo(updateOrder); | |||
| @@ -1382,11 +1390,16 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| throw new MallinkException(ErrorCode.COUPON_IS_TAKE_OFF); | |||
| } | |||
| // 检查用户 | |||
| WxCUser user = wxCUserMapper.selectById(updateOrder.getCUserId()); | |||
| if (user == null) { | |||
| logger.error("用户不存在, userId: " + updateOrder.getCUserId()); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| WxCUserBasicInfo basicUser = wxCUserBasicInfoMapper.selectById(updateOrder.getCUserId()); | |||
| if (basicUser == null) { | |||
| logger.error("会员不存在, userId: " + updateOrder.getCUserId()); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| // WxCUser user = wxCUserMapper.selectById(updateOrder.getCUserId()); | |||
| // if (user == null) { | |||
| // logger.error("用户不存在, userId: " + updateOrder.getCUserId()); | |||
| // throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||
| // } | |||
| // 记录活动 | |||
| JSONObject jo = null; | |||
| @@ -1398,11 +1411,11 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| } | |||
| if (jo != null) { | |||
| if (jo.getIntValue("type") == EnumCouponConditionType.NEW_MEMBER.getCode()) { | |||
| wxCUserBasicInfoMapper.incActRecordById(user.getId()); | |||
| wxCUserBasicInfoMapper.incActRecordById(basicUser.getId()); | |||
| } | |||
| } | |||
| sendInsideOrderSuccessMsg(updateOrder, coupon, user); | |||
| sendInsideOrderSuccessMsg(updateOrder, coupon, basicUser); | |||
| } | |||
| /** | |||
| @@ -1412,13 +1425,13 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * @param coupon | |||
| * @param user | |||
| */ | |||
| public void actionAfterCouponOrderSuccess(WxOrder updateOrder, WxCoupon coupon, WxCUser user) { | |||
| public void actionAfterCouponOrderSuccess(WxOrder updateOrder, WxCoupon coupon, WxCUserBasicInfo user) { | |||
| /// TODO 晚上会定时打一下tag | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_BUY, user); | |||
| // 交易发券 | |||
| try { | |||
| wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.C_ORDER, updateOrder); | |||
| wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.C_ORDER, updateOrder,EnumPayWay.PAY_WAY_NOT_UNPAY_TRADE); | |||
| } catch (Exception e) { | |||
| logger.error("订单发券:" + e.getMessage()); | |||
| } | |||
| @@ -1476,7 +1489,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| public int microPayOrderSuccess(WxOrder updateOrder) { | |||
| Date currentDate = new Date(); | |||
| // C端用户 | |||
| WxCUser user = wxCUserMapper.selectById(updateOrder.getCUserId()); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectById(updateOrder.getCUserId()); | |||
| if (user == null) { | |||
| logger.error("用户不存在, userId: " + updateOrder.getCUserId()); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||
| @@ -1515,7 +1528,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| try { | |||
| //扣减积分操作记录 | |||
| WxCreditHistory creditHistory = new WxCreditHistory(); | |||
| creditHistory.setOperatorType(EnumUserType.CUSER.getCode()); | |||
| creditHistory.setOperatorType(EnumUserType.CUSERBASIC.getCode()); | |||
| creditHistory.setOperatorId(user.getId()); | |||
| creditHistory.setCUserId(user.getId()); | |||
| creditHistory.setCreateDate(new Date()); | |||
| @@ -1688,7 +1701,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void shareForMicroPay(TenantEntity tenantEntity, Long orderId, Long payOrderId) { | |||
| public void shareForMicroPay(TenantEntity tenantEntity, Long orderId, Long payOrderId,EnumPayWay payWay) { | |||
| // 微信分账 | |||
| try { | |||
| WxPayOrder wxPayOrder = new WxPayOrder(); | |||
| @@ -1714,7 +1727,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| sharingOrder.updateTenantInfo(wxPayOrder); | |||
| sharingOrder.setTransactionId(wxPayOrder.getTransactionId()); | |||
| sharingOrder.setShareAmount(wxPayOrder.getShareAmount()); | |||
| ResultData resultData = wxProfitSharingOrderService.createSharingOrder(sharingOrder); | |||
| ResultData resultData = wxProfitSharingOrderService.createSharingOrder(sharingOrder,payWay.getCode()); | |||
| } else { | |||
| logger.error("微信分账: 未找到payorder or merchant at orderid-" + orderId); | |||
| } | |||
| @@ -1922,11 +1935,11 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| } | |||
| @Autowired | |||
| @Qualifier("cuserTokenRedisTemplate") | |||
| RedisTemplate<String, WxCUser> cUserTokenRedisTemplate; | |||
| @Qualifier("cUserBasicInfoRedisTemplate") | |||
| RedisTemplate<String, WxCUserBasicInfo> cUserBasicInfoRedisTemplate; | |||
| @Override | |||
| public WxOrder saveOrderForCoupon(WxCUser user, WxCoupon coupon, OrderSaveDto orderSaveDto, boolean isPress) { | |||
| public WxOrder saveOrderForCoupon(WxCUserBasicInfo user, WxCoupon coupon, OrderSaveDto orderSaveDto, boolean isPress,EnumPayWay payWay) { | |||
| WxOrder order = null; | |||
| // 防止同一用户重复抽奖(一分钟内) | |||
| // 1. 订单保存时 加入redis缓存,key --> action:userId:couponId , 时间1000ms | |||
| @@ -1935,14 +1948,14 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| if (checkCouponIsFree(coupon)) { | |||
| // 免费券 | |||
| String key = StringUtils.join("action", ":", user.getId(), coupon.getId()); | |||
| boolean hasKey = cUserTokenRedisTemplate.hasKey(key); | |||
| boolean hasKey = cUserBasicInfoRedisTemplate.hasKey(key); | |||
| if (hasKey) { | |||
| logger.error("用户正在下单,请求异常返回,user: {} " + JSON.toJSONString(user)); | |||
| throw new MallinkException(ErrorCode.SYS_REPEAT_SUBMIT_EXCEPTION); | |||
| } | |||
| cUserTokenRedisTemplate.opsForValue().set(key, user, 1000, TimeUnit.MILLISECONDS); | |||
| cUserBasicInfoRedisTemplate.opsForValue().set(key, user, 1000, TimeUnit.MILLISECONDS); | |||
| order = saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId(), null); | |||
| order = saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId(), null,payWay); | |||
| if (order != null) { | |||
| // 6. 下订单完成,发送内部消息 | |||
| // 下订单完成,发送内部消息 | |||
| @@ -1976,7 +1989,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public WxOrder saveFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId, Long couponPasswordId) { | |||
| public WxOrder saveFreeOrderForCoupon(WxCUserBasicInfo user, WxCoupon coupon, Long couponChannelId, String formId, Long couponPasswordId,EnumPayWay payWay) { | |||
| // 1. check user info and coupon info | |||
| userCouponMerchantCheck(user, coupon); | |||
| if (coupon.checkIsCreditCoupon()) { | |||
| @@ -2016,7 +2029,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| // 5. 创建couponOrder | |||
| try { | |||
| createCouponOrder(record, user, coupon, couponPasswordId); | |||
| createCouponOrder(record, user, coupon, couponPasswordId,payWay); | |||
| } catch (Exception e) { | |||
| logger.error("couponOrder失败:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | |||
| @@ -2026,7 +2039,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public Long saveOuterOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId, Long couponPasswordId) { | |||
| public Long saveOuterOrderForCoupon(WxCUserBasicInfo user, WxCoupon coupon, Long couponChannelId, String formId, Long couponPasswordId) { | |||
| // 1. check user info and coupon info | |||
| userCouponMerchantCheck(user, coupon); | |||
| if (coupon.checkIsCreditCoupon()) { | |||
| @@ -2081,7 +2094,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * @param user | |||
| * @param coupon | |||
| */ | |||
| private void saveFreeOrder(WxOrder record, WxCUser user, WxCoupon coupon) { | |||
| private void saveFreeOrder(WxOrder record, WxCUserBasicInfo user, WxCoupon coupon) { | |||
| Date curr = new Date(); | |||
| // body | |||
| String bodyStr = ""; | |||
| @@ -2107,7 +2120,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| wxOrderMapper.insert(record); | |||
| } | |||
| private void userCouponMerchantCheck(WxCUser user, WxCoupon coupon) throws MallinkException { | |||
| private void userCouponMerchantCheck(WxCUserBasicInfo user, WxCoupon coupon) throws MallinkException { | |||
| // 检查用户 | |||
| if (user == null) { | |||
| logger.error("用户不存在"); | |||
| @@ -2135,7 +2148,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| } | |||
| } | |||
| private void creditPay(WxCUser user, WxCoupon coupon) { | |||
| private void creditPay(WxCUserBasicInfo user, WxCoupon coupon) { | |||
| //-------此处为【积分支付】记录增加积分操作------- | |||
| WxCreditHistory creditHistory = new WxCreditHistory(); | |||
| //记录操作人类型 操作人id | |||
| @@ -2143,7 +2156,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| creditHistory.setOperatorType(EnumUserType.MALLUSER.getCode()); | |||
| creditHistory.setOperatorId(user.getOperatorId()); | |||
| } else { | |||
| creditHistory.setOperatorType(EnumUserType.CUSER.getCode()); | |||
| creditHistory.setOperatorType(EnumUserType.CUSERBASIC.getCode()); | |||
| creditHistory.setOperatorId(user.getId()); | |||
| } | |||
| creditHistory.setCreditNum(coupon.getCreditPrice()); | |||
| @@ -2158,7 +2171,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public WxOrder saveNoFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, boolean isPress, Long orderGroupId, String formId) { | |||
| public WxOrder saveNoFreeOrderForCoupon(WxCUserBasicInfo user, WxCoupon coupon, Long couponChannelId, boolean isPress, Long orderGroupId, String formId) { | |||
| // 1. check user info and coupon info | |||
| userCouponMerchantCheck(user, coupon); | |||
| if (coupon.checkIsCreditCoupon()) { | |||
| @@ -2238,7 +2251,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * @param coupon | |||
| * @param orderNumber | |||
| */ | |||
| private void firstPress(WxOrder record, WxCUser user, WxCoupon coupon, Long orderNumber) { | |||
| private void firstPress(WxOrder record, WxCUserBasicInfo user, WxCoupon coupon, Long orderNumber) { | |||
| // 保存砍价信息 | |||
| int total = coupon.getPrice() - coupon.getSalePrice(); | |||
| int left_total = total; | |||
| @@ -2263,7 +2276,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| wxOrderMapper.updateById(orderUpdatePress); | |||
| } | |||
| private Long saveNoFreeOrder(WxOrder record, WxCUser user, WxCoupon coupon, boolean isPress) { | |||
| private Long saveNoFreeOrder(WxOrder record, WxCUserBasicInfo user, WxCoupon coupon, boolean isPress) { | |||
| Long orderNumber; | |||
| Date curr = new Date(); | |||
| @@ -2302,7 +2315,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| return orderNumber; | |||
| } | |||
| private void checkOrderGroup(WxCUser user, Long orderGroupId,WxCoupon coupon) { | |||
| private void checkOrderGroup(WxCUserBasicInfo user, Long orderGroupId,WxCoupon coupon) { | |||
| WxOrderGroup group = wxOrderGroupMapper.selectById(orderGroupId); | |||
| if (group.getStatus().equals(EnumOrderStatus.ORDER_STATUS_COOPERATING_COMPLETE.getCode())) { | |||
| logger.error("下订单拼团人数已满>>>" + orderGroupId); | |||
| @@ -141,7 +141,7 @@ public class WxPayBillServiceImpl implements WxPayBillService { | |||
| // 支付单号 | |||
| record.setPayBillNo(payBillNo); | |||
| record.setPayAmount((Long) bill.get("owe")); | |||
| record.setPayVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||
| record.setPayVendor(payWay.getCode()); | |||
| record.setPayBillStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); | |||
| record.setShare(isShare.getCode()); | |||
| @@ -587,7 +587,7 @@ public class WxPayBillServiceImpl implements WxPayBillService { | |||
| } | |||
| String partnerKey = payAccount.getApiKey(); | |||
| try { | |||
| if (payWay == EnumPayWay.PAY_WAY_WEAPP) { | |||
| if (payWay.getType() == EnumPayWay.EnumPayWayType.ALI_MINIPAY) { | |||
| boolean signVerified = false; | |||
| if (isNormal) { | |||
| // 普通商户号支付 | |||
| @@ -20,6 +20,8 @@ import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.pay.*; | |||
| import com.iformall.service.WxProfitSharingOrderService; | |||
| import com.iformall.service.pay.PayServiceFactory; | |||
| import com.iformall.service.pay.service.share.entity.PayShareResult; | |||
| import com.iformall.utils.BeanUtils; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.Utility; | |||
| @@ -66,6 +68,9 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| @Autowired | |||
| WxCardSpendMapper wxCardSpendMapper; | |||
| @Autowired | |||
| PayServiceFactory payServiceFactory; | |||
| final JSONObject errorMap = JSON.parseObject("{" + | |||
| "\"SYSTEMERROR\":{\"detail\":\"接口返回错误\",\"reason\":\"系统超时\",\"resolution\":\"系统异常,请用相同参数重新调用\"}," + | |||
| @@ -238,7 +243,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| @Override | |||
| @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) | |||
| public ResultData createSharingOrder(WxSharingOrderDto sharingOrderDto) { | |||
| public ResultData createSharingOrder(WxSharingOrderDto sharingOrderDto,Integer payWay) { | |||
| final IdWorker idworker = IdWorker.get(); | |||
| if (!sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()) && | |||
| @@ -253,7 +258,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| WxProfitSharingReceiver psReceiverQ = new WxProfitSharingReceiver(); | |||
| psReceiverQ.updateTenantInfo(payAccount); | |||
| psReceiverQ.setMerchantId(sharingOrderDto.getMerchantId()); | |||
| psReceiverQ.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode()); | |||
| psReceiverQ.setSharingType(payServiceFactory.getPayShareAdapterService(payWay).getProfitSharingType()); | |||
| psReceiverQ.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); | |||
| List<WxProfitSharingReceiver> psReceiverList = wxProfitSharingReceiverMapper.findList(psReceiverQ); | |||
| if (psReceiverList.size() < 0 || psReceiverList.size() > 50) { | |||
| @@ -269,9 +274,8 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| // 分账完结 | |||
| sharingOrderDto.setShareAmount(sharingOrderDto.getPayAmount()+sharingOrderDto.getRateAmount()); | |||
| } | |||
| return finishSharingOrder(sharingOrderDto); | |||
| return finishSharingOrder(sharingOrderDto,payWay); | |||
| } | |||
| //计算分账账户合法性 | |||
| if (psReceiverList.size() > 1 && | |||
| psReceiverList.stream().filter(r->(r.getParameter() == null)).count() > 0) { | |||
| @@ -325,7 +329,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| psReceiverList.stream().forEach(receiver->{ | |||
| Date currentDate = new Date(); | |||
| JSONObject jo = new JSONObject(); | |||
| jo.put("type",EnumProfitSharingReceiverType.getEnum(receiver.getReceiverType()).getMessage()); | |||
| jo.put("type",payServiceFactory.getPayShareAdapterService(payWay).getShareAccount(receiver.getReceiverType()).getMessage()); | |||
| jo.put("account",receiver.getReceiverAccount()); | |||
| jo.put("amount", receiver.getSharingAmount()); | |||
| //jo.put("description",receiver.getReceiverComments()); //改为存ID, | |||
| @@ -346,78 +350,31 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| resultList.add(result); | |||
| }); | |||
| //分账提交 | |||
| WxProfitSharingP psCmd = new WxProfitSharingP(); | |||
| psCmd.setMch_id(payAccount.getMchId()); | |||
| psCmd.setSub_mch_id(payAccount.getSubMchId()); | |||
| psCmd.setAppid(appInfo.getParentAppId()); | |||
| psCmd.setSub_appid(appInfo.getAppId()); | |||
| psCmd.setNonce_str(Utility.generate32UUID()); | |||
| psCmd.setTransaction_id(sharingOrderDto.getTransactionId()); | |||
| psCmd.setOut_order_no(record.getId().toString()); | |||
| psCmd.setSign_type("HMAC-SHA256"); | |||
| psCmd.setReceivers(receivers.toJSONString()); | |||
| record.setReceivers(receivers.toJSONString()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| String response; | |||
| try { | |||
| psCmd.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(psCmd), payAccount.getApiKey())); | |||
| logger.info("request:" + psCmd.toString()); | |||
| if(sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode())) { | |||
| response = WxProfitSharing.pushOrder(BeanUtils.toStringMap(psCmd), payAccount.getCertPath(), payAccount.getMchId()); | |||
| } else if(sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode())) { | |||
| response = WxProfitSharing.pushMultiOrder(BeanUtils.toStringMap(psCmd), payAccount.getCertPath(), payAccount.getMchId()); | |||
| } else { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| } catch (Exception e) { | |||
| record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode()); | |||
| record.setErrorMsg(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage()); | |||
| record.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED); | |||
| } | |||
| logger.info("response: " + response); | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| String return_code = returnMap.get("return_code"); | |||
| if (!"SUCCESS".equals(return_code)) { | |||
| record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode()); | |||
| record.setErrorMsg(returnMap.get("return_msg")); | |||
| record.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(), returnMap.get("return_msg")); | |||
| } | |||
| if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){ | |||
| record.setErrorMsg(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage()); | |||
| record.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getCode()); | |||
| EnumProfitSharingOrderType shareType = EnumProfitSharingOrderType.getEnum(sharingOrderDto.getType()); | |||
| if (null == shareType) { | |||
| new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),sharingOrderDto.getType()+"在分账方式中不存在。EnumProfitSharingOrderType"); | |||
| } | |||
| PayShareResult shareResult = payServiceFactory.getPayShareAdapterService(payWay).haveReciversShare(appInfo, payAccount, frecord, | |||
| sharingOrderDto.getTransactionId(), receivers, shareType); | |||
| if (!shareResult.isSuccess()) { | |||
| record.setSharingStatus(shareResult.getCode()); | |||
| record.setErrorMsg(shareResult.getMsg()); | |||
| record.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),record.getErrorMsg()); | |||
| } | |||
| String result_code = returnMap.get("result_code"); | |||
| if (!"SUCCESS".equals(result_code)) { | |||
| record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); | |||
| record.setUpdateTime(new Date()); | |||
| record.setErrorMsg(returnMap.get("err_code_des")); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_APPLY_FAILED.getCode(), returnMap.get("err_code_des")); | |||
| } | |||
| record.setSharingOrderNo(returnMap.get("order_id")); | |||
| record.setSharingOrderNo(shareResult.getShareOrderNo()); | |||
| record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode()); | |||
| record.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| for (WxProfitSharingResult result:resultList) { | |||
| wxProfitSharingResultMapper.insert(result); | |||
| } | |||
| return new ResultData(returnMap); | |||
| return new ResultData(shareResult.getData()); | |||
| } | |||
| @Override | |||
| @@ -561,7 +518,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| // 分账完结 | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public ResultData finishSharingOrder(WxSharingOrderDto sharingOrderDto) { | |||
| public ResultData finishSharingOrder(WxSharingOrderDto sharingOrderDto,Integer payWay) { | |||
| final IdWorker idworker = IdWorker.get(); | |||
| if (!sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode()) | |||
| @@ -593,63 +550,20 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||
| wxProfitSharingOrderMapper.insert(record); | |||
| //分账提交 | |||
| WxProfitSharingFinishP psFCmd = new WxProfitSharingFinishP(); | |||
| psFCmd.setMch_id(payAccount.getMchId()); | |||
| psFCmd.setSub_mch_id(payAccount.getSubMchId()); | |||
| psFCmd.setAppid(appInfo.getParentAppId()); | |||
| psFCmd.setNonce_str(Utility.generate32UUID()); | |||
| psFCmd.setTransaction_id(sharingOrderDto.getTransactionId()); | |||
| psFCmd.setOut_order_no(record.getId().toString()); | |||
| psFCmd.setAmount(sharingOrderDto.getShareAmount()); | |||
| psFCmd.setDescription("分账已完结"); | |||
| psFCmd.setSign_type("HMAC-SHA256"); | |||
| String response; | |||
| try { | |||
| psFCmd.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(psFCmd), payAccount.getApiKey())); | |||
| logger.info("request:" + psFCmd.toString()); | |||
| response = WxProfitSharing.finishOrder(BeanUtils.toStringMap(psFCmd), payAccount.getCertPath(), payAccount.getMchId()); | |||
| } catch (Exception e) { | |||
| record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode()); | |||
| record.setErrorMsg(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage()); | |||
| record.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED); | |||
| } | |||
| logger.info("response: " + response); | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| String return_code = returnMap.get("return_code"); | |||
| if (!"SUCCESS".equals(return_code)) { | |||
| record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode()); | |||
| record.setErrorMsg(returnMap.get("return_msg")); | |||
| record.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(), returnMap.get("return_msg")); | |||
| } | |||
| if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){ | |||
| record.setErrorMsg(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage()); | |||
| record.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getCode()); | |||
| } | |||
| String result_code = returnMap.get("result_code"); | |||
| if (!"SUCCESS".equals(result_code)) { | |||
| record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); | |||
| PayShareResult shareResult = payServiceFactory.getPayShareAdapterService(payWay).noReciverShare(appInfo,payAccount,record,sharingOrderDto.getTransactionId(),sharingOrderDto.getShareAmount()); | |||
| if (!shareResult.isSuccess()) { | |||
| record.setSharingStatus(shareResult.getCode()); | |||
| record.setErrorMsg(shareResult.getMsg()); | |||
| record.setUpdateTime(new Date()); | |||
| record.setErrorMsg(returnMap.get("err_code_des")); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_APPLY_FAILED.getCode(), returnMap.get("err_code_des")); | |||
| return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),record.getErrorMsg()); | |||
| } | |||
| record.setSharingOrderNo(returnMap.get("order_id")); | |||
| record.setSharingOrderNo(shareResult.getShareOrderNo()); | |||
| record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode()); | |||
| record.setUpdateTime(new Date()); | |||
| wxProfitSharingOrderMapper.updateById(record); | |||
| return new ResultData(returnMap); | |||
| return new ResultData(shareResult.getData()); | |||
| } | |||
| @Override | |||
| @@ -10,6 +10,7 @@ import com.iformall.utils.PasswordHelper; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.scheduling.annotation.Async; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| @@ -242,10 +243,12 @@ public class WxProjectConfigServiceImpl implements WxProjectConfigService { | |||
| @Override | |||
| public void initSubmall(String parentTenantId, String[] tenantIds) { | |||
| wxMallService.undateSubmall(parentTenantId,tenantIds); | |||
| /** | |||
| * 初始化数据 | |||
| */ | |||
| } | |||
| @Async | |||
| @Override | |||
| public void initAfterGroup(String tenantId, String subTenantIds) { | |||
| wxProjectConfigMapper.initAfterGroup(tenantId,subTenantIds); | |||
| } | |||
| @@ -15,6 +15,7 @@ import com.iformall.mapper.*; | |||
| import com.iformall.service.WxCUserService; | |||
| import com.iformall.service.WxScoreRulesService; | |||
| import com.iformall.utils.Constant; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -104,8 +105,14 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| @Override | |||
| public WxScoreRules getScoreRules(TenantEntity tenantEntity) { | |||
| String tenantId = ""; | |||
| if(StringUtils.isNotBlank(tenantEntity.getParentTenantId())){ | |||
| tenantId = tenantEntity.getParentTenantId(); | |||
| }else{ | |||
| tenantId = tenantEntity.getTenantId(); | |||
| } | |||
| // get pushLime from cache | |||
| String key = Constant.SCORE_RULES_KEY_PREV + tenantEntity.getTenantId(); | |||
| String key = Constant.SCORE_RULES_KEY_PREV + tenantId; | |||
| // 缓存存在 | |||
| if (scoreRulesRedisTemplate.hasKey(key)) { | |||
| @@ -115,7 +122,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| } | |||
| WxScoreRules scoreRules = new WxScoreRules(); | |||
| scoreRules.updateTenantInfo(tenantEntity); | |||
| scoreRules.setTenantId(tenantId); | |||
| scoreRules.setType(EnumScoreRules.SCORE.getCode()); | |||
| List<WxScoreRules> list = wxScoreRulesMapper.findList(scoreRules); | |||
| if (list.size() > 0) { | |||
| @@ -180,8 +187,14 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| @Override | |||
| public WxScoreRules getCreditRules(TenantEntity tenantEntity) { | |||
| String tenantId = ""; | |||
| if(StringUtils.isNotBlank(tenantEntity.getParentTenantId())){ | |||
| tenantId = tenantEntity.getParentTenantId(); | |||
| }else{ | |||
| tenantId = tenantEntity.getTenantId(); | |||
| } | |||
| // get pushLime from cache | |||
| String key = Constant.CREDIT_RULES_KEY_PREV + tenantEntity.getTenantId(); | |||
| String key = Constant.CREDIT_RULES_KEY_PREV + tenantId; | |||
| // 缓存存在 | |||
| if (scoreRulesRedisTemplate.hasKey(key)) { | |||
| @@ -191,7 +204,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| } | |||
| WxScoreRules scoreRules = new WxScoreRules(); | |||
| scoreRules.updateTenantInfo(tenantEntity); | |||
| scoreRules.setTenantId(tenantId); | |||
| scoreRules.setType(EnumScoreRules.CREDIT.getCode()); | |||
| List<WxScoreRules> list = wxScoreRulesMapper.findList(scoreRules); | |||
| if (list.size() > 0) { | |||
| @@ -270,15 +283,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| return 0; | |||
| } | |||
| // 2. user score back | |||
| WxCUser wxCUser = wxCUserMapper.selectById(record.getCUserId()); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectById(record.getCUserId()); | |||
| if (wxCUser != null) { | |||
| WxCUser wxCUserNew = new WxCUser(); | |||
| wxCUserNew.setId(wxCUser.getId()); | |||
| wxCUserNew.setScore(wxCUser.getScore() - history.getScoreAmount()); | |||
| wxCUserNew.setUpdateDate(new Date()); | |||
| wxCUserMapper.updateById(wxCUserNew); | |||
| } | |||
| if (wxCUserBasicInfo != null) { | |||
| WxCUserBasicInfo wxCUserBasicInfoNew = new WxCUserBasicInfo(); | |||
| wxCUserBasicInfoNew.setId(wxCUserBasicInfo.getId()); | |||
| @@ -290,85 +295,27 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| } | |||
| private void updateScore(Long userId, int addedScoreNumber) { | |||
| // 1. 获取cUser | |||
| WxCUser wxCUser = wxCUserService.getById(userId); | |||
| if (wxCUser.getScore() == null) { | |||
| wxCUser.setScore(0); | |||
| } | |||
| int newScore = wxCUser.getScore() + addedScoreNumber; | |||
| // 2. update score | |||
| wxCUser.setScore(newScore); | |||
| wxCUserService.saveOrUpdate(wxCUser); | |||
| // 3. 修改basic points | |||
| if (wxCUser.getPhone() != null) { | |||
| //修改basic表积分 | |||
| WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo(); | |||
| wxCUserBasicInfo.setId(wxCUser.getId()); | |||
| wxCUserBasicInfo.updateTenantInfo(wxCUser); | |||
| wxCUserBasicInfo.setPhone(wxCUser.getPhone()); | |||
| wxCUserBasicInfo.setPoins(newScore); | |||
| wxCUserBasicInfoMapper.updateScore(wxCUserBasicInfo); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectById(userId); | |||
| if (wxCUserBasicInfo.getPoins() == null) { | |||
| wxCUserBasicInfo.setPoins(0); | |||
| } | |||
| } | |||
| int newScore = wxCUserBasicInfo.getPoins() + addedScoreNumber; | |||
| wxCUserBasicInfo.setPoins(newScore); | |||
| wxCUserBasicInfoMapper.updateScore(wxCUserBasicInfo); | |||
| private void resetBasicUserScore(Long userId, int scoreNumber) { | |||
| // 1. basicUser | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectById(userId); | |||
| if(user == null) { | |||
| return; | |||
| } | |||
| // 2. update score/ 修改basic表积分 | |||
| user.setPoins(scoreNumber); | |||
| wxCUserBasicInfoMapper.updateScore(user); | |||
| // 3. 修改 c_user表积分 score | |||
| if (user.getPhone() != null) { | |||
| WxCUser wxCUser = new WxCUser(); | |||
| wxCUser.updateTenantInfo(user); | |||
| wxCUser.setPhone(user.getPhone()); | |||
| List<WxCUser> list = wxCUserMapper.findList(wxCUser); | |||
| if (!list.isEmpty()) { | |||
| wxCUser = list.get(0); | |||
| wxCUser.setScore(scoreNumber); | |||
| wxCUserService.saveOrUpdate(wxCUser); | |||
| } | |||
| } | |||
| } | |||
| private void resetBasicUserScore(WxCUserBasicInfo user, boolean bHaveCUser) { | |||
| // 1. basicUser | |||
| if(user == null) { | |||
| return; | |||
| } | |||
| // 2. update score/ 修改basic表积分 | |||
| // user.setPoins(scoreNumber); | |||
| // wxCUserBasicInfoMapper.updateScore(user); | |||
| // 3. 只修改已存在 c_user表积分 score | |||
| if(bHaveCUser) { | |||
| WxCUser wxCUser = new WxCUser(); | |||
| wxCUser.setId(user.getId()); | |||
| wxCUser.setScore(user.getPoins()); | |||
| wxCUserService.saveOrUpdate(wxCUser); | |||
| } | |||
| } | |||
| private int checkTodayLoginScoreCount(WxCUser cUser) { | |||
| private int checkTodayLoginScoreCount(WxCUserBasicInfo cUser) { | |||
| WxScoreHistory scoreHistory = new WxScoreHistory(); | |||
| scoreHistory.updateTenantInfo(cUser); | |||
| scoreHistory.updateFinalTenantInfo(cUser); | |||
| scoreHistory.setCUserId(cUser.getId()); | |||
| scoreHistory.setScoreType(EnumScoreType.LOGIN.getCode()); | |||
| return wxScoreHistoryMapper.countTodayList(scoreHistory); | |||
| } | |||
| private int loginAddScore(WxCUser user) { | |||
| private int loginAddScore(WxCUserBasicInfo user) { | |||
| int addScoreNumber = 0; | |||
| if (checkTodayLoginScoreCount(user) > 0) | |||
| @@ -380,7 +327,6 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| // 2. 增长的成长值 | |||
| addScoreNumber = scoreRules.getRule(EnumScoreType.LOGIN,WxScoreRules.SCORE); | |||
| updateScore(user.getId(), addScoreNumber); | |||
| user.setScore(addScoreNumber); | |||
| // 3. 记录历史 | |||
| recordScoreHistory(addScoreNumber, user, user.getId(), EnumScoreType.LOGIN); | |||
| @@ -447,23 +393,23 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| } | |||
| private int bindCarAddScore(WxCUserCar userCar) { | |||
| private int bindCarAddScore(WxCUserBasicInfo user) { | |||
| int addScoreNumber = 0; | |||
| // 1. 获取score rules | |||
| WxScoreRules scoreRules = getScoreRules(userCar); | |||
| WxScoreRules scoreRules = getScoreRules(user); | |||
| // 2. 获取成长值 | |||
| addScoreNumber = scoreRules.getRule(EnumScoreType.BIND_CAR,WxScoreRules.SCORE); | |||
| // 3. 增长的成长值 | |||
| updateScore(userCar.getCUserId(), addScoreNumber); | |||
| updateScore(user.getId(), addScoreNumber); | |||
| // 4. 记录历史 | |||
| recordScoreHistory(addScoreNumber, userCar, userCar.getCUserId(), EnumScoreType.BIND_CAR); | |||
| recordScoreHistory(addScoreNumber, user, user.getId(), EnumScoreType.BIND_CAR); | |||
| return addScoreNumber; | |||
| } | |||
| private int personAddScore(WxCUser user) { | |||
| private int personAddScore(WxCUserBasicInfo user) { | |||
| int addScoreNumber = 0; | |||
| // 1. 获取score rules | |||
| WxScoreRules scoreRules = getScoreRules(user); | |||
| @@ -479,7 +425,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| return addScoreNumber; | |||
| } | |||
| private int phoneAddScore(WxCUser user) { | |||
| private int phoneAddScore(WxCUserBasicInfo user) { | |||
| int addScoreNumber = 0; | |||
| // 1. 获取score rules | |||
| WxScoreRules scoreRules = getScoreRules(user); | |||
| @@ -495,19 +441,17 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| return addScoreNumber; | |||
| } | |||
| private int checkCompleteInfoScoreCount(WxCUser cUser) { | |||
| private int checkCompleteInfoScoreCount(WxCUserBasicInfo user) { | |||
| WxScoreHistory scoreHistory = new WxScoreHistory(); | |||
| scoreHistory.updateTenantInfo(cUser); | |||
| scoreHistory.setCUserId(cUser.getId()); | |||
| scoreHistory.updateFinalTenantInfo(user); | |||
| scoreHistory.setCUserId(user.getId()); | |||
| scoreHistory.setScoreType(EnumScoreType.COMPLETE_INFO.getCode()); | |||
| return wxScoreHistoryMapper.countList(scoreHistory); | |||
| } | |||
| private int infoAddScore(WxCUserBasicInfo userInfo) { | |||
| private int infoAddScore(WxCUserBasicInfo user) { | |||
| int addScoreNumber = 0; | |||
| WxCUser user = wxCUserService.getById(userInfo.getId()); | |||
| if (user == null || checkCompleteInfoScoreCount(user) > 0) | |||
| if (checkCompleteInfoScoreCount(user) > 0) | |||
| return 0; | |||
| // 1. 获取score rules | |||
| @@ -526,9 +470,6 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| private int memResetScore(WxCUserBasicInfo userInfo, boolean bHaveCUser) { | |||
| // 1. 导入成长值 | |||
| resetBasicUserScore(userInfo, bHaveCUser); | |||
| // 2. 记录历史 | |||
| recordScoreHistory(userInfo, EnumScoreType.MEM_IMPORT); | |||
| return userInfo.getPoins(); | |||
| @@ -538,18 +479,18 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| int score = userInfo.getPoins() - scoreNum; | |||
| // 1. update score/ 修改basic表积分 | |||
| userInfo.setPoins(score); | |||
| wxCUserBasicInfoMapper.updateScore(userInfo); | |||
| userInfo.setPoins(scoreNum); | |||
| wxCUserBasicInfoMapper.updateDownScore(userInfo); | |||
| // 2. 修改 c_user表积分 score | |||
| if (userInfo.getPhone() != null) { | |||
| WxCUser wxCUser = new WxCUser(); | |||
| wxCUser.setId(userInfo.getId()); | |||
| wxCUser.updateTenantInfo(userInfo); | |||
| wxCUser.setPhone(userInfo.getPhone()); | |||
| wxCUser.setScore(score); | |||
| wxCUserService.saveOrUpdate(wxCUser);; | |||
| } | |||
| // if (userInfo.getPhone() != null) { | |||
| // WxCUser wxCUser = new WxCUser(); | |||
| // wxCUser.setId(userInfo.getId()); | |||
| // wxCUser.updateTenantInfo(userInfo); | |||
| // wxCUser.setPhone(userInfo.getPhone()); | |||
| // wxCUser.setScore(score); | |||
| // wxCUserService.saveOrUpdate(wxCUser);; | |||
| // } | |||
| // 2. 记录历史 | |||
| recordReduceScoreHistory(scoreNum, reason, userInfo, userInfo.getId(), EnumScoreType.MEM_REDUCE); | |||
| @@ -618,7 +559,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| Long userId = null; | |||
| if (param instanceof WxCUser) { | |||
| wxCUser = (WxCUser) param; | |||
| userId = wxCUser.getId(); | |||
| userId = wxCUser.getUserId(); | |||
| } | |||
| if (param instanceof WxCUserCar) { | |||
| userCar = (WxCUserCar) param; | |||
| @@ -628,6 +569,10 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| userBasicInfo = (WxCUserBasicInfo) param; | |||
| userId = userBasicInfo.getId(); | |||
| } | |||
| if(userId == null){ | |||
| logger.info("暂未成为会员:cUserId" + userId); | |||
| return 0; | |||
| } | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectById(userId); | |||
| if (wxCUserBasicInfo != null && wxCUserBasicInfo.getStatus().equals(EnumCUserBasicInfoStatus.LOCKED.getCode())) { | |||
| logger.info("会员权益被锁定:cUserId:" + userId); | |||
| @@ -635,19 +580,19 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| } | |||
| switch (scoreType){ | |||
| case LOGIN: { | |||
| return loginAddScore(wxCUser); | |||
| return loginAddScore(wxCUserBasicInfo); | |||
| } | |||
| case BIND_CAR:{ | |||
| return bindCarAddScore(userCar); | |||
| return bindCarAddScore(wxCUserBasicInfo); | |||
| } | |||
| case WECHAT_PERSION:{ | |||
| return personAddScore(wxCUser); | |||
| return personAddScore(wxCUserBasicInfo); | |||
| } | |||
| case WECHAT_PHONE:{ | |||
| return phoneAddScore(wxCUser); | |||
| return phoneAddScore(wxCUserBasicInfo); | |||
| } | |||
| case COMPLETE_INFO:{ | |||
| return infoAddScore(userBasicInfo); | |||
| return infoAddScore(wxCUserBasicInfo); | |||
| } | |||
| default: { | |||
| @@ -82,261 +82,261 @@ public class WxSubsidyServiceImpl implements WxSubsidyService { | |||
| "\"REQUIRE_POST_METHOD\":{\"detail\":\"请使用post方法\",\"reason\":\"未使用post传递参数\",\"resolution\":\"请检查请求参数是否通过post方法提交\"}," + | |||
| "\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"reason\":\"请检查XML参数格式是否正确\"}}"); | |||
| @Override | |||
| public ResultData createSubsidy(MallUserInfo user, String ip, String amountStr) { | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| EnumPayShare isShare = EnumPayShare.NO; | |||
| Date curDate = new Date(); | |||
| // 1. 获取c端小程序 | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(user); | |||
| // 2. 获取payAccount | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); | |||
| if (payAccount.checkShare()) { | |||
| isShare = EnumPayShare.YES; | |||
| } | |||
| // 3. 补贴订单 | |||
| BigDecimal amountY = new BigDecimal(amountStr); | |||
| int totalFee = amountY.multiply(new BigDecimal(100)).intValue(); // 元->分 | |||
| Long id = idWorker.nextId(); | |||
| String payOrderNo = String.valueOf(id); | |||
| WxSubsidy record = new WxSubsidy(); | |||
| record.setId(id); | |||
| record.updateTenantInfo(user); | |||
| record.setOperatorUserId(user.getId()); | |||
| record.setCreateTime(curDate); | |||
| record.setUpdateTime(curDate); | |||
| record.setOrderNo(payOrderNo); | |||
| record.setBody("商场补贴-"+amountStr + "元"); | |||
| record.setIp(ip); | |||
| record.setStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); | |||
| record.setPayTimeStart(curDate); | |||
| record.setPayTimeEnd(curDate); | |||
| record.setAmount(totalFee); | |||
| // 分账金额 | |||
| int iChargeFee = PayUtils.getPayRate(record.getAmount(), payAccount.getRate(), false); | |||
| Integer share_amount = record.getAmount() - iChargeFee; | |||
| record.setShareAmount(share_amount); | |||
| record.setShareRemainAmount(share_amount); | |||
| try { | |||
| wxSubsidyMapper.insert(record); | |||
| } catch (Exception e) { | |||
| logger.error("wx_subsidy save fail" + e.getMessage()); | |||
| return new ResultData(ErrorCode.DB_FAIL); | |||
| } | |||
| // 3. 支付发起 | |||
| try { | |||
| // 统一下单 // 服务商模式 | |||
| String noncestr = Utility.generate32UUID(); | |||
| WxNativePayOrderSP payOrder = new WxNativePayOrderSP(); | |||
| payOrder.setAppid(appInfo.getParentAppId()); | |||
| payOrder.setSub_appid(appInfo.getAppId()); | |||
| payOrder.setMch_id(payAccount.getMchId()); | |||
| payOrder.setSub_mch_id(payAccount.getSubMchId()); | |||
| payOrder.setDevice_info("WEB"); | |||
| payOrder.setNonce_str(noncestr); | |||
| payOrder.setBody(record.getBody()); | |||
| payOrder.setOut_trade_no(record.getOrderNo()); | |||
| payOrder.setTotal_fee(record.getAmount()); | |||
| payOrder.setSpbill_create_ip(record.getIp()); | |||
| payOrder.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(curDate)); | |||
| Date futureDate = new Date(); | |||
| futureDate.setTime(curDate.getTime() + 15 * 60 * 1000); | |||
| payOrder.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||
| payOrder.setNotify_url(payAccount.getSubsidyNotifyUrl()); | |||
| payOrder.setTrade_type("NATIVE"); | |||
| payOrder.setProduct_id(record.getOrderNo()); | |||
| payOrder.setSign_type("HMAC-SHA256"); | |||
| payOrder.setProfit_sharing(null); | |||
| if (isShare == EnumPayShare.YES) { | |||
| payOrder.setProfit_sharing("Y"); | |||
| } | |||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(payOrder); | |||
| payOrder.setSign(WxPayment.createSignHMAC(payOrderMap, payAccount.getApiKey())); | |||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(payOrder)); | |||
| logger.info("wx_subsidy wechat native Pay, " + payOrder.toString() + ", response: " + response.toString()); | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| String return_code = returnMap.get("return_code"); | |||
| String result_code = returnMap.get("result_code"); | |||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||
| if ("SUCCESS".equals(result_code)) { | |||
| String prepay_id = returnMap.get("prepay_id"); | |||
| String code_url = returnMap.get("code_url"); | |||
| // update payOrder with prepay_id | |||
| record.setPrepayId(prepay_id); | |||
| record.setCodeUrl(code_url); | |||
| record.setUpdateTime(new Date()); | |||
| try { | |||
| wxSubsidyMapper.updateById(record); | |||
| } catch (Exception e) { | |||
| logger.error("wx_subsidy update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| Map<String, String> retMap = new HashMap<String, String>(); | |||
| retMap.put("code_url", code_url); | |||
| return new ResultData(Result.SUCCESS, "创建支付订单成功", retMap); | |||
| } else { | |||
| String errMsg = ""; | |||
| JSONObject errObj = errorMap.getJSONObject(result_code); | |||
| if (errObj != null) { | |||
| errMsg = errObj.toJSONString(); | |||
| record.setFailReason(errMsg); | |||
| } else { | |||
| errMsg = returnMap.get("return_msg"); | |||
| record.setFailReason(errMsg); | |||
| } | |||
| record.setUpdateTime(new Date()); | |||
| try { | |||
| wxSubsidyMapper.updateById(record); | |||
| } catch (Exception e) { | |||
| logger.error("pay order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||
| } | |||
| } else { | |||
| String errMsg = returnMap.get("return_msg"); | |||
| record.setFailReason(errMsg); | |||
| record.setUpdateTime(new Date()); | |||
| try { | |||
| wxSubsidyMapper.updateById(record); | |||
| } catch (Exception e) { | |||
| logger.error("pay order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||
| } | |||
| } catch (RuntimeException e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| } | |||
| } | |||
| /** | |||
| * 提供微信支付回调调用 | |||
| * | |||
| * @param paramMap 异步通知参数 | |||
| * @param payWay 支付方式 | |||
| * @return | |||
| */ | |||
| @Override | |||
| public String notify(Map<String, String> paramMap, EnumPayWay payWay) { | |||
| // how to get wechatAppId, wechatMchId, partnerKey | |||
| String appId = paramMap.get("appid"); | |||
| String subAppId = paramMap.get("sub_appid"); | |||
| String mchId = paramMap.get("mch_id"); | |||
| String subMchId = paramMap.get("sub_mch_id"); | |||
| WxAppinfo appinfo = null; | |||
| boolean isNormal = true; | |||
| if (StringUtils.isBlank(subAppId) && StringUtils.isBlank(subMchId)) { | |||
| // 普通商户号 | |||
| appinfo = wxAppinfoMapper.findByAppId(appId); | |||
| if (appinfo == null) { | |||
| logger.error("appid not found: " + appId); | |||
| throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| isNormal = true; | |||
| } else { | |||
| // 服务号 现在用hmac-sha256 | |||
| appinfo = wxAppinfoMapper.findByAppId(subAppId); | |||
| if (appinfo == null) { | |||
| logger.error("subappid not found: " + subAppId); | |||
| throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| isNormal = false; | |||
| } | |||
| WxPayAccount payAccount = wxPayAccountMapper.selectById(appinfo.getPayId()); | |||
| if (payAccount == null) { | |||
| throw new MallinkException(ErrorCode.MCH_INFO_NOT_FOUND); | |||
| } | |||
| String partnerKey = payAccount.getApiKey(); | |||
| try { | |||
| if (payWay == EnumPayWay.PAY_WAY_WEAPP) { | |||
| boolean signVerified = false; | |||
| if (isNormal) { | |||
| // 普通商户号支付 | |||
| signVerified = WxPayment.verifyNotify(paramMap, partnerKey); | |||
| if (!signVerified) { | |||
| logger.warn("notify order, wxpay checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); | |||
| } | |||
| } else { | |||
| // 服务号 现在用hmac-sha256 | |||
| signVerified = WxPayment.verifyNotifyHMAC(paramMap, partnerKey); | |||
| if (!signVerified) { | |||
| logger.warn("notify order, wxpay checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); | |||
| } | |||
| } | |||
| if (!"SUCCESS".equals(paramMap.get("return_code"))) { | |||
| logger.warn("notify order, wxpay status not success, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "FAIL"); | |||
| resultMap.put("return_msg", "订单状态码非SUCCESS"); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } | |||
| String payOrderNo = paramMap.get("out_trade_no"); | |||
| String transactionId = paramMap.get("transaction_id"); | |||
| String openId = paramMap.get("sub_openid"); | |||
| String timEndStr = paramMap.get("time_end"); | |||
| Long payOrderId = Long.valueOf(payOrderNo); | |||
| WxSubsidy subsidy = wxSubsidyMapper.selectById(payOrderId); | |||
| if (subsidy == null) { | |||
| logger.warn("notify order, wxpay check pay order not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "FAIL"); | |||
| resultMap.put("return_msg", "订单不存在"); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } | |||
| // 验证支付金额 | |||
| if (!paramMap.get("total_fee").equals(subsidy.getAmount().toString())) { | |||
| logger.warn("notify order, wxpay check total_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "FAIL"); | |||
| resultMap.put("return_msg", "订单总金额不一致"); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } | |||
| Date timeEnd = null; | |||
| try { | |||
| timeEnd = Utility.getDateFromString(timEndStr); | |||
| } catch (ParseException e) { | |||
| logger.error("解析timeEnd失败"); | |||
| timeEnd = new Date(); | |||
| } | |||
| subsidy.setPayTimeEnd(timeEnd); | |||
| subsidy.setTransactionId(transactionId); | |||
| subsidy.setStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| subsidy.setOpenId(openId); | |||
| subsidy.setUpdateTime(new Date()); | |||
| try { | |||
| wxSubsidyMapper.updateById(subsidy); | |||
| } catch (Exception e) { | |||
| logger.error("wx_subsidy update exception"); | |||
| } | |||
| logger.info("notify order, wxpay checksign success, paramMap:{}, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "SUCCESS"); | |||
| resultMap.put("return_msg", "OK"); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } | |||
| } catch (RuntimeException e) { | |||
| logger.warn("notify order, checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString() + ", e:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR); | |||
| } | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "FAIL"); | |||
| resultMap.put("return_msg", "FAILED"); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } | |||
| // @Override | |||
| // public ResultData createSubsidy(MallUserInfo user, String ip, String amountStr) { | |||
| // final IdWorker idWorker = IdWorker.get(); | |||
| // EnumPayShare isShare = EnumPayShare.NO; | |||
| // Date curDate = new Date(); | |||
| // // 1. 获取c端小程序 | |||
| // WxAppinfo appInfo = wxAppinfoService.getCAppInfo(user); | |||
| // // 2. 获取payAccount | |||
| // WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); | |||
| // if (payAccount.checkShare()) { | |||
| // isShare = EnumPayShare.YES; | |||
| // } | |||
| // // 3. 补贴订单 | |||
| // BigDecimal amountY = new BigDecimal(amountStr); | |||
| // int totalFee = amountY.multiply(new BigDecimal(100)).intValue(); // 元->分 | |||
| // | |||
| // Long id = idWorker.nextId(); | |||
| // String payOrderNo = String.valueOf(id); | |||
| // WxSubsidy record = new WxSubsidy(); | |||
| // record.setId(id); | |||
| // record.updateTenantInfo(user); | |||
| // record.setOperatorUserId(user.getId()); | |||
| // record.setCreateTime(curDate); | |||
| // record.setUpdateTime(curDate); | |||
| // record.setOrderNo(payOrderNo); | |||
| // record.setBody("商场补贴-"+amountStr + "元"); | |||
| // record.setIp(ip); | |||
| // record.setStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); | |||
| // record.setPayTimeStart(curDate); | |||
| // record.setPayTimeEnd(curDate); | |||
| // record.setAmount(totalFee); | |||
| // // 分账金额 | |||
| // int iChargeFee = PayUtils.getPayRate(record.getAmount(), payAccount.getRate(), false); | |||
| // Integer share_amount = record.getAmount() - iChargeFee; | |||
| // record.setShareAmount(share_amount); | |||
| // record.setShareRemainAmount(share_amount); | |||
| // try { | |||
| // wxSubsidyMapper.insert(record); | |||
| // } catch (Exception e) { | |||
| // logger.error("wx_subsidy save fail" + e.getMessage()); | |||
| // return new ResultData(ErrorCode.DB_FAIL); | |||
| // } | |||
| // // 3. 支付发起 | |||
| // try { | |||
| // // 统一下单 // 服务商模式 | |||
| // String noncestr = Utility.generate32UUID(); | |||
| // WxNativePayOrderSP payOrder = new WxNativePayOrderSP(); | |||
| // payOrder.setAppid(appInfo.getParentAppId()); | |||
| // payOrder.setSub_appid(appInfo.getAppId()); | |||
| // payOrder.setMch_id(payAccount.getMchId()); | |||
| // payOrder.setSub_mch_id(payAccount.getSubMchId()); | |||
| // payOrder.setDevice_info("WEB"); | |||
| // payOrder.setNonce_str(noncestr); | |||
| // payOrder.setBody(record.getBody()); | |||
| // payOrder.setOut_trade_no(record.getOrderNo()); | |||
| // payOrder.setTotal_fee(record.getAmount()); | |||
| // payOrder.setSpbill_create_ip(record.getIp()); | |||
| // payOrder.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(curDate)); | |||
| // Date futureDate = new Date(); | |||
| // futureDate.setTime(curDate.getTime() + 15 * 60 * 1000); | |||
| // payOrder.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||
| // payOrder.setNotify_url(payAccount.getSubsidyNotifyUrl()); | |||
| // payOrder.setTrade_type("NATIVE"); | |||
| // payOrder.setProduct_id(record.getOrderNo()); | |||
| // payOrder.setSign_type("HMAC-SHA256"); | |||
| // payOrder.setProfit_sharing(null); | |||
| // if (isShare == EnumPayShare.YES) { | |||
| // payOrder.setProfit_sharing("Y"); | |||
| // } | |||
| // Map<String, String> payOrderMap = BeanUtils.toStringMap(payOrder); | |||
| // | |||
| // payOrder.setSign(WxPayment.createSignHMAC(payOrderMap, payAccount.getApiKey())); | |||
| // String response = WxPay.pushOrder(BeanUtils.toStringMap(payOrder)); | |||
| // logger.info("wx_subsidy wechat native Pay, " + payOrder.toString() + ", response: " + response.toString()); | |||
| // Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| // String return_code = returnMap.get("return_code"); | |||
| // String result_code = returnMap.get("result_code"); | |||
| // if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||
| // if ("SUCCESS".equals(result_code)) { | |||
| // String prepay_id = returnMap.get("prepay_id"); | |||
| // String code_url = returnMap.get("code_url"); | |||
| // // update payOrder with prepay_id | |||
| // record.setPrepayId(prepay_id); | |||
| // record.setCodeUrl(code_url); | |||
| // record.setUpdateTime(new Date()); | |||
| // try { | |||
| // wxSubsidyMapper.updateById(record); | |||
| // } catch (Exception e) { | |||
| // logger.error("wx_subsidy update error: " + record.toString()); | |||
| // throw new MallinkException(ErrorCode.DB_FAIL); | |||
| // } | |||
| // | |||
| // Map<String, String> retMap = new HashMap<String, String>(); | |||
| // retMap.put("code_url", code_url); | |||
| // return new ResultData(Result.SUCCESS, "创建支付订单成功", retMap); | |||
| // } else { | |||
| // String errMsg = ""; | |||
| // JSONObject errObj = errorMap.getJSONObject(result_code); | |||
| // if (errObj != null) { | |||
| // errMsg = errObj.toJSONString(); | |||
| // record.setFailReason(errMsg); | |||
| // } else { | |||
| // errMsg = returnMap.get("return_msg"); | |||
| // record.setFailReason(errMsg); | |||
| // } | |||
| // record.setUpdateTime(new Date()); | |||
| // try { | |||
| // wxSubsidyMapper.updateById(record); | |||
| // } catch (Exception e) { | |||
| // logger.error("pay order update error: " + record.toString()); | |||
| // throw new MallinkException(ErrorCode.DB_FAIL); | |||
| // } | |||
| // return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||
| // } | |||
| // } else { | |||
| // String errMsg = returnMap.get("return_msg"); | |||
| // record.setFailReason(errMsg); | |||
| // record.setUpdateTime(new Date()); | |||
| // try { | |||
| // wxSubsidyMapper.updateById(record); | |||
| // } catch (Exception e) { | |||
| // logger.error("pay order update error: " + record.toString()); | |||
| // throw new MallinkException(ErrorCode.DB_FAIL); | |||
| // } | |||
| // return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||
| // } | |||
| // } catch (RuntimeException e) { | |||
| // throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| // } catch (Exception e) { | |||
| // throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | |||
| // } | |||
| // } | |||
| // | |||
| // /** | |||
| // * 提供微信支付回调调用 | |||
| // * | |||
| // * @param paramMap 异步通知参数 | |||
| // * @param payWay 支付方式 | |||
| // * @return | |||
| // */ | |||
| // @Override | |||
| // public String notify(Map<String, String> paramMap, EnumPayWay payWay) { | |||
| // // how to get wechatAppId, wechatMchId, partnerKey | |||
| // String appId = paramMap.get("appid"); | |||
| // String subAppId = paramMap.get("sub_appid"); | |||
| // String mchId = paramMap.get("mch_id"); | |||
| // String subMchId = paramMap.get("sub_mch_id"); | |||
| // WxAppinfo appinfo = null; | |||
| // boolean isNormal = true; | |||
| // if (StringUtils.isBlank(subAppId) && StringUtils.isBlank(subMchId)) { | |||
| // // 普通商户号 | |||
| // appinfo = wxAppinfoMapper.findByAppId(appId); | |||
| // if (appinfo == null) { | |||
| // logger.error("appid not found: " + appId); | |||
| // throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); | |||
| // } | |||
| // isNormal = true; | |||
| // } else { | |||
| // // 服务号 现在用hmac-sha256 | |||
| // appinfo = wxAppinfoMapper.findByAppId(subAppId); | |||
| // if (appinfo == null) { | |||
| // logger.error("subappid not found: " + subAppId); | |||
| // throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); | |||
| // } | |||
| // isNormal = false; | |||
| // } | |||
| // | |||
| // WxPayAccount payAccount = wxPayAccountMapper.selectById(appinfo.getPayId()); | |||
| // if (payAccount == null) { | |||
| // throw new MallinkException(ErrorCode.MCH_INFO_NOT_FOUND); | |||
| // } | |||
| // String partnerKey = payAccount.getApiKey(); | |||
| // try { | |||
| // if (payWay.getType() == EnumPayWay.EnumPayWayType.WX_MINIPAY) { | |||
| // boolean signVerified = false; | |||
| // if (isNormal) { | |||
| // // 普通商户号支付 | |||
| // signVerified = WxPayment.verifyNotify(paramMap, partnerKey); | |||
| // if (!signVerified) { | |||
| // logger.warn("notify order, wxpay checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| // throw new MallinkException(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); | |||
| // } | |||
| // } else { | |||
| // // 服务号 现在用hmac-sha256 | |||
| // signVerified = WxPayment.verifyNotifyHMAC(paramMap, partnerKey); | |||
| // if (!signVerified) { | |||
| // logger.warn("notify order, wxpay checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| // throw new MallinkException(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); | |||
| // } | |||
| // } | |||
| // | |||
| // if (!"SUCCESS".equals(paramMap.get("return_code"))) { | |||
| // logger.warn("notify order, wxpay status not success, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| // SortedMap resultMap = new TreeMap(); | |||
| // resultMap.put("return_code", "FAIL"); | |||
| // resultMap.put("return_msg", "订单状态码非SUCCESS"); | |||
| // return XmlUtil.getRequestXml(resultMap); | |||
| // } | |||
| // | |||
| // String payOrderNo = paramMap.get("out_trade_no"); | |||
| // String transactionId = paramMap.get("transaction_id"); | |||
| // String openId = paramMap.get("sub_openid"); | |||
| // String timEndStr = paramMap.get("time_end"); | |||
| // Long payOrderId = Long.valueOf(payOrderNo); | |||
| // WxSubsidy subsidy = wxSubsidyMapper.selectById(payOrderId); | |||
| // if (subsidy == null) { | |||
| // logger.warn("notify order, wxpay check pay order not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| // SortedMap resultMap = new TreeMap(); | |||
| // resultMap.put("return_code", "FAIL"); | |||
| // resultMap.put("return_msg", "订单不存在"); | |||
| // return XmlUtil.getRequestXml(resultMap); | |||
| // } | |||
| // // 验证支付金额 | |||
| // if (!paramMap.get("total_fee").equals(subsidy.getAmount().toString())) { | |||
| // logger.warn("notify order, wxpay check total_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| // SortedMap resultMap = new TreeMap(); | |||
| // resultMap.put("return_code", "FAIL"); | |||
| // resultMap.put("return_msg", "订单总金额不一致"); | |||
| // return XmlUtil.getRequestXml(resultMap); | |||
| // } | |||
| // | |||
| // Date timeEnd = null; | |||
| // | |||
| // try { | |||
| // timeEnd = Utility.getDateFromString(timEndStr); | |||
| // } catch (ParseException e) { | |||
| // logger.error("解析timeEnd失败"); | |||
| // timeEnd = new Date(); | |||
| // } | |||
| // subsidy.setPayTimeEnd(timeEnd); | |||
| // subsidy.setTransactionId(transactionId); | |||
| // subsidy.setStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| // subsidy.setOpenId(openId); | |||
| // subsidy.setUpdateTime(new Date()); | |||
| // try { | |||
| // wxSubsidyMapper.updateById(subsidy); | |||
| // } catch (Exception e) { | |||
| // logger.error("wx_subsidy update exception"); | |||
| // } | |||
| // logger.info("notify order, wxpay checksign success, paramMap:{}, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| // SortedMap resultMap = new TreeMap(); | |||
| // resultMap.put("return_code", "SUCCESS"); | |||
| // resultMap.put("return_msg", "OK"); | |||
| // return XmlUtil.getRequestXml(resultMap); | |||
| // } | |||
| // } catch (RuntimeException e) { | |||
| // logger.warn("notify order, checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString() + ", e:" + e.getMessage()); | |||
| // throw new MallinkException(ErrorCode.PAY_ORDER_ERROR); | |||
| // } | |||
| // | |||
| // SortedMap resultMap = new TreeMap(); | |||
| // resultMap.put("return_code", "FAIL"); | |||
| // resultMap.put("return_msg", "FAILED"); | |||
| // return XmlUtil.getRequestXml(resultMap); | |||
| // } | |||
| @Override | |||
| @@ -18,17 +18,17 @@ import java.util.Map; | |||
| * @author Stormeye Wu | |||
| * @date 2019/5/10 | |||
| */ | |||
| @Service | |||
| public class FmInsideNotifyPaySuccessMsgServiceImpl implements MsgSendService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxPayOrderService wxPayOrderService; | |||
| @Override | |||
| public void send(BaseMsg baseMsg) throws Exception { | |||
| FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg)baseMsg; | |||
| Map<String, String> paramMap = JSON.parseObject(msg.getJsonMsg(), Map.class); | |||
| wxPayOrderService.notify(paramMap, EnumPayWay.getEnum(msg.getPayWay())); | |||
| } | |||
| } | |||
| //@Service | |||
| //public class FmInsideNotifyPaySuccessMsgServiceImpl implements MsgSendService { | |||
| // private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| // | |||
| // @Autowired | |||
| // private WxPayOrderService wxPayOrderService; | |||
| // | |||
| // @Override | |||
| // public void send(BaseMsg baseMsg) throws Exception { | |||
| // FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg)baseMsg; | |||
| // Map<String, String> paramMap = JSON.parseObject(msg.getJsonMsg(), Map.class); | |||
| // wxPayOrderService.notify(paramMap, EnumPayWay.getEnum(msg.getPayWay())); | |||
| // } | |||
| //} | |||
| @@ -1,14 +1,14 @@ | |||
| package com.iformall.service.msg.impl; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.msg.BaseMsg; | |||
| import com.iformall.domain.po.msg.FmInsideOrderSuccessMsg; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxCUserService; | |||
| import com.iformall.service.WxCUserBasicInfoService; | |||
| import com.iformall.service.WxCouponChannelService; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.WxOrderService; | |||
| @@ -31,7 +31,7 @@ public class FmInsideOrderSuccessMsgServiceImpl implements MsgSendService { | |||
| private WxOrderService orderService; | |||
| @Autowired | |||
| private WxCUserService userService; | |||
| private WxCUserBasicInfoService userService; | |||
| @Autowired | |||
| private WxCouponService couponService; | |||
| @@ -63,7 +63,7 @@ public class FmInsideOrderSuccessMsgServiceImpl implements MsgSendService { | |||
| throw new MallinkException(ErrorCode.ORDER_COUPON_NOT_MATCH.getCode(), "订单用户不一致" + msg.getOrderId()); | |||
| } | |||
| WxCUser user = userService.getById(msg.getCUserId()); | |||
| WxCUserBasicInfo user = userService.getById(msg.getCUserId()); | |||
| if(user == null) { | |||
| logger.error("用户未找到: " + msg.getCUserId()); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), "用户未找到" + msg.getCUserId()); | |||
| @@ -0,0 +1,132 @@ | |||
| package com.iformall.service.pay; | |||
| import java.util.Map; | |||
| import java.util.concurrent.ConcurrentHashMap; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.WxMerchantBUser; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxPayOrderService; | |||
| import com.iformall.service.pay.service.pay.CDrivingPayService; | |||
| import com.iformall.service.pay.service.pay.CPassivePayService; | |||
| import com.iformall.service.pay.service.pay.PayAdapterService; | |||
| import com.iformall.service.pay.service.pay.wx.h5.WxH5PayService; | |||
| import com.iformall.service.pay.service.pay.wx.miniApp.appPay.WxMiniAppPayAdapterService; | |||
| import com.iformall.service.pay.service.pay.wx.miniApp.maPay.WxMiniMaPayAdapterService; | |||
| import com.iformall.service.pay.service.refund.RefundPayAdapterService; | |||
| import com.iformall.service.pay.service.refund.wx.WxRefundAdapterService; | |||
| import com.iformall.service.pay.service.share.PayShareAdapterService; | |||
| import com.iformall.service.pay.service.share.neupos.NeuPosPayShareService; | |||
| import com.iformall.service.pay.service.share.wx.WxPayShareService; | |||
| /** | |||
| * 支付方式工厂 | |||
| * @author alascor | |||
| */ | |||
| @Service | |||
| public class PayServiceFactory { | |||
| private Map<Integer,PayAdapterService> serviceMap = null; | |||
| private Map<Integer,PayShareAdapterService> shareMap = null; | |||
| private Map<Integer,RefundPayAdapterService> refundMap = null; | |||
| @Autowired | |||
| WxMiniAppPayAdapterService wxMiniAppPayService; | |||
| @Autowired | |||
| WxMiniMaPayAdapterService wxMiniAppMaPayService; | |||
| @Autowired | |||
| WxH5PayService wxH5PayService; | |||
| @Autowired | |||
| WxPayShareService wxShareService; | |||
| @Autowired | |||
| NeuPosPayShareService neuPosPayShareService; | |||
| @Autowired | |||
| WxRefundAdapterService wxRefundService; | |||
| private Map<Integer,PayAdapterService> getServiceMap() { | |||
| if (null == serviceMap) { | |||
| serviceMap = new ConcurrentHashMap<Integer,PayAdapterService>(); | |||
| serviceMap.put(EnumPayWay.PAY_WAY_WECHAT.getCode(), wxMiniAppPayService); | |||
| serviceMap.put(EnumPayWay.PAY_WAY_WECHAT_MA.getCode(), wxMiniAppMaPayService); | |||
| serviceMap.put(EnumPayWay.PAY_WAY_WECHAT_WAP.getCode(), wxH5PayService); | |||
| } | |||
| return serviceMap; | |||
| } | |||
| private Map<Integer,PayShareAdapterService> getShareMap(){ | |||
| if (null == shareMap ) { | |||
| shareMap = new ConcurrentHashMap<Integer, PayShareAdapterService>(); | |||
| shareMap.put(EnumPayWay.PAY_WAY_WECHAT.getCode(), wxShareService); | |||
| shareMap.put(EnumPayWay.PAY_WAY_WECHAT_MA.getCode(), wxShareService); | |||
| shareMap.put(EnumPayWay.PAY_WAY_POS_NEU.getCode(), neuPosPayShareService); | |||
| } | |||
| return shareMap; | |||
| } | |||
| private Map<Integer,RefundPayAdapterService> getRefundMap(){ | |||
| if (null == refundMap ) { | |||
| refundMap = new ConcurrentHashMap<Integer, RefundPayAdapterService>(); | |||
| refundMap.put(EnumPayWay.PAY_WAY_WECHAT.getCode(), wxRefundService); | |||
| refundMap.put(EnumPayWay.PAY_WAY_WECHAT_MA.getCode(), wxRefundService); | |||
| } | |||
| return refundMap; | |||
| } | |||
| public PayAdapterService getPayAdapterService(Integer type) throws MallinkException{ | |||
| PayAdapterService service = getServiceMap().get(type); | |||
| if (null == service) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"payWay["+type+"] 支付service未找到"); | |||
| } | |||
| return service; | |||
| } | |||
| public CDrivingPayService getCDrivingPayService(Integer type) throws MallinkException{ | |||
| PayAdapterService service = getServiceMap().get(type); | |||
| if (null == service) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"payWay["+type+"] 支付service未找到"); | |||
| } | |||
| if (service instanceof CDrivingPayService) { | |||
| return (CDrivingPayService) service; | |||
| }else { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"payWay["+type+"] 支付service不是CDrivingPayService"); | |||
| } | |||
| } | |||
| public CPassivePayService getCPassivePayService(Integer type) throws MallinkException{ | |||
| PayAdapterService service = getServiceMap().get(type); | |||
| if (null == service) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"payWay["+type+"] 支付service未找到"); | |||
| } | |||
| if (service instanceof CPassivePayService) { | |||
| return (CPassivePayService) service; | |||
| }else { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"payWay["+type+"] 支付service不是CPassivePayService"); | |||
| } | |||
| } | |||
| public PayShareAdapterService getPayShareAdapterService(Integer type) throws MallinkException{ | |||
| PayShareAdapterService shareService = getShareMap().get(type); | |||
| if (null == shareService) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"payWay["+type+"] 分账service未找到"); | |||
| } | |||
| return shareService; | |||
| } | |||
| public RefundPayAdapterService getRefundPayAdapterService(Integer type) throws MallinkException{ | |||
| RefundPayAdapterService refundService = getRefundMap().get(type); | |||
| if (null == refundService) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"payWay["+type+"] 退款service未找到"); | |||
| } | |||
| return refundService; | |||
| } | |||
| } | |||
| @@ -0,0 +1,29 @@ | |||
| package com.iformall.service.pay.entity; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| public class PayExtraParam { | |||
| private Map map = new HashMap(); | |||
| public PayExtraParam() { | |||
| } | |||
| public PayExtraParam(Object key,Object value) { | |||
| map.put(key, value); | |||
| } | |||
| public Object getValue(String key) { | |||
| if (map.containsKey(key)) { | |||
| return map.get(key); | |||
| } | |||
| return null; | |||
| } | |||
| public PayExtraParam set(Object key,Object value) { | |||
| this.map.put(key, value); | |||
| return this; | |||
| } | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| package com.iformall.service.pay.service.pay; | |||
| /** | |||
| * C端主动发起的支付 | |||
| * @author alascor | |||
| */ | |||
| public interface CDrivingPayService extends PayAdapterService{ | |||
| } | |||
| @@ -0,0 +1,34 @@ | |||
| package com.iformall.service.pay.service.pay; | |||
| import java.util.Date; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.enums.EnumPayShare; | |||
| import com.iformall.service.pay.entity.PayExtraParam; | |||
| import com.iformall.service.pay.service.pay.entity.CreateCUser; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| /** | |||
| * C端被动发起的支付 | |||
| * @author alascor | |||
| */ | |||
| public interface CPassivePayService extends PayAdapterService{ | |||
| /** | |||
| * 支付成功之后生成用户 | |||
| * @param result 支付API或者查询API 接口返回的对象 | |||
| * @param payAccount | |||
| * @param order | |||
| * @param record | |||
| * @param isShare | |||
| * @param appInfo | |||
| * @param currentDate | |||
| * @param params | |||
| * @throws Exception | |||
| */ | |||
| public CreateCUser createCUserAfterPay(Object result,WxAppinfo appInfo) throws Exception; | |||
| } | |||
| @@ -0,0 +1,59 @@ | |||
| package com.iformall.service.pay.service.pay; | |||
| import java.util.Date; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.enums.EnumPayShare; | |||
| import com.iformall.service.pay.entity.PayExtraParam; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
| public interface PayAdapterService { | |||
| /** | |||
| * 真正支付过程,调用对应端的API调用支付 | |||
| * @param payAccount WxPayAccount | |||
| * @param order WxOrder | |||
| * @param record WxPayOrder | |||
| * @param isShare EnumPayShare | |||
| * @param appInfo C端app | |||
| * @param currentDate Date 当前时间,可能加密串用 | |||
| * @param params PayExtraParam 其他需要的参数 | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| public PayAdapterResult pay(WxPayAccount payAccount,WxOrder order,WxPayOrder record ,EnumPayShare isShare,WxAppinfo appInfo,Date currentDate, PayExtraParam params) throws Exception; | |||
| /** | |||
| * 查询支付结果,调用对应端的API查询支付结果 | |||
| * @param oldRecord WxPayOrder | |||
| * @param order WxOrder | |||
| * @param appInfo C端app | |||
| * @param payAccount WxPayAccount | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| public PayQueryAdapterResult queryPayStatus(WxPayOrder oldRecord,WxOrder order,WxAppinfo appInfo,WxPayAccount payAccount) throws Exception; | |||
| /** | |||
| * 根据返回结果对象解析出支付状态 | |||
| * @param statusObject 支付端返回的查询对象 | |||
| * @param orderOutNo 传给第三方支付端的订单唯一标识 | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| public int queryPayStatus(PayQueryAdapterResult statusObject,String orderOutNo) throws Exception; | |||
| /** | |||
| * 查询支付结果,调用对应端的API查询支付结果 | |||
| * @param oldRecord WxPayOrder | |||
| * @param order WxOrder | |||
| * @param appInfo C端app | |||
| * @param payAccount WxPayAccount | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| public int queryPayStatusCode(WxPayOrder oldRecord,WxOrder order,WxAppinfo appInfo,WxPayAccount payAccount) throws Exception; | |||
| } | |||
| @@ -0,0 +1,22 @@ | |||
| package com.iformall.service.pay.service.pay.entity; | |||
| import java.io.Serializable; | |||
| import com.iformall.utils.UserUtil; | |||
| import lombok.AllArgsConstructor; | |||
| import lombok.Data; | |||
| @Data | |||
| @AllArgsConstructor | |||
| public class CreateCUser implements Serializable{ | |||
| private static final long serialVersionUID = 877618734961866171L; | |||
| private Long cUserId; | |||
| private Long basicUserId; | |||
| public boolean isBasicInfo() { | |||
| return UserUtil.CuserIsBasicInfo(basicUserId); | |||
| } | |||
| } | |||
| @@ -0,0 +1,50 @@ | |||
| package com.iformall.service.pay.service.pay.entity; | |||
| import java.io.Serializable; | |||
| public class PayAdapterResult implements Serializable{ | |||
| private static final long serialVersionUID = -6647306162758854293L; | |||
| private boolean isSuccess; | |||
| private String msg; | |||
| private Object data; | |||
| private String transactionId; | |||
| public PayAdapterResult() { | |||
| } | |||
| public PayAdapterResult(boolean isSuccess,String msg,Object data,String transactionId) { | |||
| this.isSuccess = isSuccess; | |||
| this.msg = msg; | |||
| this.data = data; | |||
| this.transactionId = transactionId; | |||
| } | |||
| public boolean isSuccess() { | |||
| return isSuccess; | |||
| } | |||
| public void setSuccess(boolean isSuccess) { | |||
| this.isSuccess = isSuccess; | |||
| } | |||
| public String getMsg() { | |||
| return msg; | |||
| } | |||
| public void setMsg(String msg) { | |||
| this.msg = msg; | |||
| } | |||
| public Object getData() { | |||
| return data; | |||
| } | |||
| public void setData(Object data) { | |||
| this.data = data; | |||
| } | |||
| public String getTransactionId() { | |||
| return transactionId; | |||
| } | |||
| public void setTransactionId(String transactionId) { | |||
| this.transactionId = transactionId; | |||
| } | |||
| } | |||
| @@ -0,0 +1,30 @@ | |||
| package com.iformall.service.pay.service.pay.entity; | |||
| import java.io.Serializable; | |||
| import lombok.Data; | |||
| import lombok.ToString; | |||
| @Data | |||
| @ToString | |||
| public class PayQueryAdapterResult implements Serializable{ | |||
| private static final long serialVersionUID = -8271349001408799798L; | |||
| public PayQueryAdapterResult(int code, String msg, Object data,String transactionId,String endTimeStr) { | |||
| this.code = code; | |||
| this.msg = msg; | |||
| this.data = data; | |||
| } | |||
| private int code; | |||
| private String msg; | |||
| private Object data; | |||
| private String transactionId; | |||
| private String endTimeStr; | |||
| } | |||
| @@ -0,0 +1,32 @@ | |||
| package com.iformall.service.pay.service.pay.wx; | |||
| import java.util.Map; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.service.helper.WxPayOrderServiceHelper; | |||
| import com.iformall.service.pay.service.pay.PayAdapterService; | |||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
| public class BaseWxPayAdapterService { | |||
| protected PayQueryAdapterResult queryPayStatus(WxPayOrder oldRecord, WxOrder order, WxAppinfo appInfo, WxPayAccount payAccount) | |||
| throws Exception { | |||
| Map<String, String> retMap = WxPayOrderServiceHelper.wxOrderPayStatusMap(oldRecord, order, appInfo, payAccount); | |||
| int code = WxPayOrderServiceHelper.getPayStatusFromMap(retMap,oldRecord.getPayOrderNo()); | |||
| String msg = WxPayOrderServiceHelper.getPayStatusMsg(retMap, oldRecord.getPayOrderNo()); | |||
| PayQueryAdapterResult result = new PayQueryAdapterResult(code, msg, retMap,retMap.get("transaction_id"),retMap.get("time_end")); | |||
| return result; | |||
| } | |||
| protected int queryPayStatus(PayQueryAdapterResult statusObject, String orderOutNo) throws Exception { | |||
| return WxPayOrderServiceHelper.getPayStatusFromMap((Map<String, String>) statusObject.getData(),orderOutNo); | |||
| } | |||
| protected int queryPayStatusCode(WxPayOrder oldRecord, WxOrder order, WxAppinfo appInfo, WxPayAccount payAccount) | |||
| throws Exception { | |||
| return WxPayOrderServiceHelper.wxOrderPayStatus(oldRecord, order, appInfo, payAccount); | |||
| } | |||
| } | |||
| @@ -0,0 +1,45 @@ | |||
| package com.iformall.service.pay.service.pay.wx.h5; | |||
| import java.util.Date; | |||
| import org.springframework.stereotype.Service; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.enums.EnumPayShare; | |||
| import com.iformall.service.pay.entity.PayExtraParam; | |||
| import com.iformall.service.pay.service.pay.CDrivingPayService; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
| import com.iformall.service.pay.service.pay.wx.BaseWxPayAdapterService; | |||
| @Service | |||
| public class WxH5PayService extends BaseWxPayAdapterService implements CDrivingPayService{ | |||
| @Override | |||
| public PayAdapterResult pay(WxPayAccount payAccount, WxOrder order, WxPayOrder record, EnumPayShare isShare, | |||
| WxAppinfo appInfo, Date currentDate, PayExtraParam params) throws Exception { | |||
| // TODO Auto-generated method stub | |||
| return null; | |||
| } | |||
| @Override | |||
| public PayQueryAdapterResult queryPayStatus(WxPayOrder oldRecord, WxOrder order, WxAppinfo appInfo, | |||
| WxPayAccount payAccount) throws Exception { | |||
| return super.queryPayStatus(oldRecord, order, appInfo, payAccount); | |||
| } | |||
| @Override | |||
| public int queryPayStatus(PayQueryAdapterResult statusObject, String orderOutNo) throws Exception { | |||
| return super.queryPayStatus(statusObject, orderOutNo); | |||
| } | |||
| @Override | |||
| public int queryPayStatusCode(WxPayOrder oldRecord, WxOrder order, WxAppinfo appInfo, WxPayAccount payAccount) | |||
| throws Exception { | |||
| return super.queryPayStatusCode(oldRecord, order, appInfo, payAccount); | |||
| } | |||
| } | |||
| @@ -0,0 +1,254 @@ | |||
| package com.iformall.service.pay.service.pay.wx.miniApp.appPay; | |||
| import java.util.Date; | |||
| import java.util.Map; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.stereotype.Service; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.enums.EnumPayMode; | |||
| import com.iformall.enums.EnumPayShare; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.pay.WxPay; | |||
| import com.iformall.pay.WxPayOrderP; | |||
| import com.iformall.pay.WxPayOrderSP; | |||
| import com.iformall.pay.WxPayment; | |||
| import com.iformall.service.pay.entity.PayExtraParam; | |||
| import com.iformall.service.pay.service.pay.CDrivingPayService; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
| import com.iformall.service.pay.service.pay.wx.BaseWxPayAdapterService; | |||
| import com.iformall.utils.BeanUtils; | |||
| import com.iformall.utils.MapUtil; | |||
| import com.iformall.utils.Utility; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| @Slf4j | |||
| @Service | |||
| public class WxMiniAppPayAdapterService extends BaseWxPayAdapterService implements CDrivingPayService{ | |||
| JSONObject errorMap = JSON.parseObject("{" + | |||
| "\"NOAUTH\":{\"detail\":\"商户无此接口权限\",\"reason\":\"商户未开通此接口权限\",\"resolution\":\"请商户前往申请此接口权限\"}," + | |||
| "\"NOTENOUGH\":{\"detail\":\"余额不足\",\"reason\":\"用户帐号余额不足\",\"resolution\":\"用户帐号余额不足,请用户充值或更换支付卡后再支付\"}," + | |||
| "\"ORDERPAID\":{\"detail\":\"商户订单已支付\",\"reason\":\"商户订单已支付,无需重复操作\",\"resolution\":\"商户订单已支付,无需更多操作\"}," + | |||
| "\"ORDERCLOSED\":{\"detail\":\"订单已关闭\",\"reason\":\"当前订单已关闭,无法支付\",\"resolution\":\"当前订单已关闭,请重新下单\"}," + | |||
| "\"SYSTEMERROR\":{\"detail\":\"系统错误\t\",\"reason\":\"系统超时\",\"resolution\":\"系统异常,请用相同参数重新调用\"}," + | |||
| "\"APPID_NOT_EXIST\":{\"detail\":\"APPID不存在\",\"reason\":\"参数中缺少APPID\",\"resolution\":\"请检查APPID是否正确\"}," + | |||
| "\"MCHID_NOT_EXIST\":{\"detail\":\"MCHID不存在\",\"reason\":\"参数中缺少MCHID\",\"resolution\":\"请检查MCHID是否正确\"}," + | |||
| "\"APPID_MCHID_NOT_MATCH\":{\"detail\":\"appid和mch_id不匹配\",\"reason\":\"appid和mch_id不匹配\",\"resolution\":\"请确认appid和mch_id是否匹配\"}," + | |||
| "\"LACK_PARAMS\":{\"detail\":\"缺少参数\t\",\"reason\":\"缺少必要的请求参数\",\"resolution\":\"请检查参数是否齐全\"}," + | |||
| "\"OUT_TRADE_NO_USED\":{\"detail\":\"商户订单号重复\",\"reason\":\"同一笔交易不能多次提交\",\"resolution\":\"请核实商户订单号是否重复提交\"}," + | |||
| "\"SIGNERROR\":{\"detail\":\"签名错误\",\"reason\":\"参数签名结果不正确\",\"resolution\":\"请检查签名参数和方法是否都符合签名算法要求\"}," + | |||
| "\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"resolution\":\"请检查XML参数格式是否正确\"}," + | |||
| "\"REQUIRE_POST_METHOD\":{\"detail\":\"请使用post方法\",\"reason\":\"未使用post传递参数\",\"resolution\":\"请检查请求参数是否通过post方法提交\"}," + | |||
| "\"POST_DATA_EMPTY\":{\"detail\":\"post数据为空\",\"reason\":\"post数据不能为空\",\"resolution\":\"请检查post数据是否为空\"}," + | |||
| "\"NOT_UTF8\":{\"detail\":\"编码格式错误\",\"reason\":\"未使用指定编码格式\",\"resolution\":\"请使用UTF-8编码格式\"}}"); | |||
| private WxPayOrderP generateWxPayOrderP(WxPayAccount payAccount, WxOrder order, WxPayOrder record,String openId,String appId,Date currentDate) throws Exception { | |||
| // 统一下单 普通商户模式 | |||
| String noncestr = Utility.generate32UUID(); | |||
| WxPayOrderP wxPayOrderP = new WxPayOrderP(); | |||
| wxPayOrderP.setOpenid(openId); | |||
| wxPayOrderP.setAppid(appId); | |||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | |||
| wxPayOrderP.setNonce_str(noncestr); | |||
| wxPayOrderP.setBody(order.getDetail()); | |||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||
| wxPayOrderP.setTotal_fee(order.getPayment()); | |||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||
| wxPayOrderP.setGoods_tag(String.valueOf(order.getProductId())); | |||
| wxPayOrderP.setNotify_url(payAccount.getPayNotifyUrl()); | |||
| wxPayOrderP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | |||
| wxPayOrderP.setProduct_id(String.valueOf(order.getId())); // 订单ID | |||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||
| Date futureDate = new Date(); | |||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderP); | |||
| wxPayOrderP.setSign(WxPayment.createSign(payOrderMap, payAccount.getApiKey())); | |||
| return wxPayOrderP; | |||
| } | |||
| private PayAdapterResult getOrderPResult(Map<String, String> returnMap,WxPayOrder record,WxPayAccount payAccount,String noncestr) { | |||
| PayAdapterResult par = new PayAdapterResult(); | |||
| returnMap.put("payOrderId", String.valueOf(record.getId())); | |||
| String result_code = returnMap.get("result_code"); | |||
| if ("SUCCESS".equals(result_code)) { | |||
| par.setSuccess(true); | |||
| par.setMsg("success."); | |||
| par.setData(returnMap); | |||
| String prepay_id = returnMap.get("prepay_id"); | |||
| // update payOrder with prepay_id | |||
| record.setPrepayId(prepay_id); | |||
| record.setUpdateTime(new Date()); | |||
| String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); | |||
| Map<String, String> sighMap = MapUtil.getOrderMap(); | |||
| sighMap.put("appId", returnMap.get("appid")); | |||
| sighMap.put("timeStamp", timestamp); | |||
| sighMap.put("nonceStr", noncestr); | |||
| sighMap.put("package", "prepay_id=" + prepay_id); | |||
| sighMap.put("signType", "MD5"); | |||
| String signAgent = WxPayment.createSign(sighMap, payAccount.getApiKey()); | |||
| returnMap.put("timeStamp", timestamp); | |||
| returnMap.put("nonceStr", noncestr); | |||
| returnMap.put("package", "prepay_id=" + prepay_id); | |||
| returnMap.put("paySign", signAgent); | |||
| log.info("back to UI: " + returnMap.toString()); | |||
| } else { | |||
| String errMsg = ""; | |||
| JSONObject errObj = errorMap.getJSONObject(result_code); | |||
| if (errObj != null) { | |||
| errMsg = errObj.toJSONString(); | |||
| record.setFailReason(errMsg); | |||
| } else { | |||
| errMsg = returnMap.get("return_msg"); | |||
| record.setFailReason(errMsg); | |||
| } | |||
| record.setUpdateTime(new Date()); | |||
| par.setSuccess(false); | |||
| par.setMsg(errMsg); | |||
| par.setData(returnMap); | |||
| } | |||
| return par; | |||
| } | |||
| private WxPayOrderSP generateWxPayOrderSP(WxPayAccount payAccount, WxOrder order, WxPayOrder record,WxAppinfo appInfo,String openId,String appId,Date currentDate,EnumPayShare isShare) throws Exception { | |||
| String noncestr = Utility.generate32UUID(); | |||
| WxPayOrderSP wxPayOrderSP = new WxPayOrderSP(); | |||
| wxPayOrderSP.setSub_openid(openId); | |||
| wxPayOrderSP.setAppid(appInfo.getParentAppId()); | |||
| wxPayOrderSP.setMch_id(payAccount.getMchId()); | |||
| wxPayOrderSP.setSub_appid(appId); | |||
| wxPayOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||
| wxPayOrderSP.setNonce_str(noncestr); | |||
| wxPayOrderSP.setBody(order.getDetail()); | |||
| wxPayOrderSP.setOut_trade_no(record.getPayOrderNo()); | |||
| wxPayOrderSP.setTotal_fee(order.getPayment().toString()); | |||
| wxPayOrderSP.setSpbill_create_ip(record.getIp()); // 终端IP | |||
| wxPayOrderSP.setGoods_tag(String.valueOf(order.getProductId())); // 券ID | |||
| wxPayOrderSP.setNotify_url(payAccount.getPayNotifyUrl()); | |||
| wxPayOrderSP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | |||
| wxPayOrderSP.setProduct_id(String.valueOf(order.getProductId())); // 券ID | |||
| wxPayOrderSP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||
| Date futureDate = new Date(); | |||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||
| wxPayOrderSP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||
| wxPayOrderSP.setSign_type("HMAC-SHA256"); | |||
| wxPayOrderSP.setProfit_sharing(null); | |||
| if (isShare == EnumPayShare.YES) { | |||
| wxPayOrderSP.setProfit_sharing("Y"); | |||
| } | |||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderSP); | |||
| wxPayOrderSP.setSign(WxPayment.createSignHMAC(payOrderMap, payAccount.getApiKey())); | |||
| return wxPayOrderSP; | |||
| } | |||
| private PayAdapterResult getOrderSPResult(Map<String, String> returnMap,WxPayOrder record,WxPayAccount payAccount,WxAppinfo appInfo,String noncestr) { | |||
| PayAdapterResult par = new PayAdapterResult(); | |||
| returnMap.put("payOrderId", String.valueOf(record.getId())); | |||
| String result_code = returnMap.get("result_code"); | |||
| if ("SUCCESS".equals(result_code)) { | |||
| par.setSuccess(true); | |||
| par.setMsg("success."); | |||
| par.setData(returnMap); | |||
| String prepay_id = returnMap.get("prepay_id"); | |||
| // update payOrder with prepay_id | |||
| record.setPrepayId(prepay_id); | |||
| record.setUpdateTime(new Date()); | |||
| String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); | |||
| Map<String, String> sighMap = MapUtil.getOrderMap(); | |||
| sighMap.put("appId", appInfo.getAppId()); | |||
| sighMap.put("timeStamp", timestamp); | |||
| sighMap.put("nonceStr", noncestr); | |||
| sighMap.put("package", "prepay_id=" + prepay_id); | |||
| sighMap.put("signType", "HMAC-SHA256"); | |||
| String signAgent = WxPayment.createSignHMAC(sighMap, payAccount.getApiKey()); | |||
| returnMap.put("timeStamp", timestamp); | |||
| returnMap.put("nonceStr", noncestr); | |||
| returnMap.put("package", "prepay_id=" + prepay_id); | |||
| returnMap.put("paySign", signAgent); | |||
| returnMap.put("signType", "HMAC-SHA256"); | |||
| log.info("back to UI: " + returnMap.toString()); | |||
| } else { | |||
| String errMsg = ""; | |||
| JSONObject errObj = errorMap.getJSONObject(result_code); | |||
| if (errObj != null) { | |||
| errMsg = errObj.toJSONString(); | |||
| record.setFailReason(errMsg); | |||
| } else { | |||
| errMsg = returnMap.get("return_msg"); | |||
| record.setFailReason(errMsg); | |||
| } | |||
| record.setUpdateTime(new Date()); | |||
| par.setSuccess(false); | |||
| par.setMsg(errMsg); | |||
| par.setData(returnMap); | |||
| } | |||
| return par; | |||
| } | |||
| @Override | |||
| public PayAdapterResult pay(WxPayAccount payAccount, WxOrder order, WxPayOrder record,EnumPayShare isShare,WxAppinfo appInfo,Date currentDate, PayExtraParam params) throws Exception { | |||
| if (null == params ) { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"openId为空"); | |||
| } | |||
| String openId = (String) params.getValue("openId"); | |||
| if (StringUtils.isBlank(openId) ) { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"openId为空"); | |||
| } | |||
| //普通商户模式 | |||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||
| WxPayOrderP wxPayOrderP = generateWxPayOrderP(payAccount,order,record,openId,appInfo.getAppId(),currentDate); | |||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderP)); | |||
| log.info("pay order, wechat pushOrder, " + wxPayOrderP.toString() + ", response: " + response.toString()); | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| return getOrderPResult(returnMap,record,payAccount,wxPayOrderP.getNonce_str()); | |||
| } else { | |||
| // 统一下单 // 服务商模式 | |||
| WxPayOrderSP wxPayOrderSP = generateWxPayOrderSP(payAccount,order,record,appInfo,openId,appInfo.getAppId(),currentDate,isShare); | |||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderSP)); | |||
| log.info("pay order, wechat pushOrder, " + wxPayOrderSP.toString() + ", response: " + response.toString()); | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| return getOrderSPResult(returnMap,record,payAccount,appInfo,wxPayOrderSP.getNonce_str()); | |||
| } | |||
| } | |||
| @Override | |||
| public PayQueryAdapterResult queryPayStatus(WxPayOrder oldRecord, WxOrder order, WxAppinfo appInfo, | |||
| WxPayAccount payAccount) throws Exception { | |||
| return super.queryPayStatus(oldRecord, order, appInfo, payAccount); | |||
| } | |||
| @Override | |||
| public int queryPayStatus(PayQueryAdapterResult statusObject, String orderOutNo) throws Exception { | |||
| return super.queryPayStatus(statusObject, orderOutNo); | |||
| } | |||
| @Override | |||
| public int queryPayStatusCode(WxPayOrder oldRecord, WxOrder order, WxAppinfo appInfo, WxPayAccount payAccount) | |||
| throws Exception { | |||
| return super.queryPayStatusCode(oldRecord, order, appInfo, payAccount); | |||
| } | |||
| } | |||
| @@ -0,0 +1,250 @@ | |||
| package com.iformall.service.pay.service.pay.wx.miniApp.maPay; | |||
| import java.util.Date; | |||
| import java.util.Map; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.enums.EnumPayMode; | |||
| import com.iformall.enums.EnumPayShare; | |||
| import com.iformall.enums.EnumUserIsSubscribe; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxCUserMapper; | |||
| import com.iformall.pay.WxMicroPayOrderP; | |||
| import com.iformall.pay.WxMicroPayOrderSP; | |||
| import com.iformall.pay.WxPay; | |||
| import com.iformall.pay.WxPayment; | |||
| import com.iformall.service.WxCUserService; | |||
| import com.iformall.service.pay.entity.PayExtraParam; | |||
| import com.iformall.service.pay.service.pay.CPassivePayService; | |||
| import com.iformall.service.pay.service.pay.entity.CreateCUser; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
| import com.iformall.service.pay.service.pay.wx.BaseWxPayAdapterService; | |||
| import com.iformall.utils.BeanUtils; | |||
| import com.iformall.utils.Utility; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| @Slf4j | |||
| @Service | |||
| public class WxMiniMaPayAdapterService extends BaseWxPayAdapterService implements CPassivePayService{ | |||
| private WxMicroPayOrderP generateWxMicroPayOrderP(WxPayAccount payAccount, WxOrder order, WxPayOrder record, EnumPayShare isShare, | |||
| WxAppinfo appInfo, Date currentDate,String bAppId,String bUserPhone) throws Exception { | |||
| String noncestr = Utility.generate32UUID(); | |||
| WxMicroPayOrderP wxPayOrderP = new WxMicroPayOrderP(); | |||
| wxPayOrderP.setAppid(bAppId); | |||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | |||
| wxPayOrderP.setDevice_info(bUserPhone); | |||
| wxPayOrderP.setNonce_str(noncestr); | |||
| wxPayOrderP.setBody(order.getDetail()); | |||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||
| wxPayOrderP.setTotal_fee(record.getPayAmount()); | |||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||
| wxPayOrderP.setAuth_code(record.getAuthCode()); | |||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||
| Date futureDate = new Date(); | |||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderP); | |||
| wxPayOrderP.setSign(WxPayment.createSign(payOrderMap, payAccount.getApiKey())); | |||
| return wxPayOrderP; | |||
| } | |||
| private PayAdapterResult getWxMicroPayOrderPResult(Map<String, String> returnMap,WxPayOrder record,WxPayAccount payAccount) { | |||
| String return_code = returnMap.get("return_code"); | |||
| String result_code = returnMap.get("result_code"); | |||
| PayAdapterResult pr = null; | |||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||
| if ("SUCCESS".equals(result_code)) { | |||
| String openId = returnMap.get("openid"); | |||
| String isSubscribe = returnMap.get("is_subscribe"); | |||
| String transactionId = returnMap.get("transaction_id"); | |||
| record.setTransactionId(transactionId); | |||
| record.setUpdateTime(new Date()); | |||
| pr = new PayAdapterResult(true, "success", returnMap,transactionId); | |||
| } else { | |||
| String err_code = returnMap.get("err_code"); | |||
| String errMsg = returnMap.get("err_code_des"); | |||
| if (errMsg.length() <= 0) { | |||
| errMsg = returnMap.get("return_msg"); | |||
| } | |||
| record.setFailReason(errMsg); | |||
| record.setUpdateTime(new Date()); | |||
| pr = new PayAdapterResult(false, errMsg, returnMap,null); | |||
| } | |||
| } else { | |||
| String errMsg = returnMap.get("return_msg"); | |||
| record.setFailReason(errMsg); | |||
| record.setUpdateTime(new Date()); | |||
| pr = new PayAdapterResult(false, errMsg, returnMap,null); | |||
| } | |||
| return pr; | |||
| } | |||
| private WxMicroPayOrderSP generateWxMicroPayOrderSP(WxPayAccount payAccount, WxOrder order, WxPayOrder record, EnumPayShare isShare, | |||
| WxAppinfo appInfo, Date currentDate,String bUserPhone) throws Exception { | |||
| String noncestr = Utility.generate32UUID(); | |||
| WxMicroPayOrderSP wxPayOrderSP = new WxMicroPayOrderSP(); | |||
| wxPayOrderSP.setAppid(appInfo.getParentAppId()); | |||
| wxPayOrderSP.setMch_id(payAccount.getMchId()); | |||
| wxPayOrderSP.setSub_appid(appInfo.getAppId()); | |||
| wxPayOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||
| wxPayOrderSP.setDevice_info(bUserPhone); | |||
| wxPayOrderSP.setNonce_str(noncestr); | |||
| wxPayOrderSP.setBody(order.getDetail()); | |||
| wxPayOrderSP.setOut_trade_no(record.getPayOrderNo()); | |||
| wxPayOrderSP.setTotal_fee(record.getPayAmount()); | |||
| wxPayOrderSP.setSpbill_create_ip(record.getIp()); | |||
| wxPayOrderSP.setAuth_code(record.getAuthCode()); | |||
| wxPayOrderSP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||
| Date futureDate = new Date(); | |||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||
| wxPayOrderSP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||
| wxPayOrderSP.setSign_type("HMAC-SHA256"); | |||
| wxPayOrderSP.setProfit_sharing(null); | |||
| if (isShare == EnumPayShare.YES) { | |||
| wxPayOrderSP.setProfit_sharing("Y"); | |||
| } | |||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderSP); | |||
| wxPayOrderSP.setSign(WxPayment.createSignHMAC(payOrderMap, payAccount.getApiKey())); | |||
| return wxPayOrderSP; | |||
| } | |||
| private PayAdapterResult getWxMicroPayOrderSPResutl(Map<String, String> returnMap,WxPayOrder record,WxPayAccount payAccount) { | |||
| PayAdapterResult pr = null; | |||
| String return_code = returnMap.get("return_code"); | |||
| String result_code = returnMap.get("result_code"); | |||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||
| if ("SUCCESS".equals(result_code)) { | |||
| String openId = returnMap.get("sub_openid"); | |||
| String isSubscribe = returnMap.get("sub_is_subscribe"); | |||
| String transactionId = returnMap.get("transaction_id"); | |||
| record.setTransactionId(transactionId); | |||
| record.setUpdateTime(new Date()); | |||
| pr = new PayAdapterResult(true, "success", returnMap,transactionId); | |||
| } else { | |||
| String err_code = returnMap.get("err_code"); | |||
| String errMsg = returnMap.get("err_code_des"); | |||
| if (errMsg.length() <= 0) { | |||
| errMsg = returnMap.get("return_msg"); | |||
| } | |||
| record.setFailReason(errMsg); | |||
| record.setUpdateTime(new Date()); | |||
| pr = new PayAdapterResult(false, errMsg, returnMap,null); | |||
| } | |||
| } else { | |||
| String errMsg = returnMap.get("return_msg"); | |||
| record.setFailReason(errMsg); | |||
| record.setUpdateTime(new Date()); | |||
| pr = new PayAdapterResult(false, errMsg, returnMap,null); | |||
| } | |||
| return pr; | |||
| } | |||
| @Override | |||
| public PayAdapterResult pay(WxPayAccount payAccount, WxOrder order, WxPayOrder record, EnumPayShare isShare, | |||
| WxAppinfo appInfo, Date currentDate, PayExtraParam params) throws Exception { | |||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||
| // 扫码支付 普通商户模式 | |||
| String bAppId = (String) params.getValue("bAppId"); | |||
| if (StringUtils.isBlank(bAppId)) { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"bAppId 不能为空"); | |||
| } | |||
| String bUserPhone = (String) params.getValue("bUserPhone"); | |||
| if (StringUtils.isBlank(bUserPhone)) { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"bUserPhone 不能为空"); | |||
| } | |||
| WxMicroPayOrderP wxPayOrderP = generateWxMicroPayOrderP(payAccount, order, record, isShare, appInfo, currentDate, bAppId, bUserPhone); | |||
| String response = WxPay.micropay(BeanUtils.toStringMap(wxPayOrderP)); | |||
| log.info("pay order, wechat micropay, " + wxPayOrderP.toString() + ", response: " + response.toString()); | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| returnMap.put("payOrderId", record.getPayOrderNo()); | |||
| returnMap.put("orderId", String.valueOf(order.getId())); | |||
| return getWxMicroPayOrderPResult(returnMap, record, payAccount); | |||
| } else { | |||
| // 统一下单 // 服务商模式 | |||
| String bUserPhone = (String) params.getValue("bUserPhone"); | |||
| if (StringUtils.isBlank(bUserPhone)) { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"bUserPhone 不能为空"); | |||
| } | |||
| WxMicroPayOrderSP wxPayOrderSP = generateWxMicroPayOrderSP(payAccount, order, record, isShare, appInfo, currentDate, bUserPhone); | |||
| String response = WxPay.micropay(BeanUtils.toStringMap(wxPayOrderSP)); | |||
| log.info("pay order, wechat micropay, " + wxPayOrderSP.toString() + ", response: " + response.toString()); | |||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||
| returnMap.put("payOrderId", record.getPayOrderNo()); | |||
| returnMap.put("orderId", String.valueOf(order.getId())); | |||
| return getWxMicroPayOrderSPResutl(returnMap, record, payAccount); | |||
| } | |||
| } | |||
| @Autowired | |||
| WxCUserMapper wxCUserMapper; | |||
| @Autowired | |||
| WxCUserService wxCUserService; | |||
| @Override | |||
| public CreateCUser createCUserAfterPay(Object result,WxAppinfo appInfo) throws Exception { | |||
| // add c_user, 收银台支付和券支付可能不是同一个人 | |||
| Date curDate = new Date(); | |||
| WxCUser userQ = new WxCUser(); | |||
| Map<String, String> returnMap = (Map<String, String>) result; | |||
| String openId = returnMap.get("sub_openid"); | |||
| String isSubscribe = returnMap.get("sub_is_subscribe"); | |||
| userQ.setOpenId(openId); | |||
| userQ.setAppId(appInfo.getAppId()); | |||
| WxCUser user1 = wxCUserMapper.findByOpenId(userQ); | |||
| if (user1 == null) { | |||
| userQ.setCreateDate(curDate); | |||
| userQ.setUpdateDate(curDate); | |||
| if ("N".equalsIgnoreCase(isSubscribe)) { | |||
| userQ.setIsSubscribe(EnumUserIsSubscribe.NO.getCode()); | |||
| } else { | |||
| userQ.setIsSubscribe(EnumUserIsSubscribe.YES.getCode()); | |||
| } | |||
| wxCUserService.saveOrUpdate(userQ); | |||
| } else { | |||
| userQ.setId(user1.getId()); | |||
| userQ.setUpdateDate(curDate); | |||
| userQ.setLoginCount(user1.getLoginCount()); | |||
| if ("N".equalsIgnoreCase(isSubscribe)) { | |||
| userQ.setIsSubscribe(EnumUserIsSubscribe.NO.getCode()); | |||
| } else { | |||
| userQ.setIsSubscribe(EnumUserIsSubscribe.YES.getCode()); | |||
| } | |||
| wxCUserService.saveOrUpdate(userQ); | |||
| } | |||
| return new CreateCUser(userQ.getId(),userQ.getUserId()); | |||
| } | |||
| @Override | |||
| public PayQueryAdapterResult queryPayStatus(WxPayOrder oldRecord, WxOrder order, WxAppinfo appInfo, | |||
| WxPayAccount payAccount) throws Exception { | |||
| return super.queryPayStatus(oldRecord, order, appInfo, payAccount); | |||
| } | |||
| @Override | |||
| public int queryPayStatus(PayQueryAdapterResult statusObject, String orderOutNo) throws Exception { | |||
| return super.queryPayStatus(statusObject, orderOutNo); | |||
| } | |||
| @Override | |||
| public int queryPayStatusCode(WxPayOrder oldRecord, WxOrder order, WxAppinfo appInfo, WxPayAccount payAccount) | |||
| throws Exception { | |||
| return super.queryPayStatusCode(oldRecord, order, appInfo, payAccount); | |||
| } | |||
| } | |||