127 lines
4.1 KiB
PHP
127 lines
4.1 KiB
PHP
<?php
|
|
namespace app\index\model;
|
|
|
|
|
|
use app\api\model\FileType;
|
|
use think\facade\Env;
|
|
|
|
/**
|
|
* @mixin \think\Model
|
|
*/
|
|
class SoftManual extends BaseModel
|
|
{
|
|
protected $schema = [
|
|
'id' => 'int',
|
|
'platform_id' => 'int',
|
|
'site_id' => 'int',
|
|
'language_id' => 'int',
|
|
'file_type_id' => 'int',
|
|
'name' => 'string',
|
|
'introduce' => 'string',
|
|
'support' => 'string',
|
|
'os' => 'string',
|
|
'download_count'=> 'int',
|
|
'status' => 'int',
|
|
'create_time' => 'int',
|
|
'update_time' => 'int',
|
|
];
|
|
|
|
public function getSoftBtn()
|
|
{
|
|
return $this->hasMany(SoftManualBtn::class);
|
|
}
|
|
|
|
/**
|
|
* 获取列表
|
|
* @param array $data 查询条件
|
|
* @param mixed $simple 模糊搜索条件
|
|
* @param mixed $focus 精准搜索条件
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function getAllList($data,$simple = null,$focus = null,$sort = null)
|
|
{
|
|
$fields = array_keys($this->schema);
|
|
$collection = $this->where(function ($query) use ($data,$fields,$simple,$focus) {
|
|
//模糊查询条件
|
|
if (!empty($simple)) {
|
|
foreach ($simple as $key => $item) {
|
|
if (in_array($key,$fields)) {
|
|
$query->whereOr($key,'like',"%".$item."%");
|
|
}
|
|
}
|
|
}
|
|
//精准查询
|
|
if (!empty($focus)) {
|
|
foreach ($focus as $key => $item) {
|
|
if (in_array($key,$fields)) {
|
|
$query->where($key,$item);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
|
|
// $listRow = [
|
|
// 'query' => 'index/download/index', //url额外参数
|
|
// 'fragment' => '', //url锚点
|
|
// 'var_page' => 'page', //分页变量
|
|
// 'list_rows' => $data['size']??4, //每页数量
|
|
// ];
|
|
// return $collection->order($sort)->with('getSoftBtn')->paginate($listRow);
|
|
|
|
|
|
$arr = [];
|
|
if (isset($data['page']) && isset($data['size'])) {
|
|
$count = $collection->count() ?: 0;
|
|
$page = $collection->limit($data['size'])->page($data['page'])->order($sort)->with('getSoftBtn')->select()->toArray();
|
|
// if (!empty($page)) {
|
|
// foreach ($page as $key => $item) {
|
|
// $page[$key]['image'] = Env::get('QINIU.cdn').$item['image'];
|
|
// foreach ($item['getSoftBtn'] as $item1) {
|
|
// $tmp = [
|
|
// 'url' => Env::get('QINIU.cdn').$item1['url'],
|
|
// 'name' => $item1['file_name']
|
|
// ];
|
|
// $arr[$item1['btn_tips']][] = array_merge($tmp,[]);
|
|
// }
|
|
// $page[$key]['getSoftBtn'] = $arr;
|
|
// $arr = [];
|
|
// }
|
|
// }
|
|
return ['page'=>$page,'count'=>$count];
|
|
} else {
|
|
$resData = $collection->order($sort)->with('getSoftBtn')->select()->toArray();
|
|
// dump($resData);
|
|
// if (!empty($resData)) {
|
|
// foreach ($resData as $key => $item) {
|
|
// $resData[$key]['image'] = Env::get('QINIU.cdn').$item['image'];
|
|
// $tmp = [];
|
|
// foreach ($item['getSoftBtn'] as $item1) {
|
|
// $tmp = [
|
|
// 'url' => Env::get('QINIU.cdn').$item1['url'],
|
|
// 'name' => $item1['file_name']
|
|
// ];
|
|
// $arr[$item1['btn_tips']][] = array_merge($tmp,[]);
|
|
// }
|
|
// $resData[$key]['getSoftBtn'] = $arr;
|
|
// }
|
|
// }
|
|
// dump($this->getLastSql());
|
|
return $resData;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取分类
|
|
*/
|
|
public function getDownloadType()
|
|
{
|
|
return FileType::select()->toArray();
|
|
}
|
|
}
|