附近小店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

154 lines
5.3 KiB

  1. package hdl
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. storeSvc "applet/app/store/svc"
  6. "applet/app/svc"
  7. "applet/app/utils"
  8. "fmt"
  9. "github.com/gin-gonic/gin"
  10. )
  11. func StoreIndexTotal(c *gin.Context) {
  12. var arg map[string]string
  13. if err := c.ShouldBindJSON(&arg); err != nil {
  14. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  15. return
  16. }
  17. user := svc.GetUser(c)
  18. stime, etime := svc.GetDate(c, arg)
  19. sql := `select SUM(amount-agent_commission-platform_commission) AS money,SUM(amount) AS amount,SUM(commission) AS commission,SUM(IF(state=3,1,0)) as count,SUM(IF(state in(1,2),1,0)) as success_count,
  20. SUM(IF(state=1,1,0)) as wait_count
  21. from community_team_order
  22. where %s
  23. `
  24. where := "store_uid=" + utils.IntToStr(user.Info.Uid) + " and state>0"
  25. wherePay := where + " and create_at>='" + stime.Format("2006-01-02 15:04:05") + "' and create_at<'" + etime.Format("2006-01-02 15:04:05") + "'"
  26. sqlPay := fmt.Sprintf(sql, wherePay)
  27. nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sqlPay)
  28. amount := "0"
  29. money := "0"
  30. commission := "0"
  31. count := "0"
  32. successCount := "0"
  33. waitCount := "0"
  34. for _, v := range nativeString {
  35. amount = v["amount"]
  36. money = v["money"]
  37. commission = v["commission"]
  38. count = v["count"]
  39. successCount = v["success_count"]
  40. waitCount = v["wait_count"]
  41. }
  42. sqlCodePay := `select SUM(amount-agent_commission-platform_commission) AS money,SUM(amount) AS amount,SUM(commission) AS commission,SUM(IF(state=3,1,0)) as count,SUM(IF(state in(1,2),1,0)) as success_count,
  43. SUM(IF(state=1,1,0)) as wait_count
  44. from community_team_pay_order
  45. where %s
  46. `
  47. whereCodePay := where + " and create_at>='" + stime.Format("2006-01-02 15:04:05") + "' and create_at<'" + etime.Format("2006-01-02 15:04:05") + "'"
  48. sqlCodePay = fmt.Sprintf(sqlCodePay, whereCodePay)
  49. nativeStringCodePay, _ := db.QueryNativeString(svc.MasterDb(c), sqlCodePay)
  50. for _, v := range nativeStringCodePay {
  51. amount = utils.Float64ToStr(utils.StrToFloat64(amount) + utils.StrToFloat64(v["amount"]))
  52. money = utils.Float64ToStr(utils.StrToFloat64(money) + utils.StrToFloat64(v["money"]))
  53. commission = utils.Float64ToStr(utils.StrToFloat64(commission) + utils.StrToFloat64(v["commission"]))
  54. count = utils.IntToStr(utils.StrToInt(count) + utils.StrToInt(v["count"]))
  55. successCount = utils.IntToStr(utils.StrToInt(successCount) + utils.StrToInt(v["success_count"]))
  56. }
  57. store := db.GetStoreIdEg(svc.MasterDb(c), utils.IntToStr(user.Info.Uid))
  58. tmp := []map[string]string{
  59. {"name": "营业总额", "value": svc.GetCommissionPrec(c, amount, "2", "1")},
  60. }
  61. if store.StoreType == 0 {
  62. tmp = append(tmp, map[string]string{"name": "佣金收益", "value": svc.GetCommissionPrec(c, commission, "2", "1")})
  63. }
  64. if store.StoreType > 0 {
  65. tmp = append(tmp, map[string]string{"name": "订单收益", "value": svc.GetCommissionPrec(c, money, "2", "1")})
  66. }
  67. tmp = append(tmp, map[string]string{"name": "已付款订单量", "value": utils.IntToStr(utils.StrToInt(successCount))})
  68. tmp = append(tmp, map[string]string{"name": "已取消订单量", "value": utils.IntToStr(utils.StrToInt(count))})
  69. tmp = append(tmp, map[string]string{"name": "待提货订单量", "value": utils.IntToStr(utils.StrToInt(waitCount))})
  70. e.OutSuc(c, tmp, nil)
  71. return
  72. }
  73. func StoreWithdrawBase(c *gin.Context) {
  74. user := svc.GetUser(c)
  75. var res = map[string]string{
  76. "is_bind": "0",
  77. "amount": "0",
  78. "alipay_account": user.Profile.AccAlipay,
  79. "alipay_name": user.Profile.AccAlipayRealName,
  80. "info": "",
  81. }
  82. if user.Profile.AccAlipay != "" {
  83. res["is_bind"] = "1"
  84. }
  85. store := db.GetStoreIdEg(svc.MasterDb(c), utils.IntToStr(user.Info.Uid))
  86. if store != nil {
  87. amountData := db.GetStoreAmountEg(svc.MasterDb(c), user.Info.Uid, store.ParentUid, store.StoreType)
  88. if amountData != nil {
  89. res["amount"] = amountData.Amount
  90. }
  91. }
  92. e.OutSuc(c, res, nil)
  93. return
  94. }
  95. func StoreWithdrawFlowCate(c *gin.Context) {
  96. res := []map[string]string{
  97. {"name": "全部", "value": ""},
  98. {"name": "订单", "value": "1"},
  99. {"name": "收款", "value": "4"},
  100. {"name": "提现", "value": "2"},
  101. }
  102. e.OutSuc(c, res, nil)
  103. return
  104. }
  105. func StoreWithdrawFlow(c *gin.Context) {
  106. var req map[string]string
  107. if err := c.ShouldBindJSON(&req); err != nil {
  108. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  109. return
  110. }
  111. user := svc.GetUser(c)
  112. req["store_uid"] = utils.IntToStr(user.Info.Uid)
  113. store := db.GetStoreIdEg(svc.MasterDb(c), utils.IntToStr(user.Info.Uid))
  114. if store != nil {
  115. req["parent_uid"] = utils.IntToStr(store.ParentUid)
  116. req["store_type"] = utils.IntToStr(store.StoreType)
  117. }
  118. withdraw, total := db.GetStoreFlow(svc.MasterDb(c), req)
  119. list := make([]map[string]string, 0)
  120. if withdraw != nil {
  121. var stateList = []string{"", "订单", "提现", "", "收款"}
  122. for _, v := range *withdraw {
  123. tmp := map[string]string{
  124. "amount": v.Amount,
  125. "title": v.Title,
  126. "ord_type": utils.IntToStr(v.OrdType),
  127. "label": stateList[v.OrdType],
  128. "oid": utils.Int64ToStr(v.Oid),
  129. "time": v.CreateAt.Format("2006-01-02 15:04:05"),
  130. }
  131. if v.OrdType == 1 {
  132. ord := db.GetOrderInfoFirstEg(svc.MasterDb(c), utils.Int64ToStr(v.Oid))
  133. if ord != nil {
  134. tmp["title"] = ord.Title
  135. }
  136. }
  137. list = append(list, tmp)
  138. }
  139. }
  140. res := map[string]interface{}{
  141. "total": total,
  142. "list": list,
  143. }
  144. e.OutSuc(c, res, nil)
  145. return
  146. }
  147. func StoreWithdrawDoing(c *gin.Context) {
  148. storeSvc.StoreWithdrawDoing(c)
  149. }