Exemple #1
0
def AlipayCallbackUrl():
    userId='9'
    if session.has_key('userId'):
        userId=session['userId']
    if userId is None:
        redirect(LOGIN_URL)
    params=AlipayCallBackInfo(request.args)
    payRecord=AlipayChargeRecord(params.diagnoseSeriesNumber,params.buyer_email,params.buyer_id,params.is_success,params.notify_time,
                       params.notify_type,params.total_fee,params.trade_no,params.trade_status,params.out_trade_no)
    AlipayChargeRecord.save(payRecord)
    if params.is_success=='T' and params.trade_status=='TRADE_SUCCESS':
       diagnose=Diagnose.getDiagnoseByDiagnoseSeriesNo(params.diagnoseSeriesNumber)
       if diagnose:
           diagnoseId=diagnose.id
           alipayLog=AlipayLog(userId,diagnoseId,constant.AlipayLogAction.PayFilished)
           AlipayLog.save(alipayLog)
           diagnose.status=constant.DiagnoseStatus.NeedTriage
           Diagnose.save(diagnose)
           result=rs.ResultStatus(rs.SUCCESS.status,'支付成功')
           return  json.dumps(result.__dict__,ensure_ascii=False)
       else:
           # alipayLog=AlipayLog(userId,params.diagnoseSeriesNumber,constant.AlipayLogAction.PayFilished)
           # AlipayLog.save(alipayLog)
           LOG.error("支付成功,但系统诊断已经取消(诊断序列号:%s)",params.diagnoseSeriesNumber)
           result=rs.ResultStatus(rs.SUCCESS.status,'支付成功,但系统诊断已经取消')
           return  json.dumps(result.__dict__,ensure_ascii=False)
    # alipayLog=AlipayLog(userId,params.diagnoseSeriesNumber,constant.AlipayLogAction.PayFailure)
    # AlipayLog.save(alipayLog)
    LOG.error("支付失败(诊断序列号:%s)",params.diagnoseSeriesNumber)
    result=rs.ResultStatus(rs.FAILURE.status,'支付失败')
    return  json.dumps(result.__dict__,ensure_ascii=False)
Exemple #2
0
def AlipayCallbackUrl():

    params = AlipayCallBackInfo(request.args)
    if params.diagnoseSeriesNumber is None:
        LOG.error("支付回调出错,无法拿到diagnoseSeriesNumber")
        return redirect(ERROR_URL)
    if (not params.trade_no) or (not params.out_trade_no) or (
            not params.trade_status):
        LOG.error("支付回调出错,tradeNo")
        return redirect(ERROR_URL)

    diagnose = Diagnose.getDiagnoseByDiagnoseSeriesNo(
        params.diagnoseSeriesNumber)
    if diagnose is None or (not hasattr(
            diagnose, "patient")) or diagnose.patient.userID is None:
        LOG.error("支付回调出错,无法拿到诊断[diagnoseSeriesNumber%s]" %
                  params.diagnoseSeriesNumber)
    #跳过验证,以后再测试,必须传入notify_id
    # verfyParams={}
    # verfyParams['out_trade_no']=params.out_trade_no
    # verfyParams['trade_status']='TRADE_SUCCESS'
    # verfyParams['trade_no']=params.trade_no
    # verfyParams['sign']= params.sign
    # veryResult=alipay.notify_verify(request.args)
    # if not veryResult:
    #     LOG.error("支付交易出错,无法拿到诊断[diagnoseSeriesNumber%s]"%params.diagnoseSeriesNumber)
    userId = diagnose.patient.userID
    payRecord = AlipayChargeRecord(params.diagnoseSeriesNumber,
                                   params.buyer_email, params.buyer_id,
                                   params.is_success, params.notify_time,
                                   params.notify_type, params.total_fee,
                                   params.trade_no, params.trade_status,
                                   params.out_trade_no)
    AlipayChargeRecord.save(payRecord)
    if params.is_success == 'T' and params.trade_status == 'TRADE_SUCCESS':
        diagnose = Diagnose.getDiagnoseByDiagnoseSeriesNo(
            params.diagnoseSeriesNumber)
        if diagnose:
            diagnoseId = diagnose.id
            alipayLog = AlipayLog(userId, diagnoseId,
                                  constant.AlipayLogAction.PayFilished)
            AlipayLog.save(alipayLog)
            diagnose.status = constant.DiagnoseStatus.NeedTriage
            Diagnose.save(diagnose)
            result = rs.ResultStatus(rs.SUCCESS.status, '支付成功')
            return json.dumps(result.__dict__, ensure_ascii=False)
        else:
            # alipayLog=AlipayLog(userId,params.diagnoseSeriesNumber,constant.AlipayLogAction.PayFilished)
            # AlipayLog.save(alipayLog)
            LOG.error("支付成功,但系统诊断已经取消(诊断序列号:%s)", params.diagnoseSeriesNumber)
            result = rs.ResultStatus(rs.SUCCESS.status, '支付成功,但系统诊断已经取消')
            return json.dumps(result.__dict__, ensure_ascii=False)
    # alipayLog=AlipayLog(userId,params.diagnoseSeriesNumber,constant.AlipayLogAction.PayFailure)
    # AlipayLog.save(alipayLog)
    LOG.error("支付失败(诊断序列号:%s)", params.diagnoseSeriesNumber)
    result = rs.ResultStatus(rs.FAILURE.status, '支付失败')
    return json.dumps(result.__dict__, ensure_ascii=False)
Exemple #3
0
def AlipayCallbackUrl():

    params=AlipayCallBackInfo(request.args)
    if params.diagnoseSeriesNumber is None:
        LOG.error("支付回调出错,无法拿到diagnoseSeriesNumber")
        return redirect(ERROR_URL)
    if (not params.trade_no) or (not params.out_trade_no) or (not params.trade_status):
        LOG.error("支付回调出错,tradeNo")
        return redirect(ERROR_URL)

    diagnose=Diagnose.getDiagnoseByDiagnoseSeriesNo(params.diagnoseSeriesNumber)
    if diagnose is None or (not hasattr(diagnose,"patient")) or diagnose.patient.userID is None:
         LOG.error("支付回调出错,无法拿到诊断[diagnoseSeriesNumber%s]"%params.diagnoseSeriesNumber)
    #跳过验证,以后再测试,必须传入notify_id
    # verfyParams={}
    # verfyParams['out_trade_no']=params.out_trade_no
    # verfyParams['trade_status']='TRADE_SUCCESS'
    # verfyParams['trade_no']=params.trade_no
    # verfyParams['sign']= params.sign
    # veryResult=alipay.notify_verify(request.args)
    # if not veryResult:
    #     LOG.error("支付交易出错,无法拿到诊断[diagnoseSeriesNumber%s]"%params.diagnoseSeriesNumber)
    userId= diagnose.patient.userID
    payRecord=AlipayChargeRecord(params.diagnoseSeriesNumber,params.buyer_email,params.buyer_id,params.is_success,params.notify_time,
                       params.notify_type,params.total_fee,params.trade_no,params.trade_status,params.out_trade_no)
    AlipayChargeRecord.save(payRecord)
    if params.is_success=='T' and params.trade_status=='TRADE_SUCCESS':
       diagnose=Diagnose.getDiagnoseByDiagnoseSeriesNo(params.diagnoseSeriesNumber)
       if diagnose:
           diagnoseId=diagnose.id
           alipayLog=AlipayLog(userId,diagnoseId,constant.AlipayLogAction.PayFilished)
           AlipayLog.save(alipayLog)
           diagnose.status=constant.DiagnoseStatus.NeedTriage
           Diagnose.save(diagnose)
           result=rs.ResultStatus(rs.SUCCESS.status,'支付成功')
           return  json.dumps(result.__dict__,ensure_ascii=False)
       else:
           # alipayLog=AlipayLog(userId,params.diagnoseSeriesNumber,constant.AlipayLogAction.PayFilished)
           # AlipayLog.save(alipayLog)
           LOG.error("支付成功,但系统诊断已经取消(诊断序列号:%s)",params.diagnoseSeriesNumber)
           result=rs.ResultStatus(rs.SUCCESS.status,'支付成功,但系统诊断已经取消')
           return  json.dumps(result.__dict__,ensure_ascii=False)
    # alipayLog=AlipayLog(userId,params.diagnoseSeriesNumber,constant.AlipayLogAction.PayFailure)
    # AlipayLog.save(alipayLog)
    LOG.error("支付失败(诊断序列号:%s)",params.diagnoseSeriesNumber)
    result=rs.ResultStatus(rs.FAILURE.status,'支付失败')
    return  json.dumps(result.__dict__,ensure_ascii=False)
