作者 lyh

gx数据

@@ -42,11 +42,12 @@ class AiBlogTask extends Command @@ -42,11 +42,12 @@ class AiBlogTask extends Command
42 public function handle(){ 42 public function handle(){
43 $aiBlogTaskModel = new AiBlogTaskModel(); 43 $aiBlogTaskModel = new AiBlogTaskModel();
44 while (true){ 44 while (true){
45 - $list = $aiBlogTaskModel->list(['status'=>1,'type'=>2, 'created_at' => ['<', date('Y-m-d H:i:s')]],'id',['*'],'asc',1000); 45 + $list = $aiBlogTaskModel->formatQuery(['status'=>1,'type'=>2])->inRandomOrder()->limit(1000)->get();
46 if(empty($list)){ 46 if(empty($list)){
47 sleep(300); 47 sleep(300);
48 continue; 48 continue;
49 } 49 }
  50 + $list = $list->toArray();
50 $updateProject = []; 51 $updateProject = [];
51 foreach ($list as $item){ 52 foreach ($list as $item){
52 echo '开始->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s'); 53 echo '开始->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
@@ -58,6 +59,7 @@ class AiBlogTask extends Command @@ -58,6 +59,7 @@ class AiBlogTask extends Command
58 $aiBlogService->task_id = $item['task_id']; 59 $aiBlogService->task_id = $item['task_id'];
59 $result = $aiBlogService->getDetail(); 60 $result = $aiBlogService->getDetail();
60 if(!isset($result['status']) || $result['status'] != 200){ 61 if(!isset($result['status']) || $result['status'] != 200){
  62 + echo json_encode($result).PHP_EOL;
61 sleep(5); 63 sleep(5);
62 continue; 64 continue;
63 } 65 }
@@ -66,6 +68,7 @@ class AiBlogTask extends Command @@ -66,6 +68,7 @@ class AiBlogTask extends Command
66 $aiBlogModel = new AiBlog(); 68 $aiBlogModel = new AiBlog();
67 $aiBlogInfo = $aiBlogModel->read(['task_id'=>$item['task_id']],['id']); 69 $aiBlogInfo = $aiBlogModel->read(['task_id'=>$item['task_id']],['id']);
68 if($aiBlogInfo === false){ 70 if($aiBlogInfo === false){
  71 + echo '任务id不存在:'.$item['task_id'].PHP_EOL;
69 $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]); 72 $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
70 continue; 73 continue;
71 } 74 }
@@ -70,6 +70,28 @@ class Base extends Model @@ -70,6 +70,28 @@ class Base extends Model
70 } 70 }
71 71
72 /** 72 /**
  73 + * @remark :随机获取数据
  74 + * @name :limit_list
  75 + * @author :lyh
  76 + * @method :post
  77 + * @time :2025/3/17 17:26
  78 + */
  79 + public function limit_list($map = [],$order = 'id',$fields = ['*'],$sort = 'desc',$row = 0): array
  80 + {
  81 + $query = $this->formatQuery($map);
  82 + if($row != 0){
  83 + $query = $query->limit($row);
  84 + }
  85 + $query = $this->sortOrder($query,$order,$sort);
  86 + $lists = $query->select($fields)->get();
  87 + if (empty($lists)) {
  88 + return [];
  89 + }
  90 + $lists = $lists->toArray();
  91 + return $lists;
  92 + }
  93 +
  94 + /**
73 * @remark :获取数据详情 95 * @remark :获取数据详情
74 * @name :read 96 * @name :read
75 * @author :lyh 97 * @author :lyh