huangjiajun 1 month ago
parent
commit
5425eb5463
28 changed files with 1098 additions and 22 deletions
  1. +17
    -0
      app/agent/hdl/hdl_store.go
  2. +159
    -0
      app/agent/svc/svc_store.go
  3. +4
    -1
      app/db/db_goods.go
  4. +7
    -1
      app/db/db_store.go
  5. +53
    -0
      app/db/db_store_amount.go
  6. +71
    -0
      app/db/db_store_withdraw.go
  7. +9
    -0
      app/db/model/community_team_store_amount.go
  8. +20
    -0
      app/db/model/community_team_store_amount_flow.go
  9. +23
    -0
      app/db/model/community_team_store_withdraw_apply.go
  10. +7
    -0
      app/db/model/county.go
  11. +6
    -0
      app/db/model/province.go
  12. +13
    -1
      app/router/router.go
  13. +69
    -0
      app/store/hdl/hdl_login.go
  14. +4
    -1
      app/store/hdl/hdl_store.go
  15. +13
    -0
      app/store/hdl/hdl_store_amount.go
  16. +16
    -0
      app/store/hdl/hdl_store_withdraw.go
  17. +90
    -0
      app/store/svc/svc_login.go
  18. +64
    -0
      app/store/svc/svc_store.go
  19. +67
    -0
      app/store/svc/svc_store_amount.go
  20. +168
    -0
      app/store/svc/svc_store_withdraw.go
  21. +5
    -1
      app/svc/svc_cate.go
  22. +6
    -0
      app/svc/svc_goods.go
  23. +26
    -2
      app/svc/svc_order.go
  24. +24
    -13
      app/svc/svc_store.go
  25. +72
    -0
      app/svc/svc_store_order.go
  26. +79
    -0
      app/utils/xls.go
  27. +1
    -1
      go.mod
  28. +5
    -1
      go.sum

+ 17
- 0
app/agent/hdl/hdl_store.go View File

@@ -1,6 +1,7 @@
package hdl

import (
agentSvc "applet/app/agent/svc"
"applet/app/db"
"applet/app/db/model"
"applet/app/e"
@@ -298,3 +299,19 @@ func UserStoreTotal(c *gin.Context) {
e.OutSuc(c, res, nil)
return
}

func StoreWithdrawFlow(c *gin.Context) {
agentSvc.StoreWithdrawFlow(c)
}
func StoreWithdrawTotal(c *gin.Context) {
agentSvc.StoreWithdrawTotal(c)
}
func StoreWithdrawAudit(c *gin.Context) {
agentSvc.StoreWithdrawAudit(c)
}
func StoreWithdrawAuditAll(c *gin.Context) {
agentSvc.StoreWithdrawAuditAll(c)
}
func StoreWithdrawOutPut(c *gin.Context) {
agentSvc.StoreWithdrawOutPut(c)
}

+ 159
- 0
app/agent/svc/svc_store.go View File

@@ -1 +1,160 @@
package svc

import (
"applet/app/db"
"applet/app/db/model"
"applet/app/e"
"applet/app/svc"
"applet/app/utils"
"github.com/gin-gonic/gin"
"strings"
)

func StoreWithdrawFlow(c *gin.Context) {
var req map[string]string
if err := c.ShouldBindJSON(&req); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
user := svc.GetUser(c)
req["agent_uid"] = utils.IntToStr(user.Info.Uid)
withdraw, total := db.GetStoreWithdraw(svc.MasterDb(c), req)
list := make([]map[string]string, 0)
if withdraw != nil {
var stateList = []string{"审核中", "审核通过", "审核通过", "审核拒绝"}
for _, v := range *withdraw {
name := ""
store := db.GetStoreIdEg(svc.MasterDb(c), utils.IntToStr(v.Uid))
if store != nil {
name = store.Name
}
tmp := map[string]string{
"id": utils.Int64ToStr(v.Id),
"name": name,
"amount": v.Amount,
"alipay_account": v.WithdrawAccount,
"alipay_name": v.WithdrawName,
"state_str": stateList[v.State],
"state": utils.IntToStr(v.State),
"time": v.CreateAt.Format("2006-01-02 15:04:05"),
"end_time": "",
"memo": v.Memo,
}
if v.PaymentDate != "" {
tmp["end_time"] = v.PaymentDate
}
list = append(list, tmp)
}
}
res := map[string]interface{}{
"total": total,
"list": list,
"state": []map[string]string{
{"name": "审核中", "value": "0"},
{"name": "审核通过", "value": "1"},
{"name": "审核拒绝", "value": "3"},
},
}
e.OutSuc(c, res, nil)
return
}
func StoreWithdrawTotal(c *gin.Context) {
var req map[string]string
if err := c.ShouldBindJSON(&req); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
user := svc.GetUser(c)
var allAmount float64 = 0
var waitAmount float64 = 0
var failAmount float64 = 0
allAmount, _ = svc.MasterDb(c).Where("parent_uid=?", user.Info.Uid).And("state=?", 1).Sum(&model.CommunityTeamStoreWithdrawApply{}, "amount")
waitAmount, _ = svc.MasterDb(c).Where("parent_uid=?", user.Info.Uid).And("state=?", 0).Sum(&model.CommunityTeamStoreWithdrawApply{}, "amount")
failAmount, _ = svc.MasterDb(c).Where("parent_uid=?", user.Info.Uid).And("state=?", 3).Sum(&model.CommunityTeamStoreWithdrawApply{}, "amount")
res := []map[string]string{
{"name": "累计提现金额(元):" + utils.Float64ToStr(allAmount), "tip": "统计提现成功的金额"},
{"name": "审核中金额(元):" + utils.Float64ToStr(waitAmount), "tip": "统计正在审核中的金额"},
{"name": "审核拒绝金额(元):" + utils.Float64ToStr(failAmount), "tip": "统计审核拒绝的金额"},
}
e.OutSuc(c, res, nil)
return
}
func StoreWithdrawAudit(c *gin.Context) {
var req map[string]string
if err := c.ShouldBindJSON(&req); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
sess := svc.MasterDb(c).NewSession()
defer sess.Close()
sess.Begin()
data := db.GetStoreWithdrawById(sess, req["id"])
if data == nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
return
}
if data.State > 0 {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "记录已处理"))
return
}
if req["state"] == "3" {
bools := svc.MoneyCheck(c, sess, data.Uid, 0, 3, utils.StrToFloat64(data.Amount), "提现审核拒绝退回", utils.StrToInt64(utils.OrderUUID(data.Uid)))
if bools == false {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "审核失败"))
return
}
}
data.State = utils.StrToInt(req["state"])
data.Memo = req["memo"]
update, err := sess.Where("id=?", data.Id).Cols("state,memo").Update(data)
if update == 0 || err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "审核失败"))
return
}
sess.Commit()
e.OutSuc(c, "success", nil)
return
}
func StoreWithdrawAuditAll(c *gin.Context) {
var req map[string]string
if err := c.ShouldBindJSON(&req); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
count, _ := svc.MasterDb(c).In("id", strings.Split(req["ids"], ",")).And("state>0").Count(&model.CommunityTeamStoreWithdrawApply{})
if count > 0 {
e.OutErr(c, 400, e.NewErr(400, "存在已处理的记录"))
return
}
svc.MasterDb(c).In("id", strings.Split(req["ids"], ",")).Cols("state").Update(&model.CommunityTeamStoreWithdrawApply{State: 1})
e.OutSuc(c, "success", nil)
return
}
func StoreWithdrawOutPut(c *gin.Context) {
var args map[string]string
if err := c.ShouldBindJSON(&args); err != nil {
e.OutErr(c, 200, e.ERR_INVALID_ARGS)
return
}
name := "提现记录_" + args["p"]
args["state"] = "0"
args["size"] = "3000"
if args["ids"] != "" {
args["size"] = "0"
}
user := svc.GetUser(c)
args["parent_uid"] = utils.IntToStr(user.Info.Uid)
data, _ := db.GetStoreWithdraw(svc.MasterDb(c), args)
file := utils.OutputSecond(c, name, data)
filename := name + ".xls"
r := map[string]string{
"file": file,
"filename": filename,
}
e.OutSuc(c, r, nil)
return
}

+ 4
- 1
app/db/db_goods.go View File

@@ -8,10 +8,13 @@ import (

func GetGoods(eg *xorm.Engine, arg map[string]string) *[]model.CommunityTeamGoods {
var data []model.CommunityTeamGoods
sess := eg.Where("store_type=0 and state=0")
sess := eg.Where("store_type=? and state=0", arg["store_type"])
if arg["cid"] != "" {
sess.And("cid=?", arg["cid"])
}
if arg["uid"] != "" {
sess.And("uid=?", arg["uid"])
}
if arg["title"] != "" {
sess.And("title like ?", "%"+arg["title"]+"%")
}


+ 7
- 1
app/db/db_store.go View File

@@ -26,7 +26,7 @@ func GetStore(eg *xorm.Engine, arg map[string]string) []map[string]string {
if arg["parent_uid"] != "" {
where += " and store_type=2 and parent_uid=" + arg["parent_uid"]
} else if arg["uid"] != "" {
where += " and store_type=1 and uid=" + arg["parent_uid"]
where += " and store_type=1 and uid=" + arg["uid"]
} else {
if arg["store_type"] == "3" {
where += " and store_type in(1,2)"
@@ -34,6 +34,9 @@ func GetStore(eg *xorm.Engine, arg map[string]string) []map[string]string {
where += " and store_type=" + arg["store_type"]
}
}
if arg["store_id"] != "" {
where += " and uid = '" + arg["store_id"] + "'"
}
if arg["city"] != "" {
where += " and city like '%" + arg["city"] + "%'"
}
@@ -81,6 +84,9 @@ where %s %s`
where += " and cts.store_type=" + arg["store_type"]
}
}
if arg["store_id"] != "" {
where += " and cts.uid = '" + arg["store_id"] + "'"
}
if arg["city"] != "" {
where += " and cts.city='" + arg["city"] + "'"
}


+ 53
- 0
app/db/db_store_amount.go View File

@@ -0,0 +1,53 @@
package db

import (
"applet/app/db/model"
"applet/app/utils"
"xorm.io/xorm"
)

func GetStoreAmount(sess *xorm.Session, storeId int, agentUid int) *model.CommunityTeamStoreAmount {
var data model.CommunityTeamStoreAmount
get, err := sess.Where("uid=? and parent_uid=?", storeId, agentUid).Get(&data)
if get == false || err != nil {
return nil
}
return &data
}
func GetStoreAmountEg(eg *xorm.Engine, storeId int, agentUid int) *model.CommunityTeamStoreAmount {
var data model.CommunityTeamStoreAmount
get, err := eg.Where("uid=? and parent_uid=?", storeId, agentUid).Get(&data)
if get == false || err != nil {
return nil
}
return &data
}
func GetStoreAmountFlowList(eg *xorm.Engine, arg map[string]string) (*[]model.CommunityTeamStoreAmountFlow, int64) {
var data []model.CommunityTeamStoreAmountFlow
sess := eg.Where("1=1")
if arg["store_uid"] != "" {
sess.And("uid=?", arg["store_uid"])
}
if arg["parent_uid"] != "" {
sess.And("parent_uid=?", arg["parent_uid"])
}
if arg["title"] != "" {
sess.And("title like ?", "%"+arg["title"]+"%")
}
if arg["oid"] != "" {
sess.And("oid like ?", "%"+arg["oid"]+"%")
}
if arg["start_time"] != "" {
sess.And("create_at>=?", arg["start_time"])
}
if arg["end_time"] != "" {
sess.And("create_at<=?", arg["end_time"])
}
limit := utils.StrToInt(arg["size"])
start := (utils.StrToInt(arg["p"]) - 1) * limit
count, err := sess.Desc("id").Limit(limit, start).FindAndCount(&data)
if err != nil {
return nil, count
}
return &data, count
}

+ 71
- 0
app/db/db_store_withdraw.go View File

@@ -0,0 +1,71 @@
package db

import (
"applet/app/db/model"
"applet/app/utils"
"strings"
"xorm.io/xorm"
)

func GetStoreWithdraw(eg *xorm.Engine, arg map[string]string) (*[]model.CommunityTeamStoreWithdrawApply, int64) {
var data []model.CommunityTeamStoreWithdrawApply
sess := eg.Where("1=1")
if arg["store_uid"] != "" {
sess.And("uid=?", arg["store_uid"])
}
if arg["parent_uid"] != "" {
sess.And("parent_uid=?", arg["parent_uid"])
}
if arg["state"] != "" {
sess.And("state=?", arg["state"])
}
if arg["ids"] != "" {
sess.In("id", strings.Split(arg["ids"], ","))
}
if arg["alipay_account"] != "" {
sess.And("withdraw_account like ?", "%"+arg["alipay_account"]+"%")
}
if arg["alipay_name"] != "" {
sess.And("withdraw_name like ?", "%"+arg["alipay_name"]+"%")
}
if arg["store_name"] != "" {
var data1 []model.CommunityTeamStore
eg.Where("name like ?", "%"+arg["store_name"]+"%").Find(&data1)
uid := []int{-1}
for _, v := range data1 {
uid = append(uid, v.Uid)
}
sess.In("uid", uid)
}
if arg["start_time"] != "" {
sess.And("create_at>=?", arg["start_time"])
}
if arg["end_time"] != "" {
sess.And("create_at<=?", arg["end_time"])
}
if arg["payment_start_time"] != "" {
sess.And("payment_date>=?", arg["payment_start_time"])
}
if arg["payment_end_time"] != "" {
sess.And("payment_date<=?", arg["payment_end_time"])
}
limit := utils.StrToInt(arg["size"])
start := (utils.StrToInt(arg["p"]) - 1) * limit
if limit > 0 {
sess.Limit(limit, start)
}
count, err := sess.Desc("id").FindAndCount(&data)
if err != nil {
return nil, count
}
return &data, count
}

func GetStoreWithdrawById(sess *xorm.Session, id string) *model.CommunityTeamStoreWithdrawApply {
var data model.CommunityTeamStoreWithdrawApply
get, err := sess.Where("id=?", id).Get(&data)
if get == false || err != nil {
return nil
}
return &data
}

+ 9
- 0
app/db/model/community_team_store_amount.go View File

@@ -0,0 +1,9 @@
package model

type CommunityTeamStoreAmount struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"default 0 INT(11)"`
StoreType int `json:"store_type" xorm:"default 0 comment('0官方自营店 1加盟店 2连锁店') INT(11)"`
ParentUid int `json:"parent_uid" xorm:"default 0 comment('上级代理') INT(11)"`
Amount string `json:"amount" xorm:"default 0.00 DECIMAL(20,2)"`
}

+ 20
- 0
app/db/model/community_team_store_amount_flow.go View File

@@ -0,0 +1,20 @@
package model

import (
"time"
)

type CommunityTeamStoreAmountFlow struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"default 0 INT(11)"`
StoreType int `json:"store_type" xorm:"default 0 comment('0官方自营店 1加盟店 2连锁店') INT(11)"`
ParentUid int `json:"parent_uid" xorm:"default 0 comment('上级代理') INT(11)"`
Amount string `json:"amount" xorm:"default 0.00 DECIMAL(20,2)"`
BeforeAmount string `json:"before_amount" xorm:"default 0.00 DECIMAL(20,2)"`
AfterAmount string `json:"after_amount" xorm:"default 0.00 DECIMAL(20,2)"`
Oid int64 `json:"oid" xorm:"default 0 BIGINT(20)"`
Type int `json:"type" xorm:"default 0 INT(1)"`
Title string `json:"title" xorm:"VARCHAR(255)"`
OrdType int `json:"ord_type" xorm:"default 0 INT(11)"`
CreateAt time.Time `json:"create_at" xorm:"DATETIME"`
}

+ 23
- 0
app/db/model/community_team_store_withdraw_apply.go View File

@@ -0,0 +1,23 @@
package model

import (
"time"
)

type CommunityTeamStoreWithdrawApply struct {
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户ID') index INT(10)"`
Amount string `json:"amount" xorm:"not null default 0.00 comment('提现金额') DECIMAL(10,2)"`
Memo string `json:"memo" xorm:"not null default '' comment('备注,失败请备注原因') VARCHAR(500)"`
Type int `json:"type" xorm:"not null default 1 comment('提现类型;1:手动;2:自动') TINYINT(1)"`
ParentUid int `json:"parent_uid" xorm:"not null default 1 comment('提现类型;1:手动;2:自动') TINYINT(1)"`
WithdrawAccount string `json:"withdraw_account" xorm:"not null default '' comment('提现账号') VARCHAR(64)"`
WithdrawName string `json:"withdraw_name" xorm:"not null default '' comment('提现人姓名') VARCHAR(12)"`
Reason int `json:"reason" xorm:"not null default 0 comment('审核失败(驳回理由);1:当前账号不满足提现规则;2:账号异常;3:资金异常') TINYINT(1)"`
PaymentDate string `json:"payment_date" xorm:"not null default '0000-00-00 00:00:00' comment('到账时间') VARCHAR(50)"`
CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('申请时间') index TIMESTAMP"`
UpdateAt time.Time `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('处理时间') TIMESTAMP"`
State int `json:"state" xorm:"not null default 0 comment('0申请中,1通过,2完成,3失败') TINYINT(1)"`
Oid int64 `json:"oid" xorm:"not null default 0 comment('0申请中,1通过,2完成,3失败') TINYINT(1)"`
Platform string `json:"platform" xorm:"VARCHAR(255)"`
}

+ 7
- 0
app/db/model/county.go View File

@@ -0,0 +1,7 @@
package model

type County struct {
Name string `json:"name" xorm:"VARCHAR(64)"`
Id string `json:"id" xorm:"not null pk VARCHAR(12)"`
CityId string `json:"city_id" xorm:"index VARCHAR(12)"`
}

+ 6
- 0
app/db/model/province.go View File

@@ -0,0 +1,6 @@
package model

type Province struct {
Id string `json:"id" xorm:"not null pk VARCHAR(12)"`
Name string `json:"name" xorm:"VARCHAR(64)"`
}

+ 13
- 1
app/router/router.go View File

@@ -78,6 +78,11 @@ func routeCommunityTeamAgent(r *gin.RouterGroup) {
r.POST("/goods/cate/save", agentHdl.GoodsCateSave)
r.POST("/goods/cate/show", agentHdl.GoodsCateShow)
r.POST("/goods/cate/del", agentHdl.GoodsCateDel)
r.POST("/store/withdraw/flow", agentHdl.StoreWithdrawFlow)
r.POST("/store/withdraw/total", agentHdl.StoreWithdrawTotal)
r.POST("/store/withdraw/audit", agentHdl.StoreWithdrawAudit)
r.POST("/store/withdraw/all/audit", agentHdl.StoreWithdrawAuditAll)
r.POST("/store/withdraw/output", agentHdl.StoreWithdrawOutPut)

}
func routeCommunityTeamOwnStore(r *gin.RouterGroup) {
@@ -87,6 +92,8 @@ func routeCommunityTeamOwnStore(r *gin.RouterGroup) {
r.POST("/login/send_sms", storeHdl.LoginSendSms)
r.POST("/login/fast_in", storeHdl.LoginFastIn)
r.Use(mw.AuthJWT)
r.GET("/sub_region_list", storeHdl.GetRegionChildNode)
r.POST("/sms", storeHdl.Sms)
r.POST("/img/upload", storeHdl.ImgReqUpload)
r.GET("/user", storeHdl.User)
r.GET("/base", storeHdl.Base)
@@ -101,6 +108,12 @@ func routeCommunityTeamOwnStore(r *gin.RouterGroup) {
r.POST("/audit/doing", storeHdl.AuditDoing)
r.POST("/store/order", storeHdl.UserStoreOrder)
r.POST("/store/order/detail", storeHdl.UserStoreOrderDetail)
r.POST("/store/order/confirm", storeHdl.StoreOrderConfirm)
r.GET("/store/amount/base", storeHdl.StoreAmountBase)
r.POST("/store/amount/flow", storeHdl.StoreAmountFlow)
r.POST("/store/withdraw/flow", storeHdl.StoreWithdrawFlow)
r.POST("/store/withdraw/doing", storeHdl.StoreWithdrawDoing)
r.POST("/store/withdraw/bind/alipay", storeHdl.StoreWithdrawBindAlipay)
r.POST("/goods/list", storeHdl.Goods)
r.POST("/goods/save", storeHdl.GoodsSave)
r.POST("/goods/detail", storeHdl.GoodsDetail)
@@ -109,7 +122,6 @@ func routeCommunityTeamOwnStore(r *gin.RouterGroup) {
r.POST("/goods/cate/save", storeHdl.GoodsCateSave)
r.POST("/goods/cate/show", storeHdl.GoodsCateShow)
r.POST("/goods/cate/del", storeHdl.GoodsCateDel)

r.POST("/agent/goods/list", storeHdl.AgentGoods)
r.POST("/agent/goods/detail", storeHdl.AgentGoodsDetail)
r.POST("/agent/goods/copy", storeHdl.AgentGoodsCopy)


+ 69
- 0
app/store/hdl/hdl_login.go View File

@@ -1,6 +1,9 @@
package hdl

import (
"applet/app/db"
"applet/app/db/model"
"applet/app/e"
"applet/app/store/svc"
"github.com/gin-gonic/gin"
)
@@ -21,6 +24,72 @@ func Login(c *gin.Context) {
func LoginSendSms(c *gin.Context) {
svc.LoginSendSms(c)
}
func Sms(c *gin.Context) {
svc.Sms(c)
}
func LoginFastIn(c *gin.Context) {
svc.LoginFastIn(c)
}

type resultItem struct {
Id string `json:"id" example:"440100000000"`
Name string `json:"name" example:"city"`
}

func GetRegionChildNode(c *gin.Context) {
parent, has := c.GetQuery("parent")
if !has {
e.OutErr(c, e.ERR_INVALID_ARGS)
return
}
id, has := c.GetQuery("id")
if parent != "root" && !has {
e.OutErr(c, e.ERR_INVALID_ARGS)
return
}

var nodeList []interface{}
var err error

switch parent {
case "root":
var provinceList []*model.Province
err = db.Db.Find(&provinceList)
for _, item := range provinceList {
nodeList = append(nodeList, resultItem{
Id: item.Id,
Name: item.Name,
})
}
case "province":
var cityList []*model.City
err = db.Db.Where("province_id=?", id).Find(&cityList)
for _, item := range cityList {
nodeList = append(nodeList, resultItem{
Id: item.Id,
Name: item.Name,
})
}
case "city":
var countyList []*model.County
err = db.Db.Where("city_id=?", id).Find(&countyList)
for _, item := range countyList {
nodeList = append(nodeList, resultItem{
Id: item.Id,
Name: item.Name,
})
}
default:
e.OutErr(c, e.ERR_INVALID_ARGS)
return
}
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err)
return
}
if len(nodeList) == 0 {
e.OutSuc(c, []interface{}{}, nil)
return
}
e.OutSuc(c, nodeList, nil)
}

+ 4
- 1
app/store/hdl/hdl_store.go View File

@@ -5,6 +5,7 @@ import (
"applet/app/db/model"
"applet/app/e"
"applet/app/md"
storeSvc "applet/app/store/svc"
"applet/app/svc"
"applet/app/utils"
"encoding/json"
@@ -255,7 +256,9 @@ func UserStoreOrderDetail(c *gin.Context) {
e.OutSuc(c, res, nil)
return
}

func StoreOrderConfirm(c *gin.Context) {
storeSvc.StoreOrderConfirm(c)
}
func UserStoreInfo(c *gin.Context) {
var arg map[string]string
if err := c.ShouldBindJSON(&arg); err != nil {


+ 13
- 0
app/store/hdl/hdl_store_amount.go View File

@@ -0,0 +1,13 @@
package hdl

import (
"applet/app/store/svc"
"github.com/gin-gonic/gin"
)

func StoreAmountBase(c *gin.Context) {
svc.StoreAmountBase(c)
}
func StoreAmountFlow(c *gin.Context) {
svc.StoreAmountFlow(c)
}

+ 16
- 0
app/store/hdl/hdl_store_withdraw.go View File

@@ -0,0 +1,16 @@
package hdl

import (
"applet/app/store/svc"
"github.com/gin-gonic/gin"
)

func StoreWithdrawFlow(c *gin.Context) {
svc.StoreWithdrawFlow(c)
}
func StoreWithdrawDoing(c *gin.Context) {
svc.StoreWithdrawDoing(c)
}
func StoreWithdrawBindAlipay(c *gin.Context) {
svc.StoreWithdrawBindAlipay(c)
}

+ 90
- 0
app/store/svc/svc_login.go View File

@@ -383,6 +383,96 @@ func LoginSendSms(c *gin.Context) {
e.OutSuc(c, "验证码已发送,3分钟内有效", nil)
return
}
func Sms(c *gin.Context) {
var req map[string]string
if err := c.ShouldBindJSON(&req); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
user := svc.GetUser(c)
req["phone"] = user.Info.Phone
types := "bind_alipay"
var err error
smsType := svc.SysCfgGet(c, "sms_type")
c.Set("sms_type", smsType)
if c.GetString("sms_type") == "1" {
count := sms2.SmsNumGetSmsNum(db.Db, "putong", c.GetString("mid"))
if count-1 < 0 {
e.OutErr(c, e.ERR_MOB_SMS_NO_AVA, err)
return
}
} else {
count, _ := zhimeng.SmsNum(db.Db, c.GetString("mid"), c.GetString("sms_type"), db.SysCfgGet(c, "third_zm_sms_key"), db.SysCfgGet(c, "third_zm_sms_secret"))
if count-1 < 0 {
e.OutErr(c, e.ERR_MOB_SMS_NO_AVA, err)
return
}
}
appName := db.SysCfgGet(c, "sms_push_sign")
captcha := createCaptcha()
content := fmt.Sprintf("【%s】验证码:%s", appName, captcha)
key := fmt.Sprintf("%s_SMS_%s", db.SysCfgGet(c, "app_name"), req["phone"])
templateCode := ""
switch types {
case "login":
content = fmt.Sprintf("【%s】快捷登录验证码:%s", appName, captcha)
key = fmt.Sprintf("%s_SMS_FastLogin_%s", db.SysCfgGet(c, "app_name"), req["phone"])
templateCode = "login"
case "bind_alipay":
content = fmt.Sprintf("【%s】绑定支付宝验证码:%s", appName, captcha)
key = fmt.Sprintf("%s_SMS_FastLogin_%s", db.SysCfgGet(c, "app_name"), req["phone"])
templateCode = "bind_alipay"
case "register":
content = fmt.Sprintf("【%s】注册验证码:%s", appName, captcha)
key = fmt.Sprintf("%s_SMS_FastLogin_%s", db.SysCfgGet(c, "app_name"), req["phone"])
templateCode = "register"
}
marshal, _ := json.Marshal(c.Request.Header)
waykeys := "app_" + c.ClientIP() + "_" + utils.IntToStr(utils.GetApiVersion(c)) + "_" + c.Request.RequestURI + "_" + string(marshal)
postData := map[string]interface{}{
"content": content,
"mobile": req["phone"],
"templateCode": templateCode,
"way": php2go.Base64Encode(waykeys),
}
requestBody := new(md.Register)
requestBody.Mobile = req["phone"]
requestBody.Captcha = captcha
if requestBody.Zone == "" {
requestBody.Zone = "86"
}
err = sms.GetSmsConfig(c, requestBody.Zone, postData)
if err != nil {
e.OutErr(c, 400, err)
return
}
tmp := struct {
Data md.Register `json:"data"`
CacheTime int64 `json:"cache_time"`
}{
Data: *requestBody,
CacheTime: time.Now().Unix(),
}
if _, err := cache.SetEx(key, utils.Serialize(tmp), 180); err != nil {
e.OutErr(c, e.ERR, err)
return
}
//存入一个缓存 用于邀请码注册时候判断
keys := fmt.Sprintf("%s_SMSCHECK_%s", c.GetString("mid"), requestBody.Mobile)
tmps := struct {
Check int `json:"check"`
CacheTime int64 `json:"cache_time"`
}{
Check: 1,
CacheTime: time.Now().Unix(),
}
if _, err := cache.SetEx(keys, utils.Serialize(tmps), 3600); err != nil {
e.OutErr(c, e.ERR, err)
return
}
e.OutSuc(c, "验证码已发送,3分钟内有效", nil)
return
}
func createCaptcha() string {
return fmt.Sprintf("%05v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
}

+ 64
- 0
app/store/svc/svc_store.go View File

@@ -1 +1,65 @@
package svc

import (
"applet/app/db"
"applet/app/e"
"applet/app/svc"
"applet/app/utils"
"applet/app/utils/cache"
"fmt"
"github.com/gin-gonic/gin"
"time"
)

func StoreOrderConfirm(c *gin.Context) {
var arg map[string]string
if err := c.ShouldBindJSON(&arg); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
// 加锁 防止并发提取
mutexKey := fmt.Sprintf("%s:team.StoreOrderConfirm:%s", c.GetString("mid"), arg["oid"])
withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 5, "NX")
if err != nil {
e.OutErr(c, e.ERR, err)
return
}
if withdrawAvailable != "OK" {
e.OutErr(c, e.ERR, e.NewErr(400000, "请求过于频繁,请稍后再试"))
return
}
sess := svc.MasterDb(c).NewSession()
defer sess.Close()
sess.Begin()
order := db.GetOrder(sess, arg["oid"])
if order == nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单不存在"))
return
}
if order.State != 1 {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单不能确认"))
return
}
order.State = 2
order.UpdateAt = time.Now()
order.ConfirmAt = time.Now()
update, err := sess.Where("id=?", order.Id).Cols("state,confirm_at,update_at").Update(order)
if update == 0 || err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单确认失败"))
return
}
//给商家余额
money := utils.StrToFloat64(order.Amount) - utils.StrToFloat64(order.AgentCommission)
bools := svc.MoneyCheck(c, sess, order.StoreUid, 0, 1, money, "订单核销", order.Oid)
if bools == false {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单确认失败"))
return
}
sess.Commit()
e.OutSuc(c, "success", nil)
return
}

+ 67
- 0
app/store/svc/svc_store_amount.go View File

@@ -0,0 +1,67 @@
package svc

import (
"applet/app/db"
"applet/app/db/model"
"applet/app/e"
"applet/app/svc"
"applet/app/utils"
"github.com/gin-gonic/gin"
)

func StoreAmountBase(c *gin.Context) {
user := svc.GetUser(c)
var res = map[string]string{
"is_bind": "0",
"amount": "0",
"wait_amount": "0",
"alipay_account": user.Profile.AccAlipay,
"alipay_name": user.Profile.AccAlipayRealName,
}
if user.Profile.AccAlipay != "" {
res["is_bind"] = "1"
}
amount, _ := svc.MasterDb(c).Where("store_uid=? and parent_uid>0 and state=1", user.Info.Uid).Sum(&model.CommunityTeamOrder{}, "amount-agent_commission")
res["wait_amount"] = utils.Float64ToStr(amount)
store := db.GetStoreIdEg(svc.MasterDb(c), utils.IntToStr(user.Info.Uid))
if store != nil {
amountData := db.GetStoreAmountEg(svc.MasterDb(c), user.Info.Uid, store.ParentUid)
if amountData != nil {
res["amount"] = amountData.Amount
}
}
e.OutSuc(c, res, nil)
return
}
func StoreAmountFlow(c *gin.Context) {
var req map[string]string
if err := c.ShouldBindJSON(&req); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
user := svc.GetUser(c)
req["store_uid"] = utils.IntToStr(user.Info.Uid)
withdraw, total := db.GetStoreAmountFlowList(svc.MasterDb(c), req)
list := make([]map[string]string, 0)
if withdraw != nil {
var stateList = []string{"收入", "支出"}
for _, v := range *withdraw {
tmp := map[string]string{
"amount": v.Amount,
"type_str": stateList[v.Type],
"type": utils.IntToStr(v.Type),
"title": v.Title,
"oid": utils.Int64ToStr(v.Oid),
"after_amount": v.AfterAmount,
"time": v.CreateAt.Format("2006-01-02 15:04:05"),
}
list = append(list, tmp)
}
}
res := map[string]interface{}{
"total": total,
"list": list,
}
e.OutSuc(c, res, nil)
return
}

+ 168
- 0
app/store/svc/svc_store_withdraw.go View File

@@ -0,0 +1,168 @@
package svc

import (
"applet/app/db"
"applet/app/db/model"
"applet/app/e"
"applet/app/lib/mob"
"applet/app/lib/sms"
"applet/app/svc"
"applet/app/utils"
"applet/app/utils/cache"
"fmt"
"github.com/gin-gonic/gin"
"github.com/tidwall/gjson"
"time"
)

func StoreWithdrawFlow(c *gin.Context) {
var req map[string]string
if err := c.ShouldBindJSON(&req); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
user := svc.GetUser(c)
req["store_uid"] = utils.IntToStr(user.Info.Uid)
withdraw, total := db.GetStoreWithdraw(svc.MasterDb(c), req)
list := make([]map[string]string, 0)
if withdraw != nil {
var stateList = []string{"审核中", "审核通过", "审核通过", "审核拒绝"}
for _, v := range *withdraw {
tmp := map[string]string{
"amount": v.Amount,
"alipay_account": v.WithdrawAccount,
"alipay_name": v.WithdrawName,
"state_str": stateList[v.State],
"state": utils.IntToStr(v.State),
"memo": v.Memo,
"time": v.CreateAt.Format("2006-01-02 15:04:05"),
}
list = append(list, tmp)
}
}
res := map[string]interface{}{
"total": total,
"list": list,
}
e.OutSuc(c, res, nil)
return
}
func StoreWithdrawDoing(c *gin.Context) {
var req map[string]string
if err := c.ShouldBindJSON(&req); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
user := svc.GetUser(c)
if user.Profile.AccAlipay == "" || user.Profile.AccAlipayRealName == "" {
e.OutErr(c, 400, e.NewErr(400, "未绑定支付宝"))
return
}
if utils.StrToFloat64(req["amount"]) <= 0 {
e.OutErr(c, 400, e.NewErr(400, "金额不正确"))
return
}
sess := svc.MasterDb(c).NewSession()
defer sess.Close()
sess.Begin()
oid := utils.StrToInt64(utils.OrderUUID(user.Info.Uid))
store := db.GetStoreId(sess, utils.IntToStr(user.Info.Uid))
if store == nil {
e.OutErr(c, 400, e.NewErr(400, "提现失败"))
return
}
if store.ParentUid == 0 {
e.OutErr(c, 400, e.NewErr(400, "提现失败"))
return
}
bools := svc.MoneyCheck(c, sess, user.Info.Uid, 1, 2, utils.StrToFloat64(req["amount"]), "提现", oid)
if bools == false {
e.OutErr(c, 400, e.NewErr(400, "提现失败"))
return
}
var flow = &model.CommunityTeamStoreWithdrawApply{
Uid: user.Info.Uid,
ParentUid: store.ParentUid,
Amount: req["amount"],
Type: 1,
WithdrawAccount: user.Profile.AccAlipay,
WithdrawName: user.Profile.AccAlipayRealName,
CreateAt: time.Now(),
UpdateAt: time.Now(),
Oid: oid,
}
insert, err := sess.Insert(flow)
if insert == 0 || err != nil {
e.OutErr(c, 400, e.NewErr(400, "提现失败"))
return
}
sess.Commit()
e.OutSuc(c, "success", nil)
return
}

func StoreWithdrawBindAlipay(c *gin.Context) {
var req map[string]string
if err := c.ShouldBindJSON(&req); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
if req["alipay_account"] == "" {
e.OutErr(c, 400, e.NewErr(400, "支付宝不能为空"))
return
}
if req["alipay_name"] == "" {
e.OutErr(c, 400, e.NewErr(400, "真实姓名不能为空"))
return
}
mob1, errr := mob.GetMobSDK(c.GetString("mid"))
if errr != nil {
e.OutErr(c, e.ERR_MOB_CONFIG, errr)
return
}
user := svc.GetUser(c)
req["phone"] = user.Info.Phone
if req["zone"] == "" {
req["zone"] = "86"
}
send := map[string]interface{}{
"phone": req["phone"],
"zone": req["zone"],
"code": req["captcha"],
}
var ok bool
var err error
// h5(wap) 登录
smsPlatform := sms.GetSmsPlatform(c)
key := fmt.Sprintf("%s_SMS_FastLogin_%s", db.SysCfgGet(c, "app_name"), req["phone"])
if smsPlatform == "ljioe" {
b, err := cache.GetBytes(key)
if err != nil {
e.OutErr(c, e.ERR_MOB_SMS_NO_EXISTS, err)
return
}
if req["captcha"] != gjson.GetBytes(b, "data.captcha").String() {
e.OutErr(c, e.ERR_MOB_SMS_NO_SAME, err)
return
}
ok = true
} else {
c.Set("not_deduction_doing", "1")
ok, err = mob1.MobSMS(c, send)
if err != nil {
e.OutErr(c, 400, err.Error())
return
}
}

if ok {
user.Profile.AccAlipay = req["alipay_account"]
user.Profile.AccAlipayRealName = req["alipay_name"]
svc.MasterDb(c).Where("uid=?", user.Profile.Uid).Cols("acc_alipay,acc_alipay_real_name").Update(user.Profile)
e.OutSuc(c, "success", nil)
return
}
// 验证码无效或者过期,验证码错误
e.OutErr(c, e.ERR_SMS_AUTH, err)
return
}

+ 5
- 1
app/svc/svc_cate.go View File

@@ -8,7 +8,11 @@ import (
)

func Cate(c *gin.Context) {
cate := db.GetCate(MasterDb(c), "0")
storeId := c.GetHeader("store_id")
if storeId == "" {
storeId = "0"
}
cate := db.GetCate(MasterDb(c), storeId)
cateList := make([]map[string]string, 0)
if cate != nil {
for _, v := range *cate {


+ 6
- 0
app/svc/svc_goods.go View File

@@ -14,6 +14,12 @@ func Goods(c *gin.Context) {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
storeId := c.GetHeader("store_id")
arg["store_type"] = "0"
if utils.StrToInt(storeId) > 0 {
arg["store_id"] = storeId
arg["store_type"] = "1"
}
goods := db.GetGoods(MasterDb(c), arg)
goodsList := make([]map[string]interface{}, 0)



+ 26
- 2
app/svc/svc_order.go View File

@@ -232,6 +232,15 @@ func OrderCoupon(c *gin.Context) {
return
}
func CommCoupon(c *gin.Context, totalPrice string) map[string]interface{} {
couponList := make([]md.CouponList, 0)
storeId := c.GetHeader("store_id")
if utils.StrToInt(storeId) > 0 {
returnData := map[string]interface{}{
"total": "0",
"coupon_list": couponList,
}
return returnData
}
var err error
engine := MasterDb(c)
user := GetUser(c)
@@ -255,7 +264,6 @@ func CommCoupon(c *gin.Context, totalPrice string) map[string]interface{} {
merchantSchemeMap[v.Id] = v
}

couponList := make([]md.CouponList, 0)
notCouponList := make([]md.CouponList, 0)
count := 0
for _, item := range ActCouponUserList {
@@ -439,9 +447,25 @@ func OrderConfirm(c *gin.Context) {
update, err := sess.Where("id=?", order.Id).Cols("state,confirm_at,update_at").Update(order)
if update == 0 || err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单取消失败"))
e.OutErr(c, 400, e.NewErr(400, "订单确认失败"))
return
}
//给商家余额
store := db.GetStoreId(sess, utils.IntToStr(order.StoreUid))
if store == nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单确认失败"))
return
}
if store.ParentUid > 0 {
money := utils.StrToFloat64(order.Amount) - utils.StrToFloat64(order.AgentCommission)
bools := MoneyCheck(c, sess, order.StoreUid, 0, 1, money, "订单核销", order.Oid)
if bools == false {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单确认失败"))
return
}
}
sess.Commit()
e.OutSuc(c, "success", nil)
return


+ 24
- 13
app/svc/svc_store.go View File

@@ -87,18 +87,20 @@ func NewStore(c *gin.Context) {
v["km"] = "-"
}
tmp := map[string]interface{}{
"lat": v["lat"],
"lng": v["lng"],
"address": v["address"],
"name": v["name"],
"id": v["id"],
"km": v["km"],
"time_str": v["timer"],
"uid": v["uid"],
"phone": v["phone"],
"logo": v["logo"],
"is_like": "0",
"fan": "",
"lat": v["lat"],
"lng": v["lng"],
"address": v["address"],
"name": v["name"],
"id": v["id"],
"km": v["km"],
"time_str": v["timer"],
"uid": v["uid"],
"store_id": v["uid"],
"store_type": v["store_type"],
"phone": v["phone"],
"logo": v["logo"],
"is_like": "0",
"fan": "",
}
if user != nil {
count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
@@ -118,6 +120,11 @@ func StoreLike(c *gin.Context) {
return
}
arg["store_type"] = "0"
storeId := c.GetHeader("store_id")
if utils.StrToInt(storeId) > 0 {
arg["store_id"] = storeId
arg["store_type"] = "1"
}
user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
store := db.GetStoreLike(MasterDb(c), arg)
storeList := make([]map[string]interface{}, 0)
@@ -166,7 +173,11 @@ func Store(c *gin.Context) {
return
}
arg["store_type"] = "0"

storeId := c.GetHeader("store_id")
if utils.StrToInt(storeId) > 0 {
arg["store_id"] = storeId
arg["store_type"] = "1"
}
user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
store := db.GetStore(MasterDb(c), arg)
storeList := make([]map[string]interface{}, 0)


+ 72
- 0
app/svc/svc_store_order.go View File

@@ -2,6 +2,7 @@ package svc

import (
"applet/app/db"
"applet/app/db/model"
"applet/app/e"
"applet/app/md"
"applet/app/utils"
@@ -10,6 +11,7 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"time"
"xorm.io/xorm"
)

func StoreOrderCate(c *gin.Context) {
@@ -272,9 +274,79 @@ func StoreOrderConfirm(c *gin.Context) {
order.ConfirmAt = time.Now()
update, err := sess.Where("id=?", order.Id).Cols("state,confirm_at,update_at").Update(order)
if update == 0 || err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单确认失败"))
return
}
//给商家余额
store := db.GetStoreId(sess, utils.IntToStr(order.StoreUid))
if store == nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单确认失败"))
return
}
if store.ParentUid > 0 {
money := utils.StrToFloat64(order.Amount) - utils.StrToFloat64(order.AgentCommission)
bools := MoneyCheck(c, sess, order.StoreUid, 0, 1, money, "订单核销", order.Oid)
if bools == false {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单确认失败"))
return
}
}
sess.Commit()
e.OutSuc(c, "success", nil)
return
}
func MoneyCheck(c *gin.Context, sess *xorm.Session, storeId, types, ordType int, money float64, title string, oid int64) bool {
store := db.GetStoreId(sess, utils.IntToStr(storeId))
if store == nil {
return false
}
if store.ParentUid == 0 {
return false
}
amountData := db.GetStoreAmount(sess, storeId, store.ParentUid)
if amountData == nil {
amountData = &model.CommunityTeamStoreAmount{
Uid: storeId,
ParentUid: store.ParentUid,
StoreType: store.StoreType,
}
insert, err := sess.Insert(amountData)
if insert == 0 || err != nil {
return false
}
}
before := amountData.Amount
if types == 1 {
amountData.Amount = utils.Float64ToStr(utils.StrToFloat64(amountData.Amount) - money)
if utils.StrToFloat64(amountData.Amount) < 0 {
return false
}
} else {
amountData.Amount = utils.Float64ToStr(utils.StrToFloat64(amountData.Amount) + money)
}
update, err := sess.Where("id=?", amountData.Id).Cols("amount").Update(amountData)
if update == 0 || err != nil {
return false
}
var flow = &model.CommunityTeamStoreAmountFlow{
Uid: storeId,
StoreType: store.StoreType,
ParentUid: store.ParentUid,
Amount: utils.Float64ToStr(money),
BeforeAmount: before,
AfterAmount: amountData.Amount,
Oid: oid,
Type: types,
Title: title,
OrdType: ordType,
CreateAt: time.Now(),
}
insert, err := sess.Insert(flow)
if insert == 0 || err != nil {
return false
}
return true
}

+ 79
- 0
app/utils/xls.go View File

@@ -0,0 +1,79 @@
package utils

import (
"applet/app/db/model"
"bytes"
"encoding/csv"
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
"github.com/gin-gonic/gin"
"io/ioutil"
)

func Output(c *gin.Context, name string, data map[string]string) string {
//创建excel文件
xlsx := excelize.NewFile()
//创建新表单
index := xlsx.NewSheet(name)
for k, v := range data {
//设置单元格的值
xlsx.SetCellValue(name, k, v)
}
//设置默认打开的表单
xlsx.SetActiveSheet(index)
////保存文件到指定路径
//err := xlsx.SaveAs("./" + name + ".xlsx")
//if err != nil {
// log.Fatal(err)
//}
//_ = file.Save(fileName)
c.Header("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name+".xlsx"))
c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
var buffer bytes.Buffer
_ = xlsx.Write(&buffer)
r := bytes.NewReader(buffer.Bytes())
fSrc, _ := ioutil.ReadAll(r)
str := "data:application/vnd.ms-excel;base64," + Base64RawStdEncode(string(fSrc))
return str
}
func OutputSecond(c *gin.Context, name string, data *[]model.CommunityTeamStoreWithdrawApply) string {
bytesBuffer := &bytes.Buffer{}
_, _ = bytesBuffer.WriteString("\xEF\xBB\xBF") //写入UTF-8 BOM 防止乱码
writer := csv.NewWriter(bytesBuffer)
writer.Write([]string{"支付宝批量付款文件模板"})
writer.Write([]string{"序号(必填)", "收款方支付宝账号(必填)", "收款方姓名(必填)", "金额(必填,单位:元)", "备注(选填)"})
if data != nil {
for _, v := range *data {
writer.Write([]string{Int64ToStr(v.Id), v.WithdrawAccount, v.WithdrawName, v.Amount, "门店提现"})
}
}

writer.Flush() // 此时才会将缓冲区数据写入
c.Header("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name+".csv"))
c.Header("Content-Type", "application/force-download")
c.Header("Accept-Ranges", "bytes")
r := bytes.NewReader(bytesBuffer.Bytes())
fSrc, _ := ioutil.ReadAll(r)
str := "data:text/csv;charset=utf-8;base64," + Base64RawStdEncode(string(fSrc))
fmt.Println(str)

return str
}

//func OutputSecond(c *gin.Context, name string, data []map[string]string) string {
// bytesBuffer := &bytes.Buffer{}
// _, _ = bytesBuffer.WriteString("\xEF\xBB\xBF") //写入UTF-8 BOM 防止乱码
// writer := csv.NewWriter(bytesBuffer)
// writer.Write([]string{"支付宝批量付款文件模板"})
// writer.Write([]string{"序号(必填)", "收款方支付宝账号(必填)", "收款方姓名(必填)", "金额(必填,单位:元)", "备注(选填)"})
// for _, v := range data {
// writer.Write([]string{v["id"], v["alipay"], v["alipay_name"], v["real_amount"], "聚合联盟"})
// }
// writer.Flush() // 此时才会将缓冲区数据写入
// c.Header("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name+".csv"))
// r := bytes.NewReader(bytesBuffer.Bytes())
// fSrc, _ := ioutil.ReadAll(r)
// str := "data:text/csv;charset=utf-8;base64," + Base64RawStdEncode(string(fSrc))
// fmt.Println(str)
// return str
//}

+ 1
- 1
go.mod View File

@@ -7,7 +7,6 @@ require (
code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git v1.9.10-0.20240823083437-5a9b1907d83c
code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git v1.6.2-0.20240105031805-d6d481cf00c0
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/boombuler/barcode v1.0.1
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5
github.com/dgrijalva/jwt-go v3.2.0+incompatible
@@ -39,6 +38,7 @@ require (
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20230113125201-a16543b7da1d
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20240830072333-a1980ffb256e
github.com/360EntSecGroup-Skylar/excelize v1.4.1
github.com/andybalholm/cascadia v1.2.0 // indirect
github.com/antchfx/htmlquery v1.2.3 // indirect
github.com/antchfx/xmlquery v1.3.5 // indirect


+ 5
- 1
go.sum View File

@@ -38,6 +38,8 @@ git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGy
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
gitee.com/travelliu/dm v1.8.11192/go.mod h1:DHTzyhCrM843x9VdKVbZ+GKXGRbKM2sJ4LxihRxShkE=
github.com/360EntSecGroup-Skylar/excelize v1.4.1 h1:l55mJb6rkkaUzOpSsgEeKYtS6/0gHwBYyfo5Jcjv/Ks=
github.com/360EntSecGroup-Skylar/excelize v1.4.1/go.mod h1:vnax29X2usfl7HHkBrX5EvSCJcmH3dT9luvxzu8iGAE=
github.com/Azure/azure-sdk-for-go v32.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
github.com/Azure/go-autorest/autorest v0.1.0/go.mod h1:AKyIcETwSUFxIcs/Wnq/C+kwCtlEYGUVd7FPNb2slmg=
@@ -76,7 +78,6 @@ github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia
github.com/akamai/AkamaiOPEN-edgegrid-golang v0.9.0/go.mod h1:zpDJeKyp9ScW4NNrbdr+Eyxvry3ilGPewKoXw3XGN1k=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
@@ -647,6 +648,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/mvdan/xurls v1.1.0/go.mod h1:tQlNn3BED8bE/15hnSL2HLkDeLWpNPAwtw7wkEq44oU=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
@@ -863,6 +866,7 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.3-0.20181224173747-660f15d67dbb/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=


Loading…
Cancel
Save