| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace App\Module\UrsPromotion\AdminControllers\Actions;
- use App\Module\UrsPromotion\Models\UrsUserReferral;
- use App\Module\UrsPromotion\Services\UrsReferralService;
- use Illuminate\Http\Request;
- use UCore\DcatAdmin\RowActionHandler;
- /**
- * 验证推荐关系操作
- *
- * 验证推荐关系的有效性并更新状态
- */
- class ValidateReferralAction 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();
- $referral = UrsUserReferral::find($id);
-
- if (!$referral) {
- return $this->response()->error('推荐关系记录不存在');
- }
- try {
- // 验证推荐关系
- $result = UrsReferralService::validateReferral($referral);
-
- 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 '确定要验证此推荐关系吗?系统将检查推荐关系的有效性并可能更新状态。';
- }
- }
|