| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace App\Module\UrsPromotion\AdminControllers\Actions;
- use App\Module\UrsPromotion\Models\UrsProfit;
- use Illuminate\Http\Request;
- use UCore\DcatAdmin\RowActionHandler;
- /**
- * 查看收益来源详情操作
- *
- * 根据收益来源类型跳转到对应的详情页面
- */
- class ViewSourceDetailAction extends RowActionHandler
- {
- /**
- * 操作按钮标题
- *
- * @var string
- */
- public $title = '查看来源';
- /**
- * 检查是否允许显示此操作
- *
- * @return bool
- */
- public function allowed()
- {
- $row = $this->getRow();
- // 只有有来源ID的记录才显示此操作
- return !empty($row->source_id) && !empty($row->source_type);
- }
- /**
- * 处理请求
- *
- * @param Request $request
- * @return mixed
- */
- public function handle(Request $request)
- {
- $id = $this->getKey();
- $profit = UrsProfit::find($id);
-
- if (!$profit) {
- return $this->response()->error('收益记录不存在');
- }
- if (empty($profit->source_id) || empty($profit->source_type)) {
- return $this->response()->error('收益来源信息不完整');
- }
- // 根据来源类型确定跳转URL
- $url = $this->getSourceUrl($profit->source_type, $profit->source_id);
-
- if (!$url) {
- return $this->response()->error('不支持的来源类型:' . $profit->source_type);
- }
- return $this->response()->redirect($url);
- }
- /**
- * 根据来源类型获取详情页面URL
- *
- * @param string $sourceType
- * @param int $sourceId
- * @return string|null
- */
- private function getSourceUrl(string $sourceType, int $sourceId): ?string
- {
- switch ($sourceType) {
- case 'land_harvest':
- // 土地收获记录
- return admin_url("land/harvest-logs/{$sourceId}");
-
- case 'user_register':
- // 用户注册记录
- return admin_url("users/{$sourceId}");
-
- case 'promotion_reward':
- // 推广奖励记录
- return admin_url("urs-promotion/profits/{$sourceId}");
-
- case 'planting_reward':
- // 种植奖励记录
- return admin_url("urs-promotion/profits/{$sourceId}");
-
- default:
- return null;
- }
- }
- }
|