From fe0f0a63b3f35fdbc690fc143d11c9c436145f38 Mon Sep 17 00:00:00 2001 From: wanyongkang <937888580@qq.com> Date: Fri, 23 Oct 2020 16:48:49 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E9=87=91=E9=A2=9D=E6=94=B6=E6=94=AF?= =?UTF-8?q?=E6=A0=B8=E5=AF=B9=E3=80=91=20https://www.tapd.cn/39598945/pron?= =?UTF-8?q?g/stories/view/1139598945001000038?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/model/IncomeCheck.php | 19 +++++ app/api/model/ProductOrder.php | 19 +++++ app/api/model/UserChargeOrder.php | 19 +++++ app/api/model/UserScore.php | 19 +++++ config/config.php | 2 +- enum/order/ProductOrder.php | 63 ++++++++++++++ enum/order/UserChargeOrder.php | 37 ++++++++ enum/order/UserScore.php | 37 ++++++++ fastphp/base/Model.php | 11 ++- fastphp/db/Sql.php | 18 ++-- script/income_check_script.php | 137 ++++++++++++++++++++++++++++++ 11 files changed, 374 insertions(+), 7 deletions(-) create mode 100644 app/api/model/IncomeCheck.php create mode 100644 app/api/model/ProductOrder.php create mode 100644 app/api/model/UserChargeOrder.php create mode 100644 app/api/model/UserScore.php create mode 100644 enum/order/ProductOrder.php create mode 100644 enum/order/UserChargeOrder.php create mode 100644 enum/order/UserScore.php create mode 100644 script/income_check_script.php diff --git a/app/api/model/IncomeCheck.php b/app/api/model/IncomeCheck.php new file mode 100644 index 0000000..714cdf9 --- /dev/null +++ b/app/api/model/IncomeCheck.php @@ -0,0 +1,19 @@ + '余额', + 70 => '微信', + 100 => '支付宝', + ]; + + public static $Balance = 10; + public static $Wechat = 70; + public static $Ali = 100; + + //付款状态 + public static $OrderState = [ + 10 => '待付款', + 20 => '已付款', + 30 => '申请退款', + 40 => '人工退款', + 50 => '自动退款', + 80 => '超时关闭', + 90 => '订单完成', + ]; + + public static $NoPay = 10; + public static $PayOk = 20; + public static $RequestRefund = 30; + public static $UserRefundOver = 40; + public static $AutoRefundOver = 50; + public static $TimeOutClose = 80; + public static $Complete = 90; + + //付款完成 + public static $PayComplete = [20,90]; + //账单付款和退款 + public static $Refunds = [30,40,50]; + + //订单类型 + public static $OrderType = [ + 1 => '新开', + 2 => '批量新开', + 3 => '续费', + 4 => '批量续费', + 5 => '退款', + ]; + public static $New = 1; + public static $News = 2; + public static $AgainBuy = 3; + public static $AgainBuys = 4; + public static $Refund = 5; + +} diff --git a/enum/order/UserChargeOrder.php b/enum/order/UserChargeOrder.php new file mode 100644 index 0000000..791c308 --- /dev/null +++ b/enum/order/UserChargeOrder.php @@ -0,0 +1,37 @@ + '待付款', + 20 => '已付款', + 30 => '申请退款', + 40 => '人工退款', + 50 => '自动退款', + 80 => '超时关闭', + 90 => '订单完成', + ]; + + public static $NoPay = 10; + public static $PayOk = 20; + public static $RequestRefund = 30; + public static $UserRefundOver = 40; + public static $AutoRefundOver = 50; + public static $TimeOutClose = 80; + public static $Complete = 90; + + //付款完成 + public static $PayComplete = [20,90]; + +} diff --git a/enum/order/UserScore.php b/enum/order/UserScore.php new file mode 100644 index 0000000..b17350c --- /dev/null +++ b/enum/order/UserScore.php @@ -0,0 +1,37 @@ + '管理员充值', + 2 => '管理员扣除', + 3 => '淘宝充值', + 4 => '淘宝退款', + 5 => '账号退款', + 6 => '账号付款', + 7 => '用户充值', + 8 => '用户提现扣除', + 9 => '提现被拒退还', + ]; + + public static $ManageAdd = 1; + public static $ManagerDeduct = 2; + public static $TaoBaoAdd = 3; + public static $TaoBaoRefund = 4; + public static $AccountRefund = 5; + public static $Pay = 6; + public static $UserCharge = 7; + public static $UserCashOut = 8; + public static $ReturnMoney = 9; + +} diff --git a/fastphp/base/Model.php b/fastphp/base/Model.php index 63d4943..b39325c 100644 --- a/fastphp/base/Model.php +++ b/fastphp/base/Model.php @@ -2,7 +2,7 @@ /* * @Author: your name * @Date: 2020-09-30 17:32:46 - * @LastEditTime: 2020-10-14 20:40:36 + * @LastEditTime: 2020-10-23 16:23:12 * @LastEditors: kangkang * @Description: In User Settings Edit * @FilePath: /phptest/fastphp/base/Model.php @@ -61,6 +61,15 @@ class Model extends Sql { return $this->field($fields)->where($where)->limit('1')->fetch(); } + + /** + * @description: 获取最新一条数据 + * @param {*} + * @return {*} + */ + public function getNewOne($fields = '*'){ + return $this->field($fields)->order('id desc')->limit(1)->fetch(); + } /** * @description: 更新一条数据 * @param {type} diff --git a/fastphp/db/Sql.php b/fastphp/db/Sql.php index 7090b1f..708c273 100644 --- a/fastphp/db/Sql.php +++ b/fastphp/db/Sql.php @@ -40,16 +40,24 @@ class Sql if ($flag) { $flag = false; if (is_array($value)) { - $this->filter .= ' `' . $key . '` ' . $value[0] . ' :' . $key; - $this->param[$key] = $value[1]; + if($value[0] == 'in'){ + $this->filter .= ' `' . $key . '` ' . $value[0] . '('.implode(',',$value[1]).')'; + } else { + $this->filter .= ' `' . $key . '` ' . $value[0] . ' :' . $key; + $this->param[$key] = $value[1]; + } } else { $this->filter .= ' `' . $key . '` = :' . $key; $this->param[$key] = $value; } } else { if (is_array($value)) { - $this->filter .= ' AND `' . $key . '` ' . $value[0] . ' :' . $key; - $this->param[$key] = $value[1]; + if($value[0] == 'in'){ + $this->filter .= ' AND `' . $key . '` ' . $value[0] . '('.implode(',',$value[1]).')'; + } else { + $this->filter .= ' AND `' . $key . '` ' . $value[0] . ' :' . $key; + $this->param[$key] = $value[1]; + } } else { $this->filter .= ' AND `' . $key . '` = :' . $key; $this->param[$key] = $value; @@ -83,7 +91,7 @@ class Sql */ public function group($group = []) { - if ($order) { + if ($group) { $this->filter .= ' GROUP BY '; $this->filter .= ' ' . implode(' ,', $group) . ' '; } diff --git a/script/income_check_script.php b/script/income_check_script.php new file mode 100644 index 0000000..6d35d3e --- /dev/null +++ b/script/income_check_script.php @@ -0,0 +1,137 @@ +field('SUM(`RestAmount`) AS balance')->fetch()['balance']; + +$where = ['UpdateTime' => ['<', $data], 'UpdateTime' => ['>', $yesterday]]; + +$data['ali_invest'] = $charge_order_model + ->field('SUM(`OrderAmount`) AS ali_invest') + ->where(['TradeNo' => ['like', '2020%'], 'OrderState' => ['in', $charge_order_enum::$PayComplete], 'UpdateTime' => ['<', date('Y-m-d', time())], 'UpdateTime' => ['>', date('Y-m-d', (time() - 86400))]]) + ->fetch()["ali_invest"]??0; +$data['wechat_invest'] = $charge_order_model + ->field('SUM(`OrderAmount`) AS wechat_invest') + ->where(['TradeNo' => ['like', '4200%'], 'OrderState' => ['in', $charge_order_enum::$PayComplete], 'UpdateTime' => ['<', date('Y-m-d', time())], 'UpdateTime' => ['>', date('Y-m-d', (time() - 86400))]]) + ->fetch()["wechat_invest"]??0; + +$invest_info = $score_model + ->field('ScoreType,SUM(`ScoreValue`) AS money') + ->where($where) + ->group(['ScoreType']) + ->fetchAll(); + +$data['manager_invest'] = $data['manager_deduct'] = $data['cash_out'] = $data['taobao_invest'] = $data['taobao_refund'] = $data['balance_pay'] = $data['wechat_pay'] = $data['ali_pay'] = $data['new_amount'] = $data['renew_amount'] = $data['refund_amount'] = 0; +foreach ($invest_info as $v) { + switch ($v['ScoreType']) { + case $score_enum::$ManageAdd: + $data['manager_invest'] = $v['money']; + break; + case $score_enum::$ManagerDeduct: + $data['manager_deduct'] = $v['money']; + break; + case $score_enum::$UserCashOut: + $data['cash_out'] = $v['money']; + break; + case $score_enum::$TaoBaoAdd: + $data['taobao_invest'] = $v['money']; + break; + case $score_enum::$TaoBaoRefund: + $data['taobao_refund'] = $v['money']; + break; + } +} + +$pay_info_where = array_merge($where, ['OrderState' => ['in', $product_order_enum::$PayComplete]]); +$pay_info = $product_order_model + ->field('PayType,SUM(`PaymentAmount`) AS money') + ->where($pay_info_where) + ->group(['PayType']) + ->fetchAll(); +foreach ($pay_info as $v) { + switch ($v['PayType']) { + case $product_order_enum::$Balance: + $data['balance_pay'] = $v['money']; + break; + case $product_order_enum::$Wechat: + $data['wechat_pay'] = $v['money']; + break; + case $product_order_enum::$Ali: + $data['ali_pay'] = $v['money']; + break; + } +} +$amount_info_where = array_merge($where, ['OrderState' => ['in', $product_order_enum::$PayComplete]]); +$amount_info = $product_order_model + ->field('OrderType,SUM(`PaymentAmount`) AS money') + ->where($amount_info_where) + ->group(['OrderType']) + ->fetchAll(); + +$data['new_amount'] = $data['renew_amount'] = 0; +foreach ($amount_info as $v) { + switch ($v['OrderType']) { + case $product_order_enum::$New: + case $product_order_enum::$News: + $data['new_amount'] += $v['money']; + break; + case $product_order_enum::$AgainBuy: + case $product_order_enum::$AgainBuys: + $data['renew_amount'] += $v['money']; + break; + } +} +$data['refund_amount'] = $product_order_model + ->field('SUM(`RefundAmount`) AS refund_amount') + ->where(array_merge($where, ['OrderState' => ['in', $product_order_enum::$Refunds]])) + ->fetch()["refund_amount"]??0; +//获取昨天的数据 +$yestoday_user_balance = $income_check_model->getNewOne()['user_balance'] ?? 0; +//base=次日会员余额一当日会员余额+支付宝充值+微信充值+淘宝充值+管理员充值+退款金额一管理员扣除一提现一淘宝退款扣除 +$base_money = $data['user_balance'] - $yestoday_user_balance + $data['ali_invest'] + $data['wechat_invest'] + $data['taobao_invest'] + $data['manager_invest'] + $data['refund_amount'] - $data['manager_deduct'] - $data['cash_out'] - $data['taobao_refund']; +//余额差值=次日会员余额一当日会员余额+支付宝充值+微信充值+淘宝充值+管理员充值+退款金额一管理员扣除一提现一淘宝退款扣除 一余额支付 +//收支差值=次日会员余额一当日会员余额+支付宝充值+微信充值+淘宝充值+管理员充值+退款金额一管理员扣除一提现一淘宝退款扣除 +余额支付+支付宝支付+微信支付一新开金额一续费金额 +//当日销售额=新开金额+续费金额一退货金额 +//当日在总进账=支付宝充值+微信充值+淘宝充值+支付宝支付+微信支付 +//当日总支出=提现扣除金额+淘宝扣除金额 +$data['balance_diff'] = $base_money - $data['balance_pay']; +$data['in_out_diff'] = $base_money + $data['balance_pay'] + $data['ali_pay'] + $data['wechat_pay'] - $data['new_amount'] - $data['renew_amount']; +$data['sell_monet'] = $data['new_amount'] + $data['renew_amount'] - $data['refund_amount']; +$data['income'] = $data['ali_invest'] + $data['wechat_invest'] - $data['taobao_invest'] + $data['ali_pay'] + $data['wechat_pay']; +$data['expend'] = $data['cash_out'] + $data['taobao_refund']; +$data['day_time'] = date('Y-m-d H:i:s'); +// dump($data);die; +$income_check_model->add($data); \ No newline at end of file