pull/5/head
parent
8851983a77
commit
c6c16124d4
@ -0,0 +1,100 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: 萤火科技 <admin@yiovo.com> |
||||
// +---------------------------------------------------------------------- |
||||
declare (strict_types=1); |
||||
|
||||
namespace app\store\controller; |
||||
|
||||
use app\common\model\successful as SuccessfulModel; |
||||
use app\common\model\UploadFile; |
||||
use think\response\Json; |
||||
|
||||
class Successful extends Controller |
||||
{ |
||||
/** |
||||
* 成功案例列表 |
||||
* @return json |
||||
*/ |
||||
public function getList() |
||||
{ |
||||
$model = new SuccessfulModel; |
||||
$page = $this->request->param('page',1); |
||||
$pageSize = $this->request->param('pageSize',15); |
||||
$list = $model->list($page,$pageSize); |
||||
if(empty($list)){ |
||||
return $this->renderSuccess('暂无数据'); |
||||
} |
||||
$list->each(function ($item, $key) { |
||||
$imageUrl = UploadFile::withoutGlobalScope()->where('file_id', $item['image_id'])->find(); |
||||
if ($imageUrl) { |
||||
$item['image_url'] = $imageUrl['preview_url']; |
||||
} else { |
||||
$item['image_url'] = null; // 或者设置默认图片 URL |
||||
} |
||||
}); |
||||
|
||||
return $this->renderSuccess(compact('list')); |
||||
} |
||||
|
||||
/** |
||||
* @notes:新增 |
||||
* @return Json |
||||
* |
||||
*/ |
||||
public function add(): Json |
||||
{ |
||||
$data = $this->postForm(); |
||||
if (!$data) { |
||||
return $this->renderError('缺少必要参数'); |
||||
} |
||||
$model = new SuccessfulModel(); |
||||
if ($model->add($data)) { |
||||
return $this->renderSuccess('添加成功'); |
||||
} |
||||
return $this->renderError($model->getError() ?: '添加失败'); |
||||
} |
||||
|
||||
/** |
||||
* @notes:编辑 |
||||
* @param int $id |
||||
* @return Json |
||||
* @author: |
||||
*/ |
||||
public function edit(int $id): Json |
||||
{ |
||||
$data = $this->postForm(); |
||||
if (!$data) { |
||||
return $this->renderError('缺少必要参数'); |
||||
} |
||||
$model = SuccessfulModel::where('id', $id)->find(); |
||||
if (!$model) { |
||||
return $this->renderError('找不到指定的数据'); |
||||
} |
||||
$data['update_time']=time(); |
||||
SuccessfulModel::where('id', $id)->update($data); |
||||
return $this->renderSuccess('编辑成功'); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* @notes:删除 |
||||
* @param array $ids |
||||
* @return Json |
||||
* @author: |
||||
*/ |
||||
public function delete(array $ids): Json |
||||
{ |
||||
$model = new SuccessfulModel; |
||||
if ($model->remove($ids)) { |
||||
return $this->renderSuccess('删除成功'); |
||||
} |
||||
return $this->renderError('删除失败'); |
||||
} |
||||
} |
Loading…
Reference in new issue