v1.0
bruce 8 months ago
parent 001d4c9b21
commit 1679fc7964
  1. 11
      app/common/model/MaintenanceCategory.php
  2. 10
      app/store/model/Maintenance.php

@ -36,15 +36,6 @@ class MaintenanceCategory extends BaseModel
return static::get($categoryId);
}
public function catImg(): HasOne
{
$module = self::getCalledModule();
return $this->hasOne("app\\{$module}\\model\\UploadFile", 'file_id', 'img_id')
->bind(['img_url' => 'preview_url']);
}
/**
* 获取列表
* @param array $where
@ -55,7 +46,7 @@ class MaintenanceCategory extends BaseModel
*/
public function getList(array $where = []): \think\Collection
{
return $this->where($where)->with(['catImg'])
return $this->where($where)
->order(['sort', $this->getPk()])
->select();
}

@ -13,6 +13,7 @@ declare (strict_types=1);
namespace app\store\model;
use app\common\model\Maintenance as MaintenanceModel;
use think\model\relation\HasOne;
/**
* 文章模型
@ -41,7 +42,7 @@ class Maintenance extends MaintenanceModel
$params['status'] > -1 && $filter[] = ['status', '=', $params['status']];
$params['categoryId'] > 0 && $filter[] = ['category_id', '=', $params['categoryId']];
// 查询列表数据
$data = $this->where($filter)
$data = $this->where($filter)->with(['catImg'])
->where('is_delete', '=', 0)
->order(['sort' => 'asc', 'create_time' => 'desc'])
->paginate(15);
@ -108,4 +109,11 @@ class Maintenance extends MaintenanceModel
{
return (new static)->where($where)->where('is_delete', '=', 0)->count();
}
public function catImg(): HasOne
{
$module = self::getCalledModule();
return $this->hasOne("app\\{$module}\\model\\UploadFile", 'file_id', 'img_id')
->bind(['img_url' => 'preview_url']);
}
}

Loading…
Cancel
Save