| @@ -137,6 +137,7 @@ public class WxMerchantController extends BaseController { | |||||
| @PostMapping("updateMerchantLevel") | @PostMapping("updateMerchantLevel") | ||||
| public ResultData updateMerchantLevel(@RequestBody WxMerchant wxMerchant) { | public ResultData updateMerchantLevel(@RequestBody WxMerchant wxMerchant) { | ||||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::updateMerchantLevel"); | logger.debug("[" + getIpAddr() + "] WxMerchantController::updateMerchantLevel"); | ||||
| wxMerchant.setTenantId(getTenantId()); | |||||
| return wxMerchantService.updateMerchantLevel(wxMerchant); | return wxMerchantService.updateMerchantLevel(wxMerchant); | ||||
| } | } | ||||
| @@ -13,6 +13,7 @@ import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.domain.vo.WxCUserVo; | import com.iformall.domain.vo.WxCUserVo; | ||||
| import com.iformall.domain.vo.WxLevelMerchantCVo; | |||||
| import com.iformall.enums.EnumAssignTagsTrigger; | import com.iformall.enums.EnumAssignTagsTrigger; | ||||
| import com.iformall.enums.EnumScoreType; | import com.iformall.enums.EnumScoreType; | ||||
| import com.iformall.interceptor.AuthorizationInterceptor; | import com.iformall.interceptor.AuthorizationInterceptor; | ||||
| @@ -70,6 +71,7 @@ public class WxUserGrantController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| WxMerchantService wxMerchantService; | WxMerchantService wxMerchantService; | ||||
| /** | /** | ||||
| * 用户登录 | * 用户登录 | ||||
| * @param map | * @param map | ||||
| @@ -565,47 +567,30 @@ public class WxUserGrantController extends BaseController { | |||||
| * 获取用户折扣率 | * 获取用户折扣率 | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| @PostMapping("/getDiscount") | |||||
| @PostMapping("/getDiscountInfo") | |||||
| @ApiOperation(value = "获取用户折扣率", notes="") | @ApiOperation(value = "获取用户折扣率", notes="") | ||||
| public ResultData updateUserInfo(@RequestBody WxMerchant wxMerchant) { | |||||
| if (wxMerchant == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| public ResultData getDiscountInfo() { | |||||
| WxCUser user = getUser(); | WxCUser user = getUser(); | ||||
| WxCUserVo userVo = new WxCUserVo(); | |||||
| org.springframework.beans.BeanUtils.copyProperties(user, userVo); | |||||
| if (userVo.getScore() == null || userVo.getScore() == 0) { | |||||
| userVo.setLevelName("无"); | |||||
| userVo.setDiscountRate(10000); // 无折扣 | |||||
| } else { | |||||
| Integer levelConfigDiscount = null; | |||||
| List<WxLevelConfig> levelList = wxLevelConfigService.getByTenantId(user.getTenantId()); | |||||
| for(WxLevelConfig levelConfig: levelList) { | |||||
| if (userVo.getScore() >= levelConfig.getPoints()) { | |||||
| userVo.setLevelId(levelConfig.getId()); | |||||
| userVo.setLevelName(levelConfig.getLevel()); | |||||
| levelConfigDiscount = levelConfig.getDiscountEnable(); | |||||
| } | |||||
| } | |||||
| List<WxLevelConfig> levelList = wxLevelConfigService.getByTenantId(user.getTenantId()); | |||||
| if(levelConfigDiscount > 0) { | |||||
| // 用户折扣率 | |||||
| WxMerchant merchant = wxMerchantService.getById(wxMerchant.getId()); | |||||
| if(merchant != null) { | |||||
| if(levelConfigDiscount.equals(1)) { // first level | |||||
| userVo.setDiscountRate(merchant.getVipDiscountRate1()); | |||||
| } else if(levelConfigDiscount.equals(2)) { // second level | |||||
| userVo.setDiscountRate(merchant.getVipDiscountRate2()); | |||||
| } else if(levelConfigDiscount.equals(3)) { // third level | |||||
| userVo.setDiscountRate(merchant.getVipDiscountRate3()); | |||||
| } | |||||
| } | |||||
| String level = "无"; | |||||
| Long levelId = 0L; | |||||
| for(WxLevelConfig levelConfig: levelList) { | |||||
| if (user.getScore() >= levelConfig.getPoints()) { | |||||
| levelId = levelConfig.getId(); | |||||
| level = levelConfig.getLevel(); | |||||
| } | } | ||||
| } | } | ||||
| return new ResultData(userVo); | |||||
| WxLevelMerchant levelMerchant = new WxLevelMerchant(); | |||||
| levelMerchant.setLevelId(levelId); | |||||
| List<WxLevelMerchantCVo> levelMerchantList = wxLevelConfigService.findListCVo(levelMerchant); | |||||
| Map<String,Object> result = new HashMap(); | |||||
| result.put("level",level); | |||||
| result.put("levelMerchantList",levelMerchantList); | |||||
| return new ResultData(result); | |||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,73 @@ | |||||
| package com.iformall.domain.vo; | |||||
| import javax.persistence.Id; | |||||
| public class WxLevelMerchantCVo { | |||||
| private static final long serialVersionUID = 6687964942922444531L; | |||||
| @Id | |||||
| protected Long id; | |||||
| public Long getId() { | |||||
| return id; | |||||
| } | |||||
| public void setId(Long id) { | |||||
| this.id = id; | |||||
| } | |||||
| /**商户名**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="商户名",name="name") | |||||
| private String merchantName; | |||||
| /**联系方式**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="商户联系方式",name="linkPhone") | |||||
| private String merchantLinkPhone; | |||||
| @io.swagger.annotations.ApiModelProperty(value="商铺编号",name="shopNumber") | |||||
| private String shopNumber; | |||||
| /**楼座号**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="楼座",name="buildingName") | |||||
| private String buildingName; | |||||
| /**楼层号**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="楼层",name="floorName") | |||||
| private String floorName; | |||||
| /**折扣**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="折扣",name="discount") | |||||
| private Integer discount; | |||||
| public String getBuildingName() {return buildingName; } | |||||
| public void setBuildingName(String _building) { | |||||
| buildingName = _building; | |||||
| } | |||||
| public String getFloorName() { | |||||
| return floorName; | |||||
| } | |||||
| public void setFloorName(String _floor) { | |||||
| floorName = _floor; | |||||
| } | |||||
| public String getShopNumber() { | |||||
| return shopNumber; | |||||
| } | |||||
| public void setShopNumber(String _shopNumber) { | |||||
| shopNumber = _shopNumber; | |||||
| } | |||||
| public String getMerchantName() { | |||||
| return merchantName; | |||||
| } | |||||
| public void setMerchantName(String _name) { | |||||
| merchantName = _name; | |||||
| } | |||||
| public String getMerchantLinkPhone() { | |||||
| return merchantLinkPhone; | |||||
| } | |||||
| public void setMerchantLinkPhone(String _linkPhone) { | |||||
| merchantLinkPhone = _linkPhone; | |||||
| } | |||||
| public Integer getDiscount() { | |||||
| return discount; | |||||
| } | |||||
| public void setDiscount(Integer discount) { | |||||
| this.discount = discount; | |||||
| } | |||||
| } | |||||
| @@ -3,9 +3,11 @@ package com.iformall.mapper; | |||||
| import com.iformall.common.CommonMapper; | import com.iformall.common.CommonMapper; | ||||
| import com.iformall.domain.po.WxLevelMerchant; | import com.iformall.domain.po.WxLevelMerchant; | ||||
| import com.iformall.domain.vo.WxLevelMerchantCVo; | |||||
| import java.util.List; | import java.util.List; | ||||
| public interface WxLevelMerchantMapper extends CommonMapper<WxLevelMerchant, Long> { | public interface WxLevelMerchantMapper extends CommonMapper<WxLevelMerchant, Long> { | ||||
| List<WxLevelMerchant> findList(WxLevelMerchant wxLevelMerchant); | List<WxLevelMerchant> findList(WxLevelMerchant wxLevelMerchant); | ||||
| List<WxLevelMerchantCVo> findListCVo(WxLevelMerchant wxLevelMerchant); | |||||
| } | } | ||||
| @@ -3,6 +3,8 @@ package com.iformall.service; | |||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.domain.po.WxLevelConfig; | import com.iformall.domain.po.WxLevelConfig; | ||||
| import com.iformall.domain.po.WxLevelMerchant; | |||||
| import com.iformall.domain.vo.WxLevelMerchantCVo; | |||||
| import java.util.List; | import java.util.List; | ||||
| @@ -21,7 +23,8 @@ public interface WxLevelConfigService { | |||||
| List<WxLevelConfig> listByMerchantId(Long merchantId, WxLevelConfig record); | List<WxLevelConfig> listByMerchantId(Long merchantId, WxLevelConfig record); | ||||
| void batchSaveByMerchantId(Long merchantId, List<WxLevelConfig> records); | |||||
| void batchSaveByMerchantId(String tenantId, Long merchantId, List<WxLevelConfig> records); | |||||
| /** | /** | ||||
| * getByTenantId | * getByTenantId | ||||
| * @param tenantId | * @param tenantId | ||||
| @@ -80,6 +83,8 @@ public interface WxLevelConfigService { | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| List<WxLevelConfig> findList(WxLevelConfig record); | List<WxLevelConfig> findList(WxLevelConfig record); | ||||
| List<WxLevelMerchantCVo> findListCVo(WxLevelMerchant record); | |||||
| } | } | ||||
| @@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.domain.po.WxLevelConfig; | import com.iformall.domain.po.WxLevelConfig; | ||||
| import com.iformall.domain.po.WxLevelMerchant; | import com.iformall.domain.po.WxLevelMerchant; | ||||
| import com.iformall.domain.vo.WxLevelMerchantCVo; | |||||
| import com.iformall.mapper.WxLevelConfigMapper; | import com.iformall.mapper.WxLevelConfigMapper; | ||||
| import com.iformall.mapper.WxLevelMerchantMapper; | import com.iformall.mapper.WxLevelMerchantMapper; | ||||
| import com.iformall.service.WxLevelConfigService; | import com.iformall.service.WxLevelConfigService; | ||||
| @@ -57,7 +58,7 @@ public class WxLevelConfigServiceImpl implements WxLevelConfigService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void batchSaveByMerchantId(Long merchantId, List<WxLevelConfig> records) { | |||||
| public void batchSaveByMerchantId(String tenantId, Long merchantId, List<WxLevelConfig> records) { | |||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| records.stream().forEach(l->{ | records.stream().forEach(l->{ | ||||
| @@ -72,8 +73,9 @@ public class WxLevelConfigServiceImpl implements WxLevelConfigService { | |||||
| }else { | }else { | ||||
| wxLevelMerchantParam.setId(idWorker.nextId()); | wxLevelMerchantParam.setId(idWorker.nextId()); | ||||
| wxLevelMerchantParam.setCreateDate(new Date()); | wxLevelMerchantParam.setCreateDate(new Date()); | ||||
| wxLevelMerchantParam.setTenantId(tenantId); | |||||
| wxLevelMerchantParam.setDiscount(DEFAULT_MERCHANT_DISCOUNT); | wxLevelMerchantParam.setDiscount(DEFAULT_MERCHANT_DISCOUNT); | ||||
| wxLevelMerchantapper.insertSelective(wxLevelMerchant); | |||||
| wxLevelMerchantapper.insertSelective(wxLevelMerchantParam); | |||||
| } | } | ||||
| }); | }); | ||||
| @@ -162,5 +164,9 @@ public class WxLevelConfigServiceImpl implements WxLevelConfigService { | |||||
| return wxLevelConfigMapper.getLevel(tenantId,score); | return wxLevelConfigMapper.getLevel(tenantId,score); | ||||
| } | } | ||||
| @Override | |||||
| public List<WxLevelMerchantCVo> findListCVo(WxLevelMerchant record) { | |||||
| return wxLevelMerchantapper.findListCVo(record); | |||||
| } | |||||
| } | } | ||||
| @@ -518,7 +518,7 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||||
| @Override | @Override | ||||
| public ResultData updateMerchantLevel(WxMerchant wxMerchant) { | public ResultData updateMerchantLevel(WxMerchant wxMerchant) { | ||||
| try { | try { | ||||
| wxLevelConfigService.batchSaveByMerchantId(wxMerchant.getId(), wxMerchant.getLevelConfigList()); | |||||
| wxLevelConfigService.batchSaveByMerchantId(wxMerchant.getTenantId(), wxMerchant.getId(), wxMerchant.getLevelConfigList()); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("db failed: 账号操作失败, e:" + e.getMessage()); | logger.error("db failed: 账号操作失败, e:" + e.getMessage()); | ||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); | throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); | ||||
| @@ -62,4 +62,38 @@ | |||||
| </select> | </select> | ||||
| <resultMap id="CVoResultMap" type="com.iformall.domain.vo.WxLevelMerchantCVo"> | |||||
| <id column="id" jdbcType="BIGINT" property="id"/> | |||||
| <result column="name" jdbcType="VARCHAR" property="merchantName"/> | |||||
| <result column="link_phone" jdbcType="VARCHAR" property="merchantLinkPhone"/> | |||||
| <result column="shop_number" jdbcType="VARCHAR" property="shopNumber"/> | |||||
| <result column="building_name" jdbcType="VARCHAR" property="buildingName"/> | |||||
| <result column="floor_name" jdbcType="VARCHAR" property="floorName"/> | |||||
| <result column="discount" jdbcType="INTEGER" property="discount" /> | |||||
| </resultMap> | |||||
| <sql id="allCVoColumns"> | |||||
| m.id,m.name,m.link_phone, | |||||
| s.shop_number, | |||||
| mb.building_name, | |||||
| mf.floor_name, | |||||
| lm.discount | |||||
| </sql> | |||||
| <select id="findListCVo" parameterType="com.iformall.domain.po.WxLevelMerchant" resultMap="CVoResultMap"> | |||||
| select <include refid="allCVoColumns" /> | |||||
| from wx_level_merchant lm | |||||
| inner join wx_merchant m on m.status = 1 | |||||
| left join wx_merchant_shop ms on ms.merchant_id = m.id and ms.is_del = 0 | |||||
| left join wx_shop s on ms.shop_id = s.id | |||||
| left join wx_mall_building mb on s.building = mb.id | |||||
| left join wx_mall_floor mf on s.floor = mf.id | |||||
| <if test=" null != levelId "> | |||||
| and `level_id` = #{levelId} | |||||
| </if> | |||||
| </select> | |||||
| </mapper> | </mapper> | ||||