first commit
This commit is contained in:
11
app/FormModel/admin/articles/ArticlesModel.php
Executable file
11
app/FormModel/admin/articles/ArticlesModel.php
Executable file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\articles;
|
||||
|
||||
class ArticlesModel
|
||||
{
|
||||
public function edit()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
15
app/FormModel/admin/articles/BaseModify.php
Executable file
15
app/FormModel/admin/articles/BaseModify.php
Executable file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\articles;
|
||||
|
||||
class BaseModify
|
||||
{
|
||||
|
||||
protected array $attributes = [];
|
||||
|
||||
public function setAttributes(array $modifyData): static
|
||||
{
|
||||
$this->attributes = $modifyData;
|
||||
return $this;
|
||||
}
|
||||
}
|
11
app/FormModel/admin/articles/ModifyModel.php
Executable file
11
app/FormModel/admin/articles/ModifyModel.php
Executable file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\articles;
|
||||
|
||||
|
||||
use App\FormModel\admin\articles\trait\ModifyForUpdate;
|
||||
|
||||
class ModifyModel extends BaseModify
|
||||
{
|
||||
use ModifyForUpdate;
|
||||
}
|
12
app/FormModel/admin/articles/module/BaseModule.php
Executable file
12
app/FormModel/admin/articles/module/BaseModule.php
Executable file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\articles\module;
|
||||
|
||||
class BaseModule
|
||||
{
|
||||
protected array $attributes = [];
|
||||
public function setAttributes()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
8
app/FormModel/admin/articles/module/ShowsModel.php
Executable file
8
app/FormModel/admin/articles/module/ShowsModel.php
Executable file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\articles\module;
|
||||
|
||||
class ShowsModel
|
||||
{
|
||||
|
||||
}
|
8
app/FormModel/admin/articles/module/StreetModel.php
Executable file
8
app/FormModel/admin/articles/module/StreetModel.php
Executable file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\articles\module;
|
||||
|
||||
class StreetModel extends BaseModule
|
||||
{
|
||||
|
||||
}
|
23
app/FormModel/admin/articles/trait/ModifyForUpdate.php
Executable file
23
app/FormModel/admin/articles/trait/ModifyForUpdate.php
Executable file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\articles\trait;
|
||||
|
||||
use App\Model\AppArticle;
|
||||
|
||||
trait ModifyForUpdate
|
||||
{
|
||||
protected array $canUpdateFields = ['title', 'cover', 'images', 'brand', 'location'];
|
||||
|
||||
public function update()
|
||||
{
|
||||
$query = AppArticle::where(['aid' => $this->attributes['aid']])->first();
|
||||
foreach ($this->canUpdateFields as $field) {
|
||||
$val = $this->attributes[$field] ?? null;
|
||||
if ($val !== null) {
|
||||
$query->{$field} = $this->attributes[$field];
|
||||
}
|
||||
}
|
||||
|
||||
$query->save();
|
||||
}
|
||||
}
|
43
app/FormModel/admin/news/NewsFormModel.php
Normal file
43
app/FormModel/admin/news/NewsFormModel.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\news;
|
||||
|
||||
use App\Model\AppNews;
|
||||
|
||||
class NewsFormModel
|
||||
{
|
||||
|
||||
private array $attributes = [];
|
||||
|
||||
public function setAttributes(array $attr, $allowProp = [])
|
||||
{
|
||||
if (!$allowProp) {
|
||||
$this->attributes = $attr;
|
||||
}
|
||||
|
||||
foreach($allowProp as $prop) {
|
||||
if (isset($attr[$prop])) {
|
||||
$this->attributes[$prop] = $attr[$prop];
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function insert()
|
||||
{
|
||||
$model = new AppNews();
|
||||
$model->setRawAttributes($this->attributes);
|
||||
$model->save();
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
$model = AppNews::find($this->attributes['id']);
|
||||
$model->title = $this->attributes['title'];
|
||||
$model->keywords = $this->attributes['keywords'];
|
||||
$model->description = $this->attributes['description'];
|
||||
$model->cover = $this->attributes['cover'];
|
||||
$model->content = $this->attributes['content'];
|
||||
$model->save();
|
||||
}
|
||||
}
|
12
app/FormModel/api/BaseModel.php
Executable file
12
app/FormModel/api/BaseModel.php
Executable file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\api;
|
||||
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
|
||||
class BaseModel
|
||||
{
|
||||
#[Inject]
|
||||
protected RequestInterface $_request;
|
||||
}
|
50
app/FormModel/api/v1/ArticlesModel.php
Executable file
50
app/FormModel/api/v1/ArticlesModel.php
Executable file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\api\v1;
|
||||
|
||||
|
||||
use App\Helpers\AppHelper;
|
||||
use App\Model\AppArticle;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
|
||||
class ArticlesModel
|
||||
{
|
||||
#[Inject]
|
||||
private readonly RequestInterface $_request;
|
||||
|
||||
public function edit()
|
||||
{
|
||||
$query = AppArticle::find($this->_request->post('id'));
|
||||
$query->cover = AppHelper::extractImagePath($this->_request->post('cover'));
|
||||
|
||||
$query->title = $this->_request->post('title');
|
||||
$query->brand = $this->_request->post('brand');
|
||||
|
||||
$images = array_values($this->_request->post('images'));
|
||||
foreach ($images as &$image) {
|
||||
$image['src'] = AppHelper::extractImagePath($image['src']);
|
||||
}
|
||||
$query->images = json_encode($images);
|
||||
|
||||
$query->save();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$query = new AppArticle();
|
||||
$query->cover = AppHelper::extractImagePath($this->_request->post('cover'));
|
||||
$query->title = $this->_request->post('title');
|
||||
$query->brand = $this->_request->post('brand');
|
||||
|
||||
$images = array_values($this->_request->post('images') ?: []);
|
||||
foreach ($images as &$image) {
|
||||
$image['src'] = AppHelper::extractImagePath($image['src']);
|
||||
}
|
||||
$query->images = json_encode($images);
|
||||
|
||||
$query->save();
|
||||
return true;
|
||||
}
|
||||
}
|
20
app/FormModel/api/v1/UserModel.php
Executable file
20
app/FormModel/api/v1/UserModel.php
Executable file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\api\v1;
|
||||
|
||||
use App\FormModel\api\BaseModel;
|
||||
use App\Model\AppUser;
|
||||
|
||||
class UserModel extends BaseModel
|
||||
{
|
||||
|
||||
public function register()
|
||||
{
|
||||
$query = new AppUser();
|
||||
$query->name = $this->_request->post('name');
|
||||
$query->password = md5($this->_request->post('password'));
|
||||
$query->email = $this->_request->post('email');
|
||||
$query->unique_id = uniqid("", true);
|
||||
$query->save();
|
||||
}
|
||||
}
|
11
app/FormModel/rpc/BaseModel.php
Executable file
11
app/FormModel/rpc/BaseModel.php
Executable file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\rpc;
|
||||
|
||||
class BaseModel
|
||||
{
|
||||
protected function getResponse(): BaseResponse
|
||||
{
|
||||
return new BaseResponse();
|
||||
}
|
||||
}
|
43
app/FormModel/rpc/v1/RpcIndexModel.php
Executable file
43
app/FormModel/rpc/v1/RpcIndexModel.php
Executable file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\rpc\v1;
|
||||
|
||||
use App\Listener\DbQueryExecutedListener;
|
||||
use App\Model\AppArticle;
|
||||
use Hyperf\Database\Query\Builder;
|
||||
use Hyperf\DbConnection\Db;
|
||||
|
||||
class RpcIndexModel
|
||||
{
|
||||
public function index(): array
|
||||
{
|
||||
$res = [];
|
||||
Db::beforeExecuting(function ($q) {
|
||||
var_dump($q);
|
||||
});
|
||||
|
||||
$minPublishedTime = strtotime('-1 month');
|
||||
|
||||
// $res['shows'] = [];
|
||||
$res['shows'] = AppArticle::formatQuery(['brand_name'])
|
||||
->select(['cover', 'aid', 'title', 'brand as brand_name', 'images_count', 'view_count'])
|
||||
->where([
|
||||
['module', 0],
|
||||
['published_status', 1],
|
||||
['year', '>=', 2022],
|
||||
['published_at', '>=', $minPublishedTime],
|
||||
])->orderBy('year', 'DESC')->orderBy('published_at', 'DESC')->limit(25)->get()->toArray();
|
||||
|
||||
$res['street'] = AppArticle::formatQuery(['location'])
|
||||
->select(['cover', 'aid', 'title', 'brand as brand_name', 'images_count', 'view_count', 'location'])
|
||||
->where([
|
||||
['module', 1],
|
||||
['published_status', 1],
|
||||
['year', '>=', 2022],
|
||||
['published_at', '>=', $minPublishedTime],
|
||||
])->orderBy('year', 'DESC')->orderBy('published_at', 'DESC')->limit(25)->get()->toArray();
|
||||
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
32
app/FormModel/spider/ReviewModel.php
Executable file
32
app/FormModel/spider/ReviewModel.php
Executable file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\spider;
|
||||
use App\Helpers\AppHelper;
|
||||
use App\Model\AppArticle;
|
||||
use App\Model\AppSpiderArticle;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
|
||||
class ReviewModel
|
||||
{
|
||||
#[Inject]
|
||||
private readonly RequestInterface $_request;
|
||||
|
||||
public function pass($spiderArticleId)
|
||||
{
|
||||
$query = AppSpiderArticle::find($spiderArticleId);
|
||||
$model = new AppArticle();
|
||||
$model->title = $query->title;
|
||||
$model->aid = AppHelper::generateAid();
|
||||
$model->cover = $query->cover;
|
||||
$model->images = $query->images;
|
||||
$model->year = $query->year;
|
||||
$model->module = $query->module;
|
||||
$model->brand = $query->brand;
|
||||
$model->spider_article_id = $spiderArticleId;
|
||||
$model->save();
|
||||
|
||||
$query->deleted_at = time();
|
||||
$query->save();
|
||||
}
|
||||
}
|
69
app/FormModel/spiderArticle/ReviewModel.php
Executable file
69
app/FormModel/spiderArticle/ReviewModel.php
Executable file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\spiderArticle;
|
||||
|
||||
use App\Enums\SpiderArticlePublishedStatusEnum;
|
||||
use App\Helpers\AppHelper;
|
||||
use App\Model\AppArticle;
|
||||
use App\Model\AppSpiderArticle;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
|
||||
class ReviewModel
|
||||
{
|
||||
#[Inject]
|
||||
private readonly RequestInterface $_request;
|
||||
|
||||
/**
|
||||
* 爬虫文章预发布
|
||||
* @param $spiderArticleId
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function prePublish($spiderArticleId)
|
||||
{
|
||||
try {
|
||||
Db::beginTransaction();
|
||||
|
||||
$query = AppSpiderArticle::find($spiderArticleId);
|
||||
|
||||
$model = new AppArticle();
|
||||
$model->title = $query->title;
|
||||
$model->aid = AppHelper::generateAid();
|
||||
$model->cover = $query->cover;
|
||||
$model->images = $query->images;
|
||||
$model->year = $query->year;
|
||||
$model->module = $query->module;
|
||||
$model->brand = $query->brand;
|
||||
$model->spider_article_id = $spiderArticleId;
|
||||
$model->published_status = 0;
|
||||
$model->save();
|
||||
|
||||
$query->published_status = SpiderArticlePublishedStatusEnum::TRUE->value;
|
||||
$query->published_at = time();
|
||||
$query->save();
|
||||
|
||||
Db::commit();
|
||||
} catch (\Throwable $throwable) {
|
||||
Db::rollBack();
|
||||
throw new \Exception($throwable->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($spiderArticleId)
|
||||
{
|
||||
try {
|
||||
Db::beginTransaction();
|
||||
|
||||
$query = AppSpiderArticle::find($spiderArticleId);
|
||||
$query->deleted_at = SpiderArticlePublishedStatusEnum::DELETE;
|
||||
$query->deleted_at = time();
|
||||
$query->save();
|
||||
Db::commit();
|
||||
} catch (\Throwable $throwable) {
|
||||
Db::rollBack();
|
||||
throw new \Exception($throwable->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user