add:标签,球馆
This commit is contained in:
80
addons/shopro/controller/zy/Gym.php
Normal file
80
addons/shopro/controller/zy/Gym.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\controller\zy;
|
||||
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use app\admin\model\zy\Stadium;
|
||||
use think\exception\PDOException;
|
||||
use addons\shopro\controller\Common;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
class Gym extends Common
|
||||
{
|
||||
|
||||
// protected $noNeedLogin = ['index'];
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
public function index()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$model = Stadium::where('status', 1);
|
||||
if (isset($params['name'])) {
|
||||
$model->where('name', 'like', '%' . $params['name'] . '%');
|
||||
}
|
||||
$res = $model->select();
|
||||
|
||||
|
||||
$this->success('获取成功', $res);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$result = false;
|
||||
$params = $this->request->param();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$result = (new Stadium)->allowField(true)->save($params);
|
||||
Db::commit();
|
||||
} catch (ValidateException | PDOException | Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result === false) {
|
||||
$this->error(__('No rows were inserted'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
$result = false;
|
||||
$params = $this->request->param();
|
||||
$model = Stadium::get($params['id']);
|
||||
if (empty($model)) {
|
||||
$this->error(__('No rows were found'));
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$result = $model->allowField(true)->save($params);
|
||||
Db::commit();
|
||||
} catch (ValidateException | PDOException | Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result === false) {
|
||||
$this->error(__('No rows were inserted'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function view()
|
||||
{
|
||||
$model = Stadium::get($this->request->param('id'));
|
||||
if (empty($model)) {
|
||||
$this->error(__('No rows were found'));
|
||||
}
|
||||
$this->success($model);
|
||||
}
|
||||
}
|
||||
32
addons/shopro/controller/zy/Tags.php
Normal file
32
addons/shopro/controller/zy/Tags.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\controller\zy;
|
||||
|
||||
use app\admin\model\zy\Tags as TagsModel;
|
||||
use addons\shopro\controller\Common;
|
||||
|
||||
class Tags extends Common
|
||||
{
|
||||
|
||||
// protected $noNeedLogin = ['index'];
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
public function index()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$model = new TagsModel();
|
||||
if (isset($params['type'])) {
|
||||
$model->where('type', $params['type']);
|
||||
}
|
||||
if (isset($params['group'])) {
|
||||
$model->where('group', $params['group']);
|
||||
}
|
||||
$res = $model->select();
|
||||
foreach ($res as &$value) {
|
||||
$value['content_json'] = array_values(json_decode($value['content_json'] ?? '[]', true));
|
||||
}
|
||||
|
||||
$this->success('获取成功', $res);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user