update-aftercare-projects-status.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>更新售后归档项目状态为已完成</title>
  7. <script src="https://cdn.jsdelivr.net/npm/parse@5.3.0/dist/parse.min.js"></script>
  8. <style>
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. }
  14. body {
  15. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  16. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  17. min-height: 100vh;
  18. display: flex;
  19. align-items: center;
  20. justify-content: center;
  21. padding: 20px;
  22. }
  23. .container {
  24. background: white;
  25. border-radius: 16px;
  26. box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  27. padding: 40px;
  28. max-width: 800px;
  29. width: 100%;
  30. }
  31. h1 {
  32. color: #333;
  33. margin-bottom: 10px;
  34. font-size: 28px;
  35. font-weight: 600;
  36. }
  37. .subtitle {
  38. color: #666;
  39. margin-bottom: 30px;
  40. font-size: 14px;
  41. }
  42. .info-box {
  43. background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  44. color: white;
  45. padding: 20px;
  46. border-radius: 12px;
  47. margin-bottom: 30px;
  48. line-height: 1.6;
  49. }
  50. .info-box strong {
  51. display: block;
  52. margin-bottom: 10px;
  53. font-size: 16px;
  54. }
  55. .info-box ul {
  56. margin-left: 20px;
  57. margin-top: 10px;
  58. }
  59. .info-box li {
  60. margin: 5px 0;
  61. }
  62. .btn-group {
  63. display: flex;
  64. gap: 15px;
  65. margin-bottom: 30px;
  66. }
  67. button {
  68. flex: 1;
  69. padding: 14px 24px;
  70. border: none;
  71. border-radius: 10px;
  72. font-size: 16px;
  73. font-weight: 600;
  74. cursor: pointer;
  75. transition: all 0.3s ease;
  76. font-family: inherit;
  77. }
  78. .btn-primary {
  79. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  80. color: white;
  81. box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
  82. }
  83. .btn-primary:hover:not(:disabled) {
  84. transform: translateY(-2px);
  85. box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
  86. }
  87. .btn-secondary {
  88. background: #e0e0e0;
  89. color: #666;
  90. }
  91. .btn-secondary:hover:not(:disabled) {
  92. background: #d0d0d0;
  93. }
  94. button:disabled {
  95. opacity: 0.6;
  96. cursor: not-allowed;
  97. }
  98. .log-container {
  99. background: #f8f9fa;
  100. border: 1px solid #dee2e6;
  101. border-radius: 10px;
  102. padding: 20px;
  103. max-height: 500px;
  104. overflow-y: auto;
  105. font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
  106. font-size: 13px;
  107. line-height: 1.8;
  108. }
  109. .log-entry {
  110. margin: 8px 0;
  111. padding: 8px 12px;
  112. border-radius: 6px;
  113. display: flex;
  114. align-items: flex-start;
  115. gap: 10px;
  116. }
  117. .log-icon {
  118. flex-shrink: 0;
  119. font-size: 18px;
  120. }
  121. .log-info {
  122. background: #e3f2fd;
  123. border-left: 3px solid #2196f3;
  124. }
  125. .log-success {
  126. background: #e8f5e9;
  127. border-left: 3px solid #4caf50;
  128. }
  129. .log-warning {
  130. background: #fff3e0;
  131. border-left: 3px solid #ff9800;
  132. }
  133. .log-error {
  134. background: #ffebee;
  135. border-left: 3px solid #f44336;
  136. }
  137. .summary {
  138. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  139. color: white;
  140. padding: 20px;
  141. border-radius: 10px;
  142. margin-top: 20px;
  143. display: none;
  144. }
  145. .summary.show {
  146. display: block;
  147. }
  148. .summary h3 {
  149. margin-bottom: 15px;
  150. font-size: 18px;
  151. }
  152. .summary-stats {
  153. display: grid;
  154. grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  155. gap: 15px;
  156. }
  157. .stat-item {
  158. background: rgba(255,255,255,0.2);
  159. padding: 12px;
  160. border-radius: 8px;
  161. text-align: center;
  162. }
  163. .stat-value {
  164. display: block;
  165. font-size: 28px;
  166. font-weight: bold;
  167. margin-bottom: 5px;
  168. }
  169. .stat-label {
  170. font-size: 13px;
  171. opacity: 0.9;
  172. }
  173. .loading {
  174. display: inline-block;
  175. width: 20px;
  176. height: 20px;
  177. border: 3px solid rgba(255,255,255,0.3);
  178. border-radius: 50%;
  179. border-top-color: white;
  180. animation: spin 1s linear infinite;
  181. margin-left: 10px;
  182. }
  183. @keyframes spin {
  184. to { transform: rotate(360deg); }
  185. }
  186. </style>
  187. </head>
  188. <body>
  189. <div class="container">
  190. <h1>🔄 更新售后归档项目状态</h1>
  191. <p class="subtitle">将所有 currentStage 为"售后归档"的项目状态更新为"已完成"</p>
  192. <div class="info-box">
  193. <strong>📋 操作说明</strong>
  194. <ul>
  195. <li>本工具会查询所有 <code>currentStage = '售后归档'</code> 的项目</li>
  196. <li>将这些项目的 <code>status</code> 字段更新为 <code>'已完成'</code></li>
  197. <li>更新后会在管理员端项目列表中正确显示为"已完成"状态</li>
  198. <li>此操作不可逆,请谨慎执行</li>
  199. </ul>
  200. </div>
  201. <div class="btn-group">
  202. <button class="btn-primary" id="updateBtn" onclick="updateProjects()">
  203. 🚀 开始更新
  204. </button>
  205. <button class="btn-secondary" onclick="clearLogs()">
  206. 🗑️ 清空日志
  207. </button>
  208. </div>
  209. <div class="log-container" id="logContainer"></div>
  210. <div class="summary" id="summary">
  211. <h3>📊 更新统计</h3>
  212. <div class="summary-stats">
  213. <div class="stat-item">
  214. <span class="stat-value" id="totalCount">0</span>
  215. <span class="stat-label">查询到的项目</span>
  216. </div>
  217. <div class="stat-item">
  218. <span class="stat-value" id="updatedCount">0</span>
  219. <span class="stat-label">成功更新</span>
  220. </div>
  221. <div class="stat-item">
  222. <span class="stat-value" id="failedCount">0</span>
  223. <span class="stat-label">更新失败</span>
  224. </div>
  225. <div class="stat-item">
  226. <span class="stat-value" id="skippedCount">0</span>
  227. <span class="stat-label">已经是已完成</span>
  228. </div>
  229. </div>
  230. </div>
  231. </div>
  232. <script>
  233. // 初始化 Parse
  234. Parse.initialize("fmode");
  235. Parse.serverURL = "https://server.fmode.cn/parse";
  236. Parse.masterKey = "F_MODE_MASTER_KEY"; // 请替换为实际的 Master Key
  237. function log(message, type = 'info') {
  238. const logContainer = document.getElementById('logContainer');
  239. const logEntry = document.createElement('div');
  240. logEntry.className = `log-entry log-${type}`;
  241. const icons = {
  242. info: 'ℹ️',
  243. success: '✅',
  244. warning: '⚠️',
  245. error: '❌'
  246. };
  247. logEntry.innerHTML = `
  248. <span class="log-icon">${icons[type]}</span>
  249. <div>${message}</div>
  250. `;
  251. logContainer.appendChild(logEntry);
  252. logContainer.scrollTop = logContainer.scrollHeight;
  253. }
  254. function clearLogs() {
  255. document.getElementById('logContainer').innerHTML = '';
  256. document.getElementById('summary').classList.remove('show');
  257. }
  258. async function updateProjects() {
  259. const updateBtn = document.getElementById('updateBtn');
  260. updateBtn.disabled = true;
  261. updateBtn.innerHTML = '更新中... <span class="loading"></span>';
  262. clearLogs();
  263. let totalCount = 0;
  264. let updatedCount = 0;
  265. let failedCount = 0;
  266. let skippedCount = 0;
  267. try {
  268. log('🔍 开始查询售后归档的项目...', 'info');
  269. // 查询所有 currentStage 为 '售后归档' 的项目
  270. const query = new Parse.Query('Project');
  271. query.equalTo('currentStage', '售后归档');
  272. query.notEqualTo('isDeleted', true);
  273. query.limit(1000);
  274. const projects = await query.find();
  275. totalCount = projects.length;
  276. log(`📊 找到 ${totalCount} 个售后归档的项目`, 'info');
  277. if (totalCount === 0) {
  278. log('✨ 没有需要更新的项目', 'warning');
  279. updateBtn.disabled = false;
  280. updateBtn.innerHTML = '🚀 开始更新';
  281. return;
  282. }
  283. log('', 'info');
  284. log('🔄 开始批量更新项目状态...', 'info');
  285. // 批量更新
  286. for (let i = 0; i < projects.length; i++) {
  287. const project = projects[i];
  288. const title = project.get('title') || '未命名项目';
  289. const currentStatus = project.get('status');
  290. try {
  291. // 如果已经是"已完成"状态,跳过
  292. if (currentStatus === '已完成') {
  293. log(`⏭️ [${i + 1}/${totalCount}] "${title}" - 已经是已完成状态,跳过`, 'warning');
  294. skippedCount++;
  295. continue;
  296. }
  297. // 更新状态
  298. project.set('status', '已完成');
  299. await project.save();
  300. updatedCount++;
  301. log(`✅ [${i + 1}/${totalCount}] 成功更新 "${title}" (${currentStatus} → 已完成)`, 'success');
  302. } catch (error) {
  303. failedCount++;
  304. log(`❌ [${i + 1}/${totalCount}] 更新失败 "${title}": ${error.message}`, 'error');
  305. }
  306. }
  307. // 显示统计摘要
  308. log('', 'info');
  309. log('🎉 更新完成!', 'success');
  310. document.getElementById('totalCount').textContent = totalCount;
  311. document.getElementById('updatedCount').textContent = updatedCount;
  312. document.getElementById('failedCount').textContent = failedCount;
  313. document.getElementById('skippedCount').textContent = skippedCount;
  314. document.getElementById('summary').classList.add('show');
  315. } catch (error) {
  316. log(`❌ 批量更新失败: ${error.message}`, 'error');
  317. console.error('更新错误:', error);
  318. } finally {
  319. updateBtn.disabled = false;
  320. updateBtn.innerHTML = '🚀 开始更新';
  321. }
  322. }
  323. // 页面加载时显示提示
  324. window.addEventListener('load', () => {
  325. log('👋 欢迎使用售后归档项目状态更新工具', 'info');
  326. log('📝 请点击"开始更新"按钮来执行批量更新', 'info');
  327. });
  328. </script>
  329. </body>
  330. </html>