ProjectController.php 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Controller;
  4. use App\Module\Base;
  5. use App\Module\Project;
  6. use App\Module\Users;
  7. use DB;
  8. use Request;
  9. use Session;
  10. /**
  11. * @apiDefine project
  12. *
  13. * 项目
  14. */
  15. class ProjectController extends Controller
  16. {
  17. public function __invoke($method, $action = '')
  18. {
  19. $app = $method ? $method : 'main';
  20. if ($action) {
  21. $app .= "__" . $action;
  22. }
  23. return (method_exists($this, $app)) ? $this->$app() : Base::ajaxError("404 not found (" . str_replace("__", "/", $app) . ").");
  24. }
  25. /**
  26. * 项目列表
  27. *
  28. * @apiParam {String} act 类型
  29. * - join: 加入的项目(默认)
  30. * - favor: 收藏的项目
  31. * - manage: 管理的项目
  32. * @apiParam {Number} [page] 当前页,默认:1
  33. * @apiParam {Number} [pagesize] 每页显示数量,默认:20,最大:100
  34. */
  35. public function lists()
  36. {
  37. $user = Users::authE();
  38. if (Base::isError($user)) {
  39. return $user;
  40. } else {
  41. $user = $user['data'];
  42. }
  43. //
  44. $whereArray = [];
  45. $whereArray[] = ['project_lists.delete', '=', 0];
  46. $whereArray[] = ['project_users.username', '=', $user['username']];
  47. switch (Request::input('act')) {
  48. case "favor": {
  49. $whereArray[] = ['project_users.type', '=', '收藏'];
  50. break;
  51. }
  52. case "manage": {
  53. $whereArray[] = ['project_users.type', '=', '成员'];
  54. $whereArray[] = ['project_users.isowner', '=', 1];
  55. break;
  56. }
  57. default: {
  58. $whereArray[] = ['project_users.type', '=', '成员'];
  59. break;
  60. }
  61. }
  62. $lists = DB::table('project_lists')
  63. ->join('project_users', 'project_lists.id', '=', 'project_users.projectid')
  64. ->select(['project_lists.*', 'project_users.isowner', 'project_users.indate as uindate'])
  65. ->where($whereArray)
  66. ->orderByDesc('project_lists.id')->paginate(Base::getPaginate(100, 20));
  67. $lists = Base::getPageList($lists);
  68. if ($lists['total'] == 0) {
  69. return Base::retError('未找到任何相关的项目');
  70. }
  71. return Base::retSuccess('success', $lists);
  72. }
  73. /**
  74. * 项目详情
  75. *
  76. * @apiParam {Number} projectid 项目ID
  77. */
  78. public function detail()
  79. {
  80. $user = Users::authE();
  81. if (Base::isError($user)) {
  82. return $user;
  83. } else {
  84. $user = $user['data'];
  85. }
  86. //
  87. $projectid = trim(Request::input('projectid'));
  88. $projectDetail = Base::DBC2A(DB::table('project_lists')->where('id', $projectid)->where('delete', 0)->first());
  89. if (empty($projectDetail)) {
  90. return Base::retError('项目不存在或已被删除!');
  91. }
  92. $inRes = Project::inThe($projectid, $user['username']);
  93. if (Base::isError($inRes)) {
  94. return $inRes;
  95. }
  96. $projectSetting = Base::string2array($projectDetail['setting']);
  97. //子分类
  98. $label = Base::DBC2A(DB::table('project_label')->where('projectid', $projectid)->orderBy('inorder')->orderBy('id')->get());
  99. $simpleLabel = [];
  100. //任务
  101. $whereArray = [ 'projectid' => $projectid, 'delete' => 0, 'complete' => 0 ];
  102. if ($projectSetting['complete_show'] == 'show') {
  103. unset($whereArray['complete']);
  104. }
  105. $task = Base::DBC2A(DB::table('project_task')->where($whereArray)->orderByDesc('inorder')->orderByDesc('id')->get());
  106. //任务归类
  107. foreach ($label AS $index => $temp) {
  108. $taskLists = [];
  109. foreach ($task AS $info) {
  110. if ($temp['id'] == $info['labelid']) {
  111. $info['overdue'] = Project::taskIsOverdue($info);
  112. $info['subtask'] = Base::string2array($info['subtask']);
  113. $info['follower'] = Base::string2array($info['follower']);
  114. $taskLists[] = array_merge($info, Users::username2basic($info['username']));
  115. }
  116. }
  117. $label[$index]['taskLists'] = $taskLists;
  118. $simpleLabel[] = ['id' => $temp['id'], 'title' => $temp['title']];
  119. }
  120. //
  121. return Base::retSuccess('success', [
  122. 'project' => $projectDetail,
  123. 'label' => $label,
  124. 'simpleLabel' => $simpleLabel,
  125. ]);
  126. }
  127. /**
  128. * 获取项目负责人
  129. *
  130. * @apiParam {Number} projectid 项目ID
  131. */
  132. public function leader()
  133. {
  134. $user = Users::authE();
  135. if (Base::isError($user)) {
  136. return $user;
  137. } else {
  138. $user = $user['data'];
  139. }
  140. //
  141. $projectid = trim(Request::input('projectid'));
  142. $projectDetail = Base::DBC2A(DB::table('project_lists')->select(['username'])->where('id', $projectid)->where('delete', 0)->first());
  143. if (empty($projectDetail)) {
  144. return Base::retError('项目不存在或已被删除!');
  145. }
  146. return Base::retSuccess('success', [
  147. 'username' => $projectDetail['username'],
  148. ]);
  149. }
  150. /**
  151. * 添加项目
  152. *
  153. * @apiParam {String} title 项目名称
  154. * @apiParam {Array} labels 流程,格式[流程1, 流程2]
  155. */
  156. public function add()
  157. {
  158. $user = Users::authE();
  159. if (Base::isError($user)) {
  160. return $user;
  161. } else {
  162. $user = $user['data'];
  163. }
  164. //项目名称
  165. $title = trim(Request::input('title'));
  166. if (mb_strlen($title) < 2) {
  167. return Base::retError('项目名称不可以少于2个字!');
  168. } elseif (mb_strlen($title) > 32) {
  169. return Base::retError('项目名称最多只能设置32个字!');
  170. }
  171. //流程
  172. $labels = Request::input('labels');
  173. if (!is_array($labels)) $labels = [];
  174. $insertLabels = [];
  175. $inorder = 0;
  176. foreach ($labels AS $label) {
  177. $label = trim($label);
  178. if ($label) {
  179. $insertLabels[] = [
  180. 'title' => $label,
  181. 'inorder' => $inorder++,
  182. ];
  183. }
  184. }
  185. if (empty($insertLabels)) {
  186. $insertLabels[] = [
  187. 'title' => '默认',
  188. 'inorder' => 0,
  189. ];
  190. }
  191. if (count($insertLabels) > 100) {
  192. return Base::retError(['项目流程最多不能超过%个!', 100]);
  193. }
  194. //开始创建
  195. $projectid = DB::table('project_lists')->insertGetId([
  196. 'title' => $title,
  197. 'username' => $user['username'],
  198. 'createuser' => $user['username'],
  199. 'indate' => Base::time()
  200. ]);
  201. if ($projectid) {
  202. foreach ($insertLabels AS $key => $label) {
  203. $insertLabels[$key]['projectid'] = $projectid;
  204. }
  205. DB::table('project_label')->insert($insertLabels);
  206. DB::table('project_log')->insert([
  207. 'type' => '日志',
  208. 'projectid' => $projectid,
  209. 'username' => $user['username'],
  210. 'detail' => '创建项目',
  211. 'indate' => Base::time()
  212. ]);
  213. DB::table('project_users')->insert([
  214. 'type' => '成员',
  215. 'projectid' => $projectid,
  216. 'isowner' => 1,
  217. 'username' => $user['username'],
  218. 'indate' => Base::time()
  219. ]);
  220. return Base::retSuccess('添加成功!');
  221. } else {
  222. return Base::retError('添加失败!');
  223. }
  224. }
  225. /**
  226. * 设置项目
  227. *
  228. * @apiParam {String} act 类型
  229. * - save: 保存
  230. * - other: 读取
  231. * @apiParam {Number} projectid 项目ID
  232. * @apiParam {Object} ... 其他保存参数
  233. *
  234. * @throws \Throwable
  235. */
  236. public function setting()
  237. {
  238. $user = Users::authE();
  239. if (Base::isError($user)) {
  240. return $user;
  241. } else {
  242. $user = $user['data'];
  243. }
  244. //
  245. $projectid = trim(Request::input('projectid'));
  246. $projectDetail = Base::DBC2A(DB::table('project_lists')->where('id', $projectid)->where('delete', 0)->first());
  247. if (empty($projectDetail)) {
  248. return Base::retError('项目不存在或已被删除!');
  249. }
  250. //
  251. $setting = Base::string2array($projectDetail['setting']);
  252. $act = trim(Request::input('act'));
  253. if ($act == 'save') {
  254. if ($projectDetail['username'] != $user['username']) {
  255. return Base::retError('你不是项目负责人!');
  256. }
  257. foreach (Request::input() AS $key => $value) {
  258. if (in_array($key, ['project_desc', 'add_role', 'edit_role', 'complete_role', 'archived_role', 'del_role', 'complete_show'])) {
  259. $setting[$key] = $value;
  260. }
  261. }
  262. DB::table('project_lists')->where('id', $projectDetail['id'])->update([
  263. 'setting' => Base::string2array($setting)
  264. ]);
  265. }
  266. //
  267. foreach (['edit_role', 'complete_role', 'archived_role', 'del_role'] AS $key) {
  268. $setting[$key] = is_array($setting[$key]) ? $setting[$key] : ['__', 'owner'];
  269. }
  270. $setting['add_role'] = is_array($setting['add_role']) ? $setting['add_role'] : ['__', 'member'];
  271. $setting['complete_show'] = $setting['complete_show'] ?: 'hide';
  272. //
  273. return Base::retSuccess($act == 'save' ? '修改成功!' : 'success', $setting ?: json_decode('{}'));
  274. }
  275. /**
  276. * 收藏项目
  277. *
  278. * @apiParam {String} act 类型
  279. * - cancel: 取消收藏
  280. * - else: 添加收藏
  281. * @apiParam {Number} projectid 项目ID
  282. *
  283. * @throws \Throwable
  284. */
  285. public function favor()
  286. {
  287. $user = Users::authE();
  288. if (Base::isError($user)) {
  289. return $user;
  290. } else {
  291. $user = $user['data'];
  292. }
  293. //
  294. $projectid = trim(Request::input('projectid'));
  295. $projectDetail = Base::DBC2A(DB::table('project_lists')->where('id', $projectid)->where('delete', 0)->first());
  296. if (empty($projectDetail)) {
  297. return Base::retError('项目不存在或已被删除!');
  298. }
  299. return DB::transaction(function () use ($projectDetail, $user) {
  300. switch (Request::input('act')) {
  301. case 'cancel': {
  302. if (DB::table('project_users')->where([
  303. 'type' => '收藏',
  304. 'projectid' => $projectDetail['id'],
  305. 'username' => $user['username'],
  306. ])->delete()) {
  307. DB::table('project_log')->insert([
  308. 'type' => '日志',
  309. 'projectid' => $projectDetail['id'],
  310. 'username' => $user['username'],
  311. 'detail' => '取消收藏',
  312. 'indate' => Base::time()
  313. ]);
  314. return Base::retSuccess('取消成功!');
  315. }
  316. return Base::retSuccess('已取消!');
  317. }
  318. default: {
  319. $row = Base::DBC2A(DB::table('project_users')->where([
  320. 'type' => '收藏',
  321. 'projectid' => $projectDetail['id'],
  322. 'username' => $user['username'],
  323. ])->lockForUpdate()->first());
  324. if (empty($row)) {
  325. DB::table('project_users')->insert([
  326. 'type' => '收藏',
  327. 'projectid' => $projectDetail['id'],
  328. 'isowner' => $projectDetail['username'] == $user['username'] ? 1 : 0,
  329. 'username' => $user['username'],
  330. 'indate' => Base::time()
  331. ]);
  332. DB::table('project_log')->insert([
  333. 'type' => '日志',
  334. 'projectid' => $projectDetail['id'],
  335. 'username' => $user['username'],
  336. 'detail' => '收藏项目',
  337. 'indate' => Base::time()
  338. ]);
  339. return Base::retSuccess('收藏成功!');
  340. }
  341. return Base::retSuccess('已收藏!');
  342. }
  343. }
  344. });
  345. }
  346. /**
  347. * 重命名项目
  348. *
  349. * @apiParam {Number} projectid 项目ID
  350. * @apiParam {String} title 项目新名称
  351. */
  352. public function rename()
  353. {
  354. $user = Users::authE();
  355. if (Base::isError($user)) {
  356. return $user;
  357. } else {
  358. $user = $user['data'];
  359. }
  360. //
  361. $projectid = trim(Request::input('projectid'));
  362. $projectDetail = Base::DBC2A(DB::table('project_lists')->where('id', $projectid)->where('delete', 0)->first());
  363. if (empty($projectDetail)) {
  364. return Base::retError('项目不存在或已被删除!');
  365. }
  366. if ($projectDetail['username'] != $user['username']) {
  367. return Base::retError('你不是项目负责人!');
  368. }
  369. //
  370. $title = trim(Request::input('title'));
  371. if (mb_strlen($title) < 2) {
  372. return Base::retError('项目名称不可以少于2个字!');
  373. } elseif (mb_strlen($title) > 32) {
  374. return Base::retError('项目名称最多只能设置32个字!');
  375. }
  376. //
  377. DB::table('project_lists')->where('id', $projectDetail['id'])->update([
  378. 'title' => $title
  379. ]);
  380. DB::table('project_log')->insert([
  381. 'type' => '日志',
  382. 'projectid' => $projectDetail['id'],
  383. 'username' => $user['username'],
  384. 'detail' => '【' . $projectDetail['title'] . '】重命名【' . $title . '】',
  385. 'indate' => Base::time()
  386. ]);
  387. //
  388. return Base::retSuccess('修改成功!');
  389. }
  390. /**
  391. * 移交项目
  392. *
  393. * @apiParam {Number} projectid 项目ID
  394. * @apiParam {String} username 项目新负责人用户名
  395. *
  396. * @throws \Throwable
  397. */
  398. public function transfer()
  399. {
  400. $user = Users::authE();
  401. if (Base::isError($user)) {
  402. return $user;
  403. } else {
  404. $user = $user['data'];
  405. }
  406. //
  407. $projectid = trim(Request::input('projectid'));
  408. $projectDetail = Base::DBC2A(DB::table('project_lists')->where('id', $projectid)->where('delete', 0)->first());
  409. if (empty($projectDetail)) {
  410. return Base::retError('项目不存在或已被删除!');
  411. }
  412. if ($projectDetail['username'] != $user['username']) {
  413. return Base::retError('你不是项目负责人!');
  414. }
  415. //
  416. $username = trim(Request::input('username'));
  417. if ($username == $projectDetail['username']) {
  418. return Base::retError('你已是项目负责人!');
  419. }
  420. $count = DB::table('users')->where('username', $username)->count();
  421. if ($count <= 0) {
  422. return Base::retError(['成员用户名(%)不存在!', $username]);
  423. }
  424. //判断是否已在项目成员内
  425. $inRes = Project::inThe($projectDetail['id'], $username);
  426. if (Base::isError($inRes)) {
  427. DB::table('project_users')->insert([
  428. 'type' => '成员',
  429. 'projectid' => $projectDetail['id'],
  430. 'isowner' => 0,
  431. 'username' => $username,
  432. 'indate' => Base::time()
  433. ]);
  434. DB::table('project_log')->insert([
  435. 'type' => '日志',
  436. 'projectid' => $projectDetail['id'],
  437. 'username' => $username,
  438. 'detail' => '自动加入项目',
  439. 'indate' => Base::time()
  440. ]);
  441. }
  442. //开始移交
  443. return DB::transaction(function () use ($user, $username, $projectDetail) {
  444. DB::table('project_lists')->where('id', $projectDetail['id'])->update([
  445. 'username' => $username
  446. ]);
  447. DB::table('project_log')->insert([
  448. 'type' => '日志',
  449. 'projectid' => $projectDetail['id'],
  450. 'username' => $user['username'],
  451. 'detail' => '【' . $projectDetail['username'] . '】移交给【' . $username . '】',
  452. 'indate' => Base::time()
  453. ]);
  454. DB::table('project_users')->where([
  455. 'projectid' => $projectDetail['id'],
  456. 'username' => $projectDetail['username'],
  457. ])->update([
  458. 'isowner' => 0
  459. ]);
  460. DB::table('project_users')->where([
  461. 'projectid' => $projectDetail['id'],
  462. 'username' => $username,
  463. ])->update([
  464. 'isowner' => 1
  465. ]);
  466. return Base::retSuccess('移交成功!');
  467. });
  468. }
  469. /**
  470. * 删除项目
  471. *
  472. * @apiParam {Number} projectid 项目ID
  473. */
  474. public function delete()
  475. {
  476. $user = Users::authE();
  477. if (Base::isError($user)) {
  478. return $user;
  479. } else {
  480. $user = $user['data'];
  481. }
  482. //
  483. $projectid = trim(Request::input('projectid'));
  484. $projectDetail = Base::DBC2A(DB::table('project_lists')->where('id', $projectid)->where('delete', 0)->first());
  485. if (empty($projectDetail)) {
  486. return Base::retError('项目不存在或已被删除!');
  487. }
  488. if ($projectDetail['username'] != $user['username']) {
  489. return Base::retError('你不是项目负责人!');
  490. }
  491. //
  492. DB::table('project_lists')->where('id', $projectDetail['id'])->update([
  493. 'delete' => 1,
  494. 'deletedate' => Base::time()
  495. ]);
  496. DB::table('project_task')->where('projectid', $projectDetail['id'])->update([
  497. 'delete' => 1,
  498. 'deletedate' => Base::time()
  499. ]);
  500. DB::table('project_files')->where('projectid', $projectDetail['id'])->update([
  501. 'delete' => 1,
  502. 'deletedate' => Base::time()
  503. ]);
  504. DB::table('project_log')->insert([
  505. 'type' => '日志',
  506. 'projectid' => $projectDetail['id'],
  507. 'username' => $user['username'],
  508. 'detail' => '删除项目',
  509. 'indate' => Base::time()
  510. ]);
  511. //
  512. return Base::retSuccess('删除成功!');
  513. }
  514. /**
  515. * 排序任务
  516. *
  517. * @apiParam {Number} projectid 项目ID
  518. * @apiParam {String} oldsort 旧排序数据
  519. * @apiParam {String} newsort 新排序数据
  520. * @apiParam {Number} label 赋值表示排序分类,否则排序任务(调整任务所属分类)
  521. */
  522. public function sort()
  523. {
  524. $user = Users::authE();
  525. if (Base::isError($user)) {
  526. return $user;
  527. } else {
  528. $user = $user['data'];
  529. }
  530. //
  531. $projectid = trim(Request::input('projectid'));
  532. $inRes = Project::inThe($projectid, $user['username']);
  533. if (Base::isError($inRes)) {
  534. return $inRes;
  535. }
  536. //
  537. $oldSort = explode(";", Request::input('oldsort'));
  538. $newSort = explode(";", Request::input('newsort'));
  539. if (count($oldSort) != count($newSort)) {
  540. return Base::retError('参数错误!');
  541. }
  542. if (intval(Request::input('label'))) {
  543. //排序分类
  544. foreach ($newSort AS $sort => $item) {
  545. list($newLabelid, $newTask) = explode(':', $item);
  546. list($oldLabelid, $oldTask) = explode(':', $oldSort[$sort]);
  547. if ($newLabelid != $oldLabelid) {
  548. DB::table('project_label')->where([
  549. 'id' => $newLabelid,
  550. 'projectid' => $projectid
  551. ])->update([
  552. 'inorder' => intval($sort)
  553. ]);
  554. }
  555. }
  556. $detail = '调整任务列表排序';
  557. $sortType = 'label';
  558. } else {
  559. //排序任务(调整任务归类)
  560. foreach ($newSort AS $sort => $item) {
  561. list($newLabelid, $newTask) = explode(':', $item);
  562. list($oldLabelid, $oldTask) = explode(':', $oldSort[$sort]);
  563. if ($newTask != $oldTask) {
  564. $newTask = explode('-', $newTask);
  565. $inorder = count($newTask);
  566. foreach ($newTask AS $taskid) {
  567. DB::table('project_task')->where([
  568. 'id' => $taskid,
  569. 'projectid' => $projectid
  570. ])->update([
  571. 'labelid' => $newLabelid,
  572. 'inorder' => $inorder
  573. ]);
  574. $inorder--;
  575. }
  576. }
  577. }
  578. $detail = '调整任务排序';
  579. $sortType = 'task';
  580. }
  581. //
  582. $row = Base::DBC2A(DB::table('project_log')->where([ 'type' => '日志', 'projectid' => $projectid ])->orderByDesc('id')->first());
  583. $continue = 1;
  584. if ($row && $row['username'] == $user['username'] && $row['indate'] + 300 > Base::time()) {
  585. $other = Base::string2array($row['other']);
  586. if ($other['sortType'] == $sortType) {
  587. $continue = intval($other['continue']) + 1;
  588. if ($continue <= 100) {
  589. DB::table('project_log')->where('id', $row['id'])->update([
  590. 'detail' => $detail . '(' . $continue . '次)',
  591. 'other' => Base::array2string([
  592. 'sortType' => $sortType,
  593. 'continue' => $continue,
  594. 'times' => $other['times'] . '|' . Base::time(),
  595. ])
  596. ]);
  597. }
  598. }
  599. }
  600. if ($continue == 1) {
  601. DB::table('project_log')->insert([
  602. 'type' => '日志',
  603. 'projectid' => $projectid,
  604. 'username' => $user['username'],
  605. 'detail' => $detail,
  606. 'indate' => Base::time(),
  607. 'other' => Base::array2string([
  608. 'sortType' => $sortType,
  609. 'continue' => $continue,
  610. 'times' => Base::time(),
  611. ])
  612. ]);
  613. }
  614. return Base::retSuccess('保存成功!');
  615. }
  616. /**
  617. * 排序任务(todo待办)
  618. *
  619. * @apiParam {String} oldsort 旧排序数据
  620. * @apiParam {String} newsort 新排序数据
  621. */
  622. public function sort__todo()
  623. {
  624. $user = Users::authE();
  625. if (Base::isError($user)) {
  626. return $user;
  627. } else {
  628. $user = $user['data'];
  629. }
  630. //
  631. $oldSort = explode(";", Request::input('oldsort'));
  632. $newSort = explode(";", Request::input('newsort'));
  633. if (count($oldSort) != count($newSort)) {
  634. return Base::retError('参数错误!');
  635. }
  636. //
  637. $levels = [];
  638. $logArray = [];
  639. $taskLevel = [];
  640. foreach ($newSort AS $sort => $item) {
  641. list($newLevel, $newTask) = explode(':', $item);
  642. list($oldLevel, $oldTask) = explode(':', $oldSort[$sort]);
  643. if ($newTask != $oldTask) {
  644. $newTask = explode('-', $newTask);
  645. $oldTask = explode('-', $oldTask);
  646. $userorder = intval(DB::table('project_task')->select('userorder')->where([
  647. 'delete' => 0,
  648. 'archived' => 0,
  649. 'level' => $newLevel,
  650. 'username' => $user['username'],
  651. ])->orderByDesc('userorder')->value('userorder'));
  652. if (count($newTask) < count($oldTask)) {
  653. $userorder--;
  654. } else {
  655. $userorder++;
  656. }
  657. foreach ($newTask AS $taskid) {
  658. $task = Base::DBC2A(DB::table('project_task')->select(['id', 'title', 'projectid', 'level', 'userorder'])->where([
  659. 'id' => $taskid,
  660. 'username' => $user['username']
  661. ])->first());
  662. $upArray = [];
  663. if ($task) {
  664. if ($task['level'] != $newLevel) {
  665. $upArray['level'] = $newLevel;
  666. $logArray[] = [
  667. 'type' => '日志',
  668. 'projectid' => $task['projectid'],
  669. 'taskid' => $task['id'],
  670. 'username' => $user['username'],
  671. 'detail' => '调整任务等级为【P' . $newLevel . '】',
  672. 'indate' => Base::time(),
  673. 'other' => Base::array2string([
  674. 'type' => 'task',
  675. 'id' => $task['id'],
  676. 'title' => $task['title'],
  677. ])
  678. ];
  679. $taskLevel[] = [
  680. 'id' => $task['id'],
  681. 'level' => $newLevel,
  682. ];
  683. }
  684. if ($task['userorder'] != $userorder) {
  685. $upArray['userorder'] = $userorder;
  686. }
  687. }
  688. if ($upArray) {
  689. DB::table('project_task')->where('id', $taskid)->update($upArray);
  690. }
  691. $userorder--;
  692. }
  693. $levels[] = $newLevel;
  694. }
  695. }
  696. if ($logArray) {
  697. DB::table('project_log')->insert($logArray);
  698. }
  699. //
  700. return Base::retSuccess('保存成功!', [
  701. 'levels' => $levels,
  702. 'taskLevel' => $taskLevel,
  703. ]);
  704. }
  705. /**
  706. * 退出项目
  707. *
  708. * @apiParam {Number} projectid 项目ID
  709. */
  710. public function out()
  711. {
  712. $user = Users::authE();
  713. if (Base::isError($user)) {
  714. return $user;
  715. } else {
  716. $user = $user['data'];
  717. }
  718. //
  719. $projectid = trim(Request::input('projectid'));
  720. $projectDetail = Base::DBC2A(DB::table('project_lists')->where('id', $projectid)->where('delete', 0)->first());
  721. if (empty($projectDetail)) {
  722. return Base::retError('项目不存在或已被删除!');
  723. }
  724. if ($projectDetail['username'] == $user['username']) {
  725. return Base::retError('你是项目负责人,不可退出项目!');
  726. }
  727. $inRes = Project::inThe($projectid, $user['username']);
  728. if (Base::isError($inRes)) {
  729. return $inRes;
  730. }
  731. //
  732. DB::table('project_users')->where([
  733. 'type' => '成员',
  734. 'projectid' => $projectDetail['id'],
  735. 'username' => $user['username'],
  736. ])->delete();
  737. DB::table('project_log')->insert([
  738. 'type' => '日志',
  739. 'projectid' => $projectDetail['id'],
  740. 'username' => $user['username'],
  741. 'detail' => '退出项目',
  742. 'indate' => Base::time()
  743. ]);
  744. //
  745. return Base::retSuccess('退出项目成功!');
  746. }
  747. /**
  748. * 项目成员-列表
  749. *
  750. * @apiParam {Number} projectid 项目ID
  751. * @apiParam {Number} [page] 当前页,默认:1
  752. * @apiParam {Number} [pagesize] 每页显示数量,默认:20,最大:100
  753. */
  754. public function users__lists()
  755. {
  756. $user = Users::authE();
  757. if (Base::isError($user)) {
  758. return $user;
  759. } else {
  760. $user = $user['data'];
  761. }
  762. //
  763. $projectid = intval(Request::input('projectid'));
  764. $inRes = Project::inThe($projectid, $user['username']);
  765. if (Base::isError($inRes)) {
  766. return $inRes;
  767. }
  768. //
  769. $lists = DB::table('project_lists')
  770. ->join('project_users', 'project_lists.id', '=', 'project_users.projectid')
  771. ->select(['project_lists.title', 'project_users.*'])
  772. ->where([
  773. ['project_lists.id', $projectid],
  774. ['project_lists.delete', 0],
  775. ['project_users.type', '成员'],
  776. ])
  777. ->orderByDesc('project_users.isowner')->orderByDesc('project_users.id')->paginate(Base::getPaginate(100, 20));
  778. $lists = Base::getPageList($lists);
  779. if ($lists['total'] == 0) {
  780. return Base::retError('未找到任何相关的成员');
  781. }
  782. foreach ($lists['lists'] AS $key => $projectDetail) {
  783. $userInfo = Users::username2basic($projectDetail['username']);
  784. $lists['lists'][$key]['userimg'] = $userInfo['userimg'];
  785. $lists['lists'][$key]['nickname'] = $userInfo['nickname'];
  786. $lists['lists'][$key]['profession'] = $userInfo['profession'];
  787. }
  788. return Base::retSuccess('success', $lists);
  789. }
  790. /**
  791. * 项目成员-添加、删除
  792. *
  793. * @apiParam {String} act
  794. * - delete: 删除成员
  795. * - else: 添加成员
  796. * @apiParam {Number} projectid 项目ID
  797. * @apiParam {Array|String} username 用户名(或用户名组)
  798. */
  799. public function users__join()
  800. {
  801. $user = Users::authE();
  802. if (Base::isError($user)) {
  803. return $user;
  804. } else {
  805. $user = $user['data'];
  806. }
  807. //
  808. $projectid = trim(Request::input('projectid'));
  809. $projectDetail = Base::DBC2A(DB::table('project_lists')->where('id', $projectid)->where('delete', 0)->first());
  810. if (empty($projectDetail)) {
  811. return Base::retError('项目不存在或已被删除!');
  812. }
  813. $usernames = Request::input('username');
  814. if (empty($usernames)) {
  815. return Base::retError('参数错误!');
  816. }
  817. if (!is_array($usernames)) {
  818. if (Base::strExists($usernames, ',')) {
  819. $usernames = explode(',', $usernames);
  820. } else {
  821. $usernames = [$usernames];
  822. }
  823. }
  824. //
  825. $logArray = [];
  826. foreach ($usernames AS $username) {
  827. $inRes = Project::inThe($projectid, $username);
  828. switch (Request::input('act')) {
  829. case 'delete': {
  830. if (!Base::isError($inRes) && $projectDetail['username'] != $username) {
  831. DB::table('project_users')->where([
  832. 'type' => '成员',
  833. 'projectid' => $projectid,
  834. 'username' => $username,
  835. ])->delete();
  836. $logArray[] = [
  837. 'type' => '日志',
  838. 'projectid' => $projectDetail['id'],
  839. 'username' => $user['username'],
  840. 'detail' => '将成员移出项目',
  841. 'indate' => Base::time(),
  842. 'other' => Base::array2string([
  843. 'type' => 'username',
  844. 'username' => $username,
  845. ])
  846. ];
  847. }
  848. break;
  849. }
  850. default: {
  851. if (Base::isError($inRes)) {
  852. DB::table('project_users')->insert([
  853. 'type' => '成员',
  854. 'projectid' => $projectid,
  855. 'isowner' => 0,
  856. 'username' => $username,
  857. 'indate' => Base::time()
  858. ]);
  859. $logArray[] = [
  860. 'type' => '日志',
  861. 'projectid' => $projectDetail['id'],
  862. 'username' => $user['username'],
  863. 'detail' => '邀请成员加入项目',
  864. 'indate' => Base::time(),
  865. 'other' => Base::array2string([
  866. 'type' => 'username',
  867. 'username' => $username,
  868. ])
  869. ];
  870. }
  871. break;
  872. }
  873. }
  874. }
  875. if ($logArray) {
  876. DB::table('project_log')->insert($logArray);
  877. }
  878. return Base::retSuccess('操作完成!');
  879. }
  880. /**
  881. * 项目子分类-添加分类
  882. *
  883. * @apiParam {Number} projectid 项目ID
  884. * @apiParam {String} title 分类名称
  885. */
  886. public function label__add()
  887. {
  888. $user = Users::authE();
  889. if (Base::isError($user)) {
  890. return $user;
  891. } else {
  892. $user = $user['data'];
  893. }
  894. //
  895. $projectid = trim(Request::input('projectid'));
  896. $inRes = Project::inThe($projectid, $user['username']);
  897. if (Base::isError($inRes)) {
  898. return $inRes;
  899. }
  900. //
  901. $title = trim(Request::input('title'));
  902. if (empty($title)) {
  903. return Base::retError('列表名称不能为空!');
  904. } elseif (mb_strlen($title) > 32) {
  905. return Base::retError('列表名称最多只能设置32个字!');
  906. }
  907. //
  908. $count = DB::table('project_label')->where('projectid', $projectid)->where('title', $title)->count();
  909. if ($count > 0) {
  910. return Base::retError('列表名称已存在!');
  911. }
  912. if (DB::table('project_label')->where('projectid', $projectid)->count() + 1 >= 100) {
  913. return Base::retError(['列表最多不能超过%个!', 100]);
  914. }
  915. //
  916. $id = DB::table('project_label')->insertGetId([
  917. 'projectid' => $projectid,
  918. 'title' => $title,
  919. 'inorder' => intval(DB::table('project_label')->where('projectid', $projectid)->orderByDesc('inorder')->value('inorder')) + 1,
  920. ]);
  921. if (empty($id)) {
  922. return Base::retError('系统繁忙,请稍后再试!');
  923. }
  924. DB::table('project_log')->insert([
  925. 'type' => '日志',
  926. 'projectid' => $projectid,
  927. 'username' => $user['username'],
  928. 'detail' => '添加任务列表【' . $title . '】',
  929. 'indate' => Base::time()
  930. ]);
  931. //
  932. $row = Base::DBC2A(DB::table('project_label')->where('id', $id)->first());
  933. $row['taskLists'] = [];
  934. return Base::retSuccess('添加成功!', $row);
  935. }
  936. /**
  937. * 项目子分类-重命名分类
  938. *
  939. * @apiParam {Number} projectid 项目ID
  940. * @apiParam {Number} labelid 分类ID
  941. * @apiParam {String} title 新分类名称
  942. */
  943. public function label__rename()
  944. {
  945. $user = Users::authE();
  946. if (Base::isError($user)) {
  947. return $user;
  948. } else {
  949. $user = $user['data'];
  950. }
  951. //
  952. $projectid = trim(Request::input('projectid'));
  953. $inRes = Project::inThe($projectid, $user['username']);
  954. if (Base::isError($inRes)) {
  955. return $inRes;
  956. }
  957. //
  958. $title = trim(Request::input('title'));
  959. if (empty($title)) {
  960. return Base::retError('列表名称不能为空!');
  961. } elseif (mb_strlen($title) > 32) {
  962. return Base::retError('列表名称最多只能设置32个字!');
  963. }
  964. //
  965. $labelid = intval(Request::input('labelid'));
  966. $count = DB::table('project_label')->where('id', '!=', $labelid)->where('projectid', $projectid)->where('title', $title)->count();
  967. if ($count > 0) {
  968. return Base::retError('列表名称已存在!');
  969. }
  970. //
  971. $labelDetail = Base::DBC2A(DB::table('project_label')->where('id', $labelid)->where('projectid', $projectid)->first());
  972. if (empty($labelDetail)) {
  973. return Base::retError('列表不存在或已被删除!');
  974. }
  975. //
  976. if (DB::table('project_label')->where('id', $labelDetail['id'])->update([ 'title' => $title ])) {
  977. DB::table('project_log')->insert([
  978. 'type' => '日志',
  979. 'projectid' => $projectid,
  980. 'username' => $user['username'],
  981. 'detail' => '任务列表【' . $labelDetail['title'] . '】重命名【' . $title . '】',
  982. 'indate' => Base::time()
  983. ]);
  984. }
  985. //
  986. return Base::retSuccess('修改成功!');
  987. }
  988. /**
  989. * 项目子分类-删除分类
  990. *
  991. * @apiParam {Number} projectid 项目ID
  992. * @apiParam {Number} labelid 分类ID
  993. *
  994. * @throws \Throwable
  995. */
  996. public function label__delete()
  997. {
  998. $user = Users::authE();
  999. if (Base::isError($user)) {
  1000. return $user;
  1001. } else {
  1002. $user = $user['data'];
  1003. }
  1004. //
  1005. $projectid = trim(Request::input('projectid'));
  1006. $inRes = Project::inThe($projectid, $user['username']);
  1007. if (Base::isError($inRes)) {
  1008. return $inRes;
  1009. }
  1010. //
  1011. $labelid = intval(Request::input('labelid'));
  1012. $labelDetail = Base::DBC2A(DB::table('project_label')->where('id', $labelid)->where('projectid', $projectid)->first());
  1013. if (empty($labelDetail)) {
  1014. return Base::retError('列表不存在或已被删除!');
  1015. }
  1016. //
  1017. return DB::transaction(function () use ($user, $projectid, $labelDetail) {
  1018. $taskLists = Base::DBC2A(DB::table('project_task')->where('labelid', $labelDetail['id'])->get());
  1019. $logArray = [];
  1020. foreach ($taskLists AS $task) {
  1021. $logArray[] = [
  1022. 'type' => '日志',
  1023. 'projectid' => $projectid,
  1024. 'taskid' => $task['id'],
  1025. 'username' => $user['username'],
  1026. 'detail' => '删除列表任务',
  1027. 'indate' => Base::time(),
  1028. 'other' => Base::array2string([
  1029. 'type' => 'task',
  1030. 'id' => $task['id'],
  1031. 'title' => $task['title'],
  1032. ])
  1033. ];
  1034. }
  1035. $logArray[] = [
  1036. 'type' => '日志',
  1037. 'projectid' => $projectid,
  1038. 'taskid' => 0,
  1039. 'username' => $user['username'],
  1040. 'detail' => '删除任务列表【' . $labelDetail['title'] . '】',
  1041. 'indate' => Base::time(),
  1042. 'other' => Base::array2string([])
  1043. ];
  1044. DB::table('project_task')->where('labelid', $labelDetail['id'])->update([
  1045. 'delete' => 1,
  1046. 'deletedate' => Base::time()
  1047. ]);
  1048. DB::table('project_label')->where('id', $labelDetail['id'])->delete();
  1049. DB::table('project_log')->insert($logArray);
  1050. Project::updateNum($projectid);
  1051. //
  1052. return Base::retSuccess('删除成功!');
  1053. });
  1054. }
  1055. /**
  1056. * 项目任务-列表
  1057. *
  1058. * @apiParam {Number} [projectid] 项目ID
  1059. * @apiParam {Number} [taskid] 任务ID (1、填写此参数时projectid强制为此任务的projectid;2、赋值返回详细数据,不返回列表数据)
  1060. * @apiParam {Number} [labelid] 项目子分类ID
  1061. * @apiParam {String} [username] 负责人用户名(如果项目ID为空时此参数无效只获取自己的任务)
  1062. * @apiParam {Number} [level] 任务等级(1~4)
  1063. * @apiParam {String} [archived] 任务是否归档
  1064. * - 未归档 (默认)
  1065. * - 已归档
  1066. * - 全部
  1067. * @apiParam {String} [type] 任务类型
  1068. * - 全部(默认)
  1069. * - 未完成
  1070. * - 已超期
  1071. * - 已完成
  1072. * @apiParam {Number} [createuser] 是否仅获取自己创建的项目(1:是;赋值时projectid和username不强制)
  1073. * @apiParam {Number} [attention] 是否仅获取关注数据(1:是;赋值时projectid和username不强制)
  1074. * @apiParam {Number} [statistics] 是否获取统计数据(1:获取)
  1075. * @apiParam {String} [startdate] 任务开始时间,格式:YYYY-MM-DD
  1076. * @apiParam {String} [enddate] 任务结束时间,格式:YYYY-MM-DD
  1077. *
  1078. * @apiParam {Object} [sorts] 排序方式,格式:{key:'', order:''}
  1079. * - key: title|labelid|enddate|username|level|indate|type|inorder(默认)|userorder
  1080. * - order: asc|desc
  1081. * - 【archived=已归档】或【startdate和enddate赋值】时无效
  1082. *
  1083. * @apiParam {Number} [page] 当前页,默认:1
  1084. * @apiParam {Number} [pagesize] 每页显示数量,默认:20,最大:100
  1085. */
  1086. public function task__lists()
  1087. {
  1088. $user = Users::authE();
  1089. if (Base::isError($user)) {
  1090. return $user;
  1091. } else {
  1092. $user = $user['data'];
  1093. }
  1094. //
  1095. $taskid = intval(Request::input('taskid'));
  1096. $isOwner = false;
  1097. if ($taskid > 0) {
  1098. $taskDetail = Base::DBC2A(DB::table('project_task')->where('id', $taskid)->first());
  1099. if (empty($taskDetail)) {
  1100. return Base::retError('任务不存在!');
  1101. }
  1102. if ($taskDetail['username'] == $user['username']) {
  1103. $isOwner = true;
  1104. }
  1105. $projectid = $taskDetail['projectid'];
  1106. } else {
  1107. $projectid = intval(Request::input('projectid'));
  1108. }
  1109. //
  1110. if ($projectid > 0 && !$isOwner) {
  1111. $inRes = Project::inThe($projectid, $user['username']);
  1112. if (Base::isError($inRes)) {
  1113. return $inRes;
  1114. }
  1115. }
  1116. //
  1117. $orderBy = '`inorder` DESC,`id` DESC';
  1118. $sorts = Base::json2array(Request::input('sorts'));
  1119. if (in_array($sorts['order'], ['asc', 'desc'])) {
  1120. switch ($sorts['key']) {
  1121. case 'title':
  1122. case 'labelid':
  1123. case 'enddate':
  1124. case 'username':
  1125. case 'level':
  1126. case 'indate':
  1127. case 'inorder':
  1128. case 'userorder':
  1129. $orderBy = '`' . $sorts['key'] . '` ' . $sorts['order'] . ',`id` DESC';
  1130. break;
  1131. case 'type':
  1132. $orderBy = 'CASE WHEN `complete`= 0 AND `enddate` BETWEEN 1 AND ' . Base::time() . ' THEN 0 ELSE 1 END ' . $sorts['order'] . ', `complete` ' . $sorts['order'] . ',`id` DESC';
  1133. break;
  1134. }
  1135. }
  1136. //
  1137. $selectArray = ['project_task.*'];
  1138. $whereRaw = null;
  1139. $whereFunc = null;
  1140. $whereArray = [];
  1141. $whereArray[] = ['project_task.delete', '=', 0];
  1142. if (intval(Request::input('createuser')) === 1) {
  1143. $whereArray[] = ['project_task.createuser', '=', $user['username']];
  1144. if ($projectid > 0) {
  1145. $whereArray[] = ['project_lists.id', '=', $projectid];
  1146. }
  1147. if (trim(Request::input('username'))) {
  1148. $whereArray[] = ['project_task.username', '=', trim(Request::input('username'))];
  1149. }
  1150. } else if (intval(Request::input('attention')) === 1) {
  1151. if ($projectid > 0) {
  1152. $whereArray[] = ['project_lists.id', '=', $projectid];
  1153. }
  1154. if (trim(Request::input('username'))) {
  1155. $whereArray[] = ['project_task.username', '=', trim(Request::input('username'))];
  1156. }
  1157. } else {
  1158. if ($projectid > 0) {
  1159. $whereArray[] = ['project_lists.id', '=', $projectid];
  1160. if (trim(Request::input('username'))) {
  1161. $whereArray[] = ['project_task.username', '=', trim(Request::input('username'))];
  1162. }
  1163. } else {
  1164. $whereArray[] = ['project_task.username', '=', $user['username']];
  1165. }
  1166. }
  1167. if ($taskid > 0) {
  1168. $whereArray[] = ['project_task.id', '=', intval(Request::input('taskid'))];
  1169. }
  1170. if (intval(Request::input('labelid')) > 0) {
  1171. $whereArray[] = ['project_task.labelid', '=', intval(Request::input('labelid'))];
  1172. }
  1173. if (intval(Request::input('level')) > 0) {
  1174. $whereArray[] = ['project_task.level', '=', intval(Request::input('level'))];
  1175. }
  1176. $archived = trim(Request::input('archived'));
  1177. if (empty($archived)) $archived = "未归档";
  1178. switch ($archived) {
  1179. case '已归档':
  1180. $whereArray[] = ['project_task.archived', '=', 1];
  1181. $orderBy = '`archiveddate` DESC';
  1182. break;
  1183. case '未归档':
  1184. $whereArray[] = ['project_task.archived', '=', 0];
  1185. break;
  1186. }
  1187. $type = trim(Request::input('type'));
  1188. switch ($type) {
  1189. case '未完成':
  1190. $whereArray[] = ['project_task.complete', '=', 0];
  1191. break;
  1192. case '已超期':
  1193. $whereArray[] = ['project_task.complete', '=', 0];
  1194. $whereArray[] = ['project_task.enddate', '>', 0];
  1195. $whereArray[] = ['project_task.enddate', '<=', Base::time()];
  1196. break;
  1197. case '已完成':
  1198. $whereArray[] = ['project_task.complete', '=', 1];
  1199. break;
  1200. }
  1201. $startdate = trim(Request::input('startdate'));
  1202. $enddate = trim(Request::input('enddate'));
  1203. if (Base::isDate($startdate) || Base::isDate($enddate)) {
  1204. $startdate = strtotime($startdate . ' 00:00:00');
  1205. $enddate = strtotime($enddate . ' 23:59:59');
  1206. $whereRaw.= $whereRaw ? ' AND ' : '';
  1207. $whereRaw.= "((`startdate` >= " . $startdate . " OR `startdate` = 0) AND (`enddate` <= " . $enddate . " OR `enddate` = 0))";
  1208. $orderBy = '`startdate` DESC';
  1209. }
  1210. //
  1211. $builder = DB::table('project_task');
  1212. if ($projectid > 0) {
  1213. $builder->join('project_lists', 'project_lists.id', '=', 'project_task.projectid');
  1214. }
  1215. if (intval(Request::input('attention')) === 1) {
  1216. $builder->join('project_users', 'project_users.taskid', '=', 'project_task.id');
  1217. $builder->where([
  1218. ['project_users.type', '=', '关注'],
  1219. ['project_users.username', '=', $user['username']],
  1220. ]);
  1221. $selectArray[] = 'project_users.indate AS attentiondate';
  1222. }
  1223. if ($whereRaw) {
  1224. $builder->whereRaw($whereRaw);
  1225. }
  1226. $lists = $builder->select($selectArray)
  1227. ->where($whereArray)
  1228. ->orderByRaw($orderBy)
  1229. ->paginate(Base::getPaginate(100, 20));
  1230. $lists = Base::getPageList($lists, $taskid > 0 ? false : true);
  1231. if (intval(Request::input('statistics')) == 1) {
  1232. $lists['statistics_unfinished'] = $type === '未完成' ? $lists['total'] : DB::table('project_task')->where('projectid', $projectid)->where('delete', 0)->where('archived', 0)->where('complete', 0)->count();
  1233. $lists['statistics_overdue'] = $type === '已超期' ? $lists['total'] : DB::table('project_task')->where('projectid', $projectid)->where('delete', 0)->where('archived', 0)->where('complete', 0)->whereBetween('enddate', [1, Base::time()])->count();
  1234. $lists['statistics_complete'] = $type === '已完成' ? $lists['total'] : DB::table('project_task')->where('projectid', $projectid)->where('delete', 0)->where('archived', 0)->where('complete', 1)->count();
  1235. }
  1236. if ($lists['total'] == 0) {
  1237. return Base::retError('未找到任何相关的任务!', $lists);
  1238. }
  1239. foreach ($lists['lists'] AS $key => $info) {
  1240. $info['overdue'] = Project::taskIsOverdue($info);
  1241. $info['subtask'] = Base::string2array($info['subtask']);
  1242. $info['follower'] = Base::string2array($info['follower']);
  1243. $lists['lists'][$key] = array_merge($info, Users::username2basic($info['username']));
  1244. }
  1245. if ($taskid > 0) {
  1246. if (count($lists['lists']) == 0) {
  1247. return Base::retError('未能找到此任务或无法管理此任务!');
  1248. }
  1249. $data = $lists['lists'][0];
  1250. $data['projectTitle'] = $data['projectid'] > 0 ? DB::table('project_lists')->where('id', $data['projectid'])->value('title') : '';
  1251. return Base::retSuccess('success', $data);
  1252. } else {
  1253. return Base::retSuccess('success', $lists);
  1254. }
  1255. }
  1256. /**
  1257. * 项目任务-获取数量
  1258. *
  1259. * @apiParam {Number} [level] 任务等级(1~4,留空获取所有)
  1260. */
  1261. public function task__levelnum()
  1262. {
  1263. $user = Users::authE();
  1264. if (Base::isError($user)) {
  1265. return $user;
  1266. } else {
  1267. $user = $user['data'];
  1268. }
  1269. //
  1270. $whereArray = [];
  1271. $whereArray[] = ['project_task.delete', '=', 0];
  1272. $whereArray[] = ['project_task.username', '=', $user['username']];
  1273. $whereArray[] = ['project_task.archived', '=', 0];
  1274. $array = [
  1275. 'level_1' => 0,
  1276. 'level_2' => 0,
  1277. 'level_3' => 0,
  1278. 'level_4' => 0,
  1279. ];
  1280. $level = intval(Request::input('level'));
  1281. if ($level > 0) {
  1282. $array = [];
  1283. $array['level_' . $level] = 0;
  1284. }
  1285. foreach ($array AS $key => $val) {
  1286. $level = intval(Base::leftDelete($key, 'level_'));
  1287. $array[$key] = DB::table('project_task')->where($whereArray)->where('level', $level)->count();
  1288. }
  1289. return Base::retSuccess('success', $array);
  1290. }
  1291. /**
  1292. * 项目任务-添加任务
  1293. *
  1294. * @apiParam {String} title 任务标题
  1295. * @apiParam {Number} [projectid] 项目ID
  1296. * @apiParam {Number} [labelid] 项目子分类ID
  1297. * @apiParam {Number} [level] 任务紧急级别(1~4,默认:2)
  1298. * @apiParam {String} [username] 任务负责人用户名(如果项目ID为空时此参数无效,负责人为自己)
  1299. * @apiParam {Number} [insertbottom] 是否添加至列表结尾(1:是,默认:0,仅适用于项目分类列表)
  1300. *
  1301. * @throws \Throwable
  1302. */
  1303. public function task__add()
  1304. {
  1305. $user = Users::authE();
  1306. if (Base::isError($user)) {
  1307. return $user;
  1308. } else {
  1309. $user = $user['data'];
  1310. }
  1311. //
  1312. $projectid = intval(Request::input('projectid'));
  1313. $labelid = intval(Request::input('labelid'));
  1314. $insertbottom = intval(Request::input('insertbottom'));
  1315. if ($projectid > 0) {
  1316. $projectDetail = Base::DBC2A(DB::table('project_lists')->where('id', $projectid)->where('delete', 0)->first());
  1317. if (empty($projectDetail)) {
  1318. return Base::retError('项目不存在或已被删除!');
  1319. }
  1320. //
  1321. $labelDetail = Base::DBC2A(DB::table('project_label')->where('id', $labelid)->where('projectid', $projectid)->first());
  1322. if (empty($labelDetail)) {
  1323. return Base::retError('项目子分类不存在或已被删除!');
  1324. }
  1325. //
  1326. $inRes = Project::inThe($projectid, $user['username']);
  1327. if (Base::isError($inRes)) {
  1328. return $inRes;
  1329. }
  1330. $checkRole = Project::role('add_role', $projectid, 0);
  1331. if (Base::isError($checkRole)) {
  1332. return $checkRole;
  1333. }
  1334. //
  1335. $username = trim(Request::input('username'));
  1336. if (empty($username)) {
  1337. $username = $user['username'];
  1338. }
  1339. if ($username != $user['username']) {
  1340. $inRes = Project::inThe($projectid, $username);
  1341. if (Base::isError($inRes)) {
  1342. return Base::retError('负责人不在项目成员内!');
  1343. }
  1344. }
  1345. } else {
  1346. $username = $user['username'];
  1347. }
  1348. //
  1349. $title = trim(Request::input('title'));
  1350. if (empty($title)) {
  1351. return Base::retError('任务标题不能为空!');
  1352. } elseif (mb_strlen($title) > 255) {
  1353. return Base::retError('任务标题最多只能设置255个字!');
  1354. }
  1355. //
  1356. $level = max(1, min(4, intval(Request::input('level'))));
  1357. if (empty($projectid)) {
  1358. $inorder = 0;
  1359. } else {
  1360. $inorder = intval(DB::table('project_task')->where('projectid', $projectid)->orderBy('inorder', $insertbottom ? 'asc' : 'desc')->value('inorder')) + ($insertbottom ? -1 : 1);
  1361. }
  1362. $userorder = intval(DB::table('project_task')->where('username', $user['username'])->where('level', $level)->orderByDesc('userorder')->value('userorder')) + 1;
  1363. //
  1364. $inArray = [
  1365. 'projectid' => $projectid,
  1366. 'labelid' => $labelid,
  1367. 'createuser' => $user['username'],
  1368. 'username' => $username,
  1369. 'title' => $title,
  1370. 'level' => $level,
  1371. 'inorder' => $inorder,
  1372. 'userorder' => $userorder,
  1373. 'indate' => Base::time(),
  1374. 'startdate' => Base::time(),
  1375. 'subtask' => Base::array2string([]),
  1376. 'follower' => Base::array2string([]),
  1377. ];
  1378. return DB::transaction(function () use ($inArray) {
  1379. $taskid = DB::table('project_task')->insertGetId($inArray);
  1380. if (empty($taskid)) {
  1381. return Base::retError('系统繁忙,请稍后再试!');
  1382. }
  1383. DB::table('project_log')->insert([
  1384. 'type' => '日志',
  1385. 'projectid' => $inArray['projectid'],
  1386. 'taskid' => $taskid,
  1387. 'username' => $inArray['createuser'],
  1388. 'detail' => '添加任务',
  1389. 'indate' => Base::time(),
  1390. 'other' => Base::array2string([
  1391. 'type' => 'task',
  1392. 'id' => $taskid,
  1393. 'title' => $inArray['title'],
  1394. ])
  1395. ]);
  1396. Project::updateNum($inArray['projectid']);
  1397. //
  1398. $task = Base::DBC2A(DB::table('project_task')->where('id', $taskid)->first());
  1399. $task['overdue'] = Project::taskIsOverdue($task);
  1400. $task['subtask'] = Base::string2array($task['subtask']);
  1401. $task['follower'] = Base::string2array($task['follower']);
  1402. $task = array_merge($task, Users::username2basic($task['username']));
  1403. return Base::retSuccess('添加成功!', $task);
  1404. });
  1405. }
  1406. /**
  1407. * {post} 项目任务-修改
  1408. *
  1409. * @apiParam {Number} taskid 任务ID
  1410. * @apiParam {String} act 修改字段|操作类型
  1411. * - title: 标题
  1412. * - desc: 描述
  1413. * - level: 优先级
  1414. * - username: 负责人
  1415. * - plannedtime: 设置计划时间
  1416. * - unplannedtime: 取消计划时间
  1417. * - complete: 标记完成
  1418. * - unfinished: 标记未完成
  1419. * - archived: 归档
  1420. * - unarchived: 取消归档
  1421. * - delete: 删除任务
  1422. * - comment: 评论
  1423. * - attention: 添加关注
  1424. * - subtask: 修改子任务
  1425. * @apiParam {String} [content] 内容数据
  1426. *
  1427. * @throws \Throwable
  1428. */
  1429. public function task__edit()
  1430. {
  1431. $user = Users::authE();
  1432. if (Base::isError($user)) {
  1433. return $user;
  1434. } else {
  1435. $user = $user['data'];
  1436. }
  1437. //
  1438. $act = trim(Base::getPostValue('act'));
  1439. $taskid = intval(Base::getPostValue('taskid'));
  1440. $task = Base::DBC2A(DB::table('project_task')
  1441. ->where([
  1442. ['delete', '=', 0],
  1443. ['id', '=', $taskid],
  1444. ])
  1445. ->first());
  1446. if (empty($task)) {
  1447. return Base::retError('任务不存在!');
  1448. }
  1449. if ($task['projectid'] > 0) {
  1450. if ($task['username'] != $user['username']) {
  1451. $inRes = Project::inThe($task['projectid'], $user['username']);
  1452. if (Base::isError($inRes)) {
  1453. return $inRes;
  1454. }
  1455. }
  1456. if (!in_array($act, ['comment', 'attention'])) {
  1457. $checkRole = Project::role('edit_role', $task['projectid'], $task['id']);
  1458. if (Base::isError($checkRole)) {
  1459. return $checkRole;
  1460. }
  1461. switch ($act) {
  1462. case 'complete':
  1463. case 'unfinished':
  1464. $checkRole = Project::role('complete_role', $task['projectid'], $task['id']);
  1465. if (Base::isError($checkRole)) {
  1466. return $checkRole;
  1467. }
  1468. break;
  1469. case 'archived':
  1470. case 'unarchived':
  1471. $checkRole = Project::role('archived_role', $task['projectid'], $task['id']);
  1472. if (Base::isError($checkRole)) {
  1473. return $checkRole;
  1474. }
  1475. break;
  1476. case 'delete':
  1477. $checkRole = Project::role('del_role', $task['projectid'], $task['id']);
  1478. if (Base::isError($checkRole)) {
  1479. return $checkRole;
  1480. }
  1481. break;
  1482. }
  1483. }
  1484. } else {
  1485. if ($task['username'] != $user['username']) {
  1486. return Base::retError('此操作只允许任务负责人!');
  1487. }
  1488. }
  1489. //
  1490. $content = Base::newTrim(Base::getPostValue('content'));
  1491. $message = "";
  1492. $upArray = [];
  1493. $logArray = [];
  1494. switch ($act) {
  1495. /**
  1496. * 修改标题
  1497. */
  1498. case 'title': {
  1499. if ($content == $task['title']) {
  1500. return Base::retError('标题未做改变!');
  1501. }
  1502. $upArray['title'] = $content;
  1503. $logArray[] = [
  1504. 'type' => '日志',
  1505. 'projectid' => $task['projectid'],
  1506. 'taskid' => $task['id'],
  1507. 'username' => $user['username'],
  1508. 'detail' => '修改任务标题',
  1509. 'indate' => Base::time(),
  1510. 'other' => Base::array2string([
  1511. 'type' => 'task',
  1512. 'id' => $task['id'],
  1513. 'title' => $content,
  1514. 'old_title' => $task['title'],
  1515. ])
  1516. ];
  1517. break;
  1518. }
  1519. /**
  1520. * 修改描述
  1521. */
  1522. case 'desc': {
  1523. if ($content == $task['desc']) {
  1524. return Base::retError('描述未做改变!');
  1525. }
  1526. $upArray['desc'] = $content;
  1527. $logArray[] = [
  1528. 'type' => '日志',
  1529. 'projectid' => $task['projectid'],
  1530. 'taskid' => $task['id'],
  1531. 'username' => $user['username'],
  1532. 'detail' => '修改任务描述',
  1533. 'indate' => Base::time(),
  1534. 'other' => Base::array2string([
  1535. 'type' => 'task',
  1536. 'id' => $task['id'],
  1537. 'title' => $task['title'],
  1538. 'old_desc' => $task['desc'],
  1539. ])
  1540. ];
  1541. break;
  1542. }
  1543. /**
  1544. * 调整任务等级
  1545. */
  1546. case 'level': {
  1547. $content = intval($content);
  1548. if ($content == $task['level']) {
  1549. return Base::retError('优先级未做改变!');
  1550. }
  1551. if ($content > 4 || $content < 1) {
  1552. return Base::retError('优先级参数错误!');
  1553. }
  1554. $upArray['level'] = $content;
  1555. $logArray[] = [
  1556. 'type' => '日志',
  1557. 'projectid' => $task['projectid'],
  1558. 'taskid' => $task['id'],
  1559. 'username' => $user['username'],
  1560. 'detail' => '调整任务等级为【P' . $content . '】',
  1561. 'indate' => Base::time(),
  1562. 'other' => Base::array2string([
  1563. 'type' => 'task',
  1564. 'id' => $task['id'],
  1565. 'title' => $task['title'],
  1566. 'old_level' => $task['level'],
  1567. ])
  1568. ];
  1569. break;
  1570. }
  1571. /**
  1572. * 修改任务负责人
  1573. */
  1574. case 'username': {
  1575. if ($content == $task['username']) {
  1576. return Base::retError('负责人未做改变!');
  1577. }
  1578. if ($task['projectid'] > 0) {
  1579. $inRes = Project::inThe($task['projectid'], $content);
  1580. if (Base::isError($inRes)) {
  1581. return Base::retError(['%不在成员列表内!', $content]);
  1582. }
  1583. }
  1584. $upArray['username'] = $content;
  1585. $logArray[] = [
  1586. 'type' => '日志',
  1587. 'projectid' => $task['projectid'],
  1588. 'taskid' => $task['id'],
  1589. 'username' => $user['username'],
  1590. 'detail' => '修改负责人',
  1591. 'indate' => Base::time(),
  1592. 'other' => Base::array2string([
  1593. 'type' => 'task',
  1594. 'id' => $task['id'],
  1595. 'title' => $task['title'],
  1596. 'old_username' => $task['username'],
  1597. ])
  1598. ];
  1599. break;
  1600. }
  1601. /**
  1602. * 修改计划时间
  1603. */
  1604. case 'plannedtime': {
  1605. list($startdate, $enddate) = explode(",", $content);
  1606. if (!Base::isDate($startdate) || !Base::isDate($enddate)) {
  1607. return Base::retError('计划时间参数错误!');
  1608. }
  1609. $startdate = strtotime($startdate);
  1610. $enddate = strtotime($enddate);
  1611. if ($startdate == $task['startdate'] && $enddate == $task['enddate']) {
  1612. return Base::retError('与原计划时间一致!');
  1613. }
  1614. if ($startdate == $enddate) {
  1615. return Base::retError('开始时间与结束时间一致!');
  1616. }
  1617. $upArray['startdate'] = $startdate;
  1618. $upArray['enddate'] = $enddate;
  1619. $logArray[] = [
  1620. 'type' => '日志',
  1621. 'projectid' => $task['projectid'],
  1622. 'taskid' => $task['id'],
  1623. 'username' => $user['username'],
  1624. 'detail' => '设置计划时间',
  1625. 'indate' => Base::time(),
  1626. 'other' => Base::array2string([
  1627. 'type' => 'task',
  1628. 'id' => $task['id'],
  1629. 'title' => $task['title'],
  1630. 'old_startdate' => $task['startdate'],
  1631. 'old_enddate' => $task['enddate'],
  1632. ])
  1633. ];
  1634. break;
  1635. }
  1636. /**
  1637. * 取消计划时间
  1638. */
  1639. case 'unplannedtime': {
  1640. $startdate = 0;
  1641. $enddate = 0;
  1642. if ($startdate == $task['startdate'] && $enddate == $task['enddate']) {
  1643. return Base::retError('与原计划时间一致!');
  1644. }
  1645. $upArray['startdate'] = $startdate;
  1646. $upArray['enddate'] = $enddate;
  1647. $logArray[] = [
  1648. 'type' => '日志',
  1649. 'projectid' => $task['projectid'],
  1650. 'taskid' => $task['id'],
  1651. 'username' => $user['username'],
  1652. 'detail' => '取消计划时间',
  1653. 'indate' => Base::time(),
  1654. 'other' => Base::array2string([
  1655. 'type' => 'task',
  1656. 'id' => $task['id'],
  1657. 'title' => $task['title'],
  1658. 'old_startdate' => $task['startdate'],
  1659. 'old_enddate' => $task['enddate'],
  1660. ])
  1661. ];
  1662. break;
  1663. }
  1664. /**
  1665. * 标记完成
  1666. */
  1667. case 'complete': {
  1668. if ($task['complete'] == 1) {
  1669. return Base::retError('任务已标记完成,请勿重复操作!');
  1670. }
  1671. $upArray['complete'] = 1;
  1672. $upArray['completedate'] = Base::time();
  1673. $logArray[] = [
  1674. 'type' => '日志',
  1675. 'projectid' => $task['projectid'],
  1676. 'taskid' => $task['id'],
  1677. 'username' => $user['username'],
  1678. 'detail' => '标记已完成',
  1679. 'indate' => Base::time(),
  1680. 'other' => Base::array2string([
  1681. 'type' => 'task',
  1682. 'id' => $task['id'],
  1683. 'title' => $task['title'],
  1684. ])
  1685. ];
  1686. break;
  1687. }
  1688. /**
  1689. * 标记未完成
  1690. */
  1691. case 'unfinished': {
  1692. if ($task['complete'] == 0) {
  1693. return Base::retError('任务未完成,无法标记未完成!');
  1694. }
  1695. $upArray['complete'] = 0;
  1696. $logArray[] = [
  1697. 'type' => '日志',
  1698. 'projectid' => $task['projectid'],
  1699. 'taskid' => $task['id'],
  1700. 'username' => $user['username'],
  1701. 'detail' => '标记未完成',
  1702. 'indate' => Base::time(),
  1703. 'other' => Base::array2string([
  1704. 'type' => 'task',
  1705. 'id' => $task['id'],
  1706. 'title' => $task['title'],
  1707. ])
  1708. ];
  1709. break;
  1710. }
  1711. /**
  1712. * 归档
  1713. */
  1714. case 'archived': {
  1715. if ($task['archived'] == 1) {
  1716. return Base::retError('任务已经归档,请勿重复操作!');
  1717. }
  1718. $upArray['archived'] = 1;
  1719. $upArray['archiveddate'] = Base::time();
  1720. $logArray[] = [
  1721. 'type' => '日志',
  1722. 'projectid' => $task['projectid'],
  1723. 'taskid' => $task['id'],
  1724. 'username' => $user['username'],
  1725. 'detail' => '任务归档',
  1726. 'indate' => Base::time(),
  1727. 'other' => Base::array2string([
  1728. 'type' => 'task',
  1729. 'id' => $task['id'],
  1730. 'title' => $task['title'],
  1731. ])
  1732. ];
  1733. break;
  1734. }
  1735. /**
  1736. * 取消归档
  1737. */
  1738. case 'unarchived': {
  1739. if ($task['archived'] == 0) {
  1740. return Base::retError('任务未归档,无法取消归档操作!');
  1741. }
  1742. $upArray['archived'] = 0;
  1743. $logArray[] = [
  1744. 'type' => '日志',
  1745. 'projectid' => $task['projectid'],
  1746. 'taskid' => $task['id'],
  1747. 'username' => $user['username'],
  1748. 'detail' => '取消归档',
  1749. 'indate' => Base::time(),
  1750. 'other' => Base::array2string([
  1751. 'type' => 'task',
  1752. 'id' => $task['id'],
  1753. 'title' => $task['title'],
  1754. ])
  1755. ];
  1756. break;
  1757. }
  1758. /**
  1759. * 删除任务
  1760. */
  1761. case 'delete': {
  1762. if ($task['delete'] == 1) {
  1763. return Base::retError('任务已删除,请勿重复操作!');
  1764. }
  1765. $upArray['delete'] = 1;
  1766. $upArray['deletedate'] = Base::time();
  1767. $logArray[] = [
  1768. 'type' => '日志',
  1769. 'projectid' => $task['projectid'],
  1770. 'taskid' => $task['id'],
  1771. 'username' => $user['username'],
  1772. 'detail' => '删除任务',
  1773. 'indate' => Base::time(),
  1774. 'other' => Base::array2string([
  1775. 'type' => 'task',
  1776. 'id' => $task['id'],
  1777. 'title' => $task['title'],
  1778. ])
  1779. ];
  1780. $message = "删除成功!";
  1781. break;
  1782. }
  1783. /**
  1784. * 评论任务
  1785. */
  1786. case 'comment': {
  1787. if (mb_strlen($content) < 2) {
  1788. return Base::retError('评论内容至少2个字!');
  1789. }
  1790. $logArray[] = [
  1791. 'type' => '评论',
  1792. 'projectid' => $task['projectid'],
  1793. 'taskid' => $task['id'],
  1794. 'username' => $user['username'],
  1795. 'detail' => $content,
  1796. 'indate' => Base::time(),
  1797. 'other' => Base::array2string([
  1798. 'type' => 'task',
  1799. 'id' => $task['id'],
  1800. 'title' => $task['title'],
  1801. ])
  1802. ];
  1803. $message = "评论成功!";
  1804. break;
  1805. }
  1806. /**
  1807. * 添加关注
  1808. */
  1809. case 'attention': {
  1810. $userArray = explode(",", $content);
  1811. DB::transaction(function () use ($user, $task, $userArray) {
  1812. foreach ($userArray AS $uname) {
  1813. $uid = Users::username2id($uname);
  1814. if (empty($uid)) {
  1815. continue;
  1816. }
  1817. $row = Base::DBC2A(DB::table('project_users')->where([
  1818. 'type' => '关注',
  1819. 'taskid' => $task['id'],
  1820. 'username' => $uname,
  1821. ])->lockForUpdate()->first());
  1822. if (empty($row)) {
  1823. DB::table('project_users')->insert([
  1824. 'type' => '关注',
  1825. 'projectid' => $task['projectid'],
  1826. 'taskid' => $task['id'],
  1827. 'isowner' => $task['username'] == $uname ? 1 : 0,
  1828. 'username' => $uname,
  1829. 'indate' => Base::time()
  1830. ]);
  1831. DB::table('project_log')->insert([
  1832. 'type' => '日志',
  1833. 'projectid' => $task['projectid'],
  1834. 'taskid' => $task['id'],
  1835. 'username' => $uname,
  1836. 'detail' => $uname == $user['username'] ? '关注任务' : '加入关注',
  1837. 'indate' => Base::time(),
  1838. 'other' => Base::array2string([
  1839. 'type' => 'task',
  1840. 'id' => $task['id'],
  1841. 'title' => $task['title'],
  1842. 'operator' => $user['username'],
  1843. 'action' => 'attention',
  1844. ])
  1845. ]);
  1846. }
  1847. }
  1848. });
  1849. $tempRow = Base::DBC2A(DB::table('project_users')->select(['username'])->where([ 'type' => '关注', 'taskid' => $task['id'] ])->get()->pluck('username'));
  1850. $upArray['follower'] = Base::array2string($tempRow);
  1851. $message = "保存成功!";
  1852. break;
  1853. }
  1854. /**
  1855. * 取消关注
  1856. */
  1857. case 'unattention': {
  1858. $userArray = explode(",", $content);
  1859. DB::transaction(function () use ($user, $task, $userArray) {
  1860. foreach ($userArray AS $uname) {
  1861. if (DB::table('project_users')->where([
  1862. 'type' => '关注',
  1863. 'taskid' => $task['id'],
  1864. 'username' => $uname,
  1865. ])->delete()) {
  1866. DB::table('project_log')->insert([
  1867. 'type' => '日志',
  1868. 'projectid' => $task['projectid'],
  1869. 'taskid' => $task['id'],
  1870. 'username' => $uname,
  1871. 'detail' => $uname == $user['username'] ? '取消关注' : '移出关注',
  1872. 'indate' => Base::time(),
  1873. 'other' => Base::array2string([
  1874. 'type' => 'task',
  1875. 'id' => $task['id'],
  1876. 'title' => $task['title'],
  1877. 'operator' => $user['username'],
  1878. 'action' => 'unattention',
  1879. ])
  1880. ]);
  1881. }
  1882. }
  1883. });
  1884. $tempRow = Base::DBC2A(DB::table('project_users')->select(['username'])->where([ 'type' => '关注', 'taskid' => $task['id'] ])->get()->pluck('username'));
  1885. $upArray['follower'] = Base::array2string($tempRow);
  1886. $message = "保存成功!";
  1887. break;
  1888. }
  1889. /**
  1890. * 修改子任务
  1891. */
  1892. case 'subtask': {
  1893. if (!is_array($content)) {
  1894. $content = [];
  1895. }
  1896. $content = Base::array2string($content);
  1897. if ($content == $task['subtask']) {
  1898. return Base::retError('子任务未做改变!');
  1899. }
  1900. $upArray['subtask'] = $content;
  1901. //
  1902. $detail = '修改子任务';
  1903. $subtype = 'modify';
  1904. $new_count = count(Base::string2array($content));
  1905. $old_count = count(Base::string2array($task['subtask']));
  1906. if ($new_count > $old_count) {
  1907. $detail = '添加子任务';
  1908. $subtype = 'add';
  1909. } elseif ($new_count < $old_count) {
  1910. $detail = '删除子任务';
  1911. $subtype = 'del';
  1912. }
  1913. //
  1914. $logArray[] = [
  1915. 'type' => '日志',
  1916. 'projectid' => $task['projectid'],
  1917. 'taskid' => $task['id'],
  1918. 'username' => $user['username'],
  1919. 'detail' => $detail,
  1920. 'indate' => Base::time(),
  1921. 'other' => Base::array2string([
  1922. 'type' => 'task',
  1923. 'subtype' => $subtype,
  1924. 'id' => $task['id'],
  1925. 'subtask' => $content,
  1926. 'old_subtask' => $task['subtask'],
  1927. ])
  1928. ];
  1929. break;
  1930. }
  1931. default: {
  1932. return Base::retError('参数错误!');
  1933. break;
  1934. }
  1935. }
  1936. //
  1937. if ($upArray) {
  1938. DB::table('project_task')->where('id', $taskid)->update($upArray);
  1939. }
  1940. if ($logArray) {
  1941. DB::table('project_log')->insert($logArray);
  1942. }
  1943. //
  1944. if (in_array($act, ['complete', 'unfinished'])) {
  1945. Project::updateNum($task['projectid']);
  1946. }
  1947. //
  1948. $task = array_merge($task, $upArray);
  1949. $task['overdue'] = Project::taskIsOverdue($task);
  1950. $task['subtask'] = Base::string2array($task['subtask']);
  1951. $task['follower'] = Base::string2array($task['follower']);
  1952. $task['projectTitle'] = $task['projectid'] > 0 ? DB::table('project_lists')->where('id', $task['projectid'])->value('title') : '';
  1953. $task = array_merge($task, Users::username2basic($task['username']));
  1954. return Base::retSuccess($message ?: '修改成功!', $task);
  1955. }
  1956. /**
  1957. * 项目任务-待推送日志
  1958. *
  1959. * @apiParam {Number} taskid 任务ID
  1960. * @apiParam {Number} [page] 当前页,默认:1
  1961. * @apiParam {Number} [pagesize] 每页显示数量,默认:20,最大:100
  1962. * @throws \Throwable
  1963. */
  1964. public function task__pushlog()
  1965. {
  1966. $user = Users::authE();
  1967. if (Base::isError($user)) {
  1968. return $user;
  1969. } else {
  1970. $user = $user['data'];
  1971. }
  1972. //
  1973. return DB::transaction(function () {
  1974. $taskid = intval(Request::input('taskid'));
  1975. $task = Base::DBC2A(DB::table('project_task')
  1976. ->select(['pushlid', 'follower', 'username'])
  1977. ->where([
  1978. ['delete', '=', 0],
  1979. ['id', '=', $taskid],
  1980. ])
  1981. ->lockForUpdate()
  1982. ->first());
  1983. if (empty($task)) {
  1984. return Base::retError('任务不存在!');
  1985. }
  1986. $task['follower'] = Base::string2array($task['follower']);
  1987. $task['follower'][] = $task['username'];
  1988. //
  1989. $pushlid = $task['pushlid'];
  1990. $lists = DB::table('project_log')
  1991. ->select(['id', 'username', 'indate', 'detail', 'other'])
  1992. ->where([
  1993. ['id', '>', $pushlid],
  1994. ['taskid', '=', $taskid],
  1995. ['indate', '>', Base::time() - 60]
  1996. ])
  1997. ->orderBy('id')->paginate(Base::getPaginate(100, 20));
  1998. $lists = Base::getPageList($lists, false);
  1999. if (count($lists['lists']) == 0) {
  2000. return Base::retError('no lists');
  2001. }
  2002. $array = [];
  2003. foreach ($lists['lists'] AS $key => $item) {
  2004. $item = array_merge($item, Users::username2basic($item['username']));
  2005. $item['other'] = Base::string2array($item['other'], ['type' => '']);
  2006. if (!in_array($item['other']['action'], ['attention', 'unattention'])) {
  2007. $array[] = $item;
  2008. }
  2009. $pushlid = $item['id'];
  2010. }
  2011. $lists['lists'] = $array;
  2012. if ($pushlid != $task['pushlid']) {
  2013. DB::table('project_task')->where('id', $taskid)->update([
  2014. 'pushlid' => $pushlid
  2015. ]);
  2016. }
  2017. return Base::retSuccess('success', array_merge($lists, $task));
  2018. });
  2019. }
  2020. /**
  2021. * 项目文件-列表
  2022. *
  2023. * @apiParam {Number} [projectid] 项目ID
  2024. * @apiParam {Number} [taskid] 任务ID(如果项目ID为空时此参必须赋值且任务必须是自己负责人或在任务所在的项目里)
  2025. * @apiParam {String} [name] 文件名称
  2026. * @apiParam {String} [username] 上传者用户名
  2027. * @apiParam {Object} [sorts] 排序方式,格式:{key:'', order:''}
  2028. * - key: name|size|username|indate
  2029. * - order: asc|desc
  2030. * @apiParam {Number} [page] 当前页,默认:1
  2031. * @apiParam {Number} [pagesize] 每页显示数量,默认:20,最大:100
  2032. */
  2033. public function files__lists()
  2034. {
  2035. $user = Users::authE();
  2036. if (Base::isError($user)) {
  2037. return $user;
  2038. } else {
  2039. $user = $user['data'];
  2040. }
  2041. //
  2042. $taskid = intval(Request::input('taskid'));
  2043. if ($taskid > 0) {
  2044. $projectid = intval(DB::table('project_task')->select(['projectid'])->where([ 'id' => $taskid])->value('projectid'));
  2045. } else {
  2046. $projectid = intval(Request::input('projectid'));
  2047. }
  2048. if ($projectid > 0) {
  2049. $inRes = Project::inThe($projectid, $user['username']);
  2050. if (Base::isError($inRes)) {
  2051. return $inRes;
  2052. }
  2053. }
  2054. //
  2055. $orderBy = '`id` DESC';
  2056. $sorts = Base::json2array(Request::input('sorts'));
  2057. if (in_array($sorts['order'], ['asc', 'desc'])) {
  2058. switch ($sorts['key']) {
  2059. case 'name':
  2060. case 'size':
  2061. case 'download':
  2062. case 'username':
  2063. case 'indate':
  2064. $orderBy = '`' . $sorts['key'] . '` ' . $sorts['order'] . ',`id` DESC';
  2065. break;
  2066. }
  2067. }
  2068. //
  2069. $whereArray = [];
  2070. if ($projectid > 0) {
  2071. $whereArray[] = ['projectid', '=', $projectid];
  2072. if ($taskid > 0) {
  2073. $whereArray[] = ['taskid', '=', $taskid];
  2074. }
  2075. } else {
  2076. if ($taskid <= 0) {
  2077. return Base::retError('参数错误!');
  2078. }
  2079. $count = DB::table('project_task')->where([ 'id' => $taskid, 'username' => $user['username']])->count();
  2080. if ($count <= 0) {
  2081. return Base::retError('你不是任务负责人!');
  2082. }
  2083. $whereArray[] = ['taskid', '=', $taskid];
  2084. }
  2085. $whereArray[] = ['delete', '=', 0];
  2086. if (intval(Request::input('taskid')) > 0) {
  2087. $whereArray[] = ['taskid', '=', intval(Request::input('taskid'))];
  2088. }
  2089. if (trim(Request::input('name'))) {
  2090. $whereArray[] = ['name', 'like', '%' . trim(Request::input('name')) . '%'];
  2091. }
  2092. if (trim(Request::input('username'))) {
  2093. $whereArray[] = ['username', '=', trim(Request::input('username'))];
  2094. }
  2095. //
  2096. $lists = DB::table('project_files')
  2097. ->where($whereArray)
  2098. ->orderByRaw($orderBy)->paginate(Base::getPaginate(100, 20));
  2099. $lists = Base::getPageList($lists);
  2100. if ($lists['total'] == 0) {
  2101. return Base::retError('未找到任何相关的文件', $lists);
  2102. }
  2103. foreach ($lists['lists'] AS $key => $item) {
  2104. $lists['lists'][$key]['path'] = Base::fillUrl($item['path']);
  2105. $lists['lists'][$key]['thumb'] = Base::fillUrl($item['thumb']);
  2106. $lists['lists'][$key]['yetdown'] = intval(Session::get('filesDownload:' . $item['id']));
  2107. }
  2108. return Base::retSuccess('success', $lists);
  2109. }
  2110. /**
  2111. * 项目文件-上传
  2112. *
  2113. * @apiParam {Number} [projectid] 项目ID
  2114. * @apiParam {Number} [taskid] 任务ID(如果项目ID为空时此参必须赋值且任务必须是自己负责人)
  2115. */
  2116. public function files__upload()
  2117. {
  2118. $user = Users::authE();
  2119. if (Base::isError($user)) {
  2120. return $user;
  2121. } else {
  2122. $user = $user['data'];
  2123. }
  2124. //
  2125. $projectid = intval(Request::input('projectid'));
  2126. $taskid = intval(Request::input('taskid'));
  2127. if ($projectid > 0) {
  2128. $inRes = Project::inThe($projectid, $user['username']);
  2129. if (Base::isError($inRes)) {
  2130. return $inRes;
  2131. }
  2132. } else {
  2133. if ($taskid <= 0) {
  2134. return Base::retError('参数错误!');
  2135. }
  2136. $row = Base::DBC2A(DB::table('project_task')->select(['projectid'])->where([ 'id' => $taskid, 'username' => $user['username']])->first());
  2137. if (empty($row)) {
  2138. return Base::retError('你不是任务负责人!');
  2139. }
  2140. $projectid = $row['projectid'];
  2141. }
  2142. //
  2143. $data = Base::upload([
  2144. "file" => Request::file('files'),
  2145. "type" => 'file',
  2146. "path" => "uploads/projects/" . $projectid . "/",
  2147. ]);
  2148. if (Base::isError($data)) {
  2149. return Base::retError($data['msg']);
  2150. } else {
  2151. $fileData = $data['data'];
  2152. $thumb = 'images/files/file.png';
  2153. switch ($fileData['ext']) {
  2154. case "docx":
  2155. $thumb = 'images/files/doc.png';
  2156. break;
  2157. case "xlsx":
  2158. $thumb = 'images/files/xls.png';
  2159. break;
  2160. case "pptx":
  2161. $thumb = 'images/files/ppt.png';
  2162. break;
  2163. case "doc":
  2164. case "xls":
  2165. case "ppt":
  2166. case "txt":
  2167. case "esp":
  2168. case "gif":
  2169. $thumb = 'images/files/' . $fileData['ext'] . '.png';
  2170. break;
  2171. case "jpg":
  2172. case "jpeg":
  2173. case "png":
  2174. if (Base::imgThumb($fileData['file'], $fileData['file'] . "_thumb.jpg", 64, 0)) {
  2175. $thumb = $fileData['path'] . "_thumb.jpg";
  2176. }
  2177. break;
  2178. }
  2179. $array = [
  2180. 'projectid' => $projectid,
  2181. 'taskid' => $taskid,
  2182. 'name' => $fileData['name'],
  2183. 'size' => $fileData['size'] * 1024,
  2184. 'ext' => $fileData['ext'],
  2185. 'path' => $fileData['path'],
  2186. 'thumb' => $thumb,
  2187. 'username' => $user['username'],
  2188. 'indate' => Base::time(),
  2189. ];
  2190. $id = DB::table('project_files')->insertGetId($array);
  2191. $array['id'] = $id;
  2192. $array['path'] = Base::fillUrl($array['path']);
  2193. $array['thumb'] = Base::fillUrl($array['thumb']);
  2194. $array['download'] = 0;
  2195. $array['yetdown'] = 0;
  2196. DB::table('project_log')->insert([
  2197. 'type' => '日志',
  2198. 'projectid' => $projectid,
  2199. 'taskid' => $taskid,
  2200. 'username' => $user['username'],
  2201. 'detail' => '上传文件',
  2202. 'indate' => Base::time(),
  2203. 'other' => Base::array2string([
  2204. 'type' => 'file',
  2205. 'id' => $id,
  2206. 'name' => $fileData['name'],
  2207. ])
  2208. ]);
  2209. if ($taskid > 0) {
  2210. DB::table('project_task')->where('id', $taskid)->increment('filenum');
  2211. }
  2212. return Base::retSuccess('success', $array);
  2213. }
  2214. }
  2215. /**
  2216. * 项目文件-下载
  2217. *
  2218. * @apiParam {Number} fileid 文件ID
  2219. */
  2220. public function files__download()
  2221. {
  2222. $fileDetail = Base::DBC2A(DB::table('project_files')->where('id', intval(Request::input('fileid')))->where('delete', 0)->first());
  2223. if (empty($fileDetail)) {
  2224. return abort(404, '文件不存在或已被删除!');
  2225. }
  2226. $filePath = public_path($fileDetail['path']);
  2227. if (!file_exists($filePath)) {
  2228. return abort(404, '文件不存在或已被删除。');
  2229. }
  2230. if (intval(Session::get('filesDownload:' . $fileDetail['id'])) !== 1) {
  2231. Session::put('filesDownload:' . $fileDetail['id'], 1);
  2232. DB::table('project_files')->where('id', $fileDetail['id'])->increment('download');
  2233. }
  2234. return response()->download($filePath, $fileDetail['name']);
  2235. }
  2236. /**
  2237. * 项目文件-重命名
  2238. *
  2239. * @apiParam {Number} fileid 文件ID
  2240. * @apiParam {String} name 新文件名称
  2241. */
  2242. public function files__rename()
  2243. {
  2244. $user = Users::authE();
  2245. if (Base::isError($user)) {
  2246. return $user;
  2247. } else {
  2248. $user = $user['data'];
  2249. }
  2250. //
  2251. $fileDetail = Base::DBC2A(DB::table('project_files')->where('id', intval(Request::input('fileid')))->where('delete', 0)->first());
  2252. if (empty($fileDetail)) {
  2253. return Base::retError('文件不存在或已被删除!');
  2254. }
  2255. if ($fileDetail['username'] != $user['username']) {
  2256. $inRes = Project::inThe($fileDetail['projectid'], $user['username'], true);
  2257. if (Base::isError($inRes)) {
  2258. return Base::retError('此操作仅支持管理员或上传者!');
  2259. }
  2260. }
  2261. //
  2262. $name = Base::rightDelete(trim(Request::input('name')), '.' . $fileDetail['ext']);
  2263. if (empty($name)) {
  2264. return Base::retError('文件名称不能为空!');
  2265. } elseif (mb_strlen($name) > 32) {
  2266. return Base::retError('文件名称最多只能设置32个字!');
  2267. }
  2268. //
  2269. $name .= '.' . $fileDetail['ext'];
  2270. if (DB::table('project_files')->where('id', $fileDetail['id'])->update([ 'name' => $name ])) {
  2271. DB::table('project_log')->insert([
  2272. 'type' => '日志',
  2273. 'projectid' => $fileDetail['projectid'],
  2274. 'taskid' => $fileDetail['taskid'],
  2275. 'username' => $user['username'],
  2276. 'detail' => '文件【' . $fileDetail['name'] . '】重命名',
  2277. 'indate' => Base::time(),
  2278. 'other' => Base::array2string([
  2279. 'type' => 'file',
  2280. 'id' => $fileDetail['id'],
  2281. 'name' => $name,
  2282. ])
  2283. ]);
  2284. }
  2285. //
  2286. return Base::retSuccess('修改成功!', [
  2287. 'name' => $name,
  2288. ]);
  2289. }
  2290. /**
  2291. * 项目文件-删除
  2292. *
  2293. * @apiParam {Number} fileid 文件ID
  2294. */
  2295. public function files__delete()
  2296. {
  2297. $user = Users::authE();
  2298. if (Base::isError($user)) {
  2299. return $user;
  2300. } else {
  2301. $user = $user['data'];
  2302. }
  2303. //
  2304. $fileDetail = Base::DBC2A(DB::table('project_files')->where('id', intval(Request::input('fileid')))->where('delete', 0)->first());
  2305. if (empty($fileDetail)) {
  2306. return Base::retError('文件不存在或已被删除!');
  2307. }
  2308. if ($fileDetail['username'] != $user['username']) {
  2309. $inRes = Project::inThe($fileDetail['projectid'], $user['username'], true);
  2310. if (Base::isError($inRes)) {
  2311. return Base::retError('此操作仅支持管理员或上传者!');
  2312. }
  2313. }
  2314. //
  2315. DB::table('project_files')->where('id', $fileDetail['id'])->update([
  2316. 'delete' => 1,
  2317. 'deletedate' => Base::time()
  2318. ]);
  2319. DB::table('project_log')->insert([
  2320. 'type' => '日志',
  2321. 'projectid' => $fileDetail['projectid'],
  2322. 'taskid' => $fileDetail['taskid'],
  2323. 'username' => $user['username'],
  2324. 'detail' => '删除文件',
  2325. 'indate' => Base::time(),
  2326. 'other' => Base::array2string([
  2327. 'type' => 'file',
  2328. 'id' => $fileDetail['id'],
  2329. 'name' => $fileDetail['name'],
  2330. ])
  2331. ]);
  2332. if ($fileDetail['taskid'] > 0) {
  2333. DB::table('project_task')->where('id', $fileDetail['taskid'])->decrement('filenum');
  2334. }
  2335. //
  2336. return Base::retSuccess('删除成功!');
  2337. }
  2338. /**
  2339. * 项目动态-列表
  2340. *
  2341. * @apiParam {Number} [projectid] 项目ID
  2342. * @apiParam {Number} [taskid] 任务ID(如果项目ID为空时此参必须赋值且任务必须是自己负责人)
  2343. * @apiParam {String} [type] 类型
  2344. * - 全部: 日志+评论(默认)
  2345. * - 日志
  2346. * - 评论
  2347. * @apiParam {String} [username] 用户名
  2348. * @apiParam {Number} [page] 当前页,默认:1
  2349. * @apiParam {Number} [pagesize] 每页显示数量,默认:20,最大:100
  2350. */
  2351. public function log__lists()
  2352. {
  2353. $user = Users::authE();
  2354. if (Base::isError($user)) {
  2355. return $user;
  2356. } else {
  2357. $user = $user['data'];
  2358. }
  2359. //
  2360. $projectid = intval(Request::input('projectid'));
  2361. if ($projectid > 0) {
  2362. $inRes = Project::inThe($projectid, $user['username']);
  2363. if (Base::isError($inRes)) {
  2364. return $inRes;
  2365. }
  2366. }
  2367. //
  2368. $taskid = intval(Request::input('taskid'));
  2369. $whereArray = [];
  2370. $whereFunc = null;
  2371. if ($projectid > 0) {
  2372. $whereArray[] = ['projectid', '=', $projectid];
  2373. if ($taskid > 0) {
  2374. $whereArray[] = ['taskid', '=', $taskid];
  2375. }
  2376. } else {
  2377. if ($taskid < 0) {
  2378. return Base::retError('参数错误!');
  2379. }
  2380. $count = DB::table('project_task')->where([ 'id' => $taskid, 'username' => $user['username']])->count();
  2381. if ($count <= 0) {
  2382. return Base::retError('你不是任务负责人!');
  2383. }
  2384. $whereArray[] = ['taskid', '=', $taskid];
  2385. }
  2386. if (trim(Request::input('username'))) {
  2387. $whereArray[] = ['username', '=', trim(Request::input('username'))];
  2388. }
  2389. switch (trim(Request::input('type'))) {
  2390. case '日志': {
  2391. $whereArray[] = ['type', '=', '日志'];
  2392. break;
  2393. }
  2394. case '评论': {
  2395. $whereArray[] = ['type', '=', '评论'];
  2396. break;
  2397. }
  2398. default: {
  2399. $whereFunc = function ($query) {
  2400. $query->whereIn('type', ['日志', '评论']);
  2401. };
  2402. break;
  2403. }
  2404. }
  2405. //
  2406. $lists = DB::table('project_log')
  2407. ->where($whereArray)
  2408. ->where($whereFunc)
  2409. ->orderByDesc('indate')->paginate(Base::getPaginate(100, 20));
  2410. $lists = Base::getPageList($lists);
  2411. if ($lists['total'] == 0) {
  2412. return Base::retError('未找到任何相关的记录', $lists);
  2413. }
  2414. foreach ($lists['lists'] AS $key => $item) {
  2415. $item = array_merge($item, Users::username2basic($item['username']));
  2416. $item['timeData'] = [
  2417. 'ymd' => date(date("Y", $item['indate']) == date("Y", Base::time()) ? "m-d" : "Y-m-d", $item['indate']),
  2418. 'hi' => date("h:i", $item['indate']) ,
  2419. 'week' => "周" . Base::getTimeWeek($item['indate']),
  2420. 'segment' => Base::getTimeDayeSegment($item['indate']),
  2421. ];
  2422. $item['other'] = Base::string2array($item['other'], ['type' => '']);
  2423. $lists['lists'][$key] = $item;
  2424. }
  2425. return Base::retSuccess('success', $lists);
  2426. }
  2427. }