# -*- coding:utf-8 -*-

"""
Author: 陈江
Email: chenjiang@huohua.cn
Create Date: 2022/03/03 11:25 下午
"""
from base_framework.public_tools import log
from base_framework.public_tools.sqlhelper import MySqLHelper

obj_log = log.get_logger()
obj_my_sql_helper = MySqLHelper()

class AssetCommon:
    def __init__(self):
        pass

    def get_course_package_info_by_name(self, course_package_name):
        """
            功能：根据套餐名称获取套餐基本信息
            | 输入参数: | course_package_name      string | 套餐名称  |
        """
        sql = "SELECT id,code,name,price FROM `peppa`.`course_package` WHERE `name`='{}';".format(course_package_name)
        return obj_my_sql_helper.select_one(sql)

    def get_order_info_V2(self, **where_condition):
        # user_id = None, course_package_id = None, course_id = None, business_line_type = None, order_id = None, order_code = None
        ocp = ['user_id', 'business_line_type', 'order_id', 'order_code', 'status']
        sprl = ['course_package_id', 'course_id']
        where_str = None
        for k in where_condition.keys():
            t = ''
            if k in sprl:
                t = 'sprl'
            else:
                t = 'ocp'

            if not where_str:
                where_str = '{}.{}=\'{}\''.format(t, k, where_condition.get(k))
            else:
                where_str = '{} AND {}.{}=\'{}\''.format(where_str, t, k, where_condition.get(k))
        if not where_str:
            obj_log.error('参数必填')
            return False
        sql = "SELECT ocp.id as order_id,ocp.code,ocp.audit_status,ocp.status as order_status,ocp.user_id,ocp.user_address_id,ocp.business_line_type,sprl.course_package_id,sprl.course_id,sprl.subscribe_id,sprl.valid as subscribe_pre_valid,sprl.id as subscribe_pre_id FROM order_center.order_course_package ocp LEFT JOIN order_center.subscribe_pre_create_log sprl ON ocp.id=sprl.order_id WHERE {} ORDER BY ocp.id DESC LIMIT 1".format(
            where_str.replace('order_id', 'id'))
        obj_log.info(sql)
        return obj_my_sql_helper.select_one(sql)


if __name__ == '__main__':
    user_common_obj = AssetCommon()
    print(user_common_obj.get_order_info(**{'order_id': 1193182, 'business_line_type': '1', 'status': 100}))




