Beispiel #1
0
func ChildInNormalScheduleAction(w http.ResponseWriter, r *http.Request) {
	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	scheduleId := r.FormValue("scheduleId")

	pageData, err := logic.ChildInNormalSchedulePage(scheduleId, pageNo, pageSize)

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1

	commonlib.RenderTemplate(w, r, "page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/page.json")
}
Beispiel #2
0
//保存通话记录备注
func AudioNoteSaveAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	id := r.FormValue("aid")
	note := r.FormValue("note")

	sql := "update audio set note=? where aid=? "

	lessgo.Log.Debug(sql)

	db := lessgo.GetMySQL()
	defer db.Close()

	stmt, err := db.Prepare(sql)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	_, err = stmt.Exec(note, id)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	m["success"] = true
	commonlib.OutputJson(w, m, " ")
}
func ClassScheduleAttachSaveAction(w http.ResponseWriter, r *http.Request) {
	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	id := r.FormValue("id")
	intro := r.FormValue("intro")

	db := lessgo.GetMySQL()
	defer db.Close()

	updateSql := "update class_schedule_attach set intro=?  where id=? "

	lessgo.Log.Debug(updateSql)

	stmt, err := db.Prepare(updateSql)

	if err != nil {
		lessgo.Log.Error(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	_, err = stmt.Exec(intro, id)

	if err != nil {
		lessgo.Log.Error(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	m["success"] = true
	commonlib.OutputJson(w, m, " ")
}
func ContractCheckInSaveAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	childId := r.FormValue("childId")
	scheduleId := r.FormValue("scheduleId")
	contractId := r.FormValue("contractId")
	actionType := r.FormValue("type")

	flag, msg, err := logic.ContractCheckIn(childId, scheduleId, contractId, actionType)

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	if !flag {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "保存失败:" + msg
		commonlib.OutputJson(w, m, " ")
		return
	}

	m["success"] = true
	m["code"] = 200
	commonlib.OutputJson(w, m, " ")

	return
}
func AddChildToClassQuickAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	classId := r.FormValue("classId")
	scheduleId := r.FormValue("scheduleId")
	consumerId := r.FormValue("consumerId")

	flag, msg, err := logic.AddChildToClassQuick(classId, scheduleId, consumerId, employee.UserId)

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	if !flag {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "保存失败:" + msg
		commonlib.OutputJson(w, m, " ")
		return
	}

	m["success"] = true
	m["code"] = 200
	commonlib.OutputJson(w, m, " ")

	return
}
func ChangeClassScheduleAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	oldScheduleId := r.FormValue("oldScheduleId")
	newScheduleId := r.FormValue("newScheduleId")
	childId := r.FormValue("childId")

	flag, msg, err := logic.ChangeClassSchedule(childId, newScheduleId, oldScheduleId, employee.UserId)

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	if !flag {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "调班失败:" + msg
		commonlib.OutputJson(w, m, " ")
		return
	}

	m["success"] = true
	m["code"] = 200
	commonlib.OutputJson(w, m, " ")

	return
}
Beispiel #7
0
func ConsumerPayAction(w http.ResponseWriter, r *http.Request) {
	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	consumerIds := r.FormValue("ids")
	payType := r.FormValue("status")

	flag, msg, err := logic.ConsumerPay(consumerIds, payType, employee.UserId)

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	if !flag {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "操作失败:" + msg
		commonlib.OutputJson(w, m, " ")
		return
	}

	m["success"] = true
	m["code"] = 200
	m["msg"] = "操作成功"
	commonlib.OutputJson(w, m, " ")

	return
}
Beispiel #8
0
func GetCurrentEmployeeRoles(r *http.Request) (roleCodes []string, err error) {
	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		err = errors.New("用户未登陆")
		return roleCodes, err
	}

	roleCodes = strings.Split(employee.RoleCode, ",")

	return roleCodes, nil
}
Beispiel #9
0
// 获取当前用户信息
func GetCurrentEmployeeAction(w http.ResponseWriter, r *http.Request) {
	m := make(map[string]interface{})

	user_id, err := strconv.Atoi(lessgo.GetCurrentEmployee(r).UserId)
	employee, err := FindEmployeeById(user_id)

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	m["success"] = true
	m["code"] = 200
	m["datas"] = employee
	commonlib.OutputJson(w, m, " ")
}
func ChildSignInWithoutClassAction(w http.ResponseWriter, r *http.Request) {
	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	roleCodes := strings.Split(employee.RoleCode, ",")

	for _, roleCode := range roleCodes {
		if roleCode == "tmk" {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "对不起,您没有权限进行签到"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	consumerIds := r.FormValue("ids")

	flag, msg, err := logic.ChildSignInWithoutClass(consumerIds, employee.UserId)

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	if !flag {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "保存失败:" + msg
		commonlib.OutputJson(w, m, " ")
		return
	}

	m["success"] = true
	m["code"] = 200
	m["msg"] = "操作成功"
	commonlib.OutputJson(w, m, " ")

	return
}
Beispiel #11
0
func EmployeeSignInListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	dataType := ""

	roleIds := strings.Split(employee.RoleId, ",")

	for _, roleId := range roleIds {
		if roleId == "1" || roleId == "3" || roleId == "6" || roleId == "10" {
			dataType = "all"
			break
		} else if roleId == "2" {
			dataType = "center"
			break
		} else {
			dataType = "self"
		}
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	centerId := r.FormValue("cid-eq")
	st := r.FormValue("st-ge")
	et := r.FormValue("et-le")

	params := []interface{}{}

	sql := "select  esi.id,e.really_name,esi.sign_time from employee_sign_in esi left join employee e on esi.employee_id=e.user_id where 1=1 "

	if dataType == "center" {
		userId, _ := strconv.Atoi(employee.UserId)
		_employee, err := FindEmployeeById(userId)
		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}
		params = append(params, _employee.CenterId)
		sql += " and e.center_id=? "
	}

	if centerId != "" && dataType == "all" {
		params = append(params, centerId)
		sql += " and e.center_id=? "
	}

	if dataType == "self" {
		params = append(params, employee.UserId)
		sql += " and esi.employee_id=? "
	}

	if st != "" {
		params = append(params, st)
		sql += " and esi.sign_time >= ? "
	}

	if et != "" {
		params = append(params, et)
		sql += " and esi.sign_time <= ? "
	}

	countSql := ""

	countSql = "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " order by esi.id desc limit ?,?"

	lessgo.Log.Debug(sql)

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 2; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
Beispiel #12
0
func ApplyLogAddToConsumerAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	year := r.FormValue("year")
	month := r.FormValue("month")
	childName := r.FormValue("childName")
	phone := r.FormValue("phone")
	comeFrom := r.FormValue("comeFrom")
	centerId := r.FormValue("centerId")
	createTime := r.FormValue("createTime")
	applyType := r.FormValue("type")
	contactsName := childName + "家长"

	remark := ""

	if comeFrom == "网站" {
		comeFrom = "5"
		remark += "通过网站报名"
	} else if comeFrom == "微信" {
		comeFrom = "6"
		remark += "通过微信报名"
	} else {
		comeFrom = "8"
	}

	if applyType == "2" {
		remark += "美术课程"
	} else if applyType == "1" {
		remark += "英语课程"
	}

	db := lessgo.GetMySQL()
	defer db.Close()

	tx, err := db.Begin()

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	homePhoneFlag, err := CheckConsumerPhoneExist(phone)
	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	phoneFlag, err := CheckConsumerPhoneExist(phone)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	if phoneFlag {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "联系人电话已经存在,无需重复录入"
		commonlib.OutputJson(w, m, " ")
		return
	}

	if homePhoneFlag {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "家庭电话已经在系统中存在,无需重复录入"
		commonlib.OutputJson(w, m, " ")
		return
	}

	contactStatus := CONSUMER_STATUS_NO_CONTACT
	lastContactTime := ""

	if remark != "" {
		contactStatus = CONSUMER_STATUS_WAIT
		lastContactTime := strings.Replace(createTime, " ", "", -1)
		lastContactTime = strings.Replace(lastContactTime, ":", "", -1)
		lastContactTime = strings.Replace(lastContactTime, "-", "", -1)
	}

	/**********************数据插入consumer表**********************/
	insertConsumerSql := "insert into consumer_new(center_id,contact_status,home_phone,create_time,child,year,month,birthday,last_contact_time,come_from_id,remark,create_user_id,parttime_name) values(?,?,?,?,?,?,?,?,?,?,?,?,?)"
	lessgo.Log.Debug(insertConsumerSql)
	insertConsumerStmt, err := tx.Prepare(insertConsumerSql)
	if err != nil {
		tx.Rollback()

		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	insertConsumerRes, err := insertConsumerStmt.Exec(centerId, contactStatus, "", time.Now().Format("20060102150405"), childName, year, month, "", lastContactTime, comeFrom, remark, employee.UserId, "")
	if err != nil {
		tx.Rollback()

		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	consumerId, err := insertConsumerRes.LastInsertId()
	if err != nil {
		tx.Rollback()

		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	/***数据插入联系人表**/
	insertContactsSql := "insert into contacts(name,phone,is_default,consumer_id) values(?,?,?,?)"
	lessgo.Log.Debug(insertContactsSql)

	insertContactsStmt, err := tx.Prepare(insertContactsSql)
	if err != nil {
		tx.Rollback()

		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	_, err = insertContactsStmt.Exec(contactsName, phone, "1", consumerId)
	if err != nil {
		tx.Rollback()

		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	//如果添加阶段就有备注,那就要开始添加接触记录
	if remark != "" {
		insertContactLogSql := "insert into consumer_contact_log(create_user,create_time,note,consumer_id,type) values(?,?,?,?,?) "

		insertContactLogStmt, err := tx.Prepare(insertContactLogSql)
		if err != nil {
			tx.Rollback()

			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		_, err = insertContactLogStmt.Exec(employee.UserId, time.Now().Format("20060102150405"), remark, consumerId, 3)
		if err != nil {
			tx.Rollback()

			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	/******************插入parent表*****************/
	checkParentSql := "select pid from parent where telephone=? "
	lessgo.Log.Debug(checkParentSql)

	rows, err := db.Query(checkParentSql, phone)
	pid := 0

	if rows.Next() {
		err := commonlib.PutRecord(rows, &pid)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	if pid != 0 {
		updateConsumerSql := "update consumer_new set parent_id=? where id=? "
		lessgo.Log.Debug(updateConsumerSql)
		stmt, err := tx.Prepare(updateConsumerSql)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		_, err = stmt.Exec(pid, consumerId)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}
	} else {
		insertParentSql := "insert into parent(name,password,telephone,reg_date,come_form) values(?,?,?,?,?)"
		lessgo.Log.Debug(insertParentSql)
		stmt, err := tx.Prepare(insertParentSql)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		newParentName := childName + "家长"
		if contactsName != "" {
			newParentName = contactsName
		}

		res, err := stmt.Exec(newParentName, "123456", phone, time.Now().Format("20060102150405"), 2)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		newParentId, err := res.LastInsertId()
		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		insertChildSql := "insert into child(name,pid,sex,birthday,center_id) values(?,?,?,?,?)"
		lessgo.Log.Debug(insertChildSql)

		stmt, err = tx.Prepare(insertChildSql)
		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		childBirthday := "20090101"
		if year != "" && month != "" {
			childBirthday = year + month + "01"
		} else if year != "" {
			childBirthday = year + "0101"
		}

		_, err = stmt.Exec(childName, newParentId, 1, childBirthday, centerId)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		updateConsumerSql := "update consumer_new set parent_id=? where id=? "
		lessgo.Log.Debug(updateConsumerSql)

		stmt, err = tx.Prepare(updateConsumerSql)
		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		_, err = stmt.Exec(newParentId, consumerId)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	tx.Commit()

	m["success"] = true
	m["msg"] = "操作成功"
	commonlib.OutputJson(w, m, " ")
}
Beispiel #13
0
func AddCardToSignInAction(w http.ResponseWriter, r *http.Request) {
	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	ids := r.FormValue("ids")
	childId := r.FormValue("childId")

	signInIdList := strings.Split(ids, ",")

	db := lessgo.GetMySQL()
	defer db.Close()

	getCardIdSql := "select card_id from child where cid=? "
	lessgo.Log.Debug(getCardIdSql)
	rows, err := db.Query(getCardIdSql, childId)

	cardId := ""

	if rows.Next() {
		err := commonlib.PutRecord(rows, &cardId)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	if cardId == "00000000" || cardId == "" {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "当前学生没有配置卡号,请配置后再补登"
		commonlib.OutputJson(w, m, " ")
		return
	}

	tx, err := db.Begin()
	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	for _, signInId := range signInIdList {
		updateSql := "update sign_in set card_id=? where sid=? "
		lessgo.Log.Debug(updateSql)

		stmt, err := tx.Prepare(updateSql)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		_, err = stmt.Exec(cardId, signInId)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	tx.Commit()

	m["success"] = true
	m["code"] = 200
	m["msg"] = "操作成功"
	commonlib.OutputJson(w, m, " ")
	return
}
/*
select ce.cid,ce.name,a.num as '全部名单', b.num as '未联系', c.num as '待确认', d.num as '已废弃', e.num as '已邀约',f.num as '已签到'  from center ce
left join
(select count(1) num,center_id from consumer_new group by center_id )a on a.center_id=ce.cid
left join
(select count(1) num,center_id from consumer_new where contact_status=1 group by center_id )b on a.center_id=ce.cid
left join
(select count(1) num,center_id from consumer_new where contact_status=2 group by center_id )c on b.center_id=ce.cid
left join
(select count(1) num,center_id from consumer_new where contact_status=3 group by center_id )d on c.center_id=ce.cid
left join
(select count(1) num,center_id from consumer_new where contact_status=4 group by center_id )e on d.center_id=ce.cid
left join
(select count(1) num,center_id from consumer_new where contact_status=5 group by center_id )f on e.center_id=ce.cid
*/
func CallCenterStatisticsAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	dataType := ""

	roleCodes := strings.Split(employee.RoleCode, ",")

	for _, roleCode := range roleCodes {
		if roleCode == "admin" || roleCode == "yyzj" || roleCode == "zjl" || roleCode == "yyzy" {
			dataType = "all"
			break
		} else {
			dataType = "center"
			break
		}
	}

	startTime := r.FormValue("startTime-ge")
	endTime := r.FormValue("endTime-le")

	params := []interface{}{}

	sql := " select ce.cid,ce.name,a.num as '全部名单', b.num as '未联系', c.num as '拨打电话数', d.num as '邀约数', e.num as '签到数',f.num as '定金',g.num as '全额',1,2,3  from center ce "
	sql += " left join "
	sql += " (select count(1) num,center_id from consumer_new group by center_id )a on a.center_id=ce.cid "
	sql += " left join "
	sql += " (select count(1) num,center_id from consumer_new where contact_status=1 group by center_id )b on b.center_id=ce.cid "
	sql += " left join "
	sql += " (select count(1) num,cid from audio where start_time >=? and start_time<=? group by cid )c on c.cid=ce.cid "
	sql += " left join "
	sql += " (select count(1) num,ch.center_id from schedule_detail_child sdc left join child ch on sdc.child_id=ch.cid where sdc.is_free=1 and sdc.create_time>=? and sdc.create_time <=? group by ch.center_id)d on d.center_id=ce.cid "
	sql += " left join "
	sql += " (select count(1) num,ch.center_id from sign_in si left join child ch on si.child_id=ch.cid where si.type=1 and  si.is_free=1 and si.sign_time>=? and si.sign_time<=? group by ch.center_id )e on e.center_id=ce.cid "
	sql += " left join "
	sql += " (select count(1) num,center_id from consumer_new where pay_status=1 and pay_time>=? and pay_time<=? group by center_id )f on f.center_id=ce.cid "
	sql += " left join "
	sql += " (select count(1) num,center_id from consumer_new where pay_status=2 and pay_time>=? and pay_time<=? group by center_id )g on g.center_id=ce.cid where ce.cid!=9 " //屏蔽总部数据

	defaultStartTime := "2000-01-01 00:0:000"
	defaultEndTime := "2999-12-31 00:00:00"

	if startTime != "" {
		defaultStartTime = startTime
	}

	if endTime != "" {
		defaultEndTime = endTime
	}
	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)

	defaultStartTime = strings.Replace(defaultStartTime, "-", "", -1)

	defaultEndTime = strings.Replace(defaultEndTime, "-", "", -1)

	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)
	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)
	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)
	params = append(params, defaultStartTime)
	params = append(params, defaultEndTime)

	userId, _ := strconv.Atoi(employee.UserId)
	_employee, err := FindEmployeeById(userId)

	if dataType == "center" {
		sql += " and ce.cid=? "

		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		params = append(params, _employee.CenterId)
	}

	countSql := "select count(1) from center where cid!=9 "

	if dataType == "center" {
		countSql += " and cid=" + _employee.CenterId
	}

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " order by ce.cid limit ?,?"

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	lessgo.Log.Debug(sql)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 11; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")
}
func ClassScheduleAttachListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		lessgo.Log.Error(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	childId := r.FormValue("childId")
	scheduleId := r.FormValue("scheduleId")

	params := []interface{}{}

	sql := "select csa.id,csa.url,csa.intro,csa.upload_time,csa.pc_thumb_url,ce.domain_name from class_schedule_attach csa left join class_schedule_detail csd on csd.id=csa.schedule_detail_id left join center ce on ce.cid=csd.center_id where csa.schedule_detail_id=? and csa.relation_childs like ? "
	lessgo.Log.Debug(sql)

	db := lessgo.GetMySQL()
	defer db.Close()

	countSql := ""

	countSql = "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	params = append(params, scheduleId)
	params = append(params, "%["+childId+"]%")

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " limit ?,? "

	lessgo.Log.Debug(sql)

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 5; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
Beispiel #16
0
//短信发送
func WyClassSendSMSSaveAction(w http.ResponseWriter, r *http.Request) {
	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	classId := r.FormValue("classId")
	scheduleId := r.FormValue("scheduleId")
	consumerIds := r.FormValue("consumerIds")
	phones := r.FormValue("phones")
	content := r.FormValue("content")

	phoneList := strings.Split(phones, ",")
	consumerIdList := strings.Split(consumerIds, ",")

	db := lessgo.GetMySQL()
	defer db.Close()

	tx, err := db.Begin()

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	for index, phone := range phoneList {
		if phone != "" {
			getConsumerInfo := "select name from child  where cid=?"
			lessgo.Log.Debug(getConsumerInfo)
			rows, err := db.Query(getConsumerInfo, consumerIdList[index])

			if err != nil {
				lessgo.Log.Warn(err.Error())
				m["success"] = false
				m["code"] = 100
				m["msg"] = "系统发生错误,请联系IT部门"
				commonlib.OutputJson(w, m, " ")
				return
			}

			var childName string

			if rows.Next() {
				err := rows.Scan(&childName)

				if err != nil {
					lessgo.Log.Warn(err.Error())
					m["success"] = false
					m["code"] = 100
					m["msg"] = "系统发生错误,请联系IT部门"
					commonlib.OutputJson(w, m, " ")
					continue
				}
			}

			contentDetail := getSmsContent(content, childName)
			//			smsResult := SmsResult{Msg: "asdas", Result: 0}
			smsResult, err := SendMessage(phone, contentDetail)

			if err != nil {
				lessgo.Log.Warn(err.Error())
				m["success"] = false
				m["code"] = 100
				m["msg"] = "系统发生错误,请联系IT部门"
				commonlib.OutputJson(w, m, " ")
				return
			}

			if smsResult.Result != 0 { //请求短信接口没有成功
				m["success"] = false
				m["code"] = 100
				m["msg"] = "短信发送错误,请联系IT部门"
				commonlib.OutputJson(w, m, " ")
				return
			}

			smsStatus := ""

			if smsResult.Result == 0 { //发送成功
				smsStatus = "2"
			} else {
				smsStatus = "3"
			}

			updateClassSmsStatus := "update schedule_detail_child set sms_status=? where child_id=? and schedule_detail_id=? "
			lessgo.Log.Debug(updateClassSmsStatus)

			stmt, err := tx.Prepare(updateClassSmsStatus)

			if err != nil {
				tx.Rollback()
				lessgo.Log.Warn(err.Error())
				m["success"] = false
				m["code"] = 100
				m["msg"] = "系统发生错误,请联系IT部门" + err.Error()
				commonlib.OutputJson(w, m, " ")
				return
			}

			_, err = stmt.Exec(smsStatus, consumerIdList[index], scheduleId)
			if err != nil {
				tx.Rollback()
				lessgo.Log.Warn(err.Error())
				m["success"] = false
				m["code"] = 100
				m["msg"] = "系统发生错误,请联系IT部门"
				commonlib.OutputJson(w, m, " ")
				return
			}

			insertSmsLog := "insert into sms_send_log(phone,content,result_code,result_msg,send_time,send_status) values(?,?,?,?,?,?) "
			lessgo.Log.Debug(insertSmsLog)

			stmt, err = tx.Prepare(insertSmsLog)

			if err != nil {
				lessgo.Log.Warn(err.Error())
				m["success"] = false
				m["code"] = 100
				m["msg"] = "系统发生错误,请联系IT部门" + err.Error()
				commonlib.OutputJson(w, m, " ")
				return
			}

			_, err = stmt.Exec(phone, contentDetail, smsResult.Result, smsResult.Msg, time.Now().Format("20060102150405"), 3)
			if err != nil {
				tx.Rollback()
				lessgo.Log.Warn(err.Error())
				m["success"] = false
				m["code"] = 100
				m["msg"] = "系统发生错误,请联系IT部门"
				commonlib.OutputJson(w, m, " ")
				return
			}
		}
	}

	tx.Commit()

	m["success"] = true
	m["code"] = 200
	m["msg"] = "操作成功"
	commonlib.OutputJson(w, m, " ")
	return

}
Beispiel #17
0
func WyClassSendSMSLoadAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	id := r.FormValue("ids")
	classId := r.FormValue("classId")
	scheduleId := r.FormValue("scheduleId")
	centerId := r.FormValue("centerId-eq")

	loadFormObjects := []lessgo.LoadFormObject{}

	findPhoneSql := "select ch.cid,p.telephone,ch.name from child ch left join parent p on p.pid=ch.pid where ch.cid in (" + id + ")"
	lessgo.Log.Debug(findPhoneSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(findPhoneSql)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	phonesContent := ""
	phones := ""
	consumerIds := ""

	for rows.Next() {
		var consumerId, phone, childName string
		err = commonlib.PutRecord(rows, &consumerId, &phone, &childName)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		if len(phone) != 11 { //不是手机号码
			continue
		}

		phonesContent += phone + "(" + childName + "),"
		phones += phone + ","
		consumerIds += consumerId + ","
	}

	if phones == "" {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "本次没有可以发送的号码,请重新选择"
		commonlib.OutputJson(w, m, " ")
		return
	}

	h1 := lessgo.LoadFormObject{"phonesContent", phonesContent}
	h2 := lessgo.LoadFormObject{"phones", phones}
	h4 := lessgo.LoadFormObject{"consumerIds", consumerIds}
	h5 := lessgo.LoadFormObject{"classId", classId}
	h6 := lessgo.LoadFormObject{"centerId", centerId}
	h7 := lessgo.LoadFormObject{"scheduleId", scheduleId}

	getCenterInfo := "select ce.name,ce.intro,class.name,class.start_time from wyclass class left join center ce on ce.cid=class.center_id where class.class_id=?"
	lessgo.Log.Debug(getCenterInfo)
	rows, err = db.Query(getCenterInfo, classId)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	var centerName, centerIntro, className, classStartTime string

	if rows.Next() {
		err := commonlib.PutRecord(rows, &centerName, &centerIntro, &className, &classStartTime)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	h3 := lessgo.LoadFormObject{"content", getSmsTmpText(employee.ReallyName, "$child", centerIntro, classStartTime)}

	loadFormObjects = append(loadFormObjects, h1)
	loadFormObjects = append(loadFormObjects, h2)
	loadFormObjects = append(loadFormObjects, h3)
	loadFormObjects = append(loadFormObjects, h4)
	loadFormObjects = append(loadFormObjects, h5)
	loadFormObjects = append(loadFormObjects, h6)
	loadFormObjects = append(loadFormObjects, h7)

	m["success"] = true
	m["datas"] = loadFormObjects
	commonlib.OutputJson(w, m, " ")
	return
}
Beispiel #18
0
func ChildSignInLogListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	childId := r.FormValue("childId")
	startTime := r.FormValue("startTime-ge")
	endTime := r.FormValue("endTime-le")

	params := []interface{}{}

	sql := `
	select si.sid,si.sign_time,contr.contract_no,si.card_id,cour.name,contr.apply_time,cour1.name courseName1
	 		from sign_in si
	 				left join class_schedule_detail csd on csd.id=si.schedule_detail_id
	 				left join contract contr on contr.id=si.contract_id
	 				left join course cour on cour.cid=contr.course_id
	 				left join course cour1 on cour1.cid=csd.course_id
	 		where si.child_id=? and si.is_free=2 `

	params = append(params, childId)

	if startTime != "" {
		sql += " and si.sign_time>=? "
		params = append(params, startTime)
	}

	if endTime != "" {
		sql += " and si.sign_time<=? "
		params = append(params, endTime)
	}

	countSql := ""

	countSql = "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " order by si.sign_time desc limit ?,?"

	lessgo.Log.Debug(sql)

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < 6; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
Beispiel #19
0
func CourseSaveAction(w http.ResponseWriter, r *http.Request) {
	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	id := r.FormValue("id")
	name := r.FormValue("name")
	typeString := r.FormValue("type")

	if id == "" {
		userId, _ := strconv.Atoi(employee.UserId)
		_employee, err := logic.FindEmployeeById(userId)
		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		flag, msg, err := logic.InsertCourse(_employee.CenterId, name, typeString)

		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		if !flag {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "操作失败:" + msg
			commonlib.OutputJson(w, m, " ")
			return
		}
	} else {
		flag, msg, err := logic.UpdateCourse(id, name, typeString)

		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		if !flag {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "操作失败:" + msg
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	m["success"] = true
	m["code"] = 200
	m["msg"] = "操作成功"
	commonlib.OutputJson(w, m, " ")

	return
}
Beispiel #20
0
func AddContractToSignInAction(w http.ResponseWriter, r *http.Request) {
	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	ids := r.FormValue("ids")
	contractId := r.FormValue("contractId")

	signInIdList := strings.Split(ids, ",")

	db := lessgo.GetMySQL()
	defer db.Close()

	tx, err := db.Begin()
	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	for _, signInId := range signInIdList {
		updateSql := "update sign_in set contract_id=? where sid=? "
		lessgo.Log.Debug(updateSql)

		stmt, err := tx.Prepare(updateSql)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		_, err = stmt.Exec(contractId, signInId)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	tx.Commit()

	m["success"] = true
	m["code"] = 200
	m["msg"] = "操作成功"
	commonlib.OutputJson(w, m, " ")
	return
}
//顾问分页数据服务
func VideoListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	dataType := ""

	roleIds := strings.Split(employee.RoleId, ",")

	for _, roleId := range roleIds {
		if roleId == "1" || roleId == "3" || roleId == "6" || roleId == "10" {
			dataType = "all"
			break
		} else if roleId == "2" {
			dataType = "center"
			break
		} else {
			dataType = "self"
		}
	}

	//fmt.Println("dataType:" ,dataType, ",roleIds:", roleIds)
	//r.FormValue("cid-eq")
	//fmt.Println(r.Form)

	sql := ""

	params := []interface{}{}

	if dataType == "all" {
		sql += `select v.vid,v.cid,ce.name as centername,r.name rname,c.course_id,co.name,c.teacher_id,e.really_name,v.start_time,v.end_time from
				video v left join class_schedule_detail c on v.schedule_detail_id=c.id left join room r on r.rid=v.rid left join employee e
					on c.teacher_id=e.user_id left join course co on c.course_id=co.cid left join center ce on v.cid=ce.cid
						where data_rel_status=2`
	} else if dataType == "center" {
		sql += `select v.vid,v.cid,ce.name as centername,r.name rname,c.course_id,co.name,c.teacher_id,e.really_name,v.start_time,v.end_time from
				video v left join class_schedule_detail c on v.schedule_detail_id=c.id left join room r on r.rid=v.rid left join employee e
					on c.teacher_id=e.user_id left join course co on c.course_id=co.cid left join center ce on v.cid=ce.cid
						where v.cid=? and data_rel_status=2`
		userId, _ := strconv.Atoi(employee.UserId)
		_employee, err := FindEmployeeById(userId)
		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		params = append(params, _employee.CenterId)

	} else if dataType == "self" {
		sql += `select v.vid,v.cid,ce.name as centername,r.name rname,c.course_id,co.name,c.teacher_id,e.really_name,v.start_time,v.end_time from
			video v left join class_schedule_detail c on v.schedule_detail_id=c.id left join room r on r.rid=v.rid left join employee e
				on c.teacher_id=e.user_id left join course co on c.course_id=co.cid left join center ce on v.cid=ce.cid
					where c.teacher_id=? and data_rel_status=2`

		params = append(params, employee.UserId)
	}

	center_id := r.FormValue("cid-eq")
	if center_id != "" {
		sql += " and v.cid=?"
		params = append(params, center_id)
		lessgo.Log.Debug(sql)
		lessgo.Log.Debug(params)
	}

	course_id := r.FormValue("courseId-eq")
	if course_id != "" {
		sql += " and c.course_id=?"
		params = append(params, course_id)
		lessgo.Log.Debug(params...)
	}

	name := r.FormValue("name-like")
	if name != "" {
		sql += " and e.really_name like ?"
		params = append(params, "%"+name+"%")
	}

	countSql := "select count(1) from (" + sql + ") num"

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)
	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	lessgo.Log.Debug(sql + " limit ?,?")
	lessgo.Log.Debug(params...)
	lessgo.Log.Debug(params[0], ":", params[1])
	rows, err = db.Query(sql+" limit ?,?", params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}
	colums, _ := rows.Columns()
	column_len := len(colums) - 1
	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)

		fillObjects := []interface{}{}

		fillObjects = append(fillObjects, &model.Id)

		for i := 0; i < column_len; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
func ClassScheduleDetailModifyAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		lessgo.Log.Error(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	scheduleId := r.FormValue("scheduleId")
	name := r.FormValue("name")
	code := r.FormValue("code")
	teacherId := r.FormValue("teacherId")
	assistantId := r.FormValue("assistantId")
	scheduleType := r.FormValue("type")
	classId := r.FormValue("classId")

	db := lessgo.GetMySQL()
	defer db.Close()

	tx, err := db.Begin()
	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	if scheduleType == "normal" {

		updateSql := "update class_schedule_detail set teacher_id=?,assistant_id=? where id=?"
		lessgo.Log.Debug(updateSql)

		stmt, err := tx.Prepare(updateSql)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		_, err = stmt.Exec(teacherId, assistantId, scheduleId)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		tx.Commit()

		m["success"] = true
		commonlib.OutputJson(w, m, " ")
	} else {
		updateSql := "update wyclass set name=? , code=? where class_id=?"
		lessgo.Log.Debug(updateSql)

		stmt, err := tx.Prepare(updateSql)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		_, err = stmt.Exec(name, code, classId)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		tx.Commit()

		m["success"] = true
		commonlib.OutputJson(w, m, " ")
	}
}
func CreateWeekScheduleAction(w http.ResponseWriter, r *http.Request) {
	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	userId, _ := strconv.Atoi(employee.UserId)
	_employee, err := logic.FindEmployeeById(userId)
	if err != nil {
		lessgo.Log.Error(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	err = r.ParseForm()

	if err != nil {
		lessgo.Log.Error(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	firstDayOfWeek := r.FormValue("firstDayOfWeek")

	flag, msg, err := logic.CreateWeekSchedule(_employee.CenterId, firstDayOfWeek, employee.UserId)

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	if !flag {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "保存失败:" + msg
		commonlib.OutputJson(w, m, " ")
		return
	}

	m["success"] = true
	m["code"] = 200
	commonlib.OutputJson(w, m, " ")

	return
}
//课表读取
func ClassScheduleDetailLoadAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	id := r.FormValue("scheduleId")
	roomId := r.FormValue("roomId")
	timeId := r.FormValue("timeId")
	week := r.FormValue("week")
	date := r.FormValue("date")
	//	schedule := r.FormValue("type")

	db := lessgo.GetMySQL()
	defer db.Close()

	loadFormObjects := []lessgo.LoadFormObject{}

	if id != "" {
		getScheduleDetailSql := "select csd.teacher_id,csd.assistant_id,wc.name,wc.code,wc.class_id from class_schedule_detail csd left join wyclass wc on wc.class_id=csd.class_id where csd.id=?"
		lessgo.Log.Debug(getScheduleDetailSql)

		rows, err := db.Query(getScheduleDetailSql, id)

		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		var teacherId, assistantId, className, classCode, classId string

		if rows.Next() {
			err = commonlib.PutRecord(rows, &teacherId, &assistantId, &className, &classCode, &classId)

			if err != nil {
				m["success"] = false
				m["code"] = 100
				m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
				commonlib.OutputJson(w, m, " ")
				return
			}
		}

		m["success"] = true

		h1 := lessgo.LoadFormObject{"scheduleId", id}
		h2 := lessgo.LoadFormObject{"name", className}
		h3 := lessgo.LoadFormObject{"code", classCode}
		h4 := lessgo.LoadFormObject{"teacherId", teacherId}
		h5 := lessgo.LoadFormObject{"assistantId", assistantId}
		h6 := lessgo.LoadFormObject{"classId", classId}

		loadFormObjects = append(loadFormObjects, h1)
		loadFormObjects = append(loadFormObjects, h2)
		loadFormObjects = append(loadFormObjects, h3)
		loadFormObjects = append(loadFormObjects, h4)
		loadFormObjects = append(loadFormObjects, h5)
		loadFormObjects = append(loadFormObjects, h6)
	} else {
		roomInfoSql := "select name from room where rid=? "
		lessgo.Log.Debug(roomInfoSql)

		rows, err := db.Query(roomInfoSql, roomId)

		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		var roomName string

		if rows.Next() {
			err = commonlib.PutRecord(rows, &roomName)

			if err != nil {
				m["success"] = false
				m["code"] = 100
				m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
				commonlib.OutputJson(w, m, " ")
				return
			}
		}

		timeInfoSql := "select start_time,end_time from time_section where id=?"
		lessgo.Log.Debug(timeInfoSql)

		rows, err = db.Query(timeInfoSql, timeId)

		if err != nil {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		var startTime, endTime string

		if rows.Next() {
			err = commonlib.PutRecord(rows, &startTime, &endTime)

			if err != nil {
				m["success"] = false
				m["code"] = 100
				m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
				commonlib.OutputJson(w, m, " ")
				return
			}
		}

		weekDesc := ""
		if week == "1" {
			weekDesc = "星期一"
		} else if week == "2" {
			weekDesc = "星期二"
		} else if week == "3" {
			weekDesc = "星期三"
		} else if week == "4" {
			weekDesc = "星期四"
		} else if week == "5" {
			weekDesc = "星期五"
		} else if week == "6" {
			weekDesc = "星期六"
		} else if week == "7" {
			weekDesc = "星期日"
		}

		m["success"] = true

		h1 := lessgo.LoadFormObject{"id", id}
		h2 := lessgo.LoadFormObject{"roomId", roomId}
		h3 := lessgo.LoadFormObject{"timeId", timeId}
		h4 := lessgo.LoadFormObject{"roomName", roomName}
		h5 := lessgo.LoadFormObject{"timeDesc", startTime + "~" + endTime}
		h6 := lessgo.LoadFormObject{"weekDesc", date + "(" + weekDesc + ")"}
		h7 := lessgo.LoadFormObject{"week", week}
		h8 := lessgo.LoadFormObject{"date", date}
		h9 := lessgo.LoadFormObject{"capacity", "10"}

		loadFormObjects = append(loadFormObjects, h1)
		loadFormObjects = append(loadFormObjects, h2)
		loadFormObjects = append(loadFormObjects, h3)
		loadFormObjects = append(loadFormObjects, h4)
		loadFormObjects = append(loadFormObjects, h5)
		loadFormObjects = append(loadFormObjects, h6)
		loadFormObjects = append(loadFormObjects, h7)
		loadFormObjects = append(loadFormObjects, h8)
		loadFormObjects = append(loadFormObjects, h9)
	}

	m["datas"] = loadFormObjects
	commonlib.OutputJson(w, m, " ")
}
func RemoveChildFromScheduleAction(w http.ResponseWriter, r *http.Request) {
	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	roleCodes := strings.Split(employee.RoleCode, ",")

	dataType := ""

	for _, roleCode := range roleCodes {
		if roleCode == "admin" || roleCode == "yyzj" || roleCode == "zjl" || roleCode == "yyzy" || roleCode == "cd" {
			dataType = "all"
			break
		} else {
			dataType = "self"
			break
		}
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	classId := r.FormValue("classId")
	scheduleId := r.FormValue("scheduleId")
	childId := r.FormValue("childId")

	flag, msg, err := logic.RemoveChildFromSchedule(childId, scheduleId, classId, dataType, employee.UserId)

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	if !flag {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "操作失败:" + msg
		commonlib.OutputJson(w, m, " ")
		return
	}

	m["success"] = true
	m["code"] = 200
	m["msg"] = "操作成功"
	commonlib.OutputJson(w, m, " ")

	return
}
//仅删除课表,不删除模板
func DeleteSingleScheduleAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	scheduleId := r.FormValue("scheduleId")

	db := lessgo.GetMySQL()
	defer db.Close()

	checkExistSql := "select count(1) from schedule_detail_child where schedule_detail_id=?"

	lessgo.Log.Debug(checkExistSql)

	rows, err := db.Query(checkExistSql, scheduleId)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	num := 0

	if rows.Next() {

		err = commonlib.PutRecord(rows, &num)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	if num > 0 {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "有人上课,不能删除"
		commonlib.OutputJson(w, m, " ")
		return
	}

	tx, err := db.Begin()
	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	deteleSql := "delete from class_schedule_detail where id=?"

	lessgo.Log.Debug(deteleSql)

	stmt, err := tx.Prepare(deteleSql)

	if err != nil {
		tx.Rollback()
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	_, err = stmt.Exec(scheduleId)

	if err != nil {
		tx.Rollback()
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	tx.Commit()

	m["success"] = true
	m["code"] = 200
	m["msg"] = "操作成功"
	commonlib.OutputJson(w, m, " ")
	return
}
func ClassScheduleDetailPageAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	dataType := ""

	roleCodes := strings.Split(employee.RoleCode, ",")

	for _, roleCode := range roleCodes {
		if roleCode == "admin" || roleCode == "yyzj" || roleCode == "zjl" || roleCode == "yyzy" || roleCode == "tmk" {
			dataType = "all"
			break
		} else {
			dataType = "center"
			break
		}
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	pageNoString := r.FormValue("page")
	pageNo := 1
	if pageNoString != "" {
		pageNo, err = strconv.Atoi(pageNoString)
		if err != nil {
			pageNo = 1
			lessgo.Log.Warn("错误的pageNo:", pageNo)
		}
	}

	pageSizeString := r.FormValue("rows")
	pageSize := 10
	if pageSizeString != "" {
		pageSize, err = strconv.Atoi(pageSizeString)
		if err != nil {
			lessgo.Log.Warn("错误的pageSize:", pageSize)
		}
	}

	centerId := r.FormValue("cid-eq")
	kw := r.FormValue("kw-eq")

	pageData, err := logic.ClassScheduleDetailPage(centerId, kw, dataType, employee.UserId, pageNo, pageSize)

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1

	commonlib.RenderTemplate(w, r, "page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/page.json")
}
/*
课表查询sql
select csd.id,csd.room_id,csd.time_id,csd.course_id,teacher.really_name teaName,assistant.really_name assName,personNum.num perNum,signNum.num sigNum,wc.name,cour.name from class_schedule_detail csd
left join employee teacher on teacher.user_id=csd.teacher_id
left join employee assistant on assistant.user_id=csd.assistant_id
left join (select count(1) num,schedule_detail_id from schedule_detail_child group by schedule_detail_id) personNum on personNum.schedule_detail_id = csd.id
left join time_section ts on ts.id=csd.time_id
left join (select count(1) num,schedule_detail_id from sign_in group by schedule_detail_id) signNum on signNum.schedule_detail_id = csd.id
left join wyclass wc on wc.class_id=csd.class_id
left join course cour on cour.cid=csd.course_id
*/
func ClassScheduleDetailListAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		lessgo.Log.Error(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	date := r.FormValue("date")
	dateType := r.FormValue("type")

	searchDate := time.Now()

	if date != "" {
		searchDate, _ = time.ParseInLocation("20060102150405", date, time.Local)
	}

	if dateType == "pre" {
		searchDate = searchDate.Add(time.Duration(-7*24) * time.Hour)
	} else if dateType == "next" {
		searchDate = searchDate.Add(time.Duration(7*24) * time.Hour)
	}

	week := 0

	if searchDate.Weekday() == time.Monday {
		week = 1
	} else if searchDate.Weekday() == time.Tuesday {
		week = 2
	} else if searchDate.Weekday() == time.Wednesday {
		week = 3
	} else if searchDate.Weekday() == time.Thursday {
		week = 4
	} else if searchDate.Weekday() == time.Friday {
		week = 5
	} else if searchDate.Weekday() == time.Saturday {
		week = 6
	} else if searchDate.Weekday() == time.Sunday {
		week = 7
	}

	monday := searchDate.Add(-1 * time.Duration(week-1) * 24 * time.Hour)
	sunday := searchDate.Add(time.Duration(7-week) * 24 * time.Hour)
	st := monday.Format("20060102") + "000000"
	et := sunday.Format("20060102") + "235959"

	userId, _ := strconv.Atoi(employee.UserId)
	_employee, err := FindEmployeeById(userId)
	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	db := lessgo.GetMySQL()
	defer db.Close()
	rooms := []RoomOrTime{}
	times := []RoomOrTime{}
	weekdates := []Weekdate{}
	schedules := []Schedule{}

	getRoomInfoSql := "select rid,name from room where cid=? "
	lessgo.Log.Debug(getRoomInfoSql)

	rows, err := db.Query(getRoomInfoSql, _employee.CenterId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	for rows.Next() {
		room := RoomOrTime{}
		err = commonlib.PutRecord(rows, &room.Id, &room.Name)

		if err != nil {
			lessgo.Log.Error(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		rooms = append(rooms, room)
	}

	getTimeSql := "select id,start_time,end_time from time_section where center_id=? order by start_time,end_time"
	lessgo.Log.Debug(getRoomInfoSql)

	rows, err = db.Query(getTimeSql, _employee.CenterId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	for rows.Next() {
		timeObject := RoomOrTime{}
		startTime := ""
		endTime := ""
		err = commonlib.PutRecord(rows, &timeObject.Id, &startTime, &endTime)
		timeObject.Name = startTime + "~" + endTime

		if err != nil {
			lessgo.Log.Error(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		times = append(times, timeObject)
	}

	for i := 0; i < 7; i++ {
		var weekdate = Weekdate{}
		if i == 0 {
			weekdate.Week = "星期一"
		} else if i == 1 {
			weekdate.Week = "星期二"
		} else if i == 2 {
			weekdate.Week = "星期三"
		} else if i == 3 {
			weekdate.Week = "星期四"
		} else if i == 4 {
			weekdate.Week = "星期五"
		} else if i == 5 {
			weekdate.Week = "星期六"
		} else if i == 6 {
			weekdate.Week = "星期日"
		}

		theday := monday.Add(time.Duration(i*24) * time.Hour)
		weekdate.Date = theday.Format("2006-01-02")

		weekdates = append(weekdates, weekdate)
	}

	getScheduleInfoSql := "select csd.id,csd.room_id,csd.time_id,csd.course_id,teacher.really_name teaName,assistant.really_name assName,personNum.num perNum,signNum.num sigNum,wc.name,cour.name,csd.week,csd.class_id,csd.center_id,wc.code from class_schedule_detail csd "
	getScheduleInfoSql += " left join employee teacher on teacher.user_id=csd.teacher_id  "
	getScheduleInfoSql += " left join employee assistant on assistant.user_id=csd.assistant_id "
	getScheduleInfoSql += " left join (select count(1) num,schedule_detail_id from schedule_detail_child group by schedule_detail_id) personNum on personNum.schedule_detail_id = csd.id "
	getScheduleInfoSql += " left join time_section ts on ts.id=csd.time_id "
	getScheduleInfoSql += " left join (select count(1) num,schedule_detail_id from sign_in group by schedule_detail_id) signNum on signNum.schedule_detail_id = csd.id "
	getScheduleInfoSql += " left join wyclass wc on wc.class_id=csd.class_id "
	getScheduleInfoSql += " left join course cour on cour.cid=csd.course_id "
	getScheduleInfoSql += " where csd.start_time>=? and csd.start_time<=? and csd.center_id=? "
	lessgo.Log.Debug(getScheduleInfoSql)

	rows, err = db.Query(getScheduleInfoSql, st, et, _employee.CenterId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	for rows.Next() {
		schedule := Schedule{}
		courseId := 0
		className := ""
		courseName := ""

		err = commonlib.PutRecord(rows, &schedule.Id, &schedule.RoomId, &schedule.TimeId, &courseId, &schedule.Teacher, &schedule.Assistant, &schedule.PersonNum, &schedule.SignNum, &className, &courseName, &schedule.Week, &schedule.ClassId, &schedule.CenterId, &schedule.Code)

		if err != nil {
			lessgo.Log.Error(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		if courseId != 0 {
			schedule.IsNormal = 1
			schedule.Name = courseName
		} else {
			schedule.IsNormal = 2
			schedule.Name = className
		}

		schedules = append(schedules, schedule)
	}

	m["success"] = true
	m["code"] = 200
	m["msg"] = "成功"
	m["times"] = times
	m["rooms"] = rooms
	m["weekdates"] = weekdates
	m["schedules"] = schedules
	m["firstDayOfWeek"] = st

	commonlib.OutputJson(w, m, "")
}
func RemoveChildFromScheduleForNormalAction(w http.ResponseWriter, r *http.Request) {
	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	roleCodes := strings.Split(employee.RoleCode, ",")

	for _, roleCode := range roleCodes {
		if roleCode == "tmk" {
			m["success"] = false
			m["code"] = 100
			m["msg"] = "对不起,您没有权限进行结课操作"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	scheduleId := r.FormValue("scheduleId")
	childId := r.FormValue("childId")

	flag, msg, err := logic.RemoveChildFromScheduleForNormalAction(childId, scheduleId, employee.UserId)

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	if !flag {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "操作失败:" + msg
		commonlib.OutputJson(w, m, " ")
		return
	}

	m["success"] = true
	m["code"] = 200
	m["msg"] = "操作成功"
	commonlib.OutputJson(w, m, " ")

	return
}
func ClassScheduleDetailAddAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		lessgo.Log.Error(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	userId, _ := strconv.Atoi(employee.UserId)
	_employee, err := FindEmployeeById(userId)
	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	roomId := r.FormValue("roomId")
	timeId := r.FormValue("timeId")
	courseId := r.FormValue("courseId")
	teacherId := r.FormValue("teacherId")
	assistantId := r.FormValue("assistantId")
	week := r.FormValue("week")
	date := r.FormValue("date")
	scheduleType := r.FormValue("type")
	isTmp := r.FormValue("isTmp")
	capacity := r.FormValue("capacity")
	name := r.FormValue("name")
	code := r.FormValue("code")

	date = strings.Replace(date, "-", "", -1)

	timeSection, err := FindTimeSectionById(timeId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	startTime := date + strings.Replace(timeSection.StartTime, ":", "", -1) + "00"
	endTime := date + strings.Replace(timeSection.EndTime, ":", "", -1) + "00"

	db := lessgo.GetMySQL()
	defer db.Close()

	tx, err := db.Begin()
	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	if scheduleType == "normal" {

		insertScheduleSql := "insert into class_schedule_detail(teacher_id,assistant_id,course_id,center_id,time_id,room_id,day_date,week,start_time,end_time,status,capacity) values(?,?,?,?,?,?,?,?,?,?,?,?)"
		lessgo.Log.Debug(insertScheduleSql)

		stmt, err := tx.Prepare(insertScheduleSql)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		_, err = stmt.Exec(teacherId, assistantId, courseId, _employee.CenterId, timeId, roomId, date, week, startTime, endTime, 1, capacity)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		if isTmp == "1" {
			selectTmpSql := "select id from schedule_template where center_id=? and room_id=? and time_id=? and week=? "
			lessgo.Log.Debug(selectTmpSql)

			rows, err := db.Query(selectTmpSql, _employee.CenterId, roomId, timeId, week)

			scheduleTemplateId := 0

			if rows.Next() {
				err := commonlib.PutRecord(rows, &scheduleTemplateId)

				if err != nil {
					lessgo.Log.Warn(err.Error())
					m["success"] = false
					m["code"] = 100
					m["msg"] = "系统发生错误,请联系IT部门"
					commonlib.OutputJson(w, m, " ")
					return
				}
			}

			if scheduleTemplateId == 0 {
				insertScheduleTmpSql := "insert into schedule_template(center_id,room_id,teacher_id,assistant_id,time_id,week,course_id) values(?,?,?,?,?,?,?)"
				lessgo.Log.Debug(insertScheduleTmpSql)

				stmt, err = tx.Prepare(insertScheduleTmpSql)

				if err != nil {
					lessgo.Log.Warn(err.Error())
					m["success"] = false
					m["code"] = 100
					m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
					commonlib.OutputJson(w, m, " ")
					return
				}

				_, err = stmt.Exec(_employee.CenterId, roomId, teacherId, assistantId, timeId, week, courseId)

				if err != nil {
					lessgo.Log.Warn(err.Error())
					m["success"] = false
					m["code"] = 100
					m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
					commonlib.OutputJson(w, m, " ")
					return
				}
			} else {
				updateScheduleTmpSql := "update schedule_template set teacher_id=?, assistant_id=?,course_id=? where id=? "
				lessgo.Log.Debug(updateScheduleTmpSql)

				stmt, err = tx.Prepare(updateScheduleTmpSql)
				if err != nil {
					lessgo.Log.Warn(err.Error())
					m["success"] = false
					m["code"] = 100
					m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
					commonlib.OutputJson(w, m, " ")
					return
				}
				_, err = stmt.Exec(teacherId, assistantId, courseId, scheduleTemplateId)

				if err != nil {
					lessgo.Log.Warn(err.Error())
					m["success"] = false
					m["code"] = 100
					m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
					commonlib.OutputJson(w, m, " ")
					return
				}
			}

		}

		tx.Commit()

		m["success"] = true
		commonlib.OutputJson(w, m, " ")
	} else {
		insertClassSql := "insert into wyclass(name,create_time,center_id,start_time,code) values(?,?,?,?,?)"
		lessgo.Log.Debug(insertClassSql)

		stmt, err := tx.Prepare(insertClassSql)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		res, err := stmt.Exec(name, time.Now().Format("20060102150405"), _employee.CenterId, startTime, code)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		classId, err := res.LastInsertId()

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		insertScheduleSql := "insert into class_schedule_detail(class_id,center_id,time_id,room_id,day_date,week,start_time,end_time,status,capacity) values(?,?,?,?,?,?,?,?,?,?)"
		lessgo.Log.Debug(insertScheduleSql)

		stmt, err = tx.Prepare(insertScheduleSql)

		if err != nil {
			lessgo.Log.Error(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		_, err = stmt.Exec(classId, _employee.CenterId, timeId, roomId, date, week, startTime, endTime, 1, capacity)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
			commonlib.OutputJson(w, m, " ")
			return
		}

		tx.Commit()

		m["success"] = true
		commonlib.OutputJson(w, m, " ")
	}
}