作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

@@ -79,7 +79,7 @@ class PushAiccData extends Command @@ -79,7 +79,7 @@ class PushAiccData extends Command
79 $data['friend_id'] = $isExists->friend_id; 79 $data['friend_id'] = $isExists->friend_id;
80 $data['user_id'] = $isExists->user_id; 80 $data['user_id'] = $isExists->user_id;
81 81
82 - $url = env('AICC_URL'); 82 + $url = env('AICC_URL') . env('AICC_PUSH_API_URL');
83 $msg = http_post($url, json_encode(compact('data'))); 83 $msg = http_post($url, json_encode(compact('data')));
84 $status_code = 0; 84 $status_code = 0;
85 if ($msg) { 85 if ($msg) {
@@ -105,7 +105,7 @@ class PushAiccData extends Command @@ -105,7 +105,7 @@ class PushAiccData extends Command
105 105
106 public function post_data($data) 106 public function post_data($data)
107 { 107 {
108 - $url = env('AICC_URL'); 108 + $url = env('AICC_URL') . env('AICC_PUSH_API_URL');
109 $msg = http_post($url, json_encode(compact('data'))); 109 $msg = http_post($url, json_encode(compact('data')));
110 print_r($msg); 110 print_r($msg);
111 } 111 }
@@ -33,10 +33,11 @@ class UpdateController extends BaseController @@ -33,10 +33,11 @@ class UpdateController extends BaseController
33 * @method :post 33 * @method :post
34 * @time :2023/8/19 9:25 34 * @time :2023/8/19 9:25
35 */ 35 */
36 - public function updateSeoTdk(){ 36 + public function updateSeoTdk()
  37 + {
37 $this->request->validate([ 38 $this->request->validate([
38 - 'project_id'=>'required',  
39 - ],[ 39 + 'project_id' => 'required',
  40 + ], [
40 'project_id.required' => 'project_id不能为空', 41 'project_id.required' => 'project_id不能为空',
41 ]); 42 ]);
42 ProjectUpdateTdk::add_task($this->param['project_id']); 43 ProjectUpdateTdk::add_task($this->param['project_id']);
@@ -48,14 +49,42 @@ class UpdateController extends BaseController @@ -48,14 +49,42 @@ class UpdateController extends BaseController
48 * @author Akun 49 * @author Akun
49 * @date 2023/11/24 11:33 50 * @date 2023/11/24 11:33
50 */ 51 */
51 - public function dataCollect(){ 52 + public function dataCollect()
  53 + {
52 $this->request->validate([ 54 $this->request->validate([
53 - 'project_id'=>'required',  
54 - ],[ 55 + 'project_id' => 'required',
  56 + 'type' => 'required',
  57 + ], [
55 'project_id.required' => 'project_id不能为空', 58 'project_id.required' => 'project_id不能为空',
  59 + 'type.required' => '采集类型不能为空',
56 ]); 60 ]);
57 61
58 - UpdateLog::updateLog($this->param['project_id']);  
59 - $this->response('任务添加成功'); 62 + $update_info = UpdateLog::where('project_id', $this->param['project_id'])->first();
  63 + if (!$update_info) {
  64 + $this->fail('当前项目非升级项目,无法采集');
  65 + }
  66 +
  67 + $project = ProjectServer::useProject($this->param['project_id']);
  68 + if ($project) {
  69 + try {
  70 + DB::connection('custom_mysql')->statement("DELETE FROM `gl_collect_source` WHERE `origin` LIKE '%.css%' OR `origin` LIKE '%.js%'");
  71 + DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0 WHERE `language` = ''");
  72 + } catch (\Exception $e) {
  73 + errorLog('重新采集升级项目数据', $this->param, $e);
  74 +
  75 + $this->fail('采集任务添加失败');
  76 + }
  77 + }
  78 + //关闭数据库
  79 + DB::disconnect('custom_mysql');
  80 +
  81 + $update = ['collect_status' => 0];
  82 + if ($this->param['type'] == 2) {
  83 + $update['status'] = 0;
  84 + }
  85 +
  86 + UpdateLog::where('project_id', $this->param['project_id'])->whereIn('api_type', ['post', 'page', 'news', 'blog'])->update($update);
  87 +
  88 + $this->response('采集任务添加成功');
60 } 89 }
61 } 90 }
@@ -6,7 +6,9 @@ use App\Enums\Common\Code; @@ -6,7 +6,9 @@ use App\Enums\Common\Code;
6 use App\Exceptions\BsideGlobalException; 6 use App\Exceptions\BsideGlobalException;
7 use App\Http\Controllers\Bside\BaseController; 7 use App\Http\Controllers\Bside\BaseController;
8 use App\Http\Logic\Aside\ProjectAssociation\ProjectAssociationLogic; 8 use App\Http\Logic\Aside\ProjectAssociation\ProjectAssociationLogic;
  9 +use App\Models\ProjectAssociation\ProjectAssociation;
9 use Illuminate\Http\Request; 10 use Illuminate\Http\Request;
  11 +use Illuminate\Support\Facades\DB;
10 use Psr\Container\ContainerExceptionInterface; 12 use Psr\Container\ContainerExceptionInterface;
11 use Psr\Container\NotFoundExceptionInterface; 13 use Psr\Container\NotFoundExceptionInterface;
12 14
@@ -31,9 +33,9 @@ class ProjectAssociationController extends BaseController @@ -31,9 +33,9 @@ class ProjectAssociationController extends BaseController
31 if (empty($project_id)) { 33 if (empty($project_id)) {
32 $this->fail('请选择项目!', Code::USER_PARAMS_ERROE); 34 $this->fail('请选择项目!', Code::USER_PARAMS_ERROE);
33 } 35 }
34 - $status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用 36 + $status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用
35 37
36 - $user_id = (int)env('AICC_WECHAT_USER_ID') ?? 0; 38 + $user_id = (int)env('AICC_WECHAT_USER_ID') ?? 0;
37 if (empty($user_id) && $status) { 39 if (empty($user_id) && $status) {
38 $this->fail('请选择要绑定的AICC用户!', Code::USER_PARAMS_ERROE); 40 $this->fail('请选择要绑定的AICC用户!', Code::USER_PARAMS_ERROE);
39 } 41 }
@@ -44,8 +46,68 @@ class ProjectAssociationController extends BaseController @@ -44,8 +46,68 @@ class ProjectAssociationController extends BaseController
44 $nickname = request()->post('nickname', ''); 46 $nickname = request()->post('nickname', '');
45 $user_name = request()->post('user_name', ''); 47 $user_name = request()->post('user_name', '');
46 $image = request()->post('image', ''); 48 $image = request()->post('image', '');
47 - $data = compact('project_id', 'user_id', 'friend_id', 'nickname', 'user_name', 'image'); 49 + $data = compact('project_id', 'user_id', 'friend_id', 'nickname', 'user_name', 'image');
48 $this->ProjectAssociationLogic->saveWeChatData($data); 50 $this->ProjectAssociationLogic->saveWeChatData($data);
49 $this->response('success'); 51 $this->response('success');
50 } 52 }
  53 +
  54 + public function check()
  55 + {
  56 + $project_id = (int)request()->input('project_id', 0);
  57 + $status = request()->input('status');
  58 + // 重载redis缓存
  59 + $cache = request()->input('cache');
  60 + if (isset($status)) {
  61 + $status = (int)$status ? ProjectAssociation::STATUS_NORMAL : ProjectAssociation::STATUS_DISABLED;
  62 + }
  63 + $isRes = $this->ProjectAssociationLogic->normal($project_id);
  64 + DB::beginTransaction();
  65 + try {
  66 + // 当数据不存在时并开启状态,自动添加一条数据
  67 + if (is_null($isRes) && (!is_null($status) && $status)) {
  68 + $isRes = $this->ProjectAssociationLogic->disabled($project_id);
  69 + if (is_null($isRes)) {
  70 + $isRes = new ProjectAssociation();
  71 + }
  72 + $isRes->project_id = $project_id;
  73 + $isRes->user_id = (int)env('AICC_WECHAT_USER_ID');
  74 + $isRes->status = $status;
  75 + $isRes->save();
  76 + DB::commit();
  77 + } // 关闭状态
  78 + elseif (!is_null($isRes) && (!is_null($status) && empty($status))) {
  79 + $isRes->status = $status;
  80 + $isRes->save();
  81 + DB::commit();
  82 + return [
  83 + 'code' => Code::SUCCESS,
  84 + 'data' => [],
  85 + 'message' => '关闭AICC绑定成功!',
  86 + ];
  87 + }
  88 + } catch (\Exception $exception) {
  89 + DB::rollBack();
  90 + $this->response('数据错误,请重试!', Code::SERVER_ERROR);
  91 + }
  92 + if (is_null($isRes)) {
  93 + $this->response('请开启AICC绑定!', Code::USER_ERROR, []);
  94 + }
  95 + $redis_key = 'aicc_friend_lists_' . (int)env('AICC_WECHAT_USER_ID');
  96 + $result = isset($cache) ? false : redis_get($redis_key);
  97 + if (empty($result)) {
  98 + $url = env('AICC_URL') . env('AICC_WECHAT_FRIEND_API_URL');
  99 + $result = curlGet($url);
  100 + redis_set($redis_key, json_encode($result));
  101 + } else {
  102 + $result = json_decode($result, true);
  103 + }
  104 +
  105 + $result['info'] = [
  106 + 'friend_id' => $isRes->friend_id ?? 0,
  107 + 'nickname' => $isRes->nickname ?? '',
  108 + 'user_name' => $isRes->user_name ?? '',
  109 + 'image' => $isRes->image ?? '',
  110 + ];
  111 + $this->response('success', Code::SUCCESS, $result);
  112 + }
