ProjectController.php 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463
  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(Min(Max(Base::nullShow(Request::input('pagesize'), 10), 1), 100));
  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(Min(Max(Base::nullShow(Request::input('pagesize'), 10), 1), 100));
  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(Min(Max(Base::nullShow(Request::input('pagesize'), 10), 1), 100));
  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. *
  1300. * @throws \Throwable
  1301. */
  1302. public function task__add()
  1303. {
  1304. $user = Users::authE();
  1305. if (Base::isError($user)) {
  1306. return $user;
  1307. } else {
  1308. $user = $user['data'];
  1309. }
  1310. //
  1311. $projectid = intval(Request::input('projectid'));
  1312. $labelid = intval(Request::input('labelid'));
  1313. if ($projectid > 0) {
  1314. $projectDetail = Base::DBC2A(DB::table('project_lists')->where('id', $projectid)->where('delete', 0)->first());
  1315. if (empty($projectDetail)) {
  1316. return Base::retError('项目不存在或已被删除!');
  1317. }
  1318. //
  1319. $labelDetail = Base::DBC2A(DB::table('project_label')->where('id', $labelid)->where('projectid', $projectid)->first());
  1320. if (empty($labelDetail)) {
  1321. return Base::retError('项目子分类不存在或已被删除!');
  1322. }
  1323. //
  1324. $inRes = Project::inThe($projectid, $user['username']);
  1325. if (Base::isError($inRes)) {
  1326. return $inRes;
  1327. }
  1328. $checkRole = Project::role('add_role', $projectid, 0);
  1329. if (Base::isError($checkRole)) {
  1330. return $checkRole;
  1331. }
  1332. //
  1333. $username = trim(Request::input('username'));
  1334. if (empty($username)) {
  1335. $username = $user['username'];
  1336. }
  1337. if ($username != $user['username']) {
  1338. $inRes = Project::inThe($projectid, $username);
  1339. if (Base::isError($inRes)) {
  1340. return Base::retError('负责人不在项目成员内!');
  1341. }
  1342. }
  1343. } else {
  1344. $username = $user['username'];
  1345. }
  1346. //
  1347. $title = trim(Request::input('title'));
  1348. if (empty($title)) {
  1349. return Base::retError('任务标题不能为空!');
  1350. } elseif (mb_strlen($title) > 255) {
  1351. return Base::retError('任务标题最多只能设置255个字!');
  1352. }
  1353. //
  1354. $level = max(1, min(4, intval(Request::input('level'))));
  1355. $inArray = [
  1356. 'projectid' => $projectid,
  1357. 'labelid' => $labelid,
  1358. 'createuser' => $user['username'],
  1359. 'username' => $username,
  1360. 'title' => $title,
  1361. 'level' => $level,
  1362. 'inorder' => empty($projectid) ? 0 : intval(DB::table('project_task')->where('projectid', $projectid)->orderByDesc('inorder')->value('inorder')) + 1,
  1363. 'userorder' => intval(DB::table('project_task')->where('username', $user['username'])->where('level', $level)->orderByDesc('userorder')->value('userorder')) + 1,
  1364. 'indate' => Base::time(),
  1365. 'startdate' => Base::time(),
  1366. 'subtask' => Base::array2string([]),
  1367. 'follower' => Base::array2string([]),
  1368. ];
  1369. return DB::transaction(function () use ($inArray) {
  1370. $taskid = DB::table('project_task')->insertGetId($inArray);
  1371. if (empty($taskid)) {
  1372. return Base::retError('系统繁忙,请稍后再试!');
  1373. }
  1374. DB::table('project_log')->insert([
  1375. 'type' => '日志',
  1376. 'projectid' => $inArray['projectid'],
  1377. 'taskid' => $taskid,
  1378. 'username' => $inArray['createuser'],
  1379. 'detail' => '添加任务',
  1380. 'indate' => Base::time(),
  1381. 'other' => Base::array2string([
  1382. 'type' => 'task',
  1383. 'id' => $taskid,
  1384. 'title' => $inArray['title'],
  1385. ])
  1386. ]);
  1387. Project::updateNum($inArray['projectid']);
  1388. //
  1389. $task = Base::DBC2A(DB::table('project_task')->where('id', $taskid)->first());
  1390. $task['overdue'] = Project::taskIsOverdue($task);
  1391. $task['subtask'] = Base::string2array($task['subtask']);
  1392. $task['follower'] = Base::string2array($task['follower']);
  1393. $task = array_merge($task, Users::username2basic($task['username']));
  1394. return Base::retSuccess('添加成功!', $task);
  1395. });
  1396. }
  1397. /**
  1398. * 项目任务-修改
  1399. *
  1400. * @apiParam {Number} taskid 任务ID
  1401. * @apiParam {String} act 修改字段|操作类型
  1402. * - title: 标题
  1403. * - desc: 描述
  1404. * - level: 优先级
  1405. * - username: 负责人
  1406. * - plannedtime: 设置计划时间
  1407. * - unplannedtime: 取消计划时间
  1408. * - complete: 标记完成
  1409. * - unfinished: 标记未完成
  1410. * - archived: 归档
  1411. * - unarchived: 取消归档
  1412. * - delete: 删除任务
  1413. * - comment: 评论
  1414. * - attention: 添加关注
  1415. * - subtask: 修改子任务
  1416. * @apiParam {String} [content] 内容数据
  1417. *
  1418. * @throws \Throwable
  1419. */
  1420. public function task__edit()
  1421. {
  1422. $user = Users::authE();
  1423. if (Base::isError($user)) {
  1424. return $user;
  1425. } else {
  1426. $user = $user['data'];
  1427. }
  1428. //
  1429. $act = trim(Request::input('act'));
  1430. $taskid = intval(Request::input('taskid'));
  1431. $task = Base::DBC2A(DB::table('project_task')
  1432. ->where([
  1433. ['delete', '=', 0],
  1434. ['id', '=', $taskid],
  1435. ])
  1436. ->first());
  1437. if (empty($task)) {
  1438. return Base::retError('任务不存在!');
  1439. }
  1440. if ($task['projectid'] > 0) {
  1441. $inRes = Project::inThe($task['projectid'], $user['username']);
  1442. if (Base::isError($inRes)) {
  1443. return $inRes;
  1444. }
  1445. if (!in_array($act, ['comment', 'attention'])) {
  1446. $checkRole = Project::role('edit_role', $task['projectid'], $task['id']);
  1447. if (Base::isError($checkRole)) {
  1448. return $checkRole;
  1449. }
  1450. switch ($act) {
  1451. case 'complete':
  1452. case 'unfinished':
  1453. $checkRole = Project::role('complete_role', $task['projectid'], $task['id']);
  1454. if (Base::isError($checkRole)) {
  1455. return $checkRole;
  1456. }
  1457. break;
  1458. case 'archived':
  1459. case 'unarchived':
  1460. $checkRole = Project::role('archived_role', $task['projectid'], $task['id']);
  1461. if (Base::isError($checkRole)) {
  1462. return $checkRole;
  1463. }
  1464. break;
  1465. case 'delete':
  1466. $checkRole = Project::role('del_role', $task['projectid'], $task['id']);
  1467. if (Base::isError($checkRole)) {
  1468. return $checkRole;
  1469. }
  1470. break;
  1471. }
  1472. }
  1473. } else {
  1474. if ($task['username'] != $user['username']) {
  1475. return Base::retError('此操作只允许任务负责人!');
  1476. }
  1477. }
  1478. //
  1479. $content = Base::newTrim(Request::input('content'));
  1480. $message = "";
  1481. $upArray = [];
  1482. $logArray = [];
  1483. switch ($act) {
  1484. /**
  1485. * 修改标题
  1486. */
  1487. case 'title': {
  1488. if ($content == $task['title']) {
  1489. return Base::retError('标题未做改变!');
  1490. }
  1491. $upArray['title'] = $content;
  1492. $logArray[] = [
  1493. 'type' => '日志',
  1494. 'projectid' => $task['projectid'],
  1495. 'taskid' => $task['id'],
  1496. 'username' => $user['username'],
  1497. 'detail' => '修改任务标题',
  1498. 'indate' => Base::time(),
  1499. 'other' => Base::array2string([
  1500. 'type' => 'task',
  1501. 'id' => $task['id'],
  1502. 'title' => $content,
  1503. 'old_title' => $task['title'],
  1504. ])
  1505. ];
  1506. break;
  1507. }
  1508. /**
  1509. * 修改描述
  1510. */
  1511. case 'desc': {
  1512. if ($content == $task['desc']) {
  1513. return Base::retError('描述未做改变!');
  1514. }
  1515. $upArray['desc'] = $content;
  1516. $logArray[] = [
  1517. 'type' => '日志',
  1518. 'projectid' => $task['projectid'],
  1519. 'taskid' => $task['id'],
  1520. 'username' => $user['username'],
  1521. 'detail' => '修改任务描述',
  1522. 'indate' => Base::time(),
  1523. 'other' => Base::array2string([
  1524. 'type' => 'task',
  1525. 'id' => $task['id'],
  1526. 'title' => $task['title'],
  1527. 'old_desc' => $task['desc'],
  1528. ])
  1529. ];
  1530. break;
  1531. }
  1532. /**
  1533. * 调整任务等级
  1534. */
  1535. case 'level': {
  1536. $content = intval($content);
  1537. if ($content == $task['level']) {
  1538. return Base::retError('优先级未做改变!');
  1539. }
  1540. if ($content > 4 || $content < 1) {
  1541. return Base::retError('优先级参数错误!');
  1542. }
  1543. $upArray['level'] = $content;
  1544. $logArray[] = [
  1545. 'type' => '日志',
  1546. 'projectid' => $task['projectid'],
  1547. 'taskid' => $task['id'],
  1548. 'username' => $user['username'],
  1549. 'detail' => '调整任务等级为【P' . $content . '】',
  1550. 'indate' => Base::time(),
  1551. 'other' => Base::array2string([
  1552. 'type' => 'task',
  1553. 'id' => $task['id'],
  1554. 'title' => $task['title'],
  1555. 'old_level' => $task['level'],
  1556. ])
  1557. ];
  1558. break;
  1559. }
  1560. /**
  1561. * 修改任务负责人
  1562. */
  1563. case 'username': {
  1564. if ($content == $task['username']) {
  1565. return Base::retError('负责人未做改变!');
  1566. }
  1567. if ($task['projectid'] > 0) {
  1568. $inRes = Project::inThe($task['projectid'], $content);
  1569. if (Base::isError($inRes)) {
  1570. return Base::retError(['%不在成员列表内!', $content]);
  1571. }
  1572. }
  1573. $upArray['username'] = $content;
  1574. $logArray[] = [
  1575. 'type' => '日志',
  1576. 'projectid' => $task['projectid'],
  1577. 'taskid' => $task['id'],
  1578. 'username' => $user['username'],
  1579. 'detail' => '修改负责人',
  1580. 'indate' => Base::time(),
  1581. 'other' => Base::array2string([
  1582. 'type' => 'task',
  1583. 'id' => $task['id'],
  1584. 'title' => $task['title'],
  1585. 'old_username' => $task['username'],
  1586. ])
  1587. ];
  1588. break;
  1589. }
  1590. /**
  1591. * 修改计划时间
  1592. */
  1593. case 'plannedtime': {
  1594. list($startdate, $enddate) = explode(",", $content);
  1595. if (!Base::isDate($startdate) || !Base::isDate($enddate)) {
  1596. return Base::retError('计划时间参数错误!');
  1597. }
  1598. $startdate = strtotime($startdate);
  1599. $enddate = strtotime($enddate);
  1600. if ($startdate == $task['startdate'] && $enddate == $task['enddate']) {
  1601. return Base::retError('与原计划时间一致!');
  1602. }
  1603. if ($startdate == $enddate) {
  1604. return Base::retError('开始时间与结束时间一致!');
  1605. }
  1606. $upArray['startdate'] = $startdate;
  1607. $upArray['enddate'] = $enddate;
  1608. $logArray[] = [
  1609. 'type' => '日志',
  1610. 'projectid' => $task['projectid'],
  1611. 'taskid' => $task['id'],
  1612. 'username' => $user['username'],
  1613. 'detail' => '设置计划时间',
  1614. 'indate' => Base::time(),
  1615. 'other' => Base::array2string([
  1616. 'type' => 'task',
  1617. 'id' => $task['id'],
  1618. 'title' => $task['title'],
  1619. 'old_startdate' => $task['startdate'],
  1620. 'old_enddate' => $task['enddate'],
  1621. ])
  1622. ];
  1623. break;
  1624. }
  1625. /**
  1626. * 取消计划时间
  1627. */
  1628. case 'unplannedtime': {
  1629. $startdate = 0;
  1630. $enddate = 0;
  1631. if ($startdate == $task['startdate'] && $enddate == $task['enddate']) {
  1632. return Base::retError('与原计划时间一致!');
  1633. }
  1634. $upArray['startdate'] = $startdate;
  1635. $upArray['enddate'] = $enddate;
  1636. $logArray[] = [
  1637. 'type' => '日志',
  1638. 'projectid' => $task['projectid'],
  1639. 'taskid' => $task['id'],
  1640. 'username' => $user['username'],
  1641. 'detail' => '取消计划时间',
  1642. 'indate' => Base::time(),
  1643. 'other' => Base::array2string([
  1644. 'type' => 'task',
  1645. 'id' => $task['id'],
  1646. 'title' => $task['title'],
  1647. 'old_startdate' => $task['startdate'],
  1648. 'old_enddate' => $task['enddate'],
  1649. ])
  1650. ];
  1651. break;
  1652. }
  1653. /**
  1654. * 标记完成
  1655. */
  1656. case 'complete': {
  1657. if ($task['complete'] == 1) {
  1658. return Base::retError('任务已标记完成,请勿重复操作!');
  1659. }
  1660. $upArray['complete'] = 1;
  1661. $upArray['completedate'] = Base::time();
  1662. $logArray[] = [
  1663. 'type' => '日志',
  1664. 'projectid' => $task['projectid'],
  1665. 'taskid' => $task['id'],
  1666. 'username' => $user['username'],
  1667. 'detail' => '标记已完成',
  1668. 'indate' => Base::time(),
  1669. 'other' => Base::array2string([
  1670. 'type' => 'task',
  1671. 'id' => $task['id'],
  1672. 'title' => $task['title'],
  1673. ])
  1674. ];
  1675. break;
  1676. }
  1677. /**
  1678. * 标记未完成
  1679. */
  1680. case 'unfinished': {
  1681. if ($task['complete'] == 0) {
  1682. return Base::retError('任务未完成,无法标记未完成!');
  1683. }
  1684. $upArray['complete'] = 0;
  1685. $logArray[] = [
  1686. 'type' => '日志',
  1687. 'projectid' => $task['projectid'],
  1688. 'taskid' => $task['id'],
  1689. 'username' => $user['username'],
  1690. 'detail' => '标记未完成',
  1691. 'indate' => Base::time(),
  1692. 'other' => Base::array2string([
  1693. 'type' => 'task',
  1694. 'id' => $task['id'],
  1695. 'title' => $task['title'],
  1696. ])
  1697. ];
  1698. break;
  1699. }
  1700. /**
  1701. * 归档
  1702. */
  1703. case 'archived': {
  1704. if ($task['archived'] == 1) {
  1705. return Base::retError('任务已经归档,请勿重复操作!');
  1706. }
  1707. $upArray['archived'] = 1;
  1708. $upArray['archiveddate'] = Base::time();
  1709. $logArray[] = [
  1710. 'type' => '日志',
  1711. 'projectid' => $task['projectid'],
  1712. 'taskid' => $task['id'],
  1713. 'username' => $user['username'],
  1714. 'detail' => '任务归档',
  1715. 'indate' => Base::time(),
  1716. 'other' => Base::array2string([
  1717. 'type' => 'task',
  1718. 'id' => $task['id'],
  1719. 'title' => $task['title'],
  1720. ])
  1721. ];
  1722. break;
  1723. }
  1724. /**
  1725. * 取消归档
  1726. */
  1727. case 'unarchived': {
  1728. if ($task['archived'] == 0) {
  1729. return Base::retError('任务未归档,无法取消归档操作!');
  1730. }
  1731. $upArray['archived'] = 0;
  1732. $logArray[] = [
  1733. 'type' => '日志',
  1734. 'projectid' => $task['projectid'],
  1735. 'taskid' => $task['id'],
  1736. 'username' => $user['username'],
  1737. 'detail' => '取消归档',
  1738. 'indate' => Base::time(),
  1739. 'other' => Base::array2string([
  1740. 'type' => 'task',
  1741. 'id' => $task['id'],
  1742. 'title' => $task['title'],
  1743. ])
  1744. ];
  1745. break;
  1746. }
  1747. /**
  1748. * 删除任务
  1749. */
  1750. case 'delete': {
  1751. if ($task['delete'] == 1) {
  1752. return Base::retError('任务已删除,请勿重复操作!');
  1753. }
  1754. $upArray['delete'] = 1;
  1755. $upArray['deletedate'] = Base::time();
  1756. $logArray[] = [
  1757. 'type' => '日志',
  1758. 'projectid' => $task['projectid'],
  1759. 'taskid' => $task['id'],
  1760. 'username' => $user['username'],
  1761. 'detail' => '删除任务',
  1762. 'indate' => Base::time(),
  1763. 'other' => Base::array2string([
  1764. 'type' => 'task',
  1765. 'id' => $task['id'],
  1766. 'title' => $task['title'],
  1767. ])
  1768. ];
  1769. $message = "删除成功!";
  1770. break;
  1771. }
  1772. /**
  1773. * 评论任务
  1774. */
  1775. case 'comment': {
  1776. if (mb_strlen($content) < 2) {
  1777. return Base::retError('评论内容至少2个字!');
  1778. }
  1779. $logArray[] = [
  1780. 'type' => '评论',
  1781. 'projectid' => $task['projectid'],
  1782. 'taskid' => $task['id'],
  1783. 'username' => $user['username'],
  1784. 'detail' => $content,
  1785. 'indate' => Base::time(),
  1786. 'other' => Base::array2string([
  1787. 'type' => 'task',
  1788. 'id' => $task['id'],
  1789. 'title' => $task['title'],
  1790. ])
  1791. ];
  1792. $message = "评论成功!";
  1793. break;
  1794. }
  1795. /**
  1796. * 添加关注
  1797. */
  1798. case 'attention': {
  1799. $userArray = explode(",", $content);
  1800. DB::transaction(function () use ($user, $task, $userArray) {
  1801. foreach ($userArray AS $uname) {
  1802. $uid = Users::username2id($uname);
  1803. if (empty($uid)) {
  1804. continue;
  1805. }
  1806. $row = Base::DBC2A(DB::table('project_users')->where([
  1807. 'type' => '关注',
  1808. 'taskid' => $task['id'],
  1809. 'username' => $uname,
  1810. ])->lockForUpdate()->first());
  1811. if (empty($row)) {
  1812. DB::table('project_users')->insert([
  1813. 'type' => '关注',
  1814. 'projectid' => $task['projectid'],
  1815. 'taskid' => $task['id'],
  1816. 'isowner' => $task['username'] == $uname ? 1 : 0,
  1817. 'username' => $uname,
  1818. 'indate' => Base::time()
  1819. ]);
  1820. DB::table('project_log')->insert([
  1821. 'type' => '日志',
  1822. 'projectid' => $task['projectid'],
  1823. 'taskid' => $task['id'],
  1824. 'username' => $uname,
  1825. 'detail' => $uname == $user['username'] ? '关注任务' : '加入关注',
  1826. 'indate' => Base::time(),
  1827. 'other' => Base::array2string([
  1828. 'type' => 'task',
  1829. 'id' => $task['id'],
  1830. 'title' => $task['title'],
  1831. 'operator' => $user['username'],
  1832. 'action' => 'attention',
  1833. ])
  1834. ]);
  1835. }
  1836. }
  1837. });
  1838. $tempRow = Base::DBC2A(DB::table('project_users')->select(['username'])->where([ 'type' => '关注', 'taskid' => $task['id'] ])->get()->pluck('username'));
  1839. $upArray['follower'] = Base::array2string($tempRow);
  1840. $message = "保存成功!";
  1841. break;
  1842. }
  1843. /**
  1844. * 取消关注
  1845. */
  1846. case 'unattention': {
  1847. $userArray = explode(",", $content);
  1848. DB::transaction(function () use ($user, $task, $userArray) {
  1849. foreach ($userArray AS $uname) {
  1850. if (DB::table('project_users')->where([
  1851. 'type' => '关注',
  1852. 'taskid' => $task['id'],
  1853. 'username' => $uname,
  1854. ])->delete()) {
  1855. DB::table('project_log')->insert([
  1856. 'type' => '日志',
  1857. 'projectid' => $task['projectid'],
  1858. 'taskid' => $task['id'],
  1859. 'username' => $uname,
  1860. 'detail' => $uname == $user['username'] ? '取消关注' : '移出关注',
  1861. 'indate' => Base::time(),
  1862. 'other' => Base::array2string([
  1863. 'type' => 'task',
  1864. 'id' => $task['id'],
  1865. 'title' => $task['title'],
  1866. 'operator' => $user['username'],
  1867. 'action' => 'unattention',
  1868. ])
  1869. ]);
  1870. }
  1871. }
  1872. });
  1873. $tempRow = Base::DBC2A(DB::table('project_users')->select(['username'])->where([ 'type' => '关注', 'taskid' => $task['id'] ])->get()->pluck('username'));
  1874. $upArray['follower'] = Base::array2string($tempRow);
  1875. $message = "保存成功!";
  1876. break;
  1877. }
  1878. /**
  1879. * 修改子任务
  1880. */
  1881. case 'subtask': {
  1882. if (!is_array($content)) {
  1883. return Base::retError('参数错误!');
  1884. }
  1885. $content = Base::array2string($content);
  1886. if ($content == $task['subtask']) {
  1887. return Base::retError('子任务未做改变!');
  1888. }
  1889. $upArray['subtask'] = $content;
  1890. //
  1891. $detail = '修改子任务';
  1892. $subtype = 'modify';
  1893. $new_count = count(Base::string2array($content));
  1894. $old_count = count(Base::string2array($task['subtask']));
  1895. if ($new_count > $old_count) {
  1896. $detail = '添加子任务';
  1897. $subtype = 'add';
  1898. } elseif ($new_count < $old_count) {
  1899. $detail = '删除子任务';
  1900. $subtype = 'del';
  1901. }
  1902. //
  1903. $logArray[] = [
  1904. 'type' => '日志',
  1905. 'projectid' => $task['projectid'],
  1906. 'taskid' => $task['id'],
  1907. 'username' => $user['username'],
  1908. 'detail' => $detail,
  1909. 'indate' => Base::time(),
  1910. 'other' => Base::array2string([
  1911. 'type' => 'task',
  1912. 'subtype' => $subtype,
  1913. 'id' => $task['id'],
  1914. 'subtask' => $content,
  1915. 'old_subtask' => $task['subtask'],
  1916. ])
  1917. ];
  1918. break;
  1919. }
  1920. default: {
  1921. return Base::retError('参数错误!');
  1922. break;
  1923. }
  1924. }
  1925. //
  1926. if ($upArray) {
  1927. DB::table('project_task')->where('id', $taskid)->update($upArray);
  1928. }
  1929. if ($logArray) {
  1930. DB::table('project_log')->insert($logArray);
  1931. }
  1932. //
  1933. if (in_array($act, ['complete', 'unfinished'])) {
  1934. Project::updateNum($task['projectid']);
  1935. }
  1936. //
  1937. $task = array_merge($task, $upArray);
  1938. $task['overdue'] = Project::taskIsOverdue($task);
  1939. $task['subtask'] = Base::string2array($task['subtask']);
  1940. $task['follower'] = Base::string2array($task['follower']);
  1941. $task['projectTitle'] = $task['projectid'] > 0 ? DB::table('project_lists')->where('id', $task['projectid'])->value('title') : '';
  1942. $task = array_merge($task, Users::username2basic($task['username']));
  1943. return Base::retSuccess($message ?: '修改成功!', $task);
  1944. }
  1945. /**
  1946. * 项目任务-待推送日志
  1947. *
  1948. * @apiParam {Number} taskid 任务ID
  1949. * @apiParam {Number} [page] 当前页,默认:1
  1950. * @apiParam {Number} [pagesize] 每页显示数量,默认:20,最大:100
  1951. * @throws \Throwable
  1952. */
  1953. public function task__pushlog()
  1954. {
  1955. $user = Users::authE();
  1956. if (Base::isError($user)) {
  1957. return $user;
  1958. } else {
  1959. $user = $user['data'];
  1960. }
  1961. //
  1962. return DB::transaction(function () {
  1963. $taskid = intval(Request::input('taskid'));
  1964. $task = Base::DBC2A(DB::table('project_task')
  1965. ->select(['pushlid', 'follower', 'username'])
  1966. ->where([
  1967. ['delete', '=', 0],
  1968. ['id', '=', $taskid],
  1969. ])
  1970. ->lockForUpdate()
  1971. ->first());
  1972. if (empty($task)) {
  1973. return Base::retError('任务不存在!');
  1974. }
  1975. $task['follower'] = Base::string2array($task['follower']);
  1976. $task['follower'][] = $task['username'];
  1977. //
  1978. $pushlid = $task['pushlid'];
  1979. $lists = DB::table('project_log')
  1980. ->select(['id', 'username', 'indate', 'detail', 'other'])
  1981. ->where([
  1982. ['id', '>', $pushlid],
  1983. ['taskid', '=', $taskid],
  1984. ['indate', '>', Base::time() - 60]
  1985. ])
  1986. ->orderBy('id')->paginate(Min(Max(Base::nullShow(Request::input('pagesize'), 10), 1), 100));
  1987. $lists = Base::getPageList($lists, false);
  1988. if (count($lists['lists']) == 0) {
  1989. return Base::retError('no lists');
  1990. }
  1991. $array = [];
  1992. foreach ($lists['lists'] AS $key => $item) {
  1993. $item = array_merge($item, Users::username2basic($item['username']));
  1994. $item['other'] = Base::string2array($item['other'], ['type' => '']);
  1995. if (!in_array($item['other']['action'], ['attention', 'unattention'])) {
  1996. $array[] = $item;
  1997. }
  1998. $pushlid = $item['id'];
  1999. }
  2000. $lists['lists'] = $array;
  2001. if ($pushlid != $task['pushlid']) {
  2002. DB::table('project_task')->where('id', $taskid)->update([
  2003. 'pushlid' => $pushlid
  2004. ]);
  2005. }
  2006. return Base::retSuccess('success', array_merge($lists, $task));
  2007. });
  2008. }
  2009. /**
  2010. * 项目文件-列表
  2011. *
  2012. * @apiParam {Number} [projectid] 项目ID
  2013. * @apiParam {Number} [taskid] 任务ID(如果项目ID为空时此参必须赋值且任务必须是自己负责人或在任务所在的项目里)
  2014. * @apiParam {String} [name] 文件名称
  2015. * @apiParam {String} [username] 上传者用户名
  2016. * @apiParam {Object} [sorts] 排序方式,格式:{key:'', order:''}
  2017. * - key: name|size|username|indate
  2018. * - order: asc|desc
  2019. * @apiParam {Number} [page] 当前页,默认:1
  2020. * @apiParam {Number} [pagesize] 每页显示数量,默认:20,最大:100
  2021. */
  2022. public function files__lists()
  2023. {
  2024. $user = Users::authE();
  2025. if (Base::isError($user)) {
  2026. return $user;
  2027. } else {
  2028. $user = $user['data'];
  2029. }
  2030. //
  2031. $taskid = intval(Request::input('taskid'));
  2032. if ($taskid > 0) {
  2033. $projectid = intval(DB::table('project_task')->select(['projectid'])->where([ 'id' => $taskid])->value('projectid'));
  2034. } else {
  2035. $projectid = intval(Request::input('projectid'));
  2036. }
  2037. if ($projectid > 0) {
  2038. $inRes = Project::inThe($projectid, $user['username']);
  2039. if (Base::isError($inRes)) {
  2040. return $inRes;
  2041. }
  2042. }
  2043. //
  2044. $orderBy = '`id` DESC';
  2045. $sorts = Base::json2array(Request::input('sorts'));
  2046. if (in_array($sorts['order'], ['asc', 'desc'])) {
  2047. switch ($sorts['key']) {
  2048. case 'name':
  2049. case 'size':
  2050. case 'download':
  2051. case 'username':
  2052. case 'indate':
  2053. $orderBy = '`' . $sorts['key'] . '` ' . $sorts['order'] . ',`id` DESC';
  2054. break;
  2055. }
  2056. }
  2057. //
  2058. $whereArray = [];
  2059. if ($projectid > 0) {
  2060. $whereArray[] = ['projectid', '=', $projectid];
  2061. if ($taskid > 0) {
  2062. $whereArray[] = ['taskid', '=', $taskid];
  2063. }
  2064. } else {
  2065. if ($taskid <= 0) {
  2066. return Base::retError('参数错误!');
  2067. }
  2068. $count = DB::table('project_task')->where([ 'id' => $taskid, 'username' => $user['username']])->count();
  2069. if ($count <= 0) {
  2070. return Base::retError('你不是任务负责人!');
  2071. }
  2072. $whereArray[] = ['taskid', '=', $taskid];
  2073. }
  2074. $whereArray[] = ['delete', '=', 0];
  2075. if (intval(Request::input('taskid')) > 0) {
  2076. $whereArray[] = ['taskid', '=', intval(Request::input('taskid'))];
  2077. }
  2078. if (trim(Request::input('name'))) {
  2079. $whereArray[] = ['name', 'like', '%' . trim(Request::input('name')) . '%'];
  2080. }
  2081. if (trim(Request::input('username'))) {
  2082. $whereArray[] = ['username', '=', trim(Request::input('username'))];
  2083. }
  2084. //
  2085. $lists = DB::table('project_files')
  2086. ->where($whereArray)
  2087. ->orderByRaw($orderBy)->paginate(Min(Max(Base::nullShow(Request::input('pagesize'), 10), 1), 100));
  2088. $lists = Base::getPageList($lists);
  2089. if ($lists['total'] == 0) {
  2090. return Base::retError('未找到任何相关的文件', $lists);
  2091. }
  2092. foreach ($lists['lists'] AS $key => $item) {
  2093. $lists['lists'][$key]['path'] = Base::fillUrl($item['path']);
  2094. $lists['lists'][$key]['thumb'] = Base::fillUrl($item['thumb']);
  2095. $lists['lists'][$key]['yetdown'] = intval(Session::get('filesDownload:' . $item['id']));
  2096. }
  2097. return Base::retSuccess('success', $lists);
  2098. }
  2099. /**
  2100. * 项目文件-上传
  2101. *
  2102. * @apiParam {Number} [projectid] 项目ID
  2103. * @apiParam {Number} [taskid] 任务ID(如果项目ID为空时此参必须赋值且任务必须是自己负责人)
  2104. */
  2105. public function files__upload()
  2106. {
  2107. $user = Users::authE();
  2108. if (Base::isError($user)) {
  2109. return $user;
  2110. } else {
  2111. $user = $user['data'];
  2112. }
  2113. //
  2114. $projectid = intval(Request::input('projectid'));
  2115. $taskid = intval(Request::input('taskid'));
  2116. if ($projectid > 0) {
  2117. $inRes = Project::inThe($projectid, $user['username']);
  2118. if (Base::isError($inRes)) {
  2119. return $inRes;
  2120. }
  2121. } else {
  2122. if ($taskid <= 0) {
  2123. return Base::retError('参数错误!');
  2124. }
  2125. $row = Base::DBC2A(DB::table('project_task')->select(['projectid'])->where([ 'id' => $taskid, 'username' => $user['username']])->first());
  2126. if (empty($row)) {
  2127. return Base::retError('你不是任务负责人!');
  2128. }
  2129. $projectid = $row['projectid'];
  2130. }
  2131. //
  2132. $data = Base::upload([
  2133. "file" => Request::file('files'),
  2134. "type" => 'file',
  2135. "path" => "uploads/projects/" . $projectid . "/",
  2136. ]);
  2137. if (Base::isError($data)) {
  2138. return Base::retError($data['msg']);
  2139. } else {
  2140. $fileData = $data['data'];
  2141. $thumb = 'images/files/file.png';
  2142. switch ($fileData['ext']) {
  2143. case "docx":
  2144. $thumb = 'images/files/doc.png';
  2145. break;
  2146. case "xlsx":
  2147. $thumb = 'images/files/xls.png';
  2148. break;
  2149. case "pptx":
  2150. $thumb = 'images/files/ppt.png';
  2151. break;
  2152. case "doc":
  2153. case "xls":
  2154. case "ppt":
  2155. case "txt":
  2156. case "esp":
  2157. case "gif":
  2158. $thumb = 'images/files/' . $fileData['ext'] . '.png';
  2159. break;
  2160. case "jpg":
  2161. case "jpeg":
  2162. case "png":
  2163. if (Base::imgThumb($fileData['file'], $fileData['file'] . "_thumb.jpg", 64, 0)) {
  2164. $thumb = $fileData['path'] . "_thumb.jpg";
  2165. }
  2166. break;
  2167. }
  2168. $array = [
  2169. 'projectid' => $projectid,
  2170. 'taskid' => $taskid,
  2171. 'name' => $fileData['name'],
  2172. 'size' => $fileData['size'] * 1024,
  2173. 'ext' => $fileData['ext'],
  2174. 'path' => $fileData['path'],
  2175. 'thumb' => $thumb,
  2176. 'username' => $user['username'],
  2177. 'indate' => Base::time(),
  2178. ];
  2179. $id = DB::table('project_files')->insertGetId($array);
  2180. $array['id'] = $id;
  2181. $array['path'] = Base::fillUrl($array['path']);
  2182. $array['thumb'] = Base::fillUrl($array['thumb']);
  2183. $array['download'] = 0;
  2184. $array['yetdown'] = 0;
  2185. DB::table('project_log')->insert([
  2186. 'type' => '日志',
  2187. 'projectid' => $projectid,
  2188. 'taskid' => $taskid,
  2189. 'username' => $user['username'],
  2190. 'detail' => '上传文件',
  2191. 'indate' => Base::time(),
  2192. 'other' => Base::array2string([
  2193. 'type' => 'file',
  2194. 'id' => $id,
  2195. 'name' => $fileData['name'],
  2196. ])
  2197. ]);
  2198. if ($taskid > 0) {
  2199. DB::table('project_task')->where('id', $taskid)->increment('filenum');
  2200. }
  2201. return Base::retSuccess('success', $array);
  2202. }
  2203. }
  2204. /**
  2205. * 项目文件-下载
  2206. *
  2207. * @apiParam {Number} fileid 文件ID
  2208. */
  2209. public function files__download()
  2210. {
  2211. $fileDetail = Base::DBC2A(DB::table('project_files')->where('id', intval(Request::input('fileid')))->where('delete', 0)->first());
  2212. if (empty($fileDetail)) {
  2213. return abort(404, '文件不存在或已被删除!');
  2214. }
  2215. $filePath = public_path($fileDetail['path']);
  2216. if (!file_exists($filePath)) {
  2217. return abort(404, '文件不存在或已被删除。');
  2218. }
  2219. if (intval(Session::get('filesDownload:' . $fileDetail['id'])) !== 1) {
  2220. Session::put('filesDownload:' . $fileDetail['id'], 1);
  2221. DB::table('project_files')->where('id', $fileDetail['id'])->increment('download');
  2222. }
  2223. return response()->download($filePath, $fileDetail['name']);
  2224. }
  2225. /**
  2226. * 项目文件-重命名
  2227. *
  2228. * @apiParam {Number} fileid 文件ID
  2229. * @apiParam {String} name 新文件名称
  2230. */
  2231. public function files__rename()
  2232. {
  2233. $user = Users::authE();
  2234. if (Base::isError($user)) {
  2235. return $user;
  2236. } else {
  2237. $user = $user['data'];
  2238. }
  2239. //
  2240. $fileDetail = Base::DBC2A(DB::table('project_files')->where('id', intval(Request::input('fileid')))->where('delete', 0)->first());
  2241. if (empty($fileDetail)) {
  2242. return Base::retError('文件不存在或已被删除!');
  2243. }
  2244. if ($fileDetail['username'] != $user['username']) {
  2245. $inRes = Project::inThe($fileDetail['projectid'], $user['username'], true);
  2246. if (Base::isError($inRes)) {
  2247. return Base::retError('此操作仅支持管理员或上传者!');
  2248. }
  2249. }
  2250. //
  2251. $name = Base::rightDelete(trim(Request::input('name')), '.' . $fileDetail['ext']);
  2252. if (empty($name)) {
  2253. return Base::retError('文件名称不能为空!');
  2254. } elseif (mb_strlen($name) > 32) {
  2255. return Base::retError('文件名称最多只能设置32个字!');
  2256. }
  2257. //
  2258. $name .= '.' . $fileDetail['ext'];
  2259. if (DB::table('project_files')->where('id', $fileDetail['id'])->update([ 'name' => $name ])) {
  2260. DB::table('project_log')->insert([
  2261. 'type' => '日志',
  2262. 'projectid' => $fileDetail['projectid'],
  2263. 'taskid' => $fileDetail['taskid'],
  2264. 'username' => $user['username'],
  2265. 'detail' => '文件【' . $fileDetail['name'] . '】重命名',
  2266. 'indate' => Base::time(),
  2267. 'other' => Base::array2string([
  2268. 'type' => 'file',
  2269. 'id' => $fileDetail['id'],
  2270. 'name' => $name,
  2271. ])
  2272. ]);
  2273. }
  2274. //
  2275. return Base::retSuccess('修改成功!', [
  2276. 'name' => $name,
  2277. ]);
  2278. }
  2279. /**
  2280. * 项目文件-删除
  2281. *
  2282. * @apiParam {Number} fileid 文件ID
  2283. */
  2284. public function files__delete()
  2285. {
  2286. $user = Users::authE();
  2287. if (Base::isError($user)) {
  2288. return $user;
  2289. } else {
  2290. $user = $user['data'];
  2291. }
  2292. //
  2293. $fileDetail = Base::DBC2A(DB::table('project_files')->where('id', intval(Request::input('fileid')))->where('delete', 0)->first());
  2294. if (empty($fileDetail)) {
  2295. return Base::retError('文件不存在或已被删除!');
  2296. }
  2297. if ($fileDetail['username'] != $user['username']) {
  2298. $inRes = Project::inThe($fileDetail['projectid'], $user['username'], true);
  2299. if (Base::isError($inRes)) {
  2300. return Base::retError('此操作仅支持管理员或上传者!');
  2301. }
  2302. }
  2303. //
  2304. DB::table('project_files')->where('id', $fileDetail['id'])->update([
  2305. 'delete' => 1,
  2306. 'deletedate' => Base::time()
  2307. ]);
  2308. DB::table('project_log')->insert([
  2309. 'type' => '日志',
  2310. 'projectid' => $fileDetail['projectid'],
  2311. 'taskid' => $fileDetail['taskid'],
  2312. 'username' => $user['username'],
  2313. 'detail' => '删除文件',
  2314. 'indate' => Base::time(),
  2315. 'other' => Base::array2string([
  2316. 'type' => 'file',
  2317. 'id' => $fileDetail['id'],
  2318. 'name' => $fileDetail['name'],
  2319. ])
  2320. ]);
  2321. if ($fileDetail['taskid'] > 0) {
  2322. DB::table('project_task')->where('id', $fileDetail['taskid'])->decrement('filenum');
  2323. }
  2324. //
  2325. return Base::retSuccess('删除成功!');
  2326. }
  2327. /**
  2328. * 项目动态-列表
  2329. *
  2330. * @apiParam {Number} [projectid] 项目ID
  2331. * @apiParam {Number} [taskid] 任务ID(如果项目ID为空时此参必须赋值且任务必须是自己负责人)
  2332. * @apiParam {String} [type] 类型
  2333. * - 全部: 日志+评论(默认)
  2334. * - 日志
  2335. * - 评论
  2336. * @apiParam {String} [username] 用户名
  2337. * @apiParam {Number} [page] 当前页,默认:1
  2338. * @apiParam {Number} [pagesize] 每页显示数量,默认:20,最大:100
  2339. */
  2340. public function log__lists()
  2341. {
  2342. $user = Users::authE();
  2343. if (Base::isError($user)) {
  2344. return $user;
  2345. } else {
  2346. $user = $user['data'];
  2347. }
  2348. //
  2349. $projectid = intval(Request::input('projectid'));
  2350. if ($projectid > 0) {
  2351. $inRes = Project::inThe($projectid, $user['username']);
  2352. if (Base::isError($inRes)) {
  2353. return $inRes;
  2354. }
  2355. }
  2356. //
  2357. $taskid = intval(Request::input('taskid'));
  2358. $whereArray = [];
  2359. $whereFunc = null;
  2360. if ($projectid > 0) {
  2361. $whereArray[] = ['projectid', '=', $projectid];
  2362. if ($taskid > 0) {
  2363. $whereArray[] = ['taskid', '=', $taskid];
  2364. }
  2365. } else {
  2366. if ($taskid < 0) {
  2367. return Base::retError('参数错误!');
  2368. }
  2369. $count = DB::table('project_task')->where([ 'id' => $taskid, 'username' => $user['username']])->count();
  2370. if ($count <= 0) {
  2371. return Base::retError('你不是任务负责人!');
  2372. }
  2373. $whereArray[] = ['taskid', '=', $taskid];
  2374. }
  2375. if (trim(Request::input('username'))) {
  2376. $whereArray[] = ['username', '=', trim(Request::input('username'))];
  2377. }
  2378. switch (trim(Request::input('type'))) {
  2379. case '日志': {
  2380. $whereArray[] = ['type', '=', '日志'];
  2381. break;
  2382. }
  2383. case '评论': {
  2384. $whereArray[] = ['type', '=', '评论'];
  2385. break;
  2386. }
  2387. default: {
  2388. $whereFunc = function ($query) {
  2389. $query->whereIn('type', ['日志', '评论']);
  2390. };
  2391. break;
  2392. }
  2393. }
  2394. //
  2395. $lists = DB::table('project_log')
  2396. ->where($whereArray)
  2397. ->where($whereFunc)
  2398. ->orderByDesc('indate')->paginate(Min(Max(Base::nullShow(Request::input('pagesize'), 10), 1), 100));
  2399. $lists = Base::getPageList($lists);
  2400. if ($lists['total'] == 0) {
  2401. return Base::retError('未找到任何相关的记录', $lists);
  2402. }
  2403. foreach ($lists['lists'] AS $key => $item) {
  2404. $item = array_merge($item, Users::username2basic($item['username']));
  2405. $item['timeData'] = [
  2406. 'ymd' => date(date("Y", $item['indate']) == date("Y", Base::time()) ? "m-d" : "Y-m-d", $item['indate']),
  2407. 'hi' => date("h:i", $item['indate']) ,
  2408. 'week' => "周" . Base::getTimeWeek($item['indate']),
  2409. 'segment' => Base::getTimeDayeSegment($item['indate']),
  2410. ];
  2411. $item['other'] = Base::string2array($item['other'], ['type' => '']);
  2412. $lists['lists'][$key] = $item;
  2413. }
  2414. return Base::retSuccess('success', $lists);
  2415. }
  2416. }