Files
juipphp/app/manager/model/ProductOrder.php

221 lines
6.8 KiB
PHP
Raw Normal View History

2020-11-17 14:30:54 +08:00
<?php
/*
* @Descripttion:
* @version:
2020-11-17 14:30:54 +08:00
* @Author: kangkang
* @Date: 2020-10-16 14:44:02
2020-11-22 11:09:33 +08:00
* @LastEditors: Please set LastEditors
2020-11-25 09:58:17 +08:00
* @LastEditTime: 2020-11-25 09:46:23
2020-11-17 14:30:54 +08:00
*/
namespace app\manager\model;
use enum\order\ProductOrder as ProductOrderEnum;
use fastphp\base\Model;
2020-11-17 14:30:54 +08:00
class ProductOrder extends Model
{
protected $table = 'product_order';
/**
* @description: 获取所有支付成功用户的支付总金额
* @param {*}
* @return {*}
*/
public function getCost()
{
2020-11-17 14:30:54 +08:00
return $this->field('UserId,sum(PaymentAmount) as money')
->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 = [])
{
$data = $this->field('sum(PaymentAmount) as money,UserId')
->where(['OrderState' => ['in', ProductOrderEnum::$PayComplete]])
->where($where)
->where($where2)
->group(['UserId'])
->fetchAll();
$result = [
'money' => 0,
'num' => 0
];
foreach($data as $info){
$result['money'] += $info['money'];
$result['num'] ++;
}
return $result;
}
/**
* @description: 获取退款总金额
* @param {*}
* @return {*}
*/
public function getRefund($where = '', $where2 = [])
{
return $this->field('sum(PaymentAmount) as money')
->where(['OrderState' => ['in', ProductOrderEnum::$Refunds]])
->where($where)
->where($where2)
->fetch();
}
2020-11-17 14:30:54 +08:00
/**
* @description: 获取所有支付成功用户近一个月的支付总金额
* @param {*}
* @return {*}
*/
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')
->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
}
/**
* @description: 获取所有支付成功用户上一个月在筛选范围的支付总金额
2020-11-17 14:30:54 +08:00
* @param {*}
* @return {*}
*/
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')
->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 {*}
*/
public function getSort($where = [],$order = 1, $limit = '50')
{
$order_type = 'money';
if($order == '0'){
$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)
->group(['product_order.UserId'])
->order($order_type)
->limit($limit)
->fetchAll();
}
/**
* @description: 按照排序条件进行查询上一个月或者本月支付金额
* @param {*} flag = true 上一个月
* @return {*} flag = false 本月
*/
2020-11-24 15:56:59 +08:00
public function getMonthSort($where = [],$order = 1, $limit = '50', $where2 ='')
{
$order_type = 'money';
if($order == '0'){
$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)
->group(['product_order.UserId'])
->order($order_type)
->limit($limit)
->fetchAll();
}
/**
* @description: 获取所有支付成功用户筛选金额
* @param {*}
* @return {*}
*/
public function getScreenCost($where,$having, $limit = '50')
{
return $this->field('UserId,sum(PaymentAmount) as money')
->join('user ON product_order.UserId=user.Id')
->where(['OrderState' => ['in', ProductOrderEnum::$PayComplete]])
->where($where)
->group(['UserId'],$having)
->fetchAll();
2020-11-17 14:30:54 +08:00
}
2020-11-25 09:58:17 +08:00
/**
* @description: 获取用户所有的消费记录
* @param {*}
* @return {*}
*/
public function getUserCost($user_id, $index, $where='')
{
return $this->field('UpdateTime,OrderNo,OrderType,ProductName,PackageName,PaymentAmount,Accounts,ConnectCount,PayType')
->where(['UserId' => $user_id])
->where($where)
->order('Id desc')
->fetchAll();
}
2020-11-17 14:30:54 +08:00
}