Exemple #4
0
def generateAlipayUrl(diagnoseId):
    if session.has_key('userId'):
        userId=session['userId']
    if userId is None:
        return redirect(LOGIN_URL)
    diagnose=Diagnose.getDiagnoseById(diagnoseId)

    if diagnose and hasattr(diagnose,'patient') and string.atoi(userId)!=diagnose.patient.userID:
        result=rs.ResultStatus(rs.FAILURE.status,"诊断不存在或不是用户申请的")
        return  json.dumps(result.__dict__,ensure_ascii=False)

    if diagnose and diagnose.status==constant.DiagnoseStatus.NeedPay and diagnose.ossUploaded==constant.DiagnoseUploaed.Uploaded:
        alipayLog=AlipayLog(userId,diagnoseId,constant.AlipayLogAction.StartApplyAlipay)
        AlipayLog.save(alipayLog)
        description=None
        needPay=None
        if hasattr(diagnose,'pathology') and hasattr(diagnose.pathology,'pathologyPostions'):
            if len(diagnose.pathology.pathologyPostions)>0:
                if diagnose.pathology.diagnoseMethod==constant.DiagnoseMethod.Mri:
                    needPay=diagnose.getPayCount(constant.DiagnoseMethod.Mri,len(diagnose.pathology.pathologyPostions),diagnose.getUserDiscount(diagnose.patientId))
                elif diagnose.pathology.diagnoseMethod==constant.DiagnoseMethod.Ct:
                    needPay=diagnose.getPayCount(constant.DiagnoseMethod.Ct,len(diagnose.pathology.pathologyPostions),diagnose.getUserDiscount(diagnose.patientId))
            else:
                result=rs.ResultStatus(rs.FAILURE.status,"诊断不存在或这状态不对")
                return  json.dumps(result.__dict__,ensure_ascii=False)
        else:
            result=rs.ResultStatus(rs.FAILURE.status,"诊断不存在或这状态不对")
            return  json.dumps(result.__dict__,ensure_ascii=False)

        if hasattr(diagnose,'doctor') and hasattr(diagnose.doctor,'username'):

            description=' 医生(%s)的诊断费用:%f 元'%(diagnose.doctor.username,needPay)
            if hasattr(diagnose.doctor.hospital,'name'):
                description=diagnose.doctor.hospital.name+description
        payUrl=alipay.create_direct_pay_by_user(diagnose.diagnoseSeriesNumber,diagnose.diagnoseSeriesNumber,'咨询费',needPay)
        if payUrl:
            alipayLog=AlipayLog(userId,diagnoseId,constant.AlipayLogAction.GetAlipayUrl)
            alipayLog.description=description
            alipayLog.payUrl=payUrl
            AlipayLog.save(alipayLog)
            result=rs.ResultStatus(rs.SUCCESS.status,rs.SUCCESS.msg,payUrl)
            return  json.dumps(result.__dict__,ensure_ascii=False)
        else:
            alipayLog=AlipayLog(userId,diagnoseId,constant.AlipayLogAction.GetAlipayUrlFailure)
            AlipayLog.save(alipayLog)
            result=rs.ResultStatus(rs.FAILURE.status,constant.AlipayLogAction.GetAlipayUrlFailure)
            return  json.dumps(result.__dict__,ensure_ascii=False)
    result=rs.ResultStatus(rs.FAILURE.status,"诊断不存在或这状态不对")
    return  json.dumps(result.__dict__,ensure_ascii=False)
Exemple #5
0
def generateAlipayUrl(diagnoseId):
    if session.has_key('userId'):
        userId = session['userId']
    if userId is None:
        return redirect(LOGIN_URL)
    diagnose = Diagnose.getDiagnoseById(diagnoseId)

    if diagnose and hasattr(
            diagnose,
            'patient') and string.atoi(userId) != diagnose.patient.userID:
        result = rs.ResultStatus(rs.FAILURE.status, "诊断不存在或不是用户申请的")
        return json.dumps(result.__dict__, ensure_ascii=False)

    if diagnose and diagnose.status == constant.DiagnoseStatus.NeedPay and diagnose.ossUploaded == constant.DiagnoseUploaed.Uploaded:
        alipayLog = AlipayLog(userId, diagnoseId,
                              constant.AlipayLogAction.StartApplyAlipay)
        AlipayLog.save(alipayLog)
        description = None
        needPay = None
        if hasattr(diagnose, 'pathology') and hasattr(diagnose.pathology,
                                                      'pathologyPostions'):
            if len(diagnose.pathology.pathologyPostions) > 0:
                if diagnose.pathology.diagnoseMethod == constant.DiagnoseMethod.Mri:
                    needPay = diagnose.getPayCount(
                        constant.DiagnoseMethod.Mri,
                        len(diagnose.pathology.pathologyPostions),
                        diagnose.getUserDiscount(diagnose.patientId))
                elif diagnose.pathology.diagnoseMethod == constant.DiagnoseMethod.Ct:
                    needPay = diagnose.getPayCount(
                        constant.DiagnoseMethod.Ct,
                        len(diagnose.pathology.pathologyPostions),
                        diagnose.getUserDiscount(diagnose.patientId))
            else:
                result = rs.ResultStatus(rs.FAILURE.status, "诊断不存在或这状态不对")
                return json.dumps(result.__dict__, ensure_ascii=False)
        else:
            result = rs.ResultStatus(rs.FAILURE.status, "诊断不存在或这状态不对")
            return json.dumps(result.__dict__, ensure_ascii=False)

        if hasattr(diagnose, 'doctor') and hasattr(diagnose.doctor,
                                                   'username'):

            description = ' 医生(%s)的诊断费用:%f 元' % (diagnose.doctor.username,
                                                 needPay)
            if hasattr(diagnose.doctor.hospital, 'name'):
                description = diagnose.doctor.hospital.name + description
        payUrl = alipay.create_direct_pay_by_user(
            diagnose.diagnoseSeriesNumber, diagnose.diagnoseSeriesNumber,
            '咨询费', needPay)
        if payUrl:
            alipayLog = AlipayLog(userId, diagnoseId,
                                  constant.AlipayLogAction.GetAlipayUrl)
            alipayLog.description = description
            alipayLog.payUrl = payUrl
            AlipayLog.save(alipayLog)
            result = rs.ResultStatus(rs.SUCCESS.status, rs.SUCCESS.msg, payUrl)
            return json.dumps(result.__dict__, ensure_ascii=False)
        else:
            alipayLog = AlipayLog(userId, diagnoseId,
                                  constant.AlipayLogAction.GetAlipayUrlFailure)
            AlipayLog.save(alipayLog)
            result = rs.ResultStatus(
                rs.FAILURE.status,
                constant.AlipayLogAction.GetAlipayUrlFailure)
            return json.dumps(result.__dict__, ensure_ascii=False)
    result = rs.ResultStatus(rs.FAILURE.status, "诊断不存在或这状态不对")
    return json.dumps(result.__dict__, ensure_ascii=False)
Exemple #6
0
def generateAliPay(userId, diagnoseId, diagnose=None):

    if diagnoseId:
        diagnose = Diagnose.getDiagnoseById(diagnoseId)
    else:
        diagnose = Diagnose.getDiagnoseById(diagnose.id)

    if diagnoseId is None and diagnose:
        diagnoseId = diagnose.id
    if userId is None:
        LOG.warn("诊断生成阿里支付地址出错,用户未登录")

    if isinstance(userId, basestring):
        userId = string.atoi(userId)
    if diagnose is None:
        LOG.error("诊断[diagnoseId=%d]生成阿里支付地址出错,诊断在系统中不存在" % diagnoseId)

    if diagnose and diagnose.uploadUserId != userId:
        if hasattr(diagnose, 'patient') and userId != diagnose.patient.userID:
            LOG.error("诊断[diagnoseId=%d][userId=%d]生成阿里支付地址出错,用户没有权限" %
                      (diagnoseId, userId))

    if diagnose and diagnose.status == constant.DiagnoseStatus.NeedPay and diagnose.ossUploaded == constant.DiagnoseUploaed.Uploaded:
        alipayLog = AlipayLog(userId, diagnoseId,
                              constant.AlipayLogAction.StartApplyAlipay)
        AlipayLog.save(alipayLog)
        description = None
        needPay = None
        if hasattr(diagnose, 'pathology') and hasattr(diagnose.pathology,
                                                      'pathologyPostions'):
            if len(diagnose.pathology.pathologyPostions) > 0:
                if diagnose.pathology.diagnoseMethod == constant.DiagnoseMethod.Mri:
                    needPay = diagnose.getPayCount(
                        constant.DiagnoseMethod.Mri,
                        len(diagnose.pathology.pathologyPostions),
                        diagnose.getUserDiscount(diagnose.patientId))
                elif diagnose.pathology.diagnoseMethod == constant.DiagnoseMethod.Ct:
                    needPay = diagnose.getPayCount(
                        constant.DiagnoseMethod.Ct,
                        len(diagnose.pathology.pathologyPostions),
                        diagnose.getUserDiscount(diagnose.patientId))
            else:
                result = rs.ResultStatus(rs.FAILURE.status, "诊断不存在或这状态不对")
                return json.dumps(result.__dict__, ensure_ascii=False)
        else:
            result = rs.ResultStatus(rs.FAILURE.status, "诊断不存在或这状态不对")
            return json.dumps(result.__dict__, ensure_ascii=False)

        if hasattr(diagnose, 'doctor') and hasattr(diagnose.doctor,
                                                   'username'):

            description = ' 医生(%s)的诊断费用:%f 元' % (diagnose.doctor.username,
                                                 needPay)
            if hasattr(diagnose.doctor.hospital, 'name'):
                description = diagnose.doctor.hospital.name + description
        payUrl = alipay.create_direct_pay_by_user(
            diagnose.diagnoseSeriesNumber, diagnose.diagnoseSeriesNumber,
            '咨询费', needPay)
        if payUrl:
            alipayLog = AlipayLog(userId, diagnoseId,
                                  constant.AlipayLogAction.GetAlipayUrl)
            alipayLog.description = description
            alipayLog.payUrl = payUrl
            AlipayLog.save(alipayLog)

            updateDiagnose(diagnose.id, payUrl)
            LOG.info("诊断[diagnoseId=%d][userId=%d]生成阿里支付地址成功" %
                     (diagnoseId, userId))
            return payUrl
        else:
            alipayLog = AlipayLog(userId, diagnoseId,
                                  constant.AlipayLogAction.GetAlipayUrlFailure)
            AlipayLog.save(alipayLog)

            LOG.error("诊断[diagnoseId=%d][userId=%d]生成阿里支付地址出错,去阿里获取的payurl为空" %
                      (diagnoseId, userId))
    LOG.error("诊断[diagnoseId=%d][userId=%d]生成阿里支付地址出错,其他未知原因" %
              (diagnoseId, userId))