126 lines
3.2 KiB
PHP
126 lines
3.2 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Model;
|
||
|
||
|
||
|
||
use Hyperf\Database\Model\Builder;
|
||
use Hyperf\Database\Model\Collection;
|
||
use Hyperf\DbConnection\Db;
|
||
use Hyperf\Snowflake\Concern\Snowflake;
|
||
|
||
/**
|
||
* @property int $account_detail_id 主键id
|
||
* @property int $doctor_id 医生id
|
||
* @property int $year 年(2023)
|
||
* @property int $month 月(12)
|
||
* @property int $day 日(01)
|
||
* @property string $date 日期(2022-01-01)
|
||
* @property string $total_amount 订单总金额-日
|
||
* @property \Carbon\Carbon $created_at 创建时间
|
||
* @property \Carbon\Carbon $updated_at 修改时间
|
||
*/
|
||
class DoctorAccountDay extends Model
|
||
{
|
||
use Snowflake;
|
||
|
||
/**
|
||
* The table associated with the model.
|
||
*/
|
||
protected ?string $table = 'doctor_account_day';
|
||
|
||
/**
|
||
* The attributes that are mass assignable.
|
||
*/
|
||
protected array $fillable = ['account_detail_id', 'doctor_id', 'year', 'month', 'day', 'date', 'total_amount', 'created_at', 'updated_at'];
|
||
|
||
protected string $primaryKey = "account_detail_id";
|
||
|
||
/**
|
||
* 获取信息-单条
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @return object|null
|
||
*/
|
||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||
{
|
||
return self::where($params)->first($fields);
|
||
}
|
||
|
||
/**
|
||
* 获取信息-多条
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @return object|null
|
||
*/
|
||
public static function getList(array $params, array $fields = ['*']): object|null
|
||
{
|
||
return self::where($params)->get($fields);
|
||
}
|
||
|
||
/**
|
||
* 获取total_amount_day字段总和
|
||
* @param array $params
|
||
* @return int|mixed|string
|
||
*/
|
||
public static function getDoctorSumTotalAmount(array $params): mixed
|
||
{
|
||
return self::where($params)->sum("total_amount");
|
||
}
|
||
|
||
|
||
/**
|
||
* 新增
|
||
* @param array $data
|
||
* @return DoctorAccountDay|\Hyperf\Database\Model\Model
|
||
*/
|
||
public static function addDoctorAccountDay(array $data): DoctorAccountDay|\Hyperf\Database\Model\Model
|
||
{
|
||
return self::create($data);
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 自增
|
||
* @param array $params
|
||
* @param string $field
|
||
* @param float $numeral
|
||
* @return int
|
||
*/
|
||
public static function inc(array $params,string $field,float $numeral = 1): int
|
||
{
|
||
return self::where($params)->increment($field,$numeral);
|
||
}
|
||
|
||
/**
|
||
* 自减
|
||
* @param array $params
|
||
* @param string $field
|
||
* @param float $numeral
|
||
* @return int
|
||
*/
|
||
public static function dec(array $params,string $field,float $numeral = 1): int
|
||
{
|
||
return self::where($params)->decrement($field,$numeral);
|
||
}
|
||
|
||
/**
|
||
* 获取医生账户月份金额
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @return \Hyperf\Collection\Collection
|
||
*/
|
||
public static function getDoctorMonth(array $params,array $fields = ['*']): \Hyperf\Collection\Collection
|
||
{
|
||
return self::select(['year','month',Db::raw('SUM(total_amount) AS `total_amount`')])
|
||
->where($params)
|
||
->groupBy(['year','month'])
|
||
->orderBy('year')
|
||
->orderBy('month')
|
||
->get($fields);
|
||
}
|
||
}
|