saas_add.py 5.58 KB
import logging
import pandas as pdas

from djcardrenewal.common.dbase.MysqlHelper import MysqlHelper
from djcardrenewal.common.dbase import DbConect
from djcardrenewal.common.sqlcontent import DjSql
from djcardrenewal.common.sqlcontent import CurMonthYzl
from djcardrenewal.common.string.StringBuilder import StringBuilder

print("sys config " + __name__)
log_name = './log/djcardrenewal/handlemain.log'
log_format = '[%(asctime)s-%(filename)s-%(levelname)s:%(message)s]'
log_level = logging.DEBUG
log_mode = 'a'
logging.basicConfig(filename=log_name, format=log_format, level=log_level, filemode=log_mode)

class HandelMain:

    handleDescription = ''
    handleMonth = ''
    hmonth = ''

    djdb = None
    plusDb = None
    yearArray = ['2020','2021','2022']

    def __init__(self, handle_month):
        logging.info("init construct bean")
        self.handleDescription = "dj renewal match iccid and device location"

        self.handleMonth = handle_month
        self.hmonth = handle_month.replace('-', '')[2:6]

        self.djdb = MysqlHelper(DbConect.DB_shen_release_dj)
        self.plusDb = MysqlHelper(DbConect.DB_shen_release_plus)



    #------1 1.1转化店面数据 ------
    def dealTransformMerchant(self):
        for yearline in self.yearArray:
            selectSql = f'''SELECT COUNT(DISTINCT (CASE WHEN b.`sub_shop_merchant_id` THEN  b.`sub_shop_merchant_id` ELSE b.`merchant_id` END)) AS '数量'
                FROM `dj_car_life_goods_sub_order` a
                INNER JOIN `dj_car_life_goods_order` b ON b.`order_code`=a.`order_code`
                LEFT JOIN `dj_car_life_order_expense_category_calculated` d ON d.sub_order_code=a.sub_order_code
                LEFT JOIN `dj_car_life_goods` e ON e.`id`=a.`goods_id`
                LEFT JOIN `temp_dj_car_life_pricetype` f ON f.`id`=a.`id`
                WHERE DATE_FORMAT(b.`success_date`, '%Y')='{yearline}' AND e.`business_scene_type`=1 AND b.`upgrade_flag`='Y'
                ;'''
            merData = self.plusDb.execute_select(selectSql)
            print("---Plus_1.1转化 %s 商户数:%s"  % (yearline, merData[0][0]))
        return True

    #------1 1.3众筹 ------
    def dealDyEquitMerchant(self):
        for yearline in self.yearArray:
            selectSql = f'''SELECT count(distinct b.`merchant_id`) FROM `shopmall_order` a
                LEFT JOIN `shopmall_activity_info` b ON b.`activity_id`=a.`activity_id` AND a.source=b.source
                WHERE a.`marketing_status`=1 and DATE_FORMAT(a.`created_date`, '%Y')='{yearline}'
            ;'''
            merData = self.plusDb.execute_select(selectSql)
            print("---Plus_1.3众筹 %s 商户数:%s"  % (yearline, merData[0][0]))
        return True

    #------1 合并 ------
    def dealDyXsAndEqMerchant(self):
        for yearline in self.yearArray:
            selectSql = f'''select count(distinct aat.merchantId) from (
                        SELECT DISTINCT (CASE WHEN b.`sub_shop_merchant_id` THEN  b.`sub_shop_merchant_id` ELSE b.`merchant_id` END) as merchantId
                        FROM `dj_car_life_goods_sub_order` a
                        INNER JOIN `dj_car_life_goods_order` b ON b.`order_code`=a.`order_code`
                        LEFT JOIN `dj_car_life_order_expense_category_calculated` d ON d.sub_order_code=a.sub_order_code
                        LEFT JOIN `dj_car_life_goods` e ON e.`id`=a.`goods_id`
                        LEFT JOIN `temp_dj_car_life_pricetype` f ON f.`id`=a.`id`
                        WHERE DATE_FORMAT(b.`success_date`, '%Y')='{yearline}' AND e.`business_scene_type`=1 AND b.`upgrade_flag`='Y'
                        UNION ALL
                        SELECT distinct b.`merchant_id`  as merchantId FROM `shopmall_order` a
                        LEFT JOIN `shopmall_activity_info` b ON b.`activity_id`=a.`activity_id` AND a.source=b.source
                        WHERE a.`marketing_status`=1 and DATE_FORMAT(a.`created_date`, '%Y')='{yearline}'
                    ) aat
                ;'''
            merData = self.plusDb.execute_select(selectSql)
            print("---Plus_合并 %s 商户数:%s"  % (yearline, merData[0][0]))
        return True



    #------2 saasPlus在订阅中开展业务的店面数 ------
    def dealPlusInnerDyMerchant(self):
        return True

    #------2 saasPlus在订阅中开展业务的店面数 ------
    def dealPlusMergeDyMerchant(self):
        return True



    def proxySaasPlusMerchantCount(self):
        # 处理 1.1转化业务
        xsRes = False
        xsRes = handleMain.dealTransformMerchant()
        logging.info(f'===Plus1.1转化:{xsRes}')

        # 处理 1.3众筹业务
        qyRes = False
        qyRes = handleMain.dealDyEquitMerchant()
        logging.info(f'===Plus1.3众筹:{qyRes}')

        # 合并数据
        hbRes = False
        hbRes = handleMain.dealDyXsAndEqMerchant()
        logging.info(f'===Plus合并处理OK:{hbRes}')

    def proxyXXXMerchantCount(self):
        # 处理 xxx
        xsRes = False
        xsRes = handleMain.dealPlusInnerDyMerchant()
        logging.info(f'===xxx:{xsRes}')
        
        # 合并数据
        hbRes = False
        hbRes = handleMain.dealPlusMergeDyMerchant()
        logging.info(f'===xxx合并处理OK:{hbRes}')
        


if __name__ == "__main__":
    handle_month = '2022-12'
    dedRes = False
    diRes = False
    urRes = False

    #启动初始化
    handleMain = HandelMain(handle_month)
    logging.info("start handle" + handleMain.handleDescription + ' the month:' + handleMain.handleMonth)

    # 输出店面数据
    handleMain.proxySaasPlusMerchantCount()

    # 输出XXX店面数据
    # handleMain.proxyXXXMerchantCount()