SiteLogic_bak.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/4/15 0015
  6. * Time: 14:44
  7. */
  8. namespace App\Http\Logics\Admin;
  9. use App\Http\Models\CustomerLog;
  10. use App\Http\Models\DemoLog;
  11. use App\Http\Models\HootsuiteHistory;
  12. use App\Http\Models\HootsuiteUser;
  13. use App\Http\Models\Role;
  14. use App\Http\Models\Site;
  15. use App\Http\Models\SiteAddition;
  16. use App\Http\Models\SiteEnterprise;
  17. use App\Http\Models\SiteInfo;
  18. use App\Http\Models\SiteMarketer;
  19. use App\Http\Models\SitePayment;
  20. use App\Http\Models\SiteSns;
  21. use App\Http\Models\SiteStation;
  22. use App\Http\Models\Social;
  23. use App\Http\Models\SocialPublish;
  24. use App\Http\Models\User;
  25. use App\Http\Services\TemplateLibraryApiService;
  26. use Illuminate\Support\Facades\Auth;
  27. use Illuminate\Support\Facades\DB;
  28. use Illuminate\Support\Facades\Log;
  29. use \Illuminate\Database\ConnectionInterface;
  30. use GuzzleHttp\Client;
  31. class SiteLogic
  32. {
  33. public function updateOrCreate($validated, $id)
  34. {
  35. if (strpos($validated['site']['domain'], 'www') !== false) {
  36. return response()->json(['message' => '域名不要包含www'], 400);
  37. }
  38. if ($existsSite = Site::query()->where(['domain' => $validated['site']['domain']])->first()) {
  39. if ($existsSite->id != $id) {
  40. return response()->json(['message' => '域名已存在'], 400);
  41. }
  42. }
  43. if ($id == 0) {
  44. $validated['site']['identifier'] = (new Site)->identifier();
  45. if (empty($validated['site']['old_id'])) { //如果填写了说明是之前 rank上有 这里只是把它关联起来
  46. try { //如果没有的话那就是默认要创建 并且关联
  47. $siteSync = new SiteSyncLogic();
  48. $oldId = $siteSync->insertGetId($siteSync->fieldMap($validated['site']));
  49. $validated['site']['old_id'] = $oldId;
  50. } catch (\Throwable $throwable) {
  51. Log::error(var_export($throwable->getMessage(), 1));
  52. return response()->json(['message' => '远程添加项目出错'], 400);
  53. }
  54. }
  55. $validated['site']['status'] = 1; //建站期
  56. $validated['site']['server_id'] = 1; //20服务器
  57. $site = Site::query()->create($validated['site']);
  58. $siteId = $site->id;
  59. SiteInfo::query()->create([
  60. 'site_id' => $siteId,
  61. ]);
  62. DB::table('user_has_sites')->insert([
  63. 'site_id' => $siteId,
  64. 'user_id' => Auth::id()
  65. ]);
  66. $validated['payment']['site_id'] = $siteId;
  67. SitePayment::query()->create($validated['payment']);
  68. (new ProcessLogic)->initProcess($siteId); //生成初始项目流程
  69. } else {
  70. $site = Site::query()->where(['id' => $id])->first();
  71. if (!$site) return response()->json(['message' => '数据不存在']);
  72. $site->update($validated['site']);
  73. SitePayment::query()->where(['site_id' => $id])->update($validated['payment']);
  74. // 同步老rank平台的数据
  75. $siteSync = new SiteSyncLogic();
  76. $siteSync->update($site->old_id, $siteSync->fieldMap($site->toArray()));
  77. }
  78. return response()->json(['message' => '操作成功']);
  79. }
  80. /**
  81. * 客户完善处理
  82. * @param $validated
  83. * @param $act
  84. * @param $source
  85. * @param $siteId
  86. * @return \Illuminate\Http\JsonResponse
  87. */
  88. public function customerHandle($validated, $act, $source, $siteId)
  89. {
  90. // $process = Process::query()->where(['identifier' => 'know_customer_info'])->first();
  91. // if (!$process) return response()->json(['message' => '总流程信息不存在'], 400);
  92. // SiteProcess::query()->where(['site_id' => $siteId, 'process_id' => $process->id])->update(['active' => 1]);
  93. $user = auth()->user();
  94. $site = Site::query()->where(['id' => $siteId])->first();
  95. if (!$site) {
  96. return response()->json(['message' => '站点信息不存在'], 400);
  97. }
  98. $siteMap = ['site_id' => $siteId];
  99. // $source = 'customer';
  100. switch ($act) {
  101. case 'addition':
  102. if ($source == 'customer') {
  103. $addition = SiteAddition::query()->where($siteMap)->first();
  104. $additionArr = $addition ? $addition->toArray() : [];
  105. $diff = array_diff_assoc($validated['addition'], $additionArr);
  106. if ($diff) {
  107. $oldData = [];
  108. $diffKeys = array_keys($diff);
  109. foreach ($diffKeys as $inx) {
  110. $oldData[$inx] = $additionArr[$inx] ?? '';
  111. }
  112. CustomerLog::query()->create([
  113. 'site_id' => $siteId,
  114. 'title' => '网站信息',
  115. 'old_content' => serialize($oldData),
  116. 'content' => serialize($diff),
  117. 'operator_id' => $user->id,
  118. 'operator_name' => $user->nickname,
  119. 'site_name' => $site->cn_title,
  120. 'type' => $act
  121. ]);
  122. }
  123. }
  124. SiteAddition::query()->updateOrCreate($siteMap, $validated['addition'] + $siteMap);
  125. break;
  126. case 'keyword':
  127. if ($source == 'customer') {
  128. $keyword = SiteInfo::query()->where($siteMap)->first();
  129. $keywordArr = $keyword ? $keyword->keyword : [];
  130. $inputKeyword = $validated['keyword'] ?? [];
  131. $diff = array_diff_assoc($inputKeyword, $keywordArr);
  132. if ($diff) {
  133. $oldData = [];
  134. $diffKeys = array_keys($diff);
  135. foreach ($diffKeys as $inx) {
  136. $oldData[$inx] = $additionArr[$inx] ?? '';
  137. }
  138. CustomerLog::query()->create([
  139. 'site_id' => $siteId,
  140. 'title' => '核心关键词',
  141. 'old_content' => serialize($oldData),
  142. 'content' => serialize($diff),
  143. 'operator_id' => $user->id,
  144. 'operator_name' => $user->nickname,
  145. 'site_name' => $site->cn_title,
  146. 'type' => $act
  147. ]);
  148. }
  149. }
  150. SiteInfo::query()->updateOrCreate($siteMap, ['keyword' => ($validated['keyword'] ?? [])] + $siteMap);
  151. break;
  152. case 'station':
  153. if ($source == 'customer') {
  154. // $record = SiteStation::query()->where($siteMap)->first();
  155. // $recordArr = $record ? $record->toArray() : [];
  156. // dump($validated['station'],$recordArr);
  157. // $diff = array_diff_assoc($validated['station'], $recordArr);
  158. // if ($diff) {
  159. //
  160. // $oldData = [];
  161. // $diffKeys = array_keys($diff);
  162. // foreach ($diffKeys as $inx) {
  163. // $oldData[$inx] = $additionArr[$inx] ?? '';
  164. // }
  165. //
  166. // CustomerLog::query()->create([
  167. // 'site_id' => $siteId,
  168. // 'title' => '其他项目信息',
  169. // 'old_content' => serialize($oldData),
  170. // 'content' => serialize($diff),
  171. //
  172. // 'operator_id' => $user->id,
  173. // 'operator_name' => $user->nickname,
  174. // 'site_name' => $site->cn_title,
  175. // 'type' => $act
  176. // ]);
  177. // }
  178. }
  179. $validated['station']['compete_sites'] = $validated['station']['compete_sites'] ?? null;
  180. SiteStation::query()->updateOrCreate($siteMap, $validated['station'] + $siteMap);
  181. break;
  182. case 'enterprise':
  183. if ($source == 'customer') {
  184. $record = SiteEnterprise::query()->where($siteMap)->first();
  185. $recordArr = $record ? $record->toArray() : [];
  186. $diff = array_diff_assoc($validated['enterprise'], $recordArr);
  187. if ($diff) {
  188. $oldData = [];
  189. $diffKeys = array_keys($diff);
  190. foreach ($diffKeys as $inx) {
  191. $oldData[$inx] = $additionArr[$inx] ?? '';
  192. }
  193. CustomerLog::query()->create([
  194. 'site_id' => $siteId,
  195. 'title' => '项目基础信息',
  196. 'old_content' => serialize($oldData),
  197. 'content' => serialize($diff),
  198. 'operator_id' => $user->id,
  199. 'operator_name' => $user->nickname,
  200. 'site_name' => $site->cn_title,
  201. 'type' => $act
  202. ]);
  203. }
  204. }
  205. SiteEnterprise::query()->updateOrCreate($siteMap, $validated['enterprise'] + $siteMap);
  206. break;
  207. case 'marketer':
  208. if ($source == 'customer') {
  209. $record = SiteMarketer::query()->where($siteMap)->first();
  210. $recordArr = $record ? $record->toArray() : [];
  211. $diff = array_diff_assoc($validated['marketer'], $recordArr);
  212. if ($diff) {
  213. $oldData = [];
  214. $diffKeys = array_keys($diff);
  215. foreach ($diffKeys as $inx) {
  216. $oldData[$inx] = $additionArr[$inx] ?? '';
  217. }
  218. CustomerLog::query()->create([
  219. 'site_id' => $siteId,
  220. 'title' => '营销发布人信息',
  221. 'old_content' => serialize($oldData),
  222. 'content' => serialize($diff),
  223. 'operator_id' => $user->id,
  224. 'operator_name' => $user->nickname,
  225. 'site_name' => $site->cn_title,
  226. 'type' => $act
  227. ]);
  228. }
  229. }
  230. SiteMarketer::query()->updateOrCreate($siteMap, $validated['marketer'] + $siteMap);
  231. break;
  232. case 'sns':
  233. if ($source == 'customer') {
  234. $record = SiteSns::query()->where($siteMap)->first();
  235. $recordArr = $record ? $record->toArray() : [];
  236. $diff = array_diff_assoc($validated['sns'], $recordArr);
  237. if ($diff) {
  238. $oldData = [];
  239. $diffKeys = array_keys($diff);
  240. foreach ($diffKeys as $inx) {
  241. $oldData[$inx] = $additionArr[$inx] ?? '';
  242. }
  243. CustomerLog::query()->create([
  244. 'site_id' => $siteId,
  245. 'title' => 'SNS 社交资料',
  246. 'old_content' => serialize($oldData),
  247. 'content' => serialize($diff),
  248. 'operator_id' => $user->id,
  249. 'operator_name' => $user->nickname,
  250. 'site_name' => $site->cn_title,
  251. 'type' => $act
  252. ]);
  253. }
  254. }
  255. SiteSns::query()->updateOrCreate($siteMap, $validated['sns'] + $siteMap);
  256. break;
  257. default:
  258. return response()->json(['message' => '参数提交错误'], 400);
  259. }
  260. return response()->json(['message' => '操作成功']);
  261. }
  262. public function overview($siteId, $validated, $type)
  263. {
  264. if ($type == 1) { //基本信息
  265. if (strpos($validated['site']['domain'], 'www') !== false) {
  266. return response()->json(['message' => '域名不要包含www'], 400);
  267. }
  268. if ($existsSite = Site::query()->where(['domain' => $validated['site']['domain']])->first()) {
  269. if ($existsSite->id != $siteId) {
  270. return response()->json(['message' => '域名已存在'], 400);
  271. }
  272. }
  273. $site = Site::query()->with(['server'])->where(['id' => $siteId])->first();
  274. if (!$site) return response()->json(['message' => '数据不存在'], 400);
  275. if ($validated['site']['keyword_goal'] != $site->keyword_goal && $site->old_id) {
  276. $homepageReachCount = DB::connection('rank')->table('project_history')->select('top10')
  277. ->where([
  278. ['project_id', '=', (int)$site->old_id],
  279. ['create_time', '<', time()]
  280. ])->orderByDesc('create_time')->first();
  281. if ($validated['site']['keyword_goal'] > ($homepageReachCount->top10 ?? 0)) {
  282. $rankUpdate = [
  283. 'reach_days' => 0, //达标天数
  284. 'expire_time' => 0, //预期到期时间
  285. ];
  286. }
  287. }
  288. $site->update($validated['site']);
  289. //同步老rank平台的数据
  290. $siteSync = new SiteSyncLogic();
  291. if (!empty($site->server)) {
  292. $server = ['server_ip' => $site->server->server_ip];
  293. }
  294. $siteSync->update($site->old_id, $siteSync->fieldMap($site->toArray() + ($server ?? [])) + ($rankUpdate ?? []));
  295. if ($site->status == 7) {
  296. DB::connection('rank')->table('project')->where(['id' => $site->old_id])->update(['allow_googlerank' => 0]);
  297. }
  298. //同步到模版站
  299. if ($site->is_stencil == 1) {
  300. $connection = DB::connection('template');
  301. $update = [
  302. 'site_id' => $siteId,
  303. 'cn_title' => $site->cn_title ?? '',
  304. 'en_title' => $site->en_title ?? '',
  305. 'site_logo' => $site->site_logo ?? '',
  306. 'domain' => $site->domain ?? '',
  307. 'brand' => $site->brand ?? '',
  308. 'ip' => $site->server->server_ip ?? '',
  309. 'database' => $site->database ?? '',
  310. 'username' => $site->server->mysql_user_name ?? '',
  311. 'password' => $site->server->mysql_passwd ?? '',
  312. 'create_time' => date('Y-m-d')
  313. ];
  314. $result = $connection->table('template_library_project_config')->where('site_id', $siteId)->first();
  315. if (empty($result)) {
  316. $connection->table('template_library_project_config')->insert($update);
  317. } else {
  318. $connection->table('template_library_project_config')->where('site_id', $siteId)->update($update);
  319. }
  320. }
  321. return response()->json(['message' => '操作成功']);
  322. } elseif ($type == 2) {
  323. //详细信息
  324. $site = Site::query()->with(['users'])->where(['id' => $siteId])->first();
  325. if (!$site) return response()->json(['message' => '数据不存在'], 400);
  326. $validated['payment']['google_bid'] = json_encode($validated['payment']['google_bid']);
  327. SitePayment::query()->where(['site_id' => $siteId])->update($validated['payment']);
  328. return response()->json(['message' => '操作成功']);
  329. } elseif ($type == 3) {
  330. //详细信息
  331. $site = Site::query()->with(['users'])->where(['id' => $siteId])->first();
  332. if (!$site) return response()->json(['message' => '数据不存在'], 400);
  333. $userIds = array_merge(
  334. $validated['allot']['editor_ids'] ?? [],
  335. $validated['allot']['server_ids'] ?? [],
  336. $validated['allot']['article_ids'] ?? [],
  337. $validated['allot']['manager_ids'] ?? [],
  338. $validated['allot']['manage_helper_ids'] ?? [],
  339. $validated['allot']['planner_ids'] ?? [],
  340. $validated['allot']['optimizer_ids'] ?? [],
  341. $validated['allot']['bid_user_ids'] ?? [],
  342. $validated['allot']['seller_ids'] ?? [],
  343. $validated['allot']['web_ids'] ?? [],
  344. $validated['allot']['designer_ids'] ?? [],
  345. $validated['allot']['article_edit_ids'] ?? [],
  346. $validated['allot']['external_link_ids'] ?? [],
  347. $validated['allot']['chongqing_link_ids'] ?? [],
  348. $validated['allot']['optimization_editing_ids'] ?? []
  349. );
  350. foreach ($userIds as $key => $value) {
  351. if (empty($value)) {
  352. unset($userIds[$key]);
  353. }
  354. }
  355. $beforeUserIds = DB::table('user_has_sites')->where(['site_id' => $site->id])->pluck('user_id')->toArray();
  356. $updateUserIds = User::query()->whereIn('role_id', [
  357. Role::TYPE_AE,
  358. Role::TYPE_ARTICLE,
  359. Role::TYPE_SERVER,
  360. Role::TYPE_MANAGER,
  361. Role::TYPE_MANAGE_HELPER,
  362. Role::TYPE_OPTIMIZER,
  363. Role::TYPE_SELLER,
  364. Role::TYPE_BID,
  365. Role::TYPE_WEB,
  366. Role::TYPE_DESIGNER,
  367. Role::TYPE_PROPAGANDA,
  368. Role::TYPE_PLANNER,
  369. Role::TYPE_LINK,
  370. Role::TYPE_OPTIMIZATION_EDITING,
  371. Role::TYPE_SOFT_TEXT_SEARCH,
  372. Role::TYPE_LINK_PART_CHONGQING,
  373. ])->whereIn('id', $beforeUserIds)->pluck('id')->toArray();
  374. $keepUserIds = [];
  375. foreach ($beforeUserIds as $beforeUserId) {
  376. if (!in_array($beforeUserId, $updateUserIds)) {
  377. $keepUserIds[] = $beforeUserId;
  378. }
  379. }
  380. $saveUserIds = array_unique(array_merge($userIds, $keepUserIds));
  381. $site->users()->sync($saveUserIds);
  382. return response()->json(['message' => '操作成功']);
  383. } elseif ($type == 4) {
  384. $site = Site::query()->with(['server'])->where(['id' => $siteId])->first();
  385. if (!$site) return response()->json(['message' => '数据不存在'], 400);
  386. //更改为实施期去掉当月上线目标
  387. if ($validated['site']['status'] == 2) {
  388. $validated['site']['is_current_month_online'] = 0;
  389. }
  390. $site->update($validated['site']);
  391. if ($site->status == 7 || $site->status == 9 || $site->status == 10) {
  392. DB::connection('rank')->table('project')->where(['id' => $site->old_id])->update(['allow_googlerank' => 0]);
  393. }
  394. return response()->json(['message' => '操作成功']);
  395. } elseif ($type == 5) {
  396. $site = Site::query()->with(['server'])->where(['id' => $siteId])->first();
  397. if (!$site) return response()->json(['message' => '数据不存在'], 400);
  398. $site->update($validated['site']);
  399. //同步老rank平台的数据
  400. $siteSync = new SiteSyncLogic();
  401. if (!empty($site->server)) {
  402. $server = ['server_ip' => $site->server->server_ip];
  403. }
  404. $siteSync->update($site->old_id, $siteSync->fieldMap($site->toArray() + ($server ?? [])) + ($rankUpdate ?? []));
  405. return response()->json(['message' => '操作成功']);
  406. }
  407. }
  408. public function socialPublishBak($validated, ConnectionInterface $connection, $site)
  409. {
  410. $contentRecords = $connection->table('content')->whereIn('id', $validated['checkIds'])->get();
  411. $queues = [];
  412. $socialData = Social::query()->where(['site_id' => $site->id, 'type' => Social::LINKED])->first();
  413. foreach ($contentRecords as $inx => $record) {
  414. if (empty($record->uri) || empty($record->summary)) {
  415. continue;
  416. }
  417. $thumb = trim($record->thumb);
  418. $url = sprintf('http://%s/%s', $site->domain, $record->uri);
  419. if (!$connection->table('content')->where(['parent_id' => $record->id])->exists()) {
  420. $url .= '.html';
  421. }
  422. $queues[] = [
  423. 'site_id' => $site->id,
  424. 'remote_content_id' => $record->id,
  425. 'media' => $thumb ? sprintf('http://%s%s', $site->domain, $record->thumb) : null,
  426. 'url' => $url,
  427. 'content' => str_replace('<br/>', PHP_EOL, html_entity_decode(strip_tags($record->summary, '<br/>'))),
  428. 'created_at' => date('Y-m-d H:i:s'),
  429. 'updated_at' => date('Y-m-d H:i:s'),
  430. 'publish_at' => date('Y-m-d H:i:s', strtotime('+' . ($validated['release_interval'] * $inx) . ' day', strtotime($validated['release_at']))),
  431. 'pin_board' => $validated['pin_board'],
  432. 'linkedin_orgid' => $socialData->linkedin_orgid ?? ''
  433. ];
  434. }
  435. SocialPublish::query()->insert($queues);
  436. return response()->json(['message' => sprintf('操作成功!%s条记录符合!', count($queues))]);
  437. }
  438. public function socialPublish($validated, ConnectionInterface $connection, $site,$hootsuiteUser_id)
  439. {
  440. $label = '';
  441. if (!empty($validated['label_id'])) {
  442. $labelList = DB::table('social_label')
  443. ->where('site_id', $site->id)
  444. ->whereIn('id', $validated['label_id'])
  445. ->pluck('label');
  446. foreach ($labelList as $value) {
  447. $label .= '#' . $value . ' ';
  448. }
  449. }
  450. $contentRecords = $connection->table('content')->whereIn('id', $validated['checkIds'])->get();
  451. $queues = [];
  452. $client = new Client();
  453. //$hootsuiteUser = HootsuiteUser::query()->where(['id' => $site->id])->first();
  454. if(empty($hootsuiteUser_id)){
  455. $hootsuiteUser = HootsuiteUser::query()->where(['site_id' => $site->id])->first();
  456. }else{
  457. $hootsuiteUser = HootsuiteUser::query()->where(['id' => $hootsuiteUser_id])->first();
  458. }
  459. $socialProfiles = $hootsuiteUser->social_profiles ?? [];
  460. $mapSocialProfiles = array_column($socialProfiles, null, 'id');
  461. foreach ($contentRecords as $inx => $record) {
  462. if (empty($record->uri) || empty($record->summary)) {
  463. continue;
  464. }
  465. $thumb = trim($record->thumb);
  466. $string = substr($site->webmaster_domain, -1, 1);
  467. if ($string != '/') {
  468. $remoteImg = $thumb ? $site->webmaster_domain . $record->thumb : null;
  469. } else {
  470. $remoteImg = $thumb ? substr($site->webmaster_domain, 0, -1) . $record->thumb : null;
  471. }
  472. $publishAt = date('Y-m-d H:i:s', strtotime('+' . ($validated['release_interval'] * $inx) . ' day', strtotime($validated['release_at'])));
  473. $content = str_replace('<br/>', PHP_EOL, html_entity_decode(strip_tags($record->summary, '<br/>')));
  474. if (strtotime($publishAt) < (time() + 60 * 10)) {
  475. return response()->json(['message' => '发布时间距离当前时间过近或小于当前时间'], 400);
  476. }
  477. if (!$connection->table('content')->where(['parent_id' => $record->id])->exists()) {
  478. $webmasterDomain = $site->webmaster_domain . $record->uri . '.html';
  479. } else {
  480. $webmasterDomain = $site->webmaster_domain . $record->uri;
  481. }
  482. $newContent = $content . ' ' . $webmasterDomain . ' ' . $label;
  483. $lens = mb_strlen($newContent);
  484. if ($lens > 280) {
  485. $content = mb_substr($content, 0, 277 - $lens) . '...';
  486. $newContent = $content . ' ' . $webmasterDomain . ' ' . $label;
  487. }
  488. $tempSocialProfiles = [];
  489. foreach ($mapSocialProfiles as $key => $item) {
  490. if (in_array($key, $validated['social_ids'])) {
  491. $tempSocialProfiles[] = $item;
  492. }
  493. }
  494. $url = sprintf('%s/admin/hootsuite/schedule-message', config('app.wall_url'));
  495. try {
  496. $response = $client->request('POST', $url, [
  497. 'form_params' => [
  498. 'siteId' => $site->id,
  499. 'socialIds' => $validated['social_ids'],
  500. 'remoteImg' => $remoteImg,
  501. 'content' => $newContent,
  502. 'sendAt' => $publishAt
  503. ]
  504. ]);
  505. if ($response->getStatusCode() != 200) {
  506. return response()->json(['message' => "发送失败"], 400);
  507. }
  508. $result = json_decode($response->getBody()->getContents(), true);
  509. if (!empty($result['errors'])) {
  510. return response()->json(['message' => ($result['errors'][0]['message'] ?? 'schedule error')], 400);
  511. }
  512. $queues = [
  513. 'site_id' => $site->id,
  514. 'remote_content_id' => $record->id,
  515. 'media' => $remoteImg,
  516. 'url' => $webmasterDomain,
  517. 'content' => $newContent,
  518. 'created_at' => date('Y-m-d H:i:s'),
  519. 'updated_at' => date('Y-m-d H:i:s'),
  520. 'publish_at' => $publishAt,
  521. 'social_ids' => json_encode($validated['social_ids'] ?? []),
  522. 'social_profiles' => json_encode($tempSocialProfiles ?? []),
  523. 'result' => json_encode($result['data'] ?? []),
  524. ];
  525. HootsuiteHistory::query()->insert($queues);
  526. } catch (\GuzzleHttp\Exception\GuzzleException $exception) {
  527. Log::error(var_export($exception->getMessage(), 1));
  528. return response()->json(['message' => '发布失败'], 400);
  529. }
  530. }
  531. return response()->json(['message' => sprintf('操作成功!%s条记录符合!', count($queues))]);
  532. }
  533. }