public function add(Request $request, Response $response) { if ($request->is_post()) { $aid = $request->post('aid', 0); $title = $request->post('title', ''); $content = $request->post('content', ''); $img = $request->post('img', ''); $start_time = $request->post('start_time', ''); $end_time = $request->post('end_time', ''); $link = $request->post('link', ''); $tpl = $request->post('tpl', 0); $ret = ['flag' => 'ERR', 'msg' => '']; if ('' == $title) { $ret['msg'] = '活动标题不能为空'; $response->sendJSON($ret); } if ('' == $img) { $ret['msg'] = '活动封面不能为空'; $response->sendJSON($ret); } /*else if (!preg_match('!^http://.{4,}!', $img)) { $ret['msg'] = '活动封面地址无效'; $response->sendJSON($ret); }*/ if ('' == $content) { $ret['msg'] = '活动详情不能为空'; $response->sendJSON($ret); } if (!empty($start_time) && strlen($start_time) != 19) { $ret['msg'] = '活动开始时间格式不正确'; $response->sendJSON($ret); } if (!empty($end_time) && strlen($end_time) != 19) { $ret['msg'] = '活动结束时间格式不正确'; $response->sendJSON($ret); } $aid = intval($aid); $start_time = strtotime($start_time); $end_time = strtotime($end_time); $start_time = intval($start_time); $end_time = intval($end_time); $info = []; if ($aid) { $info = Activity_Model::getInfo($aid); } $now = simphp_time(); $uid = $_SESSION['logined_uid']; $params = ['title' => $title, 'tpl' => $tpl, 'content' => $content, 'img' => $img, 'start_time' => $start_time, 'end_time' => $end_time, 'link' => $link, 'createdby' => $uid, 'created' => $now, 'changedby' => $uid, 'changed' => $now, 'status' => 'R']; if (empty($info)) { // new insert $ninfo['aid'] = D()->insert('activity', $params); $ret['flag'] = 'OK'; $ret['msg'] = '添加成功!'; $response->sendJSON($ret); } else { // edit unset($params['createdby'], $params['created'], $params['status']); D()->update('activity', $params, ['aid' => $aid]); $ret['flag'] = 'OK'; $ret['msg'] = '编辑成功!'; $response->sendJSON($ret); } } else { // $aid = $request->arg(1); $aid = intval($aid); $is_edit = $aid ? TRUE : FALSE; $ainfo = $is_edit ? Activity_Model::getInfo($aid) : []; // Node Type $node_type = ''; $this->v->assign('nav_second', $node_type); $this->v->set_tplname('mod_activity_add'); $this->v->assign('ninfo', $ainfo)->assign('is_edit', $is_edit); $response->send($this->v); } }