index.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. let Parse = getApp().Parse;
  2. const company = getApp().globalData.company
  3. const util = require('../../../../../utils/util.js')
  4. const dateF = require('../../../../../utils/date')
  5. const req = require('../../../../../utils/request')
  6. let uid = Parse.User.current()?.id
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. time: null,
  13. store: null,
  14. merchant: null,
  15. totalCount: 0,
  16. todayCount: 0,
  17. totalPrice: 0,
  18. todayPrice: 0,
  19. withdraw: 0,
  20. uid:null,
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. this.setData({uid:wx.getStorageSync('merchant')?.objectId||uid})
  27. console.log(options)
  28. var TIME = util.formatTime(new Date()); //当前时间
  29. console.log(TIME);
  30. let time = dateF.formatTime("YYYY-mm-dd", TIME)
  31. this.setData({
  32. time: time
  33. });
  34. let merchant = wx.getStorageSync('merchant'); //用户
  35. this.setData({ merchant: merchant })
  36. if (!merchant) {
  37. wx.redirectTo({
  38. url: '/nova-tourism/pages/my/merchant/login/index'
  39. });
  40. }
  41. this.getShopStore()
  42. },
  43. async getShopStore() {
  44. let ShopStore = new Parse.Query('ShopStore')
  45. ShopStore.equalTo('company', company)
  46. ShopStore.equalTo('user', this.data.merchant.objectId)
  47. let shopStore = await ShopStore.first()
  48. if (shopStore && shopStore.id) {
  49. let id = shopStore.toJSON().objectId
  50. this.setData({
  51. store: shopStore.toJSON()
  52. })
  53. console.log(this.data.store, 11111);
  54. await this.getShopOrder(id)
  55. await this.getTodayOrder(id)
  56. } else {
  57. wx.setStorageSync('store', undefined)
  58. wx.setStorageSync('merchant', undefined)
  59. }
  60. },
  61. async getShopOrder(id) {
  62. let sql = ''
  63. if (this.data.store.type == 'stay') {
  64. sql = `select count("objectId") as "count", sum("price") as "totalPrice" from "RoomOrder"
  65. where "company" = '${company}' and "shopStore" = '${id}' and "isPay" = true
  66. group by "shopStore"`
  67. } else {
  68. sql = `select count("objectId") as "count", sum("price") as "totalPrice" from "ShopOrder"
  69. where "company" = '${company}' and "shopStore" = '${id}' and "status" <> 100
  70. group by "shopStore"`
  71. }
  72. let data = await req.customSQL(sql)
  73. console.log(data)
  74. if (data && data.length > 0) {
  75. this.setData({
  76. totalCount: data[0].count,
  77. totalPrice: data[0].totalPrice,
  78. })
  79. }
  80. await this.getWithdraw()
  81. },
  82. async getWithdraw() {
  83. let sql = `select sum("count") as "withdraw" from "UserAgentWithdraw"
  84. where "company" = '${company}' and "user" = '${this.data.merchant.objectId}'
  85. group by "user"`
  86. let data = await req.customSQL(sql)
  87. console.log(data)
  88. if (data && data.length > 0) {
  89. this.setData({
  90. withdraw: data[0].withdraw,
  91. earnings: (this.data.totalPrice - data[0].withdraw).toFixed(2)
  92. })
  93. } else {
  94. this.setData({
  95. earnings: this.data.totalPrice
  96. })
  97. }
  98. console.log(this.data.earnings)
  99. },
  100. async getTodayOrder(id) {
  101. var TIME = util.formatTime(new Date()); //当前时间
  102. console.log(TIME);
  103. let time = dateF.formatTime("YYYY-mm-dd 00:00:10", TIME)
  104. console.log(time);
  105. let sql = ''
  106. if (this.data.store.type == 'stay') {
  107. sql = `select count("objectId") as "count", sum("price") as "totalPrice" from "RoomOrder"
  108. where "company" = '${company}' and "shopStore" = '${id}' and "isPay" = true and "createdAt" > '${time}'
  109. group by "shopStore"`
  110. } else {
  111. sql = `select count("objectId") as "count", sum("price") as "totalPrice" from "ShopOrder"
  112. where "company" = '${company}' and "shopStore" = '${id}' and "status" <> 100 and "createdAt" > '${time}'
  113. group by "shopStore"`
  114. }
  115. let data = await req.customSQL(sql)
  116. if (data && data.length > 0) {
  117. this.setData({
  118. todayCount: data[0].count,
  119. todayPrice: data[0].totalPrice,
  120. })
  121. }
  122. },
  123. // orderlist() {
  124. // let storeId = this.data.store.objectId
  125. // wx.navigateTo({
  126. // url: '../merchant-home/order-list/index?storeId=' + storeId
  127. // });
  128. // },
  129. //民宿
  130. order2list() {
  131. let storeId = this.data.store.objectId
  132. wx.navigateTo({
  133. url: '../merchant-home/order2-list/index?storeId=' + storeId
  134. });
  135. },
  136. // order3list() {
  137. // let storeId = this.data.store.objectId
  138. // wx.navigateTo({
  139. // url: '../merchant-home/order3-list/index?storeId=' + storeId
  140. // });
  141. // },
  142. // goods() {
  143. // let id = this.data.store.objectId
  144. // wx.navigateTo({
  145. // url: '/nova-tourism/pages/my/merchant/merchant-home/goods/index?id=' + id
  146. // });
  147. // },
  148. logout() {
  149. wx.showModal({
  150. title: '确认要退出吗?',
  151. showCancel: true,
  152. success(res) {
  153. if (res.confirm) {
  154. wx.removeStorageSync('merchant')
  155. wx.removeStorageSync('store')
  156. wx.navigateTo({
  157. url: '../../../../pages/index/index'
  158. })
  159. } else {
  160. }
  161. }
  162. })
  163. },
  164. package() {
  165. wx.navigateTo({
  166. url: '/nova-tourism/pages/my/merchant/merchant-home/package/index'
  167. });
  168. },
  169. dishes() {
  170. let id = this.data.store.objectId
  171. wx.navigateTo({
  172. url: '/nova-tourism/pages/my/merchant/merchant-home/dishes/index?id=' + id
  173. });
  174. },
  175. tables() {
  176. let id = this.data.store.objectId
  177. wx.navigateTo({
  178. url: '/nova-tourism/pages/my/merchant/merchant-home/tables/index?id=' + id
  179. });
  180. },
  181. // category() {
  182. // let id = this.data.store.objectId
  183. // let type = this.data.store.type
  184. // wx.navigateTo({
  185. // url: `/nova-tourism/pages/my/merchant/merchant-home/category/index?id=${id}&&type=${type}`
  186. // });
  187. // },
  188. goodmanage() {
  189. wx.navigateTo({
  190. url: '../good/good-list/index'
  191. });
  192. },
  193. roommanage() {
  194. wx.navigateTo({
  195. url: '../room-manage/index'
  196. });
  197. },
  198. account() {
  199. wx.navigateTo({
  200. url: '../merchant-home/account/index'
  201. });
  202. },
  203. comments() {
  204. switch (this.data.store.type) {
  205. case 'stay':
  206. wx.navigateTo({
  207. url: '../../merchant/comments/hotel/index'
  208. });
  209. break;
  210. case 'catering':
  211. wx.navigateTo({
  212. url: '/nova-tourism/pages/my/merchant/comments/setmeal/index'
  213. });
  214. break;
  215. case 'shop':
  216. wx.navigateTo({
  217. url: '/nova-tourism/pages/my/merchant/comments/setmeal/index'
  218. });
  219. break;
  220. default:
  221. break;
  222. }
  223. },
  224. async codeVerify() {
  225. console.log(this.data.store.type);
  226. let that = this
  227. wx.scanCode({
  228. success(res) {
  229. let content = res.result
  230. console.log(content)
  231. let code1 = content.match(/\id=(.*)/)[1]
  232. console.log(code1);
  233. switch (that.data.store.type) {
  234. case 'stay':
  235. wx.navigateTo({
  236. url: `../code-verify/index?id=${code1}`
  237. });
  238. break;
  239. case 'catering':
  240. wx.navigateTo({
  241. url: `/nova-tourism/pages/shop-admin/index?id=${code1}`
  242. });
  243. break;
  244. case 'shop':
  245. wx.navigateTo({
  246. url: `/nova-tourism/pages/shop-admin/index?id=${code1}`
  247. });
  248. break;
  249. default:
  250. break;
  251. }
  252. // wx.navigateTo({
  253. // url: `/nova-tourism/pages/my/merchant/code-verify/index?id=${res.id}`
  254. // });
  255. },
  256. fail(err) {
  257. console.log(err)
  258. wx.showToast({
  259. title: '扫码失败,请确认二维码信息正确',
  260. icon: 'none'
  261. })
  262. }
  263. })
  264. },
  265. toWithdraw() {
  266. let id = this.data.store.storeName
  267. wx.navigateTo({
  268. url: `../../merchant/merchant-home/store-withdraw/index?earnings=${this.data.earnings}&&id=${id}`,
  269. })
  270. },
  271. gourl(e) {
  272. const url = e.currentTarget.dataset.url;
  273. wx.navigateTo({
  274. url: `${url}`,
  275. });
  276. },
  277. /**
  278. * 生命周期函数--监听页面初次渲染完成
  279. */
  280. onReady: function () {
  281. },
  282. /**
  283. * 生命周期函数--监听页面显示
  284. */
  285. onShow: function () {
  286. this.getShopStore()
  287. },
  288. /**
  289. * 生命周期函数--监听页面隐藏
  290. */
  291. onHide: function () {
  292. },
  293. /**
  294. * 生命周期函数--监听页面卸载
  295. */
  296. onUnload: function () {
  297. },
  298. /**
  299. * 页面相关事件处理函数--监听用户下拉动作
  300. */
  301. onPullDownRefresh: function () {
  302. },
  303. /**
  304. * 页面上拉触底事件的处理函数
  305. */
  306. onReachBottom: function () {
  307. },
  308. /**
  309. * 用户点击右上角分享
  310. */
  311. onShareAppMessage: function () {
  312. }
  313. })