From 60f24b7233278d897605108c4c2ca9fe8d7f1e4a Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Fri, 1 Nov 2024 15:28:09 +0800 Subject: [PATCH] 1 --- app/agent/svc/svc_store.go | 2 +- app/db/db_order.go | 17 +++- app/db/db_store_withdraw.go | 21 +++++ app/db/dbs_map.go | 2 +- app/db/model/community_team_order.go | 1 + app/db/model/community_team_pay_order.go | 1 + app/hdl/hdl_printer_list.go | 2 +- app/hdl/hdl_store_index.go | 101 ++++++++++++++++++++++- app/hdl/hdl_store_order.go | 64 ++++++++++++++ app/router/router.go | 31 +++---- app/svc/svc_order.go | 2 +- app/svc/svc_pay_community_team.go | 8 ++ app/svc/svc_pay_community_team_pay.go | 2 +- app/svc/svc_printer_list.go | 18 ++-- app/svc/svc_store_order.go | 7 +- 15 files changed, 245 insertions(+), 34 deletions(-) diff --git a/app/agent/svc/svc_store.go b/app/agent/svc/svc_store.go index a68e641..1e584df 100644 --- a/app/agent/svc/svc_store.go +++ b/app/agent/svc/svc_store.go @@ -102,7 +102,7 @@ func StoreWithdrawAudit(c *gin.Context) { return } if req["state"] == "3" { - bools := svc.MoneyCheck(c, sess, data.Uid, data.ParentUid, data.StoreType, 0, 3, utils.StrToFloat64(data.Amount), "提现审核拒绝退回", utils.StrToInt64(utils.OrderUUID(data.Uid))) + bools := svc.MoneyCheck(c, sess, data.Uid, data.ParentUid, data.StoreType, 0, 2, utils.StrToFloat64(data.Amount), "提现审核拒绝退回", utils.StrToInt64(utils.OrderUUID(data.Uid))) if bools == false { sess.Rollback() e.OutErr(c, 400, e.NewErr(400, "审核失败")) diff --git a/app/db/db_order.go b/app/db/db_order.go index 515197b..b5a0d6f 100644 --- a/app/db/db_order.go +++ b/app/db/db_order.go @@ -4,6 +4,7 @@ import ( "applet/app/db/model" "applet/app/md" "applet/app/utils" + "github.com/gin-gonic/gin" "xorm.io/xorm" ) @@ -63,6 +64,14 @@ func GetOrderInfoAllEg(eg *xorm.Engine, oid string) *[]model.CommunityTeamOrderI } return &data } +func GetOrderInfoFirstEg(eg *xorm.Engine, oid string) *model.CommunityTeamOrderInfo { + var data model.CommunityTeamOrderInfo + get, err := eg.Where("oid=?", oid).Get(&data) + if err != nil || get == false { + return nil + } + return &data +} func GetOrderInfoEg(eg *xorm.Engine, oid string) *model.CommunityTeamOrderInfo { var data model.CommunityTeamOrderInfo get, err := eg.Where("oid=?", oid).Asc("id").Get(&data) @@ -72,7 +81,7 @@ func GetOrderInfoEg(eg *xorm.Engine, oid string) *model.CommunityTeamOrderInfo { return &data } -func GetOrderList(eg *xorm.Engine, arg map[string]string) *[]model.CommunityTeamOrder { +func GetOrderList(c *gin.Context, eg *xorm.Engine, arg map[string]string) *[]model.CommunityTeamOrder { var data []model.CommunityTeamOrder sess := eg.Where("1=1") if arg["uid"] != "" { @@ -87,6 +96,12 @@ func GetOrderList(eg *xorm.Engine, arg map[string]string) *[]model.CommunityTeam if arg["code"] != "" { sess.And("code=?", arg["code"]) } + if arg["start_time"] != "" { + sess.And("create_at>=?", arg["start_time"]) + } + if arg["end_time"] != "" { + sess.And("create_at 0 { + sess.Limit(limit, start) + } + count, err := sess.Desc("id").FindAndCount(&data) + if err != nil { + return nil, count + } + return &data, count +} func CommWhere(eg *xorm.Engine, arg map[string]string) *xorm.Session { sess := eg.Where("1=1") if arg["store_uid"] != "" { @@ -32,6 +52,7 @@ func CommWhere(eg *xorm.Engine, arg map[string]string) *xorm.Session { if arg["store_type"] != "" { sess.And("store_type=?", arg["store_type"]) } + if arg["state"] != "" { sess.And("state=?", arg["state"]) } diff --git a/app/db/dbs_map.go b/app/db/dbs_map.go index 47e6cd5..9f6bd53 100644 --- a/app/db/dbs_map.go +++ b/app/db/dbs_map.go @@ -92,7 +92,7 @@ func GetAllDatabaseDev() *[]model.DbMapping { var err error if cfg.Local { // 本地调试 加快速度 //fmt.Println("notice:LOCAL TEST, only masterId:** 123456 ** available!") - err = Db.Where("deleted_at != ? AND is_dev = '1' AND db_master_id=?", 1, 123456).Find(&m) + err = Db.Where("deleted_at != ? AND is_dev = '1' AND db_master_id=?", 1, 22255132).Find(&m) //err = Db.Where(" db_master_id=?", 74856566).Find(&m) } else { err = Db.Where("deleted_at != ? AND is_dev = '1' ", 1).Find(&m) diff --git a/app/db/model/community_team_order.go b/app/db/model/community_team_order.go index 90bbd06..fe7b8dc 100644 --- a/app/db/model/community_team_order.go +++ b/app/db/model/community_team_order.go @@ -41,4 +41,5 @@ type CommunityTeamOrder struct { StoreSettleAt int `json:"store_settle_at" xorm:"default 0 comment('') INT(11)"` SettleAt int `json:"settle_at" xorm:"default 0 comment('') INT(11)"` CommissionAt int `json:"commission_at" xorm:"default 0 comment('') INT(11)"` + IsNotice int `json:"is_notice" xorm:"not null default 0 comment('支付状态:0:未支付,1:已支付') TINYINT(2)"` } diff --git a/app/db/model/community_team_pay_order.go b/app/db/model/community_team_pay_order.go index 99d86c0..7263482 100644 --- a/app/db/model/community_team_pay_order.go +++ b/app/db/model/community_team_pay_order.go @@ -26,4 +26,5 @@ type CommunityTeamPayOrder struct { UserCommission string `json:"user_commission" xorm:"default 0.00 DECIMAL(20,2)"` AgentCommission string `json:"agent_commission" xorm:"default 0.00 DECIMAL(20,2)"` PlatformCommission string `json:"platform_commission" xorm:"default 0.00 DECIMAL(20,2)"` + IsNotice int `json:"is_notice" xorm:"not null default 0 comment('支付状态:0:未支付,1:已支付') TINYINT(2)"` } diff --git a/app/hdl/hdl_printer_list.go b/app/hdl/hdl_printer_list.go index 3646420..15f2dc8 100644 --- a/app/hdl/hdl_printer_list.go +++ b/app/hdl/hdl_printer_list.go @@ -45,7 +45,7 @@ func PrinterIndexDel(c *gin.Context) { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } - svc.PrinterDelIndex(c, idsMap["id"], idsMap["store_id"]) + svc.PrinterDelIndex(c, idsMap["id"]) } // 明细 diff --git a/app/hdl/hdl_store_index.go b/app/hdl/hdl_store_index.go index 89a3ea3..801f6db 100644 --- a/app/hdl/hdl_store_index.go +++ b/app/hdl/hdl_store_index.go @@ -3,6 +3,7 @@ package hdl import ( "applet/app/db" "applet/app/e" + storeSvc "applet/app/store/svc" "applet/app/svc" "applet/app/utils" "fmt" @@ -40,6 +41,21 @@ func StoreIndexTotal(c *gin.Context) { successCount = v["success_count"] waitCount = v["wait_count"] } + 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, + SUM(IF(state=1,1,0)) as wait_count + from community_team_pay_order + where %s +` + whereCodePay := where + " and create_at>='" + stime.Format("2006-01-02 15:04:05") + "' and create_at<'" + etime.Format("2006-01-02 15:04:05") + "'" + sqlCodePay = fmt.Sprintf(sqlCodePay, whereCodePay) + nativeStringCodePay, _ := db.QueryNativeString(svc.MasterDb(c), sqlCodePay) + for _, v := range nativeStringCodePay { + amount = utils.Float64ToStr(utils.StrToFloat64(amount) + utils.StrToFloat64(v["amount"])) + money = utils.Float64ToStr(utils.StrToFloat64(money) + utils.StrToFloat64(v["money"])) + commission = utils.Float64ToStr(utils.StrToFloat64(commission) + utils.StrToFloat64(v["commission"])) + count = utils.IntToStr(utils.StrToInt(count) + utils.StrToInt(v["count"])) + successCount = utils.IntToStr(utils.StrToInt(successCount) + utils.StrToInt(v["success_count"])) + } store := db.GetStoreIdEg(svc.MasterDb(c), utils.IntToStr(user.Info.Uid)) tmp := []map[string]string{ {"name": "营业总额", "value": svc.GetCommissionPrec(c, amount, "2", "1")}, @@ -50,9 +66,88 @@ func StoreIndexTotal(c *gin.Context) { if store.StoreType > 0 { tmp = append(tmp, map[string]string{"name": "订单收益", "value": svc.GetCommissionPrec(c, money, "2", "1")}) } - tmp = append(tmp, map[string]string{"name": "已付款订单量", "value": successCount}) - tmp = append(tmp, map[string]string{"name": "已取消订单量", "value": count}) - tmp = append(tmp, map[string]string{"name": "待提货订单量", "value": waitCount}) + tmp = append(tmp, map[string]string{"name": "已付款订单量", "value": utils.IntToStr(utils.StrToInt(successCount))}) + tmp = append(tmp, map[string]string{"name": "已取消订单量", "value": utils.IntToStr(utils.StrToInt(count))}) + tmp = append(tmp, map[string]string{"name": "待提货订单量", "value": utils.IntToStr(utils.StrToInt(waitCount))}) e.OutSuc(c, tmp, nil) return } + +func StoreWithdrawBase(c *gin.Context) { + user := svc.GetUser(c) + var res = map[string]string{ + "is_bind": "0", + "amount": "0", + "alipay_account": user.Profile.AccAlipay, + "alipay_name": user.Profile.AccAlipayRealName, + "info": "", + } + if user.Profile.AccAlipay != "" { + res["is_bind"] = "1" + } + + 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, store.StoreType) + if amountData != nil { + res["amount"] = amountData.Amount + } + } + e.OutSuc(c, res, nil) + return +} +func StoreWithdrawFlowCate(c *gin.Context) { + res := []map[string]string{ + {"name": "全部", "value": ""}, + {"name": "订单", "value": "1"}, + {"name": "收款", "value": "4"}, + {"name": "提现", "value": "2"}, + } + e.OutSuc(c, res, nil) + return +} +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) + store := db.GetStoreIdEg(svc.MasterDb(c), utils.IntToStr(user.Info.Uid)) + if store != nil { + req["parent_uid"] = utils.IntToStr(store.ParentUid) + req["store_type"] = utils.IntToStr(store.StoreType) + } + withdraw, total := db.GetStoreFlow(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, + "title": v.Title, + "ord_type": utils.IntToStr(v.OrdType), + "label": stateList[v.OrdType], + "oid": utils.Int64ToStr(v.Oid), + "time": v.CreateAt.Format("2006-01-02 15:04:05"), + } + if v.OrdType == 1 { + ord := db.GetOrderInfoFirstEg(svc.MasterDb(c), utils.Int64ToStr(v.Oid)) + if ord != nil { + tmp["title"] = ord.Title + } + } + list = append(list, tmp) + } + } + res := map[string]interface{}{ + "total": total, + "list": list, + } + e.OutSuc(c, res, nil) + return +} +func StoreWithdrawDoing(c *gin.Context) { + storeSvc.StoreWithdrawDoing(c) +} diff --git a/app/hdl/hdl_store_order.go b/app/hdl/hdl_store_order.go index 5dd3f41..fea5f8d 100644 --- a/app/hdl/hdl_store_order.go +++ b/app/hdl/hdl_store_order.go @@ -1,8 +1,15 @@ package hdl import ( + "applet/app/db" + "applet/app/db/model" + "applet/app/e" "applet/app/svc" + "applet/app/utils" + "encoding/json" "github.com/gin-gonic/gin" + "strings" + "time" ) func StoreOrderList(c *gin.Context) { @@ -17,3 +24,60 @@ func StoreOrderDetail(c *gin.Context) { func StoreOrderConfirm(c *gin.Context) { svc.StoreOrderConfirm(c) } +func GetNewOrderNoticeList(c *gin.Context) { + user := svc.GetUser(c) + storeId := user.Info.Uid + payTipOpen := db.SysCfgGet(c, "community_pay_tip_open") + list := make([]string, 0) + + if payTipOpen == "1" { + today := utils.GetTimeRange("today") + todayTime := time.Unix(today["start"], 0).Format("2006-01-02 15:04:05") + sql2 := `select * from community_team_pay_order where is_notice=0 and store_uid=? and state>0 and create_at>=? order by create_at asc` + nativeString2, _ := db.QueryNativeString(svc.MasterDb(c), sql2, storeId, todayTime) + payCodeTip := db.SysCfgGet(c, "community_pay_code_tip") + payGoodsTip := db.SysCfgGet(c, "community_pay_goods_tip") + payGoodsSecondTip := db.SysCfgGet(c, "community_pay_goods_second_tip") + payGoodsTipType := db.SysCfgGet(c, "community_pay_goods_tip_type") + for _, v := range nativeString2 { + payCodeTipStr := strings.ReplaceAll(payCodeTip, "[金额]", svc.GetCommissionPrec(c, v["amount"], "2", "1")) + list = append(list, payCodeTipStr) + svc.MasterDb(c).Where("id=? ", v["id"]).Cols("is_notice").Update(&model.CommunityTeamPayOrder{IsNotice: 1}) + } + sql := `select * from community_team_order where is_notice=0 and store_uid=? and state in(1,2) and pay_at>=? order by pay_at asc` + nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql, storeId, todayTime) + mainStr := payGoodsTip + if payGoodsTipType == "1" { + mainStr = payGoodsSecondTip + } + for k, v := range nativeString { + sql1 := `select title,num,sku_info from community_team_order_info + where oid=? +` + queryNativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql1, v["oid"]) + str := "" + for _, v1 := range queryNativeString { + tmp := make([]map[string]interface{}, 0) + json.Unmarshal([]byte(v["sku_info"]), &tmp) + skuStr := "" + for _, v2 := range tmp { + skuStr += utils.AnyToString(v2["value"]) + } + str += " " + v1["title"] + skuStr + v1["num"] + " 份" + } + if payGoodsTipType == "1" { + list = append(list, mainStr+str) + } + if payGoodsTipType != "1" && k == 0 { + list = append(list, mainStr) + } + svc.MasterDb(c).Where("oid=? ", v["oid"]).Cols("is_notice").Update(&model.CommunityTeamOrder{IsNotice: 1}) + } + + } + res := map[string]interface{}{ + "list": list, + } + e.OutSuc(c, res, nil) + return +} diff --git a/app/router/router.go b/app/router/router.go index cc82c17..75731c4 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -187,20 +187,23 @@ func routeCommunityTeam(r *gin.RouterGroup) { r.POST("/store/order/detail", hdl.StoreOrderDetail) r.POST("/store/order/confirm", hdl.StoreOrderConfirm) r.GET("/store/order/cate", hdl.StoreOrderCate) - + r.GET("/store/order/notice", hdl.GetNewOrderNoticeList) r.POST("/store/index/total", hdl.StoreIndexTotal) - - r.GET("/printer/cate/list", hdl.PrinterCateList) //打印机类型列表 - r.GET("/printer/location/list", hdl.PrinterLocationList) //打印机位置列表 - r.POST("/printer/list", hdl.PrinterIndex) //打印机列表 - r.POST("/printer/save", hdl.PrinterIndexSave) //打印机添加编辑 - r.POST("/printer/del", hdl.PrinterIndexDel) //打印机删除 - r.POST("/printer/module/list", hdl.PrinterModule) //打印机模板 - r.POST("/printer/module/save", hdl.PrinterIndexModuleSave) //打印机模板选择 - r.POST("/printer/use/save", hdl.PrinterIndexStateSave) //打印机使用状态调整 - r.POST("/printer/record/list", hdl.PrinterIndexRecord) //打印机明细 - r.POST("/printer/record/screen", hdl.PrinterIndexRecordScreen) //打印机筛选 - r.POST("/printer/send", hdl.PrinterIndexToSend) //打印机测试 - r.POST("/printer/check", hdl.PrinterIndexCheck) //订 + r.GET("/store/withdraw/base", hdl.StoreWithdrawBase) + r.GET("/store/withdraw/flow/cate", hdl.StoreWithdrawFlowCate) + r.POST("/store/withdraw/flow", hdl.StoreWithdrawFlow) + r.POST("/store/withdraw/doing", hdl.StoreWithdrawDoing) + r.GET("/printer/cate/list", hdl.PrinterCateList) //打印机类型列表 + r.GET("/printer/location/list", hdl.PrinterLocationList) //打印机位置列表 + r.POST("/printer/list", hdl.PrinterIndex) //打印机列表 + r.POST("/printer/save", hdl.PrinterIndexSave) //打印机添加编辑 + r.POST("/printer/del", hdl.PrinterIndexDel) //打印机删除 + r.POST("/printer/module/list", hdl.PrinterModule) //打印机模板 + r.POST("/printer/module/save", hdl.PrinterIndexModuleSave) //打印机模板选择 + r.POST("/printer/use/save", hdl.PrinterIndexStateSave) //打印机使用状态调整 + r.POST("/printer/record/list", hdl.PrinterIndexRecord) //打印机明细 + r.GET("/printer/record/screen", hdl.PrinterIndexRecordScreen) //打印机筛选 + r.POST("/printer/send", hdl.PrinterIndexToSend) //打印机测试 + r.POST("/printer/check", hdl.PrinterIndexCheck) //订 } diff --git a/app/svc/svc_order.go b/app/svc/svc_order.go index 2c599b1..a7c089b 100644 --- a/app/svc/svc_order.go +++ b/app/svc/svc_order.go @@ -36,7 +36,7 @@ func OrderList(c *gin.Context) { } user := GetUser(c) arg["uid"] = utils.IntToStr(user.Info.Uid) - data := db.GetOrderList(MasterDb(c), arg) + data := db.GetOrderList(c, MasterDb(c), arg) var state = []string{"待付款", "待提货", "已完成", "已取消"} list := make([]map[string]interface{}, 0) scheme, host := ImageBucket(c) diff --git a/app/svc/svc_pay_community_team.go b/app/svc/svc_pay_community_team.go index 139a604..42fe4b9 100644 --- a/app/svc/svc_pay_community_team.go +++ b/app/svc/svc_pay_community_team.go @@ -117,6 +117,14 @@ func CommonCallbackCommunityTeam(c *gin.Context, orderId string, payMethod strin ord.PayAt = time.Now() ord.PayMethod = md.PayMethodIDs[payMethod] MasterDb(c).Where("id=?", ord.Id).Cols("state,update_at,code,pay_at,pay_method").Update(ord) + engine := MasterDb(c) + storeId, ord1, goodsInfo, err := CommGetPrinterContent(c, utils.Int64ToStr(ord.Oid)) + if err != nil { + e.OutErr(c, 400, err) + return + } + //打印操作 + go ReplaceDoing(c, engine, storeId, ord1, goodsInfo) return } func Code() string { diff --git a/app/svc/svc_pay_community_team_pay.go b/app/svc/svc_pay_community_team_pay.go index ef87341..34316fa 100644 --- a/app/svc/svc_pay_community_team_pay.go +++ b/app/svc/svc_pay_community_team_pay.go @@ -118,7 +118,7 @@ func CommonCallbackCommunityTeamPay(c *gin.Context, orderId string, payMethod st if ord.StoreType == 1 { money = utils.StrToFloat64(ord.Amount) - utils.StrToFloat64(ord.PlatformCommission) } - bools := MoneyCheck(c, sess, ord.StoreUid, ord.ParentUid, ord.StoreType, 0, 1, money, "收款码收款", ord.Oid) + bools := MoneyCheck(c, sess, ord.StoreUid, ord.ParentUid, ord.StoreType, 0, 4, money, "收款码收款", ord.Oid) if bools == false { sess.Rollback() return diff --git a/app/svc/svc_printer_list.go b/app/svc/svc_printer_list.go index be8b78e..0bd7ca1 100644 --- a/app/svc/svc_printer_list.go +++ b/app/svc/svc_printer_list.go @@ -135,10 +135,10 @@ func PrinterIndexSave(c *gin.Context) { return } } - + user := GetUser(c) var module = model.CommunityTeamStorePrinter{ Id: utils.StrToInt(search.Id), - StoreId: utils.StrToInt(search.StoreId), + StoreId: user.Info.Uid, SnNum: search.SnNum, IdentificationCode: search.IdentificationCode, Name: search.Name, @@ -175,7 +175,6 @@ func PrinterIndexSave(c *gin.Context) { return } - e.OutSuc(c, "success", nil) return } @@ -222,9 +221,11 @@ func PrinterIndexStateSave(c *gin.Context) { } // 删除打印机 -func PrinterDelIndex(c *gin.Context, ids, storeId string) { +func PrinterDelIndex(c *gin.Context, ids string) { engine := MasterDb(c) //查出这条记录拿sn码 + user := GetUser(c) + storeId := utils.IntToStr(user.Info.Uid) printerOne, _ := db.GetPrinterIndexById(engine, ids, storeId) if printerOne.Id == 0 { e.OutErr(c, 400, e.NewErr(400, "删除失败")) @@ -257,17 +258,14 @@ func PrinterDelIndex(c *gin.Context, ids, storeId string) { // 明细筛选条件 func PrinterIndexRecordScreen(c *gin.Context) { - var search md.RecordRequest - if err := c.ShouldBindJSON(&search); err != nil { - e.OutErr(c, e.ERR_INVALID_ARGS, err) - return - } + engine := MasterDb(c) if engine == nil { e.OutErr(c, e.ERR_MASTER_ID, nil) return } - printer, _ := db.GetPrinterIndexAll(engine, search.StoreId) + user := GetUser(c) + printer, _ := db.GetPrinterIndexAll(engine, utils.IntToStr(user.Info.Uid)) var r md.RecordPrinterScreen r.TimeSort = []md.NewSelectList{ { diff --git a/app/svc/svc_store_order.go b/app/svc/svc_store_order.go index 520aafe..0612427 100644 --- a/app/svc/svc_store_order.go +++ b/app/svc/svc_store_order.go @@ -59,7 +59,12 @@ func StoreOrderList(c *gin.Context) { } user := GetUser(c) arg["store_uid"] = utils.IntToStr(user.Info.Uid) - data := db.GetOrderList(MasterDb(c), arg) + if arg["type"] != "" && arg["date"] != "" { + stime, etime := GetDate(c, arg) + arg["start_time"] = stime.Format("2006-01-02 15:04:05") + arg["end_time"] = etime.Format("2006-01-02 15:04:05") + } + data := db.GetOrderList(c, MasterDb(c), arg) var state = []string{"待付款", "待提货", "已完成", "已取消"} list := make([]map[string]interface{}, 0) if data != nil {