加息券功能设计

        p2p常用的项目加息功能功能,加息券是用户投资时使用,使用后在原有的利率上加上利息,并产生额外的收益,投资项目满标后最后一次回款时返还额外的收益,额外收益由平台提供已借款人无关。

1:数据库设计

(1)加息券表

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `t_rate_coupon`
-- ----------------------------
DROP TABLE IF EXISTS `t_rate_coupon`;
CREATE TABLE `t_rate_coupon` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '加息券id',
  `add_name` varchar(50) DEFAULT NULL COMMENT '加息券名称',
  `add_rates` decimal(10,4) DEFAULT '0.0000' COMMENT '加息券利率',
  `add_type` int(11) DEFAULT '0' COMMENT '加息券类型',
  `add_count` int(11) DEFAULT '0' COMMENT '加息券数量',
  `is_open` bit(1) DEFAULT b'0' COMMENT '是否开启0:关闭1:开启',
  `last_time` datetime DEFAULT NULL COMMENT '最后修改时间',
  `expire_time` datetime DEFAULT NULL COMMENT '到期时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;


(2)券的类型参数类型表

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `t_rate_coupon_type`
-- ----------------------------
DROP TABLE IF EXISTS `t_rate_coupon_type`;
CREATE TABLE `t_rate_coupon_type` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '加息券类型参数表id',
  `type_name` varchar(50) DEFAULT NULL COMMENT '类型名称',
  `type_number` int(11) DEFAULT '0' COMMENT '类型标识数',
  `is_use` bit(1) DEFAULT b'0' COMMENT '是否使用0:未使用1:使用',
  `type_coupon` int(11) DEFAULT '0' COMMENT '不同券参数 0:返息券1:抵消券2:体验金',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

2:程序功能设计

package utils;

(1)错误参数表用于返回错误时的情况和描述
/**
 * 错误参数表
 * 
 * @author lzp
 * @version 6.0
 * @created 2014-3-21 下午7:52:38
 */
public class ErrorInfo {

public String msg;
public int code;
public String FRIEND_INFO  = "亲、由于系统繁忙。";
public String PROCESS_INFO = "系统已把错误信息发送到后台管理员,会尽快的处理,给您带来的不便,敬请原谅。";

public ErrorInfo() {
this.code = 0;
this.msg = "";
}


public ErrorInfo(int code, String msg) {
this.code = code;
this.msg = msg;
}

public void clear() {
this.code = 0;
this.msg = "";
}


@Override
public String toString() {
return "ErrorInfo [msg=" + msg + ", code=" + code + ", FRIEND_INFO= " + FRIEND_INFO + ", PROCESS_INFO=" + PROCESS_INFO + "]";
}
}
(2)类型参数为券的类型制制作的参数表
package models;

import java.util.Date;

import javax.persistence.Entity;

import play.db.jpa.Model;

/*
 * 返息券类型参数表   huashao
 */
@Entity
public class t_rate_coupon_type extends Model {


public String type_name;// 加息券类型名称


public int type_number;// 加息券类型标识数


public boolean is_use;// 是否使用

public int type_coupon;//不同券参数 0:返息券1:抵消券2:体验金


}

(3)加息券的类型表
package models;


import java.util.Date;


import javax.persistence.Entity;
import javax.persistence.Transient;


import business.rateCoupon;


import constants.Constants;


import play.db.jpa.Model;
import utils.Security;
/*
 * 返息券   huashao
 */
@Entity
public class t_rate_coupon extends Model {

public String add_name;//加息券名称

public double add_rates;//加息券利率

public  int add_type;//加息券类型

public int  add_count;//加息券数量

public boolean  is_open;//是否使用

public Date  last_time;//最后修改时间

public Date  expire_time;//到期时间

@Transient
public String addType;

public String getAddType() {
return rateCoupon.findCouponType(this.add_type);
}
}

(4)加息券业务类
package business;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Query;

import org.apache.commons.lang.StringUtils;


import models.t_dict_secret_questions;
import models.t_rate_coupon;
import models.t_rate_coupon_type;
import models.v_supervisors;
import play.Logger;
import play.db.jpa.JPA;
import utils.ErrorInfo;
import utils.PageBean;

