44 lines
1.2 KiB
PHP

<?php
namespace app\common\model\user_recharge;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 充值记录模型
* Class UserRecharge
* @package app\common\model\user_recharge
*/
class UserRecharge extends BaseModel
{
use SoftDelete;
protected $name = 'user_recharge';
protected $deleteTime = 'delete_time';
/**
* 获取充值统计曲线
* @param $time
* @param $type
* @param $timeType
* @param string $str
* @return mixed
*/
public function getTrendData($where,$time, $type, $timeType, $str = 'count(id)')
{
return $this->when($type != '', function ($query) use ($type) {
$query->where('channel_type', $type);
})->where($where)->where(function ($query) use ($time) {
if ($time[0] == $time[1]) {
$query->whereDay('create_time', date('Y-m-d',$time[0]));
} else {
$time[1] = $time[1] + 86400;
$query->whereTime('create_time', 'between', $time);
}
})->field("FROM_UNIXTIME(create_time,'$timeType') as days, " . $str . "as num")
->group('days')->select()->toArray();
}
}