附近小店
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.
 
 
 

158 lines
5.4 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 != nil {
  62. if store.StoreType == 0 {
  63. tmp = append(tmp, map[string]string{"name": "佣金收益", "value": svc.GetCommissionPrec(c, commission, "2", "1")})
  64. }
  65. if store.StoreType > 0 {
  66. tmp = append(tmp, map[string]string{"name": "订单收益", "value": svc.GetCommissionPrec(c, money, "2", "1")})
  67. }
  68. } else {
  69. tmp = append(tmp, map[string]string{"name": "订单收益", "value": svc.GetCommissionPrec(c, money, "2", "1")})
  70. }
  71. tmp = append(tmp, map[string]string{"name": "已付款订单量", "value": utils.IntToStr(utils.StrToInt(successCount))})
  72. tmp = append(tmp, map[string]string{"name": "已取消订单量", "value": utils.IntToStr(utils.StrToInt(count))})
  73. tmp = append(tmp, map[string]string{"name": "待提货订单量", "value": utils.IntToStr(utils.StrToInt(waitCount))})
  74. e.OutSuc(c, tmp, nil)
  75. return
  76. }
  77. func StoreWithdrawBase(c *gin.Context) {
  78. user := svc.GetUser(c)
  79. var res = map[string]string{
  80. "is_bind": "0",
  81. "amount": "0",
  82. "alipay_account": user.Profile.AccAlipay,
  83. "alipay_name": user.Profile.AccAlipayRealName,
  84. "info": "",
  85. }
  86. if user.Profile.AccAlipay != "" {
  87. res["is_bind"] = "1"
  88. }
  89. store := db.GetStoreIdEg(svc.MasterDb(c), utils.IntToStr(user.Info.Uid))
  90. if store != nil {
  91. amountData := db.GetStoreAmountEg(svc.MasterDb(c), user.Info.Uid, store.ParentUid, store.StoreType)
  92. if amountData != nil {
  93. res["amount"] = amountData.Amount
  94. }
  95. }
  96. e.OutSuc(c, res, nil)
  97. return
  98. }
  99. func StoreWithdrawFlowCate(c *gin.Context) {
  100. res := []map[string]string{
  101. {"name": "全部", "value": ""},
  102. {"name": "订单", "value": "1"},
  103. {"name": "收款", "value": "4"},
  104. {"name": "提现", "value": "2"},
  105. }
  106. e.OutSuc(c, res, nil)
  107. return
  108. }
  109. func StoreWithdrawFlow(c *gin.Context) {
  110. var req map[string]string
  111. if err := c.ShouldBindJSON(&req); err != nil {
  112. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  113. return
  114. }
  115. user := svc.GetUser(c)
  116. req["store_uid"] = utils.IntToStr(user.Info.Uid)
  117. store := db.GetStoreIdEg(svc.MasterDb(c), utils.IntToStr(user.Info.Uid))
  118. if store != nil {
  119. req["parent_uid"] = utils.IntToStr(store.ParentUid)
  120. req["store_type"] = utils.IntToStr(store.StoreType)
  121. }
  122. withdraw, total := db.GetStoreFlow(svc.MasterDb(c), req)
  123. list := make([]map[string]string, 0)
  124. if withdraw != nil {
  125. var stateList = []string{"", "订单", "提现", "", "收款"}
  126. for _, v := range *withdraw {
  127. tmp := map[string]string{
  128. "amount": v.Amount,
  129. "title": v.Title,
  130. "ord_type": utils.IntToStr(v.OrdType),
  131. "label": stateList[v.OrdType],
  132. "oid": utils.Int64ToStr(v.Oid),
  133. "time": v.CreateAt.Format("2006-01-02 15:04:05"),
  134. }
  135. if v.OrdType == 1 {
  136. ord := db.GetOrderInfoFirstEg(svc.MasterDb(c), utils.Int64ToStr(v.Oid))
  137. if ord != nil {
  138. tmp["title"] = ord.Title
  139. }
  140. }
  141. list = append(list, tmp)
  142. }
  143. }
  144. res := map[string]interface{}{
  145. "total": total,
  146. "list": list,
  147. }
  148. e.OutSuc(c, res, nil)
  149. return
  150. }
  151. func StoreWithdrawDoing(c *gin.Context) {
  152. storeSvc.StoreWithdrawDoing(c)
  153. }