function ($params) { return [ 'filters' => $params['filters'], 'fields' => ['id', 'locale', 'title', 'subtitle', 'cover', 'content', 'user_id', 'is_top', 'sort', 'status', 'publish_time', 'created_at', 'updated_at'], 'relations' => [ // 'translation' => ['model_id', 'name'], // 'brand.translation' => ['brand_id', 'name'] ], 'sorts' => [ ['field' => 'is_top', 'direction' => 'desc'], ['field' => 'sort', 'direction' => 'desc'], ['field' => 'publish_time', 'direction' => 'desc'], ], 'pagination' => [ 'page' => $params['page'] ?? 1, 'per_page' => $params['per_page'] ?? 10, ] ]; }, 'show' => function ($params) { return [ 'filters' => [ ['field' => 'status', 'operator' => '=', 'value' => '1'], ['field' => 'id', 'operator' => '=', 'value' => $params['id']] ], 'fields' => ['id', 'locale', 'title', 'subtitle', 'cover', 'content', 'user_id', 'is_top', 'sort', 'status', 'publish_time', 'created_at', 'updated_at'], 'relations' => [ // 'translation' => ['model_id', 'name'] ], ]; } ]; } public function add(array $params) { $params['locale'] = locale(); if(!empty($params['publish_time'])){ $params['publish_time'] = strtotime($params['publish_time']); }else{ $params['publish_time'] = time(); } Db::beginTransaction(); try { $info = $this->create($params); if (!$info) { throw new BusinessException('提交失败'); } Db::commit(); return true; } catch (\Throwable $th) { Db::rollBack(); throw $th; } } public function edit(array $params, int $id) { $params['locale'] = locale(); $params['publish_time'] = strtotime($params['publish_time']); Db::beginTransaction(); try { $info = $this->update($id, $params); if (!$info) { throw new BusinessException('提交失败'); } Db::commit(); return true; } catch (\Throwable $th) { Db::rollBack(); throw $th; } } }