Beispiel #1
0
def createTeacher(request):
    """
    创建老师
    :param request:
    :return:
    """
    try:
        user = AuthUser.objects.get(username=request.user.username)
        teachers = user.teacher_set.all()
        if not user.is_superuser and len(teachers) > 0:
            return JsonError("already existed")
        if request.method == 'POST':
            temp = request.data.dict() if (
                type(request.data) != type({})) else request.data
            changeObejct(temp)
            photos = temp.get('teach_show_photo', None)
            if photos and photos != "":
                temp['teach_show_photo'] = changeBaseToImg(photos)
            certificate_photo = temp.get('certificate_photo', None)
            if certificate_photo and certificate_photo != "":
                temp['certificate_photo'] = changeSingleBaseToImg(
                    certificate_photo)
            now = time.strftime('%Y-%m-%d %H:%M:%S',
                                time.localtime(time.time()))
            temp['create_time'] = now
            temp['update_time'] = now
            teacher = Teacher(**temp)
            teacher.wechat = user
            teacher.save()
        return JsonResponse({"wechat_id": teacher.wechat_id})
    except Exception, e:
        print 'traceback.print_exc():'
        traceback.print_exc()
        return JsonError(e.message)
Beispiel #2
0
def changeText(request):
    """
    修改系统配置的文本
    :return:
    """
    data = request.data
    result = {}
    #将照片的base64转换成路径,然后保存在数据库上
    if data.has_key('image') and data.has_key('url'):
        image = Config.objects.filter(key='image')[0].value
        url = Config.objects.filter(key='url')[0].value
        imgs = image.split(',') if image != "" else []
        urls = url.split(',') if url != "" else []
        if len(imgs) > 4:
            return JsonError(u"只接受5个广告位")
        banner = changeSingleBaseToImg(data['image'])
        imgs.append(banner)
        result['image'] = banner
        urls.append(data['url'])
        data['image'] = ",".join(imgs)
        data['url'] = ",".join(urls)
    try:
        with transaction.atomic():
            for k in data.keys():
                Config.objects.filter(key=k).update(value=data[k])
    except Exception,e:
        return JsonError(e.message)
Beispiel #3
0
def remindFeedBack(request):
    """
    提醒某个用户提交反馈
    :param request:
    :return:
    """
    id = request.data.get('id',None)
    userType = request.data.get('user',None)
    user = AuthUser.objects.get(username=request.user.username)
    message_title = u"好学吧家教邀请您填写反馈意见!"
    message_content = u"好学吧家教邀请您填写反馈意见!"
    if userType == "parent":
        objs = ParentOrder.objects.filter(pd_id = id)
    elif userType == "teacher":
        objs = Teacher.objects.filter(tea_id = id)
    else:
        return JsonError(u"输入数据的user值不对")
    if len(objs):
        obj = objs[0]
        now = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
        message = Message(sender=user, receiver=obj.wechat, message_title=message_title,
                          message_content=message_content,status=0,update_time=now,create_time=now)
        message.save()
        return JsonResponse()
    else:
        return JsonError(u"找不到用户!")
Beispiel #4
0
def uploadScreenshot(request):
    """
    上传订单截图
    :param request:
    :return:
    """
    user = AuthUser.objects.get(username=request.user.username)
    teas = user.teacher_set.all()
    pic = request.data.get('pic', None)
    oa_id = int(request.data.get('oa_id', -1))
    if len(teas):
        tea = teas[0]
        order_applys = OrderApply.objects.filter(oa_id=oa_id, tea=tea)
        if len(order_applys):
            name = changeSingleBaseToImg(pic)
            order_apply = order_applys[0]
            order_apply.screenshot_path = name
            order_apply.finished = 2
            order_apply.update_time = timezone.now()
            order_apply.save()
            return JsonResponse()
        else:
            return JsonError(u"找不到该订单")
    else:
        return JsonError(u"出错,你的老师信息不存在,请重新调调查问卷!")
