$app() : Base::ajaxError("404 not found (" . str_replace("__", "/", $app) . ")."); } /** * 获取内容 * * @apiParam {Number} id 数据ID */ public function content() { $row = Base::DBC2A(DB::table('report_content')->select(['rid', 'content'])->where('rid', intval(Request::input('id')))->first()); if (empty($row)) { return Base::retError('内容不存在或已被删除!'); } return Base::retSuccess('success', $row); } /** * 获取模板、保存、发送、删除 * * @apiParam {String} type 类型 * - 日报 * - 周报 * @apiParam {Number} [id] 数据ID * @apiParam {String} [act] 请求方式 * - submit: 保存 * - send: 仅发送 * - delete: 删除汇报 * - else: 获取 * @apiParam {String} [send] 是否发送(1:是),仅act=submit且未发送过的有效 * @apiParam {Object} [D] Request Payload 提交 * - title: 标题 * - ccuser: 抄送人 * - content: 内容 */ public function template() { $user = Users::authE(); if (Base::isError($user)) { return $user; } else { $user = $user['data']; } // $id = intval(Request::input('id')); $act = trim(Request::input('act')); $type = trim(Request::input('type')); if (!in_array($type, ['日报', '周报'])) { return Base::retError('参数错误!'); } $dateTitle = ""; // $whereArray = []; $whereArray[] = ['username', '=', $user['username']]; if ($id > 0) { $whereArray[] = ['id', '=', $id]; } else { switch ($type) { case "日报": $whereArray[] = ['type', '=', '日报']; $whereArray[] = ['date', '=', date("Ymd")]; $dateTitle = date("Y-m-d"); break; case "周报": $whereArray[] = ['type', '=', '周报']; $whereArray[] = ['date', '=', date("W")]; $dateTitle = date("Y年m月") . "第" . Base::getMonthWeek() . "周"; break; } } // $reportDetail = Base::DBC2A(DB::table('report_lists')->where($whereArray)->first()); if ($id > 0 && empty($reportDetail)) { return Base::retError('没有相关的数据!'); } if ($act == 'send') { if (empty($reportDetail)) { return Base::retError('没有相关的数据或已被删除!'); } $ccuser = Base::string2array($reportDetail['ccuser']); DB::table('report_ccuser')->where(['rid' => $reportDetail['id']])->update(['cc' => 0]); foreach ($ccuser AS $ck => $cuser) { if (!$cuser) { unset($ccuser[$ck]); continue; } DB::table('report_ccuser')->updateOrInsert(['rid' => $reportDetail['id'], 'username' => $cuser], ['cc' => 1]); } DB::table('report_lists')->where('id', $reportDetail['id'])->update([ 'status' => '已发送', 'ccuser' => Base::array2string($ccuser) ]); $reportDetail['ccuser'] = implode(',', $ccuser); $reportDetail['ccuserArray'] = explode(',', $reportDetail['ccuser']); return Base::retSuccess('发送成功!', array_merge($reportDetail, [ 'ccuserAgain' => $reportDetail['status'] == '已发送' ])); } elseif ($act == 'delete') { if (empty($reportDetail)) { return Base::retError('没有相关的数据或已被删除!'); } if ($reportDetail['status'] == '已发送') { return Base::retError('汇报已发送,无法删除!'); } DB::table('report_lists')->where('id', $reportDetail['id'])->delete(); DB::table('report_ccuser')->where('rid', $reportDetail['id'])->delete(); DB::table('report_content')->where('rid', $reportDetail['id'])->delete(); return Base::retSuccess('删除成功!'); } elseif ($act == 'submit') { $D = Base::getContentsParse('D'); if (mb_strlen($D['title']) < 2 || mb_strlen($D['title']) > 100) { return Base::retError('标题限制2-100个字!'); } if (empty($reportDetail)) { DB::table('report_lists')->insert([ 'username' => $user['username'], 'title' => $D['title'], 'type' => $type, 'status' => '未发送', 'date' => $type=='日报'?date("Ymd"):date("W"), 'indate' => Base::time(), ]); $reportDetail = Base::DBC2A(DB::table('report_lists')->where($whereArray)->first()); } if (empty($reportDetail)) { return Base::retError('系统繁忙,请稍后再试!'); } // $D['ccuser'] = explode(",", $D['ccuser']); $send = $reportDetail['status'] == '已发送' ? 1 : intval(Request::input('send')); $ccuserAgain = $reportDetail['status'] == '已发送'; if ($send) { DB::table('report_ccuser')->where(['rid' => $reportDetail['id']])->update(['cc' => 0]); foreach ($D['ccuser'] AS $ck => $cuser) { if (!$cuser) { unset($D['ccuser'][$ck]); continue; } DB::table('report_ccuser')->updateOrInsert(['rid' => $reportDetail['id'], 'username' => $cuser], ['cc' => 1]); } $reportDetail['status'] = '已发送'; } // DB::table('report_lists')->where('id', $reportDetail['id'])->update([ 'title' => $D['title'], 'status' => $send ? '已发送' : '未发送', 'ccuser' => Base::array2string($D['ccuser']) ]); DB::table('report_content')->updateOrInsert(['rid' => $reportDetail['id']], ['content' => $D['content']]); // $reportDetail = array_merge($reportDetail, [ 'ccuserAgain' => $ccuserAgain, 'ccuser' => $D['ccuser'], 'title' => $D['title'], 'content' => $D['content'], ]); } if (empty($reportDetail)) { //已完成 $completeContent = ''; $startTime = $type == '日报' ? strtotime(date('Y-m-d 00:00:00')) : strtotime(date('Y-m-d 00:00:00', strtotime('this week'))); $lists = Base::DBC2A(DB::table('project_task') ->select(['title', 'completedate']) ->where('username', $user['username']) ->where('complete', 1) ->where('delete', 0) ->whereBetween('completedate', [$startTime, time()]) ->orderBy('completedate') ->orderBy('id') ->get()); foreach ($lists as $item) { $pre = $type == '周报' ? ('[周' . ['日', '一', '二', '三', '四', '五', '六'][date('w')] . '] ') : ''; $completeContent .= '