new_naweigete/crmeb/app/services/crud/LeaveWordServices.php

111 lines
2.9 KiB
PHP
Raw Normal View History

2025-03-17 10:04:28 +08:00
<?php
/**
* +----------------------------------------------------------------------
* | CRMEB [ CRMEB赋能开发者助力企业发展 ]
* +----------------------------------------------------------------------
* | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
* +----------------------------------------------------------------------
* | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
* +----------------------------------------------------------------------
* | Author: CRMEB Team <admin@crmeb.com>
* +----------------------------------------------------------------------
*/
/**
* 联系我们留言
* @author crud自动生成代码
* @date 2025/03/13 11:55:43
*/
namespace app\services\crud;
use app\services\BaseServices;
use think\exception\ValidateException;
use app\dao\crud\LeaveWordDao;
use crmeb\services\FormBuilder;
/**
* Class CrudService
* @date 2025/03/13
* @package app\services\crud
*/
class LeaveWordServices extends BaseServices
{
/**
* LeaveWordServices constructor.
* @param LeaveWordDao $dao
*/
public function __construct(LeaveWordDao $dao)
{
$this->dao = $dao;
}
/**
* 主页数据接口
* @param array $where
* @return array
* @date 2025/03/13
*/
public function getCrudListIndex(array $where = [])
{
[$page, $limit] = $this->getPageValue();
$model = $this->dao->searchCrudModel($where, 'name,mobile,content,create_time,id', 'id desc', []);
return ['count' => $model->count(), 'list' => $model->page($page ?: 1, $limit ?: 10)->select()->toArray()];
}
/**
* 编辑和获取表单
* @date 2025/03/13
* @param int $id
* @return array
*/
public function getCrudForm(int $id = 0)
{
$url = '/crud/leave_word';
$info = [];
if ($id) {
$info = $this->dao->get($id);
if (!$info) {
throw new ValidateException(100026);
}
$url .= '/' . $id;
}
$rule = [];
$rule[] = FormBuilder::input("name", "姓名", $info["name"] ?? '');
$rule[] = FormBuilder::input("mobile", "联系方式", $info["mobile"] ?? '');
$rule[] = FormBuilder::textarea("content", "留言", $info["content"] ?? '');
$rule[] = FormBuilder::dateTime("create_time", "添加时间", $info["create_time"] ?? '');
return create_form('联系我们留言', $rule, $url, $id ? 'PUT' : 'POST');
}
/**
* 新增
* @date 2025/03/13
* @param array $data
* @return mixed
*/
public function crudSave(array $data)
{
return $this->dao->save($data);
}
/**
* 修改
* @date 2025/03/13
* @param int $id
* @param array $data
* @return \crmeb\basic\BaseModel
*/
public function crudUpdate(int $id, array $data)
{
return $this->dao->update($id, $data);
}
}