index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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. uid: null,
  19. profit: 0, //分润
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. this.setData({
  26. uid: wx.getStorageSync('merchant')?.objectId
  27. })
  28. console.log(options)
  29. var TIME = util.formatTime(new Date()); //当前时间
  30. console.log(TIME);
  31. let time = dateF.formatTime("YYYY-mm-dd", TIME)
  32. this.setData({
  33. time: time
  34. });
  35. let merchant = wx.getStorageSync('merchant'); //用户
  36. this.setData({
  37. merchant: merchant
  38. })
  39. if (!merchant) {
  40. wx.redirectTo({
  41. url: '/nova-tourism/pages/my/merchant/login/index'
  42. });
  43. }
  44. this.refersh()
  45. },
  46. async refersh() {
  47. await this.getShopStore()
  48. if (!this.data.store?.objectId) return
  49. this.getProfit()
  50. await this.getShopOrder(this.data.store?.objectId)
  51. await this.getTodayOrder(this.data.store?.objectId)
  52. },
  53. /**获取店铺 */
  54. async getShopStore() {
  55. let ShopStore = new Parse.Query('ShopStore')
  56. ShopStore.equalTo('company', company)
  57. ShopStore.equalTo('user', this.data.merchant.objectId)
  58. let shopStore = await ShopStore.first()
  59. if (shopStore && shopStore.id) {
  60. let id = shopStore.toJSON().objectId
  61. await this.setData({
  62. store: shopStore.toJSON()
  63. })
  64. } else {
  65. wx.setStorageSync('store', undefined)
  66. wx.setStorageSync('merchant', undefined)
  67. }
  68. },
  69. /**获取当前商户分润金额 */
  70. async getProfit() {
  71. let store_uid = wx.getStorageSync('merchant')?.objectId
  72. if (!store_uid) return
  73. let sql = `WITH t1 AS(--当前商户所绑定的用户
  74. SELECT u."objectId" FROM "_User" u
  75. LEFT JOIN "ShopStore" s ON s."objectId" = u."store"
  76. WHERE s."user" = '${store_uid}'--当前店长uid
  77. )
  78. SELECT SUM((spec.value::json->>'invite-1')::FLOAT)
  79. FROM "RoomOrder" o,
  80. jsonb_each(o."incomeMap") AS spec (key, value)
  81. WHERE o."company"='${company}'
  82. AND o."isDeleted" IS NOT TRUE
  83. AND o."isPay" IS TRUE
  84. AND o."user" IN (SELECT "objectId" FROM t1)`
  85. let data = await req.customSQL(sql)
  86. console.log(data)
  87. let profit = data[0]?.sum || 0
  88. await this.setData({
  89. profit
  90. })
  91. this.getWithdraw()
  92. },
  93. /**可提现金额=获取当前商户分润金额-申请提现金额 */
  94. async getWithdraw() {
  95. let sql = `select sum("count") as "withdraw" from "UserAgentWithdraw"
  96. where "company" = '${company}' and "user" = '${this.data.merchant.objectId}'
  97. and "isDeleted" is not true
  98. group by "user"`
  99. let data = await req.customSQL(sql)
  100. if (data && data.length > 0) {
  101. // console.log(((this.data.profit||0)*1000 - (data[0].withdraw||0)*1000)/1000)
  102. this.setData({
  103. earnings: (this.data.profit - data[0].withdraw).toFixed(5)
  104. })
  105. } else {
  106. this.setData({
  107. earnings: this.data.profit
  108. })
  109. }
  110. console.log(this.data.earnings)
  111. },
  112. /**获取累计订单数据 */
  113. async getShopOrder(id) {
  114. /**民宿订单sql */
  115. let sql = ''
  116. if (this.data.store.type == 'stay') {
  117. sql = `select count("objectId") as "count", sum("price") as "totalPrice" from "RoomOrder"
  118. where "company" = '${company}' and "shopStore" = '${id}' and "isPay" = true and "isDeleted" is not true
  119. group by "shopStore"`
  120. } else {
  121. sql = `select count("objectId") as "count", sum("totalPrice") as "totalPrice" from "ShopOrder"
  122. where "company" = '${company}' and "shopStore" = '${id}' and "status" <> 100
  123. group by "shopStore"`
  124. }
  125. let data = await req.customSQL(sql)
  126. let gift_sql = `select count("objectId") as "count", sum("totalPrice") as "totalPrice" from "Order"
  127. where "company" = '${company}' and "store" = '${id}' and "isPay" = true and "isDeleted" is not true
  128. group by "store"`
  129. let gift_data = await req.customSQL(gift_sql)
  130. let totalCount = parseFloat(data[0]?.count || 0) + parseFloat(gift_data[0]?.count || 0)
  131. let totalPrice = ((parseFloat(data[0]?.totalPrice || 0) * 1000) + (parseFloat(gift_data[0]?.totalPrice || 0) * 1000)) / 1000
  132. this.setData({
  133. totalCount:totalCount||0,
  134. totalPrice:totalPrice||0,
  135. room_count: parseFloat(data[0]?.count || 0),
  136. room_totalPrice: parseFloat(data[0]?.totalPrice || 0),
  137. gift_count: parseFloat(gift_data[0]?.count || 0),
  138. gift_totalPrice: parseFloat(gift_data[0]?.totalPrice || 0),
  139. })
  140. },
  141. /** 获取今日订单数据*/
  142. async getTodayOrder(id) {
  143. var TIME = util.formatTime(new Date()); //当前时间
  144. console.log(TIME);
  145. let time = dateF.formatTime("YYYY-mm-dd 00:00:10", TIME)
  146. console.log(time);
  147. let sql = ''
  148. if (this.data.store.type == 'stay') {
  149. sql = `select count("objectId") as "count", sum("price") as "totalPrice" from "RoomOrder"
  150. where "company" = '${company}' and "shopStore" = '${id}' and "isPay" = true and "createdAt" > '${time}'
  151. group by "shopStore"`
  152. } else {
  153. sql = `select count("objectId") as "count", sum("price") as "totalPrice" from "ShopOrder"
  154. where "company" = '${company}' and "shopStore" = '${id}' and "status" <> 100 and "createdAt" > '${time}'
  155. group by "shopStore"`
  156. }
  157. let data = await req.customSQL(sql)
  158. let gift_sql = `select count("objectId") as "count", sum("totalPrice") as "totalPrice" from "Order"
  159. where "company" = '${company}' and "store" = '${id}' and "isPay" = true and "createdAt" > '${time}' and "isDeleted" is not true
  160. group by "store"`
  161. let gift_data = await req.customSQL(gift_sql)
  162. let todayCount = parseFloat(data[0]?.count || 0) + parseFloat(gift_data[0]?.count || 0)
  163. let todayPrice = ((parseFloat(data[0]?.totalPrice || 0) * 1000) + (parseFloat(gift_data[0]?.totalPrice || 0) * 1000)) / 1000
  164. this.setData({
  165. todayCount:todayCount||0,
  166. todayPrice:todayPrice||0,
  167. room_todayCount: parseFloat(data[0]?.count || 0),
  168. room_todayPrice: parseFloat(data[0]?.totalPrice || 0),
  169. gift_todayCount: parseFloat(gift_data[0]?.count || 0),
  170. gift_todayPrice: parseFloat(gift_data[0]?.totalPrice || 0),
  171. })
  172. },
  173. // orderlist() {
  174. // let storeId = this.data.store.objectId
  175. // wx.navigateTo({
  176. // url: '../merchant-home/order-list/index?storeId=' + storeId
  177. // });
  178. // },
  179. //民宿
  180. order2list() {
  181. let storeId = this.data.store.objectId
  182. wx.navigateTo({
  183. url: '../merchant-home/order2-list/index?storeId=' + storeId
  184. });
  185. },
  186. giftOrder2list() {
  187. let storeId = this.data.store.objectId
  188. wx.navigateTo({
  189. url: '../merchant-home/gift-order/index?storeId=' + storeId
  190. });
  191. },
  192. // order3list() {
  193. // let storeId = this.data.store.objectId
  194. // wx.navigateTo({
  195. // url: '../merchant-home/order3-list/index?storeId=' + storeId
  196. // });
  197. // },
  198. // goods() {
  199. // let id = this.data.store.objectId
  200. // wx.navigateTo({
  201. // url: '/nova-tourism/pages/my/merchant/merchant-home/goods/index?id=' + id
  202. // });
  203. // },
  204. logout() {
  205. wx.showModal({
  206. title: '确认要退出吗?',
  207. showCancel: true,
  208. success(res) {
  209. if (res.confirm) {
  210. wx.removeStorageSync('merchant')
  211. wx.removeStorageSync('store')
  212. wx.navigateTo({
  213. url: '../../../../pages/index/index'
  214. })
  215. } else {
  216. }
  217. }
  218. })
  219. },
  220. package() {
  221. wx.navigateTo({
  222. url: '/nova-tourism/pages/my/merchant/merchant-home/package/index'
  223. });
  224. },
  225. dishes() {
  226. let id = this.data.store.objectId
  227. wx.navigateTo({
  228. url: '/nova-tourism/pages/my/merchant/merchant-home/dishes/index?id=' + id
  229. });
  230. },
  231. tables() {
  232. let id = this.data.store.objectId
  233. wx.navigateTo({
  234. url: '/nova-tourism/pages/my/merchant/merchant-home/tables/index?id=' + id
  235. });
  236. },
  237. // category() {
  238. // let id = this.data.store.objectId
  239. // let type = this.data.store.type
  240. // wx.navigateTo({
  241. // url: `/nova-tourism/pages/my/merchant/merchant-home/category/index?id=${id}&&type=${type}`
  242. // });
  243. // },
  244. goodmanage() {
  245. wx.navigateTo({
  246. url: '../good/good-list/index'
  247. });
  248. },
  249. roommanage() {
  250. wx.navigateTo({
  251. url: '../room-manage/index'
  252. });
  253. },
  254. account() {
  255. wx.navigateTo({
  256. url: '../merchant-home/account/index'
  257. });
  258. },
  259. comments() {
  260. switch (this.data.store.type) {
  261. case 'stay':
  262. wx.navigateTo({
  263. url: '../../merchant/comments/hotel/index'
  264. });
  265. break;
  266. case 'catering':
  267. wx.navigateTo({
  268. url: '/nova-tourism/pages/my/merchant/comments/setmeal/index'
  269. });
  270. break;
  271. case 'shop':
  272. wx.navigateTo({
  273. url: '/nova-tourism/pages/my/merchant/comments/setmeal/index'
  274. });
  275. break;
  276. default:
  277. break;
  278. }
  279. },
  280. async codeVerify() {
  281. console.log(this.data.store.type);
  282. let that = this
  283. wx.scanCode({
  284. success(res) {
  285. let content = res.result
  286. console.log(content)
  287. let code1 = content || content.match(/\id=(.*)/)[1]
  288. console.log(code1);
  289. switch (that.data.store.type) {
  290. case 'stay':
  291. wx.navigateTo({
  292. url: `../code-verify/index?id=${code1}`
  293. });
  294. break;
  295. case 'catering':
  296. wx.navigateTo({
  297. url: `/nova-tourism/pages/shop-admin/index?id=${code1}`
  298. });
  299. break;
  300. case 'shop':
  301. wx.navigateTo({
  302. url: `/nova-tourism/pages/shop-admin/index?id=${code1}`
  303. });
  304. break;
  305. default:
  306. break;
  307. }
  308. // wx.navigateTo({
  309. // url: `/nova-tourism/pages/my/merchant/code-verify/index?id=${res.id}`
  310. // });
  311. },
  312. fail(err) {
  313. console.log(err)
  314. wx.showToast({
  315. title: '扫码失败,请确认二维码信息正确',
  316. icon: 'none'
  317. })
  318. }
  319. })
  320. },
  321. toWithdraw() {
  322. let id = this.data.store.storeName
  323. wx.navigateTo({
  324. url: `../../merchant/merchant-home/store-withdraw/index?earnings=${this.data.profit||0}&&id=${id}`,
  325. })
  326. },
  327. gourl(e) {
  328. const url = e.currentTarget.dataset.url;
  329. wx.navigateTo({
  330. url: `${url}`,
  331. });
  332. },
  333. /**
  334. * 生命周期函数--监听页面初次渲染完成
  335. */
  336. onReady: function () {
  337. },
  338. /**
  339. * 生命周期函数--监听页面显示
  340. */
  341. onShow: function () {
  342. // this.getShopStore()
  343. },
  344. /**
  345. * 生命周期函数--监听页面隐藏
  346. */
  347. onHide: function () {
  348. },
  349. /**
  350. * 生命周期函数--监听页面卸载
  351. */
  352. onUnload: function () {
  353. },
  354. /**
  355. * 页面相关事件处理函数--监听用户下拉动作
  356. */
  357. onPullDownRefresh: function () {
  358. },
  359. /**
  360. * 页面上拉触底事件的处理函数
  361. */
  362. onReachBottom: function () {
  363. },
  364. /**
  365. * 用户点击右上角分享
  366. */
  367. onShareAppMessage: function () {
  368. }
  369. })