Beispiel #5
0
def setHot(request):
    """
    设置某个老师为热门或者非热门
    :param request:
    :return:
    """
    id = request.data.get('id',None)
    userType = request.data.get('user',None)
    method = request.data.get('type',None)
    if userType == "parent":
        if method:
            #设为热门
            resNum = ParentOrder.objects.filter(tea_id = id).update(hot_not=1)
        else:
            resNum = ParentOrder.objects.filter(tea_id = id).update(hot_not=0)
    elif userType == "teacher":
        if method:
            #设为热门
            resNum = Teacher.objects.filter(tea_id = id).update(hot_not=1)
        else:
            resNum = Teacher.objects.filter(tea_id = id).update(hot_not=0)
    else:
        return JsonError(u"输入数据的user值不对")
    if resNum == 1:
        return JsonResponse()
    else:
        return JsonError("not found")
Beispiel #6
0
def updateInfo(request):
    """
    更新某个家长或者老师用户信息
    :param request:
    {
      "id":1,
      "userInfo":{"name":"管理员修改过"},
      "user":"******"
    }
    :return:
    """
    id = request.data.get('id',None)
    userType = request.data.get('user',None)
    temp = request.data.dict()  if (type(request.data.get('userInfo', {})) != type({})) else request.data.get('userInfo', {})
    now = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
    temp['update_time']= now
    changeObejct(temp)
    if userType == "parent":
        resNum = ParentOrder.objects.filter(pd_id = id).update(**temp)
    elif userType == "teacher":
        resNum = Teacher.objects.filter(tea_id = id).update(**temp)
    else:
        return JsonError(u"输入数据的user值不对")
    if resNum == 1:
        return JsonResponse()
    else:
        return JsonError("not found")
Beispiel #7
0
def sendPhone(request):
    """
    发送联系方式给某个老师
    :param request:{"tea_id":1,"tel":18812345678,"oa_id":3}
    :return:
    """
    tea_id = request.data.get('tea_id',None)
    oa_id = request.data.get('oa_id',None)
    tel = request.data.get('tel',None)
    teas = Teacher.objects.filter(tea_id=tea_id)
    oas = OrderApply.objects.filter(oa_id=oa_id)
    user = AuthUser.objects.get(username=request.user.username)
    if len(teas) and len(oas):
        tea = teas[0]
        oa = oas[0]
        pd_name  = oa.pd.name
        message_title = u"向您发送了" + pd_name +u"家长的联系方式!"
        message_content = pd_name + u"家长的联系方式是" + str(tel)
        now = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
        message = Message(sender=user, receiver=tea.wechat, message_title=message_title,
                          message_content=message_content,status=0,update_time=now,create_time=now)
        message.save()
        oa.tel = str(tel)
        oa.finished = 1
        oa.save()
        return JsonResponse()
    else:
        return JsonError(u"输入数据有误")
Beispiel #8
0
def setPass(request):
    """
    审核某个家长或老师简历,是否通过
    :param request:
    {
      "id":1,
      "type":0,
      "user":"******"
    }
    :return:
    """
    id = request.data.get('id',None)
    method = request.data.get('type',None)
    userType = request.data.get('user',None)
    if userType == "parent":
        if method:
            resNum = ParentOrder.objects.filter(pd_id = id).update(pass_not=2)
        else:
            resNum = ParentOrder.objects.filter(pd_id = id).update(pass_not=0)
    elif userType == "teacher":

        #TODO:消息通知?
        if method:
            resNum = Teacher.objects.filter(tea_id = id).update(pass_not=2)
        else:
            resNum = Teacher.objects.filter(tea_id = id).update(pass_not=0)
    if resNum == 1:
        return JsonResponse()
    else:
        return JsonError("not found")
Beispiel #9
0
def getOrders(request):
    """
    获取某个家长或者老师用户订单信息
    :param request:{"id":1,"user":"******","start":0,"size":6}
    :return:
    """
    id = request.data.get('id',None)
    userType = request.data.get('user',None)
    size = int(request.data.get("size",0))
    start = int(request.data.get("start",0)) * size
    if userType == "parent":
        oas = OrderApply.objects.filter(pd_id=id).order_by('-update_time')[start:start+size]
        #家长的订单详情
        results = []
        for oa in oas:
            oa.name= oa.tea.name
            oa.result = getTeacherResult(oa)
        return Response(OrderApplySerializer(oas,many=True).data)
    elif userType == "teacher":
        #老师的订单详情
        oas = OrderApply.objects.filter(tea_id=id).order_by('-update_time')[start:start+size]
        results = []
        for oa in oas:
            oa.name= oa.pd.name
            oa.result = getParentResult(oa)

        return Response(OrderApplySerializer(oas,many=True).data)
    else:
        return JsonError(u"输入数据的user值不对")