/**
 * 返息券 业务类
 * 
 * @author huashao
 * 
 */
public class rateCoupon implements Serializable {
public long id;
private long _id;
public void setId(long id) {
t_rate_coupon ads = null;
try {
ads = t_rate_coupon.findById(id);
} catch (Exception e) {
e.printStackTrace();
Logger.info("setId时,根据ID查询加息券:" + e.getMessage());
this._id = -1;
return;
}

if (ads == null) {
this._id = -1;
return;
}
this._id = id;
this.add_name = ads.add_name;
this.add_rates = ads.add_rates;
this.add_type = ads.add_type;// 所在位置
this.add_count = ads.add_count;
this.is_open = ads.is_open;// 图片分辨率
this.last_time = ads.last_time;// 建议文件大小
this.expire_time = ads.expire_time;// 文件格式
}
public long getId() {
return _id;
}

public String add_name;// 加息券名称
public double add_rates;// 加息券利率
public int add_type;// 加息券类型
public int add_count;// 加息券数量
public boolean is_open;// 是否使用
public Date last_time;// 最后修改时间
public Date expire_time;// 到期时间
/*
* 获得返息券类型参数
*/
public static List<t_rate_coupon_type> queryCouponType(Integer type_coupon) {

List<t_rate_coupon_type> couponType = null;

try {

couponType = t_rate_coupon_type.find("(1=1) and is_use = ? and type_coupon=? ", true,type_coupon).fetch();

} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
Logger.error("根据条件查询返息券类型参数时:" + e.getMessage());
return null;
}
return couponType;
}

/*
* 获得返息券数
*/
public static List<t_rate_coupon> queryCoupon() {

List<t_rate_coupon> coupons = null;

try {

coupons = t_rate_coupon.findAll();

} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
Logger.error("根据条件查询返息券总数时:" + e.getMessage());
return null;
}
return coupons;
}
/*
* 获得返息券数
*/
public static String findCouponType(Integer add_type) {

t_rate_coupon_type rct = null;

try {

rct = t_rate_coupon_type.find("(1=1) and type_number=? ", add_type)
.first();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
Logger.error("根据条件查询返息券总数时:" + e.getMessage());
return null;
}

if (rct == null) {

return null;
}


return rct.type_name;
}

/**
* 是否存在相同的加息名称 加息券类型

* @param add_name
* @param add_type
* @param error
*/
public static void isHaveSameCoupon(String add_name, Integer add_type,
ErrorInfo error) {

error.clear();

List<t_rate_coupon> coupons = rateCoupon.queryCoupon();

for (t_rate_coupon trc : coupons) {

if (trc.add_name.equals(add_name)) {

error.code = -1;

error.msg = "返息券名称重复";

return;

}
if (trc.add_type == add_type) {
error.code = -1;

error.msg = "返息券类型重复";

return;
}
}
}
/**
* 查询所有加息券列表

* @param currPage
* @param pageSize
* @param add_name
* @param error
* @return
*/
public static PageBean<t_rate_coupon> queryAllCoupon(int currPage,
int pageSize, String add_name, ErrorInfo error) {

error.clear();

if (currPage < 1) {
currPage = 1;
}

if (pageSize < 1) {
pageSize = 5;
}

String condition = "(1=1)";
List<Object> params = new ArrayList<Object>();

if (StringUtils.isNotBlank(add_name)) {
condition += " and add_name like ?  ";
params.add("%" + add_name + "%");
}

int count = 0;

List<t_rate_coupon> page = null;

try {
count = (int) t_rate_coupon.count(condition, params.toArray());

page = t_rate_coupon.find(condition, params.toArray()).fetch(
currPage, pageSize);

} catch (Exception e) {
// TODO: handle exception
Logger.error("查询返现券列表时,出现错误" + e.getMessage());
e.printStackTrace();
error.code = -1;
error.msg = "查询返现券列表时,出现错误";

return null;
}
Map<String, Object> map = new HashMap<String, Object>();

if (StringUtils.isNotBlank(add_name)) {
map.put("addName", add_name);
}
PageBean<t_rate_coupon> bean = new PageBean<t_rate_coupon>();
bean.pageSize = pageSize;
bean.currPage = currPage;
bean.totalCount = count;
bean.page = page;
bean.conditions = map;
error.code = 0;
error.msg = "查询成功";
return bean;
}

