提交 87d2b5e4 编写于 作者: D devil

api插件调用优化

上级 72da6fe4
...@@ -87,71 +87,27 @@ class Plugins extends Common ...@@ -87,71 +87,27 @@ class Plugins extends Common
$pluginscontrol = strtolower($params['pluginscontrol']); $pluginscontrol = strtolower($params['pluginscontrol']);
$pluginsaction = strtolower($params['pluginsaction']); $pluginsaction = strtolower($params['pluginsaction']);
// 应用校验
$ret = $this->PluginsCheck($pluginsname, $pluginscontrol, $pluginsaction);
if($ret['code'] != 0)
{
if(IS_AJAX)
{
return $ret;
} else {
$this->assign('msg', $ret['msg']);
return $this->fetch('public/tips_error');
}
}
// 视图初始化 // 视图初始化
$this->PluginsViewInit($pluginsname, $pluginscontrol, $pluginsaction); $this->PluginsViewInit($pluginsname, $pluginscontrol, $pluginsaction);
// 编辑器文件存放地址定义 // 编辑器文件存放地址定义
$this->assign('editor_path_type', 'plugins_'.$pluginsname); $this->assign('editor_path_type', 'plugins_'.$pluginsname);
// 应用控制器 // 调用
$plugins = '\app\plugins\\'.$pluginsname.'\admin\\'.ucfirst($pluginscontrol); $ret = PluginsService::PluginsControlCall($pluginsname, $pluginscontrol, $pluginsaction, 'admin', $params);
if(!class_exists($plugins)) if($ret['code'] == 0)
{ {
if(IS_AJAX) return $ret['data'];
{
return DataReturn(ucfirst($pluginscontrol).' 应用控制器未定义', -1);
} else {
$this->assign('msg', ucfirst($pluginscontrol).' 应用控制器未定义');
return $this->fetch('public/tips_error');
}
} }
// 调用方法 // 调用失败
$obj = new $plugins(); if(IS_AJAX)
if(!method_exists($obj, $pluginsaction))
{
if(IS_AJAX)
{
return DataReturn(ucfirst($pluginsaction).' 应用方法未定义', -1);
} else {
$this->assign('msg', ucfirst($pluginsaction).' 应用方法未定义');
return $this->fetch('public/tips_error');
}
}
return $obj->$pluginsaction($params);
}
/**
* 应用校验
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-05-27T00:13:50+0800
* @param [string] $plugins_name [应用名称]
* @param [string] $plugins_control [控制器名称]
* @param [string] $plugins_action [方法]
*/
private function PluginsCheck($pluginsname, $pluginscontrol, $pluginsaction)
{
$ret = PluginsService::PluginsField($pluginsname, 'id');
if(empty($ret['data']))
{ {
return DataReturn('应用不存在', -10); return $ret;
} else {
$this->assign('msg', $ret['msg']);
return $this->fetch('public/tips_error');
} }
return DataReturn('验证成功', 0);
} }
/** /**
......
...@@ -10,107 +10,78 @@ ...@@ -10,107 +10,78 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\api\controller; namespace app\api\controller;
use app\service\PluginsService;
/** /**
* 优惠劵 * 应用调用入口
* @author Devil * @author Devil
* @blog http://gong.gg/ * @blog http://gong.gg/
* @version 0.0.1 * @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800 * @datetime 2016-12-01T21:51:08+0800
*/ */
class Coupon extends Common class Plugins extends Common
{ {
/** /**
* [__construct 构造方法] * 构造方法
* @author Devil * @author Devil
* @blog http://gong.gg/ * @blog http://gong.gg/
* @version 0.0.1 * @version 1.0.0
* @datetime 2016-12-03T12:39:08+0800 * @date 2020-01-02
* @desc description
*/ */
public function __construct() public function __construct()
{ {
// 调用父类前置方法
parent::__construct(); parent::__construct();
} }
/** /**
* 优惠劵首页 * 首页
* @author Devil * @author Devil
* @blog http://gong.gg/ * @blog http://gong.gg/
* @version 1.0.0 * @version 1.0.0
* @date 2019-10-15 * @date 2020-01-02
* @desc description * @desc description
*/ */
public function Index() public function Index()
{ {
// 获取基础配置信息 // 请求参数校验
$base = CallPluginsData('coupon'); $p = [
[
// 优惠劵列表 'checked_type' => 'empty',
$coupon_params = [ 'key_name' => 'pluginsname',
'where' => [ 'error_msg' => '应用名称有误',
'is_enable' => 1,
'is_user_receive' => 1,
], ],
'm' => 0, [
'n' => 0, 'checked_type' => 'empty',
'is_sure_receive' => 1, 'key_name' => 'pluginscontrol',
'user' => $this->user, 'error_msg' => '应用控制器有误',
]; ],
$ret = CallPluginsServiceMethod('coupon', 'CouponService', 'CouponList', $coupon_params); [
'checked_type' => 'empty',
// 返回数据 'key_name' => 'pluginsaction',
$result = [ 'error_msg' => '应用操作方法有误',
'base' => $base['data'],
'data' => $ret['data'],
];
return DataReturn('处理成功', 0, $result);
}
/**
* 用户优惠劵列表
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-10-15
* @desc description
*/
public function User()
{
// 是否登录
$this->IsLogin();
// 获取用户优惠劵
$coupon_params = [
'user' => $this->user,
'where' => [
'user_id' => $this->user['id'],
'is_valid' => 1,
], ],
]; ];
return CallPluginsServiceMethod('coupon', 'UserCouponService', 'CouponUserList', $coupon_params); $ret = ParamsChecked($this->data_request, $p);
} if($ret !== true)
{
return DataReturn($ret, -5000);
}
/** // 应用名称/控制器/方法
* 领取优惠劵 $pluginsname = $this->data_request['pluginsname'];
* @author Devil $pluginscontrol = strtolower($this->data_request['pluginscontrol']);
* @blog http://gong.gg/ $pluginsaction = strtolower($this->data_request['pluginsaction']);
* @version 1.0.0
* @date 2019-10-15
* @desc description
*/
public function Receive()
{
// 是否登录
$this->IsLogin();
// 是否ajax请求 // 调用
if(!IS_AJAX) $ret = PluginsService::PluginsControlCall($pluginsname, $pluginscontrol, $pluginsaction, 'api', $this->data_request);
if($ret['code'] == 0)
{ {
return $this->error('非法访问'); return $ret['data'];
} }
// 领取优惠劵 // 调用失败
return CallPluginsServiceMethod('coupon', 'CouponService', 'UserReceiveCoupon', $this->data_post); return $ret;
} }
} }
?> ?>
\ No newline at end of file
...@@ -100,7 +100,7 @@ function PathToParams($key = null, $default = null, $path = '') ...@@ -100,7 +100,7 @@ function PathToParams($key = null, $default = null, $path = '')
} }
/** /**
* 调用插件方法 - 获取插件配置信息 * 调用插件服务层方法 - 获取插件配置信息
* @author Devil * @author Devil
* @blog http://gong.gg/ * @blog http://gong.gg/
* @version 1.0.0 * @version 1.0.0
...@@ -118,8 +118,15 @@ function CallPluginsData($plugins, $attachment_field = [], $service_name = '', $ ...@@ -118,8 +118,15 @@ function CallPluginsData($plugins, $attachment_field = [], $service_name = '', $
return DataReturn('插件状态异常['.$plugins.']', -1); return DataReturn('插件状态异常['.$plugins.']', -1);
} }
// 查看是否存在基础服务层并且定义获取基础配置方法
$plugins_class = 'app\plugins\\'.$plugins.'\service\BaseService';
if(class_exists($plugins_class) && method_exists($plugins_class, 'BaseConfig'))
{
return $plugins_class::BaseConfig();
}
// 未指定附件字段则自动去获取 // 未指定附件字段则自动去获取
$attachment = []; $attachment = $attachment_field;
if(empty($attachment_field) && !empty($attachment_property)) if(empty($attachment_field) && !empty($attachment_property))
{ {
// 类自定义或者默认两个类 // 类自定义或者默认两个类
...@@ -141,7 +148,7 @@ function CallPluginsData($plugins, $attachment_field = [], $service_name = '', $ ...@@ -141,7 +148,7 @@ function CallPluginsData($plugins, $attachment_field = [], $service_name = '', $
} }
/** /**
* 调用插件方法 - 访问为静态 * 调用插件服务层方法 - 访问为静态
* @author Devil * @author Devil
* @blog http://gong.gg/ * @blog http://gong.gg/
* @version 1.0.0 * @version 1.0.0
......
...@@ -81,75 +81,27 @@ class Plugins extends Common ...@@ -81,75 +81,27 @@ class Plugins extends Common
$pluginscontrol = strtolower($params['pluginscontrol']); $pluginscontrol = strtolower($params['pluginscontrol']);
$pluginsaction = strtolower($params['pluginsaction']); $pluginsaction = strtolower($params['pluginsaction']);
// 应用校验
$ret = $this->PluginsCheck($pluginsname, $pluginscontrol, $pluginsaction);
if($ret['code'] != 0)
{
if(IS_AJAX)
{
return $ret;
} else {
$this->assign('msg', $ret['msg']);
return $this->fetch('public/tips_error');
}
}
// 视图初始化 // 视图初始化
$this->PluginsViewInit($pluginsname, $pluginscontrol, $pluginsaction); $this->PluginsViewInit($pluginsname, $pluginscontrol, $pluginsaction);
// 编辑器文件存放地址定义 // 编辑器文件存放地址定义
$this->assign('editor_path_type', 'plugins_'.$pluginsname); $this->assign('editor_path_type', 'plugins_'.$pluginsname);
// 应用控制器 // 调用
$plugins = '\app\plugins\\'.$pluginsname.'\index\\'.ucfirst($pluginscontrol); $ret = PluginsService::PluginsControlCall($pluginsname, $pluginscontrol, $pluginsaction, 'index', $params);
if(!class_exists($plugins)) if($ret['code'] == 0)
{ {
if(IS_AJAX) return $ret['data'];
{
return DataReturn(ucfirst($pluginscontrol).' 应用控制器未定义', -1);
} else {
$this->assign('msg', ucfirst($pluginscontrol).' 应用控制器未定义');
return $this->fetch('public/tips_error');
}
} }
// 调用方法 // 调用失败
$obj = new $plugins(); if(IS_AJAX)
if(!method_exists($obj, $pluginsaction))
{
if(IS_AJAX)
{
return DataReturn(ucfirst($pluginsaction).' 应用方法未定义', -1);
} else {
$this->assign('msg', ucfirst($pluginsaction).' 应用方法未定义');
return $this->fetch('public/tips_error');
}
}
return $obj->$pluginsaction($params);
}
/**
* 应用校验
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-05-27T00:13:50+0800
* @param [string] $plugins_name [应用名称]
* @param [string] $plugins_control [控制器名称]
* @param [string] $plugins_action [方法]
*/
private function PluginsCheck($pluginsname, $pluginscontrol, $pluginsaction)
{
$ret = PluginsService::PluginsField($pluginsname, 'is_enable');
if($ret['data'] === null)
{
return DataReturn('应用未安装['.$pluginsname.']', -10);
}
if($ret['data'] != 1)
{ {
return DataReturn('应用未启用['.$pluginsname.']', -10); return $ret;
} else {
$this->assign('msg', $ret['msg']);
return $this->fetch('public/tips_error');
} }
return DataReturn('验证成功', 0);
} }
/** /**
......
...@@ -187,5 +187,66 @@ class PluginsService ...@@ -187,5 +187,66 @@ class PluginsService
$ret = self::PluginsField($plugins, 'is_enable'); $ret = self::PluginsField($plugins, 'is_enable');
return $ret['data']; return $ret['data'];
} }
/**
* 应用校验
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-01-02
* @param [string] $plugins [应用标记]
*/
public static function PluginsCheck($plugins)
{
$ret = self::PluginsStatus($plugins);
if($ret === null)
{
return DataReturn('应用未安装['.$plugins.']', -10);
}
if($ret != 1)
{
return DataReturn('应用未启用['.$plugins.']', -10);
}
return DataReturn('验证成功', 0);
}
/**
* 应用控制器调用
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-01-02
* @param [string] $plugins [应用标记]
* @param [string] $control [应用控制器]
* @param [string] $action [应用方法]
* @param [string] $group [应用组(admin, index, api)]
* @param [array] $params [输入参数]
*/
public static function PluginsControlCall($plugins, $control, $action, $group = 'index', $params = [])
{
// 应用校验
$ret = self::PluginsCheck($plugins);
if($ret['code'] != 0)
{
return $ret;
}
// 应用控制器
$control = ucfirst($control);
$plugins = '\app\plugins\\'.$plugins.'\\'.$group.'\\'.$control;
if(!class_exists($plugins))
{
return DataReturn('应用控制器未定义['.$control.']', -1);
}
// 调用方法
$action = ucfirst($action);
$obj = new $plugins();
if(!method_exists($obj, $action))
{
return DataReturn('应用方法未定义['.$action.']', -1);
}
return DataReturn('验证成功', 0, $obj->$action($params));
}
} }
?> ?>
\ No newline at end of file
...@@ -32,5 +32,102 @@ return array ( ...@@ -32,5 +32,102 @@ return array (
'log_write' => 'log_write' =>
array ( array (
), ),
'plugins_css' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
1 => 'app\\plugins\\coupon\\Hook',
),
'plugins_service_navigation_header_handle' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
1 => 'app\\plugins\\coupon\\Hook',
),
'plugins_service_goods_handle_end' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
),
'plugins_service_goods_spec_base' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
),
'plugins_service_buy_handle' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
1 => 'app\\plugins\\coupon\\Hook',
),
'plugins_service_user_login_success_record' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
),
'plugins_service_goods_spec_extends_handle' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
),
'plugins_view_admin_user_save' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
),
'plugins_service_user_save_handle' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
),
'plugins_service_goods_save_handle' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
),
'plugins_view_goods_detail_panel_price_top' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
),
'plugins_view_home_goods_inside_bottom' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
),
'plugins_view_search_goods_inside_bottom' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
),
'plugins_service_goods_spec_type' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
),
'plugins_service_users_center_left_menu_handle' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
1 => 'app\\plugins\\coupon\\Hook',
),
'plugins_service_header_navigation_top_right_handle' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
1 => 'app\\plugins\\coupon\\Hook',
),
'plugins_js' =>
array (
0 => 'app\\plugins\\coupon\\Hook',
),
'plugins_view_goods_detail_panel_bottom' =>
array (
0 => 'app\\plugins\\coupon\\Hook',
),
'plugins_view_buy_goods_bottom' =>
array (
0 => 'app\\plugins\\coupon\\Hook',
),
'plugins_view_buy_form_inside' =>
array (
0 => 'app\\plugins\\coupon\\Hook',
),
'plugins_service_buy_order_insert_success' =>
array (
0 => 'app\\plugins\\coupon\\Hook',
),
'plugins_service_order_status_change_history_success_handle' =>
array (
0 => 'app\\plugins\\coupon\\Hook',
),
'plugins_service_user_register_end' =>
array (
0 => 'app\\plugins\\coupon\\Hook',
),
); );
?> ?>
\ No newline at end of file
...@@ -169,26 +169,42 @@ App({ ...@@ -169,26 +169,42 @@ App({
/** /**
* 请求地址生成 * 请求地址生成
* a 方法
* c 控制器
* plugins 插件标记(传参则表示为插件请求)
* params url请求参数
*/ */
get_request_url(a, c, m, params) { get_request_url(a, c, plugins, params) {
a = a || "index"; a = a || "index";
c = c || "index"; c = c || "index";
m = m || "api";
// 是否插件请求
var plugins_params = "";
if ((plugins || null) != null)
{
plugins_params = "&pluginsname=" + plugins + "&pluginscontrol=" + c + "&pluginsaction=" + a;
// 走api统一插件调用控制器
c = "plugins"
a = "index"
}
// 参数处理
params = params || ""; params = params || "";
if (params != "" && params.substr(0, 1) != "&") { if (params != "" && params.substr(0, 1) != "&") {
params = "&" + params; params = "&" + params;
} }
// 用户信息
var user = this.get_user_cache_info(); var user = this.get_user_cache_info();
var token = (user == false) ? '' : user.token || ''; var token = (user == false) ? '' : user.token || '';
return ( return this.data.request_url +
this.data.request_url + "index.php?s=/api/" + c + "/" + a + plugins_params+
"index.php?s=/" + m + "/" + c + "/" + a + "&application=app&application_client_type=weixin" +
"&application=app&application_client_type=alipay" +
"&token=" + "&token=" +
token + token +
"&ajax=ajax" + "&ajax=ajax" +
params params;
);
}, },
/** /**
......
...@@ -37,7 +37,7 @@ Page({ ...@@ -37,7 +37,7 @@ Page({
} }
my.request({ my.request({
url: app.get_request_url("index", "coupon"), url: app.get_request_url("index", "index", "coupon"),
method: "POST", method: "POST",
data: {}, data: {},
dataType: "json", dataType: "json",
...@@ -112,7 +112,7 @@ Page({ ...@@ -112,7 +112,7 @@ Page({
if (temp_list[index]['is_operable'] != 0) { if (temp_list[index]['is_operable'] != 0) {
my.showLoading({ title: "处理中..." }); my.showLoading({ title: "处理中..." });
my.request({ my.request({
url: app.get_request_url("receive", "coupon"), url: app.get_request_url("receive", "coupon", "coupon"),
method: "POST", method: "POST",
data: { "coupon_id": value }, data: { "coupon_id": value },
dataType: "json", dataType: "json",
......
...@@ -803,7 +803,7 @@ Page({ ...@@ -803,7 +803,7 @@ Page({
if (temp_list[index]['is_operable'] != 0) { if (temp_list[index]['is_operable'] != 0) {
my.showLoading({ title: "处理中..." }); my.showLoading({ title: "处理中..." });
my.request({ my.request({
url: app.get_request_url("receive", "coupon"), url: app.get_request_url("receive", "coupon", "coupon"),
method: "POST", method: "POST",
data: { "coupon_id": value }, data: { "coupon_id": value },
dataType: "json", dataType: "json",
......
...@@ -54,7 +54,7 @@ Page({ ...@@ -54,7 +54,7 @@ Page({
} }
my.request({ my.request({
url: app.get_request_url("user", "coupon"), url: app.get_request_url("index", "coupon", "coupon"),
method: "POST", method: "POST",
data: {}, data: {},
dataType: "json", dataType: "json",
......
...@@ -153,21 +153,44 @@ App({ ...@@ -153,21 +153,44 @@ App({
return system_info; return system_info;
}, },
/**
/** /**
* 请求地址生成 * 请求地址生成
* a 方法
* c 控制器
* plugins 插件标记(传参则表示为插件请求)
* params url请求参数
*/ */
get_request_url(a, c, m, params) { get_request_url(a, c, plugins, params) {
a = a || "index"; a = a || "index";
c = c || "index"; c = c || "index";
m = m || "api";
// 是否插件请求
var plugins_params = "";
if ((plugins || null) != null)
{
plugins_params = "&pluginsname=" + plugins + "&pluginscontrol=" + c + "&pluginsaction=" + a;
// 走api统一插件调用控制器
c = "plugins"
a = "index"
}
// 参数处理
params = params || ""; params = params || "";
if (params != "" && params.substr(0, 1) != "&") { if (params != "" && params.substr(0, 1) != "&") {
params = "&" + params; params = "&" + params;
} }
// 用户信息
var user = this.get_user_cache_info(); var user = this.get_user_cache_info();
var token = user == false ? '' : user.token || ''; var token = (user == false) ? '' : user.token || '';
return this.data.request_url + "index.php?s=/" + m + "/" + c + "/" + a + "&application=app&application_client_type=baidu" + "&token=" + token + "&ajax=ajax" + params; return this.data.request_url +
"index.php?s=/api/" + c + "/" + a + plugins_params+
"&application=app&application_client_type=weixin" +
"&token=" +
token +
"&ajax=ajax" +
params;
}, },
/** /**
......
...@@ -37,7 +37,7 @@ Page({ ...@@ -37,7 +37,7 @@ Page({
} }
swan.request({ swan.request({
url: app.get_request_url("index", "coupon"), url: app.get_request_url("index", "index", "coupon"),
method: "POST", method: "POST",
data: {}, data: {},
dataType: "json", dataType: "json",
...@@ -109,7 +109,7 @@ Page({ ...@@ -109,7 +109,7 @@ Page({
if (temp_list[index]['is_operable'] != 0) { if (temp_list[index]['is_operable'] != 0) {
swan.showLoading({ title: "处理中..." }); swan.showLoading({ title: "处理中..." });
swan.request({ swan.request({
url: app.get_request_url("receive", "coupon"), url: app.get_request_url("receive", "coupon", "coupon"),
method: "POST", method: "POST",
data: { "coupon_id": value }, data: { "coupon_id": value },
dataType: "json", dataType: "json",
......
...@@ -732,7 +732,7 @@ Page({ ...@@ -732,7 +732,7 @@ Page({
if (temp_list[index]['is_operable'] != 0) { if (temp_list[index]['is_operable'] != 0) {
swan.showLoading({ title: "处理中..." }); swan.showLoading({ title: "处理中..." });
swan.request({ swan.request({
url: app.get_request_url("receive", "coupon"), url: app.get_request_url("receive", "coupon", "coupon"),
method: "POST", method: "POST",
data: { "coupon_id": value }, data: { "coupon_id": value },
dataType: "json", dataType: "json",
......
...@@ -50,7 +50,7 @@ Page({ ...@@ -50,7 +50,7 @@ Page({
} }
swan.request({ swan.request({
url: app.get_request_url("user", "coupon"), url: app.get_request_url("index", "coupon", "coupon"),
method: "POST", method: "POST",
data: {}, data: {},
dataType: "json", dataType: "json",
......
...@@ -129,29 +129,44 @@ App({ ...@@ -129,29 +129,44 @@ App({
return system_info; return system_info;
}, },
/**
/** /**
* 请求地址生成 * 请求地址生成
* a 方法
* c 控制器
* plugins 插件标记(传参则表示为插件请求)
* params url请求参数
*/ */
get_request_url(a, c, m, params) { get_request_url(a, c, plugins, params) {
a = a || "index"; a = a || "index";
c = c || "index"; c = c || "index";
m = m || "api";
// 是否插件请求
var plugins_params = "";
if ((plugins || null) != null)
{
plugins_params = "&pluginsname=" + plugins + "&pluginscontrol=" + c + "&pluginsaction=" + a;
// 走api统一插件调用控制器
c = "plugins"
a = "index"
}
// 参数处理
params = params || ""; params = params || "";
if (params != "" && params.substr(0, 1) != "&") { if (params != "" && params.substr(0, 1) != "&") {
params = "&" + params; params = "&" + params;
} }
// 用户信息
var user = this.get_user_cache_info(); var user = this.get_user_cache_info();
var token = (user == false) ? '' : user.token || ''; var token = (user == false) ? '' : user.token || '';
return ( return this.data.request_url +
this.data.request_url + "index.php?s=/api/" + c + "/" + a + plugins_params+
"index.php?s=/" + m + "/" + c + "/" + a + "&application=app&application_client_type=weixin" +
"&application=app&application_client_type=qq" +
"&token=" + "&token=" +
token + token +
"&ajax=ajax" + "&ajax=ajax" +
params params;
);
}, },
/** /**
......
...@@ -37,7 +37,7 @@ Page({ ...@@ -37,7 +37,7 @@ Page({
} }
qq.request({ qq.request({
url: app.get_request_url("index", "coupon"), url: app.get_request_url("index", "index", "coupon"),
method: "POST", method: "POST",
data: {}, data: {},
dataType: "json", dataType: "json",
...@@ -110,7 +110,7 @@ Page({ ...@@ -110,7 +110,7 @@ Page({
if (temp_list[index]['is_operable'] != 0) { if (temp_list[index]['is_operable'] != 0) {
qq.showLoading({ title: "处理中..." }); qq.showLoading({ title: "处理中..." });
qq.request({ qq.request({
url: app.get_request_url("receive", "coupon"), url: app.get_request_url("receive", "coupon", "coupon"),
method: "POST", method: "POST",
data: { "coupon_id": value }, data: { "coupon_id": value },
dataType: "json", dataType: "json",
......
...@@ -843,7 +843,7 @@ Page({ ...@@ -843,7 +843,7 @@ Page({
if (temp_list[index]['is_operable'] != 0) { if (temp_list[index]['is_operable'] != 0) {
qq.showLoading({ title: "处理中..." }); qq.showLoading({ title: "处理中..." });
qq.request({ qq.request({
url: app.get_request_url("receive", "coupon"), url: app.get_request_url("receive", "coupon", "coupon"),
method: "POST", method: "POST",
data: { "coupon_id": value }, data: { "coupon_id": value },
dataType: "json", dataType: "json",
......
...@@ -54,7 +54,7 @@ Page({ ...@@ -54,7 +54,7 @@ Page({
} }
qq.request({ qq.request({
url: app.get_request_url("user", "coupon"), url: app.get_request_url("index", "coupon", "coupon"),
method: "POST", method: "POST",
data: {}, data: {},
dataType: "json", dataType: "json",
......
...@@ -129,29 +129,44 @@ App({ ...@@ -129,29 +129,44 @@ App({
return system_info; return system_info;
}, },
/**
/** /**
* 请求地址生成 * 请求地址生成
* a 方法
* c 控制器
* plugins 插件标记(传参则表示为插件请求)
* params url请求参数
*/ */
get_request_url(a, c, m, params) { get_request_url(a, c, plugins, params) {
a = a || "index"; a = a || "index";
c = c || "index"; c = c || "index";
m = m || "api";
// 是否插件请求
var plugins_params = "";
if ((plugins || null) != null)
{
plugins_params = "&pluginsname=" + plugins + "&pluginscontrol=" + c + "&pluginsaction=" + a;
// 走api统一插件调用控制器
c = "plugins"
a = "index"
}
// 参数处理
params = params || ""; params = params || "";
if (params != "" && params.substr(0, 1) != "&") { if (params != "" && params.substr(0, 1) != "&") {
params = "&" + params; params = "&" + params;
} }
// 用户信息
var user = this.get_user_cache_info(); var user = this.get_user_cache_info();
var token = (user == false) ? '' : user.token || ''; var token = (user == false) ? '' : user.token || '';
return ( return this.data.request_url +
this.data.request_url + "index.php?s=/api/" + c + "/" + a + plugins_params+
"index.php?s=/" + m + "/" + c + "/" + a + "&application=app&application_client_type=weixin" +
"&application=app&application_client_type=toutiao" +
"&token=" + "&token=" +
token + token +
"&ajax=ajax" + "&ajax=ajax" +
params params;
);
}, },
/** /**
......
...@@ -37,7 +37,7 @@ Page({ ...@@ -37,7 +37,7 @@ Page({
} }
tt.request({ tt.request({
url: app.get_request_url("index", "coupon"), url: app.get_request_url("index", "index", "coupon"),
method: "POST", method: "POST",
data: {}, data: {},
dataType: "json", dataType: "json",
...@@ -110,7 +110,7 @@ Page({ ...@@ -110,7 +110,7 @@ Page({
if (temp_list[index]['is_operable'] != 0) { if (temp_list[index]['is_operable'] != 0) {
tt.showLoading({ title: "处理中..." }); tt.showLoading({ title: "处理中..." });
tt.request({ tt.request({
url: app.get_request_url("receive", "coupon"), url: app.get_request_url("receive", "coupon", "coupon"),
method: "POST", method: "POST",
data: { "coupon_id": value }, data: { "coupon_id": value },
dataType: "json", dataType: "json",
......
...@@ -843,7 +843,7 @@ Page({ ...@@ -843,7 +843,7 @@ Page({
if (temp_list[index]['is_operable'] != 0) { if (temp_list[index]['is_operable'] != 0) {
tt.showLoading({ title: "处理中..." }); tt.showLoading({ title: "处理中..." });
tt.request({ tt.request({
url: app.get_request_url("receive", "coupon"), url: app.get_request_url("receive", "coupon", "coupon"),
method: "POST", method: "POST",
data: { "coupon_id": value }, data: { "coupon_id": value },
dataType: "json", dataType: "json",
......
...@@ -54,7 +54,7 @@ Page({ ...@@ -54,7 +54,7 @@ Page({
} }
tt.request({ tt.request({
url: app.get_request_url("user", "coupon"), url: app.get_request_url("index", "coupon", "coupon"),
method: "POST", method: "POST",
data: {}, data: {},
dataType: "json", dataType: "json",
......
...@@ -67,7 +67,7 @@ App({ ...@@ -67,7 +67,7 @@ App({
// 请求地址 // 请求地址
request_url: "{{request_url}}", request_url: "{{request_url}}",
// request_url: 'http://tp5-dev.com/', // request_url: 'http://shopxo.com/',
// request_url: 'https://dev.shopxo.net/', // request_url: 'https://dev.shopxo.net/',
// 基础信息 // 基础信息
...@@ -129,29 +129,44 @@ App({ ...@@ -129,29 +129,44 @@ App({
return system_info; return system_info;
}, },
/**
/** /**
* 请求地址生成 * 请求地址生成
* a 方法
* c 控制器
* plugins 插件标记(传参则表示为插件请求)
* params url请求参数
*/ */
get_request_url(a, c, m, params) { get_request_url(a, c, plugins, params) {
a = a || "index"; a = a || "index";
c = c || "index"; c = c || "index";
m = m || "api";
// 是否插件请求
var plugins_params = "";
if ((plugins || null) != null)
{
plugins_params = "&pluginsname=" + plugins + "&pluginscontrol=" + c + "&pluginsaction=" + a;
// 走api统一插件调用控制器
c = "plugins"
a = "index"
}
// 参数处理
params = params || ""; params = params || "";
if (params != "" && params.substr(0, 1) != "&") { if (params != "" && params.substr(0, 1) != "&") {
params = "&" + params; params = "&" + params;
} }
// 用户信息
var user = this.get_user_cache_info(); var user = this.get_user_cache_info();
var token = (user == false) ? '' : user.token || ''; var token = (user == false) ? '' : user.token || '';
return ( return this.data.request_url +
this.data.request_url + "index.php?s=/api/" + c + "/" + a + plugins_params+
"index.php?s=/" + m + "/" + c + "/" + a +
"&application=app&application_client_type=weixin" + "&application=app&application_client_type=weixin" +
"&token=" + "&token=" +
token + token +
"&ajax=ajax" + "&ajax=ajax" +
params params;
);
}, },
/** /**
......
...@@ -37,7 +37,7 @@ Page({ ...@@ -37,7 +37,7 @@ Page({
} }
wx.request({ wx.request({
url: app.get_request_url("index", "coupon"), url: app.get_request_url("index", "index", "coupon"),
method: "POST", method: "POST",
data: {}, data: {},
dataType: "json", dataType: "json",
...@@ -110,7 +110,7 @@ Page({ ...@@ -110,7 +110,7 @@ Page({
if (temp_list[index]['is_operable'] != 0) { if (temp_list[index]['is_operable'] != 0) {
wx.showLoading({ title: "处理中..." }); wx.showLoading({ title: "处理中..." });
wx.request({ wx.request({
url: app.get_request_url("receive", "coupon"), url: app.get_request_url("receive", "coupon", "coupon"),
method: "POST", method: "POST",
data: { "coupon_id": value }, data: { "coupon_id": value },
dataType: "json", dataType: "json",
......
...@@ -854,7 +854,7 @@ Page({ ...@@ -854,7 +854,7 @@ Page({
if (temp_list[index]['is_operable'] != 0) { if (temp_list[index]['is_operable'] != 0) {
wx.showLoading({ title: "处理中..." }); wx.showLoading({ title: "处理中..." });
wx.request({ wx.request({
url: app.get_request_url("receive", "coupon"), url: app.get_request_url("receive", "coupon", "coupon"),
method: "POST", method: "POST",
data: { "coupon_id": value }, data: { "coupon_id": value },
dataType: "json", dataType: "json",
......
...@@ -54,7 +54,7 @@ Page({ ...@@ -54,7 +54,7 @@ Page({
} }
wx.request({ wx.request({
url: app.get_request_url("user", "coupon"), url: app.get_request_url("index", "coupon", "coupon"),
method: "POST", method: "POST",
data: {}, data: {},
dataType: "json", dataType: "json",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册