元后台
This commit is contained in:
29
app/api/model/FinanceOperation.php
Normal file
29
app/api/model/FinanceOperation.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* @Descripttion:
|
||||||
|
* @version:
|
||||||
|
* @Author: kangkang
|
||||||
|
* @Date: 2020-10-22 16:13:41
|
||||||
|
* @LastEditors: kangkang
|
||||||
|
* @LastEditTime: 2020-10-30 14:44:17
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace app\api\model;
|
||||||
|
|
||||||
|
use fastphp\base\Model;
|
||||||
|
|
||||||
|
class FinanceOperation extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'finance_op';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 单独写
|
||||||
|
* @param {*}
|
||||||
|
* @return {*}
|
||||||
|
*/
|
||||||
|
public function getListSearch($where1, $where2, $fields = '*', $order = 'id desc', $limit = '50')
|
||||||
|
{
|
||||||
|
return $this->field($fields)->where($where1)->where($where2)->order($order)->limit($limit)->fetchAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
* @Author: kangkang
|
* @Author: kangkang
|
||||||
* @Date: 2020-10-13 19:52:37
|
* @Date: 2020-10-13 19:52:37
|
||||||
* @LastEditors: kangkang
|
* @LastEditors: kangkang
|
||||||
* @LastEditTime: 2020-10-29 17:42:14
|
* @LastEditTime: 2020-10-30 16:26:53
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* @Descripttion:
|
* @Descripttion:
|
||||||
@@ -79,27 +79,20 @@ class FinanceCheck extends Controller
|
|||||||
$finance_operation_model = new FinanceOperationModel;
|
$finance_operation_model = new FinanceOperationModel;
|
||||||
$finance_data = $finance_model->getOne("date(riqi)='".$data['riqi']."'");
|
$finance_data = $finance_model->getOne("date(riqi)='".$data['riqi']."'");
|
||||||
if(!$finance_data){
|
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();
|
\result();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,8 +106,26 @@ class FinanceCheck extends Controller
|
|||||||
$finance_model = new FinanceOperationModel;
|
$finance_model = new FinanceOperationModel;
|
||||||
$list = $finance_model->getListPage([], '*', 'id desc', "$page,50");
|
$list = $finance_model->getListPage([], '*', 'id desc', "$page,50");
|
||||||
$types = ['充值','退款','补差价'];
|
$types = ['充值','退款','补差价'];
|
||||||
|
$products = [
|
||||||
|
'xingxing' => '星星',
|
||||||
|
'xianfeng' => '先锋',
|
||||||
|
'jike' => '极客',
|
||||||
|
'qiangzi' => '强子',
|
||||||
|
'xunlian' => '讯连',
|
||||||
|
'tiantian' => '天天',
|
||||||
|
'laoying' => '老鹰',
|
||||||
|
'jinrui' => '金瑞',
|
||||||
|
'wujin' => '无尽',
|
||||||
|
'wanmei' => '完美',
|
||||||
|
'jinqiao' => '金桥',
|
||||||
|
'wuxian' => '无限',
|
||||||
|
'shihui' => '实惠',
|
||||||
|
'gongxiang' => '共享',
|
||||||
|
];
|
||||||
foreach ($list as $k => &$v) {
|
foreach ($list as $k => &$v) {
|
||||||
$v['type'] = $types[$v['type']-1];
|
$v['type'] = $types[$v['type']-1];
|
||||||
|
$v['product'] = $products[$v['product']];
|
||||||
|
$v['riqi'] = date('Y-m-d', strtotime($v['riqi']) - 86400);
|
||||||
}
|
}
|
||||||
$data = [
|
$data = [
|
||||||
'Code' => 10000,
|
'Code' => 10000,
|
||||||
|
|||||||
@@ -5,17 +5,19 @@
|
|||||||
* @Author: kangkang
|
* @Author: kangkang
|
||||||
* @Date: 2020-10-03 18:23:43
|
* @Date: 2020-10-03 18:23:43
|
||||||
* @LastEditors: kangkang
|
* @LastEditors: kangkang
|
||||||
* @LastEditTime: 2020-10-29 12:08:30
|
* @LastEditTime: 2020-10-30 15:52:27
|
||||||
*/
|
*/
|
||||||
$is_script = 1;
|
$is_script = 1;
|
||||||
include __DIR__ . '/../index.php';
|
include __DIR__ . '/../index.php';
|
||||||
|
|
||||||
use app\api\model\Finance as FinanceModel;
|
use app\api\model\Finance as FinanceModel;
|
||||||
use app\api\model\ProductOrder as ProductOrderModel;
|
use app\api\model\ProductOrder as ProductOrderModel;
|
||||||
|
use app\order\model\FinanceOperation as FinanceOperationModel;
|
||||||
use enum\order\ProductOrder as ProductOrderEnum;
|
use enum\order\ProductOrder as ProductOrderEnum;
|
||||||
use enum\product\Product as ProductEnum;
|
use enum\product\Product as ProductEnum;
|
||||||
|
|
||||||
$finance = new FinanceModel;
|
$finance = new FinanceModel;
|
||||||
|
$finance_operation = new FinanceOperationModel;
|
||||||
|
|
||||||
$product_order_model = new ProductOrderModel;
|
$product_order_model = new ProductOrderModel;
|
||||||
$product_order_enum = new ProductOrderEnum;
|
$product_order_enum = new ProductOrderEnum;
|
||||||
@@ -27,20 +29,26 @@ $where1 = ['UpdateTime' => ['<', $today]];
|
|||||||
$where2 = ['UpdateTime' => ['>', $yesterday]];
|
$where2 = ['UpdateTime' => ['>', $yesterday]];
|
||||||
|
|
||||||
$yesterday_data = $finance->getNewOne();
|
$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 = "
|
$fields = "
|
||||||
ProductId, PackageName,
|
ProductId, PackageName,
|
||||||
sum(
|
sum(
|
||||||
CASE OrderType
|
CASE OrderType
|
||||||
WHEN 1 THEN ConnectCount
|
WHEN 1 THEN ConnectCount*AccountCount
|
||||||
WHEN 2 THEN ConnectCount
|
WHEN 2 THEN ConnectCount*AccountCount
|
||||||
ELSE 0 END) 'NewBuyCount',
|
ELSE 0 END) 'NewBuyCount',
|
||||||
|
|
||||||
sum(
|
sum(
|
||||||
CASE OrderType
|
CASE OrderType
|
||||||
WHEN 3 THEN ConnectCount
|
WHEN 3 THEN ConnectCount*AccountCount
|
||||||
WHEN 4 THEN ConnectCount
|
WHEN 4 THEN ConnectCount*AccountCount
|
||||||
ELSE 0 END) 'AgainBuyCount'
|
ELSE 0 END) 'AgainBuyCount'
|
||||||
|
|
||||||
";
|
";
|
||||||
|
|
||||||
@@ -135,33 +143,35 @@ foreach ($refund_tlx_info as $info) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$list = [];
|
$list = [];
|
||||||
$list['xingxing'] = $yesterday_data['xingxing'] - no_jike($xingxing);
|
$list['xingxing'] = $yesterday_data['xingxing'] - no_jike($xingxing) + ($buyi_data['xingxing'] ?? 0);
|
||||||
$list['jike'] = $yesterday_data['jike'] - jike($jike);
|
$list['jike'] = $yesterday_data['jike'] - jike($jike) + ($buyi_data['jike'] ?? 0);
|
||||||
$list['wujin'] = $yesterday_data['wujin'] - no_jike($wujin);
|
$list['wujin'] = $yesterday_data['wujin'] - no_jike($wujin) + ($buyi_data['wujin'] ?? 0);
|
||||||
$list['wanmei'] = $yesterday_data['wanmei'] - no_jike($wanmei);
|
$list['wanmei'] = $yesterday_data['wanmei'] - no_jike($wanmei) + ($buyi_data['wanmei'] ?? 0);
|
||||||
$list['jinqiao'] = $yesterday_data['jinqiao'] - no_jike($jinqiao);
|
$list['jinqiao'] = $yesterday_data['jinqiao'] - no_jike($jinqiao) + ($buyi_data['jinqiao'] ?? 0);
|
||||||
$list['wuxian'] = $yesterday_data['wuxian'] - no_jike($wuxian);
|
$list['wuxian'] = $yesterday_data['wuxian'] - no_jike($wuxian) + ($buyi_data['wuxian'] ?? 0);
|
||||||
$list['shihui'] = $yesterday_data['shihui'] - no_jike($shihui);
|
$list['shihui'] = $yesterday_data['shihui'] - no_jike($shihui) + ($buyi_data['shihui'] ?? 0);
|
||||||
$list['gongxiang'] = $yesterday_data['gongxiang'] - no_jike($gongxiang);
|
$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);
|
$xunlian_rule_result = qx_rule($xunlian, $xunlian_refund);
|
||||||
$list['qiangzi'] = $yesterday_data['qiangzi'] - $qiangzi_rule_result['cost'] + $qiangzi_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'];
|
$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);
|
$tiantian_rule_result = tl_rule($tiantian, $tiantian_refund);
|
||||||
$laoying_rule_result = tl_rule($laoying, $laoying_refund);
|
$laoying_rule_result = tl_rule($laoying, $laoying_refund);
|
||||||
$list['tiantian'] = $yesterday_data['tiantian'] - $tiantian_rule_result['cost'] + $tiantian_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'];
|
$list['laoying'] = $yesterday_data['laoying'] - $laoying_rule_result['cost'] + $laoying_rule_result['refund'] + ($buyi_data['laoying'] ?? 0);
|
||||||
|
|
||||||
$xianfeng_rule_result = xianfeng($xianfeng, $xianfeng_refund);
|
$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);
|
$jinrui_rule_result = jinrui($jinrui, $jinrui_refund);
|
||||||
$list['jinrui'] = $yesterday_data['jinrui'] - $jinrui_rule_result['cost'] + $xianfeng_rule_result['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');
|
$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)
|
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;
|
$cost = 0;
|
||||||
foreach ($product as $package) {
|
foreach ($product as $package) {
|
||||||
switch ($package['PackageName']) {
|
switch ($package['PackageName']) {
|
||||||
case '天卡':
|
case '天卡':
|
||||||
$cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * 10;
|
$cost += ($package['NewBuyCount'] + $package['AgainBuyCount']) * $tian;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case '周卡':
|
case '周卡':
|
||||||
@@ -247,19 +258,29 @@ function qx_rule($product, $refunds)
|
|||||||
foreach ($refunds as $info) {
|
foreach ($refunds as $info) {
|
||||||
switch ($info['PackageName']) {
|
switch ($info['PackageName']) {
|
||||||
case '天卡':
|
case '天卡':
|
||||||
$refund += handle_time($info['RefundRestTime']) / 86400 * 10;
|
if ((86400 - handle_time($info['RefundRestTime'])) < 7200) {
|
||||||
|
$refund += $tian;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case '周卡':
|
case '周卡':
|
||||||
$refund += handle_time($info['RefundRestTime']) / 86400 * (60 / 7);
|
if ((86400 - handle_time($info['RefundRestTime'])) < 7200) {
|
||||||
|
$refund += 60;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case '月卡':
|
case '月卡':
|
||||||
$refund += handle_time($info['RefundRestTime']) / 86400 * (200 / 30);
|
if ((86400 - handle_time($info['RefundRestTime'])) < 7200) {
|
||||||
|
$refund += 200;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case '季卡':
|
case '季卡':
|
||||||
$refund += handle_time($info['RefundRestTime']) / 86400 * (600 / 90);
|
if ((86400 - handle_time($info['RefundRestTime'])) < 7200) {
|
||||||
|
$refund += 600;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case '年卡':
|
case '年卡':
|
||||||
$refund += handle_time($info['RefundRestTime']) / 86400 * (2400 / 365);
|
if ((86400 - handle_time($info['RefundRestTime'])) < 7200) {
|
||||||
|
$refund += 2400;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -432,7 +453,7 @@ function jinrui($product, $refunds)
|
|||||||
}
|
}
|
||||||
$refund = 0;
|
$refund = 0;
|
||||||
foreach ($refunds as $info) {
|
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['cost'] = $cost;
|
||||||
$count['refund'] = $refund;
|
$count['refund'] = $refund;
|
||||||
|
|||||||
Reference in New Issue
Block a user