diff --git a/application/admin/controller/fc/Post.php b/application/admin/controller/fc/Post.php index bbbdbb3..1121bc1 100644 --- a/application/admin/controller/fc/Post.php +++ b/application/admin/controller/fc/Post.php @@ -153,7 +153,7 @@ class Post extends Backend $mediaList[] = $row->cover; } - // 获取用户画像 + // 获取用户画像与关联商家门店资料 $userInfo = [ 'id' => $row->user_id, 'nickname' => $row->user_name ?: '未知用户', @@ -169,6 +169,11 @@ class Post extends Backend $userInfo['post_count'] = Db::name('fc_post')->where('user_id', $user['id'])->count(); } + $merchantInfo = null; + if (!empty($row->user_id)) { + $merchantInfo = Db::name('fc_merchant')->where('user_id', $row->user_id)->find(); + } + // 支持请求 JSON 详情 if ($this->request->param('format') === 'json') { $data = [ @@ -196,7 +201,8 @@ class Post extends Backend 'likes' => $row->likes, 'createtime_text' => date('Y-m-d H:i:s', $row->createtime), 'media_list' => $mediaList, - 'user' => $userInfo + 'user' => $userInfo, + 'merchant' => $merchantInfo ]; $this->success('获取成功', null, $data); } @@ -207,6 +213,7 @@ class Post extends Backend $this->view->assign('mode', $mode); $this->view->assign('row', $row); $this->view->assign('userInfo', $userInfo); + $this->view->assign('merchantInfo', $merchantInfo); $this->view->assign('mediaList', $mediaList); $this->view->assign('queue', $this->auditQueue($row->getData())); diff --git a/application/admin/controller/fc/Withdraw.php b/application/admin/controller/fc/Withdraw.php index 672111f..48742b5 100644 --- a/application/admin/controller/fc/Withdraw.php +++ b/application/admin/controller/fc/Withdraw.php @@ -6,7 +6,7 @@ use app\common\controller\Backend; use think\Db; /** - * 同城-提现 + * 同城-提现管理与审核控制器 * * @icon fa fa-circle-o */ @@ -19,6 +19,11 @@ class Withdraw extends Backend */ protected $model = null; + /** + * 初始化控制器 + * + * @return void + */ public function _initialize() { parent::_initialize(); @@ -26,16 +31,115 @@ class Withdraw extends Backend $this->view->assign("statusList", $this->model->getStatusList()); } - - /** - * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 - * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 - * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + * 提现审核详情与核验 + * + * @param mixed $ids 提现记录ID + * @return string */ + public function edit($ids = null) + { + $row = $this->model->get($ids); + if (!$row) { + $this->error(__('No Results were found')); + } + $adminIds = $this->getDataLimitAdminIds(); + if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { + $this->error(__('You have no permission')); + } + + if ($this->request->isPost()) { + $params = $this->request->post('row/a'); + if ($params) { + $params = $this->preExcludeFields($params); + // 资金安全:严禁在编辑中篡改提现单号、金额、用户ID、渠道与微信单号 + unset($params['withdraw_no'], $params['amount'], $params['user_id'], $params['channel'], $params['out_bill_no'], $params['transfer_id']); + + $result = false; + Db::startTrans(); + try { + // 只允许修改备注、处理时间等辅助信息 + $result = $row->allowField(['reason', 'paytime', 'updatetime'])->save($params); + Db::commit(); + } catch (\Throwable $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result !== false) { + $this->success(); + } else { + $this->error(__('No rows were updated')); + } + } + $this->error(__('Parameter %s can not be empty', '')); + } + + $userId = (int)$row['user_id']; + + // 1. 获取申请用户信息 + $user = Db::name('user') + ->where('id', $userId) + ->field('id,username,nickname,mobile,avatar,money,score,createtime') + ->find(); + + // 2. 获取用户同城扩展信息(微信OpenID、实名认证等) + $userExt = Db::name('fc_user_ext') + ->where('user_id', $userId) + ->field('openid,realname,realname_status,is_member,member_level') + ->find(); + + // 3. 计算用户分销佣金与提现对账数据 + $totalCommission = (float)Db::name('fc_commission') + ->where('user_id', $userId) + ->where('status', '<>', 2) + ->sum('amount'); + + $settledCommission = (float)Db::name('fc_commission') + ->where('user_id', $userId) + ->where('status', 1) + ->sum('amount'); + + $totalWithdrawn = (float)Db::name('fc_withdraw') + ->where('user_id', $userId) + ->where('status', 'paid') + ->sum('amount'); + + $appliedTotal = (float)Db::name('fc_withdraw') + ->where('user_id', $userId) + ->where('status', 'in', ['auditing', 'paying', 'paid']) + ->sum('amount'); + + // 当前剩余可提现金额 + $withdrawable = max(0, $settledCommission - $appliedTotal); + + // 4. 预设快捷驳回原因模板 + $rejectReasons = [ + '微信未实名或实名与提现账户不一致', + '提现用户未绑定微信或OpenID失效', + '关联分销订单存在售后退款,佣金核验中', + '账号涉嫌虚假刷单/违规套现,暂缓打款', + '用户联系客服主动申请撤回提现', + '微信商家转账账户余额不足,请稍后重试', + ]; + + $this->view->assign([ + 'row' => $row, + 'userInfo' => $user ?: [], + 'userExt' => $userExt ?: [], + 'totalCommission' => round($totalCommission, 2), + 'settledCommission' => round($settledCommission, 2), + 'totalWithdrawn' => round($totalWithdrawn, 2), + 'withdrawable' => round($withdrawable, 2), + 'rejectReasons' => $rejectReasons, + ]); + + return $this->view->fetch(); + } /** - * 提现打款/驳回 + * 提现打款/驳回操作处理 + * + * @return void */ public function pay() { @@ -134,6 +238,63 @@ class Withdraw extends Backend $this->success($msg); } + /** + * 同步微信商家转账状态(主动查询) + * + * @return void + */ + public function sync() + { + $ids = $this->request->post('ids'); + $ids = is_array($ids) ? $ids : explode(',', (string)$ids); + $ids = array_filter($ids); + if (!$ids) { + $this->error('请选择要同步的提现记录'); + } + $withdraws = Db::name('fc_withdraw') + ->where('id', 'in', $ids) + ->where('status', 'paying') + ->select(); + if (!$withdraws) { + $this->error('选中的记录中没有处于「转账中」的提现单'); + } + + $successCount = 0; + $failedCount = 0; + $payingCount = 0; + $errors = []; + + foreach ($withdraws as $withdraw) { + try { + $state = \app\common\library\WxTransfer::sync((int)$withdraw['id']); + if ($state === 'paid') { + $successCount++; + } elseif ($state === 'failed') { + $failedCount++; + } else { + $payingCount++; + } + } catch (\Throwable $e) { + $errors[] = $withdraw['withdraw_no'] . ':' . $e->getMessage(); + } + } + + $msg = '状态同步完成:'; + if ($successCount > 0) { + $msg .= $successCount . ' 笔已确认到账;'; + } + if ($payingCount > 0) { + $msg .= $payingCount . ' 笔仍待用户确认或处理中;'; + } + if ($failedCount > 0) { + $msg .= $failedCount . ' 笔转账失败;'; + } + if ($errors) { + $msg .= ' 异常:' . implode(';', $errors); + } + + $this->success($msg); + } } diff --git a/application/admin/view/fc/post/audit.html b/application/admin/view/fc/post/audit.html index 42251f3..068f61b 100644 --- a/application/admin/view/fc/post/audit.html +++ b/application/admin/view/fc/post/audit.html @@ -34,6 +34,39 @@ + + {if !empty($merchantInfo)} +
+
+
+
+ 认证商家门店 + {$merchantInfo.name|htmlentities} + {if $merchantInfo.audit_status == 1} + 资质已核验 + {/if} +
+ {if !empty($merchantInfo.category)} + 经营类目:{$merchantInfo.category|htmlentities} + {/if} +
+
+
+ 门店地址:{$merchantInfo.address|default='未填写实体地址'|htmlentities} +
+
+ 门店联系人:{$merchantInfo.contact|default='-'|htmlentities} +
+ {if !empty($merchantInfo.notice)} +
+ 门店公告:{$merchantInfo.notice|htmlentities} +
+ {/if} +
+
+
+ {/if} +
diff --git a/application/admin/view/fc/post/detail.html b/application/admin/view/fc/post/detail.html index 2caf28f..0a5d911 100644 --- a/application/admin/view/fc/post/detail.html +++ b/application/admin/view/fc/post/detail.html @@ -102,6 +102,39 @@
+ + {if !empty($merchantInfo)} +
+
+
+
+ 认证商家门店 + {$merchantInfo.name|htmlentities} + {if $merchantInfo.audit_status == 1} + 资质已核验 + {/if} +
+ {if !empty($merchantInfo.category)} + 经营类目:{$merchantInfo.category|htmlentities} + {/if} +
+
+
+ 门店地址:{$merchantInfo.address|default='未填写实体地址'|htmlentities} +
+
+ 门店联系人:{$merchantInfo.contact|default='-'|htmlentities} +
+ {if !empty($merchantInfo.notice)} +
+ 门店公告:{$merchantInfo.notice|htmlentities} +
+ {/if} +
+
+
+ {/if} +
diff --git a/application/admin/view/fc/withdraw/edit.html b/application/admin/view/fc/withdraw/edit.html index 8363eed..b5d28d7 100644 --- a/application/admin/view/fc/withdraw/edit.html +++ b/application/admin/view/fc/withdraw/edit.html @@ -1,26 +1,95 @@ -
+
- +
-
- 1 - 提现账单详情 +
+
+ 1 + 提现核心账单凭据 +
+
+ {switch name="row.status"} + {case value="auditing"} 待审核{/case} + {case value="paying"} 微信转账中{/case} + {case value="paid"} 已成功到账{/case} + {case value="failed"} 转账失败{/case} + {case value="rejected"} 已拒绝{/case} + {/switch} +
+ +
+
+
申请提现金额
+
+ ¥ {$row.amount|htmlentities} +
+
+
+
提现渠道
+
+ 微信零钱 / 商家转账 +
+
+
+
-
- -
- +
+ +
+ {$row.withdraw_no|htmlentities}
-
- -
- +
+ +
+ {if $row.createtime}{:date('Y-m-d H:i:s', $row.createtime)}{else/}-{/if} +
+
+
+
+ + {if condition="!empty($row.paytime)"} +
+
+
+ +
+ {:date('Y-m-d H:i:s', $row.paytime)} +
+
+
+
+ {/if} +
+
+ + +
+
+ 2 + 申请人与资金风控核验 +
+
+
+
+
+ +
+ {$userInfo.nickname|default='-'} + (ID: {$row.user_id}) +
+
+
+
+
+ +
+ {$userInfo.mobile|default='未绑定手机'}
@@ -28,73 +97,127 @@
-
- -
-
- ¥ - -
+
+ +
+ {if condition="!empty($userExt.openid) && strpos($userExt.openid, 'h5_') !== 0"} + 已绑定微信小程序 + {else/} + 未获取有效微信OpenID(打款将失败) + {/if}
-
- -
- +
+ +
+ {if condition="!empty($userExt.realname)"} + {$userExt.realname} + {else/} + 未实名 + {if condition="$row.amount >= 2000"} + (微信限制:≥2000元必须实名) + {/if} + {/if}
-
-
- -
-
- 2 - 审核状态与打款记录 -
-
-
- -
-
- {foreach name="statusList" item="vo"} - - {/foreach} + +
+
+ 用户分销账户对账核算 + {if condition="$row.amount > $withdrawable && $row.status eq 'auditing'"} + 提示:申请金额超出当前可提余额 + {else/} + 佣金账户对账正常 + {/if} +
+
+
+
累计分销佣金
+
¥{$totalCommission}
+
+
+
已结算佣金
+
¥{$settledCommission}
+
+
+
历史已提现总额
+
¥{$totalWithdrawn}
+
+
+
当前可提余额
+
¥{$withdrawable}
- -
- -
- -
-
- -
- -
- -
-
- -