Files
fast/addons/shopro/controller/zy/Base.php
xiadc 98eda4e5ff feat(zy): 添加俱乐部功能和用户消息功能
- 新增俱乐部相关接口和功能,包括创建俱乐部、申请加入俱乐部、邀请加入俱乐部等
- 添加用户消息功能,包括发送消息、查看消息等
- 优化了部分代码结构,提高了可维护性
- 更新了文档,添加了新的接口说明
2025-05-04 11:11:44 +08:00

87 lines
2.1 KiB
PHP

<?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 $noNeedLogin = [];
protected $noNeedRight = ['*'];
protected $model;
protected $user;
public function _initialize()
{
parent::_initialize();
$this->user = auth_user();
}
public function index()
{
$params = $this->request->param();
if (isset($params['name'])) {
$this->model->where('name', 'like', '%' . $params['name'] . '%');
}
$res = $this->model->select();
$this->success('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('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('Success');
}
public function view()
{
$model = $this->model->get($this->request->param('id'));
if (empty($model)) {
$this->error(__('No rows were found'));
}
$this->success('Success', $model);
}
}