提交 a18dc4c8 编写于 作者: D devil_gong

微信小程序优化

上级 373157e6
......@@ -67,12 +67,16 @@ ThinkPHP是一个快速、简单的基于MVC和面向对象的轻量级PHP开发
站点配置
> 站点设置
> 基础配置
> 备案信息
> 站点类型
> 用户注册
> 用户登录
> 密码找回
> 附件
> 图片验证码
> 订单售后
> 搜索
> 扩展项
> 短信设置
> 短信设置
> 消息模板
......
......@@ -164,7 +164,14 @@ class User extends Common
$result = (new \base\Wechat(MyC('common_app_mini_weixin_appid'), MyC('common_app_mini_weixin_appsecret')))->GetAuthSessionKey($this->data_post['authcode']);
if($result !== false)
{
return DataReturn('授权登录成功', 0, $result);
// 先从数据库获取用户信息
$user = UserService::AppUserInfoHandle(null, 'weixin_openid', $result);
if(empty($user))
{
return DataReturn('授权登录成功', 0, ['is_alipay_user_exist'=>0, 'openid'=>$result]);
}
$user['is_alipay_user_exist'] = 1;
return DataReturn('授权登录成功', 0, $user);
}
return DataReturn('授权登录失败', -100);
}
......
......@@ -265,7 +265,7 @@ App({
} else {
my.setStorageSync({
key: self.data.cache_user_login_key,
data: res.data.data.openid
data: data.openid
});
self.login_to_auth();
}
......
......@@ -19,7 +19,7 @@ Page({
// 初始化
init() {
var user = app.get_user_cache_info(this, "init");
var user = app.get_user_info(this, "init");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
my.redirectTo({
......
......@@ -289,7 +289,7 @@ Page({
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
my.navigateTo({
url: "/pages/login/login?event_callback=init"
url: "/pages/login/login?event_callback=goods_favor_event"
});
return false;
} else {
......@@ -601,7 +601,7 @@ Page({
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
my.navigateTo({
url: "/pages/login/login?event_callback=init"
url: "/pages/login/login?event_callback=goods_buy_confirm_event"
});
return false;
} else {
......
......@@ -52,15 +52,22 @@ Page({
init() {
var user = app.get_user_info(this, "init");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
my.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
my.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
} else {
// 获取数据
this.get_data_list();
}
} else {
// 获取数据
this.get_data_list();
this.setData({
data_list_loding_status: 0,
data_bottom_line_status: false,
});
}
},
......
......@@ -68,7 +68,7 @@ App({
// 请求地址
request_url: "{{request_url}}",
request_url: 'http://tp5-dev.com/',
request_url: 'https://dev.shopxo.net/',
//request_url: 'https://dev.shopxo.net/',
// 基础信息
application_title: "{{application_title}}",
......@@ -154,6 +154,24 @@ App({
);
},
/**
* 获取用户信息,信息不存在则唤醒授权
* object 回调操作对象
* method 回调操作对象的函数
* return 有用户数据直接返回, 则回调调用者
*/
get_user_info(object, method) {
var user = this.get_user_cache_info();
if (user == false) {
// 唤醒用户授权
this.user_auth_login(object, method);
return false;
} else {
return user;
}
},
/**
* 从缓存获取用户信息
*/
......@@ -209,11 +227,28 @@ App({
header: { 'content-type': 'application/x-www-form-urlencoded' },
success: (res) => {
if (res.data.code == 0) {
wx.setStorage({
key: self.data.cache_user_login_key,
data: res.data.data
});
self.get_user_login_info(object, method, res.data.data, auth_data);
var data = res.data.data;
if ((data.is_alipay_user_exist || 0) == 1) {
wx.hideLoading();
wx.setStorage({
key: self.data.cache_user_info_key,
data: data,
success: (res) => {
if (typeof object === 'object' && (method || null) != null) {
object[method]();
}
},
fail: () => {
self.showToast('用户信息缓存失败');
}
});
} else {
wx.setStorage({
key: self.data.cache_user_login_key,
data: data
});
self.get_user_login_info(object, method, data, auth_data);
}
} else {
wx.hideLoading();
self.showToast(res.data.msg);
......
......@@ -13,13 +13,15 @@ Page({
// 初始化
init() {
var user = app.get_user_cache_info(this, "init");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
var user = app.get_user_info(this, "init");
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
}
}
},
......
......@@ -22,31 +22,39 @@ Page({
},
init(e) {
var user = app.get_user_cache_info(this, "init");
// 用户未绑定用户则转到登录页面
var msg = (user == false) ? '授权用户信息' : '绑定手机号码';
if (app.user_is_need_login(user)) {
wx.showModal({
title: '温馨提示',
content: msg,
confirmText: '确认',
cancelText: '暂不',
success: (result) => {
if (result.confirm) {
wx.navigateTo({
url: "/pages/login/login?event_callback=init"
});
} else {
this.setData({
data_list_loding_status: 0,
data_bottom_line_status: false,
data_list_loding_msg: '请先' + msg,
});
}
},
});
var user = app.get_user_info(this, "init");
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.showModal({
title: '温馨提示',
content: msg,
confirmText: '确认',
cancelText: '暂不',
success: (result) => {
if (result.confirm) {
wx.navigateTo({
url: "/pages/login/login?event_callback=init"
});
} else {
this.setData({
data_list_loding_status: 0,
data_bottom_line_status: false,
data_list_loding_msg: '请先' + msg,
});
}
},
});
} else {
this.get_data();
}
} else {
this.get_data();
wx.stopPullDownRefresh();
this.setData({
data_list_loding_status: 0,
data_bottom_line_status: false,
data_list_loding_msg: '请先授权用户信息',
});
}
},
......
......@@ -80,7 +80,7 @@ Page({
// 优惠劵领取事件
coupon_receive_event(e) {
var user = app.get_user_cache_info(this, "coupon_receive_event");
var user = app.get_user_info(this, "coupon_receive_event");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
......
......@@ -19,7 +19,7 @@ Page({
// 初始化
init() {
var user = app.get_user_cache_info(this, "init");
var user = app.get_user_info(this, "init");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
......
......@@ -288,81 +288,85 @@ Page({
// 收藏事件
goods_favor_event(e)
{
var user = app.get_user_cache_info(this, 'goods_favor_event');
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.navigateTo({
url: "/pages/login/login?event_callback=init"
});
return false;
} else {
wx.showLoading({title: '处理中...'});
var user = app.get_user_info(this, 'goods_favor_event');
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.navigateTo({
url: "/pages/login/login?event_callback=goods_favor_event"
});
return false;
} else {
wx.showLoading({title: '处理中...'});
wx.request({
url: app.get_request_url('favor', 'goods'),
method: 'POST',
data: {"id": this.data.goods.id},
dataType: 'json',
success: (res) => {
wx.hideLoading();
if(res.data.code == 0)
{
var status = (this.data.goods.is_favor == 1) ? 0 : 1;
this.setData({
'goods.is_favor': status,
goods_favor_text: (status == 1) ? '已收藏' : '收藏',
goods_favor_icon: '/images/goods-detail-favor-icon-'+status+'.png'
});
app.showToast(res.data.msg, "success");
} else {
if (app.is_login_check(res.data)) {
app.showToast(res.data.msg);
wx.request({
url: app.get_request_url('favor', 'goods'),
method: 'POST',
data: {"id": this.data.goods.id},
dataType: 'json',
success: (res) => {
wx.hideLoading();
if(res.data.code == 0)
{
var status = (this.data.goods.is_favor == 1) ? 0 : 1;
this.setData({
'goods.is_favor': status,
goods_favor_text: (status == 1) ? '已收藏' : '收藏',
goods_favor_icon: '/images/goods-detail-favor-icon-'+status+'.png'
});
app.showToast(res.data.msg, "success");
} else {
if (app.is_login_check(res.data)) {
app.showToast(res.data.msg);
}
}
}
},
fail: () => {
wx.hideLoading();
},
fail: () => {
wx.hideLoading();
app.showToast('服务器请求出错');
}
});
app.showToast('服务器请求出错');
}
});
}
}
},
// 加入购物车事件
goods_cart_event(e, spec) {
var user = app.get_user_cache_info(this, 'goods_buy_confirm_event');
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.navigateTo({
url: "/pages/login/login?event_callback=init"
});
return false;
} else {
wx.showLoading({title: '处理中...' });
wx.request({
url: app.get_request_url('save', 'cart'),
method: 'POST',
data: { "goods_id": this.data.goods.id, "stock": this.data.temp_buy_number, "spec": JSON.stringify(spec) },
dataType: 'json',
success: (res) => {
wx.hideLoading();
if (res.data.code == 0) {
this.setData({ quick_nav_cart_count: res.data.data});
this.popup_close_event();
app.showToast(res.data.msg, "success");
} else {
if (app.is_login_check(res.data)) {
app.showToast(res.data.msg);
goods_cart_event(spec) {
var user = app.get_user_info(this, 'goods_buy_confirm_event');
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.navigateTo({
url: "/pages/login/login?event_callback=goods_buy_confirm_event"
});
return false;
} else {
wx.showLoading({title: '处理中...' });
wx.request({
url: app.get_request_url('save', 'cart'),
method: 'POST',
data: { "goods_id": this.data.goods.id, "stock": this.data.temp_buy_number, "spec": JSON.stringify(spec) },
dataType: 'json',
success: (res) => {
wx.hideLoading();
if (res.data.code == 0) {
this.setData({ quick_nav_cart_count: res.data.data});
this.popup_close_event();
app.showToast(res.data.msg, "success");
} else {
if (app.is_login_check(res.data)) {
app.showToast(res.data.msg);
}
}
}
},
fail: () => {
wx.hideLoading();
},
fail: () => {
wx.hideLoading();
app.showToast('服务器请求出错');
}
});
app.showToast('服务器请求出错');
}
});
}
}
},
......@@ -598,61 +602,63 @@ Page({
// 确认
goods_buy_confirm_event(e) {
var user = app.get_user_cache_info(this, 'goods_buy_confirm_event');
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.navigateTo({
url: "/pages/login/login?event_callback=init"
});
return false;
} else {
// 属性
var temp_data = this.data.goods_specifications_choose;
var sku_count = temp_data.length;
var active_count = 0;
var spec = [];
if(sku_count > 0)
{
for(var i in temp_data)
var user = app.get_user_info(this, 'goods_buy_confirm_event');
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.navigateTo({
url: "/pages/login/login?event_callback=goods_buy_confirm_event"
});
return false;
} else {
// 属性
var temp_data = this.data.goods_specifications_choose;
var sku_count = temp_data.length;
var active_count = 0;
var spec = [];
if(sku_count > 0)
{
for(var k in temp_data[i]['value'])
for(var i in temp_data)
{
if((temp_data[i]['value'][k]['is_active'] || null) != null)
for(var k in temp_data[i]['value'])
{
active_count++;
spec.push({"type": temp_data[i]['name'], "value": temp_data[i]['value'][k]['name']});
if((temp_data[i]['value'][k]['is_active'] || null) != null)
{
active_count++;
spec.push({"type": temp_data[i]['name'], "value": temp_data[i]['value'][k]['name']});
}
}
}
if(active_count < sku_count)
{
app.showToast('请选择属性');
return false;
}
}
if(active_count < sku_count)
{
app.showToast('请选择属性');
return false;
}
}
// 操作类型
switch (this.data.buy_event_type) {
case 'buy' :
// 进入订单确认页面
var data = {
"buy_type": "goods",
"goods_id": this.data.goods.id,
"stock": this.data.temp_buy_number,
"spec": JSON.stringify(spec)
};
wx.navigateTo({
url: '/pages/buy/buy?data=' + JSON.stringify(data)
});
this.popup_close_event();
break;
// 操作类型
switch (this.data.buy_event_type) {
case 'buy' :
// 进入订单确认页面
var data = {
"buy_type": "goods",
"goods_id": this.data.goods.id,
"stock": this.data.temp_buy_number,
"spec": JSON.stringify(spec)
};
wx.navigateTo({
url: '/pages/buy/buy?data=' + JSON.stringify(data)
});
this.popup_close_event();
break;
case 'cart' :
this.goods_cart_event(e, spec);
break;
case 'cart' :
this.goods_cart_event(spec);
break;
default :
app.showToast("操作事件类型有误");
default :
app.showToast("操作事件类型有误");
}
}
}
},
......@@ -782,7 +788,7 @@ Page({
// 商品海报分享
poster_event() {
var user = app.get_user_cache_info(this, 'poster_event');
var user = app.get_user_info(this, 'poster_event');
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.navigateTo({
......@@ -817,10 +823,10 @@ Page({
// 优惠劵领取事件
coupon_receive_event(e) {
var user = app.get_user_cache_info(this, "coupon_receive_event");
var user = app.get_user_nifo(this, "coupon_receive_event");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
my.redirectTo({
url: "/pages/login/login?event_callback=coupon_receive_event"
});
return false;
......
......@@ -30,30 +30,19 @@ Page({
* 登录授权事件
*/
get_user_info_event(e) {
this.user_auth_code(null, null, e.detail);
this.user_auth_code(e.detail);
},
/**
* 用户授权
* object 回调操作对象
* method 回调操作对象的函数
* auth_data 授权数据
*/
user_auth_code(object, method, auth_data) {
// 请求授权接口
var self = this;
wx.getSetting({
success(res) {
if (!res.authSetting['scope.userInfo']) {
self.setData({ user: null});
} else {
app.user_auth_login(self, 'user_auth_back_event', auth_data);
}
},
fail: (e) => {
app.showToast("授权校验失败");
}
});
user_auth_code(auth_data) {
if ((auth_data.encryptedData || null) != null && (auth_data.iv || null) != null) {
app.user_auth_login(this, 'user_auth_back_event', auth_data);
} else {
app.showToast("授权失败");
}
},
/**
......
......@@ -14,16 +14,23 @@ Page({
},
init() {
var user = app.get_user_cache_info(this, "init");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
var user = app.get_user_info(this, "init");
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
} else {
// 获取数据
this.get_data_list();
}
} else {
// 获取数据
this.get_data_list();
this.setData({
data_list_loding_status: 0,
data_bottom_line_status: false,
});
}
},
......
......@@ -37,22 +37,33 @@ Page({
},
init() {
var user = app.get_user_cache_info(this, "init");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
} else {
// 获取地址数据
if((this.data.params.id || null) != null)
{
this.get_user_address();
}
var user = app.get_user_info(this, "init");
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
this.setData({
data_list_loding_status: 2,
data_list_loding_msg: '请先绑定手机号码',
});
return false;
} else {
// 获取地址数据
if((this.data.params.id || null) != null)
{
this.get_user_address();
}
// 获取省
this.get_province_list();
// 获取省
this.get_province_list();
}
} else {
this.setData({
data_list_loding_status: 2,
data_list_loding_msg: '请先授权用户信息',
});
}
},
......
......@@ -19,16 +19,23 @@ Page({
// 初始化
init() {
var user = app.get_user_cache_info(this, "init");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
var user = app.get_user_info(this, "init");
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
} else {
// 获取数据
this.get_data_list();
}
} else {
// 获取数据
this.get_data_list();
this.setData({
data_list_loding_status: 0,
data_bottom_line_status: false,
});
}
},
......
......@@ -16,16 +16,23 @@ Page({
},
init() {
var user = app.get_user_cache_info(this, "init");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
var user = app.get_user_info(this, "init");
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
} else {
// 获取数据
this.get_data_list();
}
} else {
// 获取数据
this.get_data_list();
this.setData({
data_list_loding_status: 0,
data_bottom_line_status: false,
});
}
},
......
......@@ -23,7 +23,7 @@ Page({
},
init() {
var user = app.get_user_cache_info(this, "init");
var user = app.get_user_info(this, "init");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
......
......@@ -14,16 +14,23 @@ Page({
},
init() {
var user = app.get_user_cache_info(this, "init");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
var user = app.get_user_info(this, "init");
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
} else {
// 获取数据
this.get_data_list();
}
} else {
// 获取数据
this.get_data_list();
this.setData({
data_list_loding_status: 0,
data_bottom_line_status: false,
});
}
},
......
......@@ -14,16 +14,23 @@ Page({
},
init() {
var user = app.get_user_cache_info(this, "init");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
var user = app.get_user_info(this, "init");
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
} else {
// 获取数据
this.get_data_list();
}
} else {
// 获取数据
this.get_data_list();
this.setData({
data_list_loding_status: 0,
data_bottom_line_status: false,
});
}
},
......
......@@ -14,16 +14,23 @@ Page({
},
init() {
var user = app.get_user_cache_info(this, "init");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
var user = app.get_user_info(this, "init");
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
} else {
// 获取数据
this.get_data_list();
}
} else {
// 获取数据
this.get_data_list();
this.setData({
data_list_loding_status: 0,
data_bottom_line_status: false,
});
}
},
......
......@@ -49,16 +49,23 @@ Page({
},
init() {
var user = app.get_user_cache_info(this, "init");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
var user = app.get_user_info(this, 'init');
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
} else {
// 获取数据
this.get_data_list();
}
} else {
// 获取数据
this.get_data_list();
this.setData({
data_list_loding_status: 0,
data_bottom_line_status: false,
});
}
},
......
......@@ -51,16 +51,23 @@ Page({
},
init() {
var user = app.get_user_cache_info(this, "init");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
var user = app.get_user_info(this, "init");
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.redirectTo({
url: "/pages/login/login?event_callback=init"
});
return false;
} else {
// 获取数据
this.get_data_list();
}
} else {
// 获取数据
this.get_data_list();
this.setData({
data_list_loding_status: 0,
data_bottom_line_status: false,
});
}
},
......
......@@ -33,31 +33,32 @@ Page({
},
init(e) {
var user = app.get_user_cache_info(this, "init"),
self = this;
// 用户未绑定用户则转到登录页面
var msg = (user == false) ? '授权用户信息' : '绑定手机号码';
if (app.user_is_need_login(user)) {
wx.showModal({
title: '温馨提示',
content: msg,
confirmText: '确认',
cancelText: '暂不',
success: (result) => {
wx.stopPullDownRefresh();
if(result.confirm) {
wx.navigateTo({
url: "/pages/login/login?event_callback=init"
var user = app.get_user_info(this, "init"),
self = this;
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.showModal({
title: '温馨提示',
content: '绑定手机号码',
confirmText: '确认',
cancelText: '暂不',
success: (result) => {
wx.stopPullDownRefresh();
if(result.confirm) {
wx.navigateTo({
url: "/pages/login/login?event_callback=init"
});
}
self.setData({
avatar: user.avatar || app.data.default_user_head_src,
nickname: user.user_name_view || '用户名',
});
}
self.setData({
avatar: user.avatar || app.data.default_user_head_src,
nickname: user.user_name_view || '用户名',
});
},
});
} else {
self.get_data();
},
});
} else {
self.get_data();
}
}
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册