init: 项目初始代码
This commit is contained in:
84
app/api/model/Currency.php
Normal file
84
app/api/model/Currency.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
/**
|
||||
* 货币模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class Currency extends BaseModel
|
||||
{
|
||||
protected $schema = [
|
||||
'id' =>'int',
|
||||
'name' =>'string',
|
||||
'code' =>'string',
|
||||
'signal' =>'string',
|
||||
'status' =>'int',
|
||||
'create_time' =>'int',
|
||||
'update_time' =>'int',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 通过币种ID获取平台是否已经使用
|
||||
* @param $data
|
||||
* @return array|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getPlatformCoin($data)
|
||||
{
|
||||
return Platform::where('currency_id',$data)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $data 查询条件
|
||||
* @param mixed $simple 模糊搜索条件
|
||||
* @param mixed $focus 精准搜索条件
|
||||
* @param null $sort
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
|
||||
{
|
||||
$fields = array_keys($this->schema);
|
||||
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
|
||||
if (isset($data['platform_id'])) {
|
||||
if (in_array('platform_id',$fields)) {
|
||||
$query->where('platform_id',$data['platform_id']);
|
||||
}
|
||||
}
|
||||
//模糊查询条件
|
||||
if (!empty($simple)) {
|
||||
foreach ($simple as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,'like',"%".$item."%");
|
||||
}
|
||||
}
|
||||
}
|
||||
//精准查询
|
||||
if (!empty($focus)) {
|
||||
foreach ($focus as $key => $item) {
|
||||
if (in_array($key,$fields)) {
|
||||
$query->where($key,$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($data['page']) && isset($data['size'])) {
|
||||
$count = $collection->count() ?: 0;
|
||||
$page = $collection->limit($data['size'])->page($data['page'])->order($sort)->select()->toArray();
|
||||
return ['page'=>$page,'count'=>$count];
|
||||
} else {
|
||||
return $collection->order($sort)->select()->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user