/**
* 增加加息券

* @param error
*/

public void create(ErrorInfo error) {

error.clear();

t_rate_coupon trc = new t_rate_coupon();

trc.add_name = this.add_name;

trc.add_rates = this.add_rates;

trc.add_type = this.add_type;

trc.add_count = this.add_count;

trc.expire_time = this.expire_time;

trc.last_time = this.last_time;

trc.is_open = this.is_open;

try {

trc.save();

} catch (Exception e) {
e.printStackTrace();
Logger.info("保存返息券信息时:" + e.getMessage());
error.code = -1;
error.msg = "对不起,由于平台出现故障,此次添加失败!";

return;
}
error.code = 1;

error.msg = "添加返息券成功";
}

/**
* 修改加息券

* @param coupon_id
* @param error
*/

public static void updateCoupon(long coupon_id, double addRates,
int addCount, boolean isOpen, Date expireTime, ErrorInfo error) {

error.clear();
int count = 0;
Query query = JPA
.em()
.createQuery(
"update t_rate_coupon set add_rates=? ,add_count=? , is_open=? , last_time=? ,expire_time=? where id=? ")
.setParameter(1, addRates).setParameter(2, addCount)
.setParameter(3, isOpen).setParameter(4, new Date())
.setParameter(5, expireTime).setParameter(6, coupon_id);
try {
count = query.executeUpdate();

} catch (Exception e) {
// TODO: handle exception
Logger.error("修改返息券,出现错误" + e.getMessage());
e.printStackTrace();
error.code = -1;
error.msg = "修改返息券,出现错误";

return;

}
if (count == 0) {
error.code = -1;
error.msg = "修改返息券未成功";
return;
}
error.code = 1;
error.msg = "修改返息券成功";

}

/**
* 删除加息券

* @param coupon_id
* @param error
*/
public static void deleteCoupon(long coupon_id, ErrorInfo error) {

error.clear();

int count = 0;

try {

count = t_rate_coupon.delete("(1=1) and id=?", coupon_id);

} catch (Exception e) {
// TODO: handle exception
Logger.error("删除返息券,出现错误" + e.getMessage());
e.printStackTrace();
error.code = -1;
error.msg = "删除返息券,出现错误";


}


if (count == 0) {


error.code = -1;
error.msg = "删除返息券未成功";
return;


}


error.code = 1;
error.msg = "删除返息券成功";


}


/**
* 开启加息券

* @param coupon_id
* @param error
*/


public static void openCoupon(long coupon_id, ErrorInfo error) {


error.clear();


int count = 0;
Query query = JPA
.em()
.createQuery(
"update t_rate_coupon set is_open=? , last_time=? where id=? ")
.setParameter(1, true).setParameter(2, new Date())
.setParameter(3, coupon_id);


try {


count = query.executeUpdate();


} catch (Exception e) {
// TODO: handle exception
Logger.error("开启返息券,出现错误" + e.getMessage());
e.printStackTrace();
error.code = -1;
error.msg = "开启返息券,出现错误";


return;


}


if (count == 0) {


error.code = -1;
error.msg = "开启返息券未成功";
return;


}


error.code = 1;
error.msg = "开启返息券成功";


}


/**

* 关闭加息券

* @param coupon_id
* @param error
*/


public static void closeCoupon(long coupon_id, ErrorInfo error) {


error.clear();


int count = 0;
Query query = JPA
.em()
.createQuery(
"update t_rate_coupon set is_open=? , last_time=? where id=? ")
.setParameter(1, false).setParameter(2, new Date())
.setParameter(3, coupon_id);
;


try {


count = query.executeUpdate();


} catch (Exception e) {
// TODO: handle exception
Logger.error("关闭返息券,出现错误" + e.getMessage());
e.printStackTrace();
error.code = -1;
error.msg = "关闭返息券,出现错误";


return;


}


if (count == 0) {


error.code = -1;
error.msg = "关闭返息券未成功";
return;


}


error.code = 1;
error.msg = "关闭返息券成功";


}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值