1. 每天登录首次给成长值 2. 消费金额为0时,不给成长值。 3. 消费金额除以1元,四舍五入给成长值 4. 绑车牌获得成长值 5. 微信昵称授权获取成长值 6. 微信手机授权获取成长值release_toaliyun_real
| @@ -23,50 +23,18 @@ public class WxScoreRulesController extends BaseController { | |||
| @Autowired | |||
| private WxScoreRulesService wxScoreRulesService; | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||
| public ResultData list(@ModelAttribute WxScoreRules wxScoreRules, Integer pageNum, Integer pageSize) { | |||
| if (null == wxScoreRules) wxScoreRules = new WxScoreRules(); | |||
| wxScoreRules.setTenantId(getTenantId()); | |||
| final PageInfo<WxScoreRules> page = wxScoreRulesService.listAsPage(wxScoreRules, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| @ApiOperation("成长值配置") | |||
| @GetMapping("setting") | |||
| public ResultData list() { | |||
| WxScoreRules scoreRules = wxScoreRulesService.getScoreRules(getTenantId()); | |||
| return new ResultData(scoreRules); | |||
| } | |||
| @ApiOperation("新增接口") | |||
| @PostMapping("add") | |||
| public ResultData add(@RequestBody WxScoreRules wxScoreRules) { | |||
| //Assert.notNull(wxScoreRules.getName(), "角色名不能为空"); | |||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||
| wxScoreRules.setTenantId(getTenantId()); | |||
| wxScoreRulesService.saveOrUpdate(wxScoreRules); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("根据id更新接口") | |||
| @PostMapping("update") | |||
| public ResultData update(@RequestBody WxScoreRules wxScoreRules) { | |||
| wxScoreRules.setTenantId(getTenantId()); | |||
| wxScoreRulesService.saveOrUpdate(wxScoreRules); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("根据id删除接口") | |||
| @GetMapping("/del") | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| public ResultData delete(Long id) { | |||
| wxScoreRulesService.deleteById(id); | |||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||
| } | |||
| @ApiOperation("根据id查询接口") | |||
| @GetMapping("/findById") | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| public ResultData findById(Long id) { | |||
| return new ResultData(Result.SUCCESS, "查询成功", wxScoreRulesService.getById(id)); | |||
| } | |||
| } | |||
| @@ -49,6 +49,9 @@ public class WxCarController extends BaseController { | |||
| @Autowired | |||
| WxCouponOrderService wxCouponOrderService; | |||
| @Autowired | |||
| WxScoreRulesService wxScoreRulesService; | |||
| private WxPark getCurrentPark(WxCUser user) { | |||
| WxPark parkQ = new WxPark(); | |||
| parkQ.setTenantId(user.getTenantId()); | |||
| @@ -256,6 +259,8 @@ public class WxCarController extends BaseController { | |||
| userCar.setCreateDate(curr); | |||
| userCar.setUpdateDate(curr); | |||
| wxCUserCarService.saveOrUpdate(userCar); | |||
| wxScoreRulesService.bindCarAddScore(userCar); | |||
| JSONObject dataObj = retObj.getJSONObject("data"); | |||
| return new ResultData(dataObj); | |||
| } else { | |||
| @@ -309,6 +314,7 @@ public class WxCarController extends BaseController { | |||
| userCar.setUpdateDate(curr); | |||
| try { | |||
| wxCUserCarService.save(userCar); | |||
| wxScoreRulesService.bindCarAddScore(userCar); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.DB_FAIL.getCode(), "TJD保存车牌失败, e:" + e.getMessage()); | |||
| @@ -13,6 +13,7 @@ import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCUserCar; | |||
| import com.iformall.service.WxCUserCarService; | |||
| import com.iformall.service.WxCUserService; | |||
| import com.iformall.service.WxScoreRulesService; | |||
| import com.iformall.utils.IPUtil; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| @@ -47,6 +48,9 @@ public class WxUserGrantController extends BaseController { | |||
| @Autowired | |||
| private WxCUserCarService wxCUserCarService; | |||
| @Autowired | |||
| private WxScoreRulesService wxScoreRulesService; | |||
| /** | |||
| * 用户登录 | |||
| * @param map | |||
| @@ -114,9 +118,15 @@ public class WxUserGrantController extends BaseController { | |||
| if (user1.getScene() == null || user1.getScene().equals("undefined")) | |||
| user1.setScene(scene); | |||
| if (!StringUtils.isBlank(longitude)) | |||
| user.setLongitude(BigDecimal.valueOf(Double.valueOf(longitude))); | |||
| user1.setLongitude(BigDecimal.valueOf(Double.valueOf(longitude))); | |||
| if (!StringUtils.isBlank(latitude)) | |||
| user.setLatitude(BigDecimal.valueOf(Double.valueOf(latitude))); | |||
| user1.setLatitude(BigDecimal.valueOf(Double.valueOf(latitude))); | |||
| // 成长值 | |||
| try { | |||
| wxCUserService.scoreCalculate(user1, false); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| wxCUserService.saveOrUpdate(user1); | |||
| resultMap.put("token", token); | |||
| } else { | |||
| @@ -124,9 +134,9 @@ public class WxUserGrantController extends BaseController { | |||
| user.createToken(new Date()); | |||
| token = user.getToken(); | |||
| user.setRegisterIp(ipaddress); | |||
| if (user.getSceneAddress() == null || user1.getSceneAddress().equals("undefined")) | |||
| if (user.getSceneAddress() == null || user.getSceneAddress().equals("undefined")) | |||
| user.setSceneAddress(sceneAddress); | |||
| if (user.getScene() == null || user1.getScene().equals("undefined")) | |||
| if (user.getScene() == null || user.getScene().equals("undefined")) | |||
| user.setScene(scene); | |||
| user.setSessionKey(session_key); | |||
| if (!StringUtils.isBlank(longitude)) | |||
| @@ -134,6 +144,12 @@ public class WxUserGrantController extends BaseController { | |||
| if (!StringUtils.isBlank(latitude)) | |||
| user.setLatitude(BigDecimal.valueOf(Double.valueOf(latitude))); | |||
| wxCUserService.saveOrUpdate(user); | |||
| // 成长值 | |||
| try { | |||
| wxCUserService.scoreCalculate(user, true); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| resultMap.put("token", token); | |||
| } | |||
| } catch (Exception e) { | |||
| @@ -141,12 +157,7 @@ public class WxUserGrantController extends BaseController { | |||
| return new ResultData(ErrorCode.DB_FAIL.getCode(), "wx_c_user数据库保存出错", resultMap); | |||
| } | |||
| // 成长值 | |||
| try { | |||
| wxCUserService.scoreCalculate(user.getTenantId(), user.getId()); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| return new ResultData(resultMap); | |||
| } | |||
| @@ -193,6 +204,9 @@ public class WxUserGrantController extends BaseController { | |||
| user.setLanguage(userInfo.getLanguage()); | |||
| wxCUserService.saveOrUpdate(user); | |||
| // 成长值 | |||
| wxScoreRulesService.personAddScore(user); | |||
| resultMap.put("openId", user.getOpenId()); | |||
| resultMap.put("unionId", user.getUnionId()); | |||
| resultMap.put("msg", "获取用户信息成功!"); | |||
| @@ -245,6 +259,10 @@ public class WxUserGrantController extends BaseController { | |||
| user.setPurePhone(phoneNoInfo.getPurePhoneNumber()); | |||
| user.setCountryCode(phoneNoInfo.getCountryCode()); | |||
| wxCUserService.saveOrUpdate(user); | |||
| // 成长值 | |||
| wxScoreRulesService.phoneAddScore(user); | |||
| resultMap.put("msg","授权手机成功!"); | |||
| resultMap.put("phone",phoneNoInfo.getPhoneNumber()); | |||
| } else { | |||
| @@ -41,28 +41,31 @@ public class WxScoreHistory implements Serializable { | |||
| /*租户ID**/ | |||
| /**租户ID**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | |||
| private String tenantId; | |||
| /*会员ID**/ | |||
| /**会员ID**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="会员ID",name="cUserId") | |||
| private Long cUserId; | |||
| /*创建日期**/ | |||
| /**创建日期**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="创建日期",name="createDate") | |||
| private Date createDate; | |||
| /*有效日期**/ | |||
| /**成长值类型(1:每日登录, 2:消费,3:绑车牌,4:连接wifi,5:微信昵称授权,6:微信手机授权)**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="成长值类型",name="scoreType") | |||
| private Integer scoreType; | |||
| /**有效日期**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="有效日期",name="validDate") | |||
| private Date validDate; | |||
| /*单据号**/ | |||
| /**单据号**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="单据号",name="orderId") | |||
| private Long orderId; | |||
| /*支付方式**/ | |||
| /**支付方式**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="支付方式",name="payType") | |||
| private Integer payType; | |||
| /*支付金额**/ | |||
| /**支付金额**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="支付金额",name="payAmount") | |||
| private BigDecimal payAmount; | |||
| /*积分**/ | |||
| private Integer payAmount; | |||
| /**积分**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="积分",name="scoreAmount") | |||
| private Integer scoreAmount; | |||
| public String getTenantId() { | |||
| @@ -83,6 +86,15 @@ public class WxScoreHistory implements Serializable { | |||
| public void setCreateDate(Date _createDate) { | |||
| createDate = _createDate; | |||
| } | |||
| public Integer getScoreType() { | |||
| return scoreType; | |||
| } | |||
| public void setScoreType(Integer scoreType) { | |||
| this.scoreType = scoreType; | |||
| } | |||
| public Date getValidDate() { | |||
| return validDate; | |||
| } | |||
| @@ -101,10 +113,10 @@ public class WxScoreHistory implements Serializable { | |||
| public void setPayType(Integer _payType) { | |||
| payType = _payType; | |||
| } | |||
| public BigDecimal getPayAmount() { | |||
| public Integer getPayAmount() { | |||
| return payAmount; | |||
| } | |||
| public void setPayAmount(BigDecimal _payAmount) { | |||
| public void setPayAmount(Integer _payAmount) { | |||
| payAmount = _payAmount; | |||
| } | |||
| public Integer getScoreAmount() { | |||
| @@ -119,14 +131,15 @@ public class WxScoreHistory implements Serializable { | |||
| public static enum Field | |||
| { | |||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||
| ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") | |||
| ,CUserId_ASC("`cUserId` ASC"),CUserId_DESC("`cUserId` DESC") | |||
| ,CreateDate_ASC("`createDate` ASC"),CreateDate_DESC("`createDate` DESC") | |||
| ,ValidDate_ASC("`validDate` ASC"),ValidDate_DESC("`validDate` DESC") | |||
| ,OrderId_ASC("`orderId` ASC"),OrderId_DESC("`orderId` DESC") | |||
| ,PayType_ASC("`payType` ASC"),PayType_DESC("`payType` DESC") | |||
| ,PayAmount_ASC("`payAmount` ASC"),PayAmount_DESC("`payAmount` DESC") | |||
| ,ScoreAmount_ASC("`scoreAmount` ASC"),ScoreAmount_DESC("`scoreAmount` DESC") | |||
| ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC") | |||
| ,CUserId_ASC("`c_user_id` ASC"),CUserId_DESC("`c_user_id` DESC") | |||
| ,CreateDate_ASC("`create_date` ASC"),CreateDate_DESC("`create_date` DESC") | |||
| ,ScoreType_ASC("`score_type` ASC"),ScoreType_DESC("`score_type` DESC") | |||
| ,ValidDate_ASC("`valid_date` ASC"),ValidDate_DESC("`valid_date` DESC") | |||
| ,OrderId_ASC("`order_id` ASC"),OrderId_DESC("`order_id` DESC") | |||
| ,PayType_ASC("`pay_type` ASC"),PayType_DESC("`pay_type` DESC") | |||
| ,PayAmount_ASC("`pay_amount` ASC"),PayAmount_DESC("`pay_amount` DESC") | |||
| ,ScoreAmount_ASC("`score_amount` ASC"),ScoreAmount_DESC("`score_amount` DESC") | |||
| ; | |||
| private String value; | |||
| Field(String value){ | |||
| @@ -159,7 +172,7 @@ public class WxScoreHistory implements Serializable { | |||
| sb.append(","); | |||
| sb.append(fields[k].toString()); | |||
| } | |||
| this.sortColumns = sb.toString(); | |||
| } | |||
| public void setSortColumns(String sortColumns) | |||
| @@ -7,6 +7,15 @@ import java.util.List; | |||
| import javax.persistence.Id; | |||
| import java.io.Serializable; | |||
| /** | |||
| * 1. 每天登录首次给成长值 | |||
| * 2. 消费金额为0时,不给成长值。 | |||
| * 3. 消费金额除以1元,四舍五入给成长值 | |||
| * 4. 绑车牌获得成长值 | |||
| * 5. 微信昵称授权获取成长值 | |||
| * 6. 微信手机授权获取成长值 | |||
| */ | |||
| @Table(name = "wx_score_rules") | |||
| public class WxScoreRules implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| @@ -39,8 +48,6 @@ public class WxScoreRules implements Serializable { | |||
| this.ids = ids; | |||
| } | |||
| /**租户ID**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | |||
| private String tenantId; | |||
| @@ -63,16 +70,16 @@ public class WxScoreRules implements Serializable { | |||
| @io.swagger.annotations.ApiModelProperty(value="绑车牌获取积分",name="bindCarScoreNumber") | |||
| private Integer bindCarScoreNumber; | |||
| /**连接wifi次数**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="绑车牌",name="wifiNumber") | |||
| @io.swagger.annotations.ApiModelProperty(value="连接wifi次数",name="wifiNumber") | |||
| private Integer wifiNumber; | |||
| /**连接wifi获取积分**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="绑车牌获取积分",name="wifiScoreNumber") | |||
| @io.swagger.annotations.ApiModelProperty(value="连接wifi获取积分",name="wifiScoreNumber") | |||
| private Integer wifiScoreNumber; | |||
| /**个人信息获取积分**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="绑车牌获取积分",name="personScoreNumber") | |||
| @io.swagger.annotations.ApiModelProperty(value="个人信息获取积分",name="personScoreNumber") | |||
| private Integer personScoreNumber; | |||
| /**手机授权获取积分**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="绑车牌获取积分",name="phoneScoreNumber") | |||
| @io.swagger.annotations.ApiModelProperty(value="手机授权获取积分",name="phoneScoreNumber") | |||
| private Integer phoneScoreNumber; | |||
| /**创建时间**/ | |||
| @@ -77,5 +77,5 @@ public interface WxCUserService { | |||
| /** | |||
| * 计算当前用户成长值 | |||
| */ | |||
| void scoreCalculate(String tenantId, Long cUserId); | |||
| void scoreCalculate(WxCUser user, boolean isNew); | |||
| } | |||
| @@ -1,6 +1,9 @@ | |||
| package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCUserCar; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxScoreRules; | |||
| public interface WxScoreRulesService { | |||
| @@ -9,11 +12,18 @@ public interface WxScoreRulesService { | |||
| * 根据实体查询分页列表 | |||
| * | |||
| * @param record | |||
| * @param offset | |||
| * @param limit | |||
| * @param pageIndex | |||
| * @param pageSize | |||
| * @return | |||
| */ | |||
| PageInfo<WxScoreRules> listAsPage(WxScoreRules record, Integer pageIndex, Integer pageSize); | |||
| /** | |||
| * 获取租户的ScoreRules | |||
| * @param tenantId | |||
| * @return | |||
| */ | |||
| WxScoreRules getScoreRules(String tenantId); | |||
| /** | |||
| * 根据Id获得实体 | |||
| @@ -37,28 +47,45 @@ public interface WxScoreRulesService { | |||
| */ | |||
| void deleteById(Long id); | |||
| /** | |||
| * 登录 调用增长积分 | |||
| * @param tenantId | |||
| * @param cUserId | |||
| * 登录获取成长值 | |||
| * @param user | |||
| * @return 新增的积分值 | |||
| */ | |||
| int loginAddScore(String tenantId,Long cUserId); | |||
| int loginAddScore(WxCUser user); | |||
| /** | |||
| * | |||
| * @param tenantId | |||
| * @param cUserId | |||
| * @param payPrice 实际支付金额(分) | |||
| * 订单获取成长值 | |||
| * @param order | |||
| * @return 新增的积分值 | |||
| */ | |||
| int payAddScore(WxOrder order); | |||
| /** | |||
| * 绑车牌获取成长值 | |||
| * @param userCar | |||
| * @return 新增的积分值 | |||
| */ | |||
| int bindCarAddScore(WxCUserCar userCar); | |||
| /** | |||
| * wifi获取成长值 | |||
| * @return | |||
| */ | |||
| int payAddScore(String tenantId,Long cUserId,int payPrice); | |||
| int wifiAddScore(); | |||
| /** | |||
| * 微信昵称授权获取成长值 | |||
| * @param user | |||
| * @return | |||
| */ | |||
| int personAddScore(WxCUser user); | |||
| /** | |||
| * 微信手机授权获取成长值 | |||
| * @param user | |||
| * @return | |||
| */ | |||
| int phoneAddScore(WxCUser user); | |||
| } | |||
| @@ -11,6 +11,8 @@ import com.iformall.mapper.WxCUserMapper; | |||
| import com.iformall.mapper.WxCouponOrderMapper; | |||
| import com.iformall.mapper.WxScoreRulesMapper; | |||
| import com.iformall.service.WxCUserService; | |||
| import com.iformall.service.WxScoreRulesService; | |||
| import org.apache.commons.lang3.time.DateUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -30,6 +32,9 @@ public class WxCUserServiceImpl implements WxCUserService { | |||
| @Autowired | |||
| WxScoreRulesMapper wxScoreRulesMapper; | |||
| @Autowired | |||
| WxScoreRulesService wxScoreRulesService; | |||
| @Override | |||
| public PageInfo<WxCUser> listAsPage(WxCUser record, Integer pageIndex, Integer pageSize) { | |||
| @@ -87,41 +92,18 @@ public class WxCUserServiceImpl implements WxCUserService { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCUserMapper.listByChannel(sceneList, tenantId)); | |||
| } | |||
| @Override | |||
| public void scoreCalculate(String tenantId, Long cUserId) { | |||
| WxCUser user = wxCUserMapper.selectByPrimaryKey(cUserId); | |||
| if (user == null) { | |||
| return; | |||
| } | |||
| // 登录次数 | |||
| // login count | |||
| int login_count = user.getLoginCount(); | |||
| // coupon order | |||
| WxCouponOrder couponOrder = new WxCouponOrder(); | |||
| couponOrder.setTenantId(tenantId); | |||
| couponOrder.setCUserId(cUserId); | |||
| int counponCount = wxCouponOrderMapper.selectCount(couponOrder); | |||
| // score rule | |||
| WxScoreRules scoreRuleQ = new WxScoreRules(); | |||
| scoreRuleQ.setTenantId(tenantId); | |||
| WxScoreRules scoreRules = wxScoreRulesMapper.selectOne(scoreRuleQ); | |||
| if (scoreRules != null) { | |||
| Integer score = | |||
| (login_count / scoreRules.getLoginCount()) * scoreRules.getLoginScoreNumber() | |||
| + (counponCount / scoreRules.getConsumptionScoreNumber()) * scoreRules.getConsumptionAmount(); | |||
| if (user != null) { | |||
| user.setScore(score); | |||
| user.setUpdateDate(new Date()); | |||
| wxCUserMapper.updateByPrimaryKeySelective(user); | |||
| public void scoreCalculate(WxCUser user, boolean isNew) { | |||
| if (isNew) { | |||
| wxScoreRulesService.loginAddScore(user); | |||
| } else { | |||
| WxCUser oldUser = getById(user.getId()); | |||
| if (!DateUtils.isSameDay(user.getUpdateDate(), oldUser.getUpdateDate())) { | |||
| wxScoreRulesService.loginAddScore(user); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -13,6 +13,7 @@ import com.iformall.mapper.*; | |||
| import com.iformall.service.WxCUserService; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.service.WxPayOrderService; | |||
| import com.iformall.service.WxScoreRulesService; | |||
| import com.iformall.utils.RedisLock; | |||
| import com.iformall.utils.Utility; | |||
| import org.slf4j.Logger; | |||
| @@ -67,6 +68,9 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Autowired | |||
| WxPayOrderService wxPayOrderService; | |||
| @Autowired | |||
| WxScoreRulesService wxScoreRulesService; | |||
| @Override | |||
| public PageInfo<WxOrder> listAsPage(WxOrder record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxOrderMapper.findList(record)); | |||
| @@ -517,7 +521,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| // 成长值 计算 | |||
| try { | |||
| wxCUserService.scoreCalculate(user.getTenantId(), user.getId()); | |||
| wxScoreRulesService.payAddScore(updateOrder); | |||
| } catch (Exception e) { | |||
| logger.error("成长值:" + e.getMessage()); | |||
| } | |||
| @@ -1,11 +1,11 @@ | |||
| package com.iformall.service.impl; | |||
| import java.util.*; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxScoreRules; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.EnumScoreType; | |||
| import com.iformall.mapper.WxScoreHistoryMapper; | |||
| import com.iformall.mapper.WxScoreRulesMapper; | |||
| import com.iformall.service.WxCUserBasicInfoService; | |||
| import com.iformall.service.WxCUserService; | |||
| @@ -14,17 +14,21 @@ import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.iformall.common.IdWorker; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @Service | |||
| public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| @Autowired | |||
| WxScoreRulesMapper wxScoreRulesMapper; | |||
| @Autowired | |||
| @Autowired | |||
| WxScoreHistoryMapper wxScoreHistoryMapper; | |||
| @Autowired | |||
| WxCUserService wxCUserService; | |||
| @Autowired | |||
| @Autowired | |||
| WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| @@ -33,6 +37,31 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxScoreRulesMapper.findList(record)); | |||
| } | |||
| @Override | |||
| public WxScoreRules getScoreRules(String tenantId) { | |||
| WxScoreRules scoreRules = new WxScoreRules(); | |||
| scoreRules.setTenantId(tenantId); | |||
| List<WxScoreRules> list = wxScoreRulesMapper.findList(scoreRules); | |||
| if (list.size() > 0) { | |||
| return list.get(0); | |||
| } | |||
| // 如果成长值规则不存在,启用默认值 | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| scoreRules.setId(idWorker.nextId()); | |||
| scoreRules.setLoginCount(1); | |||
| scoreRules.setLoginScoreNumber(10); | |||
| scoreRules.setConsumptionAmount(1); | |||
| scoreRules.setConsumptionScoreNumber(50); | |||
| scoreRules.setBindCarNumber(1); | |||
| scoreRules.setBindCarScoreNumber(100); | |||
| scoreRules.setWifiNumber(1); | |||
| scoreRules.setWifiScoreNumber(10); | |||
| scoreRules.setPersonScoreNumber(100); | |||
| scoreRules.setPhoneScoreNumber(100); | |||
| wxScoreRulesMapper.insertSelective(scoreRules); | |||
| return scoreRules; | |||
| } | |||
| @Override | |||
| public WxScoreRules getById(Long id) { | |||
| return wxScoreRulesMapper.selectByPrimaryKey(id); | |||
| @@ -43,7 +72,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| if (record.getId() == null) { | |||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| record.setId(idWorker.nextId()); | |||
| record.setId(idWorker.nextId()); | |||
| wxScoreRulesMapper.insertSelective(record); | |||
| } else { | |||
| wxScoreRulesMapper.updateByPrimaryKeySelective(record); | |||
| @@ -55,66 +84,170 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { | |||
| wxScoreRulesMapper.deleteByPrimaryKey(id); | |||
| } | |||
| @Override | |||
| public int loginAddScore(String tenantId, Long cUserId) { | |||
| int addScoreNumber = 0; | |||
| WxScoreRules scoreRules = new WxScoreRules(); | |||
| scoreRules.setTenantId(tenantId); | |||
| List<WxScoreRules> list = wxScoreRulesMapper.findList(scoreRules); | |||
| if (list.isEmpty()) { | |||
| return addScoreNumber; | |||
| private void updateScore(Long userId, int addedScoreNumber) { | |||
| // 1. 获取cUser | |||
| WxCUser wxCUser = wxCUserService.getById(userId); | |||
| if (wxCUser.getScore() == null) { | |||
| wxCUser.setScore(0); | |||
| } | |||
| scoreRules = list.get(0); | |||
| addScoreNumber = scoreRules.getLoginScoreNumber(); | |||
| WxCUser wxCUser = wxCUserService.getById(cUserId); | |||
| wxCUser.setScore(wxCUser.getScore() + addScoreNumber); | |||
| int newScore = wxCUser.getScore() + addedScoreNumber; | |||
| // 2. update score | |||
| wxCUser.setScore(newScore); | |||
| wxCUserService.saveOrUpdate(wxCUser); | |||
| //修改basic表积分 | |||
| // 3. 修改basic points | |||
| if (wxCUser.getPhone() != null) { | |||
| //修改basic表积分 | |||
| WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo(); | |||
| wxCUserBasicInfo.setId(wxCUser.getId()); | |||
| wxCUserBasicInfo.setTenantId(tenantId); | |||
| wxCUserBasicInfo.setTenantId(wxCUser.getTenantId()); | |||
| wxCUserBasicInfo.setPhone(wxCUser.getPhone()); | |||
| wxCUserBasicInfo.setPoins(wxCUser.getScore()); | |||
| wxCUserBasicInfo.setPoins(newScore); | |||
| wxCUserBasicInfoService.updateScore(wxCUserBasicInfo); | |||
| } | |||
| } | |||
| @Override | |||
| public int loginAddScore(WxCUser user) { | |||
| int addScoreNumber = 0; | |||
| // 1. score_rules | |||
| WxScoreRules scoreRules = getScoreRules(user.getTenantId()); | |||
| // 2. 增长的成长值 | |||
| addScoreNumber = scoreRules.getLoginScoreNumber(); | |||
| updateScore(user.getId(), addScoreNumber); | |||
| // 3. 记录历史 | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| WxScoreHistory history = new WxScoreHistory(); | |||
| history.setId(idWorker.nextId()); | |||
| history.setTenantId(user.getTenantId()); | |||
| history.setCUserId(user.getId()); | |||
| history.setCreateDate(new Date()); | |||
| history.setScoreType(EnumScoreType.LOGIN.getCode()); | |||
| history.setScoreAmount(addScoreNumber); | |||
| wxScoreHistoryMapper.insert(history); | |||
| return addScoreNumber; | |||
| } | |||
| @Override | |||
| public int payAddScore(String tenantId, Long cUserId,int payPrice) { | |||
| if(payPrice==0){ | |||
| return 0; | |||
| } | |||
| public int payAddScore(WxOrder order) { | |||
| int addScoreNumber = 0; | |||
| WxScoreRules scoreRules = new WxScoreRules(); | |||
| scoreRules.setTenantId(tenantId); | |||
| List<WxScoreRules> list = wxScoreRulesMapper.findList(scoreRules); | |||
| if (list.isEmpty()) { | |||
| // 订单金额为0时不计入 | |||
| if (order.getPayment() == 0) | |||
| return 0; | |||
| } | |||
| scoreRules = list.get(0); | |||
| int priceCondition = scoreRules.getConsumptionAmount(); | |||
| // 1. 获取score rules | |||
| WxScoreRules scoreRules = getScoreRules(order.getTenantId()); | |||
| // 2. 获取成长值 | |||
| int priceCondition = scoreRules.getConsumptionAmount() * 100; // 元->分 | |||
| int baseScore = scoreRules.getConsumptionScoreNumber();//消费增长积分 | |||
| addScoreNumber = (payPrice/priceCondition)*baseScore; | |||
| WxCUser wxCUser = wxCUserService.getById(cUserId); | |||
| wxCUser.setScore(wxCUser.getScore() + addScoreNumber); | |||
| wxCUserService.saveOrUpdate(wxCUser); | |||
| // 3. 计算成长值 | |||
| Long dScoreT = Math.round(order.getPayment() * 1.0d / priceCondition * baseScore); | |||
| addScoreNumber = dScoreT.intValue(); | |||
| //修改basic表积分 | |||
| if (wxCUser.getPhone() != null) { | |||
| //修改basic表积分 | |||
| WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo(); | |||
| wxCUserBasicInfo.setId(wxCUser.getId()); | |||
| wxCUserBasicInfo.setTenantId(tenantId); | |||
| wxCUserBasicInfo.setPhone(wxCUser.getPhone()); | |||
| wxCUserBasicInfo.setPoins(wxCUser.getScore()); | |||
| wxCUserBasicInfoService.updateScore(wxCUserBasicInfo); | |||
| } | |||
| // 4. 增长的成长值 | |||
| updateScore(order.getCUserId(), addScoreNumber); | |||
| // 5. 记录历史 | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| WxScoreHistory history = new WxScoreHistory(); | |||
| history.setId(idWorker.nextId()); | |||
| history.setTenantId(order.getTenantId()); | |||
| history.setCUserId(order.getCUserId()); | |||
| history.setCreateDate(new Date()); | |||
| history.setScoreType(EnumScoreType.CONSUMPTION.getCode()); | |||
| history.setOrderId(order.getId()); | |||
| history.setPayType(order.getPaymentType()); | |||
| history.setPayAmount(order.getPayment()); | |||
| history.setScoreAmount(addScoreNumber); | |||
| wxScoreHistoryMapper.insert(history); | |||
| return addScoreNumber; | |||
| } | |||
| @Override | |||
| public int bindCarAddScore(WxCUserCar userCar) { | |||
| int addScoreNumber = 0; | |||
| // 1. 获取score rules | |||
| WxScoreRules scoreRules = getScoreRules(userCar.getTenantId()); | |||
| // 2. 获取成长值 | |||
| addScoreNumber = scoreRules.getBindCarScoreNumber(); | |||
| // 3. 增长的成长值 | |||
| updateScore(userCar.getCUserId(), addScoreNumber); | |||
| // 4. 记录历史 | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| WxScoreHistory history = new WxScoreHistory(); | |||
| history.setId(idWorker.nextId()); | |||
| history.setTenantId(userCar.getTenantId()); | |||
| history.setCUserId(userCar.getCUserId()); | |||
| history.setCreateDate(new Date()); | |||
| history.setScoreType(EnumScoreType.BINDCAR.getCode()); | |||
| history.setScoreAmount(addScoreNumber); | |||
| wxScoreHistoryMapper.insert(history); | |||
| return addScoreNumber; | |||
| } | |||
| @Override | |||
| public int wifiAddScore() { | |||
| int addScoreNumber = 0; | |||
| return addScoreNumber; | |||
| } | |||
| @Override | |||
| public int personAddScore(WxCUser user) { | |||
| int addScoreNumber = 0; | |||
| // 1. 获取score rules | |||
| WxScoreRules scoreRules = getScoreRules(user.getTenantId()); | |||
| // 2. 获取成长值 | |||
| addScoreNumber = scoreRules.getPersonScoreNumber(); | |||
| // 3. 增长的成长值 | |||
| updateScore(user.getId(), addScoreNumber); | |||
| // 4. 记录历史 | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| WxScoreHistory history = new WxScoreHistory(); | |||
| history.setId(idWorker.nextId()); | |||
| history.setTenantId(user.getTenantId()); | |||
| history.setCUserId(user.getId()); | |||
| history.setCreateDate(new Date()); | |||
| history.setScoreType(EnumScoreType.WECHAT_PERSION.getCode()); | |||
| history.setScoreAmount(addScoreNumber); | |||
| wxScoreHistoryMapper.insert(history); | |||
| return addScoreNumber; | |||
| } | |||
| @Override | |||
| public int phoneAddScore(WxCUser user) { | |||
| int addScoreNumber = 0; | |||
| // 1. 获取score rules | |||
| WxScoreRules scoreRules = getScoreRules(user.getTenantId()); | |||
| // 2. 获取成长值 | |||
| addScoreNumber = scoreRules.getPhoneScoreNumber(); | |||
| // 3. 增长的成长值 | |||
| updateScore(user.getId(), addScoreNumber); | |||
| // 4. 记录历史 | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| WxScoreHistory history = new WxScoreHistory(); | |||
| history.setId(idWorker.nextId()); | |||
| history.setTenantId(user.getTenantId()); | |||
| history.setCUserId(user.getId()); | |||
| history.setCreateDate(new Date()); | |||
| history.setScoreType(EnumScoreType.WECHAT_PHONE.getCode()); | |||
| history.setScoreAmount(addScoreNumber); | |||
| wxScoreHistoryMapper.insert(history); | |||
| return addScoreNumber; | |||
| } | |||
| @@ -101,7 +101,7 @@ | |||
| <update id="updateScore" parameterType="com.iformall.domain.po.WxCUserBasicInfo"> | |||
| update wx_c_user_basic_info set poins=#{poins} where phone=#{phone} and tenant_id=#{tenantId} | |||
| and id=#{cUserId} | |||
| and id=#{id} | |||
| </update> | |||
| <update id="updateNewId" parameterType="com.iformall.domain.vo.CUserBaseVo"> | |||