使用ssh框架实现优惠券使用时间判断功能
action页面
@Action(value = "/mobile/syhui", results = {
@Result(name = SUCCESS, location = "/mobile/fuk.jsp"),
@Result(name = LOGIN, location = "/mobile/wdyem.jsp") })
public String syhui() {
Dengl id = (Dengl) ServletActionContext.getRequest().getSession()
.getAttribute("user");
Integer did = getDengl_yhuiBean().getId();
Dengl_yhui cc = dengl_yhuiService.findById(did);
List<Orders> list = ordersService.Orderslist(id.getId());
getOrdersBean().setOrderslist(list);
Date date=new Date();
//Date date=cc.getAndAction();
Date date2=cc.getTheend();
// 循环商品集合里为0的商品小计
double p1 = cc.getPrice();// 减15
double p2 = cc.getPrice2();// 满100减
double a = 0;
if (date.before(date2)) {
for (int i = 0; i < list.size(); i++) {
double zongj = list.get(i).getZongjia();
// getOrdersBean().setZongj2(zongj);
// getOrdersBean().setZongj(zongj);
// 然后循环相加商品小计等于总
for (int j = 0; j < list.size(); j += zongj) {
a = a + zongj;
if (a >= p2) {
a = a - p1;
getOrdersBean().setZongj4(a);
}
}
}
}else {
for (int i = 0; i < list.size(); i++) {
double zongj = list.get(i).getZongjia();
for (int j = 0; j < list.size(); j += zongj) {
a = a + zongj;
getOrdersBean().setZongj4(a);
dengl_yhuiBean.setYhj("你的优惠券已过期");
Integer yid=getDengl_yhuiBean().getId();
dengl_yhuiService.deleteById(yid);
}
}
}
return SUCCESS;
}
Service页面
// 查询
public Dengl_yhui findById(Integer integer) {
// setEntityClass不能少
// 把数据库的所有字段的值,封装到Product实体类中
iDao.setEntityClass(Dengl_yhui.class);
return iDao.findById(integer);
}
// 查询集合
public List<Orders> Orderslist(Integer id) {
DetachedCriteria dc = DetachedCriteria.forClass(Orders.class, "s");
dc.add(Restrictions.eq("s.dengl.id", id));
return iDao.findByDedCriteria(dc);
}
// 过期后自动删除
public boolean deleteById(Integer id) {
String sql = "delete from dengl_yhui where id=?";
List<Object> plist = new ArrayList<Object>();
plist.add(id);
Integer num = iDao.excuteSql(sql, plist);
if (num == null) {
return false;
} else {
return true;
}
}
}
大概逻辑方面都在这里其他jsp,实体类和接口用自己的就可以了。