update
This commit is contained in:
@ -44,4 +44,70 @@ class WebsiteController extends AbstractController
|
||||
{
|
||||
return $render->render('website/view');
|
||||
}
|
||||
|
||||
/**
|
||||
* @url /admin/website/first-column
|
||||
* @param RenderInterface $render
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'first-column', methods: 'get')]
|
||||
public function firstColumn(RenderInterface $render): ResponseInterface
|
||||
{
|
||||
return $render->render('website/first-column/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @url /admin/website/first-column/insert
|
||||
* @param RenderInterface $render
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'first-column/insert', methods: 'get')]
|
||||
public function firstColumnInsert(RenderInterface $render): ResponseInterface
|
||||
{
|
||||
return $render->render('website/first-column/insert');
|
||||
}
|
||||
|
||||
/**
|
||||
* @url /admin/website/first-column/view
|
||||
* @param RenderInterface $render
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'first-column/view', methods: 'get')]
|
||||
public function firstColumnView(RenderInterface $render): ResponseInterface
|
||||
{
|
||||
return $render->render('website/first-column/view');
|
||||
}
|
||||
|
||||
/**
|
||||
* @url /admin/website/second-column
|
||||
* @param RenderInterface $render
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'second-column', methods: 'get')]
|
||||
public function secondColumn(RenderInterface $render): ResponseInterface
|
||||
{
|
||||
return $render->render('website/second-column/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @url /admin/website/second-column/insert
|
||||
* @param RenderInterface $render
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'second-column/insert', methods: 'get')]
|
||||
public function secondColumnInsert(RenderInterface $render): ResponseInterface
|
||||
{
|
||||
return $render->render('website/second-column/insert');
|
||||
}
|
||||
|
||||
/**
|
||||
* @url /admin/website/second-column/view
|
||||
* @param RenderInterface $render
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'second-column/view', methods: 'get')]
|
||||
public function secondColumnView(RenderInterface $render): ResponseInterface
|
||||
{
|
||||
return $render->render('website/second-column/view');
|
||||
}
|
||||
}
|
@ -88,7 +88,7 @@ class NewsController extends AbstractController
|
||||
public function insert()
|
||||
{
|
||||
$model = new NewsFormModel();
|
||||
$model->setAttributes($this->request->post(), ['title', 'keywords', 'description', 'cover', 'content', 'platform']);
|
||||
$model->setAttributes($this->request->post(), ['title', 'keywords', 'description', 'cover', 'content', 'platform', 'column1', 'column2']);
|
||||
$model->insert();
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok']);
|
||||
}
|
||||
@ -104,6 +104,7 @@ class NewsController extends AbstractController
|
||||
$content = $this->request->post('content', null);
|
||||
$platform = $this->request->post('platform', 0);
|
||||
$column = $this->request->post('column', 0);
|
||||
$column2 = $this->request->post('column2', 0);
|
||||
// 随机图片
|
||||
$directory = env('COVER_ROOT'); // 文件夹路径
|
||||
$images = glob($directory . '/*.{jpg,jpeg,png,gif,bmp}', GLOB_BRACE); // 获取图片文件
|
||||
@ -139,6 +140,7 @@ class NewsController extends AbstractController
|
||||
EOF
|
||||
]);
|
||||
$model->column_tag = $column;
|
||||
$model->second_column = $column2;
|
||||
$model->save();
|
||||
}
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok']);
|
||||
|
@ -3,6 +3,8 @@
|
||||
namespace App\Controller\admin\api;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\Model\AppNewsColumn;
|
||||
use App\Model\AppNewsSecondColumn;
|
||||
use App\Model\AppWebsiteConfig;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
@ -119,4 +121,167 @@ class WebsiteController extends AbstractController
|
||||
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok', 'data' => $query]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 一级栏目列表
|
||||
* @url /admin/api/website/first-column
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'first-column', methods: 'get')]
|
||||
public function firstColumn(): ResponseInterface
|
||||
{
|
||||
$query = AppNewsColumn::query()->where('is_delete', 0)->get()->toArray();
|
||||
|
||||
foreach ($query as &$item) {
|
||||
$item['website'] = AppWebsiteConfig::find($item['website'])->app_name;
|
||||
}
|
||||
|
||||
return $this->response->json([
|
||||
'code' => 0,
|
||||
'data' => $query
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增一级栏目
|
||||
* @url /admin/api/website/first-column/insert
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'first-column/insert', methods: 'post')]
|
||||
public function firstColumnInsert(): ResponseInterface
|
||||
{
|
||||
$model = new AppNewsColumn();
|
||||
$model->name = $this->request->post('name');
|
||||
$model->website = $this->request->post('website');
|
||||
$model->url = $this->request->post('url');
|
||||
$model->desc = $this->request->post('desc');
|
||||
$model->save();
|
||||
|
||||
return $this->response->json([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @url /admin/api/website/first-column/view
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'first-column/view', methods: 'get')]
|
||||
public function firstColumnView(): ResponseInterface
|
||||
{
|
||||
$id = $this->request->input('id');
|
||||
|
||||
$query = AppNewsColumn::query()->where(['id' => $id])->first()->toArray();
|
||||
if (!$query) {
|
||||
return $this->response->json(['code' => 400, 'msg' => 'id 有误']);
|
||||
}
|
||||
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok', 'data' => $query]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @url /admin/api/website/first-column/save
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'first-column/save', methods: 'post')]
|
||||
public function firstColumnSave(): ResponseInterface
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
|
||||
$query = AppNewsColumn::find($id);
|
||||
if (!$query) {
|
||||
return $this->response->json(['code' => 400, 'msg' => 'id 有误']);
|
||||
}
|
||||
|
||||
$query->website = $this->request->post('website');
|
||||
$query->name = $this->request->post('name');
|
||||
$query->url = $this->request->post('url');
|
||||
$query->desc = $this->request->post('desc');
|
||||
$query->save();
|
||||
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok', 'data' => $query]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 二级栏目列表
|
||||
* @url /admin/api/website/second-column
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'second-column', methods: 'get')]
|
||||
public function secondColumn(): ResponseInterface
|
||||
{
|
||||
$query = AppNewsSecondColumn::query()->where('is_delete', 0);
|
||||
$pagination = $query->paginate($this->request->input('limit', 10), page: $this->request->input('page'));
|
||||
$data = $query->get()->toArray();
|
||||
foreach ($data as &$item) {
|
||||
$query = AppWebsiteConfig::find($item['website']);
|
||||
$item['website'] = $query->app_name;
|
||||
$item['rid'] = AppNewsColumn::find($item['rid'])->name;
|
||||
}
|
||||
|
||||
return $this->response->json([
|
||||
'code' => 0,
|
||||
'data' => $data,
|
||||
'count' => $pagination->total()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增二级栏目
|
||||
* @url /admin/api/website/second-column/insert
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'second-column/insert', methods: 'post')]
|
||||
public function secondColumnInsert(): ResponseInterface
|
||||
{
|
||||
$model = new AppNewsSecondColumn();
|
||||
$model->name = $this->request->post('name');
|
||||
$model->website = $this->request->post('website');
|
||||
$model->url = $this->request->post('url');
|
||||
$model->desc = $this->request->post('desc');
|
||||
$model->rid = $this->request->post('rid');
|
||||
$model->save();
|
||||
|
||||
return $this->response->json([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @url /admin/api/website/second-column/view
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'second-column/view', methods: 'get')]
|
||||
public function secondColumnView(): ResponseInterface
|
||||
{
|
||||
$id = $this->request->input('id');
|
||||
|
||||
$query = AppNewsSecondColumn::query()->where(['id' => $id])->first()->toArray();
|
||||
if (!$query) {
|
||||
return $this->response->json(['code' => 400, 'msg' => 'id 有误']);
|
||||
}
|
||||
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok', 'data' => $query]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @url /admin/api/website/second-column/save
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'second-column/save', methods: 'post')]
|
||||
public function secondColumnSave(): ResponseInterface
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
|
||||
$query = AppNewsSecondColumn::find($id);
|
||||
if (!$query) {
|
||||
return $this->response->json(['code' => 400, 'msg' => 'id 有误']);
|
||||
}
|
||||
|
||||
$query->website = $this->request->post('website');
|
||||
$query->name = $this->request->post('name');
|
||||
$query->url = $this->request->post('url');
|
||||
$query->desc = $this->request->post('desc');
|
||||
$query->rid = $this->request->post('rid');
|
||||
$query->save();
|
||||
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok', 'data' => $query]);
|
||||
}
|
||||
}
|
@ -26,6 +26,10 @@ class NewsFormModel
|
||||
public function insert()
|
||||
{
|
||||
$model = new AppNews();
|
||||
$this->attributes['column_tag'] = $this->attributes['column1'] ?: 0;
|
||||
$this->attributes['second_column'] = $this->attributes['column2'] ?: 0;
|
||||
unset($this->attributes['column1']);
|
||||
unset($this->attributes['column2']);
|
||||
$model->setRawAttributes($this->attributes);
|
||||
$model->save();
|
||||
}
|
||||
@ -39,6 +43,8 @@ class NewsFormModel
|
||||
$model->cover = $this->attributes['cover'];
|
||||
$model->content = $this->attributes['content'];
|
||||
$model->platform = $this->attributes['platform'];
|
||||
$model->column_tag = $this->attributes['column1'] ?: 0;
|
||||
$model->second_column = $this->attributes['column2'] ?: 0;
|
||||
$model->save();
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ namespace App\Model;
|
||||
* @property string $source_url
|
||||
* @property string $source_platform
|
||||
* @property int $column_tag
|
||||
* @property int $second_column
|
||||
* @property-read mixed $created_at
|
||||
*/
|
||||
class AppNews extends Model
|
||||
@ -41,7 +42,7 @@ class AppNews extends Model
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'created_at' => 'datetime', 'created_by' => 'integer', 'updated_at' => 'datetime', 'updated_by' => 'integer', 'deleted_at' => 'integer', 'deleted_by' => 'integer', 'platform' => 'integer', 'is_record' => 'integer', 'is_delete' => 'integer', 'column_tag' => 'integer'];
|
||||
protected array $casts = ['id' => 'integer', 'created_at' => 'datetime', 'created_by' => 'integer', 'updated_at' => 'datetime', 'updated_by' => 'integer', 'deleted_at' => 'integer', 'deleted_by' => 'integer', 'platform' => 'integer', 'is_record' => 'integer', 'is_delete' => 'integer', 'column_tag' => 'integer', 'second_column' => 'integer'];
|
||||
|
||||
protected ?string $dateFormat = 'U';
|
||||
|
||||
|
@ -10,6 +10,13 @@ namespace App\Model;
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $url
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property int $created_by
|
||||
* @property int $website
|
||||
* @property int $is_delete
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property int $updated_by
|
||||
* @property string $desc
|
||||
*/
|
||||
class AppNewsColumn extends Model
|
||||
{
|
||||
@ -26,5 +33,5 @@ class AppNewsColumn extends Model
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer'];
|
||||
protected array $casts = ['id' => 'integer', 'created_at' => 'datetime', 'created_by' => 'integer', 'website' => 'integer', 'is_delete' => 'integer', 'updated_at' => 'datetime', 'updated_by' => 'integer'];
|
||||
}
|
||||
|
38
app/Model/AppNewsSecondColumn.php
Normal file
38
app/Model/AppNewsSecondColumn.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $url
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property int $created_by
|
||||
* @property int $website
|
||||
* @property int $is_delete
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property int $updated_by
|
||||
* @property string $desc
|
||||
* @property int $rid
|
||||
*/
|
||||
class AppNewsSecondColumn extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'app_news_second_column';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'created_at' => 'datetime', 'created_by' => 'integer', 'website' => 'integer', 'is_delete' => 'integer', 'updated_at' => 'datetime', 'updated_by' => 'integer', 'rid' => 'integer'];
|
||||
}
|
59
app/Rpc/v1/ColumnService.php
Normal file
59
app/Rpc/v1/ColumnService.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rpc\v1;
|
||||
|
||||
use App\Model\AppNews;
|
||||
use App\Model\AppNewsColumn;
|
||||
use App\Model\AppNewsSecondColumn;
|
||||
use App\Rpc\BaseService;
|
||||
use Hyperf\RpcServer\Annotation\RpcService;
|
||||
|
||||
#[RpcService(name: "column", server: "jsonrpc-http", protocol: "jsonrpc-http")]
|
||||
class ColumnService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 获取栏目
|
||||
* @url /column/index
|
||||
* @param int $app_id
|
||||
* @return array
|
||||
*/
|
||||
public function index(int $app_id = 0): array
|
||||
{
|
||||
$resp = $this->getResponse();
|
||||
if ($app_id) {
|
||||
$firstColumn = AppNewsColumn::query()->where('website', $app_id)->get()->toArray();
|
||||
$res = [];
|
||||
foreach ($firstColumn as $index => &$column) {
|
||||
$filter = [];
|
||||
$filter[] = ['column_tag', $column['id']];
|
||||
$res[] = [
|
||||
'filter' => $filter,
|
||||
'desc' => $column['desc'],
|
||||
'item' => [['title' => $column['name'], 'link' => $column['url']]],
|
||||
'path' => $column['url'],
|
||||
];
|
||||
$second = AppNewsSecondColumn::query()->where('rid', $column['id'])->get()->toArray();
|
||||
if ($second) {
|
||||
foreach ($second as $secondCol) {
|
||||
$appendArr = [];
|
||||
$appendArr[] = ['title' => $column['name'], 'link' => $column['url']];
|
||||
$appendArr[] = ['title' => $secondCol['name'], 'link' => $column['url'] . $secondCol['url']];
|
||||
$filter = [
|
||||
['column_tag', $column['id']],
|
||||
['second_column', $secondCol['id']]
|
||||
];
|
||||
$res[] = [
|
||||
'filter' => $filter,
|
||||
'path' => "{$column['url']}{$secondCol['url']}",
|
||||
'desc' => $secondCol['desc'],
|
||||
'item' => $appendArr,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $resp->setCode(200)->setData($res)->send();
|
||||
}
|
||||
|
||||
return $resp->setCode(200)->send();
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ namespace App\Rpc\v1;
|
||||
|
||||
use App\Model\AppNews;
|
||||
use App\Model\AppNewsColumn;
|
||||
use App\Model\AppNewsSecondColumn;
|
||||
use App\Rpc\BaseService;
|
||||
use Hyperf\RpcServer\Annotation\RpcService;
|
||||
|
||||
@ -60,11 +61,16 @@ class NewsService extends BaseService
|
||||
* @param int $page
|
||||
* @return array
|
||||
*/
|
||||
public function index(int $id, int $limit = 30, int $page = 1): array
|
||||
public function index(int $id, int $limit = 30, int $page = 1, array $filter = []): array
|
||||
{
|
||||
$query = AppNews::formatQuery(['created_at', 'column_tag'])
|
||||
->where('is_delete', 0);
|
||||
|
||||
if ($filter) {
|
||||
foreach ($filter as $item) {
|
||||
$query->where(...$item);
|
||||
}
|
||||
}
|
||||
if (isset(self::RELATION[$id])) {
|
||||
$query->whereIn('platform', self::RELATION[$id]);
|
||||
} else {
|
||||
@ -83,15 +89,24 @@ class NewsService extends BaseService
|
||||
|
||||
foreach ($value as &$item) {
|
||||
$item['created_at'] = date('Y-m-d', $item['created_at']);
|
||||
$columnTag = AppNewsColumn::find($item['column_tag']);
|
||||
$item['column_tag'] = $columnTag->name ?? '';
|
||||
$item['column_tag_url'] = $columnTag->url ?? '';
|
||||
|
||||
if ($item['column_tag']) {
|
||||
$columnTag = AppNewsColumn::find($item['column_tag']);
|
||||
$item['column_tag'] = $columnTag->name ?? '';
|
||||
$item['column_tag_url'] = $columnTag->url ?? '';
|
||||
|
||||
if ($item['second_column']) {
|
||||
$secondColumnTag = AppNewsSecondColumn::find($item['second_column']);
|
||||
$item['second_column_tag'] = $secondColumnTag->name ?? '';
|
||||
$item['second_column_tag_url'] = $columnTag->url . $secondColumnTag->url ?? '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$hot = AppNews::formatQuery(['created_at'])
|
||||
->where('platform', $id)
|
||||
->where('is_delete', 0)
|
||||
->select(['title', 'id', 'cover'])
|
||||
->select(['title', 'id', 'cover', 'created_at'])
|
||||
->limit(5)
|
||||
->orderBy('id', 'desc')
|
||||
->get()
|
||||
|
Reference in New Issue
Block a user