SSH框架实现优惠券使用和时间过期判断功能

使用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;
							}
						}
}

Alt
大概逻辑方面都在这里其他jsp,实体类和接口用自己的就可以了。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值