• 新鲜出炉的awk代码


    echo "" | igawk -f main.awk

    # 需求:按照多种充值方式的多种金额类型进行累加统计
    # 充值方式:移动卡 10,30,50,100元,联通卡20,30,50,100 电信卡 20,30,50,100,300 
    #           wap快充 2,3,5,10 移动短充,2,3,5,10
    # 设计:SQL语句取得表虽然不一致,但是我保证所有的记录集都包含2个字段,单元是元
    #      (固定金额的)累加值,固定金额
    #       除了支付宝的其他数据表都没有记录泡豆数,但是金额可以推算出泡豆比例
    #      目前有两种,一种1比10 ,一种1比8, 换算是通过savePayList函数完成(gold * paodouRate)
    
    @include lib/db.awk
    @include lib/makesql.awk
    
    # 创建进行统计的价格列表
    function makePriceList(s, arr, __ARGVEND__,tempArr)
    {
            split(s,tempArr,",")
            for(i in tempArr)
            {
                    arr[tempArr[i]]
            }
    }
    
    # 从记录集里提取价格
    function parseResultSet(resultSet,payList,__ARGVEND__,i,tempArr)
    {
            for(i in resultSet)
            {
                    split(i,tempArr," ")
                    total = tempArr[1]
                    price = tempArr[2]
                    payList[price] = total
            }
    }
    
    # 保存单条支付信息
    function savePayInfo(item,price,gold,paodou, __ARGVEND__, setData)
    {
            setData["item"]      = item
            setData["price"]     = price
            setData["gold"]      = gold
            setData["paodou"]    = paodou
            setData["stat_date"] = STAT_DATE
    
            makeInsertSQL(TABLE_NAME,setData,SCRIPT)
    }
    
    # 创建一个支付方式全部价格的支付信息
    function savePayList(priceList, payList, item, paodouRate, __ARGVEND__, setData, i)
    {
            for(i in priceList) # 该统计需求不在乎元素在不在数组里
            {
                    savePayInfo(item, i, int(payList[i]), int(payList[i]) * paodouRate)
            }
    }
    
    # 移动充值
    function chinaMobilePay(__ARGVEND__,sql,priceList,resultSet1, resultSet2, payList1, payList2, payAll, i)
    {
            # 易宝卡充
            sql = "select sum(price),price from pppay_order where moneyType=1 and status=4"
            sql = sql " and from_unixtime(dateline) like '" STAT_DATE "%' group by price;"
            executeResultSet(BANKDB,sql,resultSet1)
            parseResultSet(resultSet1,payList1)
    
            # 神州付卡
            sql = "select floor(sum(payMoney)/100),floor(payMoney/100) from pppay_order_szf where moneyType=1"
            sql = sql " and status=8888 and cardTypeCombine=0 and inserttime like '" STAT_DATE "%' group by payMoney"
            executeResultSet(BANKDB,sql,resultSet2)
            parseResultSet(resultSet2,payList2)
    
            # 合并两种支付方式
            makePriceList("10,30,50,100",priceList)
            for(i in priceList)
            {
                    payAll[i] = payList1[i] + payList2[i]
            }
    
            # 保存记录
            savePayList(priceList, payAll, "china_mobile", 10)
    }
    
    # 联通充值
    function chinaUnicomPay(__ARGVEND__,sql,priceList,resultSet,payList)
    {
            sql = "select floor(sum(payMoney)/100),floor(payMoney/100) from pppay_order_szf where moneyType=1"
            sql = sql " and status=8888 and cardTypeCombine=1 and inserttime like '" STAT_DATE "%' group by payMoney"
    
            executeResultSet(BANKDB,sql,resultSet)
            parseResultSet(resultSet,payList)
            makePriceList("20,30,50,100",priceList)
            savePayList(priceList, payList, "china_union", 10)
    }
    
    # 电信充值
    function chinaTelecomPay(__ARGVEND__,sql,priceList,resultSet,payList)
    {
            sql = "select floor(sum(payMoney)/100),floor(payMoney/100) from pppay_order_szf where moneyType=1"
            sql = sql " and status=8888 and cardTypeCombine=2 and inserttime like ' " STAT_DATE "%' group by payMoney"
    
            executeResultSet(BANKDB,sql,resultSet)
            parseResultSet(resultSet,payList)
            makePriceList("20,30,50,100,300",priceList)
            savePayList(priceList, payList, "china_telecom", 10)
    }
    
    
    # wap快充
    function wapPay(__ARGVEND__, sql, priceList, resultSet, payList, i)
    {
            sql = "select sum(price),price from pppay_order_yxjd where status=8888 and moneyType=1"
            sql = sql " and inserttime like '" STAT_DATE "%' group by price;"
    
            executeResultSet(BANKDB,sql,resultSet)
            parseResultSet(resultSet,payList)
            makePriceList("2,3,5,10",priceList)
            savePayList(priceList, payList, "wap", 8)
    }
    
    # 短信充值 - 移动短充
    function messagePay(__ARGVEND__,sql,priceList,resultSet,payList)
    {
            sql = "select sum(price),price from pppay_order_yxjd_sms where status=8888 "
            sql = sql" and inserttime like '" STAT_DATE "%' group by price;"
    
            executeResultSet(BANKDB,sql,resultSet)
            parseResultSet(resultSet,payList)
            makePriceList("2,3,5,10",priceList)
            savePayList(priceList, payList, "message", 8)
    }
    
    # 支付宝充值
    function zhifubaoPay(__ARGVEND__, sql, record, tempArr, totalPrice, paodou)
    {
            sql = "select sum(payMoney), sum(ppdou_num) from pppay_order_alipay where status=8888"
            sql = sql" and moneyType=1 and inserttime like '" STAT_DATE "%'"
    
            record = executeScalar(BANKDB,sql)
    
            split(record,tempArr," ")
            totalPrice = int(tempArr[1])
            paodou     = int(tempArr[2])
    
            savePayInfo("zhifubao", "-", totalPrice, paodou); 
    }
    
    
    BEGIN{
            DB = "/usr/local/bin/mysql --disable-auto-rehash -C "
            BANKDB = DB " -h 192.111.0.211 -u pp**** -pstat** bank**";
            STAT_DATE = "2013-09-18"
    
            TABLE_NAME = "pay_stat"
            SCRIPT = ""
    }
    
    END{
            chinaMobilePay()
            chinaUnicomPay()
            chinaTelecomPay()
            wapPay()
            messagePay()  
            zhifubaoPay()
    }
  • 相关阅读:
    update jdk安装与配置
    Ubuntu 14.04 FTP服务器--vsftpd的安装和配置
    ubuntu 修改开机分辨率
    win7下通过easyBCD引导安装Ubuntu14.04
    IOS swift2.0 Get HTTP 数据请求
    oracle数据库中文汉字排序
    ORACLE日期函数大全!
    Oralce常用命令
    在linux环境下安装redis
    PHP常用函数大全
  • 原文地址:https://www.cnblogs.com/code-style/p/3328802.html
Copyright © 2020-2023  润新知