From c7f9c073d964b42ad9f4ae1b007ffcde493998a6 Mon Sep 17 00:00:00 2001 From: wanyongkang <937888580@qq.com> Date: Thu, 29 Oct 2020 10:49:51 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8E=9F=E5=90=8E=E5=8F=B0=E8=B4=A2?= =?UTF-8?q?=E5=8A=A1=E6=98=8E=E7=BB=86=E5=8A=9F=E8=83=BD=E3=80=91=20https:?= =?UTF-8?q?//www.tapd.cn/39598945/prong/stories/view/1139598945001000049?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/model/Finance.php | 19 ++ enum/order/ProductOrder.php | 4 +- enum/product/Product.php | 56 +++++ script/finance_check_script.php | 406 ++++++++++++++++++++++++++++++++ 4 files changed, 484 insertions(+), 1 deletion(-) create mode 100644 app/api/model/Finance.php create mode 100644 enum/product/Product.php create mode 100644 script/finance_check_script.php diff --git a/app/api/model/Finance.php b/app/api/model/Finance.php new file mode 100644 index 0000000..1dc3536 --- /dev/null +++ b/app/api/model/Finance.php @@ -0,0 +1,19 @@ +产品名,每个产品的id不可变动 + public static $ScoreName = [ + 1 => '强子PPTP', + 2 => '讯连pptp', + 3 => '金桥-仅电脑', + 4 => '金瑞pptp', + 5 => '老鹰pptp', + 6 => '先锋pptp', + 7 => '无尽-仅电脑', + 8 => '星星pptp', + 9 => '完美-仅电脑', + 10 => '无限-单窗口单ip', + 11 => '先锋SSTP专用', + 12 => '老鹰测试', + 13 => '极客pptp', + 14 => '天天pptp', + 15 => '共享IP', + 16 => '实惠IP', + ]; + + public static $qiangzi = 1; + public static $xunlian = 2; + public static $jinqiao = 3; + public static $jinrui = 4; + public static $laoying = 5; + public static $xianfengpptp = 6; + public static $wujin = 7; + public static $xingxing = 8; + public static $wanmei = 9; + public static $wuxian = 10; + public static $xianfengsstp = 11; + public static $laoyingtest = 12; + public static $jike = 13; + public static $tiantian = 14; + public static $gongxiang = 15; + public static $shihui = 16; + + //强子、讯连 + public static $qx = [1,2]; + + //天天老鹰先锋 + public static $tlx = [5,6,14]; +} diff --git a/script/finance_check_script.php b/script/finance_check_script.php new file mode 100644 index 0000000..958fbb0 --- /dev/null +++ b/script/finance_check_script.php @@ -0,0 +1,406 @@ + ['<', $today]]; +$where2 = ['UpdateTime' => ['>', $yesterday]]; + +$yesterday_data = $finance->getNewOne(); + +$fields = " +ProductId, PackageName, + sum( + CASE OrderType + WHEN 1 THEN ConnectCount + WHEN 2 THEN ConnectCount + ELSE 0 END) 'NewBuyCount', + + sum( + CASE OrderType + WHEN 3 THEN ConnectCount + WHEN 4 THEN ConnectCount + ELSE 0 END) 'AgainBuyCount', + +"; + +$data = $product_order_model->field($fields)->where(array_merge($where2, ['OrderState' => ['in', $product_order_enum::$PayComplete]]))->where($where1)->group(['ProductId', 'PackageName'])->fetchAll(); + +$qiangzi = $xunlian = $jinqiao = $jinrui = $laoying = $xianfeng = $wujin = $xingxing = $wanmei = $wuxian = $jike = $tiantian = $gongxiang = $shihui = []; + +foreach ($data as $product) { + switch ($product['ProductId']) { + case $product_enum::$qiangzi: + $qiangzi[] = $product; + break; + case $product_enum::$xunlian: + $xunlian[] = $product; + break; + case $product_enum::$jinqiao: + $jinqiao[] = $product; + break; + case $product_enum::$jinrui: + $jinrui[] = $product; + break; + case $product_enum::$laoying: + $laoying[] = $product; + break; + case $product_enum::$xianfengpptp: + $xianfeng[] = $product; + break; + case $product_enum::$wujin: + $wujin[] = $product; + break; + case $product_enum::$xingxing: + $xingxing[] = $product; + break; + case $product_enum::$wanmei: + $wanmei[] = $product; + break; + case $product_enum::$wuxian: + $wuxian[] = $product; + break; + case $product_enum::$jike: + $jike[] = $product; + break; + case $product_enum::$tiantian: + $tiantian[] = $product; + break; + case $product_enum::$gongxiang: + $gongxiang[] = $product; + break; + case $product_enum::$shihui: + $shihui[] = $product; + break; + } +} + +//强子讯连专门处理退款 +$qx_where = array_merge($where2, ['ProductId' => ['in', $product_enum::$qx], 'OrderState' => ['in', $product_order_enum::$Refunds], 'ConnectCount' => 1, 'OrderType' => $product_order_enum::$New]); +$refund_qx_info = $product_order_model->field('ProductId,PackageName,RefundRestTime')->where($qx_where)->where($where1)->fetchAll(); +$qiangzi_refund = []; +$xunlian_refund = []; +foreach ($refund_qx_info as $info) { + switch ($info['ProductId']) { + case $product_enum::$qiangzi: + $qiangzi_refund[] = $info; + break; + case $product_enum::$xunlian: + $xunlian_refund[] = $info; + break; + } +} +//天天老鹰先锋的退款 +$tlx_where = array_merge($where2, ['ProductId' => ['in', $product_enum::$tlx], 'OrderState' => ['in', $product_order_enum::$Refunds]]); +$refund_tlx_info = $product_order_model->field('ProductId,PackageName,RefundRestTime,ConnectCount')->where($qx_where)->where($where1)->fetchAll(); +$tiantian_refund = []; +$laoying_refund = []; +$xianfeng_refund = []; +foreach ($refund_tlx_info as $info) { + switch ($info['ProductId']) { + case $product_enum::$tiantian: + $tiantian_refund[] = $info; + break; + case $product_enum::$laoying: + $laoying_refund[] = $info; + break; + case $product_enum::$xianfengpptp: + $xianfeng_refund[] = $info; + break; + } +} + +$list = []; +$list['xingxing'] = $yesterday_data['xingxing']-no_jike($xingxing); +$list['jike'] = $yesterday_data['jike']-jike($jike); +$list['wujin'] = $yesterday_data['wujin']-no_jike($wujin); +$list['wanmei'] = $yesterday_data['wanmei']-no_jike($wanmei); +$list['jinqiao'] = $yesterday_data['jinqiao']-no_jike($jinqiao); +$list['wuxian'] = $yesterday_data['wuxian']-no_jike($wuxian); +$list['shihui'] = $yesterday_data['shihui']-no_jike($shihui); +$list['gongxiang'] = $yesterday_data['gongxiang']-no_jike($gongxiang); + +$qiangzi_rule_result = qx_rule($qiangzi,$qiangzi_refund); +$xunlian_rule_result = qx_rule($xunlian,$xunlian_refund); +$list['qiangzi'] = $yesterday_data['qiangzi']-$qiangzi_rule_result['cost']+$qiangzi_rule_result['refund']; +$list['xunlian'] = $yesterday_data['xunlian']-$xunlian_rule_result['cost']+$xunlian_rule_result['refund']; + +$tiantian_rule_result = tl_rule($tiantian,$tiantian_refund); +$laoying_rule_result = tl_rule($laoying,$laoying_refund); +$list['tiantian'] = $yesterday_data['tiantian']-$tiantian_rule_result['cost']+$tiantian_rule_result['refund']; +$list['laoying'] = $yesterday_data['laoying']-$laoying_rule_result['cost']+$laoying_rule_result['refund']; + +$xianfeng_rule_result = xianfeng($xianfeng,$xianfeng_refund); +$list['xianfeng'] = $yesterday_data['xianfeng']-$xianfeng_rule_result['cost']+$xianfeng_rule_result['refund']; + +dump($list); + + +//极客每日消费规则 +function jike($product) +{ + $count = 0; + foreach ($product as $package) { + switch ($package['PackageName']) { + case '天卡': + $count += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 5; + break; + case '周卡': + $count += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 20; + break; + case '月卡': + $count += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 50; + break; + case '季卡': + $count += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 150; + break; + case '年卡': + $count += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 600; + break; + } + } + return $count; +} + +//星星,无尽,完美,金桥,无限,实惠,共享通用规则 +function no_jike($product) +{ + $count = 0; + foreach ($product as $package) { + switch ($package['PackageName']) { + case '天卡': + $count += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 4; + break; + case '周卡': + $count += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 28; + break; + case '月卡': + $count += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 100; + break; + case '季卡': + $count += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 300; + break; + case '年卡': + $count += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 1200; + break; + } + } + return $count; +} + +//强子,讯连规则 +function qx_rule($product, $refunds) +{ + $cost = 0; + foreach ($product as $package) { + switch ($package['PackageName']) { + case '天卡': + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 10; + + break; + case '周卡': + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 60; + + break; + case '月卡': + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 200; + + break; + case '季卡': + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 600; + + break; + case '年卡': + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 2400; + + break; + } + } + $refund = 0; + foreach ($refunds as $info) { + switch ($info['PackageName']) { + case '天卡': + $refund += handle_time($info['RefundRestTime'])/86400 * 10; + break; + case '周卡': + $refund += handle_time($info['RefundRestTime'])/86400 * (60 / 7); + break; + case '月卡': + $refund += handle_time($info['RefundRestTime'])/86400 * (200 / 30); + break; + case '季卡': + $refund += handle_time($info['RefundRestTime'])/86400 * (600 / 90); + break; + case '年卡': + $refund += handle_time($info['RefundRestTime'])/86400 * (2400 / 365); + break; + } + } + $count['cost'] = $cost; + $count['refund'] = $refund; + return $count; +} +//天天,老鹰退款规则 +function tl_rule($product, $refunds) +{ + $cost = 0; + foreach ($product as $package) { + switch ($package['PackageName']) { + case '天卡': + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 4; + + break; + case '周卡': + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 20; + + break; + case '月卡': + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 60; + + break; + case '季卡': + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 180; + + break; + case '年卡': + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 720; + + break; + } + } + $refund = 0; + foreach ($refunds as $info) { + switch ($info['PackageName']) { + case '天卡': + if ((86400-handle_time( $info['RefundRestTime'])) <1800) { + $refund += $info['ConnectCount'] * 4; + } else { + $refund += $info['ConnectCount'] * 4 - (86400-handle_time( $info['RefundRestTime'])) * $info['ConnectCount'] * 4; + } + break; + case '周卡': + if ((86400*7-handle_time( $info['RefundRestTime'])) <1800) { + $refund += $info['ConnectCount'] * 20; + } else { + $refund += $info['ConnectCount'] * 20 -(86400*7-handle_time( $info['RefundRestTime'])) * $info['ConnectCount'] * 4; + } + break; + case '月卡': + if ((86400*30-handle_time( $info['RefundRestTime'])) <1800) { + $refund += $info['ConnectCount'] * 60; + } else { + $refund += $info['ConnectCount'] * 60 -(86400*30-handle_time( $info['RefundRestTime'])) * $info['ConnectCount'] * 4; + } + break; + case '季卡': + if ((86400*90-handle_time( $info['RefundRestTime'])) <1800) { + $refund += $info['ConnectCount'] * 180; + } else { + $refund += $info['ConnectCount'] * 180 -(86400*90-handle_time( $info['RefundRestTime'])) * $info['ConnectCount'] * 4; + } + break; + case '年卡': + if ((86400*365-handle_time( $info['RefundRestTime'])) <1800) { + $refund += $info['ConnectCount'] * 7200; + } else { + $refund += $info['ConnectCount'] * 720 -(86400*365-handle_time( $info['RefundRestTime'])) * $info['ConnectCount'] * 4; + } + break; + } + } + $count['cost'] = $cost; + $count['refund'] = $refund; + return $count; +} +//先锋规则 +function xianfeng($product,$refunds) +{ + $cost = 0; + foreach ($product as $package) { + switch ($package['PackageName']) { + case '天卡': + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 3; + + break; + case '周卡': + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 18; + + break; + case '月卡': + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 60; + + break; + case '季卡': + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 168; + + break; + case '年卡': + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 636; + + break; + } + } + $refund = 0; + foreach ($refunds as $info) { + switch ($info['PackageName']) { + case '天卡': + if ((86400-handle_time( $info['RefundRestTime'])) <10800) { + $refund += $info['ConnectCount'] * 3; + } + break; + case '周卡': + if ((86400*7-handle_time( $info['RefundRestTime'])) <10800) { + $refund += $info['ConnectCount'] * 18; + } + break; + case '月卡': + if ((86400*30-handle_time( $info['RefundRestTime'])) <10800) { + $refund += $info['ConnectCount'] * 60; + } + break; + case '季卡': + if ((86400*90-handle_time( $info['RefundRestTime'])) <10800) { + $refund += $info['ConnectCount'] * 168; + } + break; + case '年卡': + if ((86400*365-handle_time( $info['RefundRestTime'])) <10800) { + $refund += $info['ConnectCount'] * 636; + } + break; + } + } + $count['cost'] = $cost; + $count['refund'] = $refund; + return $count; +} + +//将剩余时间进行处理切割转换为秒 +function handle_time($rest_time) +{ + $time1 = explode('天', $rest_time); + $time2 = explode('时', $time1[1]); + $time3 = explode('分', $time2[1]); + $time = $time1[0] * 86400 + $time2[0] * 3600 + $time3 * 60; + return $time; +}