Browse Source
feat(portrait): 新增企业画像图库功能
feat(portrait): 新增企业画像图库功能
- 新增企业画像图库分类模型及控制器 - 新增企业画像图库模型及控制器 - 实现图库分类的增删改查功能 - 实现图库文件的增删查功能 - 添加相关验证规则和路由配置 - 更新知识库模型注释描述 - 修复路由权限标识错误问题master
13 changed files with 480 additions and 5 deletions
-
53app/controller/EnterprisePortraitCategoryController.php
-
39app/controller/EnterprisePortraitLibraryController.php
-
15app/dao/EnterprisePortraitCategoryDao.php
-
15app/dao/EnterprisePortraitLibraryDao.php
-
2app/model/DistillationQuestions.php
-
37app/model/EnterprisePortraitCategory.php
-
37app/model/EnterprisePortraitLibrary.php
-
2app/model/KnowLedgeLibrary.php
-
32app/route/route.php
-
120app/service/EnterprisePortraitCategoryService.php
-
92app/service/EnterprisePortraitLibraryService.php
-
22app/validate/EnterprisePortraitCategoryValidate.php
-
19app/validate/EnterprisePortraitLibraryValidate.php
@ -0,0 +1,53 @@ |
|||
<?php |
|||
namespace app\controller; |
|||
|
|||
use app\service\EnterprisePortraitCategoryService; |
|||
use app\validate\EnterprisePortraitCategoryValidate; |
|||
use plugin\piadmin\app\utils\ArrayUtils; |
|||
use support\Response; |
|||
|
|||
class EnterprisePortraitCategoryController |
|||
{ |
|||
public function save(EnterprisePortraitCategoryService $service): Response |
|||
{ |
|||
$params = requestOnly([ |
|||
'name' => '', |
|||
]); |
|||
validate(EnterprisePortraitCategoryValidate::class)->check($params, 'save'); |
|||
return success($service->saveData($params)); |
|||
} |
|||
|
|||
public function update(EnterprisePortraitCategoryService $service): Response |
|||
{ |
|||
$params = requestOnly([ |
|||
'id' => '', |
|||
'name' => '', |
|||
]); |
|||
validate(EnterprisePortraitCategoryValidate::class)->check($params, 'update'); |
|||
return success($service->updateData(ArrayUtils::filterNotEmpty($params))); |
|||
} |
|||
|
|||
public function index(EnterprisePortraitCategoryService $service): Response |
|||
{ |
|||
$params = requestOnly([ |
|||
'name' => '', |
|||
'begin_time' => '', |
|||
'end_time' => '' |
|||
]); |
|||
return success($service->listData($params)); |
|||
} |
|||
|
|||
public function read(EnterprisePortraitCategoryService $service): Response |
|||
{ |
|||
$id = input('id'); |
|||
return success($service->readData($id)); |
|||
} |
|||
|
|||
public function delete(EnterprisePortraitCategoryService $service): Response |
|||
{ |
|||
$id = input('id'); |
|||
return success($service->deleteData($id)); |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
<?php |
|||
namespace app\controller; |
|||
|
|||
use app\service\EnterprisePortraitLibraryService; |
|||
use app\validate\EnterprisePortraitLibraryValidate; |
|||
use support\Response; |
|||
|
|||
class EnterprisePortraitLibraryController |
|||
{ |
|||
public function save(EnterprisePortraitLibraryService $service): Response |
|||
{ |
|||
$params = requestOnly([ |
|||
'category_id' => '', |
|||
'url' => '', |
|||
]); |
|||
validate(EnterprisePortraitLibraryValidate::class)->check($params, 'save'); |
|||
return success($service->saveData($params)); |
|||
} |
|||
|
|||
public function index(EnterprisePortraitLibraryService $service): Response |
|||
{ |
|||
$params = requestOnly([ |
|||
'category_id' => '', |
|||
'category' => '', |
|||
'use_count' => '', |
|||
'begin_time' => '', |
|||
'end_time' => '' |
|||
]); |
|||
return success($service->listData($params)); |
|||
} |
|||
|
|||
public function delete(EnterprisePortraitLibraryService $service): Response |
|||
{ |
|||
$id = input('id'); |
|||
return success($service->deleteData($id)); |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
<?php |
|||
|
|||
namespace app\dao; |
|||
|
|||
use app\model\EnterprisePortraitCategory; |
|||
use plugin\piadmin\app\base\BaseDao; |
|||
|
|||
class EnterprisePortraitCategoryDao extends BaseDao |
|||
{ |
|||
protected function setModel(): string |
|||
{ |
|||
return EnterprisePortraitCategory::class; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
<?php |
|||
|
|||
namespace app\dao; |
|||
|
|||
use app\model\EnterprisePortraitLibrary; |
|||
use plugin\piadmin\app\base\BaseDao; |
|||
|
|||
class EnterprisePortraitLibraryDao extends BaseDao |
|||
{ |
|||
protected function setModel(): string |
|||
{ |
|||
return EnterprisePortraitLibrary::class; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
<?php |
|||
|
|||
namespace app\model; |
|||
|
|||
use plugin\piadmin\app\base\BaseModel; |
|||
|
|||
/** |
|||
* 企业画像图库-分类模型 |
|||
*/ |
|||
class EnterprisePortraitCategory extends BaseModel |
|||
{ |
|||
/** |
|||
* The table associated with the model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $table = 'geo_enterprise_portrait_category'; |
|||
|
|||
/** |
|||
* The primary key associated with the table. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $primaryKey = 'id'; |
|||
|
|||
/** |
|||
* Indicates if the model should be timestamped. |
|||
* |
|||
* @var bool |
|||
*/ |
|||
public $timestamps = true; |
|||
|
|||
public function files() |
|||
{ |
|||
return $this->hasMany(EnterprisePortraitLibrary::class, 'category_id', 'id'); |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
<?php |
|||
|
|||
namespace app\model; |
|||
|
|||
use plugin\piadmin\app\base\BaseModel; |
|||
|
|||
/** |
|||
* 企业画像图库模型 |
|||
*/ |
|||
class EnterprisePortraitLibrary extends BaseModel |
|||
{ |
|||
/** |
|||
* The table associated with the model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $table = 'geo_enterprise_portrait_library'; |
|||
|
|||
/** |
|||
* The primary key associated with the table. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $primaryKey = 'id'; |
|||
|
|||
/** |
|||
* Indicates if the model should be timestamped. |
|||
* |
|||
* @var bool |
|||
*/ |
|||
public $timestamps = true; |
|||
|
|||
public function category() |
|||
{ |
|||
return $this->belongsTo(EnterprisePortraitCategory::class, 'category_id', 'id'); |
|||
} |
|||
} |
|||
@ -0,0 +1,120 @@ |
|||
<?php |
|||
|
|||
namespace app\service; |
|||
|
|||
use app\dao\EnterprisePortraitCategoryDao; |
|||
use app\dao\EnterprisePortraitLibraryDao; |
|||
use plugin\piadmin\app\base\BaseService; |
|||
use plugin\piadmin\app\exception\ApiException; |
|||
use support\think\Db; |
|||
|
|||
class EnterprisePortraitCategoryService extends BaseService |
|||
{ |
|||
|
|||
protected $dao; |
|||
protected $libraryDao; |
|||
|
|||
public function __construct(EnterprisePortraitCategoryDao $dao) |
|||
{ |
|||
$this->dao = $dao; |
|||
$this->libraryDao = app()->make(EnterprisePortraitLibraryDao::class); |
|||
} |
|||
|
|||
/** |
|||
* 保存信息 |
|||
* @param array $params |
|||
* @return array |
|||
*/ |
|||
public function saveData(array $params): array |
|||
{ |
|||
Db::startTrans(); |
|||
try { |
|||
$data = $this->dao->save($params); |
|||
Db::commit(); |
|||
} catch (\Exception $exception) { |
|||
Db::rollback(); |
|||
throw new ApiException($exception->getMessage()); |
|||
} |
|||
return $data->toArray(); |
|||
} |
|||
|
|||
/** |
|||
* 修改信息 |
|||
* @param array $params |
|||
* @return array |
|||
*/ |
|||
public function updateData(array $params): array |
|||
{ |
|||
// 落库
|
|||
Db::startTrans(); |
|||
try { |
|||
$this->dao->update(['id' => $params['id']], $params); |
|||
Db::commit(); |
|||
} catch (\Exception $exception) { |
|||
Db::rollback(); |
|||
throw new ApiException($exception->getMessage()); |
|||
} |
|||
return $params; |
|||
} |
|||
|
|||
/** |
|||
* 获取列表 |
|||
* @param array $params |
|||
* @return array |
|||
*/ |
|||
public function listData(array $params): array |
|||
{ |
|||
$query = [ |
|||
'delete_time' => 0 |
|||
]; |
|||
if (isNotBlank($params['name'])) { |
|||
$query[] = ['name', 'like', '%' . $params['name'] . '%']; |
|||
} |
|||
if (isNotBlank($params['begin_time'])) { |
|||
$query[] = ['create_time', '>=', strtotime($params['begin_time'])]; |
|||
} |
|||
if (isNotBlank($params['end_time'])) { |
|||
$query[] = ['create_time', '<=', strtotime($params['end_time'] . ' 23:59:59')]; |
|||
} |
|||
$list = $this->dao->getList($query, '*', 0, 0, 'id DESC', [], ['files']); |
|||
$count = $this->dao->getCount($query); |
|||
return compact('list', 'count'); |
|||
} |
|||
|
|||
/** |
|||
* 获取信息 |
|||
* @param mixed $id |
|||
* @return array |
|||
*/ |
|||
public function readData(mixed $id): array |
|||
{ |
|||
$category = $this->dao->get(['id' => $id]); |
|||
if (empty($category)) { |
|||
throw new ApiException('数据不存在'); |
|||
} |
|||
return $category->toArray(); |
|||
} |
|||
|
|||
/** |
|||
* 删除信息 |
|||
* @param mixed $id |
|||
* @return array |
|||
*/ |
|||
public function deleteData(mixed $id): array |
|||
{ |
|||
// 落库
|
|||
Db::startTrans(); |
|||
try { |
|||
//删除表
|
|||
$this->dao->update($id, ['delete_time' => time()]); |
|||
//删图库
|
|||
$this->libraryDao->update(['category_id' => $id], ['delete_time' => time()]); |
|||
Db::commit(); |
|||
} catch (\Exception $exception) { |
|||
Db::rollback(); |
|||
throw new ApiException($exception->getMessage()); |
|||
} |
|||
return ['id' => $id]; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,92 @@ |
|||
<?php |
|||
|
|||
namespace app\service; |
|||
|
|||
use app\dao\EnterprisePortraitCategoryDao; |
|||
use app\dao\EnterprisePortraitLibraryDao; |
|||
use plugin\piadmin\app\base\BaseService; |
|||
use plugin\piadmin\app\exception\ApiException; |
|||
use support\think\Db; |
|||
|
|||
class EnterprisePortraitLibraryService extends BaseService |
|||
{ |
|||
|
|||
protected $dao; |
|||
protected $categoryDao; |
|||
|
|||
public function __construct(EnterprisePortraitLibraryDao $dao) |
|||
{ |
|||
$this->dao = $dao; |
|||
$this->categoryDao = app()->make(EnterprisePortraitCategoryDao::class); |
|||
} |
|||
|
|||
/** |
|||
* 保存信息 |
|||
* @param array $params |
|||
* @return array |
|||
*/ |
|||
public function saveData(array $params): array |
|||
{ |
|||
Db::startTrans(); |
|||
try { |
|||
$data = $this->dao->save($params); |
|||
Db::commit(); |
|||
} catch (\Exception $exception) { |
|||
Db::rollback(); |
|||
throw new ApiException($exception->getMessage()); |
|||
} |
|||
return $data->toArray(); |
|||
} |
|||
|
|||
/** |
|||
* 获取列表 |
|||
* @param array $params |
|||
* @return array |
|||
*/ |
|||
public function listData(array $params): array |
|||
{ |
|||
$query = [ |
|||
'delete_time' => 0 |
|||
]; |
|||
if (isNotBlank($params['category_id']) && empty($params['category'])) { |
|||
$query[] = ['category_id', '=', $params['category_id']]; |
|||
} |
|||
if (isNotBlank($params['category'])) { |
|||
$cids = $this->categoryDao->getColumn([['name', 'like', '%' . $params['category'] . '%']], 'id'); |
|||
$query[] = ['category_id', 'in', $cids]; |
|||
} |
|||
if (isNotBlank($params['use_count'])) { |
|||
$query[] = ['use_count', '=', $params['use_count']]; |
|||
} |
|||
if (isNotBlank($params['begin_time'])) { |
|||
$query[] = ['create_time', '>=', strtotime($params['begin_time'])]; |
|||
} |
|||
if (isNotBlank($params['end_time'])) { |
|||
$query[] = ['create_time', '<=', strtotime($params['end_time'] . ' 23:59:59')]; |
|||
} |
|||
$list = $this->dao->getList($query, '*', 0, 0, 'id desc', ['category']); |
|||
$count = $this->dao->getCount($query); |
|||
return compact('list', 'count'); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 删除信息 |
|||
* @param mixed $id |
|||
* @return array |
|||
*/ |
|||
public function deleteData(mixed $id): array |
|||
{ |
|||
// 落库
|
|||
Db::startTrans(); |
|||
try { |
|||
$this->dao->update($id, ['delete_time' => time()]); |
|||
Db::commit(); |
|||
} catch (\Exception $exception) { |
|||
Db::rollback(); |
|||
throw new ApiException($exception->getMessage()); |
|||
} |
|||
return ['id' => $id]; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
<?php |
|||
|
|||
namespace app\validate; |
|||
|
|||
use plugin\piadmin\app\base\BaseValidate; |
|||
|
|||
class EnterprisePortraitCategoryValidate extends BaseValidate |
|||
{ |
|||
protected $group = [ |
|||
'save' => [ |
|||
'name' => 'require', |
|||
], |
|||
'update' => [ |
|||
'id' => 'require', |
|||
'name' => 'require', |
|||
] |
|||
]; |
|||
protected $message = [ |
|||
'id.require' => 'ID不能为空', |
|||
'name.require' => '分类不能为空', |
|||
]; |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
<?php |
|||
|
|||
namespace app\validate; |
|||
|
|||
use plugin\piadmin\app\base\BaseValidate; |
|||
|
|||
class EnterprisePortraitLibraryValidate extends BaseValidate |
|||
{ |
|||
protected $group = [ |
|||
'save' => [ |
|||
'category_id' => 'require', |
|||
'url' => 'require', |
|||
], |
|||
]; |
|||
protected $message = [ |
|||
'category_id.require' => '分类ID不能为空', |
|||
'url.require' => '图片地址不能为空', |
|||
]; |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue