| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 | 
							- <?php
 
- /**
 
-  * IdentifyFire.php UTF-8
 
-  *  实名认证队列消耗
 
-  *
 
-  * @date    : 2021/4/28 11:54
 
-  *
 
-  * @license 这不是一个自由软件,未经授权不许任何使用和传播。
 
-  * @author  : chenbingling <cbl@huosdk.com>
 
-  * @version : HUOSDK-IDENTITY 1.0
 
-  */
 
- namespace huoIdentify\lib\queue\job;
 
- use huoIdentify\lib\queue\constant\JobConst;
 
- use huoIdentify\model\IdentifyInQueueModel;
 
- use huolib\queue\job\Fire;
 
- use think\queue\Job;
 
- class IdentifyFire extends Fire {
 
-     /**
 
-      * fire方法是消息队列默认调用的方法
 
-      *
 
-      * @param Job         $job  当前的任务对象
 
-      * @param array|mixed $data 发布任务时自定义的数据
 
-      */
 
-     public function fire(Job $job, $data) {
 
-         $_is_job_done = $this->doJob($data);
 
-         if ($_is_job_done) {
 
-             /* 如果任务执行成功, 记得删除任务 */
 
-             $job->delete();
 
-         } else {
 
-             $_limit_attempts = get_val($data, 'attempts', JobConst::JOB_ATTEMPTS_MAX_CNT);
 
-             $_attempts = $job->attempts();
 
-             if ($_attempts >= $_limit_attempts) {
 
-                 /* 任务达到最大次数则删除任务不再执行 */
 
-                 $job->delete();
 
-                 $this->deleteData($data);
 
-             } else {
 
-                 /* 重新发布任务 */
 
-                 switch ($_attempts) {
 
-                     case 1:
 
-                         $_delay = JobConst::JOB_ATTEMPTS_SECOND_TIME;
 
-                         break;
 
-                     case 2:
 
-                         $_delay = JobConst::JOB_ATTEMPTS_THIRD_TIME;
 
-                         break;
 
-                     case 3:
 
-                         $_delay = JobConst::JOB_ATTEMPTS_FOURTH_TIME;
 
-                         break;
 
-                     case 4:
 
-                         $_delay = JobConst::JOB_ATTEMPTS_FIFTH_TIME;
 
-                         break;
 
-                     default:
 
-                         $_delay = JobConst::JOB_ATTEMPTS_ONCE_TIME;
 
-                 }
 
-                 $job->release($_delay); /* $_delay为延迟时间,表示该任务延迟$_delay秒后再执行 */
 
-             }
 
-         }
 
-     }
 
-     /**
 
-      * 根据消息中的数据进行实际的业务处理
 
-      *
 
-      * @param array $data 发布任务时自定义的数据
 
-      *
 
-      * @return bool 任务执行的结果
 
-      */
 
-     public function doJob($data) {
 
-         $_iiq_id = isset($data['iiq_id']) ? $data['iiq_id'] : '';
 
-         if (empty($_iiq_id)) {
 
-             /* $_iiq_id 为空认为执行成功,否则会重复入队列 */
 
-             return true;
 
-         }
 
-         $_identify_class = isset($data['identify_class']) ? $data['identify_class'] : '';
 
-         if (class_exists($_identify_class)) {
 
-             return (new $_identify_class())->checkFromQueue($_iiq_id);
 
-         }
 
-         return true;
 
-     }
 
-     /**
 
-      * 删除数据库数据
 
-      *
 
-      * @param $data
 
-      */
 
-     public function deleteData($data) {
 
-         $_iiq_id = isset($data['iiq_id']) ? $data['iiq_id'] : '';
 
-         if (!empty($_iiq_id)) {
 
-             (new IdentifyInQueueModel())->deleteData($_iiq_id);
 
-         }
 
-     }
 
- }
 
 
  |