2020-11-17 14:30:54 +08:00
< ? php
/*
2020-11-20 16:02:54 +08:00
* @ Descripttion :
* @ version :
2020-11-17 14:30:54 +08:00
* @ Author : kangkang
* @ Date : 2020 - 10 - 16 14 : 44 : 02
2023-08-10 19:05:21 +08:00
* @ LastEditors : “wanyongkang” “937888580 @ qq . com”
* @ LastEditTime : 2023 - 08 - 10 19 : 04 : 59
2020-11-17 14:30:54 +08:00
*/
namespace app\manager\model ;
use enum\order\ProductOrder as ProductOrderEnum ;
2020-11-20 16:02:54 +08:00
use fastphp\base\Model ;
2020-11-17 14:30:54 +08:00
class ProductOrder extends Model
{
protected $table = 'product_order' ;
/**
* @ description : 获取所有支付成功用户的支付总金额
* @ param { * }
* @ return { * }
*/
2020-11-20 16:02:54 +08:00
public function getCost ()
{
2020-11-17 14:30:54 +08:00
return $this -> field ( 'UserId,sum(PaymentAmount) as money' )
2020-11-20 16:02:54 +08:00
-> where ([ 'OrderState' => [ 'in' , ProductOrderEnum :: $PayComplete ]])
-> group ([ 'UserId' ])
-> order ( 'money' )
-> fetchAll ();
2020-11-17 14:30:54 +08:00
}
2020-11-22 11:09:33 +08:00
/**
* @ description : 获取支付总金额
* @ param { * }
* @ return { * }
*/
public function getAllMoney ( $where = '' , $where2 = [])
{
2020-11-25 16:42:25 +08:00
$data = $this -> field ( 'sum(PaymentAmount) as money,UserId' )
2020-11-22 11:09:33 +08:00
-> where ([ 'OrderState' => [ 'in' , ProductOrderEnum :: $PayComplete ]])
-> where ( $where )
-> where ( $where2 )
-> group ([ 'UserId' ])
-> fetchAll ();
$result = [
'money' => 0 ,
2020-11-25 16:42:25 +08:00
'num' => 0 ,
2020-11-22 11:09:33 +08:00
];
2020-11-25 16:42:25 +08:00
foreach ( $data as $info ) {
2020-11-22 11:09:33 +08:00
$result [ 'money' ] += $info [ 'money' ];
2020-11-25 16:42:25 +08:00
$result [ 'num' ] ++ ;
2020-11-22 11:09:33 +08:00
}
return $result ;
}
/**
* @ description : 获取退款总金额
* @ param { * }
* @ return { * }
*/
public function getRefund ( $where = '' , $where2 = [])
{
2023-08-10 19:05:21 +08:00
return $this -> field ( 'sum(RefundAmount) as money' )
2020-11-22 11:09:33 +08:00
-> where ([ 'OrderState' => [ 'in' , ProductOrderEnum :: $Refunds ]])
-> where ( $where )
-> where ( $where2 )
-> fetch ();
}
2020-11-17 14:30:54 +08:00
/**
* @ description : 获取所有支付成功用户近一个月的支付总金额
* @ param { * }
* @ return { * }
*/
2020-11-20 16:02:54 +08:00
public function getMonthCost ( $user_id )
{
2020-11-17 14:30:54 +08:00
$last_month = date ( " Y-m-d H:i:s " , strtotime ( " -1 month " ));
$new_month = date ( " Y-m-d H:i:s " , time ());
return $this -> field ( 'UserId,sum(PaymentAmount) as money' )
2020-11-20 16:02:54 +08:00
-> where ([ 'OrderState' => [ 'in' , ProductOrderEnum :: $PayComplete ], 'UpdateTime' => [ '<' , $new_month ]])
-> where ([ 'UpdateTime' => [ '>' , $last_month ]])
-> where ([ 'UserId' => [ 'in' , $user_id ]])
-> group ([ 'UserId' ])
-> order ( 'money' )
-> fetchAll ();
}
/**
* @ description : 获取所有支付成功用户的支付总金额
* @ param { * }
* @ return { * }
*/
public function getAllCost ( $user_id )
{
return $this -> field ( 'UserId,sum(PaymentAmount) as money' )
-> where ([ 'OrderState' => [ 'in' , ProductOrderEnum :: $PayComplete ]])
-> where ([ 'UserId' => [ 'in' , $user_id ]])
-> group ([ 'UserId' ])
-> fetchAll ();
2020-11-17 14:30:54 +08:00
}
/**
2020-11-20 16:02:54 +08:00
* @ description : 获取所有支付成功用户上一个月在筛选范围的支付总金额
2020-11-17 14:30:54 +08:00
* @ param { * }
* @ return { * }
*/
2020-11-20 16:02:54 +08:00
public function getScreenMonthCost ( $screen )
{
2020-11-17 14:30:54 +08:00
$last_month = date ( " Y-m-01 " , strtotime ( " -1 month " ));
$new_month = date ( " Y-m-t " , strtotime ( " -1 month " ));
return $this -> field ( 'UserId,sum(PaymentAmount) as money' )
2020-11-20 16:02:54 +08:00
-> where ([ 'OrderState' => [ 'in' , ProductOrderEnum :: $PayComplete ], 'UpdateTime' => [ '<' , $new_month ]])
-> where ([ 'UpdateTime' => [ '>' , $last_month ]])
-> group ([ 'UserId' ], 'having money>' . $screen [ 'money1' ] . ' and money<' . $screen [ 'money2' ])
-> fetchAll ();
}
/**
* @ description : 获取所有支付成功用户上一个月或者本月支付金额
* @ param { * } flag = true 上一个月
* @ return { * } false 本月
*/
public function getPreMonthCost ( $user_id , $where )
{
return $this -> field ( 'UserId,sum(PaymentAmount) as money' )
-> where ([ 'OrderState' => [ 'in' , ProductOrderEnum :: $PayComplete ]])
-> where ( $where )
-> where ([ 'UserId' => [ 'in' , $user_id ]])
-> group ([ 'UserId' ])
-> order ( 'money' )
-> fetchAll ();
}
/**
* @ description : 获取用户所有的帐号记录
* @ param { * }
* @ return { * }
*/
public function getUserAccount ( $user_id )
{
return $this -> field ( 'UserName,ProductName,PackageName,PaymentAmount,Accounts,UpdateTime' )
-> where ([ 'OrderState' => [ 'in' , ProductOrderEnum :: $PayComplete ], 'UserId' => $user_id ])
-> order ( 'Id desc' )
-> fetchAll ();
}
/**
* @ description : 按照排序条件进行查询
* @ param { * }
* @ return { * }
*/
2020-11-25 16:42:25 +08:00
public function getSort ( $where = [], $order = 1 , $limit = '50' , $time_where , $having = '' )
2020-11-20 16:02:54 +08:00
{
$order_type = 'money' ;
2020-11-25 16:42:25 +08:00
if ( $order == '0' ) {
2020-11-20 16:02:54 +08:00
$order_type = 'money desc' ;
}
return $this -> field ( 'product_order.UserId,sum(product_order.PaymentAmount) as money' )
-> join ( 'user ON product_order.UserId=user.Id' )
-> where ([ 'OrderState' => [ 'in' , ProductOrderEnum :: $PayComplete ]])
2020-11-25 16:42:25 +08:00
-> where ( $time_where )
2020-11-20 16:02:54 +08:00
-> where ( $where )
2020-11-25 16:42:25 +08:00
-> group ([ 'product_order.UserId' ], $having )
2020-11-20 16:02:54 +08:00
-> order ( $order_type )
-> limit ( $limit )
-> fetchAll ();
}
/**
* @ description : 按照排序条件进行查询上一个月或者本月支付金额
* @ param { * } flag = true 上一个月
* @ return { * } flag = false 本月
*/
2020-11-25 16:42:25 +08:00
public function getMonthSort ( $where = [], $order = 1 , $limit = '50' , $where2 = '' , $having = '' )
2020-11-20 16:02:54 +08:00
{
$order_type = 'money' ;
2020-11-25 16:42:25 +08:00
if ( $order == '0' ) {
2020-11-20 16:02:54 +08:00
$order_type = 'money desc' ;
}
return $this -> field ( 'product_order.UserId,sum(product_order.PaymentAmount) as money' )
-> join ( 'user ON product_order.UserId=user.Id' )
-> where ([ 'OrderState' => [ 'in' , ProductOrderEnum :: $PayComplete ]])
-> where ( $where )
2020-11-24 15:56:59 +08:00
-> where ( $where2 )
2020-11-25 16:42:25 +08:00
-> group ([ 'product_order.UserId' ], $having )
2020-11-20 16:02:54 +08:00
-> order ( $order_type )
-> limit ( $limit )
-> fetchAll ();
}
/**
* @ description : 获取所有支付成功用户筛选金额
* @ param { * }
2020-11-25 16:42:25 +08:00
* @ return { * }
2020-11-20 16:02:54 +08:00
*/
2020-11-25 16:42:25 +08:00
public function getScreenCost ( $where , $having , $limit = '50' , $where2 = [])
2020-11-20 16:02:54 +08:00
{
return $this -> field ( 'UserId,sum(PaymentAmount) as money' )
-> join ( 'user ON product_order.UserId=user.Id' )
-> where ([ 'OrderState' => [ 'in' , ProductOrderEnum :: $PayComplete ]])
-> where ( $where )
2020-11-25 16:42:25 +08:00
-> where ( $where2 )
-> group ([ 'UserId' ], $having )
2020-11-20 16:02:54 +08:00
-> fetchAll ();
2020-11-17 14:30:54 +08:00
}
2020-11-25 09:58:17 +08:00
/**
* @ description : 获取用户所有的消费记录
* @ param { * }
* @ return { * }
*/
2020-11-25 16:42:25 +08:00
public function getUserCost ( $user_id , $index , $where = '' )
2020-11-25 09:58:17 +08:00
{
2020-11-28 17:06:29 +08:00
return $this -> field ( 'UpdateTime,OrderNo,OrderType,ProductName,PackageName,PaymentAmount,Accounts,ConnectCount,AccountCount,PayType,DayPrice as OrderAmount' )
2020-11-25 09:58:17 +08:00
-> where ([ 'UserId' => $user_id ])
-> where ( $where )
2021-03-20 13:47:59 +08:00
-> where ([ 'OrderState' => [ 'in' , ProductOrderEnum :: $PayComplete ]])
2020-11-25 09:58:17 +08:00
-> order ( 'Id desc' )
-> fetchAll ();
}
2020-11-25 13:22:00 +08:00
/**
* @ description : 获取用户最后消费时间
* @ param { * } //SELECT UserId,max(UpdateTime) from product_order group by UserId
* @ return { * }
*/
public function getUserCostTime ()
{
return $this -> field ( 'UserId,max(UpdateTime) as last_time' )
-> where ([ 'OrderState' => [ 'in' , ProductOrderEnum :: $PayComplete ]])
2020-11-25 13:28:22 +08:00
-> group ([ 'UserId' ])
2020-11-25 13:22:00 +08:00
-> fetchAll ();
}
2020-11-17 14:30:54 +08:00
}