作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

@@ -27,7 +27,7 @@ class RemainDay extends Command @@ -27,7 +27,7 @@ class RemainDay extends Command
27 * @var 按优化时间统计 27 * @var 按优化时间统计
28 */ 28 */
29 protected $projectId = [ 29 protected $projectId = [
30 - 1434,1812,276,2414,2974 30 + 1434,1812,276,2414,2974,793
31 ];//需要单独处理的项目 31 ];//需要单独处理的项目
32 32
33 /** 33 /**
@@ -51,6 +51,12 @@ class GeoQuestionRes extends Command @@ -51,6 +51,12 @@ class GeoQuestionRes extends Command
51 sleep(300); 51 sleep(300);
52 continue; 52 continue;
53 } 53 }
  54 + $lock_key = "geo_task_lock:$task_id";
  55 + if (!Redis::setnx($lock_key, 1)) {
  56 + $this->output("任务 $task_id 已被其他进程锁定,跳过");
  57 + continue;
  58 + }
  59 + Redis::expire($lock_key, 1200); // 1小时自动解锁
54 $this->output('执行的任务ID:' . $task_id); 60 $this->output('执行的任务ID:' . $task_id);
55 $geoQuestionModel = new GeoQuestion(); 61 $geoQuestionModel = new GeoQuestion();
56 $taskInfo = $geoQuestionModel->read(['id'=>$task_id]); 62 $taskInfo = $geoQuestionModel->read(['id'=>$task_id]);
@@ -345,7 +351,10 @@ class GeoQuestionRes extends Command @@ -345,7 +351,10 @@ class GeoQuestionRes extends Command
345 foreach ($project_ids as $project_id){ 351 foreach ($project_ids as $project_id){
346 $ids = GeoQuestion::where(['project_id' => $project_id, 'status' => GeoQuestion::STATUS_OPEN])->where('next_time', '<=', date('Y-m-d'))->pluck('id'); 352 $ids = GeoQuestion::where(['project_id' => $project_id, 'status' => GeoQuestion::STATUS_OPEN])->where('next_time', '<=', date('Y-m-d'))->pluck('id');
347 foreach ($ids as $id) { 353 foreach ($ids as $id) {
348 - Redis::lpush($key, $id); 354 + //检查任务是否执行过
  355 + if (!Redis::exists("geo_task_lock:$id")) {
  356 + Redis::lpush($key, $id);
  357 + }
349 } 358 }
350 $task_id = Redis::rpop($key); 359 $task_id = Redis::rpop($key);
351 } 360 }
@@ -73,7 +73,7 @@ class GeoWritingsTask extends Command @@ -73,7 +73,7 @@ class GeoWritingsTask extends Command
73 'status'=>2, 73 'status'=>2,
74 'writings_id'=>$id, 74 'writings_id'=>$id,
75 ]; 75 ];
76 - $geoWritingsTaskModel->edit($data,['task_id'=>$task_id]); 76 + $geoWritingsTaskModel->edit($data,['id'=>$task_id]);
77 }catch (\Exception $e){ 77 }catch (\Exception $e){
78 echo date('Y-m-d H:i:s').'保存失败:'.$task_id.$e->getMessage().PHP_EOL; 78 echo date('Y-m-d H:i:s').'保存失败:'.$task_id.$e->getMessage().PHP_EOL;
79 continue; 79 continue;
@@ -54,6 +54,7 @@ class GeoWritingsLogic extends BaseLogic @@ -54,6 +54,7 @@ class GeoWritingsLogic extends BaseLogic
54 $id = $this->param['id']; 54 $id = $this->param['id'];
55 $this->model->edit($this->param,['id'=>$id]); 55 $this->model->edit($this->param,['id'=>$id]);
56 }else{ 56 }else{
  57 + $this->param['type'] = GeoWritings::TYPE_SUBMIT;
57 $this->param['uniqid'] = uniqid().$this->param['project_id']; 58 $this->param['uniqid'] = uniqid().$this->param['project_id'];
58 $id = $this->model->addReturnId($this->param); 59 $id = $this->model->addReturnId($this->param);
59 } 60 }
@@ -135,16 +135,23 @@ class GeoQuestionResLogic extends BaseLogic @@ -135,16 +135,23 @@ class GeoQuestionResLogic extends BaseLogic
135 ]; 135 ];
136 }else{ 136 }else{
137 $keywordUrlCount = $questionLogModel->counts(['project_id'=>$this->user['project_id'],'hit'=>['!=',0]]); 137 $keywordUrlCount = $questionLogModel->counts(['project_id'=>$this->user['project_id'],'hit'=>['!=',0]]);
  138 + $keywordArrs = [];
  139 + $urlArrs = [];
138 foreach ($list as $item){ 140 foreach ($list as $item){
  141 + $keywordArrs = array_merge($keywordArrs,$item['keywords'] ?? []);
  142 + $urlArrs = array_merge($urlArrs,$item['url'] ??[]);
139 $questionTotalCount += count($item['question'] ?? []); 143 $questionTotalCount += count($item['question'] ?? []);
140 - $keywordsTotalCount += count($item['keywords'] ?? []);  
141 - $urlTotalCount += count($item['url'] ?? []);  
142 foreach ($item['keywords'] as $keyWordItem){ 144 foreach ($item['keywords'] as $keyWordItem){
143 if (!array_key_exists($keyWordItem, $keywordArr)) { 145 if (!array_key_exists($keyWordItem, $keywordArr)) {
144 $keywordArr[$keyWordItem] = $questionLogModel->counts(['project_id'=>$this->user['project_id'],'keywords'=>['like','%"'.$keyWordItem.'"%']]); 146 $keywordArr[$keyWordItem] = $questionLogModel->counts(['project_id'=>$this->user['project_id'],'keywords'=>['like','%"'.$keyWordItem.'"%']]);
145 } 147 }
146 } 148 }
147 } 149 }
  150 + // 去重
  151 + $keywordArrs = array_unique($keywordArrs);
  152 + $keywordsTotalCount = count($keywordArrs);
  153 + $urlArrs = array_unique($urlArrs);
  154 + $urlTotalCount = count($urlArrs);
148 $data = [ 155 $data = [
149 'question_count'=>$questionTotalCount, 156 'question_count'=>$questionTotalCount,
150 'keywords_count'=>$keywordsTotalCount, 157 'keywords_count'=>$keywordsTotalCount,
@@ -35,7 +35,7 @@ class GeoConf extends Base @@ -35,7 +35,7 @@ class GeoConf extends Base
35 $optimize = Cache::get($key); 35 $optimize = Cache::get($key);
36 if (empty($optimize)) { 36 if (empty($optimize)) {
37 $optimize = ManageHr::where(['status' => ManageHr::STATUS_ONE, 'entry_position' => 46])->pluck('name', 'id')->toArray(); 37 $optimize = ManageHr::where(['status' => ManageHr::STATUS_ONE, 'entry_position' => 46])->pluck('name', 'id')->toArray();
38 - $optimize[1] = '陶婵'; 38 + $optimize[11] = '陶婵';
39 $optimize[875] = '艾媛媛'; 39 $optimize[875] = '艾媛媛';
40 ksort($optimize); 40 ksort($optimize);
41 Cache::put($key, $optimize, 3600); 41 Cache::put($key, $optimize, 3600);