Beispiel #10
0
def getTeachers(request):
    """
        全部老师根据类别获取老师列表
        :param request:
        {
        "size":6,
        "start":0,
        "subject":"语文",
        "grade":1,
        "hot":1,
        }
        :return:
            teacher obejcts
    """
    #TODO:排序与选择
    size = int(request.data.get("size", 0))
    start = int(request.data.get("start", 0)) * size
    #根据学科排序
    subject = request.data.get("subject", '')
    #根据年级排序
    grade = request.data.get("grade", '')
    keyword = request.data.get("keyword", '')
    #根据最新最热排序,两个参数是最热门和最新,默认为最热门(参数为1),然后是最新(参数为2)
    hot = request.data.get("hot", 1)
    where = []
    filter = {}
    order = ['-hot_not', '-update_time']
    if hot == 2:
        order = ['-update_time']
    if subject and subject != '':
        where = ['FIND_IN_SET("' + subject + '",subject)']
    #年级,如果里面是字符串,需要加引号
    if grade and grade != '':
        where = ['FIND_IN_SET("' + grade + '",grade)']
    if keyword and keyword != '':
        filter["name__contains"] = keyword
    teachers = Teacher.objects.extra(where=where).filter(**filter).order_by(
        *order)[start:start + size]
    user = AuthUser.objects.get(username=request.user.username)
    pds = user.parentorder_set.all()
    #管理员调用该该接口,没有isInvited
    if len(pds) > 0 and not user.is_superuser:
        pd = pds[0]
        #获取到老师的数据,需要判断是不是报名或者被邀请
        for t in teachers:
            t.distance = getUserDistance(user, t.wechat)
            t.isInvited = ''
            #家长主动
            orderApply = OrderApply.objects.filter(pd=pd, tea=t)
            if len(orderApply):
                oa = orderApply[0]
                t.isInvited = getTeacherResult(oa)

    elif len(pds) == 0 and not user.is_superuser:
        return JsonError("家长不存在!请重新填问卷")

    serializer = TeacherSerializer(teachers, many=True)
    teachersData = serializer.data
    getTeacherObj(teachersData, many=True)
    return Response(teachersData)
Beispiel #11
0
def setLocations(request):
    """
    用户设置locations
    :param request:
        {
        "longitude":23.0580629881,
        "latitude":113.3853235930
        }
    :return:
    """
    try:
        longitude = float(request.data.get("longitude", -1))
        latitude = float(request.data.get("latitude", -1))
        user = AuthUser.objects.get(username=request.user.username)
        address = getAddress(latitude, longitude)
        locations = user.locations_set.all()
        if len(locations) > 0:
            l = locations[0]
            l.longitude = longitude
            l.latitude = latitude
            l.address = address
        else:
            l = Locations(longitude=longitude,
                          latitude=latitude,
                          wechat=user,
                          address=address)
        l.save()
        return JsonResponse()
    except Exception, e:
        print 'traceback.print_exc():'
        traceback.print_exc()
        return JsonError(e.message)
Beispiel #12
0
def getPayInfo(request):
    """
    获取订单的支付信息,订单开始计时
    :param request:
    :return:
    """
    payAmount = 50  #支付金额
    payAccount = 18812341235  #支付账号
    user = AuthUser.objects.get(username=request.user.username)
    teas = user.teacher_set.all()
    if len(teas):
        tea = teas[0]
        oa_id = request.data.get('oa_id', None)
        oas = OrderApply.objects.filter(oa_id=oa_id,
                                        tea=tea,
                                        finished=0,
                                        teacher_willing=1)
        print oas
        # if len(oas):
        #     oa = oas[0]
        #     oa.teacher_willing = 2
        #     oa.update_time = timezone.now()
        #     oa.save()
    else:
        return JsonError(u"你的信息不存在!")

    return JsonResponse({payAccount: payAccount, payAmount: payAmount})
