diff --git a/app/api/model/FinanceOperation.php b/app/api/model/FinanceOperation.php new file mode 100644 index 0000000..299b856 --- /dev/null +++ b/app/api/model/FinanceOperation.php @@ -0,0 +1,29 @@ +field($fields)->where($where1)->where($where2)->order($order)->limit($limit)->fetchAll(); + } +} \ No newline at end of file diff --git a/app/order/controller/FinanceCheck.php b/app/order/controller/FinanceCheck.php index c2037a7..797c164 100644 --- a/app/order/controller/FinanceCheck.php +++ b/app/order/controller/FinanceCheck.php @@ -5,7 +5,7 @@ * @Author: kangkang * @Date: 2020-10-13 19:52:37 * @LastEditors: kangkang - * @LastEditTime: 2020-10-29 17:42:14 + * @LastEditTime: 2020-10-30 16:26:53 */ /* * @Descripttion: @@ -79,27 +79,20 @@ class FinanceCheck extends Controller $finance_operation_model = new FinanceOperationModel; $finance_data = $finance_model->getOne("date(riqi)='".$data['riqi']."'"); if(!$finance_data){ - die; + $finance_operation_model->add($data); + } else { + $data['finance_id'] = $finance_data['id']; + $finance_buyi = $finance_data[$data['product']] + $data['money']; + $types = ['充值','退款','补差价']; + $finance_update = [ + $data['product']=>$finance_buyi, + 'remark'=>'<'.$finance_data['remark'].$data['product'].'补遗 '.$types[$data['type']-1].$data['money'].'>' + ]; + if($finance_model->updateOne(['id'=>$finance_data['id']],$finance_update)) + $finance_operation_model->add($data); + else + die; } - $data['finance_id'] = $finance_data['id']; - $finance_buyi = 0; - switch($data['type']){ - case 1: - case 3: - $finance_buyi = $finance_data[$data['product']] + $data['money']; - break; - case 2: - $finance_buyi = $finance_data[$data['product']] - $data['money']; - break; - } - $types = ['充值','退款','补差价']; - $finance_update = [ - $data['product']=>$finance_buyi, - 'remark'=>'<'.$finance_data['remark'].$data['product'].'补遗 '.$types[$data['type']-1].$data['money'].'>' - ]; - $finance_model->updateOne(['id'=>$finance_data['id']],$finance_update); - - $finance_operation_model->add($data); \result(); } @@ -113,8 +106,26 @@ class FinanceCheck extends Controller $finance_model = new FinanceOperationModel; $list = $finance_model->getListPage([], '*', 'id desc', "$page,50"); $types = ['充值','退款','补差价']; + $products = [ + 'xingxing' => '星星', + 'xianfeng' => '先锋', + 'jike' => '极客', + 'qiangzi' => '强子', + 'xunlian' => '讯连', + 'tiantian' => '天天', + 'laoying' => '老鹰', + 'jinrui' => '金瑞', + 'wujin' => '无尽', + 'wanmei' => '完美', + 'jinqiao' => '金桥', + 'wuxian' => '无限', + 'shihui' => '实惠', + 'gongxiang' => '共享', + ]; foreach ($list as $k => &$v) { $v['type'] = $types[$v['type']-1]; + $v['product'] = $products[$v['product']]; + $v['riqi'] = date('Y-m-d', strtotime($v['riqi']) - 86400); } $data = [ 'Code' => 10000, diff --git a/script/finance_check_script.php b/script/finance_check_script.php index 2da917b..36e07ed 100644 --- a/script/finance_check_script.php +++ b/script/finance_check_script.php @@ -5,17 +5,19 @@ * @Author: kangkang * @Date: 2020-10-03 18:23:43 * @LastEditors: kangkang - * @LastEditTime: 2020-10-29 12:08:30 + * @LastEditTime: 2020-10-30 15:52:27 */ $is_script = 1; include __DIR__ . '/../index.php'; use app\api\model\Finance as FinanceModel; use app\api\model\ProductOrder as ProductOrderModel; +use app\order\model\FinanceOperation as FinanceOperationModel; use enum\order\ProductOrder as ProductOrderEnum; use enum\product\Product as ProductEnum; $finance = new FinanceModel; +$finance_operation = new FinanceOperationModel; $product_order_model = new ProductOrderModel; $product_order_enum = new ProductOrderEnum; @@ -27,20 +29,26 @@ $where1 = ['UpdateTime' => ['<', $today]]; $where2 = ['UpdateTime' => ['>', $yesterday]]; $yesterday_data = $finance->getNewOne(); +$buyis = $finance_operation->field('product,sum(money) money')->where(['finance_id' => ['IS', NULL]])->group(['product'])->fetchAll(); + +$buyi_data = []; +foreach ($buyis as $buyi) { + $buyi_data[$buyi['product']] = $buyi['money']; +} $fields = " ProductId, PackageName, - sum( + sum( CASE OrderType - WHEN 1 THEN ConnectCount - WHEN 2 THEN ConnectCount + WHEN 1 THEN ConnectCount*AccountCount + WHEN 2 THEN ConnectCount*AccountCount ELSE 0 END) 'NewBuyCount', sum( - CASE OrderType - WHEN 3 THEN ConnectCount - WHEN 4 THEN ConnectCount - ELSE 0 END) 'AgainBuyCount' + CASE OrderType + WHEN 3 THEN ConnectCount*AccountCount + WHEN 4 THEN ConnectCount*AccountCount + ELSE 0 END) 'AgainBuyCount' "; @@ -135,33 +143,35 @@ foreach ($refund_tlx_info as $info) { } } $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); +$list['xingxing'] = $yesterday_data['xingxing'] - no_jike($xingxing) + ($buyi_data['xingxing'] ?? 0); +$list['jike'] = $yesterday_data['jike'] - jike($jike) + ($buyi_data['jike'] ?? 0); +$list['wujin'] = $yesterday_data['wujin'] - no_jike($wujin) + ($buyi_data['wujin'] ?? 0); +$list['wanmei'] = $yesterday_data['wanmei'] - no_jike($wanmei) + ($buyi_data['wanmei'] ?? 0); +$list['jinqiao'] = $yesterday_data['jinqiao'] - no_jike($jinqiao) + ($buyi_data['jinqiao'] ?? 0); +$list['wuxian'] = $yesterday_data['wuxian'] - no_jike($wuxian) + ($buyi_data['wuxian'] ?? 0); +$list['shihui'] = $yesterday_data['shihui'] - no_jike($shihui) + ($buyi_data['shihui'] ?? 0); +$list['gongxiang'] = $yesterday_data['gongxiang'] - no_jike($gongxiang) + ($buyi_data['gongxiang'] ?? 0); -$qiangzi_rule_result = qx_rule($qiangzi, $qiangzi_refund); +$qiangzi_rule_result = qx_rule($qiangzi, $qiangzi_refund, false); $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']; +$list['qiangzi'] = $yesterday_data['qiangzi'] - $qiangzi_rule_result['cost'] + $qiangzi_rule_result['refund'] + ($buyi_data['qiangzi'] ?? 0); +$list['xunlian'] = $yesterday_data['xunlian'] - $xunlian_rule_result['cost'] + $xunlian_rule_result['refund'] + ($buyi_data['xunlian'] ?? 0); $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']; +$list['tiantian'] = $yesterday_data['tiantian'] - $tiantian_rule_result['cost'] + $tiantian_rule_result['refund'] + ($buyi_data['tiantian'] ?? 0); +$list['laoying'] = $yesterday_data['laoying'] - $laoying_rule_result['cost'] + $laoying_rule_result['refund'] + ($buyi_data['laoying'] ?? 0); $xianfeng_rule_result = xianfeng($xianfeng, $xianfeng_refund); -$list['xianfeng'] = $yesterday_data['xianfeng'] - $xianfeng_rule_result['cost'] + $xianfeng_rule_result['refund']; +$list['xianfeng'] = $yesterday_data['xianfeng'] - $xianfeng_rule_result['cost'] + $xianfeng_rule_result['refund'] + ($buyi_data['xianfeng'] ?? 0); -$jinrui_rule_result = xianfeng($jinrui, $jinrui_refund); -$list['jinrui'] = $yesterday_data['jinrui'] - $jinrui_rule_result['cost'] + $xianfeng_rule_result['refund']; +$jinrui_rule_result = jinrui($jinrui, $jinrui_refund); +$list['jinrui'] = $yesterday_data['jinrui'] - $jinrui_rule_result['cost'] + $xianfeng_rule_result['refund'] + ($buyi_data['jinrui'] ?? 0); $list['riqi'] = date('Y-m-d H:i:s'); -dump($finance->add($list)); + +$finance->add($list); +$finance_operation->where('finance_id IS NULL')->update(['finance_id' => ($yesterday_data['id'] + 1)]); //极客每日消费规则 function jike($product) @@ -216,13 +226,14 @@ function no_jike($product) } //强子,讯连规则 -function qx_rule($product, $refunds) +function qx_rule($product, $refunds, $product_type = true) { + $tian = $product_type ? 10 : 12; $cost = 0; foreach ($product as $package) { switch ($package['PackageName']) { case '天卡': - $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 10; + $cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * $tian; break; case '周卡': @@ -247,19 +258,29 @@ function qx_rule($product, $refunds) foreach ($refunds as $info) { switch ($info['PackageName']) { case '天卡': - $refund += handle_time($info['RefundRestTime']) / 86400 * 10; + if ((86400 - handle_time($info['RefundRestTime'])) < 7200) { + $refund += $tian; + } break; case '周卡': - $refund += handle_time($info['RefundRestTime']) / 86400 * (60 / 7); + if ((86400 - handle_time($info['RefundRestTime'])) < 7200) { + $refund += 60; + } break; case '月卡': - $refund += handle_time($info['RefundRestTime']) / 86400 * (200 / 30); + if ((86400 - handle_time($info['RefundRestTime'])) < 7200) { + $refund += 200; + } break; case '季卡': - $refund += handle_time($info['RefundRestTime']) / 86400 * (600 / 90); + if ((86400 - handle_time($info['RefundRestTime'])) < 7200) { + $refund += 600; + } break; case '年卡': - $refund += handle_time($info['RefundRestTime']) / 86400 * (2400 / 365); + if ((86400 - handle_time($info['RefundRestTime'])) < 7200) { + $refund += 2400; + } break; } } @@ -432,7 +453,7 @@ function jinrui($product, $refunds) } $refund = 0; foreach ($refunds as $info) { - $refund += handle_time($info['RefundRestTime'])/86400*2*$info['ConnectCount']; + $refund += handle_time($info['RefundRestTime']) / 86400 * 2 * $info['ConnectCount']; } $count['cost'] = $cost; $count['refund'] = $refund;