本文整理汇总了PHP中Response::sendJSON方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::sendJSON方法的具体用法?PHP Response::sendJSON怎么用?PHP Response::sendJSON使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response::sendJSON方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: elseif
/**
* 提交地址
*
* @param Request $request
* @param Response $response
*/
function post_address(Request $request, Response $response)
{
$uid = $GLOBALS['user']->uid;
if ($request->is_post()) {
//送花奖励阶梯
$sendmoney_phases = [30, 50, 100];
$address_id = $request->post('address_id', 0);
$match_id = $request->post('match_id', 0);
$player_id = $request->post('player_id', 0);
$order_id = $request->post('order_id', 0);
$sendmoney = $request->post('sendmoney', 0);
$backurl = $request->post('backurl', 0);
$consignee = $request->post('consignee', '');
$mobile = $request->post('mobile', '');
$province = $request->post('province', 0);
$city = $request->post('city', 0);
$address = $request->post('address', '');
$zipcode = $request->post('zipcode', '');
$res = ['flag' => 'FAIL', 'msg' => '', 'match_id' => $match_id, 'backurl' => $backurl];
if (empty($uid)) {
$res['msg'] = '未登录,请先登录';
$response->sendJSON($res);
}
if ('' == $consignee) {
$res['msg'] = '姓名不能为空';
$response->sendJSON($res);
}
if ('' == $mobile) {
$res['msg'] = '手机不能为空';
$response->sendJSON($res);
} elseif (!preg_match('/^\\d{11,14}$/', $mobile)) {
$res['msg'] = '手机号码不正确';
$response->sendJSON($res);
}
if (empty($province)) {
$res['msg'] = '身份地址不能为空';
$response->sendJSON($res);
}
$province_name = Match_Model::getLocationName($province);
if (empty($city)) {
$res['msg'] = '城市地址不能为空';
$response->sendJSON($res);
}
$city_name = Match_Model::getLocationName($city);
if ('' == $address) {
$res['msg'] = '详细地址不能为空';
$response->sendJSON($res);
}
if ('' != $zipcode && !preg_match('/^\\d{6}$/', $zipcode)) {
$res['msg'] = '邮政编码不正确';
$response->sendJSON($res);
}
$tbname = 'member_address';
$tbdata = ['address_name' => '', 'user_id' => $uid, 'consignee' => $consignee, 'country' => 2, 'country_name' => '中国', 'province' => $province, 'province_name' => $province_name, 'city' => $city, 'city_name' => $city_name, 'district' => 0, 'district_name' => '', 'address' => $address, 'zipcode' => $zipcode, 'mobile' => $mobile];
if (!$address_id) {
// Insert mode
$address_id = D()->insert($tbname, $tbdata);
} else {
// Edit mode
D()->update($tbname, $tbdata, ['address_id' => $address_id]);
}
//送奖品记录
if ($address_id && $sendmoney >= $sendmoney_phases[0] && $player_id && $order_id) {
$phasemoney = $sendmoney_phases[0];
if ($sendmoney >= $sendmoney_phases[1] && $sendmoney < $sendmoney_phases[2]) {
$phasemoney = $sendmoney_phases[1];
} elseif ($sendmoney >= $sendmoney_phases[2]) {
$phasemoney = $sendmoney_phases[2];
}
$tbdata = ['user_id' => $uid, 'address_id' => $address_id, 'player_id' => $player_id, 'order_id' => $order_id, 'phase_money' => $phasemoney, 'true_money' => $sendmoney, 'timeline' => simphp_time()];
$rid = D()->from("member_giftpay")->where("`user_id`=%d AND `player_id`=%d AND `order_id`=%d", $uid, $player_id, $order_id)->select('`rid`')->result();
if (!$rid) {
//一个订单只有没有生成过记录时才记录,避免重复
D()->insert('member_giftpay', $tbdata);
} else {
$res['flag'] = 'SUC';
$res['msg'] = '当前订单之前申请过礼物,不能重复申请';
$response->sendJSON($res);
}
}
$res['flag'] = 'SUC';
$res['msg'] = '地址保存成功!';
$response->sendJSON($res);
} else {
$this->v->set_tplname('mod_match_post_address');
$this->v->set_page_render_mode(View::RENDER_MODE_GENERAL);
$this->nav_flag1 = 'match_address';
$this->topnav_no = 1;
$match_id = $request->arg(1);
$sendmoney = $request->get('sendmoney', 0);
$player_id = $request->get('player_id', 0);
$order_id = $request->get('order_id', 0);
$backurl = $request->get('backurl', '');
$this->v->assign('match_id', $match_id);
//.........这里部分代码省略.........
示例2: import
/**
* action 'import'
* @param Request $request
* @param Response $response
*/
public function import(Request $request, Response $response)
{
if ($request->is_post()) {
$source_id = $request->post('source_id');
$source_url = $request->post('source_url');
$ret = ['flag' => 'ERR', 'msg' => ''];
if (!$source_id || !in_array($source_id, Node_Model::getSourceList('music', true))) {
$ret['msg'] = '请选择有效的来源';
$response->sendJSON($ret);
}
if (!$source_url || !preg_match('!^http://.{4,}!i', $source_url)) {
$ret['msg'] = '请输入有效的URL地址';
$response->sendJSON($ret);
}
Node_Model::importMusic($source_id, $source_url);
$ret = ['flag' => 'OK', 'msg' => '导入成功!'];
$response->sendJSON($ret);
} else {
// Node Info
$import_ntype = $request->arg(2);
$this->v->assign('nav_second', $import_ntype);
// Music Source List
$sourceList = Node_Model::getSourceList('music');
$this->v->set_tplname('mod_node_import');
$this->v->assign('sourceList', $sourceList);
$response->send($this->v);
}
}
示例3: collect_cancel
public function collect_cancel(Request $request, Response $response)
{
if ($request->is_post()) {
$res = ['flag' => 'FAIL', 'msg' => '取消失败'];
$ec_user_id = $GLOBALS['user']->ec_user_id;
if (!$ec_user_id) {
$res['msg'] = '未登录, 请登录';
$response->sendJSON($res);
}
$rec_id = $request->post('rec_id', 0);
if (!$rec_id) {
$res['msg'] = '记录id为空';
$response->sendJSON($res);
}
$b = Goods::goodsCollectCancel($rec_id);
if ($b) {
$res = ['flag' => 'SUC', 'msg' => '取消成功'];
}
$response->sendJSON($res);
}
}
示例4: upfile
/**
* 简单上传一个文件,然后用标准JSON格式返回文件的地址,不记录数据库数据
* @param Request $request
* @param Response $response
*/
public function upfile(Request $request, Response $response)
{
if ($request->has_files()) {
$upfile = $request->files('upfile');
$dbsave = $request->get('dbsave', 0);
$isplayer = $request->get('isplayer', 0);
$extpart = strtolower(strrchr($upfile['name'], '.'));
$fileext = substr($extpart, 1);
$filetype = 'attach';
if ('swf' == $fileext) {
$filetype = 'flash';
} elseif (in_array($fileext, array('jpg', 'jpeg', 'png', 'gif'))) {
$filetype = 'pic';
} elseif ('apk' == $fileext) {
$filetype = 'android';
} elseif ('ipa' == $fileext) {
$filetype = 'ios';
} elseif ('xap' == $fileext || 'cab' == $fileext) {
$filetype = 'wp';
} elseif (in_array($fileext, array('mp3'))) {
$filetype = 'audio';
}
if ($isplayer) {
$filetype = 'player';
}
//~ create directory
$targetfilecode = date('d_His') . '_' . randchar();
$targetfile = $targetfilecode . $extpart;
$targetdir = ltrim($this->_uproot_dir, '/') . "{$filetype}/" . date('Ym') . '/';
if ($isplayer) {
$targetdir .= 'original/';
}
if (!is_dir($targetdir)) {
mkdirs($targetdir, 0777, TRUE);
}
//~ move upload file to target dir
$filepath = $targetdir . $targetfile;
move_uploaded_file($upfile['tmp_name'], $filepath);
chmod($filepath, 0644);
if (file_exists($filepath)) {
$mid = 0;
$width = 0;
$height = 0;
$size = filesize($filepath);
if ($filetype == 'pic') {
list($width, $height, $type, $attr) = getimagesize($filepath);
}
$filepath_site = C('env.contextpath', '/') . $filepath;
//要补上网站的根路径
if ($dbsave) {
$data = ['mtype' => $filetype, 'filesize' => $size, 'path' => $filepath_site];
$mid = Media::save($data);
}
if ($isplayer) {
$rt = Upload_Model::makeImgThumb($filepath_site);
if (is_numeric($rt)) {
$response->sendJSON(['flag' => 'ERR', 'msg' => 'make thumb fail']);
} else {
$mid = Upload_Model::savePlayerGallery(0, $rt);
}
}
$response->sendJSON(['flag' => 'OK', 'msg' => 'upload file success', 'mid' => $mid, 'path' => $filepath_site, 'type' => $filetype, 'width' => $width, 'height' => $height, 'size' => $size]);
}
$response->sendJSON(['flag' => 'ERR', 'msg' => 'upload file error']);
}
$response->sendJSON(['flag' => 'ERR_NOFILES', 'msg' => 'no files upload']);
}
示例5: order_confirm_shipping
/**
* 取消订单
*
* @param Request $request
* @param Response $response
*/
public function order_confirm_shipping(Request $request, Response $response)
{
if ($request->is_post()) {
$ret = ['flag' => 'FAIL', 'msg' => '取消失败'];
$ec_user_id = $GLOBALS['user']->ec_user_id;
if (!$ec_user_id) {
$ret['msg'] = '未登录, 请登录';
$response->sendJSON($ret);
}
$order_id = $request->post('order_id', 0);
if (!$order_id) {
$ret['msg'] = '订单id为空';
$response->sendJSON($ret);
}
$b = Order::confirm_shipping($order_id);
if ($b) {
$ret = ['flag' => 'SUC', 'msg' => '确认成功', 'order_id' => $order_id];
}
$response->sendJSON($ret);
}
}
示例6: show_jsonmsg
function show_jsonmsg($content)
{
Response::sendJSON($content);
exit;
}
示例7: cities
/**
* 获取省下的城市名列表
*
* @param Request $request
* @param Response $response
*/
function cities(Request $request, Response $response)
{
$parent_id = $request->get('parent_id', 0);
$res = ['flag' => 'FAIL', 'msg' => ''];
if (empty($parent_id)) {
$res['msg'] = 'parent_id empty';
$response->sendJSON($res);
}
$cities = Member_Model::getCities($parent_id);
if (empty($cities)) {
$res['msg'] = 'parent_id invalid';
$response->sendJSON($res);
}
$res['flag'] = 'SUC';
$res['msg'] = '';
$res['data'] = $cities;
$response->sendJSON($res);
}
示例8: delete
public function delete(Request $request, Response $response)
{
if ($request->is_post()) {
$ids = $request->post('rids');
$ret = News_Model::delete($ids);
$response->sendJSON(['flag' => 'OK', 'rids' => $ret]);
}
}
示例9: ad_del
public function ad_del(Request $request, Response $response)
{
if ($request->is_post()) {
$ids = $request->post('rids');
$ret = Other_Model::deleteAdList($ids);
$response->sendJSON(['flag' => 'OK', 'rids' => $ret]);
}
}
示例10: join
public function join(Request $request, Response $response)
{
$res = ['flag' => 'FAIL', 'msg' => ''];
if (Member::isLogined()) {
$user = Member::getUser();
$uid = $user['uid'];
} else {
$res['msg'] = '请先登录';
$response->sendJSON($res);
}
$aid = $request->post('aid', 0);
$act = $request->post('act', '');
$info = Activity_Model::getActivityByAid($aid);
if (empty($info)) {
$res['msg'] = '该活动不存在';
$response->sendJson($res);
}
if (!in_array($act, ['join', 'vote'])) {
$res['msg'] = '未知操作';
$response->sendJson($res);
}
$inc = 1;
if ($act == 'join') {
$cur_time = time();
if ($info['start_time'] > $cur_time) {
$res['msg'] = '活动还没有开始';
$response->sendJson($res);
}
if ($info['end_time'] < $cur_time) {
$res['msg'] = '活动已结束';
$response->sendJson($res);
}
if (Activity_Model::isJoin($aid, $uid, 'join')) {
$inc = -1;
$res['msg'] = '您已经参与过本次活动了';
$response->sendJson($res);
}
} elseif ($act == 'vote') {
if (Activity_Model::isJoin($aid, $uid, 'vote')) {
$inc = -1;
/*
$res['msg'] = '已赞';
$response->sendJson($res);*/
}
}
$jid = Activity_Model::joinActivity(['aid' => $aid, 'uid' => $uid, 'act' => $act, 'timeline' => time()], $inc);
if ($jid > 0) {
$res['flag'] = 'SUC';
if ($act == 'join') {
$res['msg'] = '参与成功';
} elseif ($act == 'vote') {
if ($inc > 0) {
$res['msg'] = '已赞';
} else {
$res['msg'] = '已取消赞';
}
}
} else {
$res['msg'] = '系统繁忙,请稍后再试';
}
$response->sendJson($res);
}
示例11: relatedRank
/**
* 更新关联数据的排序值
* @param Request $request [description]
* @param Response $response [description]
* @return [type] [description]
*/
public function relatedRank(Request $request, Response $response)
{
if ($request->is_post()) {
$res = ['flag' => 'FAIL', 'msg' => ''];
$aid = $request->post('aid', '');
$nid = $request->post('nid', '');
$new_rank = $request->post('new_rank', 0);
if (Activity_Model::updateRelatedRank($aid, $nid, $new_rank)) {
$res['flag'] = 'SUC';
$res['msg'] = '更新成功';
} else {
$res['msg'] = '系统繁忙,请稍后再试';
}
$response->sendJSON($res);
}
}
示例12: checkLogin_ajax
/**
* 检测用户是否登录
*/
function checkLogin_ajax()
{
$res = ['flag' => 'FAIL', 'msg' => '请先登录'];
if (!Member::isLogined()) {
Response::sendJSON($res);
}
}