1111
1212class JudgePlugin extends BasePlugin implements PluginTaskInterface
1313{
14+ private const VOTE_RESULT_SUCCESS = 'success ' ;
15+ private const VOTE_RESULT_RETRY = 'retry ' ;
16+ private const VOTE_RESULT_SKIP = 'skip ' ;
17+
1418 private AuthFailureClassifier $ authFailureClassifier ;
1519 private ?ApiJury $ juryApi = null ;
1620
@@ -74,7 +78,8 @@ protected function judgementTask(): void
7478 return ;
7579 }
7680
77- if (!$ this ->vote ($ case ['id ' ], $ case ['vote ' ])) {
81+ $ voteResult = $ this ->vote ($ case ['id ' ], $ case ['vote ' ]);
82+ if ($ voteResult === self ::VOTE_RESULT_RETRY ) {
7883 $ this ->scheduleAfter (60.0 );
7984
8085 return ;
@@ -106,10 +111,19 @@ protected function caseCheck(string $caseId): bool
106111
107112 $ vote = $ voteInfo ['vote ' ];
108113 $ voteText = $ voteInfo ['vote_text ' ];
109- $ this ->wait_case [] = ['id ' => $ caseId , 'vote ' => $ vote ];
110114 $ this ->info ("風機委員: 案件 {$ caseId }的預測投票結果 {$ vote }( {$ voteText }) " );
111- $ this ->vote ($ caseId , 0 );
112- $ this ->scheduleAfter (65 );
115+
116+ $ voteResult = $ this ->vote ($ caseId , 0 , 0 );
117+ if ($ voteResult === self ::VOTE_RESULT_SUCCESS ) {
118+ $ this ->wait_case [] = ['id ' => $ caseId , 'vote ' => $ vote ];
119+ $ this ->scheduleAfter (65 );
120+
121+ return false ;
122+ }
123+
124+ if ($ voteResult === self ::VOTE_RESULT_RETRY ) {
125+ $ this ->scheduleAfter (60.0 );
126+ }
113127
114128 return false ;
115129 }
@@ -118,20 +132,37 @@ protected function caseCheck(string $caseId): bool
118132 * 处理vote
119133 * @param string $caseId
120134 * @param int $vote
121- * @return bool
135+ * @return self::VOTE_RESULT_*
122136 */
123- private function vote (string $ caseId , int $ vote ): bool
137+ private function vote (string $ caseId , int $ vote, ? int $ insiders = null ): string
124138 {
125- $ response = $ this ->juryApi ()->vote ($ caseId , $ vote , '' , 0 , array_rand ([0 , 1 ]));
139+ $ response = $ this ->juryApi ()->vote ($ caseId , $ vote , '' , 0 , $ insiders ?? array_rand ([0 , 1 ]));
126140 $ this ->authFailureClassifier ->assertNotAuthFailure ($ response , "風機委員: 案件 {$ caseId }投票时账号未登录 " );
127141
128- if ( $ response ['code ' ]) {
129- $ this -> warning ( " 風機委員: 案件 { $ caseId } 投票失败 { $ response ['code ' ]} -> { $ response [ ' message ' ]}" );
130- return false ;
131- } else {
142+ $ code = ( int )( $ response ['code ' ] ?? - 500 );
143+ $ message = trim (( string )( $ response ['message ' ] ?? '' ) );
144+
145+ if ( $ code === 0 ) {
132146 $ this ->notice ("風機委員: 案件 {$ caseId }投票成功 " );
133- return true ;
147+
148+ return self ::VOTE_RESULT_SUCCESS ;
149+ }
150+
151+ $ logMessage = "風機委員: 案件 {$ caseId }投票失败 {$ code } -> {$ message }" ;
152+ if ($ this ->isTerminalVoteFailure ($ code , $ message )) {
153+ $ this ->warning ($ logMessage . ',跳过该案件 ' );
154+
155+ return self ::VOTE_RESULT_SKIP ;
134156 }
157+
158+ $ this ->warning ($ logMessage );
159+
160+ return self ::VOTE_RESULT_RETRY ;
161+ }
162+
163+ private function isTerminalVoteFailure (int $ code , string $ message ): bool
164+ {
165+ return in_array ($ code , [25009 , 25018 ], true ) || str_contains ($ message , '不能进行此操作 ' );
135166 }
136167
137168 /**
0 commit comments