index.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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: '/nova-tourism/pages/my/merchant/merchant-home/order-list/index?storeId=' + storeId
  124. });
  125. },
  126. order2list() {
  127. let storeId = this.data.store.objectId
  128. wx.navigateTo({
  129. url: '/nova-tourism/pages/my/merchant/merchant-home/order2-list/index?storeId=' + storeId
  130. });
  131. },
  132. order3list() {
  133. let storeId = this.data.store.objectId
  134. wx.navigateTo({
  135. url: '/nova-tourism/pages/my/merchant/merchant-home/order3-list/index?storeId=' + storeId
  136. });
  137. },
  138. goods() {
  139. let id = this.data.store.objectId
  140. wx.navigateTo({
  141. url: '/nova-tourism/pages/my/merchant/merchant-home/goods/index?id=' + id
  142. });
  143. },
  144. logout() {
  145. wx.showModal({
  146. title: '确认要退出吗?',
  147. showCancel: true,
  148. success(res) {
  149. if (res.confirm) {
  150. wx.removeStorageSync('merchant')
  151. wx.removeStorageSync('store')
  152. wx.navigateTo({
  153. url: '/nova-tourism/pages/index/index'
  154. })
  155. } else {
  156. }
  157. }
  158. })
  159. },
  160. package() {
  161. wx.navigateTo({
  162. url: '/nova-tourism/pages/my/merchant/merchant-home/package/index'
  163. });
  164. },
  165. dishes() {
  166. let id = this.data.store.objectId
  167. wx.navigateTo({
  168. url: '/nova-tourism/pages/my/merchant/merchant-home/dishes/index?id=' + id
  169. });
  170. },
  171. tables() {
  172. let id = this.data.store.objectId
  173. wx.navigateTo({
  174. url: '/nova-tourism/pages/my/merchant/merchant-home/tables/index?id=' + id
  175. });
  176. },
  177. category() {
  178. let id = this.data.store.objectId
  179. let type = this.data.store.type
  180. wx.navigateTo({
  181. url: `/nova-tourism/pages/my/merchant/merchant-home/category/index?id=${id}&&type=${type}`
  182. });
  183. },
  184. roommanage() {
  185. wx.navigateTo({
  186. url: '/nova-tourism/pages/my/merchant/room-manage/index'
  187. });
  188. },
  189. account() {
  190. wx.navigateTo({
  191. url: '/nova-tourism/pages/my/merchant/merchant-home/account/index'
  192. });
  193. },
  194. comments() {
  195. switch (this.data.store.type) {
  196. case 'stay':
  197. wx.navigateTo({
  198. url: '/nova-tourism/pages/my/merchant/comments/hotel/index'
  199. });
  200. break;
  201. case 'catering':
  202. wx.navigateTo({
  203. url: '/nova-tourism/pages/my/merchant/comments/setmeal/index'
  204. });
  205. break;
  206. case 'shop':
  207. wx.navigateTo({
  208. url: '/nova-tourism/pages/my/merchant/comments/setmeal/index'
  209. });
  210. break;
  211. default:
  212. break;
  213. }
  214. },
  215. async codeVerify() {
  216. console.log(this.data.store.type);
  217. let that = this
  218. wx.scanCode({
  219. success(res) {
  220. let content = res.result
  221. console.log(content)
  222. let code1 = content.match(/\id=(.*)/)[1]
  223. console.log(code1);
  224. switch (that.data.store.type) {
  225. case 'stay':
  226. wx.navigateTo({
  227. url: `/nova-tourism/pages/my/merchant/code-verify/index?id=${code1}`
  228. });
  229. break;
  230. case 'catering':
  231. wx.navigateTo({
  232. url: `/nova-tourism/pages/shop-admin/index?id=${code1}`
  233. });
  234. break;
  235. case 'shop':
  236. wx.navigateTo({
  237. url: `/nova-tourism/pages/shop-admin/index?id=${code1}`
  238. });
  239. break;
  240. default:
  241. break;
  242. }
  243. // wx.navigateTo({
  244. // url: `/nova-tourism/pages/my/merchant/code-verify/index?id=${res.id}`
  245. // });
  246. },
  247. fail(err) {
  248. console.log(err)
  249. wx.showToast({
  250. title: '扫码失败,请确认二维码信息正确',
  251. icon: 'none'
  252. })
  253. }
  254. })
  255. },
  256. toWithdraw() {
  257. let id = this.data.store.storeName
  258. wx.navigateTo({
  259. url: `/nova-tourism/pages/my/merchant/merchant-home/store-withdraw/index?earnings=${this.data.earnings}&&id=${id}`,
  260. })
  261. },
  262. /**
  263. * 生命周期函数--监听页面初次渲染完成
  264. */
  265. onReady: function () {
  266. },
  267. /**
  268. * 生命周期函数--监听页面显示
  269. */
  270. onShow: function () {
  271. },
  272. /**
  273. * 生命周期函数--监听页面隐藏
  274. */
  275. onHide: function () {
  276. },
  277. /**
  278. * 生命周期函数--监听页面卸载
  279. */
  280. onUnload: function () {
  281. },
  282. /**
  283. * 页面相关事件处理函数--监听用户下拉动作
  284. */
  285. onPullDownRefresh: function () {
  286. },
  287. /**
  288. * 页面上拉触底事件的处理函数
  289. */
  290. onReachBottom: function () {
  291. },
  292. /**
  293. * 用户点击右上角分享
  294. */
  295. onShareAppMessage: function () {
  296. }
  297. })