feat: 新增师傅入驻审核与接单状态联动功能
- 新增师傅资质审核模块及权限 - 未审核通过的师傅默认禁用接单状态 - 新增售后退款申诉功能与相关界面 - 新增用户钱包管理及充值功能 - 更新服务定价矩阵相关数据库结构 - 修复微信支付证书验证问题
这个提交包含在:
@@ -4,7 +4,10 @@ namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\library\Ems;
|
||||
use app\common\library\FinanceConfigService;
|
||||
use app\common\library\PaymentService;
|
||||
use think\Config;
|
||||
use think\Db;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
@@ -256,4 +259,193 @@ class User extends Api
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户钱包资产看板(可用余额与收支统计)
|
||||
* @ApiMethod (GET)
|
||||
*/
|
||||
public function wallet()
|
||||
{
|
||||
$uid = $this->auth->id;
|
||||
$user = Db::name('user')->field('id,nickname,mobile,avatar,money')->where('id', $uid)->find();
|
||||
if (!$user) {
|
||||
$this->error('用户不存在');
|
||||
}
|
||||
|
||||
$totalRecharge = Db::name('wallet_log')
|
||||
->where('user_type', 'user')
|
||||
->where('user_id', $uid)
|
||||
->where('type', 'recharge')
|
||||
->sum('amount');
|
||||
|
||||
$totalConsume = Db::name('wallet_log')
|
||||
->where('user_type', 'user')
|
||||
->where('user_id', $uid)
|
||||
->where('type', 'consume')
|
||||
->sum('amount');
|
||||
|
||||
$totalRefund = Db::name('wallet_log')
|
||||
->where('user_type', 'user')
|
||||
->where('user_id', $uid)
|
||||
->where('type', 'refund')
|
||||
->sum('amount');
|
||||
|
||||
$totalCount = Db::name('wallet_log')
|
||||
->where('user_type', 'user')
|
||||
->where('user_id', $uid)
|
||||
->count();
|
||||
|
||||
$rechargeConfig = FinanceConfigService::getRechargeConfig();
|
||||
|
||||
$this->success('', [
|
||||
'balance' => (float)$user['money'],
|
||||
'total_recharge' => round((float)$totalRecharge, 2),
|
||||
'total_consume' => round(abs((float)$totalConsume), 2),
|
||||
'total_refund' => round((float)$totalRefund, 2),
|
||||
'total_count' => (int)$totalCount,
|
||||
'recharge_config' => $rechargeConfig,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询用户资金收支账单流水
|
||||
* @ApiMethod (GET)
|
||||
*/
|
||||
public function walletLogs()
|
||||
{
|
||||
$uid = $this->auth->id;
|
||||
$type = trim((string)$this->request->get('type', 'all'));
|
||||
$page = max(1, (int)$this->request->get('page', 1));
|
||||
$limit = min(50, max(1, (int)$this->request->get('limit', 20)));
|
||||
|
||||
$query = Db::name('wallet_log')
|
||||
->where('user_type', 'user')
|
||||
->where('user_id', $uid);
|
||||
|
||||
if (in_array($type, ['recharge', 'consume', 'refund'], true)) {
|
||||
$query->where('type', $type);
|
||||
}
|
||||
|
||||
$total = $query->count();
|
||||
$rows = $query->order('id desc')->page($page, $limit)->select();
|
||||
|
||||
$orderIds = [];
|
||||
foreach ($rows as $r) {
|
||||
if ((int)$r['order_id'] > 0) {
|
||||
$orderIds[] = (int)$r['order_id'];
|
||||
}
|
||||
}
|
||||
$orderMap = [];
|
||||
if (!empty($orderIds)) {
|
||||
$orders = Db::name('order')->where('id', 'in', array_unique($orderIds))->field('id,order_no,service_name')->select();
|
||||
foreach ($orders as $o) {
|
||||
$orderMap[(int)$o['id']] = $o;
|
||||
}
|
||||
}
|
||||
|
||||
$list = [];
|
||||
foreach ($rows as $r) {
|
||||
$oid = (int)$r['order_id'];
|
||||
$ord = $oid > 0 ? ($orderMap[$oid] ?? null) : null;
|
||||
$list[] = [
|
||||
'id' => (int)$r['id'],
|
||||
'type' => $r['type'],
|
||||
'type_label' => $this->formatWalletTypeLabel($r['type']),
|
||||
'amount' => (float)$r['amount'],
|
||||
'balance' => (float)$r['balance'],
|
||||
'order_id' => $oid,
|
||||
'order_no' => $ord ? $ord['order_no'] : '',
|
||||
'service_name' => $ord ? $ord['service_name'] : '',
|
||||
'remark' => (string)$r['remark'],
|
||||
'createtime' => (int)$r['createtime'],
|
||||
'created_at' => $r['createtime'] ? date('Y-m-d H:i', (int)$r['createtime']) : '',
|
||||
];
|
||||
}
|
||||
|
||||
$this->success('', [
|
||||
'list' => $list,
|
||||
'total' => (int)$total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'has_more' => ($page * $limit) < $total,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起微信在线充值(生成 JSAPI 支付参数)
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function recharge()
|
||||
{
|
||||
$uid = $this->auth->id;
|
||||
$amount = round((float)$this->request->post('amount'), 2);
|
||||
$wxCode = trim((string)$this->request->post('wx_code', ''));
|
||||
|
||||
if ($amount < 0.01) {
|
||||
$this->error('充值金额必须大于 ¥0.00');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$res = PaymentService::createRechargeJsapiPay($uid, $amount, $wxCode);
|
||||
$this->success('请完成微信支付', $res);
|
||||
} catch (\think\exception\HttpResponseException $e) {
|
||||
throw $e;
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->error($e->getMessage());
|
||||
} catch (\Throwable $e) {
|
||||
\think\Log::error('[User::recharge] ' . $e->getMessage());
|
||||
$this->error('发起充值支付失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 充值完成后小程序端主动查单幂等核销
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function confirmRecharge()
|
||||
{
|
||||
$uid = $this->auth->id;
|
||||
$outTradeNo = trim((string)$this->request->post('out_trade_no', ''));
|
||||
|
||||
if ($outTradeNo === '') {
|
||||
$this->error('缺少充值单号');
|
||||
return;
|
||||
}
|
||||
|
||||
$payOrder = Db::name('pay_order')->where('out_trade_no', $outTradeNo)->find();
|
||||
if (!$payOrder) {
|
||||
$this->error('充值支付单不存在');
|
||||
return;
|
||||
}
|
||||
if ((int)$payOrder['user_id'] !== $uid) {
|
||||
$this->error('无权操作该充值单');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$res = PaymentService::confirmRechargePay($outTradeNo);
|
||||
$this->success('充值已成功到账', $res);
|
||||
} catch (\think\exception\HttpResponseException $e) {
|
||||
throw $e;
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->error($e->getMessage());
|
||||
} catch (\Throwable $e) {
|
||||
\think\Log::error('[User::confirmRecharge] ' . $e->getMessage());
|
||||
$this->error('充值确认失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected function formatWalletTypeLabel($type)
|
||||
{
|
||||
$map = [
|
||||
'recharge' => '微信在线充值',
|
||||
'consume' => '订单余额消费',
|
||||
'refund' => '售后/取消退款',
|
||||
'income' => '奖励补贴入账',
|
||||
'settle' => '工单收益结算',
|
||||
'withdraw' => '余额提现出账',
|
||||
];
|
||||
return $map[$type] ?? '资金变动';
|
||||
}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户