def delete_course(self): """ 删除课程排班 """ if not is_doctor(): return AuthorityError("无权限") with db.auto_commit(): for course in request.json: course_id = course["coid"] co_dict = {"isdelete": 1} co_instance = Course.query.filter( Course.COid == course_id).first_('未找到该课程排班信息') if co_instance["COstatus"] != 101: return AuthorityError("无权限") subscribe = Subscribe.query.filter( Subscribe.COid == course_id).all() if subscribe: return AuthorityError("已有人报名,不可修改") co_instance.update(co_dict, null='not') db.session.add(co_instance) cancel_async_task(conn_id='start_course{}'.format( co_instance.COid)) # 取消已有的开始时间异步任务 cancel_async_task(conn_id='end_course{}'.format( co_instance.COid)) # 取消已有的结束时间异步任务 return Success(message='删除成功')
def set_evaluationanswer(self): """设置题目选项""" data = parameter_required(( 'eiid', 'eaname', 'eaindex', 'eapoint') if not request.json.get('delete') else ('eaid', )) if not is_admin(): return AuthorityError() ea_dict = { "EIid": data.get('eiid'), "EAname": data.get('eaname'), "EAindex": data.get('eaindex'), "EApoint": Decimal(str(data.get('eapoint') or 0)) } eaid = data.get("eaid") with db.auto_commit(): if not eaid: # 新增 ea_dict["EAid"] = str(uuid.uuid1()) ea_instance = EvaluationAnswer.create(ea_dict) msg = "新增成功" else: ea_instance = EvaluationAnswer.query.filter( EvaluationAnswer.EAid == eaid).first_("未找到该选项") if data.get("delete"): ea_instance.update({"isdelete": 1}) msg = "删除成功" else: ea_instance.update(ea_dict) msg = "修改成功" db.session.add(ea_instance) return Success(message=msg)
def userlist(self): """获取用户优惠券(前台)""" args = parameter_required(('ucalreadyuse', )) # 601已使用602未使用603已过期604可使用 if not is_user(): return AuthorityError() usid = request.user.id ucalreadyuse = int(args.get('ucalreadyuse')) if ucalreadyuse in [601, 602, 603]: coupon_list = CouponUser.query.filter(CouponUser.isdelete == 0, CouponUser.USid == usid, CouponUser.UCalreadyuse == ucalreadyuse)\ .order_by(CouponUser.createtime.desc()).all_with_page() elif ucalreadyuse in [604]: coupon_list = CouponUser.query.filter(CouponUser.isdelete == 0, CouponUser.USid == usid, CouponUser.UCalreadyuse == 602, CouponUser.COstarttime < datetime.datetime.now(), CouponUser.COendtime > datetime.datetime.now())\ .order_by(CouponUser.createtime.desc()).all_with_page() else: coupon_list = [] for coupon in coupon_list: coupon.fill("ucalreadyuse_zh", CouponUserStatus(coupon.UCalreadyuse).zh_value) if coupon.COdownline == 0: coupon.fill("codownline_zh", "无限制") else: coupon.fill("codownline_zh", "满足{0}元即可使用".format(Decimal(str(coupon.COdownline)))) coupon.fill("cotime", "{0}月{1}日-{2}月{3}日".format(coupon.COstarttime.month, coupon.COstarttime.day, coupon.COendtime.month, coupon.COendtime.day)) return Success(message="获取优惠券成功", data=coupon_list)
def set_evaluationitem(self): """设置问卷题目""" data = parameter_required(( 'evid', 'einame', 'eiindex', ) if not request.json.get('delete') else ('eiid', )) if not (is_hign_level_admin() or is_admin()): return AuthorityError() ei_dict = { "EVid": data.get('evid'), "EIname": data.get('einame'), "EIindex": data.get('eiindex') } eiid = data.get("eiid") with db.auto_commit(): if not eiid: # 新增 ei_dict["EIid"] = str(uuid.uuid1()) ei_instance = EvaluationItem.create(ei_dict) msg = "新增成功" else: ei_instance = EvaluationItem.query.filter( EvaluationItem.EIid == eiid).first_("未找到该题目") if data.get("delete"): ei_instance.update({"isdelete": 1}) msg = "删除成功" else: ei_instance.update(ei_dict) msg = "修改成功" db.session.add(ei_instance) return Success(message=msg)
def delete_admin(self): """冻结管理员""" data = parameter_required(('adid', 'adtype')) token = token_to_user_(request.args.get("token")) # 权限判断 ad = Admin.query.filter(Admin.isdelete == 0, Admin.ADid == token.id).first() adid = ad.ADid if adid != "1": raise AuthorityError("无权限") else: with db.auto_commit(): ad_dict = { "isdelete": 1 } if data['adtype'] == 1: ad_instance = Admin.query.filter(Admin.ADid == data.get("adid"), Admin.isdelete == 0)\ .first_('未找到该账号信息') ad_instance.update(ad_dict, null='not') elif data['adtype'] == 2: ad_instance = Doctor.query.filter(Doctor.DOid == data.get('adid'), Doctor.isdelete == 0)\ .first_('未找到该账号信息') ad_instance.update(ad_dict, null='not') db.session.add(ad_instance) msg = "删除账号成功" return Success(message=msg)
def reset_password(self): """重置管理员密码""" data = parameter_required(('adid', 'adtype')) token = token_to_user_(request.args.get('token')) # 判断权限 ad = Admin.query.filter(Admin.isdelete == 0, Admin.ADid == token.id).first() adid = ad.ADid if adid != "1": raise AuthorityError("无权限") else: with db.auto_commit(): if data['adtype'] == 1: ad_dict = { 'ADpassword': generate_password_hash('123456') } ad_instance = Admin.query.filter(Admin.ADid == data.get("adid"), Admin.isdelete == 0)\ .first_('未找到该账号信息') ad_instance.update(ad_dict, null='not') elif data['adtype'] == 2: ad_instance = Doctor.query.filter(Doctor.DOid == data.get('adid'), Doctor.isdelete == 0)\ .first_('未找到该账号信息') ad_dict = { 'DOpassword': generate_password_hash(str(ad_instance.DOtel)[-6:]) } ad_instance.update(ad_dict, null='not') db.session.add(ad_instance) msg = "重置密码成功" return Success(message=msg)
def set_evaluation(self): """设置问卷主体""" data = parameter_required(( 'evname', 'evpicture', ) if not request.json.get('delete') else ('evid', )) if not is_admin(): return AuthorityError() ev_dict = { "EVname": data.get('evname'), "EVpicture": data.get('evpicture') } evid = data.get("evid") with db.auto_commit(): if not evid: # 新增 ev_dict["EVid"] = str(uuid.uuid1()) ev_instance = Evaluation.create(ev_dict) msg = "新增成功" else: ev_instance = Evaluation.query.filter( Evaluation.EVid == evid).first_("未找到该问卷") if data.get("delete"): ev_instance.update({"isdelete": 1}) msg = "删除成功" else: ev_instance.update(ev_dict) msg = "修改成功" db.session.add(ev_instance) return Success(message=msg)
def get_review(self): """获取评论""" """案例404id/医生id/活动id403/视频id405/评价人名称==>rvtype+rvtypeid/usname/doid""" """当前使用场景用于pc后台和前台业务页面,不涉及用户个人""" args = parameter_required() if is_admin() or is_user(): filter_args = [Review.isdelete == 0] if args.get('rvtype') and args.get('rvtypeid') and args.get('rvtypeid') != 'undefined': filter_args.append(Review.RVtypeid == args.get('rvtypeid')) if args.get('doid'): filter_args.append(Review.DOid == args.get('doid')) if args.get('usname'): filter_args.append(Review.USname.like("%{0}%".format(args.get('usname')))) review_list = Review.query.filter(*filter_args).order_by(Review.createtime.desc()).all_with_page() for review in review_list: if review["DOid"]: doctor = Doctor.query.filter(Doctor.DOid == review["DOid"], Doctor.isdelete == 0).first_("未找到医生信息") review.fill("doname", doctor["DOname"]) rp = ReviewPicture.query.filter(ReviewPicture.RVid == review["RVid"], ReviewPicture.isdelete == 0).all() review.fill("createtime", review["createtime"]) review.fill("rp_list", rp) rvtype = review["RVtype"] review.fill("rvtype_zn", ReviewStatus(rvtype).zh_value) return Success(message="获取评论成功", data=review_list) else: return AuthorityError()
def get(self): """获取优惠券详情(后台)""" args = parameter_required(('token', 'coid', )) if not is_admin(): return AuthorityError('无权限') coupon = Coupon.query.filter(Coupon.isdelete == 0, Coupon.COid == args.get('coid')).first_("未找到该优惠券") coupon.fill("costatus_zh", CouponStatus(coupon.COstatus).zh_value) return Success(message="获取优惠券信息成功", data=coupon)
def get_admin_list(self): """管理员列表""" token = token_to_user_(request.args.get('token')) # 判断权限 ad = Admin.query.filter(Admin.isdelete == 0, Admin.ADid == token.id).first() adid = ad.ADid if adid != "1": raise AuthorityError("无权限") else: ad_list = Admin.query.filter(Admin.isdelete == 0, Admin.ADlevel == 2)\ .order_by(Admin.createtime.desc()).all() admin_list = [] for admin in ad_list: admin_dict = {} admin_dict['adid'] = admin.ADid admin_dict['adname'] = admin.ADname admin_dict['adtype'] = 1 admin_dict['adtype_zh'] = '管理员' action = AdminActions.query.filter(AdminActions.ADid == admin.ADid, AdminActions.AAaction == 4, AdminActions.AAmodel == 'Admin')\ .order_by(AdminActions.createtime.desc()).first() if action: admin_dict['adlogin_last'] = action['createtime'] else: admin_dict['adlogin_last'] = None admin_list.append(admin_dict) dc_list = Doctor.query.filter(Doctor.isdelete == 0).order_by(Doctor.createtime.desc()).all() for doctor in dc_list: admin_dict = {} admin_dict['adid'] = doctor.DOid admin_dict['adname'] = doctor.DOtel admin_dict['adtype'] = 2 admin_dict['adtype_zh'] = '医生' action = AdminActions.query.filter(AdminActions.ADid == doctor.DOid, AdminActions.AAaction == 4, AdminActions.AAmodel == 'Doctor') \ .order_by(AdminActions.createtime.desc()).first() if action: admin_dict['adlogin_last'] = action['createtime'] else: admin_dict['adlogin_last'] = None admin_list.append(admin_dict) start_num = int(int(request.args.get('page_num')) - 1) * int(request.args.get('page_size') or 10) end_num = int(request.args.get('page_num')) * int(request.args.get('page_size') or 10) if len(admin_list) % int(request.args.get('page_size') or 10) == 0: total_page = int(len(admin_list) / int(request.args.get('page_size') or 10)) else: total_page = int(len(admin_list) / int(request.args.get('page_size') or 10)) + 1 return { "status": 200, "message": "获取管理员列表成功", "data": admin_list[start_num: end_num], "total_page": total_page, "total_size": len(admin_list) }
def delete(self): """删除评论""" if not is_admin(): return AuthorityError() data = request.json with db.auto_commit(): for rvid in data: rvid = rvid["rvid"] review_instance = Review.query.filter(Review.RVid == rvid).first_("未找到该评论") review_instance.update({"isdelete": 1}) db.session.add(review_instance) return Success('删除成功')
def get_pointtask(self): """获取任务列表""" args = parameter_required(('token', )) # user = token_to_user_(args.get('token')) usid = getattr(request, 'user').id if is_doctor(): return AuthorityError() else: pointtask_list = PointTask.query.filter(PointTask.isdelete == 0).order_by(PointTask.PTid.asc()).all() if is_user(): # 前台需要增加是否可完成的状态 for pointtask in pointtask_list: userintegral = UserIntegral.query.filter(UserIntegral.isdelete == 0, UserIntegral.UItrue == 0, UserIntegral.UItype == 1, UserIntegral.USid == usid, UserIntegral.UIaction == pointtask.PTtype).all() if userintegral: pointtask.fill("is_get", 1) else: pointtask.fill("is_get", 0) time_now = datetime.datetime.now() pttime = pointtask.PTtime or 0 if pttime > 0: userintegral_end = UserIntegral.query.filter(UserIntegral.isdelete == 0, UserIntegral.UItrue == 1, UserIntegral.UItype == 1, UserIntegral.USid == usid, UserIntegral.UIaction == pointtask.PTtype, UserIntegral.createtime > datetime.datetime(time_now.year, time_now.month, time_now.day, 0, 0, 0), UserIntegral.createtime < datetime.datetime(time_now.year, time_now.month, time_now.day, 23, 59, 59) ).all() if pttime <= len(userintegral_end): pointtask.is_get = 2 elif pttime < 0: pttime = abs(pttime) userintegral_end = UserIntegral.query.filter(UserIntegral.isdelete == 0, UserIntegral.UItrue == 1, UserIntegral.UItype == 1, UserIntegral.USid == usid, UserIntegral.UIaction == pointtask.PTtype ).all() if pttime <= len(userintegral_end): pointtask.is_get = 2 else: pass return Success(message="获取任务列表成功", data=pointtask_list)
def update_sustatus(self): """ 批量确认已上课 """ with db.auto_commit(): for subcribe in request.json: subcribe_id = subcribe["suid"] su_dict = {"SUstatus": 202} su_instance = Subscribe.query.filter( Subscribe.SUid == subcribe_id).first_('未找到该课程预约信息') if su_instance["DOid"] != getattr(request, 'user').id: return AuthorityError("无权限") su_instance.update(su_dict, null='not') db.session.add(su_instance) return Success(message='确认成功')
def list_series(self): data = parameter_required() filter_args = [Series.isdelete == 0] if getattr(request, 'user').model == "Admin": pass elif getattr(request, 'user').model == "Doctor": doid = getattr(request, 'user').id filter_args.append(Series.DOid == doid) else: return AuthorityError() sename = data.get('sename') if sename: filter_args.append(Series.SEname.ilike('%{}%'.format(sename))) series_list = Series.query.filter(*filter_args).order_by( Series.SEsort.asc(), Series.createtime.desc()).all_with_page() return Success('获取成功', data=series_list)
def set_setmeal(self): """ 新增/修改/删除课时套餐 """ if not (is_admin() or is_hign_level_admin()): return AuthorityError('无权限') data = parameter_required(( 'clid', 'smnum', 'smprice') if not request.json.get('delete') else ('smid', )) smid = data.get('smid') if smid: setmeal = Setmeal.query.filter( Setmeal.SMid == smid).first_("未找到该套餐信息") classes = Classes.query.filter( Classes.isdelete == 0, Classes.CLid == setmeal.CLid).first_("未找到该课程信息") else: classes = Classes.query.filter( Classes.isdelete == 0, Classes.CLid == data.get('clid')).first_("未找到该课程信息") clname = classes["CLname"] sm_dict = { "CLid": data.get('clid'), "CLname": clname, "SMnum": data.get('smnum'), "SMprice": data.get('smprice') } with db.auto_commit(): if not smid: """新增""" sm_dict['SMid'] = str(uuid.uuid1()) sm_instance = Setmeal.create(sm_dict) msg = '添加成功' else: """修改/删除""" sm_instance = Setmeal.query.filter_by_( SMid=smid).first_('未找到该轮播图信息') if data.get('delete'): sm_instance.update({'isdelete': 1}) msg = '删除成功' else: sm_instance.update(sm_dict, null='not') msg = '编辑成功' db.session.add(sm_instance) return Success(message=msg, data={'smid': sm_instance.SMid})
def set_class(self): """ 创建/编辑/删除课程 """ if not (is_admin() or is_hign_level_admin()): return AuthorityError('无权限') data = parameter_required(( 'clname', "clpicture", "deid", "clintroduction", "clprice") if not request.json.get('delete') else ('clid', )) clid = data.get('clid') if clid: classes = Classes.query.filter( Classes.CLid == clid).first_("未找到课程信息") department = Departments.query.filter( Departments.DEid == classes.DEid).first_("未找到科室信息") else: department = Departments.query.filter( Departments.DEid == data.get("deid")).first_("未找到科室信息") cl_dict = { 'CLname': data.get('clname'), 'CLpicture': data.get('clpicture'), 'DEid': data.get('deid'), 'DEname': department['DEname'], 'CLintroduction': data.get('clintroduction'), 'CLprice': data.get('clprice') } with db.auto_commit(): if not clid: """新增""" cl_dict['CLid'] = str(uuid.uuid1()) cl_instance = Classes.create(cl_dict) msg = '添加成功' else: """修改/删除""" cl_instance = Classes.query.filter_by_( CLid=clid).first_('未找到该轮播图信息') if data.get('delete'): cl_instance.update({'isdelete': 1}) msg = '删除成功' else: cl_instance.update(cl_dict, null='not') msg = '编辑成功' db.session.add(cl_instance) return Success(message=msg, data={'clid': cl_instance.CLid})
def list(self): data = parameter_required() syid = data.get('syid') index = data.get('index', 'list') examples_sql = Example.query.join(Symptom, Symptom.SYid == Example.SYid).filter( Example.isdelete == 0, Symptom.isdelete == 0) if syid: examples_sql = examples_sql.filter(Example.SYid == syid) else: if not is_admin(): raise AuthorityError() examples = examples_sql.order_by( Example.EXsort.asc(), Example.createtime.desc()).all_with_page() for exm in examples: self._fill_example(exm, index) return Success('获取成功', data=examples)
def update_pointtask(self): """更新任务积分以及次数""" # 后台更新次数以及积分数,负表示仅限次数,0表示无限次,正表示每日可完成次数 if not (is_admin() or is_hign_level_admin()): return AuthorityError() data = parameter_required(('ptid', 'ptnumber', 'pttime', 'pticon')) if not data.get('ptnumber'): data['ptnumber'] = 0 if not data.get('pttime'): data['pttime'] = 0 pt_dict = { "PTnumber": data.get('ptnumber'), "PTtime": data.get('pttime'), "PTicon": data.get('pticon') } pt_instance = PointTask.query.filter(PointTask.PTid == data.get('ptid')).first_("未找到该任务") with db.auto_commit(): pt_instance.update(pt_dict, null='not') db.session.add(pt_instance) return Success(message="更新任务成功")
def update_admin_password(self): """更新管理员密码""" data = parameter_required(('password_old', 'password_new', 'password_repeat')) # 校检两次密码是否相同 pwd_new = data.get('password_new') pwd_old = data.get('password_old') pwd_repeat = data.get('password_repeat') if pwd_new != pwd_repeat: raise ParamsError('两次输入的密码不同') token = token_to_user_(request.args.get("token")) if int(request.args.get('adtype')) == 1: ad = Admin.query.filter(Admin.isdelete == 0, Admin.ADid == token.id).first() adpassword = ad.ADpassword ad_dict = { "ADpassword": generate_password_hash(pwd_new) } elif int(request.args.get('adtype')) == 2: ad = Doctor.query.filter(Doctor.isdelete == 0, Doctor.DOid == token.id).first() print(ad) adpassword = ad.DOpassword ad_dict = { "DOpassword": generate_password_hash(pwd_new) } else: ad = None adpassword = None ad_dict = {} if ad: with db.auto_commit(): if check_password_hash(adpassword, pwd_old): print(1) self.__check_password(pwd_new) ad.ADpassword = generate_password_hash(pwd_new) ad.update(ad_dict, null='not') else: raise ParamsError('旧密码有误') db.session.add(ad) return Success('更新密码成功') raise AuthorityError('账号已被回收')
def get_integral(self): """获取个人积分变动情况""" # 后台可筛选,前台默认用户token args = parameter_required(('token', )) filter_args = [UserIntegral.isdelete == 0] user = token_to_user_(args.get('token')) if is_user(): filter_args.append(UserIntegral.USid == user.id) filter_args.append(UserIntegral.UItrue == 1) else: if not (is_admin() or is_hign_level_admin()): return AuthorityError() if args.get('usid'): filter_args.append(UserIntegral.USid == args.get('usid')) userIntegral = UserIntegral.query.filter(*filter_args).order_by(UserIntegral.createtime.desc()).all_with_page() for user_item in userIntegral: user = User.query.filter(User.USid == user_item.USid).first() user_item.fill('usname', user.USname) user_item.fill('utname', PointTaskType(user_item.UIaction).zh_value) user_item.fill('createtime', user_item.createtime) return Success(message="获取积分变动成功", data=userIntegral)
def list_submitter(self): if not is_admin(): raise AuthorityError('权限不足') data = parameter_required({'evid': '问卷'}) evid = data.get('evid') an_list = Answer.query.filter( Evaluation.EVid == Answer.EVid, Answer.EVid == evid, Answer.isdelete == 0, Evaluation.isdelete == 0).order_by( Answer.createtime.desc()).all_with_page() usid_list = [an.USid for an in an_list] user_list = User.query.filter(User.USid.in_(usid_list), User.isdelete == 0).all() user_dict = {user.USid: user for user in user_list} for an in an_list: user = user_dict.get(an.USid) if not user: continue an.fill('USname', user.USname or '') an.fill('UStelphone', user.UStelphone or '') an.fill('USavatar', user['USavatar'] or '') return Success(data=an_list)
def add_admin(self): """超级管理员添加普通管理""" if not is_hign_level_admin(): return AuthorityError() data = parameter_required(('adname',)) adid = str(uuid.uuid1()) adname = data.get('adname') adlevel = 2 # 账户名校验 self.__check_adname(adname) # 创建管理员 with db.auto_commit(): adinstance = Admin.create({ 'ADid': adid, 'ADname': adname, "ADtelphone": "", 'ADpassword': generate_password_hash("123456"), 'ADheader': "", 'ADlevel': adlevel, 'ADstatus': 0, }) db.session.add(adinstance) # 创建管理员变更记录 an_instance = AdminActions.create({ 'AAid': str(uuid.uuid1()), 'ADid': "1", "AAaction": 1, "AAmodel": "Admin", 'AAdetail': str(data) }) db.session.add(an_instance) return Success('创建管理员成功')
def make_evaluation(self): """提交评测""" data = parameter_required(('evid', 'ei_list')) # user = getattr(request, 'user') if not is_user(): raise AuthorityError('权限不足') usid = getattr(request, 'user').id evid = data.get('evid') anid = str(uuid.uuid1()) with db.auto_commit(): point = Decimal(0.0) evaluationitem_all = EvaluationItem.query.filter( EvaluationItem.isdelete == 0, EvaluationItem.EVid == evid).all() if len(evaluationitem_all) != len(data.get('ei_list')): return EvaluationNumError() for ei in data.get('ei_list'): eiid = ei["eiid"] eaid = ei["eaid"] evaluationitem = EvaluationItem.query.filter(EvaluationItem.EIid == eiid, EvaluationItem.isdelete == 0) \ .first_("未找到该题目") evaluationanswer = EvaluationAnswer.query.filter(EvaluationAnswer.EAid == eaid, EvaluationAnswer.isdelete == 0) \ .first_("未找到该选项") ai_dict = { "AIid": str(uuid.uuid1()), "EIname": evaluationitem["EIname"], "EAindex": evaluationanswer["EAindex"], "EApoint": evaluationanswer["EApoint"], "EAname": evaluationanswer["EAname"], "USid": usid, "ANid": anid } point = Decimal(str(evaluationanswer["EApoint"] or 0)) + Decimal(str(point or 0)) ai_instance = AnswerItem.create(ai_dict) db.session.add(ai_instance) evaluation = Evaluation.query.filter( Evaluation.isdelete == 0, Evaluation.EVid == evid).first_("未找到该评测") # 总积分逻辑改为平均分 # point = Decimal(str(point / len(evaluationitem_all))) current_app.logger.info(point) evaluationpoint = EvaluationPoint.query.filter(EvaluationPoint.EPstart <= point, EvaluationPoint.EVid == evid, EvaluationPoint.EPend >= point, EvaluationPoint.isdelete == 0) \ .first_("未找到评测结论") answer = evaluationpoint["EPanswer"] an_dict = { "ANid": anid, "USid": usid, "EVid": evid, "EVname": evaluation["EVname"], "EVpoint": point, "EPanswer": answer } an_instance = Answer.create(an_dict) share_url = Share(usid, point, an_instance).drawshare() an_instance.EVshare = share_url db.session.add(an_instance) # todo 创建分享图 from .CConfig import CConfig from ..config.enums import PointTaskType CConfig()._judge_point(PointTaskType.make_evaluation.value, 1, usid) return Success(message="提交评测成功", data={ "answer": answer, 'share': HTTP_HOST + share_url })
def set_coupon(self): """ 创建/编辑/删除优惠券 """ if not is_admin(): return AuthorityError('无权限') data = parameter_required(('costarttime', "coendtime", "cosubtration", "colimitnum") if not request.json.get('delete') else('coid',)) if data.get('codownline'): codownline = data.get('codownline') else: codownline = 0 costarttime = data.get('costarttime') coendtime = data.get('coendtime') if costarttime: start_time = datetime.datetime.strptime(costarttime, "%Y-%m-%d %H:%M:%S") else: start_time = datetime.datetime.now() if coendtime: end_time = datetime.datetime.strptime(coendtime, "%Y-%m-%d %H:%M:%S") else: end_time = datetime.datetime.now() co_dict = { 'COstarttime': costarttime, 'COendtime': coendtime, 'COdownline': codownline, 'COlimitnum': data.get('colimitnum'), 'COsubtration': Decimal(str(data.get('cosubtration') or 0)), 'COgetnum': 0 } coid = data.get('coid') with db.auto_commit(): if not coid: """新增""" if end_time < start_time or datetime.datetime.now() > start_time: return TimeError() co_dict['COid'] = str(uuid.uuid1()) co_dict["COstatus"] = 501 co_instance = Coupon.create(co_dict) msg = '添加成功' # 添加优惠券到期时的定时任务 add_async_task(func=change_coupon_status, start_time=end_time, func_args=(co_dict['COid'],), conn_id='end_coupon{}'.format(co_dict['COid'])) else: """修改/删除""" co_instance = Coupon.query.filter(Coupon.COid == coid).first_('未找到该优惠券信息') cancel_async_task(conn_id='end_coupon{}'.format(co_instance.COid)) # 取消已有定时任务 if data.get('delete'): co_instance.update({'isdelete': 1}) msg = '删除成功' else: if not (end_time > start_time >= datetime.datetime.now()): raise TimeError('结束时间需大于开始时间,开始时间需大于当前时间') co_instance.update(co_dict, null='not') msg = '编辑成功' # 重新添加优惠券到期时的定时任务 add_async_task(func=change_coupon_status, start_time=end_time, func_args=(co_instance.COid,), conn_id='end_coupon{}'.format(co_instance.COid)) db.session.add(co_instance) return Success(message=msg)
def set_review(self): """ 创建评论 """ if not is_user(): return AuthorityError() data = parameter_required(("rvcontent", "rvtype", "rvtypeid", "rvnum")) usid = request.user.id rvtype = int(data.get('rvtype')) rvtypeid = data.get('rvtypeid') if rvtype == 401: """课程""" subscribe = Subscribe.query.filter(Subscribe.SUid == rvtypeid).first_("未找到预约信息") classes = Course.query.filter(Course.COid == subscribe.COid).first_("未找到该课程排班") doid = classes["DOid"] elif rvtype == 402: """挂诊""" register = Register.query.filter(Register.REid == rvtypeid).first_("未找到该挂诊信息") doid = register["DOid"] elif rvtype == 403: """活动""" doid = None elif rvtype == 404: """案例""" doid = None elif rvtype == 405: """视频""" video = Video.query.filter(Video.VIid == rvtypeid).first_("未找到该视频信息") doid = video["DOid"] else: return StatusError("评论种类异常") rvid = str(uuid.uuid1()) user_dict = User.query.filter(User.USid == usid).first_("未找到该用户") if (rvtype == 401 or rvtype == 402) and Review.query.filter( Review.isdelete == 0, Review.USid == usid, Review.RVtype == rvtype, Review.RVtypeid == data.get('rvtypeid')).first(): raise StatusError('您已进行过评价') rv_dict = { "USid": usid, "USname": user_dict["USname"], "USavatar": user_dict["USavatar"], "RVcontent": data.get('rvcontent'), "DOid": doid, "RVtype": rvtype, "RVtypeid": data.get('rvtypeid'), "RVnum": Decimal(str(data.get('rvnum') or 0)) } if data.get('rppicture_list'): rppicture_list = data.get('rppicture_list') else: rppicture_list = [] with db.auto_commit(): if rvtype == 401: subscribe_instance = Subscribe.query.filter(Subscribe.SUid == rvtypeid).first_("未找到预约信息") subscribe_instance.update({ "SUstatus": 203 }) db.session.add(subscribe_instance) elif rvtype == 402: register_instance = Register.query.filter(Register.REid == rvtypeid).first_("未找到该挂诊信息") register_instance.update({ "REstatus": 4 }) db.session.add(register_instance) elif rvtype == 403: # 更改用户活动状态为已评价 rv_dict["RVtypeid"] = self._change_user_activity_comment_status(rvtypeid, usid) else: pass for repicture in rppicture_list: rp_dict = { "RPid": str(uuid.uuid1()), "RVid": rvid, "RPpicture": repicture["rppicture"] } rv_instance = ReviewPicture.create(rp_dict) db.session.add(rv_instance) rv_dict["RVid"] = rvid rv_instance = Review.create(rv_dict) db.session.add(rv_instance) from .CConfig import CConfig from ..config.enums import PointTaskType CConfig()._judge_point(PointTaskType.review.value, 1, usid) return Success("评论成功")
def inner(self, *args, **kwargs): if not is_doctor(): raise AuthorityError('需医生权限操作') return func(self, *args, **kwargs)
def inner(self, *args, **kwargs): if not is_admin(): raise AuthorityError() return func(self, *args, **kwargs)
def set_evaluationpoint(self): """设置分数区间""" data = parameter_required(( 'evid', 'epstart', 'epend', 'epanswer') if not request.json.get('delete') else ('epid', )) epid = data.get("epid") if not is_admin(): return AuthorityError() if data.get('epstart') and data.get('epend'): epstart = Decimal(str(data.get('epstart') or 0)) epend = Decimal(str(data.get('epend') or 0)) if epstart >= epend: return PointError("区间大小设置错误") else: epstart = 0 epend = 0 epsharelevel = data.get('epsharelevel') if not data.get('delete'): try: epsharelevel = EvaluationPointLevel(int(epsharelevel)).value except: raise ParamsError('分享等级目前只支持3级') doid = data.get('doid') title = data.get('eptitle') or '' if len(title) > 4: raise ParamsError('分享图标题 长度超标') analysis = data.get('epanalysis') or '' if len(analysis) > 12: raise ParamsError('初步分析 长度超标') evaluation = data.get('epevaluation') or '' if len(evaluation) > 162: raise ParamsError('评估建议 长度超标') award = data.get('epaward') or '' if len(award) > 15: raise ParamsError('奖励语 长度超标') shareWords = data.get('epshareWords') or '' if len(shareWords) > 63: raise ParamsError('分享文案 长度超标') ep_dict = { "EVid": data.get('evid'), "EPstart": epstart, "EPtitle": title, "EPanalysis": analysis, "EPevaluation": evaluation, "EPshareWords": shareWords, "EPshareLevel": epsharelevel, "EPend": epend, "EPanswer": data.get('epanswer') } if epsharelevel == EvaluationPointLevel.good.value: if not award: raise ParamsError('请输入奖励词') ep_dict['EPaward'] = award ep_dict['DOid'] = '' ep_dict['DOname'] = '' elif epsharelevel == EvaluationPointLevel.vigilant.value: doctor = Doctor.query.filter(Doctor.DOid == doid, Doctor.isdelete == 0).first() if not doctor: raise ParamsError('当前医生不存在') ep_dict['DOid'] = doid ep_dict['DOname'] = doctor.DOname ep_dict['EPaward'] = '' else: ep_dict['EPaward'] = '' ep_dict['DOid'] = '' ep_dict['DOname'] = '' epid = data.get("epid") if data.get('evid'): filter_args = [ EvaluationPoint.EVid == data.get('evid'), EvaluationPoint.isdelete == 0 ] if epid: filter_args.append(EvaluationPoint.EPid != epid) ep_list = EvaluationPoint.query.filter(*filter_args).all() for ep in ep_list: if not (epstart > Decimal(str(ep["EPend"] or 0)) or epend < Decimal(str(ep["EPstart"]) or 0)): return PointError('存在重叠分数区间') with db.auto_commit(): if not epid: # 新增 ep_dict["EPid"] = str(uuid.uuid1()) ep_instance = EvaluationPoint.create(ep_dict) msg = "新增成功" else: ep_instance = EvaluationPoint.query.filter( EvaluationPoint.EPid == epid).first_("未找到该分数区间") if data.get("delete"): ep_instance.update({"isdelete": 1}) msg = "删除成功" else: ep_instance.update(ep_dict) msg = "修改成功" db.session.add(ep_instance) return Success(message=msg)
def set_course(self): """ 课程排班 """ data = parameter_required( ('clid', 'costarttime', 'coendtime', 'conum')) coid = data.get('coid') classes = Classes.query.filter( Classes.CLid == data.get('clid')).first_("未找到课程信息,请联系管理员") doctor = Doctor.query.filter(Doctor.DOid == request.user.id, Doctor.isdelete == 0).first() # 时间控制 start_time = datetime.datetime.strptime(data.get('costarttime'), "%Y-%m-%d %H:%M:%S") end_time = datetime.datetime.strptime(data.get('coendtime'), "%Y-%m-%d %H:%M:%S") if not (end_time > start_time > datetime.datetime.now()): raise ParamsError('课程结束时间要大于开始时间, 开始时间要大于当前时间') if start_time.date() != end_time.date(): return { "status": 405, "status_code": 405301, "message": "课程开始结束时间需要同一天" } co_dict = { "CLid": data.get("clid"), "CLname": classes["CLname"], "DOid": request.user.id, "DOname": doctor["DOname"], "COstarttime": data.get("costarttime"), "COendtime": data.get("coendtime"), "COnum": data.get("conum"), "COstatus": 101 } with db.auto_commit(): if not coid: co_dict["COid"] = str(uuid.uuid1()) co_instance = Course.create(co_dict) msg = "创建成功" # 添加开始异步任务 add_async_task(func=change_course_status, start_time=start_time, func_args=(co_dict["COid"], ), conn_id='start_course{}'.format( co_dict["COid"])) # 添加结束异步任务 add_async_task(func=change_course_status, start_time=end_time, func_args=(co_dict["COid"], True), conn_id='end_course{}'.format(co_dict["COid"])) else: # 判断课程排班状态和已报名人数,已开始/已结束或者存在报名人员不可修改 course = Course.query.filter(Course.COid == coid).first() if course["COstatus"] != 101: return AuthorityError("无权限") subscribe = Subscribe.query.filter( Subscribe.COid == coid).all() if subscribe: return AuthorityError("已有人报名,不可修改") co_instance = Course.query.filter( Course.COid == coid).first_('未找到该课程排班信息') co_instance.update(co_dict, null='not') msg = '编辑成功' cancel_async_task(conn_id='start_course{}'.format( co_instance.COid)) # 取消已有的开始时间异步任务 cancel_async_task(conn_id='end_course{}'.format( co_instance.COid)) # 取消已有的结束时间异步任务 # 重新添加开始异步任务 add_async_task(func=change_course_status, start_time=start_time, func_args=(co_instance.COid, ), conn_id='start_course{}'.format( co_instance.COid)) # 重新添加结束异步任务 add_async_task(func=change_course_status, start_time=end_time, func_args=(co_instance.COid, True), conn_id='end_course{}'.format(co_instance.COid)) db.session.add(co_instance) return Success(message=msg, data={"coid": co_instance.COid})