Beispiel #13
0
def deleteOrder(request):
    oa_id = int(request.data.get('oa_id',0))
    oas = OrderApply.objects.filter(oa_id=oa_id)
    if len(oas):
        oa = oas[0]
        oa.delete()
        return JsonResponse()
    else:
        return JsonError(u"not found")
Beispiel #14
0
def deleteUser(request):
    """
    删除用户
    :param request: {"id":1,"user":"******"}
    :return:
    """
    #TODO:删除外键约束
    userType = request.data.get('user',None)
    id = request.data.get('id',None)
    if userType == "parent":
        obj = ParentOrder.objects.filter(pd_id=id)
    elif userType == "teacher":
        obj = Teacher.objects.filter(tea_id=id)
    else:
        return JsonError(u"输入数据的user值不对")
    if len(obj):
        obj[0].delete()
    else:
        return JsonError(u"找不到该用户")
    return JsonResponse()
Beispiel #15
0
def getInfo(request):
    """
    获取某个家长或者老师的信息
    :param request:
    {
      "id":1,
      "format":true/false,
      "user":"******"
    }
    :return:
    """
    id = request.data.get('id',None)
    format = request.data.get('format',None)
    userType = request.data.get('user',None)
    if userType == "parent":
        pds = ParentOrder.objects.filter(pd_id = id)
        if len(pds):
            serializer = ParentOrderSerializer(pds[0])
            result = serializer.data
        else:
            return JsonError("not found")
        if format:
            getParentOrderObj(result)
        else:
            changeTime(result)
    elif userType == "teacher":
        teas = Teacher.objects.filter(tea_id=id)
        if len(teas):
            serializer = TeacherSerializer(teas[0])
            result = serializer.data
        else:
            return JsonError("not found")
        if format:
            getTeacherObj(result)
        else:
            defaultChangeTeachShowPhoto(result)
            changeTime(result)

    else:
        return JsonError(u"输入数据的user值不对")
    return JsonResponse(result)
Beispiel #16
0
def loginAdmin(request):
    username = request.data.get('username',None)
    password = request.data.get('password',None)
    user = authenticate(username=username, password=password)
    if user is not None:
        # the password verified for the user
        if user.is_active:
            login(request,user)
            return JsonResponse()
    else:
        # the authentication system was unable to verify the username and password
        return JsonError('The username and password were incorrect.')
Beispiel #17
0
def deleteTeacher(request):
    """
    删除
    :param request:
    :return:
    """
    #TODO:删除外键约束
    user = AuthUser.objects.get(username=request.user.username)
    teachers = user.teacher_set.all()
    if len(teachers) > 0:
        teachers[0].delete()
        return JsonResponse()
    return JsonError("not found")
Beispiel #18
0
def deleteParent(request):
    """
    删除
    :param request:
    :return:
    """
    #TODO:删除外键约束
    user = AuthUser.objects.get(username=request.user.username)
    parentorder = user.parentorder_set.all()
    if len(parentorder) > 0:
        parentorder[0].delete()
        return JsonResponse()
    return JsonError("not found")
Beispiel #19
0
def getParentInfo(request):
    """
    获取个人信息
    :param request:
    :return:
    """
    user = AuthUser.objects.get(username=request.user.username)
    format = None
    if request.method == "GET":
        parents = user.parentorder_set.all()
        if len(parents):
            serializer = ParentOrderSerializer(parents[0])
            result = serializer.data
        else:
            return JsonError("not found")
    elif request.method == "POST":
        pd_id = request.data.get('pd_id',None)
        format = request.data.get('format',None)
        if not pd_id:
            parents =  user.parentorder_set.all()
            if len(parents):
                serializer = ParentOrderSerializer(parents[0])
                result = serializer.data
            else:
                return JsonError("not found")
        else:
            pds = ParentOrder.objects.filter(pd_id = pd_id)
            if len(pds):
                serializer = ParentOrderSerializer(pds[0])
                result = serializer.data
            else:
                return JsonError("not found")
    if format:
        getParentOrderObj(result)
    else:
        changeTime(result)
    return Response(result)
