Files
huangjingfen/pro_v3.5.1/app/controller/admin/v1/work/Welcome.php
panchengyong c1e74d8e68 chore(php): 统一 ScottPan 文件头与注释域名替换
- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明

Made-with: Cursor
2026-03-29 11:22:58 +08:00

143 lines
3.4 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | Author: ScottPan Team
// +----------------------------------------------------------------------
namespace app\controller\admin\v1\work;
use app\controller\admin\AuthController;
use app\services\work\WorkWelcomeServices;
use think\annotation\Inject;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/**
* 企业微信欢迎语
* Class Welcome
* @package app\controller\admin\v1\work
*/
class Welcome extends AuthController
{
/**
* @var WorkWelcomeServices
*/
#[Inject]
protected WorkWelcomeServices $services;
/**
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function index()
{
$where = $this->request->getMore([
['add_time', ''],
['userids', []]
]);
return $this->success($this->services->getList($where));
}
/**
* 欢迎语
* @param $id
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function read($id)
{
if (!$id) {
return $this->fail('缺少参数');
}
return $this->success($this->services->getWelcomeInfo((int)$id));
}
/**
* 保存
* @return mixed
*/
public function save()
{
$data = $this->request->postMore([
['type', 0],
['content', ''],
['attachments', []],
['userids', []],
['sort', 0]
]);
if (!$data['attachments'] && !$data['content']) {
return $this->fail('欢迎语内容和欢迎语消息体不能同时为空');
}
if (!$data['content']) {
return $this->fail('缺少消息内容');
}
if ($data['type'] == 1 && !$data['userids']) {
return $this->fail('至少选择一个成员');
}
if ($this->services->saveWelcome($data)) {
return $this->success('添加成功');
} else {
return $this->fail('添加失败');
}
}
/**
* 修改
* @param $id
* @return mixed
*/
public function update($id)
{
$data = $this->request->postMore([
['type', 0],
['content', ''],
['attachments', []],
['userids', []],
['sort', 0]
]);
if (!$data['attachments'] && !$data['content']) {
return $this->fail('欢迎语内容和欢迎语消息体不能同时为空');
}
if (!$data['content']) {
return $this->fail('缺少消息内容');
}
if ($data['type'] == 1 && !$data['userids']) {
return $this->fail('至少选择一个成员');
}
if ($this->services->saveWelcome($data, (int)$id)) {
return $this->success('修改成功');
} else {
return $this->fail('修改失败');
}
}
/**
* 删除
* @param $id
* @return mixed
*/
public function delete($id)
{
if (!$id) {
return $this->fail('缺少参数');
}
if ($this->services->deleteWelcome($id)) {
return $this->success('删除成功');
} else {
return $this->fail('删除失败');
}
}
}