| @@ -1,34 +1,29 @@ | |||
| //app.js | |||
| let config = require('./config/config.js') | |||
| App({ | |||
| data: { | |||
| appId: '' | |||
| }, | |||
| onLaunch: function() { | |||
| onLaunch: function (options) { | |||
| var that = this; | |||
| that.globalData.sceneAddress = options.scene; | |||
| // 登录 | |||
| wx.login({ | |||
| success: res => { | |||
| console.log(res) | |||
| wx.request({ | |||
| url: 'https://ciformall.youlane.cn/C/api/user/login', | |||
| header: { | |||
| "content-type": "application/json;charset=UTF-8" | |||
| }, | |||
| url: config.api.login, | |||
| data: { | |||
| appId: "wx649b3be73c1afe47", | |||
| code: res.code | |||
| appId: config.weapp.AppId, | |||
| code: res.code, | |||
| sceneAddress: that.globalData.sceneAddress, | |||
| }, | |||
| method: 'POST', | |||
| success: (result)=>{ | |||
| console.log(result) | |||
| this.globalData.openId = result.data.data.openId | |||
| that.globalData.token = result.data.data.token; | |||
| console.log(that.globalData.token) | |||
| } | |||
| }) | |||
| // Http.postResquest('/api/user/login', '登录中', { | |||
| // appId: "wx649b3be73c1afe47", | |||
| // code: result.code | |||
| // }, (res) => { | |||
| // console.log(res) | |||
| // }) | |||
| } | |||
| }) | |||
| // 获取用户信息 | |||
| @@ -73,16 +68,15 @@ App({ | |||
| }) | |||
| }, | |||
| globalData: { | |||
| // 当前用户信息 | |||
| userInfo: null, | |||
| openId:null, | |||
| // token | |||
| token: null, | |||
| // 渠道 | |||
| sceneAddress: null, | |||
| // 二维码参数 | |||
| scene: null, | |||
| // 当前商场信息 | |||
| market: { | |||
| name: "陕西大悦城" | |||
| } | |||
| }, | |||
| getAppid() { | |||
| let appId = "wx649b3be73c1afe47" | |||
| return appId | |||
| } | |||
| }) | |||
| @@ -0,0 +1,180 @@ | |||
| const Promise = require('../utils/es6-promise.min').Promise | |||
| let config = require("../config/config.js"); | |||
| var app = getApp(); | |||
| const func = { | |||
| wxLogin: function (scene) { | |||
| return new Promise((resolve, reject) => { | |||
| wx.login({ | |||
| success: function (res) { | |||
| resolve(res) | |||
| }, | |||
| fail: function (err) { | |||
| reject(err) | |||
| }, | |||
| complete: function (res) { | |||
| //console.log("wxLogin complete:" + res) | |||
| } | |||
| }) | |||
| }) | |||
| }, | |||
| userLogin: function (code, source) { | |||
| return new Promise((resolve, reject) => { | |||
| wx.request({ | |||
| url: config.api.login, | |||
| data: { | |||
| appId: app.globalData.appId, | |||
| code: code, | |||
| scene: scene, | |||
| sceneAddress: sceneAddress | |||
| }, | |||
| method: "POST", | |||
| success: function (res) { | |||
| resolve(res) | |||
| }, | |||
| fail: function (err) { | |||
| reject(err) | |||
| }, | |||
| complete: function (res) { | |||
| //console.log("userLogin complete:" + res) | |||
| } | |||
| }) | |||
| }) | |||
| }, | |||
| /** | |||
| * 授权后获取用户的昵称,unionId等信息 | |||
| */ | |||
| getUserInfo: function (encryptedData, iv) { | |||
| console.log(app.globalData.openId) | |||
| return new Promise((resolve, reject) => { | |||
| wx.request({ | |||
| url: config.api.getUserInfo, | |||
| header: { | |||
| "content-type": "application/json;charset=UTF-8", | |||
| "token": app.globalData.token | |||
| }, | |||
| data: { | |||
| encryptedData: encryptedData, | |||
| iv: iv, | |||
| }, | |||
| method: "POST", | |||
| success: function (res) { | |||
| resolve(res) | |||
| }, | |||
| fail: function (err) { | |||
| reject(err) | |||
| }, | |||
| complete: function (res) { | |||
| //console.log("getUserInfo complete:" + res) | |||
| } | |||
| }) | |||
| }) | |||
| }, | |||
| /** | |||
| * 授权后获取用户的手机号 | |||
| */ | |||
| getUserPhone: function (encryptedData, iv) { | |||
| return new Promise((resolve, reject) => { | |||
| wx.request({ | |||
| url: config.api.getUserPhone + "?token=" + app.globalData.token, | |||
| data: { | |||
| encryptedData: encryptedData, | |||
| iv: iv, | |||
| }, | |||
| header: { | |||
| "content-type": "application/json;charset=UTF-8", | |||
| "token": app.globalData.token | |||
| }, | |||
| method: "POST", | |||
| success: function (res) { | |||
| resolve(res) | |||
| }, | |||
| fail: function (err) { | |||
| reject(err) | |||
| }, | |||
| complete: function (res) { | |||
| //console.log("getUserInfo complete:" + res) | |||
| } | |||
| }) | |||
| }) | |||
| }, | |||
| /** | |||
| * 优惠券查询 | |||
| */ | |||
| getCouponList: function (pageNum, pageSize) { | |||
| return new Promise((resolve, reject) => { | |||
| wx.request({ | |||
| url: config.api.couponList, | |||
| header: { | |||
| "content-type": "application/json;charset=UTF-8", | |||
| "token": app.globalData.token | |||
| }, | |||
| method: "Get", | |||
| data: { | |||
| pageNum: pageNum, | |||
| pageSize: pageSize | |||
| }, | |||
| success: function (res) { | |||
| resolve(res) | |||
| }, | |||
| fail: function (err) { | |||
| reject(err) | |||
| }, | |||
| complete: function (res) { | |||
| console.log(res) | |||
| } | |||
| }) | |||
| }) | |||
| }, | |||
| /** | |||
| * 优惠券详情 | |||
| */ | |||
| getCouponDetail: function (couponId) { | |||
| return new Promise((resolve, reject) => { | |||
| wx.request({ | |||
| url: config.api.couponDetail, | |||
| header: { | |||
| "content-type": "application/json;charset=UTF-8", | |||
| "token": app.globalData.token | |||
| }, | |||
| method: "Get", | |||
| data: { | |||
| id: couponId | |||
| }, | |||
| success: function (res) { | |||
| resolve(res) | |||
| }, | |||
| fail: function (err) { | |||
| reject(err) | |||
| }, | |||
| complete: function (res) { | |||
| console.log(res) | |||
| } | |||
| }) | |||
| }) | |||
| }, | |||
| /** | |||
| * 订单下单 | |||
| */ | |||
| orderSave: function (couponId) { | |||
| return new Promise((resolve, reject) => { | |||
| wx.request({ | |||
| url: config.api.orderSave, | |||
| header: { | |||
| "token": app.globalData.token | |||
| }, | |||
| method: "Post", | |||
| data: JSON.stringify({"couponId": couponId}), | |||
| success: function (res) { | |||
| resolve(res) | |||
| }, | |||
| fail: function (err) { | |||
| reject(err) | |||
| }, | |||
| complete: function (res) { | |||
| console.log(res) | |||
| } | |||
| }) | |||
| }) | |||
| }, | |||
| } | |||
| module.exports = func; | |||
| @@ -0,0 +1,42 @@ | |||
| var url = 'https://ciformall.youlane.cn' | |||
| //var url = 'http://localhost:8001' | |||
| var apiPrefix = url + '/C/'; | |||
| var config = { | |||
| name: "富茂", | |||
| api: { | |||
| /** | |||
| * 接口用途:login | |||
| */ | |||
| login: '/api/user/login', | |||
| /** | |||
| * 授权后获取用户的昵称,unionId等信息 | |||
| */ | |||
| getUserInfo: '/api/user/getUserInfo', | |||
| /** | |||
| * 接口用途:授权后获取用户的手机号 | |||
| */ | |||
| getUserPhone: '/api/user/getUserPhone', | |||
| /** | |||
| * 优惠券查询 | |||
| */ | |||
| couponList: '/wxCoupon/list', | |||
| /** | |||
| * 优惠券详情 | |||
| */ | |||
| couponDetail: '/wxCoupon/findById', | |||
| /** | |||
| * 下单 | |||
| */ | |||
| orderSave: '/wxOrder/save', | |||
| }, | |||
| weapp: { | |||
| AppId: 'wx649b3be73c1afe47', | |||
| } | |||
| }; | |||
| for (var key in config.api) { | |||
| config.api[key] = apiPrefix + config.api[key]; | |||
| } | |||
| module.exports = config; | |||
| @@ -1,35 +1,39 @@ | |||
| let Http = require('../../../utils/http.js') | |||
| let Common = require('../../../common/common.js') | |||
| var app = getApp() | |||
| Page({ | |||
| data: { | |||
| list:{}, | |||
| cuponId:null | |||
| couponId:null | |||
| }, | |||
| onLoad(e) { | |||
| console.log(e.id) | |||
| Http.getResquest('/wxCoupon/findById','加载中',{ | |||
| id: e.id | |||
| },(res)=>{ | |||
| Common.getCouponDetail(e.id) | |||
| .then(res =>{ | |||
| console.log(res) | |||
| this.setData({ | |||
| list: res.data, | |||
| cuponId:e.id | |||
| list: res.data.data, | |||
| couponId: e.id | |||
| }) | |||
| }) | |||
| }, | |||
| aaa(){ | |||
| Http.postResquest('/wxOrder/save', '加载中', { | |||
| couponId: this.data.cuponId, | |||
| openId: app.globalData.openId | |||
| }, (res) => { | |||
| wx.showLoading({ | |||
| title: '加载中...', | |||
| }) | |||
| Common.orderSave(''+this.data.couponId) | |||
| .then(res => { | |||
| wx.hideLoading(); | |||
| console.log(res) | |||
| if (res.code == 200) { | |||
| if (res.data.code == 200) { | |||
| wx.showToast({ | |||
| title: '购买成功', | |||
| }) | |||
| wx.navigateBack({ | |||
| delta: 2 | |||
| }) | |||
| setTimeout(() => { | |||
| wx.hideToast(); | |||
| }, 2000) | |||
| } | |||
| }) | |||
| } | |||
| @@ -1,5 +1,5 @@ | |||
| // pages/index/sw/index.js | |||
| let Common = require('../../../common/common.js') | |||
| let Http = require('../../../utils/http.js') | |||
| Component({ | |||
| /** | |||
| @@ -103,13 +103,11 @@ Component({ | |||
| }, | |||
| }, | |||
| ready(){ | |||
| Http.getResquest("/wxCoupon/list",'加载中',{ | |||
| "pageNum":1, | |||
| "pageSize":10 | |||
| },(res)=>{ | |||
| Common.getCouponList(1, 10) | |||
| .then(res=>{ | |||
| console.log(res) | |||
| this.setData({ | |||
| list:res.data.list | |||
| list: res.data.data.list | |||
| }) | |||
| }) | |||
| } | |||
| @@ -3,7 +3,6 @@ let app = getApp() | |||
| Page({ | |||
| data: { | |||
| appId: app.getAppid() | |||
| }, | |||
| onLoad() { | |||
| @@ -1,8 +1,5 @@ | |||
| let host = 'https://ciformall.youlane.cn/C'; | |||
| let openId="12313213"; | |||
| const postResquest = (url, message, postData, doSuccess, doFail) => { | |||
| const postResquest = (url, token, message, postData, doSuccess, doFail) => { | |||
| let body={...postData}; | |||
| body["openid"] = openId; | |||
| if (message != "") { | |||
| wx.showLoading({ | |||
| title: message, | |||
| @@ -10,9 +7,10 @@ const postResquest = (url, message, postData, doSuccess, doFail) => { | |||
| } | |||
| wx.request({ | |||
| //项目的真正接口,通过字符串拼接方式实现 | |||
| url: host + url, | |||
| url: url, | |||
| header: { | |||
| "content-type": "application/json;charset=UTF-8" | |||
| "content-type": "application/json;charset=UTF-8", | |||
| "token": token | |||
| }, | |||
| data: body, | |||
| method: 'POST', | |||
| @@ -33,18 +31,18 @@ const postResquest = (url, message, postData, doSuccess, doFail) => { | |||
| }, | |||
| }) | |||
| } | |||
| const getResquest = (url, message, getData, doSuccess, doFail) => { | |||
| const getResquest = (url, token, message, getData, doSuccess, doFail) => { | |||
| let body = { ...getData }; | |||
| body["openid"] = openId; | |||
| if (message != "") { | |||
| wx.showLoading({ | |||
| title: message, | |||
| }) | |||
| } | |||
| wx.request({ | |||
| url: host + url, | |||
| url: url, | |||
| header: { | |||
| "content-type": "application/json;charset=UTF-8" | |||
| "content-type": "application/json;charset=UTF-8", | |||
| "token": token | |||
| }, | |||
| data: body, | |||
| method: 'GET', | |||