数据库: - db/schema_phase1.sql 16 张业务表(类目/服务/地址/师傅/订单/流水/取证/报价/评价/券/钱包/提现/结算/消息) - db/seed_phase1.sql 15 类目 + 32 服务项目 + 新人券(幂等) 后端 API (application/api/controller): - Base/Auth/Home/Address/Order/Master/Review - app/common/library/OrderStatus 11 状态机 + 流转矩阵 - application/api/common.php PHP 8.5 兼容垫片(E_DEPRECATED 不再升级为异常) 测试: - tests/e2e_flow.js 用户下单→支付→师傅抢单→履约→验收→结算→评价 全链路 65 项断言 - 含异常用例:越权/重复操作/非法状态流转/2h 未联系自动回流
160 行
5.1 KiB
PHP
可执行文件
160 行
5.1 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\common\controller\Backend;
|
|
use app\common\model\Category as CategoryModel;
|
|
use fast\Tree;
|
|
|
|
/**
|
|
* 分类管理
|
|
*
|
|
* @icon fa fa-list
|
|
* @remark 用于管理网站的所有分类,分类可进行无限级分类,分类类型请在常规管理->系统配置->字典配置中添加
|
|
*/
|
|
class Category extends Backend
|
|
{
|
|
|
|
/**
|
|
* @var \app\common\model\Category
|
|
*/
|
|
protected $model = null;
|
|
protected $categorylist = [];
|
|
protected $noNeedRight = ['selectpage'];
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->model = model('app\common\model\Category');
|
|
|
|
$tree = Tree::instance();
|
|
$tree->init(collection($this->model->order('weigh desc,id desc')->select())->toArray(), 'pid');
|
|
$this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
|
|
$categorydata = [0 => ['type' => 'all', 'name' => __('None')]];
|
|
foreach ($this->categorylist as $k => $v) {
|
|
$categorydata[$v['id']] = $v;
|
|
}
|
|
$typeList = CategoryModel::getTypeList();
|
|
$this->view->assign("flagList", $this->model->getFlagList());
|
|
$this->view->assign("typeList", $typeList);
|
|
$this->view->assign("parentList", $categorydata);
|
|
$this->assignconfig('typeList', $typeList);
|
|
}
|
|
|
|
/**
|
|
* 查看
|
|
*/
|
|
public function index()
|
|
{
|
|
//设置过滤方法
|
|
$this->request->filter(['strip_tags']);
|
|
if ($this->request->isAjax()) {
|
|
$search = $this->request->request("search");
|
|
$type = $this->request->request("type");
|
|
|
|
//构造父类select列表选项数据
|
|
$list = [];
|
|
|
|
foreach ($this->categorylist as $k => $v) {
|
|
if ($search) {
|
|
if ($v['type'] == $type && stripos($v['name'], $search) !== false || stripos($v['nickname'], $search) !== false) {
|
|
if ($type == "all" || $type == null) {
|
|
$list = $this->categorylist;
|
|
} else {
|
|
$list[] = $v;
|
|
}
|
|
}
|
|
} else {
|
|
if ($type == "all" || $type == null) {
|
|
$list = $this->categorylist;
|
|
} elseif ($v['type'] == $type) {
|
|
$list[] = $v;
|
|
}
|
|
}
|
|
}
|
|
|
|
$total = count($list);
|
|
$result = array("total" => $total, "rows" => $list);
|
|
|
|
return json($result);
|
|
}
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
/**
|
|
* 添加
|
|
*/
|
|
public function add()
|
|
{
|
|
if ($this->request->isPost()) {
|
|
$this->token();
|
|
}
|
|
return parent::add();
|
|
}
|
|
|
|
/**
|
|
* 编辑
|
|
*/
|
|
public function edit($ids = null)
|
|
{
|
|
$row = $this->model->get($ids);
|
|
if (!$row) {
|
|
$this->error(__('No Results were found'));
|
|
}
|
|
$adminIds = $this->getDataLimitAdminIds();
|
|
if (is_array($adminIds)) {
|
|
if (!in_array($row[$this->dataLimitField], $adminIds)) {
|
|
$this->error(__('You have no permission'));
|
|
}
|
|
}
|
|
if ($this->request->isPost()) {
|
|
$this->token();
|
|
$params = $this->request->post("row/a");
|
|
if ($params) {
|
|
$params = $this->preExcludeFields($params);
|
|
$params = $this->preExcludePrimaryKey($params);
|
|
|
|
if ($params['pid'] != $row['pid']) {
|
|
$childrenIds = Tree::instance()->init(collection(\app\common\model\Category::select())->toArray())->getChildrenIds($row['id'], true);
|
|
if (in_array($params['pid'], $childrenIds)) {
|
|
$this->error(__('Can not change the parent to child or itself'));
|
|
}
|
|
}
|
|
|
|
try {
|
|
//是否采用模型验证
|
|
if ($this->modelValidate) {
|
|
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
|
|
$row->validate($validate);
|
|
}
|
|
$result = $row->allowField(true)->save($params);
|
|
if ($result !== false) {
|
|
$this->success();
|
|
} else {
|
|
$this->error($row->getError());
|
|
}
|
|
} catch (\think\exception\PDOException $e) {
|
|
$this->error($e->getMessage());
|
|
} catch (\think\Exception $e) {
|
|
$this->error($e->getMessage());
|
|
}
|
|
}
|
|
$this->error(__('Parameter %s can not be empty', ''));
|
|
}
|
|
$this->view->assign("row", $row);
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
|
|
/**
|
|
* Selectpage搜索
|
|
*
|
|
* @internal
|
|
*/
|
|
public function selectpage()
|
|
{
|
|
return parent::selectpage();
|
|
}
|
|
}
|