51 } 113 }
@@ -110,26 +110,23 @@ class DomainInfoLogic extends BaseLogic @@ -110,26 +110,23 @@ class DomainInfoLogic extends BaseLogic
110 } 110 }
111 111
112 /** 112 /**
113 - * @remark :删除域名  
114 - * @name :delDomain  
115 - * @author :lyh  
116 - * @method :post  
117 - * @time :2023/8/1 15:41 113 + * 删除域名
  114 + * @return array
  115 + * @throws \App\Exceptions\AsideGlobalException
  116 + * @throws \App\Exceptions\BsideGlobalException
118 */ 117 */
119 public function delDomain(){ 118 public function delDomain(){
120 $ids = $this->param['id']; 119 $ids = $this->param['id'];
  120 + // 初始化数据
  121 + if (FALSE == is_array($ids))
  122 + $ids = [$ids];
121 foreach ($ids as $k => $v){ 123 foreach ($ids as $k => $v){
122 - $info = $this->model->read(['id'=>$v]);  
123 - $deployOptimizeModel = new DeployOptimize();  
124 - $domainInfo = $deployOptimizeModel->read(['domain'=>$info['domain']]);  
125 - if($domainInfo !== false){  
126 - $this->fail('当前域名正在使用中');  
127 - }  
128 - }  
129 - $this->param['id'] = ['in',$ids];  
130 - $rs = $this->model->del($this->param);  
131 - if($rs === false){  
132 - $this->fail('error'); 124 + $domain = DomainInfo::where(['id' => $v])->first();
  125 + if (empty($domain))
  126 + continue;
  127 + if (FALSE == empty($domain['project_id']))
  128 + $this->fail($domain->domain . '域名正在使用中, 删除失败!');
  129 + $domain->delete();
133 } 130 }
134 return $this->success(); 131 return $this->success();
135 } 132 }
@@ -5,6 +5,8 @@ namespace App\Http\Logic\Aside\ProjectAssociation; @@ -5,6 +5,8 @@ namespace App\Http\Logic\Aside\ProjectAssociation;
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Http\Logic\Logic; 6 use App\Http\Logic\Logic;
7 use App\Models\ProjectAssociation\ProjectAssociation; 7 use App\Models\ProjectAssociation\ProjectAssociation;
  8 +use Illuminate\Database\Eloquent\Builder;
  9 +use Illuminate\Database\Eloquent\Model;