Beispiel #20
0
def updateTeacher(request):
    """
    修改老师
    :param request:
    :return:
    """
    try:
        user = AuthUser.objects.get(username=request.user.username)
        teachers = user.teacher_set.all()
        if request.method == 'POST' and len(teachers) > 0:
            temp = request.data.dict() if (
                type(request.data) != type({})) else request.data
            changeObejct(temp)
            temp['pass_not'] = 1
            photos = temp.get('teach_show_photo', None)
            if photos and photos != "":
                temp['teach_show_photo'] = changeBaseToImg(photos)
            certificate_photo = temp.get('certificate_photo', None)
            if certificate_photo and certificate_photo != "":
                temp['certificate_photo'] = changeSingleBaseToImg(
                    certificate_photo)
            now = time.strftime('%Y-%m-%d %H:%M:%S',
                                time.localtime(time.time()))
            temp['update_time'] = now
            teacher = user.teacher_set.update(**temp)
            return JsonResponse()
            # 返回更新后的对象
            # serializer = TeacherSerializer(user.teacher_set.all()[0])
            # result = serializer.data
            # getTeacherObj(result)
            # return Response(result)
        return JsonError("not found")
    except Exception, e:
        print 'traceback.print_exc():'
        traceback.print_exc()
        return JsonError(e.message)
Beispiel #21
0
def handleUserOrder(request):
    """
    管理员处理订单
    :param request:
    {
     "oa_id": 1         订单ID
     "user":teacher/parent,           修改老师还是家长的意愿
     "willing": 0/1/2      0/1/2  0:拒绝 1:待处理 2:接受
     }
    :return:
    """
    user = AuthUser.objects.get(username=request.user.username)
    oa_id = int(request.data.get('oa_id',0))
    userType = request.data.get('user',None)
    willing = request.data.get('willing',None)
    try:
        oa = OrderApply.objects.get(oa_id = oa_id)
        if userType == 'teacher':
            #TODO:管理员暂时无法处理老师的订单
            if willing == 0:
                oa.teacher_willing = 0
                oa.finished = 1
            if willing == 2:
                oa.teacher_willing = 2
        if userType == 'parent':
            #将家长意愿修改为拒绝
            if willing == 0:
                oa.parent_willing = 0
                oa.finished = 1
                message_title = oa.pd.name + u"拒绝了你的报名!"
                message_content = oa.pd.name +  u"拒绝了你的报名!请到“我的家长”处查看详细信息!"

            if willing == 2:
                oa.parent_willing = 2
                oa.finished = 0
                message_title = oa.pd.name + u"接受了你的报名!"
                message_content = oa.pd.name +  u"接受了你的报名!请到“我的家长”处查看详细信息!"

            now = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
            message = Message(sender=user, receiver=oa.tea.wechat, message_title=message_title,
                              message_content=message_content,status=0,update_time=now,create_time=now)
            oa.save()
            message.save()
        return JsonResponse()
    except Exception,e:
        print 'traceback.print_exc():'; traceback.print_exc()
        return JsonError(e.message)
Beispiel #22
0
def deleteBanner(request):
    try:
        image = request.data.get('image',None)
        img = Config.objects.filter(key='image')[0]
        imgs = img.value.split(',')
        url = Config.objects.filter(key='url')[0]
        urls = url.value.split(',')
        idx = imgs.index(image)
        del imgs[idx]
        del urls[idx]
        url.value = ",".join(urls)
        img.value = ",".join(imgs)
        url.save()
        img.save()
        return JsonResponse()
    except Exception,e:
        print e
        return JsonError(e.message)
Beispiel #23
0
def submitFeedBack(request):
    """
    提交反馈
    :param request:
    {
        "tutorservice":"tutorService",
        "appservice":"appService",
        "rate":4
    }
    :return:
    """
    try:
        user = AuthUser.objects.get(username=request.user.username)
        data = request.data
        data['create_time'] = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
        data['wechat'] = user
        fb = Feedback(**data)
        fb.save()
    except Exception,e:
        return JsonError(str(e))
