$per, 'query' => $param ]; return self::with(["archivesCategory"])->where($where) ->order(["sort"=>"desc"]) ->paginate($paginate, false); } /** * 创建人信息 * * @return HasOne */ public function member(): HasOne { return $this->hasOne(Member::class, 'id', 'created_by')->bind(['nickname']); } /** * 栏目 后台用 * * @return HasOne */ public function category(): HasOne { return $this->hasOne(ArchivesCategory::class, 'id', 'category_id')->bind(['category' => 'title']); } /** * 栏目 * @return HasOne */ public function archivesCategory(): HasOne { return $this->hasOne(ArchivesCategory::class, 'id', 'category_id'); } public static function onAfterInsert( $archives) { $archives->sort = ceil(self::max("sort")+1); $archives->save(); } public static function onBeforeUpdate( $archives) { //检查sort $hasFlag = self::where([ ["sort","=",$archives->sort], ["id","<>",$archives->id] ])->find(); if(!empty($hasFlag)){ throw new RepositoryException('sort不能重复,保留小数点后2位'); } } }