8 use Illuminate\Support\Facades\DB; 10 use Illuminate\Support\Facades\DB;
9 11
10 class ProjectAssociationLogic extends Logic 12 class ProjectAssociationLogic extends Logic
@@ -24,4 +26,25 @@ class ProjectAssociationLogic extends Logic @@ -24,4 +26,25 @@ class ProjectAssociationLogic extends Logic
24 } 26 }
25 return $status; 27 return $status;
26 } 28 }
  29 +
  30 + /**
  31 + * status - 正常
  32 + * @param $project_id
  33 + * @return ProjectAssociation|Builder|Model|object|null
  34 + */
  35 + public function normal($project_id)
  36 + {
  37 + return ProjectAssociation::query()->whereProjectId($project_id)->whereStatus(ProjectAssociation::STATUS_NORMAL)->first();
  38 + }
  39 +
  40 +
  41 + /**
  42 + * status - 禁用
  43 + * @param $project_id
  44 + * @return ProjectAssociation|Builder|Model|object|null
  45 + */
  46 + public function disabled($project_id)
  47 + {
  48 + return ProjectAssociation::query()->whereProjectId($project_id)->whereStatus(ProjectAssociation::STATUS_DISABLED)->first();
  49 + }
27 } 50 }
@@ -73,6 +73,8 @@ Route::middleware(['aloginauth'])->group(function () { @@ -73,6 +73,8 @@ Route::middleware(['aloginauth'])->group(function () {
73 Route::any('/log', [Aside\Ai\AiLogController::class, 'lists'])->name('admin.lists'); 73 Route::any('/log', [Aside\Ai\AiLogController::class, 'lists'])->name('admin.lists');
74 // 绑定AICC微信应用 74 // 绑定AICC微信应用
75 Route::post('/wechat', [ProjectAssociationController::class, 'saveWeChatData'])->name('admin.aicc.wechat'); 75 Route::post('/wechat', [ProjectAssociationController::class, 'saveWeChatData'])->name('admin.aicc.wechat');
  76 + // OA后台开启关闭AICC用户绑定
  77 + Route::post('/check', [ProjectAssociationController::class, 'check'])->name('admin.aicc.check');
76 }); 78 });
77 //特殊模块权限设置 79 //特殊模块权限设置
78 Route::prefix('special')->group(function () { 80 Route::prefix('special')->group(function () {