diff --git a/business/jxstore/cms/job.go b/business/jxstore/cms/job.go index b4a73c9a2..9de59a8e1 100644 --- a/business/jxstore/cms/job.go +++ b/business/jxstore/cms/job.go @@ -439,7 +439,7 @@ func AcceptJob(ctx *jxcontext.Context, jobID, dropShippingDeliveryID, dropShippi return } dao.Commit(db, txDB) - } else { + } else if job.JobCategoryID != model.JobCategoryIDUnion { //任务限时完成 timer := checkLimitJobOrders(db, job, jobOrder, model.JobTimerTypeAccept) JobTimers.s.Lock() @@ -1951,16 +1951,19 @@ func GetUnionActList(ctx *jxcontext.Context, vendorID, actType int) (actList []* func ShareUnionLink(ctx *jxcontext.Context, jobID, linkType int) (link string, err error) { var ( - db = dao.GetDB() - job = &model.Job{} + db = dao.GetDB() + job = &model.Job{} + jobOrder = &model.JobOrder{} ) job.ID = jobID err = dao.GetEntity(db, job) if err != nil { return link, err } + jobOrder.JobID = job.ID + err = dao.GetEntity(db, jobOrder, "JobID") if handler := partner.GetHandler(job.VendorID); handler != nil { - handler.ShareUnionLink(ctx, linkType) + handler.ShareUnionLink(ctx, linkType, job.UnionActID, jobOrder.UserID) } return link, err } diff --git a/business/jxstore/cms/order.go b/business/jxstore/cms/order.go index f0e30d17e..c9be266fe 100644 --- a/business/jxstore/cms/order.go +++ b/business/jxstore/cms/order.go @@ -29,11 +29,18 @@ func CreateOrder(ctx *jxcontext.Context, type1, orderType int, way string, price if err = auth2.CheckWeixinminiAuthBind(ctx.GetUserID()); err != nil { return "", errCode, err } + txDB, _ := dao.Begin(db) + defer func() { + if r := recover(); r != nil { + dao.Rollback(db, txDB) + panic(r) + } + }() if type1 == model.OrderTypeCash { //如果用户没有对应账单信息就给他生成一条 userBill, err := dao.GetUserBill(db, ctx.GetUserID(), "") if userBill == nil { - err = financial.AddUserBill(db, jxutils.GenBillID(), ctx.GetUserID()) + err = financial.AddUserBill(txDB, jxutils.GenBillID(), ctx.GetUserID()) } if userBill.AccountBalance < price { return "", model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("用户余额不足!") @@ -63,14 +70,7 @@ func CreateOrder(ctx *jxcontext.Context, type1, orderType int, way string, price CityCode: cCode, } dao.WrapAddIDCULEntity(order, ctx.GetUserName()) - txDB, _ := dao.Begin(db) - defer func() { - if r := recover(); r != nil { - dao.Rollback(db, txDB) - panic(r) - } - }() - if err = dao.CreateEntity(db, order); err != nil { + if err = dao.CreateEntityTx(txDB, order); err != nil { dao.Rollback(db, txDB) } dao.Commit(db, txDB) @@ -96,11 +96,19 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType stri } payHandler.Order = order //如果用户没有对应账单信息就给他生成一条 + txDB, _ := dao.Begin(db) + defer func() { + if r := recover(); r != nil { + dao.Rollback(db, txDB) + panic(r) + } + }() userBill, err := dao.GetUserBill(db, order.UserID, "") if userBill == nil { - err = financial.AddUserBill(db, jxutils.GenBillID(), order.UserID) + err = financial.AddUserBill(txDB, jxutils.GenBillID(), order.UserID) } - err = payHandler.CreatePay() + err = payHandler.CreatePay(txDB) + dao.Commit(db, txDB) globals.SugarLogger.Debugf("result : %v", utils.Format4Output(payHandler.WxPayParam, false)) return payHandler.WxPayParam, err } diff --git a/business/jxstore/cms/user2.go b/business/jxstore/cms/user2.go index f305ca35e..858857592 100644 --- a/business/jxstore/cms/user2.go +++ b/business/jxstore/cms/user2.go @@ -601,7 +601,7 @@ func InvestMember(ctx *jxcontext.Context, memberID int, userID string, isFree bo } if !isFree { //支出明细 - if err = financial.AddExpendUpdateAccount(db, userBill, model.BillTypeMember, memberCard.Price, 0); err != nil { + if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypeMember, memberCard.Price, 0); err != nil { dao.Rollback(db, txDB) return } diff --git a/business/jxstore/event/event.go b/business/jxstore/event/event.go index 6a03d6d77..51d71b519 100644 --- a/business/jxstore/event/event.go +++ b/business/jxstore/event/event.go @@ -608,12 +608,12 @@ func DeleteMessageGroup(ctx *jxcontext.Context, groupID int, userID string, flag } }() //账户支出 - if err = financial.AddExpendUpdateAccount(db, userBill, model.BillTypeQuitGroup, quitPrice, 0); err != nil { + if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypeQuitGroup, quitPrice, 0); err != nil { dao.Rollback(db, txDB) return errCode, err } //群主收到退团金额 - if err = financial.AddIncomeUpdateAccount(db, userBillGroupMaster, model.BillTypeQuitGroup, quitPrice, 0); err != nil { + if err = financial.AddIncomeUpdateAccount(txDB, userBillGroupMaster, model.BillTypeQuitGroup, quitPrice, 0); err != nil { dao.Rollback(db, txDB) return errCode, err } diff --git a/business/jxstore/financial/financial.go b/business/jxstore/financial/financial.go index 060ff6e60..07c10d2ec 100644 --- a/business/jxstore/financial/financial.go +++ b/business/jxstore/financial/financial.go @@ -6,6 +6,7 @@ import ( "crypto/sha256" "encoding/json" "fmt" + "github.com/astaxie/beego/client/orm" "sort" "strings" "time" @@ -33,7 +34,7 @@ var ( } ) -func (p *PayHandler) CreatePay() (err error) { +func (p *PayHandler) CreatePay(txDB orm.TxOrmer) (err error) { switch p.PayType { case model.PayTypeTL: param := &tonglianpayapi.CreateUnitorderOrderParam{ @@ -53,7 +54,7 @@ func (p *PayHandler) CreatePay() (err error) { json.Unmarshal([]byte(result.PayInfo), &result2) p.Order.PrepayID = result2.Package[strings.LastIndex(result2.Package, "=")+1 : len(result2.Package)] p.Order.TransactionID = result.TrxID - _, err = dao.UpdateEntity(dao.GetDB(), p.Order, "PrepayID", "TransactionID") + _, err = dao.UpdateEntityTx(txDB, p.Order, "PrepayID", "TransactionID") } case model.PayTypeWX: param := &wxpayapi.CreateOrderParam{ @@ -96,7 +97,7 @@ func (p *PayHandler) CreatePay() (err error) { p.WxPayParam = wxPay p.Order.PrepayID = result.PrepayID p.Order.Comment = result.CodeURL - _, err = dao.UpdateEntity(dao.GetDB(), p.Order, "PrepayID", "Comment") + _, err = dao.UpdateEntityTx(txDB, p.Order, "PrepayID", "Comment") } else { return err2 } diff --git a/business/jxstore/financial/pay.go b/business/jxstore/financial/pay.go index 6844c55fe..c6f500c61 100644 --- a/business/jxstore/financial/pay.go +++ b/business/jxstore/financial/pay.go @@ -58,7 +58,7 @@ func OnPayFinished(order *model.Order) (err error) { case model.OrderTypePay: //如果是账户充值(发布任务等) //账户收入 - if err = AddIncomeUpdateAccount(db, userBill, model.BillTypeInvest, order.PayPrice, 0); err != nil { + if err = AddIncomeUpdateAccount(txDB, userBill, model.BillTypeInvest, order.PayPrice, 0); err != nil { dao.Rollback(db, txDB) } default: @@ -93,7 +93,7 @@ func OnCashFinished(order *model.Order) (err error) { case model.OrderTypeCash: //如果是账户提现 //账户支出 - if err = AddExpendUpdateAccount(db, userBill, model.BillTypeCash, order.PayPrice, 0); err != nil { + if err = AddExpendUpdateAccount(txDB, userBill, model.BillTypeCash, order.PayPrice, 0); err != nil { dao.Rollback(db, txDB) } default: diff --git a/business/jxstore/partner/jds/union.go b/business/jxstore/partner/jds/union.go index c6750c5f6..c53ad35f0 100644 --- a/business/jxstore/partner/jds/union.go +++ b/business/jxstore/partner/jds/union.go @@ -17,7 +17,7 @@ func init() { partner.HandlerMap[model.VendorIDJDShop] = unionHandler } -func (s *UnionHandler) ShareUnionLink(ctx *jxcontext.Context, linkType int) (link string, err error) { +func (s *UnionHandler) ShareUnionLink(ctx *jxcontext.Context, linkType, unionActID int, userID string) (link string, err error) { return "jds", err } diff --git a/business/jxstore/partner/mt/union.go b/business/jxstore/partner/mt/union.go index af1deae13..bd42d133f 100644 --- a/business/jxstore/partner/mt/union.go +++ b/business/jxstore/partner/mt/union.go @@ -7,8 +7,13 @@ import ( "strings" ) -func (s *UnionHandler) ShareUnionLink(ctx *jxcontext.Context, linkType int) (link string, err error) { - return "mt", err +func (s *UnionHandler) ShareUnionLink(ctx *jxcontext.Context, linkType, unionActID int, userID string) (link string, err error) { + if linkType == partner.LinkTypeWeiXinMini { + //return api.MtUnionAPI.GenerateLink(unionActID, userID) + } else { + + } + return link, err } func (s *UnionHandler) GetUnionActList(ctx *jxcontext.Context, actType int) (actList []*partner.ActivityList, err error) { diff --git a/business/jxstore/partner/partner.go b/business/jxstore/partner/partner.go index 2c1410a53..2722ee51b 100644 --- a/business/jxstore/partner/partner.go +++ b/business/jxstore/partner/partner.go @@ -31,7 +31,7 @@ func init() { } type UnionInterface interface { - ShareUnionLink(ctx *jxcontext.Context, linkType int) (link string, err error) + ShareUnionLink(ctx *jxcontext.Context, linkType, unionActID int, userID string) (link string, err error) GetUnionActList(ctx *jxcontext.Context, actType int) (result []*ActivityList, err error) } diff --git a/business/model/job.go b/business/model/job.go index 2594a6d3c..286477f20 100644 --- a/business/model/job.go +++ b/business/model/job.go @@ -125,6 +125,7 @@ type Job struct { BrowseCount int `json:"browseCount"` //任务浏览量,点一下加一下 UnionImg string `json:"unionImg"` //联盟任务分享链接的背景图 UnionQrcodePosition string `json:"unionQrcodePosition"` //联盟任务分享链接的二维码图的方位 + UnionActID int `orm:"column(union_act_id)" json:"unionActID"` //联盟任务ID // JobSteps []*JobStep `orm:"-" json:"jobSteps"` // JobImgs []*JobImg `orm:"-" json:"jobImgs"` }