| @@ -31,6 +31,37 @@ public class PosController extends BaseController { | |||||
| private final PosService posService; | private final PosService posService; | ||||
| private final ThDevInfoService thDevInfoService; | private final ThDevInfoService thDevInfoService; | ||||
| @ApiOperation(value = "获取会员折扣/优惠券是否启用", notes = "{" + | |||||
| "\"dev_id\":\"string(必填)\"," + | |||||
| "\"tenant_id\":\"string(必填)\"," + | |||||
| "\"nonce_str\":\"string(必填)\"}") | |||||
| @PostMapping("/getPosMemConfigStatus") | |||||
| public Map<String, String> getMemStatus(@RequestBody Map<String, String> params) { | |||||
| JSONObject payContent = new JSONObject(); | |||||
| // 1. check sign | |||||
| Map<String, String> retMap = checkSign(params, payContent); | |||||
| if (retMap != null) { | |||||
| // 签名相关异常返回 | |||||
| return retMap; | |||||
| } | |||||
| String resKey = payContent.getString("resKey"); | |||||
| logger.info("resKey: " + resKey); | |||||
| try { | |||||
| retMap = posService.getMemConfigStatus(params); | |||||
| return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", WxPayConstant.RET_SUCCESS, null); | |||||
| } catch (MallinkException e) { | |||||
| return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", WxPayConstant.RET_FAIL, | |||||
| e.getErrorCode(), | |||||
| e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", WxPayConstant.RET_FAIL, | |||||
| 500, | |||||
| e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation(value = "获取注册二维码及小票二维码规则", notes = "{" + | @ApiOperation(value = "获取注册二维码及小票二维码规则", notes = "{" + | ||||
| "\"dev_id\":\"string(必填)\"," + | "\"dev_id\":\"string(必填)\"," + | ||||
| "\"tenant_id\":\"string(必填)\"," + | "\"tenant_id\":\"string(必填)\"," + | ||||
| @@ -8,6 +8,13 @@ import java.util.Map; | |||||
| public interface PosService { | public interface PosService { | ||||
| /** | |||||
| * 获取商城会员设置状态 | |||||
| * @param params | |||||
| * @return | |||||
| */ | |||||
| Map<String, String> getMemConfigStatus(Map<String, String> params) throws MallinkException; | |||||
| /** | /** | ||||
| * 获取商城二维码 | * 获取商城二维码 | ||||
| * @param params | * @param params | ||||
| @@ -35,6 +35,7 @@ public class PosServiceImpl implements PosService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| private final WxMallService mallService; | private final WxMallService mallService; | ||||
| private final PosMallConfigService posMallConfigService; | |||||
| private final WxCUserService cUserService; | private final WxCUserService cUserService; | ||||
| private final WxLevelConfigService levelConfigService; | private final WxLevelConfigService levelConfigService; | ||||
| private final WxCouponOrderService couponOrderService; | private final WxCouponOrderService couponOrderService; | ||||
| @@ -49,6 +50,32 @@ public class PosServiceImpl implements PosService { | |||||
| private final WxCouponMerchantMapper couponMerchantMapper; | private final WxCouponMerchantMapper couponMerchantMapper; | ||||
| private final WxCouponMapper couponMapper; | private final WxCouponMapper couponMapper; | ||||
| /** | |||||
| * 获取商城会员设置状态 | |||||
| * @param params | |||||
| * @return | |||||
| */ | |||||
| @Override | |||||
| public Map<String, String> getMemConfigStatus(Map<String, String> params) throws MallinkException { | |||||
| Map<String, String> retMap = new HashMap<>(); | |||||
| String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID | |||||
| if (StringUtils.isBlank(tenantId)) { | |||||
| String errMessage = "request params[tenant_id] error."; | |||||
| logger.error(errMessage); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); | |||||
| } | |||||
| PosMallConfig config = posMallConfigService.getByTenantId(tenantId); | |||||
| if (config == null) { | |||||
| logger.error(ErrorCode.MALL_INFO_NOT_FOUND.getMessage()); | |||||
| throw new MallinkException(ErrorCode.MALL_INFO_NOT_FOUND); | |||||
| } | |||||
| retMap.put(WxPayConstant.MEM_DISCOUNT, String.valueOf(config.getDiscount().equals(EnumEnableType.Enable.getCode()))); | |||||
| retMap.put(WxPayConstant.MEM_COUPON, String.valueOf(config.getCoupon().equals(EnumEnableType.Enable.getCode()))); | |||||
| return retMap; | |||||
| } | |||||
| /** | /** | ||||
| * 获取商城二维码 | * 获取商城二维码 | ||||
| * @param params | * @param params | ||||
| @@ -79,6 +79,27 @@ public class PosAppTest { | |||||
| .andDo(MockMvcResultHandlers.print()); | .andDo(MockMvcResultHandlers.print()); | ||||
| } | } | ||||
| @Test | |||||
| public void getPosConfigTest() throws Exception { | |||||
| Map<String, String> reqObj = new HashMap<>(); | |||||
| reqObj.put(WxPayConstant.DEV_ID, devId); | |||||
| reqObj.put(WxPayConstant.TENANT_ID, tenantId); | |||||
| reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); | |||||
| String reqJsonStr = JSONObject.toJSONString(reqObj); | |||||
| RequestBuilder request = MockMvcRequestBuilders.post("/getPosMemConfigStatus") | |||||
| .contentType(MediaType.APPLICATION_JSON) | |||||
| .content(reqJsonStr); | |||||
| MvcResult result = mockMvc.perform(request).andReturn(); | |||||
| String responseStr = result.getResponse().getContentAsString(); | |||||
| System.out.println(responseStr); | |||||
| ObjectMapper mapper = new ObjectMapper(); | |||||
| Map<String,String> respMap = mapper.readValue(responseStr, Map.class); | |||||
| boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); | |||||
| System.out.println("response sign: " + resSigned); | |||||
| Assert.assertEquals(resSigned, true); | |||||
| } | |||||
| @Test | @Test | ||||
| public void getQrCodeTest() throws Exception { | public void getQrCodeTest() throws Exception { | ||||
| Map<String, String> reqObj = new HashMap<>(); | Map<String, String> reqObj = new HashMap<>(); | ||||
| @@ -0,0 +1,35 @@ | |||||
| package com.iformall.domain.po; | |||||
| import lombok.Data; | |||||
| import javax.persistence.*; | |||||
| import java.util.*; | |||||
| import java.math.*; | |||||
| import javax.persistence.Transient; | |||||
| import java.util.List; | |||||
| import javax.persistence.Id; | |||||
| import java.io.Serializable; | |||||
| @Table(name = "pos_mall_config") | |||||
| @Data | |||||
| public class PosMallConfig implements Serializable { | |||||
| private static final long serialVersionUID = 1L; | |||||
| @Id | |||||
| protected Long id; | |||||
| @Transient | |||||
| protected List<Long> ids; | |||||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | |||||
| private String tenantId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="会员折扣状态,0-使用中,1-禁用",name="discount") | |||||
| private Integer discount; | |||||
| @io.swagger.annotations.ApiModelProperty(value="会员优惠券状态,0-使用中,1-禁用",name="coupon") | |||||
| private Integer coupon; | |||||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||||
| private Date createDate; | |||||
| @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | |||||
| private Date updateDate; | |||||
| } | |||||
| @@ -0,0 +1,16 @@ | |||||
| package com.iformall.mapper; | |||||
| import java.util.*; | |||||
| import com.iformall.common.CommonMapper; | |||||
| import com.iformall.domain.po.PosMallConfig; | |||||
| public interface PosMallConfigMapper extends CommonMapper<PosMallConfig, Long> { | |||||
| List<PosMallConfig> findList(PosMallConfig posMallConfig); | |||||
| PosMallConfig getByTenantId(String tenantId); | |||||
| } | |||||
| @@ -36,6 +36,7 @@ public class WxPayConstant { | |||||
| public final static String MEM_DISCOUNT = "discount"; | public final static String MEM_DISCOUNT = "discount"; | ||||
| public final static String MEM_COUPON = "coupon"; | |||||
| public final static String MEM_LEVEL = "level"; | public final static String MEM_LEVEL = "level"; | ||||
| public final static String AVAIL_CO_LIST = "avail_co_list"; | public final static String AVAIL_CO_LIST = "avail_co_list"; | ||||
| public final static String ID = "id"; | public final static String ID = "id"; | ||||
| @@ -0,0 +1,55 @@ | |||||
| package com.iformall.service; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.domain.po.PosMallConfig; | |||||
| public interface PosMallConfigService { | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | |||||
| */ | |||||
| PageInfo<PosMallConfig> listAsPage(PosMallConfig record, Integer pageIndex, Integer pageSize); | |||||
| /** | |||||
| * 根据Id获得实体 | |||||
| * | |||||
| * @param id | |||||
| * @return | |||||
| */ | |||||
| PosMallConfig getById(Long id); | |||||
| /** | |||||
| * 根据TenantId获得实体 | |||||
| * | |||||
| * @param tenantId | |||||
| * @return | |||||
| */ | |||||
| PosMallConfig getByTenantId(String tenantId); | |||||
| /** | |||||
| * 保存或更新实体 | |||||
| * | |||||
| * @param record | |||||
| */ | |||||
| void saveOrUpdate(PosMallConfig record); | |||||
| /** | |||||
| * 根据Id删除实体 | |||||
| * | |||||
| * @param id | |||||
| */ | |||||
| void deleteById(Long id); | |||||
| } | |||||
| @@ -0,0 +1,60 @@ | |||||
| package com.iformall.service.impl; | |||||
| import java.util.*; | |||||
| import com.github.pagehelper.PageHelper; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.domain.po.PosMallConfig; | |||||
| import com.iformall.mapper.PosMallConfigMapper; | |||||
| import com.iformall.service.PosMallConfigService; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import com.iformall.common.IdWorker; | |||||
| @Service | |||||
| public class PosMallConfigServiceImpl implements PosMallConfigService { | |||||
| @Autowired | |||||
| PosMallConfigMapper posMallConfigMapper; | |||||
| @Override | |||||
| public PageInfo<PosMallConfig> listAsPage(PosMallConfig record, Integer pageIndex, Integer pageSize) { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> posMallConfigMapper.findList(record)); | |||||
| } | |||||
| @Override | |||||
| public PosMallConfig getById(Long id) { | |||||
| return posMallConfigMapper.selectByPrimaryKey(id); | |||||
| } | |||||
| @Override | |||||
| public PosMallConfig getByTenantId(String id) { | |||||
| PosMallConfig config = posMallConfigMapper.getByTenantId(id); | |||||
| return config; | |||||
| } | |||||
| @Override | |||||
| public void saveOrUpdate(PosMallConfig record) { | |||||
| if (record.getId() == null) { | |||||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| posMallConfigMapper.insertSelective(record); | |||||
| } else { | |||||
| posMallConfigMapper.updateByPrimaryKeySelective(record); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void deleteById(Long id) { | |||||
| posMallConfigMapper.deleteByPrimaryKey(id); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,63 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
| <mapper namespace="com.iformall.mapper.PosMallConfigMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.PosMallConfig"> | |||||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||||
| <result column="discount" jdbcType="INTEGER" property="discount" /> | |||||
| <result column="coupon" jdbcType="INTEGER" property="coupon" /> | |||||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | |||||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| `id`,`tenant_id`,`discount`,`coupon`,`create_date`,`update_date` | |||||
| </sql> | |||||
| <sql id="dynamicWhereConditions"> | |||||
| where 1 = 1 | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| <if test=" null != tenantId "> | |||||
| and `tenant_id` like concat('%', #{tenantId},'%') | |||||
| </if> | |||||
| <if test=" null != discount "> | |||||
| and `discount` = #{discount} | |||||
| </if> | |||||
| <if test=" null != coupon "> | |||||
| and `coupon` = #{coupon} | |||||
| </if> | |||||
| <if test=" null != createDate "> | |||||
| and `create_date` = #{createDate} | |||||
| </if> | |||||
| <if test=" null != updateDate "> | |||||
| and `update_date` = #{updateDate} | |||||
| </if> | |||||
| <if test=" null != ids "> | |||||
| and id in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
| #{idItem} | |||||
| </foreach> | |||||
| </if> | |||||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||||
| </sql> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.PosMallConfig" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from pos_mall_config | |||||
| <include refid="dynamicWhereConditions" /> | |||||
| </select> | |||||
| <select id="getByTenantId" parameterType="string" resultMap="BaseResultMap"> | |||||
| select | |||||
| <include refid="allColumns"/> | |||||
| from pos_mall_config | |||||
| where 1=1 and `tenant_id` = #{value} | |||||
| </select> | |||||
| </mapper> | |||||