feat 添加爱情故事接口
This commit is contained in:
parent
60bfa1390c
commit
7dc456195e
82
app/api/controller/LoveStory/LoveStory.php
Normal file
82
app/api/controller/LoveStory/LoveStory.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\LoveStory;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\LoveStory\LoveStory as ModelLoveStory;
|
||||
use app\Request;
|
||||
use think\Validate;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Filesystem;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\common\arw\adjfut\src\UploadFile;
|
||||
use think\facade\Db;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Env;
|
||||
|
||||
|
||||
class LoveStory extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取爱情故事列表
|
||||
*/
|
||||
public function getLoveStoryList(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$con = [];
|
||||
|
||||
$con = Tool::getOptionalQuery(['love_story_title', 'LIKE'], ['love_story_place', 'LIKE'],);
|
||||
|
||||
$query = ModelLoveStory::where($con)
|
||||
->field([
|
||||
'love_story_id',
|
||||
'love_story_title',
|
||||
'love_story_author',
|
||||
'love_story_place',
|
||||
'love_story_date',
|
||||
'love_story_cover',
|
||||
])
|
||||
->order('love_story_sort', 'asc');
|
||||
|
||||
return msg("获取爱情故事列表成功!", $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取爱情故事详情
|
||||
*/
|
||||
public function getLoveStoryInfo(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
|
||||
$this->validate($params, ['love_story_id' => 'require']);
|
||||
|
||||
$find = ModelLoveStory::field([
|
||||
'love_story_id',
|
||||
'love_story_title',
|
||||
'love_story_author',
|
||||
'love_story_place',
|
||||
'love_story_date',
|
||||
'love_story_cover',
|
||||
'love_story_sort',
|
||||
'love_story_music',
|
||||
'love_story_content'
|
||||
])
|
||||
->append(['love_story_music_name'])
|
||||
->where('love_story_id', $params['love_story_id'])
|
||||
->find();
|
||||
|
||||
// 上下个数据返回
|
||||
$last_next = Tool::getLastNextData(
|
||||
ModelLoveStory::class,
|
||||
$find->love_story_sort,
|
||||
[
|
||||
'field' => ['love_story_id', 'love_story_title'],
|
||||
'extraWhere' => [],
|
||||
]
|
||||
);
|
||||
$find['prve'] = $last_next[0];
|
||||
$find['next'] = $last_next[1];
|
||||
|
||||
return msg(0, '获取爱情故事详情成功!', ['data' => $find]);
|
||||
}
|
||||
}
|
@ -141,7 +141,7 @@ class LoveStory extends BaseModel
|
||||
*
|
||||
* @param \app\common\arw\adjfut\src\UploadFile $file excel
|
||||
*/
|
||||
public static function importExcel(\app\common\arw\adjfut\src\UploadFile $file): string
|
||||
public static function importExcel(\app\common\arw\adjfut\src\UploadFile $file)
|
||||
{
|
||||
$msg = [];
|
||||
|
||||
@ -157,7 +157,7 @@ class LoveStory extends BaseModel
|
||||
foreach ($data as $line => $value) {
|
||||
try {
|
||||
$model = self::importExcelInit($value);
|
||||
$msg[] = "{$line} <span style='color:#27af49'>新增成功!</span><br>";
|
||||
$msg[] = "{$line} <span style='color:#27af49'>【{$value['love_story_title']}】新增成功!</span><br>";
|
||||
} catch (\Throwable $th) {
|
||||
$msg[] = "{$line} <span style='color:red'>{$th->getMessage()}</span><br>";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user