1. 账号体系与数据库解耦: - 师傅表 fa_master 解除对 fa_user.id 的外键依赖,升级为独立认证账号主表; - 新增师傅端独立支撑表:fa_master_security、fa_master_token、fa_master_wechat、fa_master_agreement_read; - 新增工单超时未接单自动关闭与原路退款配置(order_unaccepted_close_days)。 2. 服务端(Server): - 新增师傅端独立 API 控制器与认证库(MasterAuth, MasterBase, MasterMessage, MasterSecurity, MasterToken); - WxLogin 支持双小程序端(user/master)独立换取 session_key、openid 与 access_token; - 新增控制台调度命令 php think order:autoclose,支持订单超时自动关闭与售后退款闭环; - 修复 PHP 8.5 兼容性问题(Request.php 的 (bool) 强制转换); - 系统业务配置全面收敛至数据库 fa_config 及 site.php。 3. 小程序端: - yjyf-app(用户端):彻底剥离师傅端路由、组件及静态资源,增加隐私授权弹窗与评价模块; - yjyf-master-app(师傅端):全新独立微信小程序工程(wx140d90ceda786107),实现工作台、接单大厅、资质认证、工单协同与钱包提现完整闭环。
129 行
4.5 KiB
PHP
129 行
4.5 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\library\OrderStatus;
|
|
use think\Db;
|
|
|
|
/**
|
|
* 评价:用户提交 / 师傅收到的评价
|
|
*/
|
|
class Review extends Base
|
|
{
|
|
protected $noNeedLogin = ['masterList'];
|
|
|
|
/**
|
|
* 提交评价
|
|
* @ApiMethod (POST)
|
|
*/
|
|
public function create()
|
|
{
|
|
$orderId = (int)$this->request->post('order_id');
|
|
$score = (int)$this->request->post('score', 5);
|
|
$content = trim((string)$this->request->post('content'));
|
|
$tags = $this->request->post('tags', '');
|
|
$images = $this->request->post('images', '', null);
|
|
$anonymous = (int)$this->request->post('is_anonymous', 0);
|
|
$isShowcase = (int)$this->request->post('is_showcase', 1);
|
|
|
|
$order = $this->ownOrder($orderId, 'user');
|
|
if ((int)$order['status'] !== OrderStatus::COMPLETED) {
|
|
$this->error('订单未完成,暂不能评价');
|
|
}
|
|
if ((int)$order['is_review'] === 1) {
|
|
$this->error('该订单已评价');
|
|
}
|
|
if ($score < 1 || $score > 5) {
|
|
$this->error('请选择 1-5 星');
|
|
}
|
|
|
|
$now = time();
|
|
Db::startTrans();
|
|
try {
|
|
Db::name('review')->insert([
|
|
'order_id' => $orderId,
|
|
'user_id' => $this->uid(),
|
|
'master_id' => (int)$order['master_id'],
|
|
'score' => $score,
|
|
'tags' => is_array($tags) ? json_encode($tags, JSON_UNESCAPED_UNICODE) : (string)$tags,
|
|
'content' => mb_substr($content, 0, 500),
|
|
'images' => is_array($images) ? json_encode($images, JSON_UNESCAPED_UNICODE) : (string)$images,
|
|
'is_anonymous' => $anonymous ? 1 : 0,
|
|
'is_showcase' => $isShowcase ? 1 : 0,
|
|
'status' => 'normal',
|
|
'createtime' => $now,
|
|
]);
|
|
Db::name('order')->where('id', $orderId)->update([
|
|
'is_review' => 1,
|
|
'is_showcase' => $isShowcase ? 1 : 0,
|
|
'showcase_time' => $isShowcase ? $now : null,
|
|
'updatetime' => $now,
|
|
]);
|
|
|
|
// 刷新师傅综合评分
|
|
$masterId = (int)$order['master_id'];
|
|
if ($masterId > 0) {
|
|
$avg = Db::name('review')->where('master_id', $masterId)->where('status', 'normal')->avg('score');
|
|
Db::name('master')->where('id', $masterId)->update([
|
|
'score' => round((float)$avg, 2),
|
|
'updatetime' => time(),
|
|
]);
|
|
}
|
|
|
|
// 同步至独立晒单表 fa_showcase
|
|
$this->syncOrderShowcase($order, $isShowcase ? 1 : 0);
|
|
Db::commit();
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
$this->error('评价失败:' . $e->getMessage());
|
|
}
|
|
|
|
$this->success('评价成功');
|
|
}
|
|
|
|
/**
|
|
* 师傅收到的评价
|
|
*/
|
|
public function masterList()
|
|
{
|
|
$masterId = (int)$this->request->param('master_id');
|
|
if ($masterId <= 0) {
|
|
$token = $this->request->server('HTTP_TOKEN', $this->request->request('token', ''));
|
|
$masterAuth = \app\common\library\MasterAuth::instance();
|
|
if ($token && $masterAuth->init($token)) {
|
|
$masterId = (int)$masterAuth->id();
|
|
}
|
|
if ($masterId <= 0) {
|
|
$this->error('师傅不存在');
|
|
}
|
|
}
|
|
$list = Db::name('review')
|
|
->alias('r')
|
|
->join('user u', 'u.id = r.user_id', 'LEFT')
|
|
->field('r.id,r.score,r.tags,r.content,r.images,r.is_anonymous,r.reply,r.createtime,u.nickname,u.avatar')
|
|
->where('r.master_id', $masterId)
|
|
->where('r.status', 'normal')
|
|
->order('r.id desc')
|
|
->limit(50)
|
|
->select();
|
|
|
|
foreach ($list as &$row) {
|
|
if ((int)$row['is_anonymous'] === 1) {
|
|
$row['nickname'] = '匿名用户';
|
|
$row['avatar'] = '';
|
|
}
|
|
$row['time_text'] = date('Y-m-d H:i', (int)$row['createtime']);
|
|
}
|
|
unset($row);
|
|
|
|
$stat = Db::name('review')->where('master_id', $masterId)->where('status', 'normal')
|
|
->field('count(*) as total, avg(score) as avg_score')->find();
|
|
|
|
$this->success('', [
|
|
'list' => $list,
|
|
'total' => (int)$stat['total'],
|
|
'avg_score' => round((float)$stat['avg_score'], 2),
|
|
]);
|
|
}
|
|
}
|