from datetime import time

import pytest
import time
from ids_list import get_ids
import path_setting
from in_common.base_request import BaseRequest
from all_backend_api.settlement_request import settlement_request
from all_backend_api.pay_request import pay_request

class TestOrderProcess:
    data = BaseRequest().api_load(path_setting.ORDER_PROCESS_DATA)
    order_process_case, order_process_data = get_ids(data, "order_process")

    @pytest.mark.parametrize("param",order_process_data,ids=order_process_case)
    def test_order_process(self,param):
        preview_v1 = settlement_request().preview_v1(param["current_city_id"],param["service_item_id"],param["number"],param["use_platform_coupon"],param["use_doctor_coupon"],param["use_coupon_grey"],param["is_create_groupbuy"])
        print("preview_v1返回结果",preview_v1)
        actual_pay = preview_v1["data"]["pre_payment_total_price"]
        print("actual_pay返回结果",actual_pay)
        payment_final_price = preview_v1["data"]["payment_final_price"]
        print("payment_final_price返回结果", payment_final_price)
        number = preview_v1["data"]["services"][0]["number"]
        print("number返回结果", number)
        phone= preview_v1["data"]["phone"]
        pay_v1 = settlement_request().pay_v1(actual_pay, payment_final_price, 0,0)
        print("pay_v1返回结果", pay_v1)
        use_point = 0
        is_doctor_see = 0
        is_create_groupbuy = 0
        create_v1 = settlement_request().create_v1(param["service_item_id"], number,use_point,is_doctor_see,is_create_groupbuy,phone)
        print("create_v1结果",create_v1)
        print("当前时间start： ", time.strftime('%Y.%m.%d %H:%M:%S ', time.localtime(time.time())))
        settlememt_id = create_v1["data"]["id"]
        print("当前时间end: ", time.strftime('%Y.%m.%d %H:%M:%S ', time.localtime(time.time())))
        alipay_prepay = pay_request().alipay_prepay(settlememt_id,"v1",0,0)
        jump = pay_request().jump(settlememt_id)
        cancle = settlement_request().delete(settlememt_id,2)
        print("cancle",cancle)
        assert jump["error"] == 0
        assert alipay_prepay["error"] == 0
        assert cancle["message"] == "取消成功"
        # print("0000000000000000",r)


