收支核对修改
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* @Author: kangkang
|
||||
* @Date: 2020-10-13 19:52:37
|
||||
* @LastEditors: kangkang
|
||||
* @LastEditTime: 2020-10-24 14:23:06
|
||||
* @LastEditTime: 2020-10-26 10:36:11
|
||||
*/
|
||||
/*
|
||||
* @Descripttion:
|
||||
@@ -64,7 +64,7 @@ class IncomeCheck extends Controller
|
||||
$data[0] = date('Y-m-d', strtotime($data[0]) + 86400) . ' 00:00:00';
|
||||
$data[1] = date('Y-m-d', strtotime($data[1]) + 86400) . ' 23:59:59';
|
||||
$check_model = new CheckModel;
|
||||
$list = $check_model->getListPages(['day_time' => [['>' , $data[0]], ['<' , $data[1]]]], '*', 'id desc', "10000");
|
||||
$list = $check_model->getListSearch(['day_time' => ['>' , $data[0]]], ['day_time' => ['<' , $data[1]]], '*', 'id desc', "10000");
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['day_time'] = date('Y-m-d', strtotime($v['day_time']) - 86400);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
<?php
|
||||
/*
|
||||
* @Descripttion:
|
||||
* @version:
|
||||
* @Descripttion:
|
||||
* @version:
|
||||
* @Author: kangkang
|
||||
* @Date: 2020-10-22 16:13:41
|
||||
* @LastEditors: kangkang
|
||||
* @LastEditTime: 2020-10-23 17:07:07
|
||||
* @LastEditTime: 2020-10-26 10:34:48
|
||||
*/
|
||||
|
||||
|
||||
namespace app\order\model;
|
||||
|
||||
use fastphp\base\Model;
|
||||
@@ -16,4 +15,14 @@ use fastphp\base\Model;
|
||||
class IncomeCheck extends Model
|
||||
{
|
||||
protected $table = 'income_check';
|
||||
}
|
||||
|
||||
/**
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2020-09-30 17:32:46
|
||||
* @LastEditTime: 2020-10-24 12:11:18
|
||||
* @LastEditTime: 2020-10-26 10:33:22
|
||||
* @LastEditors: kangkang
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: /phptest/fastphp/base/Model.php
|
||||
@@ -52,18 +52,6 @@ class Model extends Sql
|
||||
return $this->field($fields)->where($where)->order($order)->limit($limit)->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按照页数获取数据 复杂查询
|
||||
* @param $fields 'id,count(1)...'
|
||||
* @param $order 'id desc'/'id asc'
|
||||
* @param $limit = '100' 限制查询100条
|
||||
* $limit = '2,100' 查询第二页 100条数据
|
||||
*/
|
||||
public function getListPages($where = [], $fields = '*', $order = 'id desc', $limit = '50')
|
||||
{
|
||||
return $this->field($fields)->wheres($where)->order($order)->limit($limit)->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 获取一条数据
|
||||
* @param {type}
|
||||
|
||||
@@ -28,11 +28,12 @@ class Sql
|
||||
*/
|
||||
public function where($where)
|
||||
{
|
||||
$this->param = [];
|
||||
$this->filter = '';
|
||||
$this->filter .= '';
|
||||
if ($where) {
|
||||
if(!strpos('$this->filter','WHERE') !== false){
|
||||
if(!strpos($this->filter,'WHERE') !== false){
|
||||
$this->filter .= ' WHERE ';
|
||||
} else {
|
||||
$this->filter .= ' AND ';
|
||||
}
|
||||
if (is_string($where)) {
|
||||
$this->filter .= $where;
|
||||
@@ -45,8 +46,9 @@ class Sql
|
||||
if($value[0] == 'in'){
|
||||
$this->filter .= ' `' . $key . '` ' . $value[0] . '('.implode(',',$value[1]).')';
|
||||
} else {
|
||||
$this->filter .= ' `' . $key . '` ' . $value[0] . ' :' . $key;
|
||||
$this->param[$key] = $value[1];
|
||||
$param_key = $this->paramIsExit($key,$this->param);
|
||||
$this->filter .= ' `' . $key . '` ' . $value[0] . ' :' . $param_key;
|
||||
$this->param[$param_key] = $value[1];
|
||||
}
|
||||
} else {
|
||||
$this->filter .= ' `' . $key . '` = :' . $key;
|
||||
@@ -57,8 +59,9 @@ class Sql
|
||||
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];
|
||||
$param_key = $this->paramIsExit($key,$this->param);
|
||||
$this->filter .= ' AND `' . $key . '` ' . $value[0] . ' :' . $param_key;
|
||||
$this->param[$param_key] = $value[1];
|
||||
}
|
||||
} else {
|
||||
$this->filter .= ' AND `' . $key . '` = :' . $key;
|
||||
@@ -71,73 +74,15 @@ class Sql
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 查询条件 处理复杂查询条件
|
||||
* @param {*} [ 'day_time' => [ ['>' , val1], ['<' , val2] ] ]
|
||||
* @return {*}
|
||||
*/
|
||||
public function wheres($where)
|
||||
{
|
||||
$this->param = [];
|
||||
$this->filter = '';
|
||||
if ($where) {
|
||||
|
||||
if(!strpos('$this->filter','WHERE') !== false){
|
||||
$this->filter .= ' WHERE ';
|
||||
}
|
||||
if (is_string($where)) {
|
||||
$this->filter .= ' WHERE ' . $where;
|
||||
} else {
|
||||
$flag = true;
|
||||
foreach ($where as $key => $value) {
|
||||
if ($flag) {
|
||||
$flag = false;
|
||||
if (is_array($value)) {
|
||||
$flag2 = true;
|
||||
foreach($value as $k => $v) {
|
||||
if($flag2){
|
||||
$flag2 = false;
|
||||
if($v[0] == 'in'){
|
||||
$this->filter .= ' `' . $key . '` ' . $v[0] . '('.implode(',',$v[1]).')';
|
||||
} else {
|
||||
$this->filter .= ' `' . $key . '` ' . $v[0] . ' :' . $key.$k;
|
||||
$this->param[$key.$k] = $v[1];
|
||||
}
|
||||
} else {
|
||||
if($v[0] == 'in'){
|
||||
$this->filter .= ' AND `' . $key . '` ' . $v[0] . '('.implode(',',$v[1]).')';
|
||||
} else {
|
||||
$this->filter .= ' AND `' . $key . '` ' . $v[0] . ' :' . $key.$k;
|
||||
$this->param[$key.$k] = $v[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->filter .= ' `' . $key . '` = :' . $key;
|
||||
$this->param[$key] = $value;
|
||||
}
|
||||
} else {
|
||||
if (is_array($value)) {
|
||||
foreach($value as $k => $v) {
|
||||
if($v[0] == 'in'){
|
||||
$this->filter .= ' AND `' . $key . '` ' . $v[0] . '('.implode(',',$v[1]).')';
|
||||
} else {
|
||||
$this->filter .= ' AND `' . $key . '` ' . $v[0] . ' :' . $key.$k;
|
||||
$this->param[$key.$k] = $v[1];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->filter .= ' AND `' . $key . '` = :' . $key;
|
||||
$this->param[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function paramIsExit($key,$param){
|
||||
if(!isset($param[$key])){
|
||||
return $key;
|
||||
} else {
|
||||
$key .= $key;
|
||||
return $this->paramIsExit($key,$param);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 拼装排序条件
|
||||
* @param array $order 排序条件
|
||||
@@ -202,6 +147,7 @@ class Sql
|
||||
$this->filter = '';
|
||||
$sth = Db::pdo()->prepare($sql);
|
||||
$sth = $this->formatParam($sth, $this->param);
|
||||
$this->param = [];
|
||||
$sth->execute();
|
||||
|
||||
return $sth->fetchAll();
|
||||
@@ -217,6 +163,7 @@ class Sql
|
||||
$this->filter = '';
|
||||
$sth = Db::pdo()->prepare($sql);
|
||||
$sth = $this->formatParam($sth, $this->param);
|
||||
$this->param = [];
|
||||
$sth->execute();
|
||||
|
||||
return $sth->fetch();
|
||||
@@ -233,6 +180,7 @@ class Sql
|
||||
$this->filter = '';
|
||||
$sth = Db::pdo()->prepare($sql);
|
||||
$sth = $this->formatParam($sth, $this->param);
|
||||
$this->param = [];
|
||||
$sth->execute();
|
||||
|
||||
return $sth->rowCount();
|
||||
@@ -279,6 +227,7 @@ class Sql
|
||||
$sth = Db::pdo()->prepare($sql);
|
||||
$sth = $this->formatParam($sth, $data);
|
||||
$sth = $this->formatParam($sth, $this->param);
|
||||
$this->param = [];
|
||||
$sth->execute();
|
||||
|
||||
return $sth->rowCount();
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @Author: kangkang
|
||||
* @Date: 2020-10-03 18:23:43
|
||||
* @LastEditors: kangkang
|
||||
* @LastEditTime: 2020-10-24 14:52:12
|
||||
* @LastEditTime: 2020-10-26 11:45:39
|
||||
*/
|
||||
$is_script = 1;
|
||||
include __DIR__ . '/../index.php';
|
||||
@@ -37,20 +37,25 @@ $today = date('Y-m-d', time());
|
||||
$yesterday = date('Y-m-d', (time() - 86400));
|
||||
$data['user_balance'] = $user->field('SUM(`RestAmount`) AS balance')->fetch()['balance'];
|
||||
|
||||
$where = ['UpdateTime' => [['<', $today],['>', $yesterday]]];
|
||||
$where1 = ['UpdateTime' => ['<', $today]];
|
||||
$where2 = ['UpdateTime' => ['>', $yesterday]];
|
||||
|
||||
$data['ali_invest'] = $charge_order_model
|
||||
->field('SUM(`OrderAmount`) AS ali_invest')
|
||||
->wheres(['TradeNo' => ['like', '2020%'], 'OrderState' => ['in', $charge_order_enum::$PayComplete], 'UpdateTime' => [['<', date('Y-m-d', time())],['>', date('Y-m-d', (time() - 86400))]]])
|
||||
->where(['TradeNo' => ['like', '2020%'], 'OrderState' => ['in', $charge_order_enum::$PayComplete], 'UpdateTime' => ['<', $today]])
|
||||
->where(['UpdateTime' => ['>', $yesterday]])
|
||||
->fetch()["ali_invest"] ?? 0;
|
||||
|
||||
$data['wechat_invest'] = $charge_order_model
|
||||
->field('SUM(`OrderAmount`) AS wechat_invest')
|
||||
->wheres(['TradeNo' => ['like', '4200%'], 'OrderState' => ['in', $charge_order_enum::$PayComplete], 'UpdateTime' => [['<', date('Y-m-d', time())],['>', date('Y-m-d', (time() - 86400))]]])
|
||||
->where(['TradeNo' => ['like', '4200%'], 'OrderState' => ['in', $charge_order_enum::$PayComplete], 'UpdateTime' => ['<', $today]])
|
||||
->where(['UpdateTime' => ['>', $yesterday]])
|
||||
->fetch()["wechat_invest"] ?? 0;
|
||||
|
||||
$invest_info = $score_model
|
||||
->field('ScoreType,SUM(`ScoreValue`) AS money')
|
||||
->wheres($where)
|
||||
->where($where1)
|
||||
->where($where2)
|
||||
->group(['ScoreType'])
|
||||
->fetchAll();
|
||||
|
||||
@@ -78,10 +83,11 @@ foreach ($invest_info as $v) {
|
||||
}
|
||||
}
|
||||
|
||||
$pay_info_where = array_merge($where, ['OrderState' => ['in', $product_order_enum::$PayComplete]]);
|
||||
$pay_info_where = array_merge($where2, ['OrderState' => ['in', $product_order_enum::$PayComplete]]);
|
||||
$pay_info = $product_order_model
|
||||
->field('PayType,SUM(`PaymentAmount`) AS money')
|
||||
->wheres($pay_info_where)
|
||||
->where($where1)
|
||||
->where($pay_info_where)
|
||||
->group(['PayType'])
|
||||
->fetchAll();
|
||||
foreach ($pay_info as $v) {
|
||||
@@ -97,10 +103,11 @@ foreach ($pay_info as $v) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$amount_info_where = array_merge($where, ['OrderState' => ['in', $product_order_enum::$PayComplete]]);
|
||||
$amount_info_where = array_merge($where2, ['OrderState' => ['in', $product_order_enum::$PayComplete]]);
|
||||
$amount_info = $product_order_model
|
||||
->field('OrderType,SUM(`PaymentAmount`) AS money')
|
||||
->wheres($amount_info_where)
|
||||
->where($where1)
|
||||
->where($amount_info_where)
|
||||
->group(['OrderType'])
|
||||
->fetchAll();
|
||||
|
||||
@@ -119,7 +126,8 @@ foreach ($amount_info as $v) {
|
||||
}
|
||||
$data['refund_amount'] = $product_order_model
|
||||
->field('SUM(`RefundAmount`) AS refund_amount')
|
||||
->wheres(array_merge($where, ['OrderState' => ['in', $product_order_enum::$Refunds]]))
|
||||
->where($where1)
|
||||
->where(array_merge($where2, ['OrderState' => ['in', $product_order_enum::$Refunds]]))
|
||||
->fetch()["refund_amount"] ?? 0;
|
||||
//获取昨天的数据
|
||||
$yestoday_user_balance = $income_check_model->getNewOne()['user_balance'] ?? 0;
|
||||
@@ -136,5 +144,5 @@ $data['sell_monet'] = $data['new_amount'] + $data['renew_amount'] - $data['refun
|
||||
$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['cash_out_refund'];
|
||||
$data['day_time'] = date('Y-m-d H:i:s');
|
||||
// dump($data);die;
|
||||
dump($data);die;
|
||||
$income_check_model->add($data);
|
||||
|
||||
Reference in New Issue
Block a user