feat: 新增师傅入驻审核与接单状态联动功能
- 新增师傅资质审核模块及权限 - 未审核通过的师傅默认禁用接单状态 - 新增售后退款申诉功能与相关界面 - 新增用户钱包管理及充值功能 - 更新服务定价矩阵相关数据库结构 - 修复微信支付证书验证问题
这个提交包含在:
@@ -394,7 +394,7 @@ class Auth extends Base
|
||||
|
||||
$redirect = '/pages/index/index';
|
||||
if ($role === 'master') {
|
||||
$redirect = '/pages/master/hall';
|
||||
$redirect = '/pages/master/workbench';
|
||||
} elseif ($role === 'merchant') {
|
||||
$redirect = '/pages/mine/mine';
|
||||
}
|
||||
|
||||
@@ -658,13 +658,17 @@ class Home extends Base
|
||||
$ret = [];
|
||||
foreach ($specs as $sp) {
|
||||
$spImg = isset($sp['image']) ? trim((string)$sp['image']) : '';
|
||||
$spPrices = !empty($sp['service_prices']) ? (json_decode($sp['service_prices'], true) ?: []) : [];
|
||||
$spAddons = !empty($sp['addon_prices']) ? (json_decode($sp['addon_prices'], true) ?: []) : [];
|
||||
$ret[] = [
|
||||
'id' => (int)$sp['id'],
|
||||
'service_id' => (int)$sp['service_id'],
|
||||
'name' => $sp['name'],
|
||||
'image_url' => $spImg !== '' ? (strpos($spImg, 'http') === 0 ? $spImg : cdnurl($spImg, true)) : '',
|
||||
'description' => (string)$sp['description'],
|
||||
'base_price' => (float)$sp['base_price'],
|
||||
'id' => (int)$sp['id'],
|
||||
'service_id' => (int)$sp['service_id'],
|
||||
'name' => $sp['name'],
|
||||
'image_url' => $spImg !== '' ? (strpos($spImg, 'http') === 0 ? $spImg : cdnurl($spImg, true)) : '',
|
||||
'description' => (string)$sp['description'],
|
||||
'base_price' => (float)$sp['base_price'],
|
||||
'service_prices' => $spPrices,
|
||||
'addon_prices' => $spAddons,
|
||||
];
|
||||
}
|
||||
$this->success('', ['list' => $ret]);
|
||||
@@ -682,7 +686,30 @@ class Home extends Base
|
||||
}
|
||||
$cat = Db::name('service_cat')->where('id', $service['cat_id'])->find();
|
||||
$service['cat_name'] = $cat ? $cat['name'] : '';
|
||||
$this->success('', ['detail' => $this->formatService($service)]);
|
||||
$detail = $this->formatService($service);
|
||||
$specs = Db::name('service_spec')
|
||||
->where('service_id', $id)
|
||||
->where('status', 'normal')
|
||||
->order('weigh desc, id asc')
|
||||
->select();
|
||||
$specList = [];
|
||||
foreach ($specs as $sp) {
|
||||
$spImg = isset($sp['image']) ? trim((string)$sp['image']) : '';
|
||||
$spPrices = !empty($sp['service_prices']) ? (json_decode($sp['service_prices'], true) ?: []) : [];
|
||||
$spAddons = !empty($sp['addon_prices']) ? (json_decode($sp['addon_prices'], true) ?: []) : [];
|
||||
$specList[] = [
|
||||
'id' => (int)$sp['id'],
|
||||
'service_id' => $id,
|
||||
'name' => $sp['name'],
|
||||
'image_url' => $spImg !== '' ? (strpos($spImg, 'http') === 0 ? $spImg : cdnurl($spImg, true)) : '',
|
||||
'description' => (string)$sp['description'],
|
||||
'base_price' => (float)$sp['base_price'],
|
||||
'service_prices' => $spPrices,
|
||||
'addon_prices' => $spAddons,
|
||||
];
|
||||
}
|
||||
$detail['specs'] = $specList;
|
||||
$this->success('', ['detail' => $detail]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -712,11 +739,12 @@ class Home extends Base
|
||||
|
||||
$this->success('', [
|
||||
'count' => (int)$total,
|
||||
'is_local' => $matchedLocal,
|
||||
'platform_count' => $platformCount,
|
||||
'region' => trim($city . ' ' . $district),
|
||||
'tip' => $matchedLocal
|
||||
? "该地区可提供服务的师傅共 {$total} 位"
|
||||
: "平台认证可服务师傅共 {$total} 位",
|
||||
: "全网已调度认证服务师傅共 {$total} 位",
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -846,7 +874,9 @@ class Home extends Base
|
||||
}
|
||||
}
|
||||
|
||||
$specRow = null;
|
||||
$specPrice = 0.0;
|
||||
$specPricesMap = [];
|
||||
if ($specId > 0 && $dbSvc) {
|
||||
$cacheKey = $sid . ':' . $specId;
|
||||
if (!array_key_exists($cacheKey, $specCache)) {
|
||||
@@ -856,8 +886,12 @@ class Home extends Base
|
||||
->where('status', 'normal')
|
||||
->find() ?: null;
|
||||
}
|
||||
if (!empty($specCache[$cacheKey])) {
|
||||
$specPrice = (float)$specCache[$cacheKey]['base_price'];
|
||||
$specRow = $specCache[$cacheKey];
|
||||
if (!empty($specRow)) {
|
||||
$specPrice = (float)$specRow['base_price'];
|
||||
if (!empty($specRow['service_prices'])) {
|
||||
$specPricesMap = json_decode((string)$specRow['service_prices'], true) ?: [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -876,14 +910,22 @@ class Home extends Base
|
||||
$matchedTypePrice = isset($st['price']) ? (float)$st['price'] : 0.0;
|
||||
}
|
||||
}
|
||||
$effectiveTargetCode = ($reqServiceType !== '') ? $reqServiceType : $defaultCode;
|
||||
|
||||
// 若规格设置了专属一口价(>0)且当前为默认主服务,则优先采用规格专属价;否则采用所选主服务定价或商品默认价
|
||||
$isDefaultService = ($reqServiceType === '' || $reqServiceType === $defaultCode || $reqServiceType === 'install');
|
||||
if ($specPrice > 0 && $isDefaultService) {
|
||||
// 1. 若当前规格对当前工项设置了专属定价 (>0),直接采用规格专属一口价!
|
||||
if (isset($specPricesMap[$effectiveTargetCode]) && (float)$specPricesMap[$effectiveTargetCode] > 0) {
|
||||
$itemPrice = (float)$specPricesMap[$effectiveTargetCode];
|
||||
}
|
||||
// 2. 兼容历史数据:若规格设置了 base_price > 0 且当前为默认主服务工项
|
||||
elseif ($specPrice > 0 && ($effectiveTargetCode === $defaultCode || $effectiveTargetCode === 'install')) {
|
||||
$itemPrice = $specPrice;
|
||||
} elseif ($matchedTypePrice > 0) {
|
||||
}
|
||||
// 3. 继承父级:沿用商品父级中当前工项设置的基准一口价
|
||||
elseif ($matchedTypePrice > 0) {
|
||||
$itemPrice = $matchedTypePrice;
|
||||
} elseif ($specPrice > 0) {
|
||||
}
|
||||
// 4. 兜底保护:规格或商品级默认基准价
|
||||
elseif ($specPrice > 0) {
|
||||
$itemPrice = $specPrice;
|
||||
} elseif ((float)$dbSvc['base_price'] > 0) {
|
||||
$itemPrice = (float)$dbSvc['base_price'];
|
||||
@@ -898,6 +940,15 @@ class Home extends Base
|
||||
$dbAddonsMap[(string)$ad['code']] = (float)$ad['price'];
|
||||
}
|
||||
}
|
||||
// 若当前规格配置了增值服务专属加价字典,覆盖对应增值项
|
||||
if (!empty($specRow['addon_prices'])) {
|
||||
$specAddonMap = json_decode((string)$specRow['addon_prices'], true) ?: [];
|
||||
foreach ($specAddonMap as $sKey => $sVal) {
|
||||
if ((float)$sVal > 0) {
|
||||
$dbAddonsMap[(string)$sKey] = (float)$sVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($isFixedLike && $itemPrice <= 0) {
|
||||
@@ -906,9 +957,12 @@ class Home extends Base
|
||||
|
||||
$itemNum = isset($g['num']) ? max(1, (int)$g['num']) : (isset($g['goods_num']) ? max(1, (int)$g['goods_num']) : 1);
|
||||
$base += round($itemPrice * $itemNum, 2);
|
||||
if (!empty($g['extras']) && is_array($g['extras'])) {
|
||||
foreach ($g['extras'] as $ex) {
|
||||
$exNum = isset($ex['num']) ? max(0, (int)$ex['num']) : 0;
|
||||
$curAddonsList = !empty($g['extras']) && is_array($g['extras'])
|
||||
? $g['extras']
|
||||
: (!empty($g['addons']) && is_array($g['addons']) ? $g['addons'] : []);
|
||||
if (!empty($curAddonsList)) {
|
||||
foreach ($curAddonsList as $ex) {
|
||||
$exNum = isset($ex['num']) ? max(0, (int)$ex['num']) : (isset($ex['count']) ? max(0, (int)$ex['count']) : 1);
|
||||
if ($exNum <= 0) {
|
||||
continue;
|
||||
}
|
||||
@@ -934,14 +988,18 @@ class Home extends Base
|
||||
$specId = isset($params['spec_id']) ? (int)$params['spec_id'] : 0;
|
||||
$reqServiceType = isset($params['service_type']) ? trim((string)$params['service_type']) : '';
|
||||
$specPrice = 0.0;
|
||||
$specPricesMap = [];
|
||||
if ($specId > 0) {
|
||||
$spRow = Db::name('service_spec')
|
||||
->where('id', $specId)
|
||||
->where('service_id', (int)$service['id'])
|
||||
->where('status', 'normal')
|
||||
->find();
|
||||
if ($spRow && (float)$spRow['base_price'] > 0) {
|
||||
if ($spRow) {
|
||||
$specPrice = (float)$spRow['base_price'];
|
||||
if (!empty($spRow['service_prices'])) {
|
||||
$specPricesMap = json_decode((string)$spRow['service_prices'], true) ?: [];
|
||||
}
|
||||
}
|
||||
}
|
||||
$svcTypes = !empty($service['service_types']) ? (json_decode((string)$service['service_types'], true) ?: []) : [];
|
||||
@@ -955,12 +1013,22 @@ class Home extends Base
|
||||
$matchedTypePrice = isset($st['price']) ? (float)$st['price'] : 0.0;
|
||||
}
|
||||
}
|
||||
$isDefaultService = ($reqServiceType === '' || $reqServiceType === $defaultCode || $reqServiceType === 'install');
|
||||
if ($specPrice > 0 && $isDefaultService) {
|
||||
$effectiveTargetCode = ($reqServiceType !== '') ? $reqServiceType : $defaultCode;
|
||||
|
||||
// 1. 若当前规格对当前工项设置了专属定价 (>0),直接采用规格专属一口价!
|
||||
if (isset($specPricesMap[$effectiveTargetCode]) && (float)$specPricesMap[$effectiveTargetCode] > 0) {
|
||||
$unitPrice = (float)$specPricesMap[$effectiveTargetCode];
|
||||
}
|
||||
// 2. 兼容历史数据:若规格设置了 base_price > 0 且当前为默认主服务工项
|
||||
elseif ($specPrice > 0 && ($effectiveTargetCode === $defaultCode || $effectiveTargetCode === 'install')) {
|
||||
$unitPrice = $specPrice;
|
||||
} elseif ($matchedTypePrice > 0) {
|
||||
}
|
||||
// 3. 继承父级:沿用商品父级中当前工项设置的基准一口价
|
||||
elseif ($matchedTypePrice > 0) {
|
||||
$unitPrice = $matchedTypePrice;
|
||||
} elseif ($specPrice > 0) {
|
||||
}
|
||||
// 4. 兜底保护:规格专属价或商品级默认基准价
|
||||
elseif ($specPrice > 0) {
|
||||
$unitPrice = $specPrice;
|
||||
}
|
||||
if ($isFixedLike && $unitPrice <= 0) {
|
||||
@@ -968,6 +1036,47 @@ class Home extends Base
|
||||
}
|
||||
$goodsNum = isset($params['goods_num']) ? max(1, (int)$params['goods_num']) : 1;
|
||||
$base = round($unitPrice * $goodsNum, 2);
|
||||
|
||||
$singleAddons = !empty($params['extras']) && is_array($params['extras'])
|
||||
? $params['extras']
|
||||
: (!empty($params['addons']) && is_array($params['addons']) ? $params['addons'] : []);
|
||||
if (!empty($singleAddons)) {
|
||||
$dbAddonsMap = [];
|
||||
$svcAddons = !empty($service['addons']) ? (json_decode((string)$service['addons'], true) ?: []) : [];
|
||||
foreach ($svcAddons as $ad) {
|
||||
if (!empty($ad['name']) && isset($ad['price']) && (float)$ad['price'] > 0) {
|
||||
$dbAddonsMap[(string)$ad['name']] = (float)$ad['price'];
|
||||
}
|
||||
if (!empty($ad['code']) && isset($ad['price']) && (float)$ad['price'] > 0) {
|
||||
$dbAddonsMap[(string)$ad['code']] = (float)$ad['price'];
|
||||
}
|
||||
}
|
||||
if (!empty($spRow['addon_prices'])) {
|
||||
$specAddonMap = json_decode((string)$spRow['addon_prices'], true) ?: [];
|
||||
foreach ($specAddonMap as $sKey => $sVal) {
|
||||
if ((float)$sVal > 0) {
|
||||
$dbAddonsMap[(string)$sKey] = (float)$sVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($singleAddons as $ex) {
|
||||
$exNum = isset($ex['num']) ? max(0, (int)$ex['num']) : (isset($ex['count']) ? max(0, (int)$ex['count']) : 1);
|
||||
if ($exNum <= 0) {
|
||||
continue;
|
||||
}
|
||||
$exPrice = 0.0;
|
||||
$exName = isset($ex['name']) ? (string)$ex['name'] : '';
|
||||
$exCode = isset($ex['code']) ? (string)$ex['code'] : '';
|
||||
if ($exName !== '' && isset($dbAddonsMap[$exName])) {
|
||||
$exPrice = $dbAddonsMap[$exName];
|
||||
} elseif ($exCode !== '' && isset($dbAddonsMap[$exCode])) {
|
||||
$exPrice = $dbAddonsMap[$exCode];
|
||||
} elseif (!$isFixedLike && isset($ex['price'])) {
|
||||
$exPrice = max(0, (float)$ex['price']);
|
||||
}
|
||||
$base += round($exPrice * $exNum, 2);
|
||||
}
|
||||
}
|
||||
} elseif ($isFixedLike && (!empty($params['is_custom']) || $isStrict || (isset($params['base_price']) && (float)$params['base_price'] > 0))) {
|
||||
throw new \InvalidArgumentException('自定义商品不支持一口价模式,请关联有效服务项目或切换为师傅报价/自主定价');
|
||||
}
|
||||
@@ -986,14 +1095,15 @@ class Home extends Base
|
||||
$urgentAmount = 0;
|
||||
} else {
|
||||
$floor = max(0, (int)$params['floor']);
|
||||
$freeFloor = $service ? (int)$service['free_floor'] : 2;
|
||||
$floorFee = $service ? (float)$service['floor_fee'] : 10.0;
|
||||
$freeFloor = ($service && (int)$service['free_floor'] > 0) ? (int)$service['free_floor'] : 2;
|
||||
$floorFee = ($service && (float)$service['floor_fee'] > 0) ? (float)$service['floor_fee'] : 10.0;
|
||||
|
||||
if ((int)$params['has_elevator'] === 0 && $floor > $freeFloor) {
|
||||
$floorAmount = ($floor - $freeFloor) * $floorFee;
|
||||
}
|
||||
|
||||
$urgentAmount = (int)$params['urgent'] === 1 ? round($base * 0.2, 2) : 0;
|
||||
$singleUrgent = max(20.0, min(200.0, round($base * 0.2, 2)));
|
||||
$urgentAmount = (int)$params['urgent'] === 1 ? $singleUrgent : 0;
|
||||
$total = round($base + $floorAmount + $urgentAmount, 2);
|
||||
}
|
||||
|
||||
@@ -1020,6 +1130,7 @@ class Home extends Base
|
||||
'base_amount' => $type === 'quote' ? 0 : round($base, 2),
|
||||
'floor_amount' => round($floorAmount, 2),
|
||||
'urgent_amount' => round($urgentAmount, 2),
|
||||
'estimated_urgent_amount' => round(max(20.0, min(200.0, round($base * 0.2, 2))), 2),
|
||||
'total_amount' => $total,
|
||||
'discount_amount' => round($discount, 2),
|
||||
'pay_amount' => max(0, round($total - $discount, 2)),
|
||||
@@ -1157,13 +1268,17 @@ class Home extends Base
|
||||
$specsMap[$sid] = [];
|
||||
}
|
||||
$spImg = isset($sp['image']) ? trim((string)$sp['image']) : '';
|
||||
$spPrices = !empty($sp['service_prices']) ? (json_decode($sp['service_prices'], true) ?: []) : [];
|
||||
$spAddons = !empty($sp['addon_prices']) ? (json_decode($sp['addon_prices'], true) ?: []) : [];
|
||||
$specsMap[$sid][] = [
|
||||
'id' => (int)$sp['id'],
|
||||
'service_id' => $sid,
|
||||
'name' => $sp['name'],
|
||||
'image_url' => $spImg !== '' ? (strpos($spImg, 'http') === 0 ? $spImg : cdnurl($spImg, true)) : '',
|
||||
'description' => (string)$sp['description'],
|
||||
'base_price' => (float)$sp['base_price'],
|
||||
'id' => (int)$sp['id'],
|
||||
'service_id' => $sid,
|
||||
'name' => $sp['name'],
|
||||
'image_url' => $spImg !== '' ? (strpos($spImg, 'http') === 0 ? $spImg : cdnurl($spImg, true)) : '',
|
||||
'description' => (string)$sp['description'],
|
||||
'base_price' => (float)$sp['base_price'],
|
||||
'service_prices' => $spPrices,
|
||||
'addon_prices' => $spAddons,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,8 +142,10 @@ class Master extends Base
|
||||
'idcard_back' => $idcardBack,
|
||||
'cert_images' => $certImages,
|
||||
'city' => $normalizedCity,
|
||||
'work_status' => 'off',
|
||||
'verify_status' => 'pass',
|
||||
'audit_msg' => '腾讯云二要素实名核验通过',
|
||||
'audittime' => time(),
|
||||
'updatetime' => time(),
|
||||
];
|
||||
|
||||
@@ -296,6 +298,9 @@ class Master extends Base
|
||||
if (!in_array($status, ['on', 'off'], true)) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
if ($status === 'on' && (string)$master['verify_status'] !== 'pass') {
|
||||
$this->error('师傅资质尚未审核通过,无法开启听单接单');
|
||||
}
|
||||
Db::name('master')->where('id', $master['id'])->update(['work_status' => $status, 'updatetime' => time()]);
|
||||
$this->success($status === 'on' ? '已开启接单' : '已暂停接单', ['work_status' => $status]);
|
||||
}
|
||||
|
||||
@@ -57,6 +57,23 @@ class Merchant extends Base
|
||||
$this->error('您已是认证商家,无需重复入驻');
|
||||
}
|
||||
|
||||
// 统一社会信用代码唯一性校验(排除自身已有档案,防止同一企业重复建档)
|
||||
$licenseNo = strtoupper($data['license_no']);
|
||||
$dupQuery = Db::name('merchant')->where(function ($q) use ($licenseNo, $data) {
|
||||
$q->where('license_no', $licenseNo)->whereOr('license_no', $data['license_no']);
|
||||
});
|
||||
if ($exist) {
|
||||
$dupQuery->where('id', '<>', (int)$exist['id']);
|
||||
}
|
||||
$dupLicense = $dupQuery->order('id', 'asc')->find();
|
||||
if ($dupLicense) {
|
||||
$tips = (int)$dupLicense['user_id'] === (int)$this->uid()
|
||||
? '该统一社会信用代码已提交过入驻申请,请勿重复提交'
|
||||
: '该统一社会信用代码已绑定其他企业,请核实营业执照信息后重新提交';
|
||||
$this->error($tips);
|
||||
}
|
||||
$data['license_no'] = $licenseNo;
|
||||
|
||||
$save = array_merge($data, [
|
||||
'verify_status' => 'pending',
|
||||
'audit_msg' => '',
|
||||
|
||||
@@ -613,10 +613,15 @@ class Order extends Base
|
||||
{
|
||||
$orderId = (int)$this->request->post('order_id');
|
||||
$wxCode = trim((string)$this->request->post('wx_code', ''));
|
||||
$payType = trim((string)$this->request->post('pay_type', 'wechat'));
|
||||
$order = $this->ownOrder($orderId, 'user');
|
||||
|
||||
try {
|
||||
$res = PaymentService::createOrderJsapiPay($order, $this->uid(), 'order', 0, $wxCode);
|
||||
if ($payType === 'balance') {
|
||||
$res = PaymentService::payOrderByBalance($order, $this->uid(), 'order');
|
||||
} else {
|
||||
$res = PaymentService::createOrderJsapiPay($order, $this->uid(), 'order', 0, $wxCode);
|
||||
}
|
||||
} catch (\think\exception\HttpResponseException $e) {
|
||||
throw $e;
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
@@ -624,7 +629,7 @@ class Order extends Base
|
||||
return;
|
||||
} catch (\Throwable $e) {
|
||||
\think\Log::error('[Order::pay] ' . $e->getMessage());
|
||||
$this->error('发起微信支付失败:' . $e->getMessage());
|
||||
$this->error('发起支付失败:' . $e->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -680,10 +685,15 @@ class Order extends Base
|
||||
{
|
||||
$orderId = (int)$this->request->post('order_id');
|
||||
$wxCode = trim((string)$this->request->post('wx_code', ''));
|
||||
$payType = trim((string)$this->request->post('pay_type', 'wechat'));
|
||||
$order = $this->ownOrder($orderId, 'user');
|
||||
|
||||
try {
|
||||
$res = PaymentService::createOrderJsapiPay($order, $this->uid(), 'diff', 0, $wxCode);
|
||||
if ($payType === 'balance') {
|
||||
$res = PaymentService::payOrderByBalance($order, $this->uid(), 'diff');
|
||||
} else {
|
||||
$res = PaymentService::createOrderJsapiPay($order, $this->uid(), 'diff', 0, $wxCode);
|
||||
}
|
||||
} catch (\think\exception\HttpResponseException $e) {
|
||||
throw $e;
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
@@ -695,7 +705,8 @@ class Order extends Base
|
||||
return;
|
||||
}
|
||||
|
||||
$this->success('请完成增项补差价微信支付', $res);
|
||||
$msg = !empty($res['paid']) ? '增项补差价支付成功' : '请完成增项补差价微信支付';
|
||||
$this->success($msg, $res);
|
||||
}
|
||||
|
||||
public function index()
|
||||
@@ -1176,10 +1187,15 @@ class Order extends Base
|
||||
$orderId = (int)$this->request->post('order_id');
|
||||
$quoteId = (int)$this->request->post('quote_id');
|
||||
$wxCode = trim((string)$this->request->post('wx_code', ''));
|
||||
$payType = trim((string)$this->request->post('pay_type', 'wechat'));
|
||||
$order = $this->ownOrder($orderId, 'user');
|
||||
|
||||
try {
|
||||
$res = PaymentService::createOrderJsapiPay($order, $this->uid(), 'quote', $quoteId, $wxCode);
|
||||
if ($payType === 'balance') {
|
||||
$res = PaymentService::payOrderByBalance($order, $this->uid(), 'quote', $quoteId);
|
||||
} else {
|
||||
$res = PaymentService::createOrderJsapiPay($order, $this->uid(), 'quote', $quoteId, $wxCode);
|
||||
}
|
||||
} catch (\think\exception\HttpResponseException $e) {
|
||||
throw $e;
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
@@ -1323,6 +1339,131 @@ class Order extends Base
|
||||
$this->success('订单已取消');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户售后退款申请(已完成订单可申请,提交后进入平台售后仲裁队列)
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="order_id", type="integer", required=true, description="订单ID")
|
||||
* @ApiParams (name="content", type="string", required=true, description="售后申请原因(10~300字)")
|
||||
* @ApiParams (name="refund_expect", type="float", required=false, description="期望退款金额(元,留空或0=全额)")
|
||||
* @ApiParams (name="images", type="string", required=false, description="举证图片,逗号分隔的附件URL")
|
||||
*/
|
||||
public function afterSaleApply()
|
||||
{
|
||||
$orderId = (int)$this->request->post('order_id');
|
||||
$content = trim((string)$this->request->post('content', ''));
|
||||
$refundExpect = round((float)$this->request->post('refund_expect', 0), 2);
|
||||
$images = trim((string)$this->request->post('images', ''));
|
||||
|
||||
if ($content === '' || mb_strlen($content) < 10) {
|
||||
$this->error('请填写至少 10 个字的售后申请原因,便于平台快速核实');
|
||||
}
|
||||
if (mb_strlen($content) > 300) {
|
||||
$this->error('售后申请原因请控制在 300 字以内');
|
||||
}
|
||||
if ($refundExpect < 0) {
|
||||
$this->error('期望退款金额不能为负数');
|
||||
}
|
||||
|
||||
$order = $this->ownOrder($orderId, 'user');
|
||||
|
||||
// 仅已完成订单可发起售后退款申请;未完成履约请走"取消订单"通道(同样支持原路退款)
|
||||
if ((int)$order['status'] !== OrderStatus::COMPLETED) {
|
||||
$this->error('当前状态(' . OrderStatus::label($order['status']) . ')不支持售后申请,未完成订单请使用"取消订单"');
|
||||
}
|
||||
if ((int)$order['pay_status'] !== 1) {
|
||||
$this->error('该订单不是已支付状态(支付状态:' . ((int)$order['pay_status'] === 2 ? '已退款' : '未支付') . '),无需申请售后退款');
|
||||
}
|
||||
if ((float)$order['pay_amount'] > 0 && $refundExpect > 0 && $refundExpect > (float)$order['pay_amount']) {
|
||||
$this->error('期望退款金额不能超过订单实付金额 ¥' . $order['pay_amount']);
|
||||
}
|
||||
|
||||
// 防重复:同订单同一用户存在待受理/处理中的售后申诉时禁止重复提交
|
||||
$exists = Db::name('appeal')
|
||||
->where('order_id', $orderId)
|
||||
->where('user_id', $this->uid())
|
||||
->where('type', 'aftersale')
|
||||
->whereIn('status', ['wait', 'handling'])
|
||||
->count();
|
||||
if ($exists > 0) {
|
||||
$this->error('该订单已有售后申请正在处理中,请耐心等待平台仲裁结果');
|
||||
}
|
||||
|
||||
$now = time();
|
||||
Db::name('appeal')->insert([
|
||||
'order_id' => $orderId,
|
||||
'master_id' => 0,
|
||||
'user_id' => $this->uid(),
|
||||
'type' => 'aftersale',
|
||||
'content' => mb_substr($content, 0, 500),
|
||||
'images' => mb_substr($images, 0, 1000),
|
||||
'refund_amount' => $refundExpect > 0 ? $refundExpect : null,
|
||||
'status' => 'wait',
|
||||
'reply' => '',
|
||||
'createtime' => $now,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
|
||||
// 通知平台运营侧(写入系统消息,便于后台待办跟进)
|
||||
Db::name('message')->insert([
|
||||
'receive_type' => 'user',
|
||||
'receive_id' => $this->uid(),
|
||||
'type' => 'order',
|
||||
'order_id' => (string)$orderId,
|
||||
'title' => '售后申请已提交',
|
||||
'content' => '您对订单【' . $order['order_no'] . '】的售后退款申请已提交(' . ($refundExpect > 0 ? '期望退款 ¥' . $refundExpect : '期望全额退款') . '),平台将在 1~2 个工作日内完成仲裁,结果将通过站内消息通知您。',
|
||||
'is_read' => 0,
|
||||
'createtime' => $now,
|
||||
]);
|
||||
Db::name('order_log')->insert([
|
||||
'order_id' => $orderId,
|
||||
'status' => (int)$order['status'],
|
||||
'remark' => mb_substr('用户提交售后退款申请:' . $content, 0, 255),
|
||||
'operator_type' => 'user',
|
||||
'operator_id' => $this->uid(),
|
||||
'createtime' => $now,
|
||||
]);
|
||||
|
||||
$this->success('售后申请已提交,等待平台仲裁');
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的售后申请记录(含仲裁进度与平台答复)
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function myAfterSales()
|
||||
{
|
||||
$rows = Db::name('appeal')
|
||||
->alias('a')
|
||||
->join('order o', 'o.id = a.order_id', 'LEFT')
|
||||
->where('a.user_id', $this->uid())
|
||||
->where('a.type', 'aftersale')
|
||||
->field('a.id, a.order_id, o.order_no, o.service_name, o.pay_amount, a.content, a.images, a.refund_amount, a.status, a.reply, a.createtime, a.updatetime')
|
||||
->order('a.id desc')
|
||||
->limit(50)
|
||||
->select();
|
||||
|
||||
$statusText = ['wait' => '待平台受理', 'handling' => '核实处理中', 'done' => '处理已完结', 'reject' => '已驳回诉求'];
|
||||
$list = [];
|
||||
foreach ($rows as $r) {
|
||||
$list[] = [
|
||||
'id' => (int)$r['id'],
|
||||
'order_id' => (int)$r['order_id'],
|
||||
'order_no' => (string)($r['order_no'] ?? ''),
|
||||
'service_name' => (string)($r['service_name'] ?? ''),
|
||||
'pay_amount' => (float)($r['pay_amount'] ?? 0),
|
||||
'content' => (string)$r['content'],
|
||||
'images' => (string)$r['images'],
|
||||
'refund_amount' => $r['refund_amount'] !== null ? (float)$r['refund_amount'] : null,
|
||||
'status' => (string)$r['status'],
|
||||
'status_text' => $statusText[$r['status']] ?? (string)$r['status'],
|
||||
'reply' => (string)$r['reply'],
|
||||
'createtime' => $r['createtime'] ? date('Y-m-d H:i', (int)$r['createtime']) : '',
|
||||
];
|
||||
}
|
||||
|
||||
$this->success('查询成功', ['list' => $list]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户验收(验收码可选校验)→ 生成结算并给师傅入账
|
||||
* @ApiMethod (POST)
|
||||
@@ -2116,10 +2257,14 @@ class Order extends Base
|
||||
$priceType = (string)$fs['price_type'];
|
||||
$unit = (string)($fs['unit'] ?: $unit);
|
||||
$specPrice = 0.0;
|
||||
$specPricesMap = [];
|
||||
if ($specId > 0 && !empty($fs['specs'])) {
|
||||
foreach ($fs['specs'] as $spItem) {
|
||||
if ((int)$spItem['id'] === $specId && (float)$spItem['base_price'] > 0) {
|
||||
$specPrice = (float)$spItem['base_price'];
|
||||
if ((int)$spItem['id'] === $specId) {
|
||||
$specPrice = (float)($spItem['base_price'] ?? 0);
|
||||
if (!empty($spItem['service_prices']) && is_array($spItem['service_prices'])) {
|
||||
$specPricesMap = $spItem['service_prices'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2133,11 +2278,18 @@ class Order extends Base
|
||||
}
|
||||
}
|
||||
foreach ($rawSt as $idx => $st) {
|
||||
$sCode = (string)($st['code'] ?? '');
|
||||
$isDef = !empty($st['is_default']) || (!$hasDef && $idx === 0);
|
||||
$pVal = ($isDef && $specPrice > 0) ? $specPrice : (float)($st['price'] ?? 0);
|
||||
if (isset($specPricesMap[$sCode]) && (float)$specPricesMap[$sCode] > 0) {
|
||||
$pVal = (float)$specPricesMap[$sCode];
|
||||
} elseif ($isDef && $specPrice > 0) {
|
||||
$pVal = $specPrice;
|
||||
} else {
|
||||
$pVal = (float)($st['price'] ?? 0);
|
||||
}
|
||||
$st['price'] = $pVal;
|
||||
$serviceTypes[] = $st;
|
||||
if ((string)$st['code'] === (string)$r['service_type']) {
|
||||
if ($sCode === (string)$r['service_type']) {
|
||||
$basePrice = $pVal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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] ?? '资金变动';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,13 @@ class Wxpay extends Api
|
||||
$data = $parsed['data'];
|
||||
|
||||
if ($eventType === 'TRANSACTION.SUCCESS' && !empty($data['out_trade_no'])) {
|
||||
PaymentService::confirmOrderPay((string)$data['out_trade_no'], $data);
|
||||
$outTradeNo = (string)$data['out_trade_no'];
|
||||
$payOrder = Db::name('pay_order')->where('out_trade_no', $outTradeNo)->find();
|
||||
if ($payOrder && $payOrder['scene'] === 'recharge') {
|
||||
PaymentService::confirmRechargePay($outTradeNo, $data);
|
||||
} else {
|
||||
PaymentService::confirmOrderPay($outTradeNo, $data);
|
||||
}
|
||||
}
|
||||
return $this->wxResponse(true);
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
在新工单中引用
屏蔽一个用户