index.js 9.5 KB

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