public function save() { if (empty($_POST['title']) || mb_strlen($_POST['title']) < 2) { $GLOBALS['tmpl']->assign("post", "{$_POST}"); $GLOBALS['tmpl']->assign("inc_file", "inc/uc/uc_send_message.html"); $GLOBALS['tmpl']->display("uc.html"); } else { foreach ($_POST as $k => $v) { $_POST[$k] = htmlspecialchars(addslashes(trim($v))); } try { $taoxin = array(); $taoxin['title'] = $_POST['title']; $taoxin['price'] = $_POST['price']; $taoxin['address'] = $_POST['address']; $taoxin['contact'] = $_POST['contact']; $taoxin['qq'] = $_POST['qq']; $taoxin['detail'] = $_POST['detail']; $taoxin['create_time'] = time(); $taoxin['city_id'] = !empty($_POST['city_id']) ? $_POST['city_id'] : 1; $taoxin['area_id'] = !empty($_POST['area_id']) ? $_POST['area_id'] : 0; $taoxin['cate_id'] = empty($_POST['subcate_id']) ? isset($_POST['cate_id']) ? $_POST['cate_id'] : 1 : $_POST['subcate_id']; $taoxin['uid'] = $GLOBALS['user_info']['id']; $taoxin['verify'] = 0; $taoxin['longitude'] = !empty($_POST['longitude']) ? $_POST['longitude'] : '119.025595'; $taoxin['latitude'] = !empty($_POST['latitude']) ? $_POST['latitude'] : '33.596043'; $taoxin['location'] = 'GeomFromText("POINT(' . $taoxin['longitude'] . ' ' . $taoxin['latitude'] . ')")'; $uplod_file_ret = upload_taoxin_files(); if (!empty($uplod_file_ret['file_link'])) { $taoxin['goods_photos'] = json_encode($uplod_file_ret['file_link']); } if (!empty($_POST['id'])) { // 如果是编辑 $id = $_POST['id']; $GLOBALS['db']->autoExecute("tb_taoxin", $taoxin, "UPDATE", "id=" . $id); header('Location:' . APP_ROOT . '/index.php?ctl=uc_my_release&act=detail&id=' . $id); } else { if ($GLOBALS['db']->autoExecute("tb_taoxin", $taoxin, "INSERT")) { $id = $GLOBALS['db']->insert_id(); header('Location:' . APP_ROOT . '/index.php?ctl=uc_my_release&act=detail&id=' . $id); } else { // 如果出错,把原来添加的信息返回回去 $GLOBALS['tmpl']->assign("old_taoxin", $taoxin); $GLOBALS['tmpl']->assign("inc_file", "inc/uc/uc_my_release.html"); $GLOBALS['tmpl']->display("uc.html"); } } } catch (Exception $e) { echo $e->getMessage(); } } }
/** * 添加淘信 */ public function app_add_taoxin() { if (empty($_POST['title'])) { echo json_encode(array('ret' => '102', 'msg' => '标题太短')); } elseif (empty($_POST['phone']) || empty($_POST['sig'])) { echo json_encode(array('ret' => '104', 'msg' => '身份验证失败')); } else { $phone = $_POST['phone']; $sig = $_POST['sig']; $verify = login_verify($phone, $sig); if ($verify !== true) { echo json_encode(array('ret' => $verify)); exit; } foreach ($_POST as $k => $v) { $_POST[$k] = addslashes(trim($v)); } try { $taoxin = array(); $taoxin['title'] = $_POST['title']; $taoxin['price'] = isset($_POST['price']) ? $_POST['price'] : ""; $taoxin['address'] = isset($_POST['address']) ? $_POST['address'] : ""; $taoxin['contact'] = isset($_POST['contact']) ? $_POST['contact'] : ""; $taoxin['qq'] = $_POST['qq']; $taoxin['detail'] = $_POST['detail']; $taoxin['create_time'] = time(); $taoxin['city_id'] = !empty($_POST['city_id']) ? $_POST['city_id'] : 1; $taoxin['area_id'] = !empty($_POST['area_id']) ? $_POST['area_id'] : 0; $taoxin['cate_id'] = empty($_POST['subcate_id']) ? isset($_POST['cate_id']) ? $_POST['cate_id'] : 1 : $_POST['subcate_id']; $uid = $GLOBALS['app_add_taoxin']['id']; $taoxin['uid'] = $GLOBALS['user_info']['id']; $taoxin['verify'] = 0; $taoxin['longitude'] = !empty($_POST['lng']) ? $_POST['lng'] : '119.025595'; $taoxin['latitude'] = !empty($_POST['lat']) ? $_POST['lat'] : '33.596043'; $taoxin['location'] = 'GeomFromText("POINT(' . $taoxin['longitude'] . ' ' . $taoxin['latitude'] . ')")'; $uplod_file_ret = upload_taoxin_files(); if (!empty($uplod_file_ret['file_link'])) { $taoxin['goods_photos'] = json_encode($uplod_file_ret['file_link']); } if (!empty($_POST['id'])) { // 如果是编辑 $id = $_POST['id']; $GLOBALS['db']->autoExecute(DB_PREFIX . "taoxin", $taoxin, "UPDATE", "id=" . $id); echo json_encode(array('ret' => '0', 'taoxin_id' => $id)); } else { if ($GLOBALS['db']->autoExecute(DB_PREFIX . "taoxin", $taoxin, "INSERT")) { $id = $GLOBALS['db']->insert_id(); echo json_encode(array('ret' => '0', 'taoxin_id' => $id)); } else { throw new Exception('淘信添加失败'); } } } catch (Exception $e) { echo json_encode(array('ret' => '-1', 'msg' => $e->getMessage())); } } }