Beispiel #24
0
def updateParentOrder(request):
    """
    更新家长订单
    :param request:
    :return:
    """
    user = AuthUser.objects.get(username=request.user.username)
    parentorder = user.parentorder_set.all()
    if request.method == 'POST' and len(parentorder) > 0:
        now = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
        temp = request.data.dict()  if (type(request.data) != type({})) else request.data
        changeObejct(temp)
        temp['update_time']= now
        temp['pass_not'] =1
        po = user.parentorder_set.update(**temp)
        return JsonResponse()
        # serializer = ParentOrderSerializer(user.parentorder_set.all()[0])
        # result = serializer.data
        # getParentOrderObj(result)
        # return Response(result)
    return JsonError("not found")
Beispiel #25
0
def getParentOrder(request):
    """
    获取家长列表。家长对于老师的申请处理
    :param request:
    {"start":0,"size":6}
    :return:
    """
    size = int(request.data.get("size",0))
    start = int(request.data.get("start",0)) * size
    keyword = request.data.get("keyword", '')
    filter = {}
    if keyword and keyword != '':
        filter["name__contains"] = keyword
    user = AuthUser.objects.get(username=request.user.username)
    parentOrders = ParentOrder.objects.filter(**filter).order_by('-update_time')[start:start + size]
    teas = user.teacher_set.all()
    if len(teas) > 0 and not user.is_superuser:
        tea = teas[0]
        for po in parentOrders:
            #计算距离
            po.distance = getUserDistance(user,po.wechat)
            #替换微信端的地址
            po.address = ''
            locations = po.wechat.locations_set.all()
            if len(locations) > 0:
                po.address = locations[0].address

            po.isInvited = ''
            #老师主动报名
            orderApply = OrderApply.objects.filter(pd=po,tea= tea)
            if len(orderApply):
                oa = orderApply[0]
                po.isInvited = getParentResult(oa)
    elif len(teas) == 0 and not user.is_superuser:
        return JsonError(u"您不是老师!请重新填问卷")

    serializer = ParentOrderSerializer(parentOrders, many=True)
    result = serializer.data
    getParentOrderObj(result, many=True)
    return Response(result)
Beispiel #26
0
def createParentOrder(request):
    """
    创建家长订单
    :param request:
    :return:
    """
    user = AuthUser.objects.get(username=request.user.username)
    parentorder = user.parentorder_set.all()
    #TODO:管理员创建多个会有什么连锁反应
    #TODO:这个以后会加个限制,不让同时创建老师和家长
    if not user.is_superuser and len(parentorder) > 0:
        return JsonError("already existed")
    if request.method == 'POST':
        temp = request.data.dict()  if (type(request.data) != type({})) else request.data
        changeObejct(temp)
        now = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
        temp['create_time']= now
        temp['update_time']= now
        po = ParentOrder(**temp)
        po.wechat = user
        po.save()
    return JsonResponse({"wechat_id":po.wechat_id})
Beispiel #27
0
def getTeacherInfo(request):
    """
    获取个人信息
    :param request:
    :return:
    """
    user = AuthUser.objects.get(username=request.user.username)
    format = None
    result = {}
    if request.method == "GET":
        teacher = user.teacher_set.all()
        if len(teacher):
            serializer = TeacherSerializer(teacher[0])
            result = serializer.data
        else:
            return JsonError("not found")
    elif request.method == "POST":
        tea_id = request.data.get('tea_id', None)
        format = request.data.get('format', None)
        if not tea_id:
            teacher = user.teacher_set.all()
            if len(teacher):
                serializer = TeacherSerializer(teacher[0])
                result = serializer.data
        else:
            teas = Teacher.objects.filter(tea_id=tea_id)
            if len(teas):
                serializer = TeacherSerializer(teas[0])
                result = serializer.data
    if format:
        getTeacherObj(result)
    else:
        defaultChangeTeachShowPhoto(result)
        changeTime(result)

    return Response(result)
Beispiel #28
0
def getText(request):
    """
    获取系统一些配置信息
    :param request:
    :return:
    """
    key = request.data.get('key', None)
    result = {}
    try:
        for k in key:
            if k == "getImg":
                value = []
                image = Config.objects.filter(key='image')[0].value
                url = Config.objects.filter(key='url')[0].value
                imgs = image.split(',') if image != "" else []
                urls = url.split(',') if image != "" else []
                for i, v in enumerate(imgs):
                    value.append({"img": v, "url": urls[i]})
            else:
                value = Config.objects.get(key=k).value
            result[k] = value
        return JsonResponse(result)
    except Exception, e:
        return JsonError(e.message)
