Files
juipphp/app/manager/model/ProductAccount.php
2020-11-25 14:57:55 +08:00

92 lines
2.9 KiB
PHP

<?php
/*
* @Descripttion:
* @version:
* @Author: kangkang
* @Date: 2020-10-16 14:44:02
* @LastEditors: Please set LastEditors
* @LastEditTime: 2020-11-25 14:56:10
*/
namespace app\manager\model;
use fastphp\base\Model;
use enum\account\ProductAccount as ProductAccountEnum;
class ProductAccount extends Model
{
protected $table = 'product_account';
/**
* @description: 获取使用中和已经过期额的帐号
* @param {*}
* @return {*}
*/
public function getUesdAccount($where = [])
{
return $this->field('UserId, sum(ConnectCount) used_count')->where($where)->group(['UserId'])->fetchAll();
}
/**
* @description: 获取用户帐号信息
* @param {*}
* @return {*}
*/
public function getUserAccount($user_id, $index)
{
$product_account_enum = new ProductAccountEnum;
$where = [];
$wheres = [];
switch($index){
case 1:
$where = ['DeleteTag' => 0, 'AccountType' => ['<>', $product_account_enum::$Test]];
break;
case 2:
$where = ['DeleteTag' => 0, 'EndTime' => ['<', date('Y-m-d H:i:s')], 'AccountType' => ['<>', $product_account_enum::$Test]];
break;
case 3:
$where = ['DeleteTag' => 0, 'EndTime' => ['>', date('Y-m-d H:i:s')], 'AccountType' => ['<>', $product_account_enum::$Test]];
break;
}
return $this->field('ProductName,PackageName,Account,StartTime,EndTime,UpdateTime')
->where(['UserId' => $user_id])
->where($where)
->order('Id desc')
->fetchAll();
}
/**
* @description: 按照排序条件进行查询
* @param {*}
* @return {*}
*/
public function getSort($where = [],$order = 1, $limit = '50',$index)
{
$order_type = 'account_count';
if($order == '0'){
$order_type = 'account_count desc';
}
$product_account_enum = new ProductAccountEnum;
$wheres = [];
switch($index){
case 1:
$wheres = "product_account.DeleteTag=0 and AccountType<>".$product_account_enum::$Test;
break;
case 2:
$wheres = "product_account.DeleteTag=0 and AccountType<>".$product_account_enum::$Test." and product_account.EndTime>'".date('Y-m-d H:i:s')."'";
break;
case 3:
$wheres = "product_account.DeleteTag=0 and AccountType<>".$product_account_enum::$Test." and product_account.EndTime<='".date('Y-m-d H:i:s')."'";
break;
}
return $this->field('product_account.UserId,sum(product_account.ConnectCount) account_count')
->join('user ON product_account.UserId=user.Id')
->where($where)
->where($wheres)
->group(['product_account.UserId'])
->order($order_type)
->limit($limit)
->fetchAll();
}
}