114 lines
2.8 KiB
PHP
114 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
use Hyperf\Snowflake\Concern\Snowflake;
|
|
|
|
/**
|
|
* @property int $amount_id 主键id
|
|
* @property int $product_platform_id 处方平台商品id
|
|
* @property string $product_platform_code 处方平台商品编码
|
|
* @property int $stock 现有库存
|
|
* @property \Carbon\Carbon $created_at 创建时间
|
|
* @property \Carbon\Carbon $updated_at 修改时间
|
|
*/
|
|
class ProductPlatformAmount extends Model
|
|
{
|
|
use Snowflake;
|
|
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'product_platform_amount';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected array $fillable = ['amount_id', 'product_platform_id', 'product_platform_code', 'stock', 'created_at', 'updated_at'];
|
|
|
|
protected string $primaryKey = "amount_id";
|
|
|
|
/**
|
|
* 自增
|
|
* @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 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 getSharedLockOne(array $params, array $fields = ['*']): object|null
|
|
{
|
|
return self::where($params)->sharedLock()->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);
|
|
}
|
|
|
|
/**
|
|
* 新增
|
|
* @param array $data
|
|
* @return ProductPlatformAmount|\Hyperf\Database\Model\Model
|
|
*/
|
|
public static function addProductPlatformAmount(array $data = []): ProductPlatformAmount|\Hyperf\Database\Model\Model
|
|
{
|
|
return self::create($data);
|
|
}
|
|
|
|
/**
|
|
* 修改
|
|
* @param array $params
|
|
* @param array $data
|
|
* @return int
|
|
*/
|
|
public static function edit(array $params = [], array $data = []): int
|
|
{
|
|
return self::where($params)->update($data);
|
|
}
|
|
}
|