Beispiel #29
0
def applyParent(request):
    """
    老师报名家长,取消报名
    :param request:
    {
        "pd_id":2,
        "type": 1/0,
        "expectation":""
    }
    :return:
    """
    #获取家长id
    temp = request.data.dict() if (
        type(request.data) != type({})) else request.data
    pd_id = int(temp.get("pd_id", -1))
    method = int(temp.get("type", -1))
    expectation = temp.get("expectation", None)

    user = AuthUser.objects.get(username=request.user.username)
    #查找教师
    teachers = user.teacher_set.all()
    #查找家长订单
    pds = ParentOrder.objects.filter(pd_id=pd_id)
    if len(pds) and len(teachers):
        teacher = teachers[0]
        pd = pds[0]
        if method == 1:
            #老师报名家长,老师可以报名多个家长!!

            #检查家长是否已经邀请该老师,是否已经存在两个人的对应订单
            orders = OrderApply.objects.filter(apply_type=2,
                                               pd=pd,
                                               tea=teacher,
                                               finished__in=[0, 2])
            if len(orders):
                return JsonError(u"该家长已经邀请了您!")

            #家长之前拒绝了该老师,老师再次报名家长
            orders = OrderApply.objects.filter(apply_type=1,
                                               pd=pd,
                                               tea=teacher)
            if len(orders):
                order = orders[0]
                order.finished = 0
                order.parent_willing = 1
                order.teacher_willing = 1
                order.update_time = timezone.now()
                order.expectation = expectation
            else:
                order = OrderApply(apply_type=1,
                                   pd=pd,
                                   tea=teacher,
                                   parent_willing=1,
                                   teacher_willing=1,
                                   pass_not=1,
                                   update_time=timezone.now(),
                                   expectation=expectation,
                                   finished=0)
            #事务
            try:
                with transaction.atomic():
                    #新建订单
                    order.save()
                    message_title = teacher.name + u"向您报名!"
                    message_content = teacher.name + u"向您报名!请到“我的老师”处查看详细信息!"
                    now = time.strftime('%Y-%m-%d %H:%M:%S',
                                        time.localtime(time.time()))
                    #新建消息
                    message = Message(sender=user,
                                      receiver=pd.wechat,
                                      message_title=message_title,
                                      message_content=message_content,
                                      status=0,
                                      update_time=now,
                                      create_time=now)
                    message.save()
                    sendTemplateMessage(
                        pd, settings.DOMAIN + 'tutor_web/view/myList.html',
                        message_title, message_content, teacher.name, now)
                    #TODO:推送到微信端

            except Exception, e:
                return JsonError(e.message)
            return JsonResponse()

        elif method == 0:
            #老师取消报名家长
            try:
                with transaction.atomic():
                    #删除订单
                    orders = OrderApply.objects.filter(apply_type=1,
                                                       pd=pd,
                                                       tea=teacher,
                                                       finished=0)
                    if len(orders):
                        order = orders[0]
                        order.delete()
                        message_title = teacher.name + u"取消了报名!"
                        message_content = teacher.name + u"取消了报名!"
                        now = time.strftime('%Y-%m-%d %H:%M:%S',
                                            time.localtime(time.time()))
                        #新建消息
                        message = Message(sender=user,
                                          receiver=pd.wechat,
                                          message_title=message_title,
                                          message_content=message_content,
                                          status=0,
                                          update_time=now,
                                          create_time=now)
                        message.save()
                        sendTemplateMessage(
                            pd, settings.DOMAIN + 'tutor_web/view/myList.html',
                            message_title, message_content, teacher.name, now)
                    else:
                        return JsonError(u"找不到该订单")
                        #TODO:推送到微信端

            except Exception, e:
                return JsonError(e.message)
            return JsonResponse()
