| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace App\Module\UrsPromotion\AdminControllers\Actions;
- use App\Module\UrsPromotion\Models\UrsUserMapping;
- use App\Module\UrsPromotion\Services\UrsUserMappingService;
- use Illuminate\Http\Request;
- use UCore\DcatAdmin\RowActionHandler;
- /**
- * 验证映射关系操作
- *
- * 验证URS用户与农场用户的映射关系有效性
- */
- class ValidateMappingAction extends RowActionHandler
- {
- /**
- * 操作按钮标题
- *
- * @var string
- */
- public $title = '验证映射';
- /**
- * 检查是否允许显示此操作
- *
- * @return bool
- */
- public function allowed()
- {
- // 所有记录都允许验证
- return true;
- }
- /**
- * 处理请求
- *
- * @param Request $request
- * @return mixed
- */
- public function handle(Request $request)
- {
- $id = $this->getKey();
- $mapping = UrsUserMapping::find($id);
-
- if (!$mapping) {
- return $this->response()->error('用户映射记录不存在');
- }
- try {
- // 验证映射关系
- $result = UrsUserMappingService::validateMapping($mapping);
-
- if ($result['valid']) {
- $message = "映射关系验证通过!";
-
- if ($result['updated']) {
- $message .= " 状态已更新为有效。";
- } else {
- $message .= " 状态保持有效。";
- }
-
- // 添加验证详情
- if (!empty($result['details'])) {
- $message .= "\n验证详情:" . implode(', ', $result['details']);
- }
-
- return $this->response()
- ->success($message)
- ->refresh();
- } else {
- $message = "映射关系验证失败!";
-
- if ($result['updated']) {
- $message .= " 状态已更新为无效。";
- }
-
- // 添加失败原因
- if (!empty($result['reasons'])) {
- $message .= "\n失败原因:" . implode(', ', $result['reasons']);
- }
-
- return $this->response()
- ->warning($message)
- ->refresh();
- }
- } catch (\Exception $e) {
- return $this->response()->error('验证失败:' . $e->getMessage());
- }
- }
- /**
- * 确认对话框
- *
- * @return string
- */
- public function confirm()
- {
- return '确定要验证此映射关系吗?系统将检查URS用户与农场用户的关联有效性。';
- }
- }
|