逻辑:判断当前课程是否超过可以取消预约的次数,是否超过可以取消预约的时间
1、获取私教课的相关信息传至页面
GdUser user = (GdUser) this.getSessionUser();
String gym = user.getXX("gym");
String userId = user.getId();
// 私教课
Entity en = new EntityImpl("yp_private_record", this);
String sql = "SELECT\n" + " a.*, b.lesson_name,d.lesson_num,d.nums,\n" + " b.lesson_type,\n"
+ " c.emp_name,\n" + " c.phone,\n" + " d.level\n" + "FROM\n" + " yp_private_record_" + gym + " a,\n"
+ " yp_private_user d,\n" + " yp_private_plan b,\n" + " yp_emp c\n" + "WHERE\n" + " a.mem_id =?\n"
+ "AND a.private_id = d.id\n" + "and d.lesson_id = b.ID\n" + "AND a.emp_id = c.id"
+ " AND (a.state=? or a.state=? or a.state=?)";
int size = en.executeQuery(sql, new String[] { userId, "001", "002", "003" });
List<Map<String, Object>> SclassList = en.getValues();
if (size > 0) {
Code xx = Codes.code("CLASS_STATE");
for (Map<String, Object> m : SclassList) {
Date order_time = (Date) m.get("order_time");
String time = sdf.format(order_time);
m.put("order_time", time);
String state = xx.getNote(m.get("state").toString());
m.put("state", state);
}
}
this.obj.put("data", SclassList);
2、获取团课相关信息
// 团课课
en = new EntityImpl("yp_grp_list", this);
sql = "select a.id,a.grp_name,a.order_time,a.state,a.feedback, b.emp_name,b.phone,c.start_time,c.end_time, c.grp_id from yp_grp_list_"
+ gym + " a,yp_emp b ,yp_grp_plan c where a.grp_id = c.id and c.emp_id =b.id and a.mem_id=?"
+ " AND (a.state=? or a.state=? or a.state=?)";
size = en.executeQuery(sql, new String[] { userId, "001", "002", "003" });
// 查询购买的团课
Entity entity = new EntityImpl("yp_grp_user", this);
entity.setValue("mem_id", userId);
entity.search();
List<Map<String, Object>> grpUser = entity.getValues();
List<Map<String, Object>> TclassList = en.getValues();
if (size > 0) {
Code xx = Codes.code("CLASS_STATE");
for (Map<String, Object> m : TclassList) {
Date start_time = (Date) m.get("start_time");
String s_time = sdf.format(start_time);
m.put("start_time", s_time);
Date end_time = (Date) m.get("end_time");
String e_time = sdf.format(end_time);
m.put("end_time", e_time);
Date order_time = (Date) m.get("order_time");
String o_time = sdf.format(order_time);
m.put("order_time", o_time);
String state = xx.getNote(m.get("state").toString());
m.put("state", state);
String g_id = m.get("grp_id").toString();
int nums = 1;
int lesson_num = 1;
for (int j = 0; j < grpUser.size(); j++) {
String grp_id = entity.getStringValue("grp_id", j);
if (g_id.equals(grp_id)) {
nums = entity.getIntegerValue("nums", j);
lesson_num = entity.getIntegerValue("lesson_num", j);
break;
}
}
m.put("nums", nums);
m.put("lesson_num", lesson_num);
}
}
this.obj.put("Tdata", TclassList);
获取的团课私课信息 用map存起来,data传到前台,再用模版展现出来
将查到的data用for循环的形式遍历筛选,显示在指定的地方
3、取消团课预约
@Route(value = "cancle_class", conn = true, mdb = false, m = HttpMethod.POST, type = ContentType.JSON)
public void cancle_class() throws Exception {
GdUser user = (GdUser) this.getSessionUser();
String mem_id = user.getId();
String tid = this.getParameter("tid");
String cust_name = user.getCust_name();
String gym = user.getGym();
List<Map<String, Object>> cardList = AppUtils.getCards(this.getConnection(), gym, mem_id);
Entity en = new EntityImpl(this);
/**
* 查询设置的最大取消预约次数
*/
String sql = "select note from yp_param where cust_name=? and code='order_setting'";
int size = en.executeQuery(sql, new String[] { cust_name });
JSONObject noteObj = null;
if (size > 0) {
String note = en.getStringValue("note");
JSONObject x = new JSONObject(note);
noteObj = x.getJSONObject(gym);
int canelTimes = 0;
for (Map<String, Object> m : cardList) {
String card_type = (String) m.get("card_type");
if ("001".equals(card_type)) {
try {
canelTimes = noteObj.getInt("007");
} catch (Exception e) {
}
break;
} else if ("003".equals(card_type)) {
// 会员最多取消预约次数(次卡)
try {
canelTimes = noteObj.getInt("008");
} catch (Exception e) {
}
break;
} else if ("002".equals(card_type)) {
// 会员最多取消预约次数(储值卡)
try {
canelTimes = noteObj.getInt("009");
} catch (Exception e) {
}
break;
}
}
if (canelTimes == 0) {
throw new Exception("您预约的课程不能取消哦");
}
// 获取当前用户已经取消预约了的次数
en = new EntityImpl("yp_private_record", this);
sql = "select id from yp_private_record_" + gym + " where state = '004' and mem_id =? ";
size = en.executeQuery(sql, new String[] { mem_id });
if (size > canelTimes) {
throw new Exception("您最多能取消" + canelTimes + "次课程");
}
}
en = new EntityImpl("yp_grp_list", this);
sql = "select a.id,a.order_time,b.start_time from yp_grp_list_" + gym
+ " a,yp_grp_plan b where a.grp_id = b.id and a.state ='001' and a.mem_id=? and a.cust_name = ? and a.id = ?";
size = en.executeQuery(sql, new String[] { mem_id, cust_name, tid });
if (size > 0) {
String order_time = en.getStringValue("order_time");
String start_time = en.getStringValue("start_time");
SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH:mm");
/**
* 判断是否可以取消
*/
en = new EntityImpl(this);
sql = "select note from yp_param where code='order_setting' and cust_name=?";
size = en.executeQuery(sql, new String[] { user.getCust_name() });
if (size > 0) {
String note = en.getStringValue("note");
JSONObject obj = new JSONObject(note);
obj = obj.getJSONObject(gym);
if (obj.has("002")) {
String hour = obj.get("002").toString();// 会员需提前几小时取消预约
Calendar cld = Calendar.getInstance();
cld.setTime(date.parse(start_time));
cld.add(Calendar.HOUR, -Integer.parseInt(hour));
Date newDate = cld.getTime();
// 如果减去提前取消预约的是时间在当前时间之后
if ((new Date()).after(newDate)) {
throw new Exception("该课程必须提前" + hour + "小时取消预约");
}
}
}
Date now_date = new Date();
en = new EntityImpl("yp_param", this);
en = new EntityImpl("yp_grp_list", this);
en.setTablename("yp_grp_list_" + gym);
en.setValue("id", tid);
en.setValue("state", "004");
en.setValue("un_order_time", now_date);
en.update();
this.obj.put("data", "cancel_success");
} else {
throw new Exception("没有查询到团课预约");
}
}
做判断
查询设置的最大取消预约次数 最迟预约时间 然后判断 正常的条件下才可以取消预约 执行取消预约的数据修改