def AddCreatorIntoActivity(CreatorID, TheActivityID): ''' 描述:将创建者加入活动 参数:创建者id,活动id 返回:成功{result:success},失败{result:fail,reason:xxx, code:xxx} ''' Success = True Return = {} Code = Constants.UNDEFINED_NUMBER Reason = "" TheSubmitTime = -1 TheJoinTime = -1 TheCheckTime = -1 if Success: try: TheUser = User.objects.get(OpenID=CreatorID) TheActivity = Activity.objects.get(ID=TheActivityID) except: Success = False Reason = "未找到创建者或活动" Code = Constants.ERROR_CODE_NOT_FOUND if Success: try: TheSubmitTime = GlobalFunctions.GetCurrentTime() TheJoinTime = GlobalFunctions.GetCurrentTime() TheCheckTime = GlobalFunctions.GetCurrentTime() TheJoinReason = "无" TheStatus = Constants.USER_STATUS_CHECKED TheRole = Constants.USER_ROLE_CREATOR try: TheJoinInformation = JoinInformation.objects.get( UserId=TheUser, ActivityId=TheActivity) TheJoinInformation.delete() except: donothing = 0 TheJoinInformation = JoinInformation.objects.create(UserId = TheUser, ActivityId = TheActivity, Status = TheStatus,\ Role = TheRole, SubmitTime = TheSubmitTime, JoinTime = TheJoinTime, CheckTime = TheCheckTime, JoinReason = TheJoinReason) TheJoinInformation.save() TheActivity.CurrentUser = TheActivity.CurrentUser + 1 TheActivity.save() except: Success = False Reason = "将创建者加入活动失败" Code = Constants.ERROR_CODE_UNKNOWN if Success: Return["result"] = "success" else: Return["result"] = "fail" Return["reason"] = Reason Return["code"] = Code return Return
def AddUserActivity(TheUserID, TheActivityID, TheStatus, TheRole, TheJoinReason): ''' 描述:将一条报名信息加入数据库 参数:用户id,活动id,状态,权限,报名原因(没有就是None) 返回:成功{result:success},失败{result:fail,reason:xxx, code:xxx} ''' Success = True Return = {} Code = Constants.UNDEFINED_NUMBER Reason = "" TheSubmitTime = -1 TheJoinTime = -1 TheCheckTime = -1 if Success: try: TheUser = User.objects.get(OpenID = TheUserID) TheActivity = Activity.objects.get(ID = TheActivityID) except: Success = False Reason = "未找到用户或活动" Code = Constants.ERROR_CODE_NOT_FOUND if Success: try: TheSubmitTime = GlobalFunctions.GetCurrentTime() TheCheckTime = Constants.UNDEFINED_NUMBER if TheStatus != Constants.USER_STATUS_WAITVALIDATE: TheJoinTime = TheSubmitTime TheActivity.CurrentUser = TheActivity.CurrentUser + 1 else: TheCheckTime = Constants.UNDEFINED_NUMBER TheActivity.save() #print(TheJoinTime, TheCheckTime) if TheJoinReason == None: TheJoinReason = "无" try: TheJoinInformation = JoinInformation.objects.get(UserId = TheUser, ActivityId = TheActivity) TheJoinInformation.delete() except: donothing = 0 TheJoinInformation = JoinInformation.objects.create(UserId = TheUser, ActivityId = TheActivity, Status = TheStatus,\ Role = TheRole, SubmitTime = TheSubmitTime, JoinTime = TheJoinTime, CheckTime = TheCheckTime, JoinReason = TheJoinReason) TheJoinInformation.save() except: Success = False Reason = "添加记录失败" Code = Constants.ERROR_CODE_UNKNOWN if Success: Return["result"] = "success" else: Return["result"] = "fail" Return["reason"] = Reason Return["code"] = Code return Return
def ReportActivity(TheUserID, TheActivityID, TheReportReason): ''' 描述:举报函数 参数:用户id,活动id, 举报原因 返回:成功{result: success},失败{result:fail,reason:xxx, code:xxx} ''' Success = True Reason = "" Return = {} Code = Constants.UNDEFINED_NUMBER TheStatus = -1 TheRole = -1 if Success: try: TheUser = User.objects.get(OpenID = TheUserID) TheActivity = Activity.objects.get(ID = TheActivityID) except: Success = False Reason = "未找到用户或活动" Code = Constants.ERROR_CODE_NOT_FOUND #print(Success) TheRole = Constants.USER_ROLE_COMMONER if Success: if JudgeValid.JudgeActivityNormal(TheActivityID) != True: Success = False Reason = "活动状态为异常或结束,不能操作!" Code = Constants.ERROR_CODE_INVALID_CHANGE if Success: try: TheSubmitTime = GlobalFunctions.GetCurrentTime() try: TheReportInformation = ReportInformation.objects.get(UserId = TheUser, ActivityId = TheActivity) TheReportInformation.delete() except: donothing = 0 TheReportInformation = ReportInformation.objects.create(UserId = TheUser, ActivityId = TheActivity, \ SubmitTime = TheSubmitTime, Reason = TheReportReason) TheReportInformation.save() except: Success = False Reason = "添加举报记录失败" Code = Constants.ERROR_CODE_UNKNOWN #print(Return) if Success: Return["result"] = "success" else: Return["result"] = "fail" Return["reason"] = Reason Return["code"] = Code return Return
def ChangeActivityStatusByTime(): ''' 描述:根据时间修改所有活动数据 参数: 无 返回:成功True, 失败False ''' Success = True if Success: try: Info = Activity.objects.all() except: Success = False if Success: try: for item in Info: if item.StatusGlobal != Constants.ACTIVITY_STATUS_GLOBAL_NORMAL: continue TheCurrentTime = GlobalFunctions.GetCurrentTime() TheJoinStartTime = item.SignUpStartTime TheJoinEndTime = item.SignUpEndTime TheCheckStartTime = item.StartTime TheCheckEndTime = item.EndTime TheCurrentUser = item.CurrentUser TheMinUser = item.MinUser if item.StatusJoin == Constants.ACTIVITY_STATUS_JOIN_BEFORE: if GlobalFunctions.JudgeWhetherSameMinute( TheJoinStartTime): item.StatusJoin = Constants.ACTIVITY_STATUS_JOIN_CONTINUE if item.StatusJoin != Constants.ACTIVITY_STATUS_JOIN_STOPPED: if GlobalFunctions.JudgeWhetherSameMinute(TheJoinEndTime): item.StatusJoin = Constants.ACTIVITY_STATUS_JOIN_STOPPED if item.StatusCheck == Constants.ACTIVITY_STATUS_CHECK_BEFORE: if GlobalFunctions.JudgeWhetherSameMinute( TheCheckStartTime ) and TheCurrentUser >= TheMinUser: item.StatusCheck = Constants.ACTIVITY_STATUS_CHECK_CONTINUE if item.StatusCheck != Constants.ACTIVITY_STATUS_CHECK_STOPPED: if GlobalFunctions.JudgeWhetherSameMinute(TheCheckEndTime): item.StatusCheck = Constants.ACTIVITY_STATUS_CHECK_STOPPED item.save() except: Success = False return Success
def CheckInActivity(TheUserID, TheActivityID, TheCode, TheDistance): ''' 描述:用户签到 参数:用户openid,活动id,二维码code, 距离 返回:成功{result:success} 失败:{result:fail,reason:xxx,code:xxx} ''' Return = {} Reason = "" Code = 0 Success = True ThePass = -1 ResultList = [] if Success: try: TheActivity = Activity.objects.get(ID = TheActivityID) TheUser = User.objects.get(OpenID = TheUserID) if TheCode != None: if TheCode != TheActivity.Code: Success = False Reason = "二维码和活动不匹配!" Code = Constants.ERROR_CODE_INVALID_CHANGE elif TheDistance != None: if TheDistance > Constants.SUCCESS_THRESHOLD: Success = False Reason = "距离太远,签到失败!" Code = Constants.ERROR_CODE_INVALID_CHANGE else: Success = False Reason = "请求参数不合法!" Code = Constants.ERROR_CODE_INVALID_PARAMETER except: Success = False Reason = "未找到用户或活动!" Code = Constants.ERROR_CODE_NOT_FOUND if Success: if JudgeValid.JudgeActivityNormal(TheActivityID) != True: Success = False Reason = "活动状态为异常或结束,不能操作!" Code = Constants.ERROR_CODE_INVALID_CHANGE if Success: try: TheJoinActivity = JoinInformation.objects.get(ActivityId = TheActivity, UserId = TheUser) TheStatus = TheJoinActivity.Status TheRole = TheJoinActivity.Role if JudgeValid.JudgeUserStatusDoingActivity(TheStatus) != True: Success = False Reason = "该用户不是活动正式成员" Code = Constants.ERROR_CODE_INVALID_CHANGE elif TheStatus == Constants.USER_STATUS_CHECKED: Success = False Reason = "该用户已经签到!" Code = Constants.ERROR_CODE_INVALID_CHANGE except: Success = False Reason = "用户未参加该活动!" Code = Constants.ERROR_CODE_NOT_FOUND #判断状态是否可行 if Success: if JudgeValid.JudgeActivityCanCheck(TheActivityID)!= True: Success = False Reason = "当前活动不在可以签到状态,可能签到未开始,已暂停或已经截止" Code = Constants.ERROR_CODE_INVALID_CHANGE if Success: try: TheCheckTime = GlobalFunctions.GetCurrentTime() TheJoinActivity.CheckTime = TheCheckTime TheJoinActivity.Status = Constants.USER_STATUS_CHECKED TheJoinActivity.save() except: Success = False Reason = "签到失败!" Code = Constants.ERROR_CODE_UNKNOWN if Success: Return["result"] = "success" else: Return["result"] = "fail" Return["reason"] = Reason Return["code"] = Code return Return
def AuditUser(TheManagerID, TheUserID, TheActivityID, WhetherPass): ''' 描述:审核用户 参数:管理员openid,用户openid,活动id,是否通过(0或1) 返回:成功{result:success} 失败:{result:fail,reason:xxx,code:xxx} ''' Return = {} Reason = "" Code = 0 Success = True ThePass = -1 ResultList = [] if Success: try: if JudgeValid.JudgeWhetherManager(TheManagerID, TheActivityID) != True: Success = False Reason = "权限不足,需要是管理员或创建者!" Code = Constants.ERROR_CODE_LACK_ACCESS TheActivity = Activity.objects.get(ID = TheActivityID) TheUser = User.objects.get(OpenID = TheUserID) except: Success = False Reason = "未找到用户或活动!" Code = Constants.ERROR_CODE_NOT_FOUND if Success: if JudgeValid.JudgeActivityNormal(TheActivityID) != True: Success = False Reason = "活动状态为异常或结束,不能操作!" Code = Constants.ERROR_CODE_INVALID_CHANGE if Success: try: TheJoinActivity = JoinInformation.objects.get(ActivityId = TheActivity, UserId = TheUser) TheStatus = TheJoinActivity.Status if TheStatus != Constants.USER_STATUS_WAITVALIDATE: Success = False Reason = "该用户不是待审核状态" Code = Constants.ERROR_CODE_INVALID_CHANGE except: Success = False Reason = "用户未参加该活动!" Code = Constants.ERROR_CODE_NOT_FOUND if Success: try: ThePass = int(WhetherPass) if ThePass != 0 and ThePass != 1: Success = False Reason = "参数不合法!" Code = Constants.ERROR_CODE_INVALID_PARAMETER except: Success = False Reason = "参数不合法!" Code = Constants.ERROR_CODE_INVALID_PARAMETER if Success: try: if ThePass == 0: TheJoinActivity.Status = Constants.USER_STATUS_REFUSED TheJoinActivity.save() else: if TheActivity.MaxUser != Constants.UNDEFINED_NUMBER and TheActivity.CurrentUser >= TheActivity.MaxUser: Success = False Reason = "当前人数已满,不能审核通过!" Code = Constants.ERROR_CODE_INVALID_CHANGE else: CurrentTime = GlobalFunctions.GetCurrentTime() TheJoinActivity.Status = Constants.USER_STATUS_JOINED TheJoinActivity.JoinTime = CurrentTime TheJoinActivity.JoinReason = "无" TheActivity.CurrentUser = TheActivity.CurrentUser + 1 TheActivity.save() TheJoinActivity.save() except: Success = False Reason = "审核失败!" Code = Constants.ERROR_CODE_UNKNOWN if Success: Return["result"] = "success" else: Return["result"] = "fail" Return["reason"] = Reason Return["code"] = Code return Return
def ChangeActivity(TheUserID, Information): ''' 描述:修改活动信息 参数:用户openid,待修改信息 返回:{result:success}/{result:fail,reason:xxx, code:xxx} ''' Success = True Return = {} Reason = "" Code = Constants.UNDEFINED_NUMBER ChangeDictionary = {} #判断是否能找到这个活动 if Success: try: TheUser = User.objects.get(OpenID=TheUserID) TheActivity = Activity.objects.get(ID=Information["id"]) if JudgeValid.JudgeWhetherManager(TheUserID, Information["id"]) != True: Success = False Reason = "没有修改权限,需要是管理员或者创建者!" Code = Constants.ERROR_CODE_LACK_ACCESS except: Success = False Reason = "没有修改权限" Code = Constants.ERROR_CODE_LACK_ACCESS if Success: if JudgeValid.JudgeActivityNormal(Information["id"]) != True: Success = False Reason = "活动状态为异常或结束,不能操作!" Code = Constants.ERROR_CODE_INVALID_CHANGE #读取修改数据 WhetherJudgeTime = False if Success: try: if "name" in Information: ChangeDictionary["name"] = Information["name"] else: ChangeDictionary["name"] = TheActivity.Name if "place" in Information: ChangeDictionary["place"] = Information["place"] else: ChangeDictionary["place"] = TheActivity.Place if "start" in Information: WhetherJudgeTime = True ChangeDictionary["start"] = int( GlobalFunctions.TimeStringToTimeStamp( Information["start"])) else: ChangeDictionary["start"] = TheActivity.StartTime if "end" in Information: WhetherJudgeTime = True ChangeDictionary["end"] = int( GlobalFunctions.TimeStringToTimeStamp(Information["end"])) else: ChangeDictionary["end"] = TheActivity.EndTime if "signupBeginAt" in Information: WhetherJudgeTime = True ChangeDictionary["signupBeginAt"] = int( GlobalFunctions.TimeStringToTimeStamp( Information["signupBeginAt"])) else: ChangeDictionary["signupBeginAt"] = TheActivity.SignUpStartTime if "signupStopAt" in Information: WhetherJudgeTime = True ChangeDictionary["signupStopAt"] = int( GlobalFunctions.TimeStringToTimeStamp( Information["signupStopAt"])) else: ChangeDictionary["signupStopAt"] = TheActivity.SignUpEndTime if "minUser" in Information: ChangeDictionary["minUser"] = int(Information["minUser"]) else: ChangeDictionary["minUser"] = TheActivity.MinUser if "maxUser" in Information: ChangeDictionary["maxUser"] = int(Information["maxUser"]) else: ChangeDictionary["maxUser"] = TheActivity.MaxUser if "type" in Information: ChangeDictionary["type"] = Information["type"] else: ChangeDictionary["type"] = TheActivity.Type if "statusGlobal" in Information: ChangeDictionary["statusGlobal"] = Information["statusGlobal"] else: ChangeDictionary["statusGlobal"] = TheActivity.StatusGlobal if "statusJoin" in Information: ChangeDictionary["statusJoin"] = Information["statusJoin"] else: ChangeDictionary["statusJoin"] = TheActivity.StatusJoin if "statusCheck" in Information: ChangeDictionary["statusCheck"] = Information["statusCheck"] else: ChangeDictionary["statusCheck"] = TheActivity.StatusCheck if "canBeSearched" in Information: ChangeDictionary["canBeSearched"] = bool( Information["canBeSearched"]) else: ChangeDictionary["canBeSearched"] = TheActivity.CanBeSearched if "imageUrl" in Information: ChangeDictionary["imageUrl"] = Information["imageUrl"] else: ChangeDictionary["imageUrl"] = TheActivity.ImageURL if "position" in Information: ChangeDictionary["position"] = Information["position"] else: ChangeDictionary["position"] = TheActivity.GPSPlace if "tags" in Information: if JudgeValid.JudgeTagListValid(Information["tags"]) != True: Success = False Reason = "参数不合法,标签不能带有英文逗号!" Code = Constants.ERROR_CODE_INVALID_PARAMETER ChangeDictionary["tags"] = GlobalFunctions.MergeTags( Information["tags"]) else: ChangeDictionary["tags"] = TheActivity.Tags #如果rules不存在就changedictionary为空,要判断 if "rules" in Information: if "ruleType" in Information["rules"]: ChangeDictionary["ruleType"] = Information["rules"][ "ruleType"] else: ChangeDictionary["ruleType"] = TheActivity.GlobalRule ChangeDictionary["rules"] = Information["rules"] else: ChangeDictionary["rules"] = [] ChangeDictionary["ruleType"] = TheActivity.GlobalRule ChangeDictionary["curTime"] = GlobalFunctions.GetCurrentTime() ChangeDictionary["curUser"] = TheActivity.CurrentUser except: Success = False Reason = "待修改数据格式不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER #print(Success) #判断活动type修改后是否有效 if Success: try: JudgeResult = JudgeValid.JudgeTypeChangeValid( TheActivity.Type, ChangeDictionary["type"], TheActivity.StatusGlobal) if JudgeResult["result"] != "success": Success = False Reason = JudgeResult["reason"] Code = JudgeResult["code"] except: Success = False Reason = "待修改数据格式不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER #判断时间,人数等修改后是否有效 if Success and WhetherJudgeTime: try: JudgeResult = JudgeValid.JudgeParameterValid(ChangeDictionary["curTime"], ChangeDictionary["start"], ChangeDictionary["end"], \ ChangeDictionary["signupBeginAt"], ChangeDictionary["signupStopAt"], ChangeDictionary["curUser"], ChangeDictionary["minUser"], \ ChangeDictionary["maxUser"]) if JudgeResult["result"] != "success": Success = False Reason = JudgeResult["reason"] Code = Constants.ERROR_CODE_INVALID_CHANGE except: Success = False Reason = "待修改数据格式不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER if Success and ChangeDictionary["maxUser"] != Constants.UNDEFINED_NUMBER: try: if ChangeDictionary["minUser"] > ChangeDictionary["maxUser"]: Success = False Reason = "最小人数不能大于最大人数!" Code = Constants.ERROR_CODE_INVALID_CHANGE if ChangeDictionary["curUser"] > ChangeDictionary["maxUser"]: Success = False Reason = "当前人数不能大于最大人数!" Code = Constants.ERROR_CODE_INVALID_CHANGE except: Success = False Reason = "待修改数据格式不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER #判断状态等改后是否有效 if Success: try: JudgeResult = JudgeValid.JudgeActivityStatusChangeValid( TheActivity.StatusGlobal, ChangeDictionary["statusGlobal"]) if JudgeResult["result"] != "success": Success = False Reason = JudgeResult["reason"] Code = Constants.ERROR_CODE_INVALID_CHANGE if JudgeValid.JudgeActivityStatusJoinValid( ChangeDictionary["statusJoin"]) != True: Success = False Reason = "待修改的活动加入状态不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER if JudgeValid.JudgeActivityStatusCheckValid( ChangeDictionary["statusCheck"]) != True: Success = False Reason = "待修改的活动签到状态不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER if JudgeValid.JudgeRuleTypeValid( ChangeDictionary["ruleType"]) != True: Success = False Reason = "待修改的活动规则类型不合法!" Code = Constants.ERROR_CODE_INVALID_PARAMETER except: Success = False Reason = "待修改数据格式不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER #判断高级规则等改后是否有效 if Success: try: if ChangeDictionary["rules"] != []: JudgeResult = JudgeValid.JudgeAdvancedRuleValid( ChangeDictionary["rules"]) if JudgeResult["result"] != "success": Success = False Reason = JudgeResult["reason"] Code = Constants.ERROR_CODE_INVALID_CHANGE except: Success = False Reason = "待修改数据格式不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER #修改 #print(Success) if Success: try: TheActivity.Name = ChangeDictionary["name"] TheActivity.Place = ChangeDictionary["place"] TheActivity.StartTime = ChangeDictionary["start"] TheActivity.EndTime = ChangeDictionary["end"] TheActivity.SignUpStartTime = ChangeDictionary["signupBeginAt"] TheActivity.SignUpEndTime = ChangeDictionary["signupStopAt"] TheActivity.MinUser = ChangeDictionary["minUser"] TheActivity.MaxUser = ChangeDictionary["maxUser"] TheActivity.Type = ChangeDictionary["type"] TheActivity.StatusGlobal = ChangeDictionary["statusGlobal"] TheActivity.StatusJoin = ChangeDictionary["statusJoin"] TheActivity.StatusCheck = ChangeDictionary["statusCheck"] TheActivity.CanBeSearched = ChangeDictionary["canBeSearched"] TheActivity.GlobalRule = ChangeDictionary["ruleType"] TheActivity.Tags = ChangeDictionary["tags"] TheActivity.ImageURL = ChangeDictionary["imageUrl"] TheActivity.GPSPlace = ChangeDictionary["position"] TheActivity.save() TheSearcher = SearchAndRecommend.WhooshSearcher.Create() TheSearcher.UpdateOneInfo( Information["id"], TheActivity.Name + ',' + TheActivity.Tags) except: Success = False Reason = "修改数据失败" Code = Constants.ERROR_CODE_UNKNOWN if Success: try: #print(ChangeDictionary["rules"], Information["id"]) if ChangeDictionary["rules"] != []: #修改高级报名规则 if ChangeAdvancedRules(Information["id"], ChangeDictionary["rules"]) != True: Success = False Reason = "修改数据失败" Code = Constants.ERROR_CODE_UNKNOWN except: Success = False Reason = "修改数据失败" Code = Constants.ERROR_CODE_UNKNOWN if Success == False: Return["result"] = "fail" Return["reason"] = Reason Return["code"] = Code else: Return["result"] = "success" return Return
def AddActivity(ID, Information): ''' 描述:添加一个活动到数据库 参数:创建者ID,数据信息 返回:{result:success,activityId:xxx}/失败{result:fail,reason:xxx, code:xxx} ''' Return = {} Success = True Code = Constants.UNDEFINED_NUMBER Reason = "" CurTime = 0 StartTime = 0 EndTime = 0 StartSignTime = 0 StopSignTime = 0 TheMinUser = 0 TheMaxUser = 0 TheStatus = 0 TheSearched = False TheGlobalRule = -1 TheAcceptRule = [] TheAuditRule = [] TheRejectRule = [] TheType = "" #把时间转化为时间戳,并且判断时间和人数是否合法 if Success: try: CurTime = GlobalFunctions.GetCurrentTime() StartTime = GlobalFunctions.TimeStringToTimeStamp( Information["start"]) EndTime = GlobalFunctions.TimeStringToTimeStamp(Information["end"]) if 'signupBeginAt' in Information: StartSignTime = GlobalFunctions.TimeStringToTimeStamp( Information["signupBeginAt"]) else: StartSignTime = CurTime if 'signupStopAt' in Information: StopSignTime = GlobalFunctions.TimeStringToTimeStamp( Information["signupStopAt"]) else: StopSignTime = StartTime if 'minUser' in Information: TheMinUser = int(Information["minUser"]) else: TheMinUser = 0 if 'maxUser' in Information: TheMaxUser = int(Information["maxUser"]) else: TheMaxUser = Constants.UNDEFINED_NUMBER JudgeResult = JudgeValid.JudgeParameterValid( CurTime, StartTime, EndTime, StartSignTime, StopSignTime, 1, TheMinUser, TheMaxUser) if "imageUrl" in Information: TheImageURL = Information["imageUrl"] else: TheImageURL = "UNDEFINED" if "position" in Information: ThePosition = Information["position"] else: ThePosition = "" if JudgeResult["result"] != "success": Success = False Reason = JudgeResult["reason"] Code = Constants.ERROR_CODE_INVALID_CHANGE except: Success = False Reason = "输入的开始/结束/开始报名/报名截止时间不合理!" Code = Constants.ERROR_CODE_INVALID_PARAMETER #判断活动状态,类型等是否合法 if Success: try: TheType = Information["type"] TheSearched = bool(Information["canBeSearched"]) if JudgeValid.JudgeActivityTypeValid(TheType) == False: Success = False Reason = "活动类型不合法,添加活动失败!" Code = Constants.ERROR_CODE_INVALID_PARAMETER TheStatusGlobal = GlobalFunctions.GetStartActivityGlobalStatus( TheType) TheStatusJoin = GlobalFunctions.GetStartActivityJoinStatus( StartSignTime, StopSignTime) TheStatusCheck = GlobalFunctions.GetStartActivityCheckStatus( StartTime, EndTime) except: Success = False Reason = "参数不合法,添加活动失败!" Code = Constants.ERROR_CODE_INVALID_PARAMETER #获得标签,正文,头像 if Success: try: TheTagsList = Information["tags"] TheDescription = Information["description"] if JudgeValid.JudgeTagListValid(TheTagsList) != True: Success = False Reason = "参数不合法,标签不能带有英文逗号!" Code = Constants.ERROR_CODE_INVALID_PARAMETER TheTags = GlobalFunctions.MergeTags(TheTagsList) except: Success = False Reason = "参数不合法,添加活动失败!" Code = Constants.ERROR_CODE_INVALID_PARAMETER #获得高级报名信息 if Success: try: #判断是否合法 TheGlobalRule = Information["rules"]["ruleType"] if JudgeValid.JudgeRuleTypeValid(TheGlobalRule) != True: Success = False Reason = "参数不合法,规则类型不合法!" Code = Constants.ERROR_CODE_INVALID_PARAMETER TheJudgeAdvanceRuleResult = JudgeValid.JudgeAdvancedRuleValid( Information["rules"]) #print(TheJudgeAdvanceRuleResult) if TheJudgeAdvanceRuleResult["result"] != "success": Success = False Reason = TheJudgeAdvanceRuleResult["reason"] Code = TheJudgeAdvanceRuleResult["code"] try: TheAcceptRule = Information["rules"]["accept"] except: TheAcceptRule = [] try: TheAuditRule = Information["rules"]["needAudit"] except: TheAuditRule = [] try: TheRejectRule = Information["rules"]["reject"] except: TheRejectRule = [] except: Success = False Reason = "参数不合法,添加活动失败!" Code = Constants.ERROR_CODE_INVALID_PARAMETER #print(CurTime, StartTime, EndTime, StartSignTime, StopSignTime) #print(Success) #插入数据库 if Success: try: TheName = Information["name"] ThePlace = Information["place"] #TheCreator = User.objects.get(OpenID = ID) #print(TheCreator.ID) TheCreateTime = GlobalFunctions.GetCurrentTime() NewActivity = Activity.objects.create(Name = TheName, Place = ThePlace, CreateTime = TheCreateTime, StartTime = StartTime, EndTime = EndTime, SignUpStartTime = StartSignTime,\ SignUpEndTime = StopSignTime, MinUser = TheMinUser, MaxUser = TheMaxUser, CurrentUser = 0, Type = TheType, \ StatusGlobal = TheStatusGlobal, StatusJoin = TheStatusJoin, StatusCheck = TheStatusCheck, CanBeSearched = TheSearched, \ GlobalRule = TheGlobalRule, Tags = TheTags, Description = TheDescription, ImageURL = TheImageURL, GPSPlace = ThePosition) NewActivity.save() ActivityID = NewActivity.ID TheSearcher = SearchAndRecommend.WhooshSearcher.Create() TheSearcher.AddOneInfo(ActivityID, TheName + ',' + TheTags) except: Success = False Reason = "参数不合法,添加活动失败!" Code = Constants.ERROR_CODE_INVALID_PARAMETER if Success: if "rules" in Information: try: #添加rules for item in TheAcceptRule: AddAdvancedRules(ActivityID, item, Constants.ADVANCED_RULE_ACCEPT) for item in TheAuditRule: AddAdvancedRules(ActivityID, item, Constants.ADVANCED_RULE_AUDIT) for item in TheRejectRule: AddAdvancedRules(ActivityID, item, Constants.ADVANCED_RULE_REJECT) except: Success = False Reason = "参数不合法,添加活动失败!" Code = Constants.ERROR_CODE_INVALID_PARAMETER #print(Success) #让creator加入活动 if Success: try: #print(int(Return["id"])) JoinActivityResult = AddCreatorIntoActivity(ID, ActivityID) if JoinActivityResult["result"] != "success": Success = False Reason = JoinActivityResult["reason"] Code = JoinActivityResult["code"] else: Return["activityId"] = ActivityID except: Success = False Reason = "添加活动失败" Code = Constants.ERROR_CODE_UNKNOWN if Success: if TheStatusGlobal == Constants.ACTIVITY_STATUS_GLOBAL_NORMAL: Return["result"] = "success" else: Return["result"] = "needAudit" else: Return["result"] = "fail" Return["reason"] = Reason Return["code"] = Code return Return