Beispiel #30
0
def handleOrder(request):
    """
    处理订单的各种情况,接受或者拒绝老师的报名或者家长的邀请
    :param request:
     {
     "type": 0/1        0:老师处理家长 1:家长处理老师
     "id":1,            如果是老师处理家长,则填对应的pd_id,如果家长处理老师,则填对应的tea_id
     "accept": 0/1      0/1  0:拒绝 1:接受
     }
    :return:
    """
    type = request.data.get('type', None)
    id = request.data.get('id', None)
    accept = request.data.get('accept', None)
    if (type != None and id != None and accept != None):
        user = AuthUser.objects.get(username=request.user.username)
        #家长处理老师
        if (type):
            parentorders = user.parentorder_set.all()
            teas = Teacher.objects.filter(tea_id=id)
            if (len(parentorders) and len(teas)):
                pd = parentorders[0]
                tea = teas[0]
                orders = OrderApply.objects.filter(tea=tea, pd=pd, finished=0)
                if len(orders):
                    order = orders[0]
                    #对订单进行处理
                    if (accept):
                        order.parent_willing = 2
                        message_title = pd.name + u"接受了你的报名!"
                        message_content = pd.name + u"接受了你的报名!请到“我的家长”处查看详细信息!"
                    else:
                        order.parent_willing = 0
                        order.finished = 1
                        message_title = pd.name + u"拒绝了你的报名!"
                        message_content = pd.name + u"拒绝了你的报名!请到“我的家长”处查看详细信息!"
                    #新建消息
                    now = time.strftime('%Y-%m-%d %H:%M:%S',
                                        time.localtime(time.time()))
                    message = Message(sender=user,
                                      receiver=tea.wechat,
                                      message_title=message_title,
                                      message_content=message_content,
                                      status=0,
                                      update_time=now,
                                      create_time=now)
                    try:
                        with transaction.atomic():
                            message.save()
                            order.update_time = timezone.now()
                            order.save()
                            #TODO:消息推送到微信端
                            sendTemplateMessage(
                                tea,
                                settings.DOMAIN + 'tutor_web/view/myList.html',
                                message_title, message_content, pd.name, now)
                    except Exception, e:
                        return JsonError(e.message)
                    return JsonResponse()
                else:
                    return JsonError(u"处理错误,请确定数据无误!")
            else:
                return JsonError(u"处理错误,请确定数据无误!")
        else:
            #老师处理家长
            #finished为0
            # 第一种情况:老师处理家长的邀请
            # 第二种情况:老师报名家长后,家长同意后,老师再次处理同意
            #finished为1
            #老师拒绝了家长,再次接受邀请,tea=tea,pd=pd,finished=1,type=2
            teas = user.teacher_set.all()
            parentorders = ParentOrder.objects.filter(pd_id=id)
            if (len(parentorders) and len(teas)):
                pd = parentorders[0]
                tea = teas[0]
                orders = OrderApply.objects.filter(tea=tea, pd=pd, finished=0)
                if len(orders):
                    order = orders[0]
                    result = {}
                    #对订单进行处理
                    if (accept):
                        #老师同意,不应该设为2,应该在获取支付信息的时候改变??
                        order.teacher_willing = 2
                        message_title = tea.name + u"接受了你的邀请!"
                        message_content = tea.name + u"接受了你的邀请!请到“我的老师”处查看详细信息!"
                        payAmount = 50  #支付金额
                        payAccount = 18812341235  #支付账号
                        result = {payAccount: payAccount, payAmount: payAmount}
                    else:
                        order.teacher_willing = 0
                        order.finished = 1
                        message_title = tea.name + u"拒绝了你的邀请!"
                        message_content = tea.name + u"拒绝了你的邀请!请到“我的老师”处查看详细信息!"
                    now = time.strftime('%Y-%m-%d %H:%M:%S',
                                        time.localtime(time.time()))
                    message = Message(sender=user,
                                      receiver=pd.wechat,
                                      message_title=message_title,
                                      message_content=message_content,
                                      status=0,
                                      update_time=now,
                                      create_time=now)
                    try:
                        with transaction.atomic():
                            message.save()
                            order.update_time = timezone.now()
                            order.save()
                            sendTemplateMessage(
                                pd,
                                settings.DOMAIN + 'tutor_web/view/myList.html',
                                message_title, message_content, tea.name, now)
                        #消息推送到微信端
                    except Exception, e:
                        return JsonError(e.message)
                    return JsonResponse(result)

                else:
                    return JsonError(u"处理错误,请确定数据无误!")
            else: