Example #1
0
    def to_log(notify_data, notify_dict, mer_id, uc):
        print notify_dict
        order_no = notify_dict['orderNumber']
        order_time = notify_dict['orderTime']
        settle_amount = notify_dict['settleAmount']
        order_amount = settle_amount
        trans_type = notify_dict['transType']
        qn = notify_dict['qn']
        # print(order_no, order_time, settle_amount, trans_type, mer_id, qn)

        # 如果商户号不存,则立即返回
        db = Sqlite()
        merchant = db.get_upmp_data_by_merid(mer_id)
        if not merchant:
            return

        if trans_type == UpmpConfig.TRANS_TYPE_TRADE:
            if not merchant['charge_notify']:
                print('=========charge_notify========')
                db.set_upmp_charge_notify_data(mer_id, notify_data)

            if not merchant['charge_query_res']:
                print('=========charge_query========')
                # charge retrieve
                post_data, res_data = uc.charge_retrieve(order_no, order_time)
                db.set_upmp_charge_query_data(mer_id, post_data, res_data)

            if not merchant['void_notify']:
                print('=========void========')
                # void
                post_data, res_data, req_dict, res_dict = uc.void(
                    order_time, order_amount, qn)
                db.set_upmp_void_data(mer_id, post_data, res_data)
            elif not merchant['refund_notify']:
                print('=========refund========')
                # refund
                post_data, res_data, req_dict, res_dict = uc.refund(
                    order_time, qn)
                db.set_upmp_refund_data(mer_id, post_data, res_data)
        elif trans_type == UpmpConfig.TRANS_TYPE_VOID:
            print('=========void_notify========')
            db.set_upmp_void_notify_data(mer_id, notify_data)

            if not merchant['void_query_res']:
                print('=========void_query========')
                # void retrieve
                post_data, res_data = uc.void_retrieve(order_no, order_time)
                db.set_upmp_void_query_data(mer_id, post_data, res_data)
        elif trans_type == UpmpConfig.TRANS_TYPE_REFUND:
            print('=========refund_notify========')
            db.set_upmp_refund_notify_data(mer_id, notify_data)

            if not merchant['refund_query_res']:
                print('=========refund_query========')
                # refund retrieve
                post_data, res_data = uc.refund_retrieve(order_no, order_time)
                db.set_upmp_refund_query_data(mer_id, post_data, res_data)

        if db.is_upmp_data_complete(mer_id):
            print('=========TO EXCEL========')
            from util.excel_handler import ExcelHandler
            eh = ExcelHandler()
            report_file = os.path.join('data/2014', merchant['id'] + '.xlsx')
            merchant = db.get_upmp_data_by_merid(mer_id)
            eh.save('./data/template.xlsx', report_file, merchant)

            print('========SEND MAIL========')
            from util import mail
            attchment_path = os.path.join('data/2014',
                                          merchant['id'] + '.xlsx')
            if os.path.isfile(attchment_path):
                mailto_list = list()
                with open('data/maillist') as f:
                    for line in f:
                        mailto_list.append(line.strip())

                if mail.send_mail(mailto_list, merchant, attchment_path):
                    print "发送成功"
                else:
                    print "发送失败"

            print('=========GIT PUSH========')
            repo = RepoGit(root_path)
            repo.add(os.path.join('2014', '*'))
            repo.commit("Merchant " + merchant['id'] + ' test finished')
            repo.push()

            print('========TEST DONE========')
        else:
            print('========CONTINUE=========')
Example #2
0
    def to_log(notify_data, notify_dict, mer_id, uc):
        print notify_dict
        order_no = notify_dict['orderNumber']
        order_time = notify_dict['orderTime']
        settle_amount = notify_dict['settleAmount']
        order_amount = settle_amount
        trans_type = notify_dict['transType']
        qn = notify_dict['qn']
        # print(order_no, order_time, settle_amount, trans_type, mer_id, qn)

        # 如果商户号不存,则立即返回
        db = Sqlite()
        merchant = db.get_upmp_data_by_merid(mer_id)
        if not merchant:
            return

        if trans_type == UpmpConfig.TRANS_TYPE_TRADE:
            if not merchant['charge_notify']:
                print('=========charge_notify========')
                db.set_upmp_charge_notify_data(mer_id, notify_data)

            if not merchant['charge_query_res']:
                print('=========charge_query========')
                # charge retrieve
                post_data, res_data = uc.charge_retrieve(order_no, order_time)
                db.set_upmp_charge_query_data(mer_id, post_data, res_data)

            if not merchant['void_notify']:
                print('=========void========')
                # void
                post_data, res_data, req_dict, res_dict = uc.void(order_time, order_amount, qn)
                db.set_upmp_void_data(mer_id, post_data, res_data)
            elif not merchant['refund_notify']:
                print('=========refund========')
                # refund
                post_data, res_data, req_dict, res_dict = uc.refund(order_time, qn)
                db.set_upmp_refund_data(mer_id, post_data, res_data)
        elif trans_type == UpmpConfig.TRANS_TYPE_VOID:
            print('=========void_notify========')
            db.set_upmp_void_notify_data(mer_id, notify_data)

            if not merchant['void_query_res']:
                print('=========void_query========')
                # void retrieve
                post_data, res_data = uc.void_retrieve(order_no, order_time)
                db.set_upmp_void_query_data(mer_id, post_data, res_data)
        elif trans_type == UpmpConfig.TRANS_TYPE_REFUND:
            print('=========refund_notify========')
            db.set_upmp_refund_notify_data(mer_id, notify_data)

            if not merchant['refund_query_res']:
                print('=========refund_query========')
                # refund retrieve
                post_data, res_data = uc.refund_retrieve(order_no, order_time)
                db.set_upmp_refund_query_data(mer_id, post_data, res_data)

        if db.is_upmp_data_complete(mer_id):
            print('=========TO EXCEL========')
            from util.excel_handler import ExcelHandler
            eh = ExcelHandler()
            report_file = os.path.join('data/2014', merchant['id'] + '.xlsx')
            merchant = db.get_upmp_data_by_merid(mer_id)
            eh.save('./data/template.xlsx', report_file, merchant)

            print('========SEND MAIL========')
            from util import mail
            attchment_path = os.path.join('data/2014', merchant['id'] + '.xlsx')
            if os.path.isfile(attchment_path):
                mailto_list = list()
                with open('data/maillist') as f:
                    for line in f:
                        mailto_list.append(line.strip())

                if mail.send_mail(mailto_list, merchant, attchment_path):
                    print "发送成功"
                else:
                    print "发送失败"

            print('=========GIT PUSH========')
            repo = RepoGit(root_path)
            repo.add(os.path.join('2014', '*'))
            repo.commit("Merchant " + merchant['id'] + ' test finished')
            repo.push()

            print('========TEST DONE========')
        else:
            print('========CONTINUE=========')