feat: 完善协议管理、师傅资质认证、分账配置并完成测试环境全量部署与同步
这个提交包含在:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\AgreementService;
|
||||
|
||||
/**
|
||||
* 协议与隐私管理
|
||||
*
|
||||
* 统一编辑管理平台《用户服务协议》《隐私保护指引》《师傅入驻协议》《商家协同协议》,
|
||||
* 保存后实时同步至小程序与 H5 独立协议展示页面。
|
||||
*
|
||||
* @icon fa fa-file-text-o
|
||||
*/
|
||||
class Agreement extends Backend
|
||||
{
|
||||
/**
|
||||
* @var \app\admin\model\Agreement
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\Agreement;
|
||||
}
|
||||
|
||||
/**
|
||||
* 协议与隐私编辑工作台
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$agreements = AgreementService::getAllForAdmin();
|
||||
$this->view->assign([
|
||||
'agreements' => $agreements,
|
||||
'agreementsJson' => json_encode($agreements, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP),
|
||||
'canSave' => $this->auth->check('agreement/save'),
|
||||
]);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存协议内容与元数据
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
if (false === $this->request->isPost()) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$this->token();
|
||||
|
||||
$code = trim((string)$this->request->post('code', ''));
|
||||
// 读取未剥离标签的原始数组,由 AgreementService::sanitizeHtml 执行严格 XSS 白名单净化
|
||||
$row = $this->request->post('row/a', [], null);
|
||||
if ($code === '' || !is_array($row) || empty($row)) {
|
||||
$this->error('提交的协议数据不能为空', null, ['token' => $this->request->token()]);
|
||||
}
|
||||
|
||||
try {
|
||||
$saved = AgreementService::saveByCode($code, $row);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->error($e->getMessage(), null, ['token' => $this->request->token()]);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error('保存协议失败:' . $e->getMessage(), null, ['token' => $this->request->token()]);
|
||||
}
|
||||
|
||||
$this->success('协议内容已保存并同步生效', null, [
|
||||
'token' => $this->request->token(),
|
||||
'agreement' => $saved,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,363 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\CommissionService;
|
||||
use app\common\library\FinanceConfigService;
|
||||
use think\Db;
|
||||
use think\exception\PDOException;
|
||||
|
||||
/**
|
||||
* 抽佣与提现配置中心
|
||||
*
|
||||
* 统一管理:
|
||||
* 1. 按订单多维度(计价模式/客群/服务类目/加急/金额阶梯)动态抽佣规则与订单快照兜底策略
|
||||
* 2. 师傅钱包提现规则与微信小程序商家转账(场景 1005 劳务报酬)合规参数
|
||||
*
|
||||
* @icon fa fa-sliders
|
||||
*/
|
||||
class FinanceConfig extends Backend
|
||||
{
|
||||
/**
|
||||
* @var \app\admin\model\CommissionRule
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
protected $searchFields = 'id,name,remark';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\CommissionRule;
|
||||
|
||||
$catRows = Db::name('service_cat')
|
||||
->field('id,name,status')
|
||||
->order('weigh desc, id asc')
|
||||
->select();
|
||||
$catMap = [0 => '不限服务分类'];
|
||||
foreach ($catRows as $c) {
|
||||
$catMap[(int)$c['id']] = (string)$c['name'] . ($c['status'] === 'hidden' ? '(已隐藏)' : '');
|
||||
}
|
||||
|
||||
$this->view->assign([
|
||||
'orderModeList' => $this->model->getOrderModeList(),
|
||||
'customerTypeList' => $this->model->getCustomerTypeList(),
|
||||
'urgentModeList' => $this->model->getUrgentModeList(),
|
||||
'calcModeList' => $this->model->getCalcModeList(),
|
||||
'statusList' => $this->model->getStatusList(),
|
||||
'catMap' => $catMap,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置中心首页(GET 渲染独立双页签配置界面;Ajax 返回按订单维度抽佣规则列表)
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
if (false === $this->request->isAjax()) {
|
||||
$allCfg = FinanceConfigService::getAll(true);
|
||||
$withdrawCfg = FinanceConfigService::getWithdrawConfig();
|
||||
$commDefaults = FinanceConfigService::getCommissionDefaults();
|
||||
|
||||
$this->view->assign([
|
||||
'cfg' => $allCfg,
|
||||
'withdrawCfg' => $withdrawCfg,
|
||||
'commDefaults' => $commDefaults,
|
||||
]);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
|
||||
$orderExpr = $sort === 'weigh' ? "weigh {$order}, id desc" : "{$sort} {$order}";
|
||||
$list = $this->model
|
||||
->where($where)
|
||||
->order($orderExpr)
|
||||
->paginate($limit);
|
||||
|
||||
$rows = $list->items();
|
||||
if (!empty($rows)) {
|
||||
$cats = Db::name('service_cat')->column('name', 'id');
|
||||
foreach ($rows as &$r) {
|
||||
$cid = (int)$r['cat_id'];
|
||||
$r['cat_name'] = $cid > 0 ? ($cats[$cid] ?? ('分类#' . $cid)) : '';
|
||||
}
|
||||
unset($r);
|
||||
}
|
||||
|
||||
return json([
|
||||
'total' => $list->total(),
|
||||
'rows' => $rows,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存订单默认兜底抽佣设置 / 提现与微信转账规则配置
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
if (false === $this->request->isPost()) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$this->token();
|
||||
|
||||
$section = (string)$this->request->post('section', '');
|
||||
$row = $this->request->post('row/a', []);
|
||||
if (!is_array($row) || empty($row)) {
|
||||
$this->error('提交的配置数据不能为空');
|
||||
}
|
||||
|
||||
// 处理多选框全部取消勾选时前端未上送对应键的情况
|
||||
if ($section === 'withdraw') {
|
||||
if (!array_key_exists('withdraw_channels', $row)) {
|
||||
$this->error('请至少勾选一种开放提现渠道', null, ['token' => $this->request->token()]);
|
||||
}
|
||||
if (!array_key_exists('withdraw_allow_weekdays', $row)) {
|
||||
$this->error('请至少选择一天允许提现的周期', null, ['token' => $this->request->token()]);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
FinanceConfigService::saveConfigs($row);
|
||||
CommissionService::clearCache();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->error($e->getMessage(), null, ['token' => $this->request->token()]);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error('保存配置失败:' . $e->getMessage(), null, ['token' => $this->request->token()]);
|
||||
}
|
||||
|
||||
$msg = $section === 'commission_default'
|
||||
? '抽佣默认设置已保存(仅影响新订单,已下单工单不受影响)'
|
||||
: '提现规则已保存生效';
|
||||
|
||||
$this->success($msg, null, ['token' => $this->request->token()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增按订单维度抽佣规则
|
||||
*/
|
||||
public function rule_add()
|
||||
{
|
||||
if (false === $this->request->isPost()) {
|
||||
$this->view->assign('row', [
|
||||
'name' => '',
|
||||
'order_mode' => 'all',
|
||||
'customer_type' => 'all',
|
||||
'cat_id' => 0,
|
||||
'urgent_mode' => 'all',
|
||||
'min_amount' => '0.00',
|
||||
'max_amount' => '0.00',
|
||||
'calc_mode' => 'percent',
|
||||
'commission_rate' => '10.00',
|
||||
'fixed_fee' => '0.00',
|
||||
'min_commission' => '0.00',
|
||||
'max_commission' => '0.00',
|
||||
'weigh' => 100,
|
||||
'status' => 'normal',
|
||||
'remark' => '',
|
||||
]);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$this->token();
|
||||
$raw = $this->request->post('row/a', []);
|
||||
try {
|
||||
$clean = $this->validateAndCleanRuleInput($raw);
|
||||
$this->model->allowField(true)->save($clean);
|
||||
CommissionService::clearCache();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->error($e->getMessage());
|
||||
} catch (PDOException|\Exception $e) {
|
||||
$this->error('新增规则失败:' . $e->getMessage());
|
||||
}
|
||||
|
||||
$this->success('抽佣规则已创建(仅对后续新订单生效)');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑按订单维度抽佣规则
|
||||
*/
|
||||
public function rule_edit($ids = null)
|
||||
{
|
||||
$row = $this->model->get($ids);
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
if (false === $this->request->isPost()) {
|
||||
$this->view->assign('row', $row);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$this->token();
|
||||
$raw = $this->request->post('row/a', []);
|
||||
try {
|
||||
$clean = $this->validateAndCleanRuleInput($raw);
|
||||
$row->allowField(true)->save($clean);
|
||||
CommissionService::clearCache();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->error($e->getMessage());
|
||||
} catch (PDOException|\Exception $e) {
|
||||
$this->error('更新规则失败:' . $e->getMessage());
|
||||
}
|
||||
|
||||
$this->success('抽佣规则已更新(历史已创订单不受影响)');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除抽佣规则
|
||||
*/
|
||||
public function rule_del($ids = null)
|
||||
{
|
||||
if (false === $this->request->isPost()) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$ids = $ids ?: $this->request->post('ids');
|
||||
$idArr = array_values(array_filter(array_map('intval', explode(',', (string)$ids))));
|
||||
if (empty($idArr)) {
|
||||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
Db::startTrans();
|
||||
try {
|
||||
$list = $this->model->where('id', 'in', $idArr)->select();
|
||||
foreach ($list as $item) {
|
||||
$count += $item->delete();
|
||||
}
|
||||
Db::commit();
|
||||
CommissionService::clearCache();
|
||||
} catch (PDOException|\Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
if ($count) {
|
||||
$this->success();
|
||||
}
|
||||
$this->error(__('No rows were deleted'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量启用/停用抽佣规则
|
||||
*/
|
||||
public function rule_multi($ids = null)
|
||||
{
|
||||
if (false === $this->request->isPost()) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$ids = $ids ?: $this->request->post('ids');
|
||||
$params = (string)$this->request->post('params', '');
|
||||
parse_str($params, $values);
|
||||
if (empty($ids) || empty($values)) {
|
||||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||||
}
|
||||
|
||||
$allowed = [];
|
||||
if (isset($values['status']) && in_array($values['status'], ['normal', 'hidden'], true)) {
|
||||
$allowed['status'] = $values['status'];
|
||||
}
|
||||
if (isset($values['weigh']) && is_numeric($values['weigh'])) {
|
||||
$allowed['weigh'] = (int)$values['weigh'];
|
||||
}
|
||||
if (empty($allowed)) {
|
||||
$this->error('仅允许批量修改启用状态或优先级权重');
|
||||
}
|
||||
|
||||
$idArr = array_values(array_filter(array_map('intval', explode(',', (string)$ids))));
|
||||
$allowed['updatetime'] = time();
|
||||
Db::name('commission_rule')->where('id', 'in', $idArr)->update($allowed);
|
||||
CommissionService::clearCache();
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽佣规则入参强白名单与业务区间合法性校验
|
||||
*
|
||||
* @param array $raw
|
||||
* @return array
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function validateAndCleanRuleInput(array $raw): array
|
||||
{
|
||||
$name = trim((string)($raw['name'] ?? ''));
|
||||
if ($name === '' || mb_strlen($name) > 80) {
|
||||
throw new \InvalidArgumentException('请填写规则名称(1 ~ 80 个字符)');
|
||||
}
|
||||
|
||||
$orderMode = (string)($raw['order_mode'] ?? 'all');
|
||||
if (!array_key_exists($orderMode, $this->model->getOrderModeList())) {
|
||||
throw new \InvalidArgumentException('请选择有效的适用订单计价模式');
|
||||
}
|
||||
|
||||
$customerType = (string)($raw['customer_type'] ?? 'all');
|
||||
if (!array_key_exists($customerType, $this->model->getCustomerTypeList())) {
|
||||
throw new \InvalidArgumentException('请选择有效的适用发单客群');
|
||||
}
|
||||
|
||||
$catId = max(0, (int)($raw['cat_id'] ?? 0));
|
||||
if ($catId > 0 && !Db::name('service_cat')->where('id', $catId)->find()) {
|
||||
throw new \InvalidArgumentException('所选服务类目不存在');
|
||||
}
|
||||
|
||||
$urgentMode = (string)($raw['urgent_mode'] ?? 'all');
|
||||
if (!array_key_exists($urgentMode, $this->model->getUrgentModeList())) {
|
||||
throw new \InvalidArgumentException('请选择有效的加急属性条件');
|
||||
}
|
||||
|
||||
$minAmount = round((float)($raw['min_amount'] ?? 0), 2);
|
||||
$maxAmount = round((float)($raw['max_amount'] ?? 0), 2);
|
||||
if ($minAmount < 0 || $maxAmount < 0) {
|
||||
throw new \InvalidArgumentException('订单金额区间不能为负数');
|
||||
}
|
||||
if ($maxAmount > 0 && $minAmount > $maxAmount) {
|
||||
throw new \InvalidArgumentException('订单起始金额不能大于订单上限金额(0 表示不限上限)');
|
||||
}
|
||||
|
||||
$calcMode = (string)($raw['calc_mode'] ?? 'percent');
|
||||
if (!array_key_exists($calcMode, $this->model->getCalcModeList())) {
|
||||
throw new \InvalidArgumentException('请选择有效的计佣方式');
|
||||
}
|
||||
|
||||
$rate = 0.00;
|
||||
if (in_array($calcMode, ['percent', 'mixed'], true)) {
|
||||
$rate = CommissionService::validateRateInput($raw['commission_rate'] ?? '');
|
||||
}
|
||||
|
||||
$fixedFee = 0.00;
|
||||
if (in_array($calcMode, ['fixed', 'mixed'], true)) {
|
||||
if (!isset($raw['fixed_fee']) || !is_numeric($raw['fixed_fee']) || (float)$raw['fixed_fee'] < 0) {
|
||||
throw new \InvalidArgumentException('请填写有效的每单固定抽佣金额(≥ 0 元)');
|
||||
}
|
||||
$fixedFee = round((float)$raw['fixed_fee'], 2);
|
||||
}
|
||||
|
||||
$minComm = round(max(0.00, (float)($raw['min_commission'] ?? 0)), 2);
|
||||
$maxComm = round(max(0.00, (float)($raw['max_commission'] ?? 0)), 2);
|
||||
if ($minComm > 0 && $maxComm > 0 && $minComm > $maxComm) {
|
||||
throw new \InvalidArgumentException('单笔保底抽佣金额不能大于单笔封顶抽佣金额');
|
||||
}
|
||||
|
||||
$weigh = isset($raw['weigh']) && is_numeric($raw['weigh']) ? (int)$raw['weigh'] : 100;
|
||||
$status = in_array($raw['status'] ?? 'normal', ['normal', 'hidden'], true) ? $raw['status'] : 'normal';
|
||||
$remark = mb_substr(trim((string)($raw['remark'] ?? '')), 0, 255);
|
||||
|
||||
return [
|
||||
'name' => $name,
|
||||
'order_mode' => $orderMode,
|
||||
'customer_type' => $customerType,
|
||||
'cat_id' => $catId,
|
||||
'urgent_mode' => $urgentMode,
|
||||
'min_amount' => number_format($minAmount, 2, '.', ''),
|
||||
'max_amount' => number_format($maxAmount, 2, '.', ''),
|
||||
'calc_mode' => $calcMode,
|
||||
'commission_rate' => number_format($rate, 2, '.', ''),
|
||||
'fixed_fee' => number_format($fixedFee, 2, '.', ''),
|
||||
'min_commission' => number_format($minComm, 2, '.', ''),
|
||||
'max_commission' => number_format($maxComm, 2, '.', ''),
|
||||
'weigh' => $weigh,
|
||||
'status' => $status,
|
||||
'remark' => $remark,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -173,9 +173,9 @@ class Home extends Backend
|
||||
'waitingInvoice' => $waitingInvoice,
|
||||
'pendingDispatch' => $pendingDispatch,
|
||||
|
||||
'masterAvgScore' => $masterAvg['avg_score'] ?: '5.0',
|
||||
'masterAvgAccept' => $masterAvg['avg_accept'] ?: '100',
|
||||
'masterAvgOntime' => $masterAvg['avg_ontime'] ?: '100',
|
||||
'masterAvgScore' => ($masterAvg && $masterAvg['avg_score'] !== null) ? (string)$masterAvg['avg_score'] : '0.0',
|
||||
'masterAvgAccept' => ($masterAvg && $masterAvg['avg_accept'] !== null) ? (string)$masterAvg['avg_accept'] : '0',
|
||||
'masterAvgOntime' => ($masterAvg && $masterAvg['avg_ontime'] !== null) ? (string)$masterAvg['avg_ontime'] : '0',
|
||||
|
||||
'totalService' => $totalService,
|
||||
'totalCategory' => $totalCategory,
|
||||
|
||||
@@ -418,6 +418,13 @@ class Master extends Backend
|
||||
->field('s.*, c.name as cat_name')
|
||||
->select();
|
||||
|
||||
// 5.5 技能证书记录
|
||||
$certs = Db::name('master_cert')
|
||||
->field('id,cert_code,cert_name,is_custom,cert_image,expire_date,is_long_term,status,audit_msg,updatetime')
|
||||
->where('master_id', $row['id'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
|
||||
// 6. 钱包资金变动流水
|
||||
$walletLogs = Db::name('wallet_log')
|
||||
->where('user_type', 'master')
|
||||
@@ -426,6 +433,14 @@ class Master extends Backend
|
||||
->limit(6)
|
||||
->select();
|
||||
|
||||
// 7. 证件防伪水印安全转换(方案1:腾讯云数据万象动态水印)
|
||||
if (!empty($row['idcard_front'])) {
|
||||
$row['idcard_front_watermark'] = \app\common\library\TencentVerifyService::getWatermarkUrl($row['idcard_front']);
|
||||
}
|
||||
if (!empty($row['idcard_back'])) {
|
||||
$row['idcard_back_watermark'] = \app\common\library\TencentVerifyService::getWatermarkUrl($row['idcard_back']);
|
||||
}
|
||||
|
||||
$this->view->assign([
|
||||
'row' => $row,
|
||||
'recentOrders' => $recentOrders,
|
||||
@@ -433,6 +448,7 @@ class Master extends Backend
|
||||
'recentSettles' => $recentSettles,
|
||||
'recentReviews' => $recentReviews,
|
||||
'skills' => $skills,
|
||||
'certs' => $certs,
|
||||
'walletLogs' => $walletLogs,
|
||||
]);
|
||||
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use Exception;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 师傅技能证书审核管理
|
||||
*
|
||||
* @icon fa fa-id-badge
|
||||
*/
|
||||
class MasterCert extends Backend
|
||||
{
|
||||
/**
|
||||
* @var \app\admin\model\MasterCert
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $relationSearch = true;
|
||||
protected $searchFields = 'id,cert_name,cert_code,master.realname,master.mobile';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\MasterCert;
|
||||
$this->view->assign('statusList', $this->model->getStatusList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 技能证书列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
if (false === $this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
if ($this->request->request('keyField')) {
|
||||
return $this->selectpage();
|
||||
}
|
||||
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
|
||||
$list = $this->model
|
||||
->with(['master'])
|
||||
->where($where)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
|
||||
return json(['total' => $list->total(), 'rows' => $list->items()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看证书详情
|
||||
*/
|
||||
public function detail($ids = null)
|
||||
{
|
||||
$row = $this->model->with(['master'])->where('master_cert.id', (int)$ids)->find();
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
$this->view->assign('row', $row);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核技能证书
|
||||
*/
|
||||
public function audit($ids = null)
|
||||
{
|
||||
return $this->handleAudit((int)$ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容 FastAdmin 默认编辑路由,复用审核逻辑
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return $this->handleAudit((int)$ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一证书审核处理(保护证件原图只读,仅更新审核状态与意见并通知师傅)
|
||||
*/
|
||||
private function handleAudit($id)
|
||||
{
|
||||
$row = $this->model->with(['master'])->where('master_cert.id', (int)$id)->find();
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
|
||||
if (false === $this->request->isPost()) {
|
||||
$this->view->assign('row', $row);
|
||||
return $this->view->fetch('audit');
|
||||
}
|
||||
|
||||
$params = $this->request->post('row/a', []);
|
||||
if (empty($params)) {
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
|
||||
$status = trim((string)($params['status'] ?? $row['status']));
|
||||
$auditMsg = trim((string)($params['audit_msg'] ?? ''));
|
||||
|
||||
$statusList = $this->model->getStatusList();
|
||||
if (!isset($statusList[$status])) {
|
||||
$this->error('审核状态不合法');
|
||||
}
|
||||
if ($status === 'reject' && $auditMsg === '') {
|
||||
$this->error('驳回技能证书时,必须填写驳回原因说明');
|
||||
}
|
||||
|
||||
$oldStatus = (string)$row['status'];
|
||||
$now = time();
|
||||
$adminId = (int)$this->auth->id;
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
Db::name('master_cert')->where('id', (int)$row['id'])->update([
|
||||
'status' => $status,
|
||||
'audit_msg' => mb_substr($auditMsg, 0, 255),
|
||||
'audit_admin_id' => $adminId,
|
||||
'audittime' => in_array($status, ['pass', 'reject'], true) ? $now : null,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
|
||||
$masterId = (int)$row['master_id'];
|
||||
if ($masterId > 0) {
|
||||
$images = Db::name('master_cert')
|
||||
->where('master_id', $masterId)
|
||||
->where('status', 'in', ['pass', 'pending'])
|
||||
->order('id desc')
|
||||
->column('cert_image');
|
||||
$cleanImages = array_values(array_unique(array_filter(array_map('strval', $images ?: []))));
|
||||
$json = !empty($cleanImages) ? json_encode($cleanImages, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : '';
|
||||
Db::name('master')->where('id', $masterId)->update([
|
||||
'cert_images' => mb_substr($json, 0, 1000),
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($status !== $oldStatus && in_array($status, ['pass', 'reject'], true) && $masterId > 0) {
|
||||
$certName = (string)$row['cert_name'];
|
||||
$msgTitle = $status === 'pass'
|
||||
? "技能证书审核通过({$certName})"
|
||||
: "技能证书审核未通过({$certName})";
|
||||
$msgContent = $status === 'pass'
|
||||
? "您上传的「{$certName}」已通过平台审核,可正常承接对应资质要求的工单。"
|
||||
: ("您上传的「{$certName}」未通过审核,原因:" . ($auditMsg !== '' ? $auditMsg : '照片不清晰或证件不符合要求,请重新上传。'));
|
||||
|
||||
Db::name('message')->insert([
|
||||
'receive_type' => 'master',
|
||||
'receive_id' => $masterId,
|
||||
'type' => 'audit',
|
||||
'title' => $msgTitle,
|
||||
'content' => $msgContent,
|
||||
'order_id' => 0,
|
||||
'is_read' => 0,
|
||||
'createtime' => $now,
|
||||
]);
|
||||
|
||||
$userId = (int)Db::name('master')->where('id', $masterId)->value('user_id');
|
||||
if ($userId > 0) {
|
||||
Db::name('message')->insert([
|
||||
'receive_type' => 'user',
|
||||
'receive_id' => $userId,
|
||||
'type' => 'audit',
|
||||
'title' => $msgTitle,
|
||||
'content' => $msgContent,
|
||||
'order_id' => 0,
|
||||
'is_read' => 0,
|
||||
'createtime' => $now,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$this->success('审核操作成功');
|
||||
}
|
||||
}
|
||||
@@ -127,6 +127,8 @@ class Order extends Backend
|
||||
$params['discount_amount'],
|
||||
$params['total_amount'],
|
||||
$params['pay_amount'],
|
||||
$params['commission_rate'],
|
||||
$params['commission_snapshot'],
|
||||
$params['pay_status'],
|
||||
$params['pay_type'],
|
||||
$params['pay_time'],
|
||||
@@ -173,6 +175,23 @@ class Order extends Backend
|
||||
}
|
||||
}
|
||||
|
||||
// 后台取消工单前置防资损与原路退款(必须在开启数据库事务之前调用远程退款接口)
|
||||
if ($oldStatus !== 9 && $newStatus === 9) {
|
||||
if ((int)$row['settle_status'] === 1) {
|
||||
$this->error('该工单已完成向师傅结算分账,不允许直接取消退款');
|
||||
}
|
||||
if ((int)$row['pay_status'] === 1) {
|
||||
$cancelReasonPre = trim((string)($params['cancel_reason'] ?? $row['cancel_reason'] ?? '平台后台取消工单'));
|
||||
try {
|
||||
$refundedAmount = \app\common\library\PaymentService::refundOrder((int)$row['id'], $cancelReasonPre ?: '平台后台取消工单');
|
||||
} catch (\Throwable $re) {
|
||||
$this->error('微信原路退款失败:' . $re->getMessage());
|
||||
}
|
||||
$params['pay_status'] = 2;
|
||||
$params['refund_amount'] = $refundedAmount > 0 ? $refundedAmount : (float)$row['pay_amount'];
|
||||
}
|
||||
}
|
||||
|
||||
$result = false;
|
||||
Db::startTrans();
|
||||
try {
|
||||
@@ -523,8 +542,9 @@ class Order extends Backend
|
||||
$review['tags_arr'] = $tagsArr;
|
||||
}
|
||||
|
||||
// 6. 财务结算记录
|
||||
// 6. 财务结算记录与订单锁定快照预计结算核算
|
||||
$settle = Db::name('settle')->where('order_id', $row['id'])->find();
|
||||
$settlePreview = \app\common\library\CommissionService::calcByOrder($row->toArray());
|
||||
|
||||
// 7. 企业商家协同发包来源
|
||||
$merchantOrder = Db::name('merchant_order')
|
||||
@@ -552,6 +572,24 @@ class Order extends Backend
|
||||
->order('a.id desc')
|
||||
->select();
|
||||
|
||||
// 10. 微信支付与原路退款交易流水(含失败错误码及中文诊断原因)
|
||||
$sceneMap = [
|
||||
'order' => '主订单支付',
|
||||
'quote' => '选定师傅报价',
|
||||
'diff' => '增项补差价',
|
||||
'batch' => '批量下单',
|
||||
];
|
||||
$payOrders = Db::name('pay_order')
|
||||
->where('order_id', (int)$row['id'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
foreach ($payOrders as &$poItem) {
|
||||
$poItem['scene_text'] = $sceneMap[$poItem['scene'] ?? ''] ?? ($poItem['scene'] ?? '-');
|
||||
$poItem['status_text'] = \app\common\library\PaymentService::payOrderStatusLabel($poItem['status'] ?? '');
|
||||
$poItem['refund_status_text'] = \app\common\library\PaymentService::refundStatusLabel($poItem['refund_status'] ?? 'none');
|
||||
}
|
||||
unset($poItem);
|
||||
|
||||
$this->view->assign([
|
||||
'row' => $row,
|
||||
'goodsList' => $goodsList,
|
||||
@@ -560,11 +598,126 @@ class Order extends Backend
|
||||
'quoteList' => $quoteList,
|
||||
'review' => $review,
|
||||
'settle' => $settle,
|
||||
'settlePreview' => $settlePreview,
|
||||
'merchantOrder' => $merchantOrder,
|
||||
'invoiceInfo' => $invoiceInfo,
|
||||
'appealList' => $appealList,
|
||||
'payOrders' => $payOrders,
|
||||
]);
|
||||
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台主动同步单笔支付/退款流水在微信网关的真实状态
|
||||
*/
|
||||
public function syncpay($ids = null)
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error('非法请求方式');
|
||||
}
|
||||
$payOrderId = $this->request->post('pay_order_id/d', 0);
|
||||
if ($payOrderId <= 0) {
|
||||
$payOrderId = (int)$ids;
|
||||
}
|
||||
$po = Db::name('pay_order')->where('id', $payOrderId)->find();
|
||||
if (!$po) {
|
||||
$this->error('未找到指定的支付交易流水');
|
||||
}
|
||||
|
||||
$status = (string)($po['status'] ?? '');
|
||||
try {
|
||||
if (in_array($status, ['refunding', 'refund_failed'], true) || trim((string)($po['refund_no'] ?? '')) !== '') {
|
||||
$updated = \app\common\library\PaymentService::syncRefundPayOrder($payOrderId);
|
||||
$label = \app\common\library\PaymentService::refundStatusLabel($updated['refund_status'] ?? '');
|
||||
$this->success('退款状态已从微信同步:' . $label);
|
||||
}
|
||||
|
||||
if ($status === 'paid') {
|
||||
$this->success('该笔流水当前已完成微信入账,状态正常');
|
||||
}
|
||||
|
||||
$res = \app\common\library\PaymentService::confirmOrderPay((string)$po['out_trade_no']);
|
||||
if (!empty($res['paid'])) {
|
||||
$msg = '微信已确认支付成功,系统已完成入账核销';
|
||||
if (!empty($res['duplicate_refund_error'])) {
|
||||
$this->error($res['duplicate_refund_error']);
|
||||
}
|
||||
$this->success($msg);
|
||||
}
|
||||
$this->success('同步成功,当前微信状态:' . ($res['trade_state_text'] ?? '待确认'));
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台手动对退款失败(或未退)的微信支付流水重发原路退款
|
||||
*/
|
||||
public function retryrefund($ids = null)
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error('非法请求方式');
|
||||
}
|
||||
$payOrderId = $this->request->post('pay_order_id/d', 0);
|
||||
if ($payOrderId <= 0) {
|
||||
$payOrderId = (int)$ids;
|
||||
}
|
||||
$po = Db::name('pay_order')->where('id', $payOrderId)->find();
|
||||
if (!$po) {
|
||||
$this->error('未找到指定的支付交易流水');
|
||||
}
|
||||
|
||||
$order = Db::name('order')->where('id', (int)$po['order_id'])->find();
|
||||
if (!$order) {
|
||||
$this->error('关联业务订单不存在');
|
||||
}
|
||||
if ((int)$order['settle_status'] === 1) {
|
||||
$this->error('该工单已完成向师傅结算分账,不允许再执行退款');
|
||||
}
|
||||
|
||||
$status = (string)($po['status'] ?? '');
|
||||
if ($status === 'refunding') {
|
||||
$this->error('该流水处于微信退款处理中,请先点击【同步微信状态】核实是否已到账,切勿盲目重退');
|
||||
}
|
||||
if (!in_array($status, ['refund_failed', 'paid'], true)) {
|
||||
$this->error('当前流水状态为「' . \app\common\library\PaymentService::payOrderStatusLabel($status) . '」,不可发起原路退款');
|
||||
}
|
||||
|
||||
$reason = trim($this->request->post('reason/s', ''));
|
||||
try {
|
||||
$after = \app\common\library\PaymentService::refundSinglePayOrder(
|
||||
$payOrderId,
|
||||
$reason !== '' ? $reason : '管理员后台手动发起/重试原路退款'
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error('发起原路退款失败:' . $e->getMessage());
|
||||
}
|
||||
|
||||
// 若主工单已处于取消状态且本笔退款受理/到账成功,同步汇总真实退款金额
|
||||
if ((int)$order['status'] === 9 && in_array($after['status'] ?? '', ['refunding', 'refunded'], true)) {
|
||||
$allPaid = Db::name('pay_order')
|
||||
->where('order_id', (int)$order['id'])
|
||||
->whereIn('status', ['paid', 'refunding', 'refunded', 'refund_failed'])
|
||||
->select();
|
||||
$hasUnsettledRefund = false;
|
||||
$sumRefund = 0.00;
|
||||
foreach ($allPaid as $item) {
|
||||
if (in_array($item['status'], ['refunding', 'refunded'], true)) {
|
||||
$sumRefund = round($sumRefund + (float)($item['refund_amount'] ?: $item['amount']), 2);
|
||||
} else {
|
||||
$hasUnsettledRefund = true;
|
||||
}
|
||||
}
|
||||
Db::name('order')->where('id', (int)$order['id'])->update([
|
||||
'pay_status' => $hasUnsettledRefund ? (int)$order['pay_status'] : 2,
|
||||
'refund_amount' => $sumRefund,
|
||||
'updatetime' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
$statusLabel = \app\common\library\PaymentService::payOrderStatusLabel($after['status'] ?? '');
|
||||
$refundLabel = \app\common\library\PaymentService::refundStatusLabel($after['refund_status'] ?? 'none');
|
||||
$this->success('微信原路退款请求已提交,当前状态:' . $statusLabel . '(' . $refundLabel . ')');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,12 +346,13 @@ class Service extends Backend
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步商品规格型号表(支持特殊规格单独设价覆盖,留空或0则沿用商品默认服务价)
|
||||
* 同步商品规格型号表(支持特殊规格单独设价覆盖与规格参考图,同步联动系统图库)
|
||||
*/
|
||||
protected function syncSpecs($serviceId, $specsInput)
|
||||
{
|
||||
if (empty($serviceId)) return;
|
||||
$now = time();
|
||||
$catId = (int)Db::name('service')->where('id', $serviceId)->value('cat_id');
|
||||
$keepIds = [];
|
||||
if (!empty($specsInput) && is_array($specsInput)) {
|
||||
$idx = 0;
|
||||
@@ -359,6 +360,7 @@ class Service extends Backend
|
||||
$name = trim(isset($item['name']) ? $item['name'] : '');
|
||||
if ($name === '') continue;
|
||||
$specDesc = isset($item['description']) ? trim($item['description']) : '';
|
||||
$specImage = isset($item['image']) ? trim((string)$item['image']) : '';
|
||||
$specPrice = (isset($item['base_price']) && is_numeric($item['base_price']) && (float)$item['base_price'] > 0)
|
||||
? round((float)$item['base_price'], 2)
|
||||
: 0.00;
|
||||
@@ -367,18 +369,23 @@ class Service extends Backend
|
||||
$idx++;
|
||||
|
||||
if ($specId > 0) {
|
||||
Db::name('service_spec')->where('id', $specId)->where('service_id', $serviceId)->update([
|
||||
$updateData = [
|
||||
'name' => $name,
|
||||
'base_price' => $specPrice,
|
||||
'description' => $specDesc,
|
||||
'weigh' => $weigh,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
];
|
||||
if (array_key_exists('image', $item)) {
|
||||
$updateData['image'] = $specImage;
|
||||
}
|
||||
Db::name('service_spec')->where('id', $specId)->where('service_id', $serviceId)->update($updateData);
|
||||
$keepIds[] = $specId;
|
||||
} else {
|
||||
$newId = Db::name('service_spec')->insertGetId([
|
||||
$specId = (int)Db::name('service_spec')->insertGetId([
|
||||
'service_id' => $serviceId,
|
||||
'name' => $name,
|
||||
'image' => $specImage,
|
||||
'base_price' => $specPrice,
|
||||
'description' => $specDesc,
|
||||
'weigh' => $weigh,
|
||||
@@ -386,7 +393,35 @@ class Service extends Backend
|
||||
'createtime' => $now,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
$keepIds[] = $newId;
|
||||
$keepIds[] = $specId;
|
||||
}
|
||||
|
||||
// 若管理员为细分规格上传了参考图,自动同步更新或补充至 fa_system_gallery
|
||||
if ($specImage !== '') {
|
||||
$existingGal = Db::name('system_gallery')
|
||||
->where('service_id', $serviceId)
|
||||
->where('spec_id', $specId)
|
||||
->find();
|
||||
if ($existingGal) {
|
||||
Db::name('system_gallery')->where('id', $existingGal['id'])->update([
|
||||
'cat_id' => $catId,
|
||||
'title' => $name,
|
||||
'image' => $specImage,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
} else {
|
||||
Db::name('system_gallery')->insert([
|
||||
'cat_id' => $catId,
|
||||
'service_id' => $serviceId,
|
||||
'spec_id' => $specId,
|
||||
'title' => $name,
|
||||
'image' => $specImage,
|
||||
'weigh' => $weigh,
|
||||
'status' => 'normal',
|
||||
'createtime' => $now,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -417,6 +452,7 @@ class Service extends Backend
|
||||
Db::startTrans();
|
||||
try {
|
||||
Db::name('service_spec')->where('service_id', 'in', $idArr)->delete();
|
||||
Db::name('system_gallery')->where('service_id', 'in', $idArr)->delete();
|
||||
$deleted = Db::name('service')->where('id', 'in', $idArr)->delete();
|
||||
Db::commit();
|
||||
} catch (Exception $e) {
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\FinanceConfigService;
|
||||
use app\common\library\PaymentService;
|
||||
use think\Db;
|
||||
use think\exception\PDOException;
|
||||
|
||||
@@ -24,7 +26,7 @@ class Withdraw extends Backend
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $relationSearch = true;
|
||||
protected $searchFields = 'id,account,audit_msg,master.realname,master.mobile';
|
||||
protected $searchFields = 'id,account,audit_msg,fail_code,fail_reason,out_bill_no,transfer_bill_no,master.realname,master.mobile';
|
||||
|
||||
/**
|
||||
* 审核状态机:当前状态 => 允许流转到的目标状态
|
||||
@@ -105,10 +107,12 @@ class Withdraw extends Backend
|
||||
}
|
||||
|
||||
/**
|
||||
* 财务审核:申请信息只读,仅允许合法状态流转并做资金联动
|
||||
* - 驳回:退回师傅余额并解冻,写入钱包流水,通知师傅
|
||||
* - 通过:仅标记审核通过,等待财务打款
|
||||
* - 打款完成:划出冻结资金,写入钱包流水,通知师傅
|
||||
* 财务审核与微信商家转账打款处理:
|
||||
* - 微信渠道(channel=wechat):
|
||||
* 1) 审核通过(pass):调用微信支付 V3 新版「商家转账(场景 1005 佣金报酬)」接口生成转账单,等待师傅在小程序确认收款
|
||||
* 2) 同步状态(sync):主动查询微信商家转账单状态,若 SUCCESS 则划出冻结资金标记 done;若 FAIL/CANCELLED 则解冻退回师傅余额
|
||||
* 3) 驳回/撤销(reject):若尚未发微信转账则直接退回余额;若已发微信转账则先调微信查单并撤销确认后再退回余额(防双重资损)
|
||||
* - 银行卡渠道(channel=bank):保留审核通过 → 线下打款完成(done) / 驳回(reject)
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
@@ -116,40 +120,101 @@ class Withdraw extends Backend
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
|
||||
$wdCfg = FinanceConfigService::getWithdrawConfig();
|
||||
$isWechat = ($row['channel'] === 'wechat');
|
||||
$useWxApi = $isWechat && ($wdCfg['transfer_mode'] === 'wx_mch_transfer');
|
||||
$hasWxBill = !empty($row['out_bill_no']);
|
||||
$txState = strtoupper(trim((string)($row['transfer_state'] ?? '')));
|
||||
$flowOptions = [];
|
||||
if ($row['status'] === 'wait') {
|
||||
if ($hasWxBill) {
|
||||
if (in_array($txState, ['FAIL', 'NOT_FOUND'], true) && $useWxApi) {
|
||||
$flowOptions = ['pass', 'sync', 'reject'];
|
||||
} else {
|
||||
$flowOptions = ['sync', 'reject'];
|
||||
}
|
||||
} else {
|
||||
$flowOptions = ['pass', 'reject'];
|
||||
}
|
||||
} elseif ($row['status'] === 'pass') {
|
||||
if ($isWechat && $hasWxBill) {
|
||||
if (in_array($txState, ['FAIL', 'NOT_FOUND'], true) && $useWxApi) {
|
||||
$flowOptions = ['pass', 'sync', 'reject'];
|
||||
} else {
|
||||
$flowOptions = ['sync', 'reject'];
|
||||
}
|
||||
} elseif ($useWxApi && !$hasWxBill) {
|
||||
$flowOptions = ['pass', 'done', 'reject'];
|
||||
} else {
|
||||
$flowOptions = ['done', 'reject'];
|
||||
}
|
||||
}
|
||||
|
||||
if (false === $this->request->isPost()) {
|
||||
// 展示师傅当前钱包情况,辅助财务判断
|
||||
$master = Db::name('master')->where('id', (int)$row['master_id'])->field('id,realname,mobile,user_id,money,frozen_money')->find();
|
||||
$this->view->assign('row', $row);
|
||||
$this->view->assign('master', $master ?: []);
|
||||
$this->view->assign('flowOptions', $this->statusFlow[$row['status']] ?? []);
|
||||
$this->view->assign('flowOptions', $flowOptions);
|
||||
$this->view->assign('useWxApi', $useWxApi);
|
||||
$this->view->assign('transferStateLabel', PaymentService::transferStateLabel($row['transfer_state'] ?? ''));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$status = (string)$this->request->post('row.status');
|
||||
$auditMsg = trim((string)$this->request->post('row.audit_msg'));
|
||||
|
||||
// 状态机校验:终态禁止操作,流转目标必须合法
|
||||
if (!isset($this->statusFlow[$row['status']])) {
|
||||
$this->error('该提现单已处于终态(已驳回/已打款),不允许再次审核');
|
||||
if (empty($flowOptions)) {
|
||||
$this->error('该提现单已处于终态(已驳回/已打款),不允许再次操作');
|
||||
}
|
||||
if (!in_array($status, $this->statusFlow[$row['status']], true)) {
|
||||
if (!in_array($status, $flowOptions, true)) {
|
||||
$this->error('状态流转不合法,请刷新后重试');
|
||||
}
|
||||
if ($status === 'reject' && $auditMsg === '') {
|
||||
$this->error('驳回时必须填写驳回原因');
|
||||
$this->error('驳回或撤销转账时必须填写原因');
|
||||
}
|
||||
|
||||
// 1. 驳回或撤销转账(统一走防双重资损方法)
|
||||
if ($status === 'reject') {
|
||||
try {
|
||||
$res = PaymentService::cancelOrRejectWithdraw((int)$row['id'], $auditMsg);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success($res['message'] ?? '已驳回处理');
|
||||
}
|
||||
|
||||
// 2. 微信钱包渠道(启用微信商家转账模式时):发起微信商家转账(1005) 或 同步微信转账状态
|
||||
if ($useWxApi && $status === 'pass') {
|
||||
try {
|
||||
PaymentService::initiateWithdrawTransfer((int)$row['id'], $auditMsg);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success('已审核通过并发起微信商家转账,等待师傅在小程序「我的钱包」确认收款');
|
||||
}
|
||||
|
||||
if ($isWechat && $status === 'sync') {
|
||||
try {
|
||||
$updated = PaymentService::syncWithdrawTransfer((int)$row['id']);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error('同步微信状态失败:' . $e->getMessage());
|
||||
}
|
||||
$stateText = PaymentService::transferStateLabel($updated['transfer_state'] ?? '');
|
||||
$this->success('已同步最新微信转账状态:' . $stateText);
|
||||
}
|
||||
|
||||
// 3. 线下银行卡打款(或历史未发微信单的线下打款完成)
|
||||
$masterId = (int)$row['master_id'];
|
||||
$amount = round((float)$row['amount'], 2);
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 乐观锁更新状态,防止并发重复审核
|
||||
$affected = Db::name('withdraw')
|
||||
->where('id', $row['id'])
|
||||
->where('status', $row['status'])
|
||||
->update([
|
||||
'status' => $status,
|
||||
'audit_msg' => $auditMsg,
|
||||
'audit_msg' => $auditMsg !== '' ? $auditMsg : $row['audit_msg'],
|
||||
'updatetime' => time(),
|
||||
]);
|
||||
if (!$affected) {
|
||||
@@ -161,32 +226,11 @@ class Withdraw extends Backend
|
||||
throw new \Exception('提现师傅不存在');
|
||||
}
|
||||
|
||||
if ($status === 'reject') {
|
||||
// 驳回:解冻并退回余额,写入钱包流水
|
||||
$newMoney = round((float)$master['money'] + $amount, 2);
|
||||
Db::name('master')->where('id', $masterId)->update([
|
||||
'money' => $newMoney,
|
||||
'frozen_money' => round((float)$master['frozen_money'] - $amount, 2),
|
||||
'updatetime' => time(),
|
||||
]);
|
||||
Db::name('wallet_log')->insert([
|
||||
'user_type' => 'master',
|
||||
'user_id' => $masterId,
|
||||
'type' => 'refund',
|
||||
'amount' => $amount,
|
||||
'balance' => $newMoney,
|
||||
'order_id' => 0,
|
||||
'remark' => '提现驳回,申请金额退回钱包余额' . ($auditMsg !== '' ? '(原因:' . $auditMsg . ')' : ''),
|
||||
'createtime' => time(),
|
||||
]);
|
||||
$this->sendMasterMessage($masterId, (int)$master['user_id'], '提现申请已驳回', '您的提现申请 ¥' . $amount . ' 未通过财务审核:' . ($auditMsg !== '' ? $auditMsg : '无') . ',申请金额已退回钱包余额');
|
||||
} elseif ($status === 'pass') {
|
||||
// 审核通过:仅标记,资金保持冻结,等待财务打款
|
||||
$this->sendMasterMessage($masterId, (int)$master['user_id'], '提现审核通过', '您的提现申请 ¥' . $amount . ' 已通过审核,财务将尽快安排打款到 ' . ($row['channel'] === 'bank' ? '银行卡' : '微信钱包'));
|
||||
if ($status === 'pass') {
|
||||
$this->sendMasterMessage($masterId, (int)$master['user_id'], '提现审核通过', '您的提现申请 ¥' . $amount . ' 已通过审核,财务将尽快安排打款到银行卡');
|
||||
} elseif ($status === 'done') {
|
||||
// 打款完成:冻结资金划出
|
||||
Db::name('master')->where('id', $masterId)->update([
|
||||
'frozen_money' => round((float)$master['frozen_money'] - $amount, 2),
|
||||
'frozen_money' => max(0, round((float)$master['frozen_money'] - $amount, 2)),
|
||||
'updatetime' => time(),
|
||||
]);
|
||||
Db::name('wallet_log')->insert([
|
||||
@@ -209,6 +253,27 @@ class Withdraw extends Backend
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台列表一键同步微信商家转账单最新状态
|
||||
*/
|
||||
public function sync($ids = null)
|
||||
{
|
||||
$row = $this->model->get($ids);
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
if (empty($row['out_bill_no'])) {
|
||||
$this->error('该提现单尚未发起微信商家转账');
|
||||
}
|
||||
try {
|
||||
$updated = PaymentService::syncWithdrawTransfer((int)$row['id']);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error('同步失败:' . $e->getMessage());
|
||||
}
|
||||
$stateText = PaymentService::transferStateLabel($updated['transfer_state'] ?? '');
|
||||
$this->success('同步成功,当前微信状态:' . $stateText);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现单仅由师傅端发起,禁止后台手工添加
|
||||
*/
|
||||
|
||||
@@ -181,7 +181,7 @@ class Config extends Backend
|
||||
if ($name && $config) {
|
||||
try {
|
||||
$config->delete();
|
||||
ConfigModel::refreshFile();
|
||||
ConfigModel::refreshFile($name);
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\service;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 系统图库管理
|
||||
*
|
||||
* @icon fa fa-picture-o
|
||||
*/
|
||||
class Gallery extends Backend
|
||||
{
|
||||
/**
|
||||
* Gallery模型对象
|
||||
* @var \app\admin\model\service\Gallery
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $relationSearch = true;
|
||||
protected $searchFields = 'id,title,service.name,cat.name';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\service\Gallery;
|
||||
$this->view->assign('statusList', $this->model->getStatusList());
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
if (false === $this->request->isAjax()) {
|
||||
$cats = Db::name('service_cat')
|
||||
->where('status', 'normal')
|
||||
->where('id', '<>', 15)
|
||||
->order('weigh desc, id asc')
|
||||
->select();
|
||||
$initServiceId = (int)$this->request->get('service_id', 0);
|
||||
$initServiceName = $initServiceId > 0 ? (string)Db::name('service')->where('id', $initServiceId)->value('name') : '';
|
||||
$this->view->assign([
|
||||
'catList' => $cats,
|
||||
'initServiceId' => $initServiceId,
|
||||
'initServiceName' => $initServiceName,
|
||||
]);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
if ($this->request->request('keyField')) {
|
||||
return $this->selectpage();
|
||||
}
|
||||
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
|
||||
$list = $this->model
|
||||
->with(['cat', 'service'])
|
||||
->where($where)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
|
||||
return json(['total' => $list->total(), 'rows' => $list->items()]);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->post('row/a');
|
||||
if (!$params) {
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
$params = $this->preExcludeFields($params);
|
||||
$serviceId = isset($params['service_id']) ? (int)$params['service_id'] : 0;
|
||||
if ($serviceId <= 0) {
|
||||
$this->error('请选择所属商品');
|
||||
}
|
||||
$svc = Db::name('service')->where('id', $serviceId)->find();
|
||||
if (!$svc) {
|
||||
$this->error('所选商品不存在');
|
||||
}
|
||||
$catId = (int)$svc['cat_id'];
|
||||
$rawImages = isset($params['image']) ? trim((string)$params['image']) : '';
|
||||
$imgArr = array_values(array_filter(array_map('trim', explode(',', $rawImages))));
|
||||
if (empty($imgArr)) {
|
||||
$this->error('请至少上传一张系统参考图');
|
||||
}
|
||||
|
||||
$baseTitle = isset($params['title']) ? trim((string)$params['title']) : '';
|
||||
$weigh = isset($params['weigh']) ? (int)$params['weigh'] : 100;
|
||||
$status = (!empty($params['status']) && in_array($params['status'], ['normal', 'hidden'], true)) ? $params['status'] : 'normal';
|
||||
$now = time();
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($imgArr as $idx => $imgUrl) {
|
||||
$itemTitle = $baseTitle !== '' ? $baseTitle : (string)$svc['name'];
|
||||
if (count($imgArr) > 1 && $baseTitle !== '') {
|
||||
$itemTitle = $baseTitle . ' ' . ($idx + 1);
|
||||
}
|
||||
Db::name('system_gallery')->insert([
|
||||
'cat_id' => $catId,
|
||||
'service_id' => $serviceId,
|
||||
'spec_id' => 0,
|
||||
'title' => mb_substr($itemTitle, 0, 80),
|
||||
'image' => $imgUrl,
|
||||
'weigh' => max(0, $weigh - $idx),
|
||||
'status' => $status,
|
||||
'createtime' => $now,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
}
|
||||
Db::commit();
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
$initServiceId = (int)$this->request->get('service_id', 0);
|
||||
$initCatId = (int)$this->request->get('cat_id', 0);
|
||||
if ($initServiceId > 0 && $initCatId <= 0) {
|
||||
$initCatId = (int)Db::name('service')->where('id', $initServiceId)->value('cat_id');
|
||||
}
|
||||
$this->view->assign([
|
||||
'initCatId' => $initCatId ?: '',
|
||||
'initServiceId' => $initServiceId ?: '',
|
||||
]);
|
||||
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) {
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
$params = $this->preExcludeFields($params);
|
||||
$serviceId = isset($params['service_id']) ? (int)$params['service_id'] : (int)$row['service_id'];
|
||||
if ($serviceId <= 0) {
|
||||
$this->error('请选择所属商品');
|
||||
}
|
||||
$svc = Db::name('service')->where('id', $serviceId)->find();
|
||||
if (!$svc) {
|
||||
$this->error('所选商品不存在');
|
||||
}
|
||||
$params['cat_id'] = (int)$svc['cat_id'];
|
||||
if (empty($params['title']) || trim((string)$params['title']) === '') {
|
||||
$params['title'] = (string)$svc['name'];
|
||||
}
|
||||
if (empty($params['image']) || trim((string)$params['image']) === '') {
|
||||
$this->error('系统参考图不能为空');
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$row->allowField(true)->save($params);
|
||||
if ((int)$row['spec_id'] > 0) {
|
||||
Db::name('service_spec')
|
||||
->where('id', (int)$row['spec_id'])
|
||||
->where('service_id', $serviceId)
|
||||
->update([
|
||||
'image' => trim((string)$params['image']),
|
||||
'updatetime' => time(),
|
||||
]);
|
||||
}
|
||||
Db::commit();
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
$this->view->assign('row', $row);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户