feat(api): 全链路后端 + 数据库设计 + E2E 测试(65 项断言全通过)
数据库: - 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 未联系自动回流
这个提交包含在:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\admin\model\WechatResponse;
|
||||
|
||||
/**
|
||||
* 微信自动回复管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Autoreply extends Backend
|
||||
{
|
||||
|
||||
protected $model = null;
|
||||
protected $noNeedRight = ['check_text_unique'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = model('WechatAutoreply');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
$row = $this->model->get(['id' => $ids]);
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->post("row/a");
|
||||
if ($params) {
|
||||
$row->save($params);
|
||||
$this->success();
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
$response = WechatResponse::get(['eventkey' => $row['eventkey']]);
|
||||
$this->view->assign("response", $response);
|
||||
$this->view->assign("row", $row);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断文本是否唯一
|
||||
* @internal
|
||||
*/
|
||||
public function check_text_unique()
|
||||
{
|
||||
$row = $this->request->post("row/a");
|
||||
$except = $this->request->post("except");
|
||||
$text = isset($row['text']) ? $row['text'] : '';
|
||||
if ($this->model->where('text', $text)->where(function ($query) use ($except) {
|
||||
if ($except) {
|
||||
$query->where('text', '<>', $except);
|
||||
}
|
||||
})->count() == 0) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error(__('Text already exists'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Controller;
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* 微信配置管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Config extends Backend
|
||||
{
|
||||
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = model('WechatConfig');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->post("row/a");
|
||||
if ($params) {
|
||||
foreach ($params as $k => &$v) {
|
||||
$v = is_array($v) ? implode(',', $v) : $v;
|
||||
}
|
||||
|
||||
if ($params['mode'] == 'json') {
|
||||
//JSON字段
|
||||
$fieldarr = $valuearr = [];
|
||||
$field = $this->request->post('field/a');
|
||||
$value = $this->request->post('value/a');
|
||||
foreach ($field as $k => $v) {
|
||||
if ($v != '') {
|
||||
$fieldarr[] = $field[$k];
|
||||
$valuearr[] = $value[$k];
|
||||
}
|
||||
}
|
||||
$params['value'] = json_encode(array_combine($fieldarr, $valuearr), JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
unset($params['mode']);
|
||||
try {
|
||||
//是否采用模型验证
|
||||
if ($this->modelValidate) {
|
||||
$name = basename(str_replace('\\', '/', get_class($this->model)));
|
||||
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
|
||||
$this->model->validate($validate);
|
||||
}
|
||||
$result = $this->model->save($params);
|
||||
if ($result !== false) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error($this->model->getError());
|
||||
}
|
||||
} catch (\think\exception\PDOException $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
$row = $this->model->get($ids);
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->post("row/a");
|
||||
if ($params) {
|
||||
foreach ($params as $k => &$v) {
|
||||
$v = is_array($v) ? implode(',', $v) : $v;
|
||||
}
|
||||
|
||||
if ($params['mode'] == 'json') {
|
||||
//JSON字段
|
||||
$fieldarr = $valuearr = [];
|
||||
$field = $this->request->post('field/a');
|
||||
$value = $this->request->post('value/a');
|
||||
foreach ($field as $k => $v) {
|
||||
if ($v != '') {
|
||||
$fieldarr[] = $field[$k];
|
||||
$valuearr[] = $value[$k];
|
||||
}
|
||||
}
|
||||
$params['value'] = json_encode(array_combine($fieldarr, $valuearr), JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
unset($params['mode']);
|
||||
try {
|
||||
//是否采用模型验证
|
||||
if ($this->modelValidate) {
|
||||
$name = basename(str_replace('\\', '/', get_class($this->model)));
|
||||
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
|
||||
$row->validate($validate);
|
||||
}
|
||||
$result = $row->save($params);
|
||||
if ($result !== false) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error($row->getError());
|
||||
}
|
||||
} catch (\think\exception\PDOException $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
$this->view->assign("row", $row);
|
||||
$this->view->assign("value", (array)json_decode($row->value, true));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use addons\wechat\library\Config;
|
||||
use app\common\controller\Backend;
|
||||
use app\admin\model\WechatResponse;
|
||||
use EasyWeChat\Factory;
|
||||
use think\Exception;
|
||||
|
||||
/**
|
||||
* 菜单管理
|
||||
*
|
||||
* @icon fa fa-list-alt
|
||||
*/
|
||||
class Menu extends Backend
|
||||
{
|
||||
protected $wechatcfg = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->wechatcfg = \app\admin\model\WechatConfig::get(['name' => 'menu']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$responselist = array();
|
||||
$all = WechatResponse::all();
|
||||
foreach ($all as $k => $v) {
|
||||
$responselist[$v['eventkey']] = $v['title'];
|
||||
}
|
||||
$this->view->assign('responselist', $responselist);
|
||||
$this->view->assign('menu', (array)json_decode($this->wechatcfg->value, true));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
$menu = $this->request->post("menu");
|
||||
$menu = (array)json_decode($menu, true);
|
||||
foreach ($menu as $index => &$item) {
|
||||
if (isset($item['sub_button'])) {
|
||||
foreach ($item['sub_button'] as &$subitem) {
|
||||
if ($subitem['type'] == 'view') {
|
||||
$allowFields = ['type', 'name', 'url'];
|
||||
$subitem = ['type' => $subitem['type'], 'name' => $subitem['name'], 'url' => $subitem['url']];
|
||||
} else {
|
||||
if ($subitem['type'] == 'miniprogram') {
|
||||
$allowFields = ['type', 'name', 'url', 'appid', 'pagepath'];
|
||||
$subitem = ['type' => $subitem['type'], 'name' => $subitem['name'], 'url' => $subitem['url'], 'appid' => $subitem['appid'], 'pagepath' => $subitem['pagepath']];
|
||||
} else {
|
||||
$allowFields = ['type', 'name', 'key'];
|
||||
$subitem = ['type' => $subitem['type'], 'name' => $subitem['name'], 'key' => $subitem['key']];
|
||||
}
|
||||
}
|
||||
$subitem = array_intersect_key($subitem, array_flip($allowFields));
|
||||
}
|
||||
} else {
|
||||
if ($item['type'] == 'view') {
|
||||
$allowFields = ['type', 'name', 'url'];
|
||||
} else {
|
||||
if ($item['type'] == 'miniprogram') {
|
||||
$allowFields = ['type', 'name', 'url', 'appid', 'pagepath'];
|
||||
} else {
|
||||
$allowFields = ['type', 'name', 'key'];
|
||||
}
|
||||
}
|
||||
$item = array_intersect_key($item, array_flip($allowFields));
|
||||
}
|
||||
}
|
||||
$this->wechatcfg->value = json_encode($menu, JSON_UNESCAPED_UNICODE);
|
||||
$this->wechatcfg->save();
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载远程菜单
|
||||
*/
|
||||
public function remote()
|
||||
{
|
||||
$app = Factory::officialAccount(Config::load());
|
||||
|
||||
try {
|
||||
$list = $app->menu->list();
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if (isset($list['menu']['button'])) {
|
||||
$buttons = $list['menu']['button'];
|
||||
foreach ($buttons as $index => &$item) {
|
||||
if (isset($item['sub_button'])) {
|
||||
if ($item['sub_button']) {
|
||||
foreach ($item['sub_button'] as $key => &$value) {
|
||||
if (!isset($value['sub_button']) || !$value['sub_button']) {
|
||||
unset($value['sub_button']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unset($item['sub_button']);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->wechatcfg->value = json_encode($buttons, JSON_UNESCAPED_UNICODE);
|
||||
$this->wechatcfg->save();
|
||||
$this->success();
|
||||
} else {
|
||||
if (isset($list['errcode']) && $list['errcode'] == '46003') {
|
||||
$this->error("服务端菜单为空");
|
||||
} else {
|
||||
$this->error("加载菜单失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步到服务器
|
||||
*/
|
||||
public function sync($ids = null)
|
||||
{
|
||||
$app = Factory::officialAccount(Config::load());
|
||||
try {
|
||||
$hasError = false;
|
||||
$menu = json_decode($this->wechatcfg->value, true);
|
||||
foreach ($menu as $k => $v) {
|
||||
if (isset($v['sub_button'])) {
|
||||
foreach ($v['sub_button'] as $m => $n) {
|
||||
if ($n['type'] == 'click' && isset($n['key']) && !$n['key']) {
|
||||
$hasError = true;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($v['type'] == 'click' && isset($v['key']) && !$v['key']) {
|
||||
$hasError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$hasError) {
|
||||
try {
|
||||
$ret = $app->menu->create($menu);
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($ret['errcode'] == 0) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error($ret['errmsg']);
|
||||
}
|
||||
} else {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use addons\wechat\library\Wechat;
|
||||
|
||||
/**
|
||||
* 资源管理
|
||||
*
|
||||
* @icon fa fa-list-alt
|
||||
*/
|
||||
class Response extends Backend
|
||||
{
|
||||
|
||||
protected $model = null;
|
||||
protected $searchFields = 'id,title';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = model('WechatResponse');
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择素材
|
||||
*/
|
||||
public function select()
|
||||
{
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->post("row/a", [], 'xss_clean');
|
||||
$params['eventkey'] = isset($params['eventkey']) && $params['eventkey'] ? $params['eventkey'] : uniqid();
|
||||
$params['content'] = json_encode($params['content']);
|
||||
$params['createtime'] = time();
|
||||
if ($params) {
|
||||
$this->model->save($params);
|
||||
$this->success();
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
$appConfig = Wechat::appConfig();
|
||||
$this->view->applist = $appConfig;
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit($ids = NULL)
|
||||
{
|
||||
$row = $this->model->get($ids);
|
||||
if (!$row)
|
||||
$this->error(__('No Results were found'));
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->post("row/a", [], 'xss_clean');
|
||||
$params['eventkey'] = isset($params['eventkey']) && $params['eventkey'] ? $params['eventkey'] : uniqid();
|
||||
$params['content'] = json_encode($params['content']);
|
||||
if ($params) {
|
||||
$row->save($params);
|
||||
$this->success();
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
$this->view->assign("row", $row);
|
||||
$appConfig = Wechat::appConfig();
|
||||
$this->view->applist = $appConfig;
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户