123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- let Parse = getApp().Parse;
- const company = getApp().globalData.company
- const util = require('../../../../../utils/util.js')
- const dateF = require('../../../../../utils/date')
- const req = require('../../../../../utils/request')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- time: null,
- store: null,
- merchant: null,
- totalCount: 0,
- todayCount: 0,
- totalPrice: 0,
- todayPrice: 0,
- uid: null,
- profit: 0, //分润
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- uid: wx.getStorageSync('merchant')?.objectId
- })
- console.log(options)
- var TIME = util.formatTime(new Date()); //当前时间
- console.log(TIME);
- let time = dateF.formatTime("YYYY-mm-dd", TIME)
- this.setData({
- time: time
- });
- let merchant = wx.getStorageSync('merchant'); //用户
- this.setData({
- merchant: merchant
- })
- if (!merchant) {
- wx.redirectTo({
- url: '/nova-tourism/pages/my/merchant/login/index'
- });
- }
- this.refersh()
- },
- async refersh() {
- await this.getShopStore()
- if (!this.data.store?.objectId) return
- this.getProfit()
- await this.getShopOrder(this.data.store?.objectId)
- await this.getTodayOrder(this.data.store?.objectId)
- },
- /**获取店铺 */
- async getShopStore() {
- let ShopStore = new Parse.Query('ShopStore')
- ShopStore.equalTo('company', company)
- ShopStore.equalTo('user', this.data.merchant.objectId)
- let shopStore = await ShopStore.first()
- if (shopStore && shopStore.id) {
- let id = shopStore.toJSON().objectId
- await this.setData({
- store: shopStore.toJSON()
- })
- } else {
- wx.setStorageSync('store', undefined)
- wx.setStorageSync('merchant', undefined)
- }
- },
- /**获取当前商户分润金额 */
- async getProfit() {
- let store_uid = wx.getStorageSync('merchant')?.objectId
- if (!store_uid) return
- let sql = `WITH t1 AS(--当前商户所绑定的用户
- SELECT u."objectId" FROM "_User" u
- LEFT JOIN "ShopStore" s ON s."objectId" = u."store"
- WHERE s."user" = '${store_uid}'--当前店长uid
- )
- SELECT SUM((spec.value::json->>'invite-1')::FLOAT)
- FROM "RoomOrder" o,
- jsonb_each(o."incomeMap") AS spec (key, value)
- WHERE o."company"='${company}'
- AND o."isDeleted" IS NOT TRUE
- AND o."isPay" IS TRUE
- AND o."user" IN (SELECT "objectId" FROM t1)`
- let data = await req.customSQL(sql)
- console.log(data)
- let profit = data[0]?.sum || 0
- await this.setData({
- profit
- })
- this.getWithdraw()
- },
- /**可提现金额=获取当前商户分润金额-申请提现金额 */
- async getWithdraw() {
- let sql = `select sum("count") as "withdraw" from "UserAgentWithdraw"
- where "company" = '${company}' and "user" = '${this.data.merchant.objectId}'
- and "isDeleted" is not true
- group by "user"`
- let data = await req.customSQL(sql)
- if (data && data.length > 0) {
- // console.log(((this.data.profit||0)*1000 - (data[0].withdraw||0)*1000)/1000)
- this.setData({
- earnings: (this.data.profit - data[0].withdraw).toFixed(5)
- })
- } else {
- this.setData({
- earnings: this.data.profit
- })
- }
- console.log(this.data.earnings)
- },
- /**获取累计订单数据 */
- async getShopOrder(id) {
- /**民宿订单sql */
- let sql = ''
- if (this.data.store.type == 'stay') {
- sql = `select count("objectId") as "count", sum("price") as "totalPrice" from "RoomOrder"
- where "company" = '${company}' and "shopStore" = '${id}' and "isPay" = true and "isDeleted" is not true
- group by "shopStore"`
- } else {
- sql = `select count("objectId") as "count", sum("totalPrice") as "totalPrice" from "ShopOrder"
- where "company" = '${company}' and "shopStore" = '${id}' and "status" <> 100
- group by "shopStore"`
- }
- let data = await req.customSQL(sql)
- let gift_sql = `select count("objectId") as "count", sum("totalPrice") as "totalPrice" from "Order"
- where "company" = '${company}' and "store" = '${id}' and "isPay" = true and "isDeleted" is not true
- group by "store"`
- let gift_data = await req.customSQL(gift_sql)
- let totalCount = parseFloat(data[0]?.count || 0) + parseFloat(gift_data[0]?.count || 0)
- let totalPrice = ((parseFloat(data[0]?.totalPrice || 0) * 1000) + (parseFloat(gift_data[0]?.totalPrice || 0) * 1000)) / 1000
- this.setData({
- totalCount:totalCount||0,
- totalPrice:totalPrice||0,
- room_count: parseFloat(data[0]?.count || 0),
- room_totalPrice: parseFloat(data[0]?.totalPrice || 0),
- gift_count: parseFloat(gift_data[0]?.count || 0),
- gift_totalPrice: parseFloat(gift_data[0]?.totalPrice || 0),
- })
- },
- /** 获取今日订单数据*/
- async getTodayOrder(id) {
- var TIME = util.formatTime(new Date()); //当前时间
- console.log(TIME);
- let time = dateF.formatTime("YYYY-mm-dd 00:00:10", TIME)
- console.log(time);
- let sql = ''
- if (this.data.store.type == 'stay') {
- sql = `select count("objectId") as "count", sum("price") as "totalPrice" from "RoomOrder"
- where "company" = '${company}' and "shopStore" = '${id}' and "isPay" = true and "createdAt" > '${time}'
- group by "shopStore"`
- } else {
- sql = `select count("objectId") as "count", sum("price") as "totalPrice" from "ShopOrder"
- where "company" = '${company}' and "shopStore" = '${id}' and "status" <> 100 and "createdAt" > '${time}'
- group by "shopStore"`
- }
- let data = await req.customSQL(sql)
- let gift_sql = `select count("objectId") as "count", sum("totalPrice") as "totalPrice" from "Order"
- where "company" = '${company}' and "store" = '${id}' and "isPay" = true and "createdAt" > '${time}' and "isDeleted" is not true
- group by "store"`
- let gift_data = await req.customSQL(gift_sql)
- let todayCount = parseFloat(data[0]?.count || 0) + parseFloat(gift_data[0]?.count || 0)
- let todayPrice = ((parseFloat(data[0]?.totalPrice || 0) * 1000) + (parseFloat(gift_data[0]?.totalPrice || 0) * 1000)) / 1000
- this.setData({
- todayCount:todayCount||0,
- todayPrice:todayPrice||0,
- room_todayCount: parseFloat(data[0]?.count || 0),
- room_todayPrice: parseFloat(data[0]?.totalPrice || 0),
- gift_todayCount: parseFloat(gift_data[0]?.count || 0),
- gift_todayPrice: parseFloat(gift_data[0]?.totalPrice || 0),
- })
- },
- // orderlist() {
- // let storeId = this.data.store.objectId
- // wx.navigateTo({
- // url: '../merchant-home/order-list/index?storeId=' + storeId
- // });
- // },
- //民宿
- order2list() {
- let storeId = this.data.store.objectId
- wx.navigateTo({
- url: '../merchant-home/order2-list/index?storeId=' + storeId
- });
- },
- giftOrder2list() {
- let storeId = this.data.store.objectId
- wx.navigateTo({
- url: '../merchant-home/gift-order/index?storeId=' + storeId
- });
- },
- // order3list() {
- // let storeId = this.data.store.objectId
- // wx.navigateTo({
- // url: '../merchant-home/order3-list/index?storeId=' + storeId
- // });
- // },
- // goods() {
- // let id = this.data.store.objectId
- // wx.navigateTo({
- // url: '/nova-tourism/pages/my/merchant/merchant-home/goods/index?id=' + id
- // });
- // },
- logout() {
- wx.showModal({
- title: '确认要退出吗?',
- showCancel: true,
- success(res) {
- if (res.confirm) {
- wx.removeStorageSync('merchant')
- wx.removeStorageSync('store')
- wx.navigateTo({
- url: '../../../../pages/index/index'
- })
- } else {
- }
- }
- })
- },
- package() {
- wx.navigateTo({
- url: '/nova-tourism/pages/my/merchant/merchant-home/package/index'
- });
- },
- dishes() {
- let id = this.data.store.objectId
- wx.navigateTo({
- url: '/nova-tourism/pages/my/merchant/merchant-home/dishes/index?id=' + id
- });
- },
- tables() {
- let id = this.data.store.objectId
- wx.navigateTo({
- url: '/nova-tourism/pages/my/merchant/merchant-home/tables/index?id=' + id
- });
- },
- // category() {
- // let id = this.data.store.objectId
- // let type = this.data.store.type
- // wx.navigateTo({
- // url: `/nova-tourism/pages/my/merchant/merchant-home/category/index?id=${id}&&type=${type}`
- // });
- // },
- goodmanage() {
- wx.navigateTo({
- url: '../good/good-list/index'
- });
- },
- roommanage() {
- wx.navigateTo({
- url: '../room-manage/index'
- });
- },
- account() {
- wx.navigateTo({
- url: '../merchant-home/account/index'
- });
- },
- comments() {
- switch (this.data.store.type) {
- case 'stay':
- wx.navigateTo({
- url: '../../merchant/comments/hotel/index'
- });
- break;
- case 'catering':
- wx.navigateTo({
- url: '/nova-tourism/pages/my/merchant/comments/setmeal/index'
- });
- break;
- case 'shop':
- wx.navigateTo({
- url: '/nova-tourism/pages/my/merchant/comments/setmeal/index'
- });
- break;
- default:
- break;
- }
- },
- async codeVerify() {
- console.log(this.data.store.type);
- let that = this
- wx.scanCode({
- success(res) {
- let content = res.result
- console.log(content)
- let code1 = content || content.match(/\id=(.*)/)[1]
- console.log(code1);
- switch (that.data.store.type) {
- case 'stay':
- wx.navigateTo({
- url: `../code-verify/index?id=${code1}`
- });
- break;
- case 'catering':
- wx.navigateTo({
- url: `/nova-tourism/pages/shop-admin/index?id=${code1}`
- });
- break;
- case 'shop':
- wx.navigateTo({
- url: `/nova-tourism/pages/shop-admin/index?id=${code1}`
- });
- break;
- default:
- break;
- }
- // wx.navigateTo({
- // url: `/nova-tourism/pages/my/merchant/code-verify/index?id=${res.id}`
- // });
- },
- fail(err) {
- console.log(err)
- wx.showToast({
- title: '扫码失败,请确认二维码信息正确',
- icon: 'none'
- })
- }
- })
- },
- toWithdraw() {
- let id = this.data.store.storeName
- wx.navigateTo({
- url: `../../merchant/merchant-home/store-withdraw/index?earnings=${this.data.profit||0}&&id=${id}`,
- })
- },
- gourl(e) {
- const url = e.currentTarget.dataset.url;
- wx.navigateTo({
- url: `${url}`,
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- // this.getShopStore()
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|