add:俱乐部
This commit is contained in:
75
addons/shopro/controller/zy/Base.php
Normal file
75
addons/shopro/controller/zy/Base.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\controller\zy;
|
||||
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\exception\PDOException;
|
||||
use addons\shopro\controller\Common;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
class Base extends Common
|
||||
{
|
||||
protected $model;
|
||||
|
||||
public function index()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
if (isset($params['name'])) {
|
||||
$this->model->where('name', 'like', '%' . $params['name'] . '%');
|
||||
}
|
||||
$res = $this->model->select();
|
||||
|
||||
|
||||
$this->success('获取成功', $res);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$result = false;
|
||||
$params = $this->request->param();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$result = $this->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 update()
|
||||
{
|
||||
$result = false;
|
||||
$params = $this->request->param();
|
||||
$model = $this->model->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 = $this->model->get($this->request->param('id'));
|
||||
if (empty($model)) {
|
||||
$this->error(__('No rows were found'));
|
||||
}
|
||||
$this->success($model);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user