删除一些model和dao文件
This commit is contained in:
@@ -60,13 +60,8 @@ func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
|||||||
"purchaseVendorInfo": model.PurchaseVendorInfo,
|
"purchaseVendorInfo": model.PurchaseVendorInfo,
|
||||||
"afsReasonTypeName": model.AfsReasonTypeName,
|
"afsReasonTypeName": model.AfsReasonTypeName,
|
||||||
"afsAppealTypeName": model.AfsAppealTypeName,
|
"afsAppealTypeName": model.AfsAppealTypeName,
|
||||||
"actTypeName": model.ActTypeName,
|
|
||||||
"actStatusName": model.ActStatusName,
|
|
||||||
"actCreateTypeName": model.ActCreateTypeName,
|
|
||||||
"configTypeName": model.ConfigTypeName,
|
"configTypeName": model.ConfigTypeName,
|
||||||
"userTypeName": model.UserTypeName,
|
"userTypeName": model.UserTypeName,
|
||||||
"payStatusName": model.PayStatusName,
|
|
||||||
"refundStatusName": model.RefundStatusName,
|
|
||||||
"complaintReasons": model.ComplaintReasons,
|
"complaintReasons": model.ComplaintReasons,
|
||||||
"supplementType": model.SupplementTypeName,
|
"supplementType": model.SupplementTypeName,
|
||||||
"operateType": model.OperateTypeName,
|
"operateType": model.OperateTypeName,
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import (
|
|||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/event"
|
"git.rosy.net.cn/jx-callback/business/jxstore/event"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/financial"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
@@ -356,26 +354,6 @@ func LoadUserCart(ctx *jxcontext.Context, userID string, storeIDs []int) (cartIt
|
|||||||
return cartItems, err
|
return cartItems, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSelfInfo(ctx *jxcontext.Context) (getSelfInfoResult *dao.GetSelfInfoResult, err error) {
|
|
||||||
tokenInfo, err := auth2.GetTokenInfo(ctx.GetToken())
|
|
||||||
if err == nil {
|
|
||||||
if getSelfInfoResult, err = dao.GetUserByIDWithMembers(dao.GetDB(), "user_id", tokenInfo.GetID()); err == nil {
|
|
||||||
if userMembers, err3 := dao.GetUserMember(dao.GetDB(), getSelfInfoResult.User.UserID, 0); err3 == nil {
|
|
||||||
getSelfInfoResult.UserMembers = userMembers
|
|
||||||
} else {
|
|
||||||
err = err3
|
|
||||||
}
|
|
||||||
if price, err := dao.GetUserAllWaitCashPrice(dao.GetDB(), getSelfInfoResult.User.UserID); err == nil {
|
|
||||||
getSelfInfoResult.WaitCashPrice = price
|
|
||||||
}
|
|
||||||
if price, err := dao.GetUserAllWaitRealCashPrice(dao.GetDB(), getSelfInfoResult.User.UserID); err == nil {
|
|
||||||
getSelfInfoResult.WaitRealCashPrice = price
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getSelfInfoResult, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func RefreshUserMemberStatus(ctx *jxcontext.Context) (err error) {
|
func RefreshUserMemberStatus(ctx *jxcontext.Context) (err error) {
|
||||||
var (
|
var (
|
||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
@@ -390,90 +368,6 @@ func RefreshUserMemberStatus(ctx *jxcontext.Context) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func InvestMember(ctx *jxcontext.Context, memberID int, userID string, isFree bool) (errCode string, err error) {
|
|
||||||
var (
|
|
||||||
db = dao.GetDB()
|
|
||||||
memberCards []*model.MemberCard
|
|
||||||
memberCard *model.MemberCard
|
|
||||||
userIDReal string
|
|
||||||
)
|
|
||||||
if !isFree {
|
|
||||||
userIDReal = ctx.GetUserID()
|
|
||||||
} else {
|
|
||||||
userIDReal = userID
|
|
||||||
}
|
|
||||||
userMembers, err := dao.GetUserMember(db, userIDReal, model.MemberTypeNormal)
|
|
||||||
configList, err := dao.QueryConfigs(db, model.ConfigTypeName[model.ConfigTypeMemberCard], model.ConfigTypeMemberCard, "")
|
|
||||||
userBill, err := dao.GetUserBill(db, userIDReal, "")
|
|
||||||
if len(configList) <= 0 {
|
|
||||||
return "", fmt.Errorf("未找到会员卡配置!")
|
|
||||||
}
|
|
||||||
config := configList[0]
|
|
||||||
err = jxutils.Strings2Objs(config.Value, &memberCards)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
for _, v := range memberCards {
|
|
||||||
if v.ID == memberID {
|
|
||||||
memberCard = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !isFree {
|
|
||||||
//验证微信绑定
|
|
||||||
if err = auth2.CheckWeixinminiAuthBind(userIDReal); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if userBill.AccountBalance < memberCard.Price {
|
|
||||||
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("用户余额不足,请充值!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
txDB, _ := dao.Begin(db)
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
dao.Rollback(db, txDB)
|
|
||||||
panic(r)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
//证明已经开了会员了,相当于续费
|
|
||||||
if len(userMembers) > 0 {
|
|
||||||
userMember := userMembers[0]
|
|
||||||
if memberID == model.MemberCardTypeMonth {
|
|
||||||
userMember.EndAt = userMember.EndAt.AddDate(0, 1, 0)
|
|
||||||
} else {
|
|
||||||
userMember.EndAt = userMember.EndAt.AddDate(1, 0, 0)
|
|
||||||
}
|
|
||||||
if _, err = dao.UpdateEntity(db, userMember, "EndAt"); err != nil {
|
|
||||||
dao.Rollback(db, txDB)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
userMember2 := &model.UserMember{
|
|
||||||
UserID: userIDReal,
|
|
||||||
MemberType: model.MemberTypeNormal,
|
|
||||||
MemberTypeID: memberID,
|
|
||||||
}
|
|
||||||
if memberID == model.MemberCardTypeMonth {
|
|
||||||
userMember2.EndAt = time.Now().AddDate(0, 1, 0)
|
|
||||||
} else {
|
|
||||||
userMember2.EndAt = time.Now().AddDate(1, 0, 0)
|
|
||||||
}
|
|
||||||
dao.WrapAddIDCULDEntity(userMember2, ctx.GetUserName())
|
|
||||||
if err = dao.CreateEntity(db, userMember2); err != nil {
|
|
||||||
dao.Rollback(db, txDB)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !isFree {
|
|
||||||
//支出明细
|
|
||||||
if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypeMember, memberCard.Price, 0); err != nil {
|
|
||||||
dao.Rollback(db, txDB)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dao.Commit(db, txDB)
|
|
||||||
return errCode, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateUser(ctx *jxcontext.Context, payload map[string]interface{}) (err error) {
|
func UpdateUser(ctx *jxcontext.Context, payload map[string]interface{}) (err error) {
|
||||||
var (
|
var (
|
||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/financial"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
@@ -554,82 +553,6 @@ func UpdateMessageGroup(ctx *jxcontext.Context, groupID int, payload map[string]
|
|||||||
return num, err
|
return num, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteMessageGroup(ctx *jxcontext.Context, groupID int, userID string, flag bool) (errCode string, err error) {
|
|
||||||
var (
|
|
||||||
db = dao.GetDB()
|
|
||||||
messageGroup = &model.MessageGroup{
|
|
||||||
GroupID: groupID,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
if err = dao.GetEntity(db, messageGroup, "GroupID"); err != nil {
|
|
||||||
return errCode, err
|
|
||||||
}
|
|
||||||
//解散群
|
|
||||||
if flag {
|
|
||||||
if messageGroup.UserID != ctx.GetUserID() {
|
|
||||||
return errCode, fmt.Errorf("只有群主才能解散群!")
|
|
||||||
}
|
|
||||||
messageGroup.DeletedAt = time.Now()
|
|
||||||
messageGroup.LastOperator = ctx.GetUserName()
|
|
||||||
dao.UpdateEntity(db, messageGroup, "DeletedAt", "LastOperator")
|
|
||||||
messageGroupMembers, _ := dao.GetMessageGroupMembers(db, groupID, 0, "")
|
|
||||||
for _, v := range messageGroupMembers {
|
|
||||||
v.DeletedAt = time.Now()
|
|
||||||
v.LastOperator = ctx.GetUserName()
|
|
||||||
dao.UpdateEntity(db, v, "DeletedAt", "LastOperator")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//token中用户与传入user不一致就判定为踢人
|
|
||||||
if ctx.GetUserID() != userID {
|
|
||||||
if messageGroup.UserID != ctx.GetUserID() {
|
|
||||||
messageGroupMembers, err := dao.GetMessageGroupMembers(db, groupID, 0, ctx.GetUserID())
|
|
||||||
if err != nil {
|
|
||||||
return errCode, err
|
|
||||||
}
|
|
||||||
if messageGroupMembers[0].Type == model.GroupMemberTypeNormal {
|
|
||||||
return errCode, fmt.Errorf("只有创建者和管理员才能踢人!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
quitPrice := messageGroup.QuitPrice
|
|
||||||
userBill, err := dao.GetUserBill(db, userID, "")
|
|
||||||
userBillGroupMaster, err := dao.GetUserBill(db, messageGroup.UserID, "")
|
|
||||||
if err != nil {
|
|
||||||
return errCode, err
|
|
||||||
}
|
|
||||||
if userBill.AccountBalance < quitPrice {
|
|
||||||
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("用户余额不足,请充值!")
|
|
||||||
}
|
|
||||||
txDB, _ := dao.Begin(db)
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
dao.Rollback(db, txDB)
|
|
||||||
panic(r)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
//账户支出
|
|
||||||
if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypeQuitGroup, quitPrice, 0); err != nil {
|
|
||||||
dao.Rollback(db, txDB)
|
|
||||||
return errCode, err
|
|
||||||
}
|
|
||||||
//群主收到退团金额
|
|
||||||
if err = financial.AddIncomeUpdateAccount(txDB, userBillGroupMaster, model.BillTypeQuitGroup, quitPrice, 0); err != nil {
|
|
||||||
dao.Rollback(db, txDB)
|
|
||||||
return errCode, err
|
|
||||||
}
|
|
||||||
dao.Commit(db, txDB)
|
|
||||||
}
|
|
||||||
messageGroupMembers, err := dao.GetMessageGroupMembers(db, groupID, 0, userID)
|
|
||||||
if err != nil {
|
|
||||||
return errCode, err
|
|
||||||
}
|
|
||||||
messageGroupMembers[0].DeletedAt = time.Now()
|
|
||||||
messageGroupMembers[0].LastOperator = ctx.GetUserName()
|
|
||||||
dao.UpdateEntity(db, messageGroupMembers[0], "DeletedAt", "LastOperator")
|
|
||||||
}
|
|
||||||
return errCode, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func TransferMessageGroupMaster(ctx *jxcontext.Context, groupID int, userID string) (err error) {
|
func TransferMessageGroupMaster(ctx *jxcontext.Context, groupID int, userID string) (err error) {
|
||||||
var (
|
var (
|
||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
|
|||||||
@@ -1,167 +1 @@
|
|||||||
package financial
|
package financial
|
||||||
|
|
||||||
import (
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
|
||||||
"github.com/astaxie/beego/client/orm"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func AddBillIncome(txDB orm.TxOrmer, billID int64, billType, incomePrice, jobID int) (err error) {
|
|
||||||
billIncome := &model.BillIncome{
|
|
||||||
BillID: billID,
|
|
||||||
Type: billType,
|
|
||||||
IncomePrice: incomePrice,
|
|
||||||
JobID: jobID,
|
|
||||||
}
|
|
||||||
dao.WrapAddIDCULEntity(billIncome, jxcontext.AdminCtx.GetUserName())
|
|
||||||
return dao.CreateEntityTx(txDB, billIncome)
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddBillExpend(txDB orm.TxOrmer, billID int64, billType, expendPrice, jobID int) (err error) {
|
|
||||||
billExpend := &model.BillExpend{
|
|
||||||
BillID: billID,
|
|
||||||
Type: billType,
|
|
||||||
ExpendPrice: expendPrice,
|
|
||||||
JobID: jobID,
|
|
||||||
}
|
|
||||||
dao.WrapAddIDCULEntity(billExpend, jxcontext.AdminCtx.GetUserName())
|
|
||||||
return dao.CreateEntityTx(txDB, billExpend)
|
|
||||||
}
|
|
||||||
func AddUserBill(txDB orm.TxOrmer, billID int64, userID string) (err error) {
|
|
||||||
userBillInsert := &model.UserBill{
|
|
||||||
BillID: billID,
|
|
||||||
UserID: userID,
|
|
||||||
}
|
|
||||||
dao.WrapAddIDCULDEntity(userBillInsert, jxcontext.AdminCtx.GetUserName())
|
|
||||||
return dao.CreateEntityTx(txDB, userBillInsert)
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddUserBillDb(db *dao.DaoDB, billID int64, userID string) (err error) {
|
|
||||||
userBillInsert := &model.UserBill{
|
|
||||||
BillID: billID,
|
|
||||||
UserID: userID,
|
|
||||||
}
|
|
||||||
dao.WrapAddIDCULDEntity(userBillInsert, jxcontext.AdminCtx.GetUserName())
|
|
||||||
return dao.CreateEntity(db, userBillInsert)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetUserBillDetail(ctx *jxcontext.Context, userID, fromTime, toTime string, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
|
||||||
return dao.GetUserBillDetail(dao.GetDB(), userID, utils.Str2Time(fromTime), utils.Str2Time(toTime), pageSize, offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddExpendUpdateAccount(txDB orm.TxOrmer, userBill *model.UserBill, billType, price, jobID int) (err error) {
|
|
||||||
//1、账户支出增加一条记录
|
|
||||||
err = AddBillExpend(txDB, userBill.BillID, billType, price, jobID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
//2、账户表余额减少相应值
|
|
||||||
userBill.AccountBalance -= price
|
|
||||||
_, err = dao.UpdateEntityTx(txDB, userBill, "AccountBalance")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddIncomeUpdateAccount(txDB orm.TxOrmer, userBill *model.UserBill, billType, price, jobID int) (err error) {
|
|
||||||
//2、账户收入增加一条记录
|
|
||||||
err = AddBillIncome(txDB, userBill.BillID, billType, price, jobID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
//1、根据任务剩余数量退钱到账户余额中
|
|
||||||
userBill.AccountBalance += price
|
|
||||||
_, err = dao.UpdateEntityTx(txDB, userBill, "AccountBalance")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func SettleUnionOrders(ctx *jxcontext.Context, vendorIDs []int) (err error) {
|
|
||||||
var (
|
|
||||||
db = dao.GetDB()
|
|
||||||
unionOrderVendorMap map[int][]*model.UnionOrder //key 为平台ID
|
|
||||||
unionOrderMap map[string]map[int][]*model.UnionOrder //key为userID,整个map把每个User的不同平台的订单放一起
|
|
||||||
settleOrders []*model.UnionOrderSettle
|
|
||||||
)
|
|
||||||
unionOrderVendorMap = make(map[int][]*model.UnionOrder)
|
|
||||||
unionOrderMap = make(map[string]map[int][]*model.UnionOrder)
|
|
||||||
unionOrders, err := dao.GetUnionOrders(db, vendorIDs, []int{model.UnionOrderStatusFinish}, utils.ZeroTimeValue, utils.ZeroTimeValue, model.NO)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, v := range unionOrders {
|
|
||||||
if _, ok := unionOrderMap[v.UserID]; ok {
|
|
||||||
if _, ol := unionOrderVendorMap[v.VendorID]; ol {
|
|
||||||
unionOrderMap[v.UserID][v.VendorID] = append(unionOrderMap[v.UserID][v.VendorID], v)
|
|
||||||
} else {
|
|
||||||
unionOrderMap[v.UserID][v.VendorID] = []*model.UnionOrder{v}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
unionOrderVendorMap[v.VendorID] = []*model.UnionOrder{v}
|
|
||||||
unionOrderMap[v.UserID] = unionOrderVendorMap
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for userID, v := range unionOrderMap {
|
|
||||||
var (
|
|
||||||
billID int64
|
|
||||||
)
|
|
||||||
userBill, _ := dao.GetUserBill(db, userID, "")
|
|
||||||
if userBill == nil {
|
|
||||||
billID = jxutils.GenBillID()
|
|
||||||
AddUserBillDb(db, billID, userID)
|
|
||||||
} else {
|
|
||||||
billID = userBill.BillID
|
|
||||||
}
|
|
||||||
for vendorID, vv := range v {
|
|
||||||
var (
|
|
||||||
sumPrice, count int
|
|
||||||
)
|
|
||||||
for _, unionOrder := range vv {
|
|
||||||
count++
|
|
||||||
sumPrice += unionOrder.PromotionAmount
|
|
||||||
}
|
|
||||||
unionOrderSettle := &model.UnionOrderSettle{
|
|
||||||
BillID: billID,
|
|
||||||
VendorID: vendorID,
|
|
||||||
Issue: jxutils.GetIssue(),
|
|
||||||
EarningPrice: sumPrice,
|
|
||||||
OrderCount: count,
|
|
||||||
}
|
|
||||||
dao.WrapAddIDCULEntity(unionOrderSettle, ctx.GetUserName())
|
|
||||||
settleOrders = append(settleOrders, unionOrderSettle)
|
|
||||||
//err = dao.CreateEntity(db, unionOrderSettle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
txDB, _ := dao.Begin(db)
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
dao.Rollback(db, txDB)
|
|
||||||
panic(r)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
for _, v := range settleOrders {
|
|
||||||
//插入结算表
|
|
||||||
if err = dao.CreateEntityTx(txDB, v); err != nil {
|
|
||||||
dao.Rollback(db, txDB)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
//更新用户账户
|
|
||||||
userBill, _ := dao.GetUserBill(db, "", utils.Int64ToStr(v.BillID))
|
|
||||||
if err = AddIncomeUpdateAccount(txDB, userBill, model.BillTypeUnionShare, v.EarningPrice, 0); err != nil {
|
|
||||||
dao.Rollback(db, txDB)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//修改订单结算标志
|
|
||||||
for _, v := range unionOrders {
|
|
||||||
v.IsEarning = model.YES
|
|
||||||
v.UpdatedAt = time.Now()
|
|
||||||
if _, err = dao.UpdateEntityTx(txDB, v, "IsEarning", "UpdatedAt"); err != nil {
|
|
||||||
dao.Rollback(db, txDB)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dao.Commit(db, txDB)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,106 +1 @@
|
|||||||
package financial
|
package financial
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PayHandler struct {
|
|
||||||
PayType int `json:"-"` //支付方式
|
|
||||||
Ctx *jxcontext.Context
|
|
||||||
Order *model.Order
|
|
||||||
VendorPayType string
|
|
||||||
|
|
||||||
WxPayParam *WxPayParam `json:"wxPayParam"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type WxPayParam struct {
|
|
||||||
Prepayid string `json:"prepayid"`
|
|
||||||
Noncestr string `json:"noncestr"`
|
|
||||||
Timestamp string `json:"timestamp"`
|
|
||||||
Package string `json:"package"`
|
|
||||||
Partnerid string `json:"partnerid"`
|
|
||||||
Appid string `json:"appid"`
|
|
||||||
Sign string `json:"sign"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PayHandlerInterface interface {
|
|
||||||
CreatePay() (err error)
|
|
||||||
CreateRefund() (err error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func OnPayFinished(order *model.Order) (err error) {
|
|
||||||
var (
|
|
||||||
db = dao.GetDB()
|
|
||||||
)
|
|
||||||
globals.SugarLogger.Debugf("OnPayFinished begin modify account order: %v", utils.Format4Output(order, false))
|
|
||||||
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 {
|
|
||||||
globals.SugarLogger.Debugf("OnPayFinished 未找到该用户的账单 order: %v", utils.Format4Output(order, false))
|
|
||||||
return fmt.Errorf("未找到该用户的账单!%v", order.UserID)
|
|
||||||
}
|
|
||||||
//根据订单类型来操作账户
|
|
||||||
switch order.Type {
|
|
||||||
case model.OrderTypePay:
|
|
||||||
//如果是账户充值(发布任务等)
|
|
||||||
//账户收入
|
|
||||||
if err = AddIncomeUpdateAccount(txDB, userBill, model.BillTypeInvest, order.PayPrice, 0); err != nil {
|
|
||||||
dao.Rollback(db, txDB)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
globals.SugarLogger.Debugf("OnPayFinished 暂不支持此订单类型 order: %v", utils.Format4Output(order, false))
|
|
||||||
return fmt.Errorf("暂不支持此订单类型!")
|
|
||||||
}
|
|
||||||
dao.Commit(db, txDB)
|
|
||||||
globals.SugarLogger.Debugf("OnPayFinished end modify account ...")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func OnCashFinished(order *model.Order) (err error) {
|
|
||||||
var (
|
|
||||||
db = dao.GetDB()
|
|
||||||
)
|
|
||||||
globals.SugarLogger.Debugf("OnCashFinished begin modify account order: %v", utils.Format4Output(order, false))
|
|
||||||
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 {
|
|
||||||
globals.SugarLogger.Debugf("OnCashFinished 未找到该用户的账单 order: %v", utils.Format4Output(order, false))
|
|
||||||
return fmt.Errorf("未找到该用户的账单!%v", order.UserID)
|
|
||||||
}
|
|
||||||
//根据订单类型来操作账户
|
|
||||||
switch order.Type {
|
|
||||||
case model.OrderTypeCash:
|
|
||||||
//如果是账户提现
|
|
||||||
//账户支出
|
|
||||||
if err = AddExpendUpdateAccount(txDB, userBill, model.BillTypeCash, order.PayPrice, 0); err != nil {
|
|
||||||
dao.Rollback(db, txDB)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
globals.SugarLogger.Debugf("OnPayFinished 暂不支持此订单类型 order: %v", utils.Format4Output(order, false))
|
|
||||||
return fmt.Errorf("暂不支持此订单类型!")
|
|
||||||
}
|
|
||||||
dao.Commit(db, txDB)
|
|
||||||
globals.SugarLogger.Debugf("OnCashFinished end modify account ...")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -49,20 +49,6 @@ func init() {
|
|||||||
orderNoBeginTimestamp = utils.Str2Time("2010-01-01 00:00:00").Unix()
|
orderNoBeginTimestamp = utils.Str2Time("2010-01-01 00:00:00").Unix()
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSaleStoreIDFromAfsOrder(order *model.AfsOrder) (retVal int) {
|
|
||||||
if order.JxStoreID > 0 {
|
|
||||||
return order.JxStoreID
|
|
||||||
}
|
|
||||||
return order.StoreID
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetSkuIDFromOrderSkuFinancial(sku *model.OrderSkuFinancial) (skuID int) {
|
|
||||||
if sku.JxSkuID > 0 {
|
|
||||||
return sku.JxSkuID
|
|
||||||
}
|
|
||||||
return sku.SkuID
|
|
||||||
}
|
|
||||||
|
|
||||||
func SplitUniversalOrderID(universalOrderID string) (orderID string, vendorID int) {
|
func SplitUniversalOrderID(universalOrderID string) (orderID string, vendorID int) {
|
||||||
index := strings.Index(universalOrderID, "|")
|
index := strings.Index(universalOrderID, "|")
|
||||||
if index != -1 {
|
if index != -1 {
|
||||||
@@ -545,19 +531,6 @@ func Strings2Objs(strAndObjAddPairs ...interface{}) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RefreshAfsOrderSkuRelated(afsOrder *model.AfsOrder) *model.AfsOrder {
|
|
||||||
afsOrder.SkuUserMoney = 0
|
|
||||||
afsOrder.PmSkuSubsidyMoney = 0
|
|
||||||
for _, orderSku := range afsOrder.Skus {
|
|
||||||
if orderSku.SkuID > math.MaxInt32 {
|
|
||||||
orderSku.SkuID = orderSku.JxSkuID
|
|
||||||
}
|
|
||||||
afsOrder.SkuUserMoney += orderSku.UserMoney
|
|
||||||
afsOrder.PmSkuSubsidyMoney += orderSku.PmSkuSubsidyMoney
|
|
||||||
}
|
|
||||||
return afsOrder
|
|
||||||
}
|
|
||||||
|
|
||||||
func TaskResult2Hint(resultList []interface{}) (hint string) {
|
func TaskResult2Hint(resultList []interface{}) (hint string) {
|
||||||
strList := make([]string, len(resultList))
|
strList := make([]string, len(resultList))
|
||||||
for k, v := range resultList {
|
for k, v := range resultList {
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
package jxutils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ActStoreSkuMap struct {
|
|
||||||
actStoreSkuMap map[int64]map[int]*model.ActStoreSku2
|
|
||||||
}
|
|
||||||
|
|
||||||
// isActPrice为true表示是活动,false表示是结算
|
|
||||||
func NewActStoreSkuMap(actStoreSkuList []*model.ActStoreSku2, isActPrice bool) (actMap *ActStoreSkuMap) {
|
|
||||||
actMap = &ActStoreSkuMap{}
|
|
||||||
actStoreSkuMap := make(map[int64]map[int]*model.ActStoreSku2)
|
|
||||||
for _, v := range actStoreSkuList {
|
|
||||||
index := Combine2Int(v.StoreID, v.SkuID)
|
|
||||||
if actStoreSkuMap[index] == nil {
|
|
||||||
actStoreSkuMap[index] = make(map[int]*model.ActStoreSku2)
|
|
||||||
}
|
|
||||||
if (isActPrice && v.ActualActPrice > 0 && (actStoreSkuMap[index][v.VendorID] == nil || actStoreSkuMap[index][v.VendorID].ActualActPrice > v.ActualActPrice)) ||
|
|
||||||
(!isActPrice && v.EarningPrice > 0 && (actStoreSkuMap[index][v.VendorID] == nil || actStoreSkuMap[index][v.VendorID].EarningPrice > v.EarningPrice)) {
|
|
||||||
actStoreSkuMap[index][v.VendorID] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
actMap.actStoreSkuMap = actStoreSkuMap
|
|
||||||
return actMap
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *ActStoreSkuMap) GetActStoreSku(storeID, skuID, vendorID int) (storeSku *model.ActStoreSku2) {
|
|
||||||
index := Combine2Int(storeID, skuID)
|
|
||||||
if a.actStoreSkuMap[index] != nil {
|
|
||||||
if vendorID < 0 {
|
|
||||||
for k := range a.actStoreSkuMap[index] {
|
|
||||||
vendorID = k
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
storeSku = a.actStoreSkuMap[index][vendorID]
|
|
||||||
}
|
|
||||||
return storeSku
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -35,23 +34,6 @@ type PagedInfo struct {
|
|||||||
Data interface{} `json:"data"`
|
Data interface{} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrderFinancialExt struct {
|
|
||||||
OrderFinancial
|
|
||||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"` //
|
|
||||||
OrderFinishedAt time.Time `orm:"type(datetime)" json:"orderFinishedAt"` // 订单妥投/完成时间
|
|
||||||
StoreID int `orm:"column(store_id)" json:"storeID"` // 外部系统里记录的 jxstoreid
|
|
||||||
JxStoreID int `orm:"column(jx_store_id)" json:"jxStoreID"` // 根据VendorStoreID在本地系统里查询出来的 jxstoreid
|
|
||||||
StoreName string `orm:"size(64)" json:"storeName"` //
|
|
||||||
Status int `json:"status"` // 参见OrderStatus*相关的常量定义
|
|
||||||
Skus []*OrderSkuFinancial `orm:"-" json:"skus"` // 正向订单购买商品列表
|
|
||||||
Discounts []*OrderDiscountFinancial `orm:"-" json:"discounts"` // 正向订单享受优惠列表
|
|
||||||
}
|
|
||||||
|
|
||||||
type OrderFinancialSkuExt struct {
|
|
||||||
OrderSkuFinancial
|
|
||||||
Image string `json:"image"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProductInfo struct {
|
type ProductInfo struct {
|
||||||
OriginalName string `json:"originalName"`
|
OriginalName string `json:"originalName"`
|
||||||
OriginalSpec string `json:"originalSpec"`
|
OriginalSpec string `json:"originalSpec"`
|
||||||
|
|||||||
@@ -1,499 +0,0 @@
|
|||||||
package dao
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ActMapPureInfo struct {
|
|
||||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
|
||||||
VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空
|
|
||||||
VendorActID string `orm:"column(vendor_act_id);size(48)" json:"vendorActID"`
|
|
||||||
SyncStatus int `orm:"default(2)" json:"syncStatus"`
|
|
||||||
Remark string `orm:"column(map_remark)" json:"remark"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ActVendorInfo struct {
|
|
||||||
model.Act
|
|
||||||
VendorList []*ActMapPureInfo `json:"vendorList"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type tActAndMap struct {
|
|
||||||
model.Act
|
|
||||||
MapID int `orm:"column(map_id)" json:"-"` // 内部使用,不暴露
|
|
||||||
ActMapPureInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
type PagedActListInfo struct {
|
|
||||||
TotalCount int `json:"totalCount"`
|
|
||||||
Data []*ActVendorInfo `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetActVendorInfo(db *DaoDB, actID int, vendorIDs []int) (actMap map[int]*model.Act2, err error) {
|
|
||||||
leftOrEmpty := ""
|
|
||||||
if len(vendorIDs) == 1 && vendorIDs[0] == -1 {
|
|
||||||
leftOrEmpty = "LEFT"
|
|
||||||
}
|
|
||||||
sql := fmt.Sprintf(`
|
|
||||||
SELECT t1.*,
|
|
||||||
t2.id map_id, t2.vendor_id, t2.vendor_org_code, t2.vendor_act_id, t2.sync_status
|
|
||||||
FROM act t1
|
|
||||||
%s JOIN act_map t2 ON t2.act_id = t1.id AND t2.deleted_at = ?`, leftOrEmpty)
|
|
||||||
sqlParams := []interface{}{
|
|
||||||
utils.DefaultTimeValue,
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(vendorIDs) > 0 {
|
|
||||||
sql += " AND t2.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
|
||||||
sqlParams = append(sqlParams, vendorIDs)
|
|
||||||
}
|
|
||||||
|
|
||||||
sql += `
|
|
||||||
WHERE t1.deleted_at = ? AND t1.id = ?`
|
|
||||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, actID)
|
|
||||||
|
|
||||||
var actList []*model.Act2
|
|
||||||
if err = GetRows(db, &actList, sql, sqlParams...); err == nil {
|
|
||||||
actMap = make(map[int]*model.Act2)
|
|
||||||
for _, v := range actList {
|
|
||||||
if leftOrEmpty != "" {
|
|
||||||
v.VendorID = -1
|
|
||||||
}
|
|
||||||
actMap[v.VendorID] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return actMap, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetActStoreSkuVendorList(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs []int, keyword string, offset, pageSize int) (totalCount int, actStoreSkuList []*model.ActStoreSku2, err error) {
|
|
||||||
// globals.SugarLogger.Debugf("GetActStoreSkuVendorList actID:%d", actID)
|
|
||||||
// offset = jxutils.FormalizePageOffset(offset)
|
|
||||||
// pageSize = jxutils.FormalizePageSize(pageSize)
|
|
||||||
|
|
||||||
// leftOrEmpty := ""
|
|
||||||
// if len(vendorIDs) == 1 && (vendorIDs[0] == -1 || vendorIDs[0] == model.VendorIDJX) {
|
|
||||||
// leftOrEmpty = "LEFT"
|
|
||||||
// }
|
|
||||||
// sql := fmt.Sprintf(`
|
|
||||||
// SELECT SQL_CALC_FOUND_ROWS
|
|
||||||
// t1.*,
|
|
||||||
// t2.id map_id, t2.vendor_id, t2.vendor_act_id, t2.sync_status, t2.actual_act_price, t2.vendor_price, t2.trend_type, t2.trend_price,
|
|
||||||
// t3.vendor_store_id,
|
|
||||||
// CASE t2.vendor_id
|
|
||||||
// WHEN 0 THEN
|
|
||||||
// t4m.vendor_thing_id
|
|
||||||
// WHEN 1 THEN
|
|
||||||
// t5.mtwm_id
|
|
||||||
// WHEN 3 THEN
|
|
||||||
// t5.ebai_id
|
|
||||||
// ELSE
|
|
||||||
// ''
|
|
||||||
// END vendor_sku_id,
|
|
||||||
// t4.comment, t4.spec_quality, t4.spec_unit,
|
|
||||||
// t6.name store_name,
|
|
||||||
// t7.name sku_name_name, t7.unit, t7.prefix, t7.ex_prefix, t7.ex_prefix_begin, t7.ex_prefix_end
|
|
||||||
// FROM act_store_sku t1
|
|
||||||
// %s JOIN act_store_sku_map t2 ON t2.act_id = ? AND t2.bind_id = t1.id AND t2.deleted_at = ?`, leftOrEmpty)
|
|
||||||
// sqlParams := []interface{}{
|
|
||||||
// actID,
|
|
||||||
// utils.DefaultTimeValue,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if len(vendorIDs) > 0 {
|
|
||||||
// sql += " AND t2.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
|
||||||
// sqlParams = append(sqlParams, vendorIDs)
|
|
||||||
// }
|
|
||||||
// sql += `
|
|
||||||
// LEFT JOIN store_map t3 ON t3.store_id = t1.store_id AND t3.vendor_id = t2.vendor_id AND t3.deleted_at = ?
|
|
||||||
// JOIN sku t4 ON t4.id = t1.sku_id
|
|
||||||
// LEFT JOIN thing_map t4m ON t4m.vendor_id = ? AND t4m.thing_id = t4.id AND t4m.thing_type = ? AND t4m.vendor_id = t2.vendor_id AND t4m.vendor_org_code = t3.vendor_org_code AND t4m.deleted_at = ?
|
|
||||||
// LEFT JOIN store_sku_bind t5 ON t5.sku_id = t1.sku_id AND t5.store_id = t1.store_id AND t5.deleted_at = ?
|
|
||||||
// LEFT JOIN store t6 ON t6.id = t1.store_id
|
|
||||||
// JOIN sku_name t7 ON t7.id = t4.name_id
|
|
||||||
// WHERE t1.act_id = ?
|
|
||||||
// `
|
|
||||||
// sqlParams = append(sqlParams,
|
|
||||||
// utils.DefaultTimeValue,
|
|
||||||
// model.VendorIDJD, model.ThingTypeSku, utils.DefaultTimeValue,
|
|
||||||
// utils.DefaultTimeValue,
|
|
||||||
// actID,
|
|
||||||
// )
|
|
||||||
// if keyword != "" {
|
|
||||||
// keywordLike := "%" + keyword + "%"
|
|
||||||
// sql += " AND (t7.name LIKE ? OR t6.name LIKE ?"
|
|
||||||
// sqlParams = append(sqlParams, keywordLike, keywordLike)
|
|
||||||
// if intKeyword := int(utils.Str2Int64WithDefault(keyword, 0)); intKeyword > 0 {
|
|
||||||
// sql += " OR t1.sku_id = ? OR t1.store_id = ?"
|
|
||||||
// sqlParams = append(sqlParams, intKeyword, intKeyword)
|
|
||||||
// }
|
|
||||||
// sql += ")"
|
|
||||||
// }
|
|
||||||
// if leftOrEmpty != "" {
|
|
||||||
// sql += " AND t1.deleted_at = ?"
|
|
||||||
// sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
|
||||||
// }
|
|
||||||
// if len(storeIDs) > 0 {
|
|
||||||
// sql += " AND t1.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
|
||||||
// sqlParams = append(sqlParams, storeIDs)
|
|
||||||
// }
|
|
||||||
// if len(skuIDs) > 0 {
|
|
||||||
// sql += " AND t1.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
|
||||||
// sqlParams = append(sqlParams, skuIDs)
|
|
||||||
// }
|
|
||||||
// sql += " LIMIT ? OFFSET ?;"
|
|
||||||
// sqlParams = append(sqlParams, pageSize, offset)
|
|
||||||
// // globals.SugarLogger.Debug(sql)
|
|
||||||
// // globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
|
|
||||||
// // globals.SugarLogger.Debug(utils.Format4Output(actStoreSkuList, false))
|
|
||||||
// Begin(db)
|
|
||||||
// defer Commit(db)
|
|
||||||
// if err = GetRows(db, &actStoreSkuList, sql, sqlParams...); err == nil {
|
|
||||||
// totalCount = GetLastTotalRowCount(db)
|
|
||||||
// }
|
|
||||||
return totalCount, actStoreSkuList, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetActStoreSkuVendorInfo(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs []int) (actStoreSkuMap map[int][]*model.ActStoreSku2, err error) {
|
|
||||||
leftOrEmpty := ""
|
|
||||||
if len(vendorIDs) == 1 && vendorIDs[0] == -1 {
|
|
||||||
leftOrEmpty = "LEFT"
|
|
||||||
}
|
|
||||||
_, actStoreSkuList, err := GetActStoreSkuVendorList(db, actID, vendorIDs, storeIDs, skuIDs, "", 0, -1)
|
|
||||||
if err == nil {
|
|
||||||
actStoreSkuMap = make(map[int][]*model.ActStoreSku2)
|
|
||||||
for _, v := range actStoreSkuList {
|
|
||||||
if leftOrEmpty != "" {
|
|
||||||
v.VendorID = -1
|
|
||||||
}
|
|
||||||
actStoreSkuMap[v.VendorID] = append(actStoreSkuMap[v.VendorID], v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return actStoreSkuMap, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func QueryActs(db *DaoDB, actID int, offset, pageSize int, syncStatus int, keyword string, vendorID int, statusList, actTypeList, createTypeList []int,
|
|
||||||
storeID int, skuIDs []int, cityCode int, beginAt, endAt, createdAtFrom, createdAtTo time.Time) (pagedInfo *PagedActListInfo, err error) {
|
|
||||||
if actID == 0 && utils.IsTimeZero(createdAtFrom) && utils.IsTimeZero(beginAt) {
|
|
||||||
return nil, fmt.Errorf("actID,createdAtFrom和beginAt中,至少要指定一个条件")
|
|
||||||
}
|
|
||||||
offset = jxutils.FormalizePageOffset(offset)
|
|
||||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
|
||||||
isGetAll := offset == 0 && pageSize == model.UnlimitedPageSize
|
|
||||||
|
|
||||||
sql := `
|
|
||||||
SELECT SQL_CALC_FOUND_ROWS
|
|
||||||
DISTINCT t1.id
|
|
||||||
FROM act t1`
|
|
||||||
sqlParams := []interface{}{}
|
|
||||||
if isGetAll {
|
|
||||||
sql = `
|
|
||||||
SELECT
|
|
||||||
t1.*,
|
|
||||||
t2.id map_id, t2.vendor_id, t2.vendor_act_id, t2.sync_status, t2.remark map_remark
|
|
||||||
FROM act t1`
|
|
||||||
}
|
|
||||||
sql += " LEFT JOIN act_map t2 ON t2.act_id = t1.id AND t2.deleted_at = ?"
|
|
||||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
|
||||||
if syncStatus >= 0 {
|
|
||||||
sql += " AND (t2.sync_status = ? OR t2.sync_status & ? <> 0)"
|
|
||||||
sqlParams = append(sqlParams, syncStatus, syncStatus)
|
|
||||||
}
|
|
||||||
sql += `
|
|
||||||
WHERE t1.deleted_at = ?`
|
|
||||||
if syncStatus >= 0 {
|
|
||||||
sql += " AND t2.id IS NOT NULL"
|
|
||||||
}
|
|
||||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
|
||||||
keywordInt := int64(0)
|
|
||||||
if keyword != "" {
|
|
||||||
keywordLike := "%" + keyword + "%"
|
|
||||||
sql += " AND ( t1.name LIKE ? OR t1.advertising LIKE ? OR t1.remark LIKE ? OR t2.vendor_act_id LIKE ?"
|
|
||||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike)
|
|
||||||
keywordInt = utils.Str2Int64WithDefault(keyword, 0)
|
|
||||||
if keywordInt > 0 {
|
|
||||||
sql += `
|
|
||||||
OR t1.id = ?`
|
|
||||||
sqlParams = append(sqlParams, keywordInt)
|
|
||||||
}
|
|
||||||
sql += ")"
|
|
||||||
}
|
|
||||||
if storeID > 0 || len(skuIDs) > 0 || cityCode > 0 {
|
|
||||||
sql += ` AND (SELECT COUNT(*)
|
|
||||||
FROM act_store_sku t2`
|
|
||||||
if cityCode > 0 {
|
|
||||||
sql += " JOIN store t3 ON t3.id = t2.store_id AND t3.city_code = ?"
|
|
||||||
sqlParams = append(sqlParams, cityCode)
|
|
||||||
}
|
|
||||||
sql += `
|
|
||||||
WHERE t2.act_id = t1.id AND t2.deleted_at = ?`
|
|
||||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
|
||||||
if storeID > 0 {
|
|
||||||
sql += " AND t2.store_id = ?"
|
|
||||||
sqlParams = append(sqlParams, storeID)
|
|
||||||
}
|
|
||||||
if len(skuIDs) > 0 {
|
|
||||||
sql += " AND t2.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
|
||||||
sqlParams = append(sqlParams, skuIDs)
|
|
||||||
}
|
|
||||||
sql += ") > 0"
|
|
||||||
}
|
|
||||||
if actID > 0 {
|
|
||||||
sql += " AND t1.id = ?"
|
|
||||||
sqlParams = append(sqlParams, actID)
|
|
||||||
}
|
|
||||||
if vendorID >= 0 {
|
|
||||||
sql += " AND t1.vendor_mask & ? <> 0"
|
|
||||||
sqlParams = append(sqlParams, model.GetVendorMask(vendorID))
|
|
||||||
}
|
|
||||||
if len(statusList) > 0 {
|
|
||||||
sql += " AND t1.status IN (" + GenQuestionMarks(len(statusList)) + ")"
|
|
||||||
sqlParams = append(sqlParams, statusList)
|
|
||||||
}
|
|
||||||
if len(actTypeList) > 0 {
|
|
||||||
sql += " AND t1.type IN (" + GenQuestionMarks(len(actTypeList)) + ")"
|
|
||||||
sqlParams = append(sqlParams, actTypeList)
|
|
||||||
}
|
|
||||||
if len(createTypeList) > 0 {
|
|
||||||
sql += " AND t1.create_type IN (" + GenQuestionMarks(len(createTypeList)) + ")"
|
|
||||||
sqlParams = append(sqlParams, createTypeList)
|
|
||||||
}
|
|
||||||
if !utils.IsTimeZero(beginAt) {
|
|
||||||
sql += " AND t1.begin_at <= ?"
|
|
||||||
sqlParams = append(sqlParams, beginAt)
|
|
||||||
}
|
|
||||||
if !utils.IsTimeZero(endAt) {
|
|
||||||
sql += " AND t1.end_at >= ?"
|
|
||||||
sqlParams = append(sqlParams, endAt)
|
|
||||||
}
|
|
||||||
if !utils.IsTimeZero(createdAtFrom) {
|
|
||||||
sql += " AND t1.created_at >= ?"
|
|
||||||
sqlParams = append(sqlParams, createdAtFrom)
|
|
||||||
}
|
|
||||||
if !utils.IsTimeZero(createdAtTo) {
|
|
||||||
sql += " AND t1.created_at <= ?"
|
|
||||||
sqlParams = append(sqlParams, createdAtTo)
|
|
||||||
}
|
|
||||||
|
|
||||||
pagedInfo = &PagedActListInfo{}
|
|
||||||
if isGetAll {
|
|
||||||
sql += `
|
|
||||||
ORDER BY t1.id DESC, t2.vendor_id`
|
|
||||||
} else {
|
|
||||||
sql += `
|
|
||||||
ORDER BY 1 DESC
|
|
||||||
LIMIT ? OFFSET ?
|
|
||||||
`
|
|
||||||
sqlParams = append(sqlParams, pageSize, offset)
|
|
||||||
var idList []int
|
|
||||||
|
|
||||||
txDB, _ := Begin(db)
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
Rollback(db, txDB)
|
|
||||||
panic(r)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
// globals.SugarLogger.Debug(sql)
|
|
||||||
if err = GetRowsTx(txDB, &idList, sql, sqlParams...); err != nil || len(idList) == 0 {
|
|
||||||
Rollback(db, txDB)
|
|
||||||
return pagedInfo, err
|
|
||||||
}
|
|
||||||
pagedInfo.TotalCount = GetLastTotalRowCountTx(txDB)
|
|
||||||
Commit(db, txDB)
|
|
||||||
|
|
||||||
sql = `
|
|
||||||
SELECT
|
|
||||||
t1.*,
|
|
||||||
t2.id map_id, t2.vendor_id, t2.vendor_org_code, t2.vendor_act_id, t2.sync_status, t2.remark map_remark
|
|
||||||
FROM act t1
|
|
||||||
LEFT JOIN act_map t2 ON t2.act_id = t1.id AND t2.deleted_at = ?
|
|
||||||
WHERE t1.id IN (` + GenQuestionMarks(len(idList)) + `)`
|
|
||||||
if syncStatus >= 0 {
|
|
||||||
sql += " AND t2.id IS NOT NULL"
|
|
||||||
}
|
|
||||||
sql += `
|
|
||||||
ORDER BY t1.id DESC, t2.vendor_id`
|
|
||||||
sqlParams = []interface{}{
|
|
||||||
utils.DefaultTimeValue,
|
|
||||||
idList,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var actList []*tActAndMap
|
|
||||||
// globals.SugarLogger.Debug(sql)
|
|
||||||
if err = GetRows(db, &actList, sql, sqlParams...); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
actMap := make(map[int]*ActVendorInfo)
|
|
||||||
for _, v := range actList {
|
|
||||||
tmpAct := actMap[v.ID]
|
|
||||||
if tmpAct == nil {
|
|
||||||
tmpAct = &ActVendorInfo{
|
|
||||||
Act: v.Act,
|
|
||||||
}
|
|
||||||
actMap[v.ID] = tmpAct
|
|
||||||
pagedInfo.Data = append(pagedInfo.Data, tmpAct)
|
|
||||||
}
|
|
||||||
if v.MapID > 0 {
|
|
||||||
tmpAct.VendorList = append(tmpAct.VendorList, &v.ActMapPureInfo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if isGetAll {
|
|
||||||
pagedInfo.TotalCount = len(pagedInfo.Data)
|
|
||||||
}
|
|
||||||
return pagedInfo, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetExistVendorActIDs(db *DaoDB, vendorID int) (vendorActIDs []string, err error) {
|
|
||||||
// todo 不应该是全表扫描
|
|
||||||
sql := `
|
|
||||||
SELECT
|
|
||||||
DISTINCT t1.vendor_act_id
|
|
||||||
FROM act_store_sku_map t1
|
|
||||||
WHERE t1.deleted_at = ? AND t1.vendor_id = ?`
|
|
||||||
sqlParams := []interface{}{
|
|
||||||
utils.DefaultTimeValue,
|
|
||||||
vendorID,
|
|
||||||
}
|
|
||||||
err = GetRows(db, &vendorActIDs, sql, sqlParams...)
|
|
||||||
return vendorActIDs, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateActStatusByTime(db *DaoDB, refTime time.Time) (num int64, err error) {
|
|
||||||
sql := `
|
|
||||||
UPDATE act t1
|
|
||||||
SET t1.status = ?
|
|
||||||
WHERE t1.deleted_at = ? AND t1.status < ? AND t1.end_at < ?;`
|
|
||||||
sqlParams := []interface{}{
|
|
||||||
model.ActStatusEnded,
|
|
||||||
utils.DefaultTimeValue,
|
|
||||||
model.ActStatusCanceled,
|
|
||||||
utils.Time2Date(refTime),
|
|
||||||
}
|
|
||||||
num, err = ExecuteSQL(db, sql, sqlParams...)
|
|
||||||
return num, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// func ActStoreSkuMap2StoreSkuAct(actStoreSkuMap *model.ActStoreSkuMap, isCanceled bool) (storeSkuAct *model.StoreSkuAct) {
|
|
||||||
// storeSkuAct = &model.StoreSkuAct{
|
|
||||||
// StoreID: actStoreSkuMap.StoreID,
|
|
||||||
// SkuID: actStoreSkuMap.SkuID,
|
|
||||||
// VendorID: actStoreSkuMap.VendorID,
|
|
||||||
// }
|
|
||||||
// storeSkuAct.CreatedAt = actStoreSkuMap.CreatedAt
|
|
||||||
// storeSkuAct.UpdatedAt = actStoreSkuMap.UpdatedAt
|
|
||||||
// storeSkuAct.LastOperator = actStoreSkuMap.LastOperator
|
|
||||||
|
|
||||||
// if actStoreSkuMap.ActualActPrice > 0 {
|
|
||||||
// if isCanceled || !utils.IsTimeZero(actStoreSkuMap.DeletedAt) {
|
|
||||||
// storeSkuAct.ActID = 0
|
|
||||||
// } else {
|
|
||||||
// storeSkuAct.ActID = actStoreSkuMap.ActID
|
|
||||||
// storeSkuAct.VendorActID = actStoreSkuMap.VendorActID
|
|
||||||
// storeSkuAct.SyncStatus = actStoreSkuMap.SyncStatus
|
|
||||||
// storeSkuAct.VendorPrice = actStoreSkuMap.VendorPrice
|
|
||||||
// storeSkuAct.ActualActPrice = actStoreSkuMap.ActualActPrice
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if actStoreSkuMap.EarningPrice > 0 {
|
|
||||||
// if isCanceled || !utils.IsTimeZero(actStoreSkuMap.DeletedAt) {
|
|
||||||
// storeSkuAct.EarningActID = 0
|
|
||||||
// } else {
|
|
||||||
// storeSkuAct.EarningActID = actStoreSkuMap.ActID
|
|
||||||
// storeSkuAct.EarningPrice = actStoreSkuMap.EarningPrice
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return storeSkuAct
|
|
||||||
// }
|
|
||||||
|
|
||||||
func BatchUpdateActEntity(db *DaoDB, isCanceled bool, items []*KVUpdateItem) (num int64, err error) {
|
|
||||||
return BatchUpdateEntityByKV(db, items)
|
|
||||||
// if globals.IsStoreSkuAct {
|
|
||||||
// Begin(db)
|
|
||||||
// defer func() {
|
|
||||||
// if r := recover(); r != nil || err != nil {
|
|
||||||
// Rollback(db)
|
|
||||||
// if r != nil {
|
|
||||||
// panic(r)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }()
|
|
||||||
|
|
||||||
// for _, v := range items {
|
|
||||||
// if actStoreSku, ok := v.Item.(*model.ActStoreSkuMap); ok {
|
|
||||||
// for k1, v1 := range v.KVs {
|
|
||||||
// refutil.SetObjFieldByName(actStoreSku, k1, v1)
|
|
||||||
// }
|
|
||||||
// if err = CreateOrUpdateActStoreSku(db, ActStoreSkuMap2StoreSkuAct(actStoreSku, isCanceled)); err != nil {
|
|
||||||
// return 0, err
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if _, err = BatchUpdateEntityByKV(db, items); err != nil {
|
|
||||||
// return 0, err
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if globals.IsStoreSkuAct {
|
|
||||||
// Commit(db)
|
|
||||||
// }
|
|
||||||
// return num, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreateOrUpdateActStoreSku(db *DaoDB, storeSkuAct *model.StoreSkuAct) (err error) {
|
|
||||||
storeSkuActCopy := *storeSkuAct
|
|
||||||
if err2 := GetEntity(db, &storeSkuActCopy, model.FieldStoreID, model.FieldSkuID, model.FieldVendorID); err2 == nil {
|
|
||||||
storeSkuAct.ID = storeSkuActCopy.ID
|
|
||||||
_, err = UpdateEntity(db, storeSkuAct)
|
|
||||||
} else if IsNoRowsError(err2) {
|
|
||||||
err = CreateEntity(db, storeSkuAct)
|
|
||||||
} else {
|
|
||||||
err = err2
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetStoresSkusAct(db *DaoDB, hintActID int, mustDirty bool, storeIDs, skuIDs, vendorIDs []int, mustHaveVendorActID bool, minActPercentage, maxActPercentage int) (storeSkuActList []*model.StoreSkuAct, err error) {
|
|
||||||
sql := `
|
|
||||||
SELECT *
|
|
||||||
FROM store_sku_act t1
|
|
||||||
WHERE 1 = 1
|
|
||||||
`
|
|
||||||
sqlParams := []interface{}{}
|
|
||||||
if hintActID > 0 {
|
|
||||||
sql += " AND t1.hint_act_id = ?"
|
|
||||||
sqlParams = append(sqlParams, hintActID)
|
|
||||||
}
|
|
||||||
if mustDirty {
|
|
||||||
sql += " AND (t1.sync_status <> 0 OR (t1.act_percentage = 0 AND t1.vendor_act_id <> '') OR (t1.act_percentage <> 0 AND t1.vendor_act_id = ''))"
|
|
||||||
}
|
|
||||||
if len(storeIDs) > 0 {
|
|
||||||
sql += " AND t1.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
|
||||||
sqlParams = append(sqlParams, storeIDs)
|
|
||||||
}
|
|
||||||
if len(skuIDs) > 0 {
|
|
||||||
sql += " AND t1.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
|
||||||
sqlParams = append(sqlParams, skuIDs)
|
|
||||||
}
|
|
||||||
if len(vendorIDs) > 0 {
|
|
||||||
sql += " AND t1.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
|
||||||
sqlParams = append(sqlParams, vendorIDs)
|
|
||||||
}
|
|
||||||
if mustHaveVendorActID {
|
|
||||||
sql += " AND t1.vendor_act_id <> ''"
|
|
||||||
}
|
|
||||||
if minActPercentage > 0 {
|
|
||||||
sql += " AND t1.act_percentage >= ?"
|
|
||||||
sqlParams = append(sqlParams, minActPercentage)
|
|
||||||
}
|
|
||||||
if maxActPercentage > 0 {
|
|
||||||
sql += " AND t1.act_percentage <= ?"
|
|
||||||
sqlParams = append(sqlParams, maxActPercentage)
|
|
||||||
}
|
|
||||||
err = GetRows(db, &storeSkuActList, sql, sqlParams...)
|
|
||||||
return storeSkuActList, err
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package dao
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestGetEffectiveActStoreSkuInfo(t *testing.T) {
|
|
||||||
type testData struct {
|
|
||||||
ResultCount int
|
|
||||||
|
|
||||||
ActID int
|
|
||||||
VendorIDs []int
|
|
||||||
StoreIDs []int
|
|
||||||
SkuIDs []int
|
|
||||||
FromTime time.Time
|
|
||||||
ToTime time.Time
|
|
||||||
}
|
|
||||||
for _, v := range []*testData{
|
|
||||||
&testData{
|
|
||||||
StoreIDs: []int{100190},
|
|
||||||
SkuIDs: []int{23847},
|
|
||||||
ResultCount: 1,
|
|
||||||
FromTime: utils.Str2Time("2019-08-06 12:34:56"),
|
|
||||||
ToTime: utils.Str2Time("2019-08-06 12:34:56"),
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
result, err := GetEffectiveActStoreSkuInfo(GetDB(), v.ActID, v.VendorIDs, model.ActTypeAll, v.StoreIDs, v.SkuIDs, v.FromTime, v.ToTime)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if len(result) != v.ResultCount {
|
|
||||||
t.Log(utils.Format4Output(result, false))
|
|
||||||
t.Errorf("cond:%s, len(result):%d, v.ResultCount:%d", utils.Format4Output(v, false), len(result), v.ResultCount)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestUpdateActStatusByTime(t *testing.T) {
|
|
||||||
_, err := UpdateActStatusByTime(GetDB(), time.Now().Add(-48*time.Hour))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetActStoreSkuVendorList(t *testing.T) {
|
|
||||||
_, _, err := GetActStoreSkuVendorList(GetDB(), 18440, nil, nil, nil, "", 0, 0)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,654 +0,0 @@
|
|||||||
package dao
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetDeliveryOrdersNoPage(db *DaoDB, userIDs []string, statuss []int, fromTime, toTime time.Time, isWeights []int) (dOrders []*model.DeliveryOrder, err error) {
|
|
||||||
sql := `
|
|
||||||
SELECT a.*
|
|
||||||
FROM delivery_order a
|
|
||||||
WHERE 1 = 1
|
|
||||||
`
|
|
||||||
sqlParams := []interface{}{}
|
|
||||||
if len(userIDs) > 0 {
|
|
||||||
sql += ` AND a.user_id IN (` + GenQuestionMarks(len(userIDs)) + `)`
|
|
||||||
sqlParams = append(sqlParams, userIDs)
|
|
||||||
}
|
|
||||||
if len(statuss) > 0 {
|
|
||||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
|
||||||
sqlParams = append(sqlParams, statuss)
|
|
||||||
}
|
|
||||||
if len(isWeights) > 0 {
|
|
||||||
sql += ` AND a.is_weight IN (` + GenQuestionMarks(len(isWeights)) + `)`
|
|
||||||
sqlParams = append(sqlParams, isWeights)
|
|
||||||
}
|
|
||||||
if fromTime != utils.ZeroTimeValue {
|
|
||||||
sql += ` AND a.created_at >= ?`
|
|
||||||
sqlParams = append(sqlParams, fromTime)
|
|
||||||
}
|
|
||||||
if toTime != utils.ZeroTimeValue {
|
|
||||||
sql += ` AND a.created_at <= ?`
|
|
||||||
sqlParams = append(sqlParams, toTime)
|
|
||||||
}
|
|
||||||
err = GetRows(db, &dOrders, sql, sqlParams)
|
|
||||||
return dOrders, err
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetDeliveryOrdersResult struct {
|
|
||||||
model.DeliveryOrder
|
|
||||||
DeliverySendInfo *UserDeliveryAddressEx `json:"deliverySendInfo"`
|
|
||||||
DeliveryReceiveInfo *UserDeliveryAddressEx `json:"deliveryReceiveInfo"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetDeliveryOrders(db *DaoDB, userIDs []string, statuss []int, fromTime, toTime time.Time, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
|
||||||
var dOrders []*GetDeliveryOrdersResult
|
|
||||||
sql := `
|
|
||||||
SELECT SQL_CALC_FOUND_ROWS a.*
|
|
||||||
FROM delivery_order a
|
|
||||||
WHERE 1 = 1
|
|
||||||
`
|
|
||||||
sqlParams := []interface{}{}
|
|
||||||
if len(userIDs) > 0 {
|
|
||||||
sql += ` AND a.user_id IN (` + GenQuestionMarks(len(userIDs)) + `)`
|
|
||||||
sqlParams = append(sqlParams, userIDs)
|
|
||||||
}
|
|
||||||
if len(statuss) > 0 {
|
|
||||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
|
||||||
sqlParams = append(sqlParams, statuss)
|
|
||||||
}
|
|
||||||
if fromTime != utils.ZeroTimeValue {
|
|
||||||
sql += ` AND a.created_at >= ?`
|
|
||||||
sqlParams = append(sqlParams, fromTime)
|
|
||||||
}
|
|
||||||
if toTime != utils.ZeroTimeValue {
|
|
||||||
sql += ` AND a.created_at <= ?`
|
|
||||||
sqlParams = append(sqlParams, toTime)
|
|
||||||
}
|
|
||||||
sql += " ORDER BY a.created_at DESC"
|
|
||||||
sql += " LIMIT ? OFFSET ?"
|
|
||||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
|
||||||
sqlParams = append(sqlParams, pageSize, offset)
|
|
||||||
txDB, _ := Begin(db)
|
|
||||||
defer Commit(db, txDB)
|
|
||||||
if err = GetRowsTx(txDB, &dOrders, sql, sqlParams...); err == nil {
|
|
||||||
pagedInfo = &model.PagedInfo{
|
|
||||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
|
||||||
// Data: dOrders,
|
|
||||||
}
|
|
||||||
for _, v := range dOrders {
|
|
||||||
if addressList1, _, err := QueryUserDeliveryAddress(db, int64(v.DeliverySendID), nil, 0, 0, 0); err == nil && len(addressList1) > 0 {
|
|
||||||
v.DeliverySendInfo = addressList1[0]
|
|
||||||
} else {
|
|
||||||
sendInfo := &UserDeliveryAddressEx{}
|
|
||||||
sendInfo.ConsigneeName = v.SendName
|
|
||||||
sendInfo.ConsigneeMobile = v.SendMobile
|
|
||||||
sendInfo.Address = v.SendAddress
|
|
||||||
sendInfo.AutoAddress = v.SendAutoAddress
|
|
||||||
sendInfo.CityCode = v.SendCityCode
|
|
||||||
sendInfo.DistrictCode = v.SendDistrictCode
|
|
||||||
sendInfo.DetailAddress = v.SendDetailAddress
|
|
||||||
sendInfo.Lng = v.SendLng
|
|
||||||
sendInfo.Lat = v.SendLat
|
|
||||||
v.DeliverySendInfo = sendInfo
|
|
||||||
}
|
|
||||||
if addressList2, _, err := QueryUserDeliveryAddress(db, int64(v.DeliveryReceiveID), nil, 0, 0, 0); err == nil && len(addressList2) > 0 {
|
|
||||||
v.DeliveryReceiveInfo = addressList2[0]
|
|
||||||
} else {
|
|
||||||
receiveInfo := &UserDeliveryAddressEx{}
|
|
||||||
receiveInfo.ConsigneeName = v.ReceiveName
|
|
||||||
receiveInfo.ConsigneeMobile = v.ReceiveMobile
|
|
||||||
receiveInfo.Address = v.ReceiveAddress
|
|
||||||
receiveInfo.AutoAddress = v.ReceiveAutoAddress
|
|
||||||
receiveInfo.CityCode = v.ReceiveCityCode
|
|
||||||
receiveInfo.DistrictCode = v.ReceiveDistrictCode
|
|
||||||
receiveInfo.DetailAddress = v.ReceiveDetailAddress
|
|
||||||
receiveInfo.Lng = v.ReceiveLng
|
|
||||||
receiveInfo.Lat = v.ReceiveLat
|
|
||||||
v.DeliveryReceiveInfo = receiveInfo
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pagedInfo.Data = dOrders
|
|
||||||
}
|
|
||||||
return pagedInfo, err
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetOrdersResult struct {
|
|
||||||
model.Order
|
|
||||||
UserName string `json:"userName"`
|
|
||||||
Mobile string `json:"mobile"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetOrders(db *DaoDB, orderID, userID string, orderType int, cityCodes []int, fromTime, toTime time.Time, keyword string, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
|
||||||
var orders []*GetOrdersResult
|
|
||||||
sql := `
|
|
||||||
SELECT SQL_CALC_FOUND_ROWS a.*, b.name user_name, b.mobile
|
|
||||||
FROM ` + "`order`" + ` a
|
|
||||||
JOIN user b ON b.user_id = a.user_id AND b.deleted_at = ?
|
|
||||||
WHERE 1 = 1
|
|
||||||
`
|
|
||||||
|
|
||||||
sqlParams := []interface{}{
|
|
||||||
utils.DefaultTimeValue,
|
|
||||||
}
|
|
||||||
if orderID != "" {
|
|
||||||
sql += ` AND a.order_id = ?`
|
|
||||||
sqlParams = append(sqlParams, orderID)
|
|
||||||
}
|
|
||||||
if userID != "" {
|
|
||||||
sql += ` AND a.user_id = ?`
|
|
||||||
sqlParams = append(sqlParams, userID)
|
|
||||||
}
|
|
||||||
if orderType != 0 {
|
|
||||||
sql += ` AND a.type = ?`
|
|
||||||
sqlParams = append(sqlParams, orderType)
|
|
||||||
}
|
|
||||||
if len(cityCodes) > 0 {
|
|
||||||
sql += ` AND a.city_code IN (` + GenQuestionMarks(len(cityCodes)) + `)`
|
|
||||||
sqlParams = append(sqlParams, cityCodes)
|
|
||||||
}
|
|
||||||
if fromTime != utils.ZeroTimeValue {
|
|
||||||
sql += ` AND a.created_at >= ?`
|
|
||||||
sqlParams = append(sqlParams, fromTime)
|
|
||||||
}
|
|
||||||
if toTime != utils.ZeroTimeValue {
|
|
||||||
sql += ` AND a.created_at <= ?`
|
|
||||||
sqlParams = append(sqlParams, toTime)
|
|
||||||
}
|
|
||||||
if keyword != "" {
|
|
||||||
sql += ` AND (b.mobile LIKE ? OR b.name LIKE ?)`
|
|
||||||
sqlParams = append(sqlParams, "%"+keyword+"%", "%"+keyword+"%")
|
|
||||||
}
|
|
||||||
sql += " LIMIT ? OFFSET ?"
|
|
||||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
|
||||||
sqlParams = append(sqlParams, pageSize, offset)
|
|
||||||
txDB, _ := Begin(db)
|
|
||||||
defer Commit(db, txDB)
|
|
||||||
if err = GetRowsTx(txDB, &orders, sql, sqlParams); err == nil {
|
|
||||||
pagedInfo = &model.PagedInfo{
|
|
||||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
|
||||||
Data: orders,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pagedInfo, err
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetPayStatisticsResult struct {
|
|
||||||
TotalPay int `json:"totalPay"` //支付总额
|
|
||||||
CanCash int `json:"canCash"` //可提现(未提现+申请提现)
|
|
||||||
AccountBalance int `json:"accountBalance"` //未提现(含保证金)
|
|
||||||
SubmitCash int `json:"submitCash"` //申请提现
|
|
||||||
Cashed int `json:"cashed"` //已经体现
|
|
||||||
CashIncome int `json:"cashIncome"` //提现收益
|
|
||||||
TotalIncome int `json:"totalIncome"` //收益总额
|
|
||||||
MemberIncome int `json:"memberIncome"` //会员收益
|
|
||||||
}
|
|
||||||
|
|
||||||
func getFromSql(orderType, status int, alies string, userID string, pop int, cityCodes []int, mobile string, fromTime, toTime time.Time, orderTypes []int) (sql string, sqlParams []interface{}) {
|
|
||||||
sql += `
|
|
||||||
(SELECT SUM(IFNULL(b.pay_price,0)) total_pay
|
|
||||||
FROM user a
|
|
||||||
JOIN ` + "`order` b " + `ON b.user_id = a.user_id AND b.type = ? AND b.status = ?
|
|
||||||
`
|
|
||||||
sqlParams = append(sqlParams, orderType, status)
|
|
||||||
if len(orderTypes) > 0 {
|
|
||||||
sql += ` AND b.order_type IN (` + GenQuestionMarks(len(orderTypes)) + `)`
|
|
||||||
sqlParams = append(sqlParams, orderTypes)
|
|
||||||
}
|
|
||||||
if fromTime != utils.ZeroTimeValue {
|
|
||||||
sql += ` AND b.created_at > ?`
|
|
||||||
sqlParams = append(sqlParams, fromTime)
|
|
||||||
}
|
|
||||||
if toTime != utils.ZeroTimeValue {
|
|
||||||
sql += ` AND b.created_at < ?`
|
|
||||||
sqlParams = append(sqlParams, toTime)
|
|
||||||
}
|
|
||||||
if mobile != "" {
|
|
||||||
if pop == 1 {
|
|
||||||
sql += " JOIN user e ON e.moblie = ? AND a.pop_user = e.user_id"
|
|
||||||
sqlParams = append(sqlParams, mobile)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sql += `
|
|
||||||
WHERE a.status = ? AND a.deleted_at = ?
|
|
||||||
`
|
|
||||||
sqlParams = append(sqlParams, model.UserStatusNormal, utils.DefaultTimeValue)
|
|
||||||
if userID != "" {
|
|
||||||
if pop == 1 {
|
|
||||||
sql += " AND a.pop_user = ?"
|
|
||||||
sqlParams = append(sqlParams, userID)
|
|
||||||
} else {
|
|
||||||
sql += " AND a.user_id = ?"
|
|
||||||
sqlParams = append(sqlParams, userID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if mobile != "" {
|
|
||||||
if pop == 0 {
|
|
||||||
sql += " AND a.mobile = ?"
|
|
||||||
sqlParams = append(sqlParams, mobile)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(cityCodes) > 0 {
|
|
||||||
sql += ` AND a.city_code IN (` + GenQuestionMarks(len(cityCodes)) + `)`
|
|
||||||
sqlParams = append(sqlParams, cityCodes)
|
|
||||||
}
|
|
||||||
sql += `) ` + alies
|
|
||||||
return sql, sqlParams
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetPayStatistics(db *DaoDB, userID string, pop int, cityCodes []int, mobile string, fromTime, toTime time.Time, orderTypes []int) (getPayStatisticsResult *GetPayStatisticsResult, err error) {
|
|
||||||
sqlParams := []interface{}{}
|
|
||||||
sql := `SELECT t1.total_pay, t2.total_pay submit_cash, t3.total_pay cashed, t4.account_balance, t4.account_balance + t2.total_pay can_cash
|
|
||||||
FROM `
|
|
||||||
rSQL1, rSQLParams1 := getFromSql(model.OrderTypePay, model.OrderStatusFinished, "t1", userID, pop, cityCodes, mobile, fromTime, toTime, orderTypes)
|
|
||||||
sql += rSQL1 + ","
|
|
||||||
sqlParams = append(sqlParams, rSQLParams1...)
|
|
||||||
rSQL2, rSQLParams2 := getFromSql(model.OrderTypeCash, model.OrderStatusWait4Pay, "t2", userID, pop, cityCodes, mobile, fromTime, toTime, orderTypes)
|
|
||||||
sql += rSQL2 + ","
|
|
||||||
sqlParams = append(sqlParams, rSQLParams2...)
|
|
||||||
rSQL3, rSQLParams3 := getFromSql(model.OrderTypeCash, model.OrderStatusFinished, "t3", userID, pop, cityCodes, mobile, fromTime, toTime, orderTypes)
|
|
||||||
sql += rSQL3 + ","
|
|
||||||
sqlParams = append(sqlParams, rSQLParams3...)
|
|
||||||
sql += `(SELECT SUM(IFNULL(b.account_balance,0)) account_balance
|
|
||||||
FROM user a
|
|
||||||
JOIN user_bill b ON a.user_id = b.user_id
|
|
||||||
`
|
|
||||||
if mobile != "" {
|
|
||||||
if pop == 1 {
|
|
||||||
sql += " JOIN user e ON e.moblie = ? AND a.pop_user = e.user_id"
|
|
||||||
sqlParams = append(sqlParams, mobile)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sql += `
|
|
||||||
WHERE 1 = 1
|
|
||||||
`
|
|
||||||
if userID != "" {
|
|
||||||
if pop == 1 {
|
|
||||||
sql += " AND a.pop_user = ?"
|
|
||||||
sqlParams = append(sqlParams, userID)
|
|
||||||
} else {
|
|
||||||
sql += " AND a.user_id = ?"
|
|
||||||
sqlParams = append(sqlParams, userID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if mobile != "" {
|
|
||||||
if pop == 0 {
|
|
||||||
sql += " AND a.mobile = ?"
|
|
||||||
sqlParams = append(sqlParams, mobile)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(cityCodes) > 0 {
|
|
||||||
sql += ` AND a.city_code IN (` + GenQuestionMarks(len(cityCodes)) + `)`
|
|
||||||
sqlParams = append(sqlParams, cityCodes)
|
|
||||||
}
|
|
||||||
sql += `
|
|
||||||
) t4`
|
|
||||||
err = GetRow(db, &getPayStatisticsResult, sql, sqlParams)
|
|
||||||
sqlParams2 := []interface{}{}
|
|
||||||
getPayStatisticsResult1 := &GetPayStatisticsResult{}
|
|
||||||
sql2 := `
|
|
||||||
SELECT SUM(IFNULL(d.expend_price,0)) member_income
|
|
||||||
FROM user a`
|
|
||||||
if mobile != "" {
|
|
||||||
if pop == 1 {
|
|
||||||
sql2 += " JOIN user e ON e.moblie = ? AND a.pop_user = e.user_id"
|
|
||||||
sqlParams2 = append(sqlParams2, mobile)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sql2 += `
|
|
||||||
LEFT JOIN user_bill c ON c.user_id = a.user_id
|
|
||||||
LEFT JOIN bill_expend d ON d.bill_id = c.bill_id AND d.type = ?
|
|
||||||
`
|
|
||||||
sqlParams2 = append(sqlParams2, model.BillTypeMember)
|
|
||||||
if fromTime != utils.ZeroTimeValue {
|
|
||||||
sql2 += ` AND d.created_at > ?`
|
|
||||||
sqlParams2 = append(sqlParams2, fromTime)
|
|
||||||
}
|
|
||||||
if toTime != utils.ZeroTimeValue {
|
|
||||||
sql2 += ` AND d.created_at < ?`
|
|
||||||
sqlParams2 = append(sqlParams2, toTime)
|
|
||||||
}
|
|
||||||
sql2 += `
|
|
||||||
WHERE a.status = ? AND a.deleted_at = ?
|
|
||||||
`
|
|
||||||
sqlParams2 = append(sqlParams2, model.UserStatusNormal, utils.DefaultTimeValue)
|
|
||||||
if len(cityCodes) > 0 {
|
|
||||||
sql2 += ` AND a.city_code IN (` + GenQuestionMarks(len(cityCodes)) + `)`
|
|
||||||
sqlParams2 = append(sqlParams2, cityCodes)
|
|
||||||
}
|
|
||||||
if mobile != "" {
|
|
||||||
if pop == 0 {
|
|
||||||
sql2 += " AND a.mobile = ?"
|
|
||||||
sqlParams2 = append(sqlParams2, mobile)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if userID != "" {
|
|
||||||
if pop == 1 {
|
|
||||||
sql2 += " AND a.pop_user = ?"
|
|
||||||
sqlParams2 = append(sqlParams2, userID)
|
|
||||||
} else {
|
|
||||||
sql2 += " AND a.user_id = ?"
|
|
||||||
sqlParams2 = append(sqlParams2, userID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err = GetRow(db, &getPayStatisticsResult1, sql2, sqlParams2)
|
|
||||||
getPayStatisticsResult.MemberIncome = getPayStatisticsResult1.MemberIncome
|
|
||||||
getPayStatisticsResult.CashIncome = getPayStatisticsResult.Cashed / 10
|
|
||||||
getPayStatisticsResult.TotalIncome = getPayStatisticsResult.MemberIncome + getPayStatisticsResult.CashIncome
|
|
||||||
return getPayStatisticsResult, err
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetManageStatisticsResult struct {
|
|
||||||
Date time.Time `json:"date"` //日期
|
|
||||||
BrowseCount int `json:"browseCount"` //点击次数
|
|
||||||
AcceptCount int `json:"acceptCount"` //接受任务数
|
|
||||||
FinishCount int `json:"finishCount"` //完成任务数
|
|
||||||
CancelCount int `json:"cancelCount"` //取消任务数
|
|
||||||
TotalCash int `json:"totalCash"` //返现总额
|
|
||||||
InversionRate float64 `json:"inversionRate"` //转化率
|
|
||||||
}
|
|
||||||
|
|
||||||
func getFromSqlManage(status int, alies string, cityCodes []int, jobTime, endTime time.Time, jobIDs []int) (sql string, sqlParams []interface{}) {
|
|
||||||
sql += `
|
|
||||||
(SELECT COUNT(b.id) count
|
|
||||||
FROM job a
|
|
||||||
JOIN job_order b ON a.id = b.job_id
|
|
||||||
WHERE a.deleted_at = ?
|
|
||||||
`
|
|
||||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
|
||||||
if status != 0 {
|
|
||||||
sql += " AND b.status = ?"
|
|
||||||
sqlParams = append(sqlParams, status)
|
|
||||||
}
|
|
||||||
if jobTime != utils.ZeroTimeValue {
|
|
||||||
sql += " AND a.created_at > ?"
|
|
||||||
sqlParams = append(sqlParams, jobTime)
|
|
||||||
}
|
|
||||||
if endTime != utils.ZeroTimeValue {
|
|
||||||
sql += " AND a.created_at < ?"
|
|
||||||
sqlParams = append(sqlParams, endTime)
|
|
||||||
}
|
|
||||||
if len(cityCodes) > 0 {
|
|
||||||
sql += ` AND a.job_city_code IN (` + GenQuestionMarks(len(cityCodes)) + `)`
|
|
||||||
sqlParams = append(sqlParams, cityCodes)
|
|
||||||
}
|
|
||||||
if len(jobIDs) > 0 {
|
|
||||||
sql += ` AND a.id IN (` + GenQuestionMarks(len(jobIDs)) + `)`
|
|
||||||
sqlParams = append(sqlParams, jobIDs)
|
|
||||||
}
|
|
||||||
sql += ") " + alies
|
|
||||||
return sql, sqlParams
|
|
||||||
}
|
|
||||||
|
|
||||||
func getWhereSqlManage(cityCodes []int, jobTime, endTime time.Time, jobIDs []int) (sql string, sqlParams []interface{}) {
|
|
||||||
if jobTime != utils.ZeroTimeValue {
|
|
||||||
sql += " AND a.created_at > ?"
|
|
||||||
sqlParams = append(sqlParams, jobTime)
|
|
||||||
}
|
|
||||||
if endTime != utils.ZeroTimeValue {
|
|
||||||
sql += " AND a.created_at < ?"
|
|
||||||
sqlParams = append(sqlParams, endTime)
|
|
||||||
}
|
|
||||||
if len(cityCodes) > 0 {
|
|
||||||
sql += ` AND a.job_city_code IN (` + GenQuestionMarks(len(cityCodes)) + `)`
|
|
||||||
sqlParams = append(sqlParams, cityCodes)
|
|
||||||
}
|
|
||||||
if len(jobIDs) > 0 {
|
|
||||||
sql += ` AND a.id IN (` + GenQuestionMarks(len(jobIDs)) + `)`
|
|
||||||
sqlParams = append(sqlParams, jobIDs)
|
|
||||||
}
|
|
||||||
return sql, sqlParams
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetManageStatistics(db *DaoDB, cityCodes []int, jobTime time.Time, jobIDs []int) (getManageStatisticsResult *GetManageStatisticsResult, err error) {
|
|
||||||
endTime := jobTime.AddDate(0, 0, 1)
|
|
||||||
sqlParams := []interface{}{}
|
|
||||||
sql := `
|
|
||||||
SELECT t1.count accept_count, t2.count finish_count, t3.count cancel_count, t4.browse_count, t6.total_cash
|
|
||||||
FROM
|
|
||||||
`
|
|
||||||
rSQL1, rSQLparams1 := getFromSqlManage(model.JobOrderStatusAccept, "t1", cityCodes, jobTime, endTime, jobIDs)
|
|
||||||
sql += rSQL1 + ","
|
|
||||||
sqlParams = append(sqlParams, rSQLparams1...)
|
|
||||||
rSQL2, rSQLparams2 := getFromSqlManage(model.JobOrderStatusFinish, "t2", cityCodes, jobTime, endTime, jobIDs)
|
|
||||||
sql += rSQL2 + ","
|
|
||||||
sqlParams = append(sqlParams, rSQLparams2...)
|
|
||||||
rSQL3, rSQLparams3 := getFromSqlManage(model.JobOrderStatusCancel, "t3", cityCodes, jobTime, endTime, jobIDs)
|
|
||||||
sql += rSQL3 + ","
|
|
||||||
sqlParams = append(sqlParams, rSQLparams3...)
|
|
||||||
sql += `
|
|
||||||
(SELECT SUM(a.browse_count) browse_count
|
|
||||||
FROM job a
|
|
||||||
JOIN job_order b ON a.id = b.job_id
|
|
||||||
WHERE a.deleted_at = ?
|
|
||||||
`
|
|
||||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
|
||||||
rSQL4, rSQLparams4 := getWhereSqlManage(cityCodes, jobTime, endTime, jobIDs)
|
|
||||||
sql += rSQL4
|
|
||||||
sqlParams = append(sqlParams, rSQLparams4...)
|
|
||||||
sql += `
|
|
||||||
) t4,
|
|
||||||
`
|
|
||||||
sql += `
|
|
||||||
(SELECT t5.count * a.avg_price total_cash FROM job a,
|
|
||||||
(SELECT COUNT(b.id) count, a.id
|
|
||||||
FROM job a
|
|
||||||
JOIN job_order b ON a.id = b.job_id
|
|
||||||
WHERE a.deleted_at = ? AND b.status = ?
|
|
||||||
`
|
|
||||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, model.JobOrderStatusFinish)
|
|
||||||
rSQL5, rSQLparams5 := getWhereSqlManage(cityCodes, jobTime, endTime, jobIDs)
|
|
||||||
sql += rSQL5
|
|
||||||
sqlParams = append(sqlParams, rSQLparams5...)
|
|
||||||
sql += `
|
|
||||||
GROUP BY 2) t5
|
|
||||||
WHERE a.id = t5.id
|
|
||||||
)t6
|
|
||||||
`
|
|
||||||
GetRow(db, &getManageStatisticsResult, sql, sqlParams)
|
|
||||||
if getManageStatisticsResult == nil {
|
|
||||||
return &GetManageStatisticsResult{
|
|
||||||
Date: jobTime,
|
|
||||||
}, err
|
|
||||||
} else {
|
|
||||||
getManageStatisticsResult.Date = jobTime
|
|
||||||
if getManageStatisticsResult.BrowseCount == 0 {
|
|
||||||
getManageStatisticsResult.InversionRate = 0
|
|
||||||
} else {
|
|
||||||
getManageStatisticsResult.InversionRate = float64(getManageStatisticsResult.FinishCount) / float64(getManageStatisticsResult.BrowseCount)
|
|
||||||
}
|
|
||||||
return getManageStatisticsResult, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetManageStatisticsJobResult struct {
|
|
||||||
BrowseCount int `json:"browseCount"` //点击次数
|
|
||||||
AcceptCount int `json:"acceptCount"` //接受任务数
|
|
||||||
FinishCount int `json:"finishCount"` //完成任务数
|
|
||||||
CancelCount int `json:"cancelCount"` //取消任务数
|
|
||||||
TotalCash int `json:"totalCash"` //返现总额
|
|
||||||
InversionRate float64 `json:"inversionRate"` //转化率
|
|
||||||
Title string `json:"title"` //任务标题
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetManageStatisticsJob(db *DaoDB, cityCodes []int, fromTime, toTime time.Time, jobIDs []int, offset, pageSize int) (pageInfo *model.PagedInfo, err error) {
|
|
||||||
var (
|
|
||||||
sqlParams = []interface{}{}
|
|
||||||
getManageStatisticsJobResult []*GetManageStatisticsJobResult
|
|
||||||
)
|
|
||||||
sql := `
|
|
||||||
SELECT t1.count acceptCount, t2.count finish_count, t3.count cancel_count, a.browse_count, a.title, a.browse_count / t2.count inversion_rate, t4.total_cash
|
|
||||||
FROM job a
|
|
||||||
LEFT JOIN (SELECT job_id, COUNT(*) count FROM job_order WHERE status = ? GROUP BY 1) t1 ON t1.job_id = a.id
|
|
||||||
LEFT JOIN (SELECT job_id, COUNT(*) count FROM job_order WHERE status = ? GROUP BY 1) t2 ON t2.job_id = a.id
|
|
||||||
LEFT JOIN (SELECT job_id, COUNT(*) count FROM job_order WHERE status = ? GROUP BY 1) t3 ON t3.job_id = a.id
|
|
||||||
`
|
|
||||||
sql += `
|
|
||||||
LEFT JOIN (SELECT COUNT(b.id) * a.avg_price total_cash, a.id
|
|
||||||
FROM job a
|
|
||||||
JOIN job_order b ON a.id = b.job_id AND b.status = ?
|
|
||||||
GROUP BY 2) t4 ON t4.id = a.id
|
|
||||||
`
|
|
||||||
sqlParams = append(sqlParams, model.JobOrderStatusAccept, model.JobOrderStatusFinish, model.JobOrderStatusCancel, model.JobOrderStatusFinish)
|
|
||||||
sql += " WHERE a.deleted_at = ?"
|
|
||||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
|
||||||
rSQL, rSQLparams := getWhereSqlManage(cityCodes, fromTime, toTime, jobIDs)
|
|
||||||
sql += rSQL
|
|
||||||
sqlParams = append(sqlParams, rSQLparams...)
|
|
||||||
sql += " LIMIT ? OFFSET ?"
|
|
||||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
|
||||||
sqlParams = append(sqlParams, pageSize, offset)
|
|
||||||
txDB, _ := Begin(db)
|
|
||||||
defer Commit(db, txDB)
|
|
||||||
err = GetRowsTx(txDB, &getManageStatisticsJobResult, sql, sqlParams)
|
|
||||||
if err == nil {
|
|
||||||
pageInfo = &model.PagedInfo{
|
|
||||||
Data: getManageStatisticsJobResult,
|
|
||||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pageInfo, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetUnionOrders(db *DaoDB, vendorIDs, statuss []int, beginTime, endTime time.Time, isEarning int) (orders []*model.UnionOrder, err error) {
|
|
||||||
sql := `
|
|
||||||
SELECT *
|
|
||||||
FROM union_order
|
|
||||||
WHERE 1 = 1
|
|
||||||
`
|
|
||||||
sqlParams := []interface{}{}
|
|
||||||
if len(vendorIDs) > 0 {
|
|
||||||
sql += ` AND vendor_id IN (` + GenQuestionMarks(len(vendorIDs)) + `)`
|
|
||||||
sqlParams = append(sqlParams, vendorIDs)
|
|
||||||
}
|
|
||||||
if len(statuss) > 0 {
|
|
||||||
sql += ` AND status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
|
||||||
sqlParams = append(sqlParams, statuss)
|
|
||||||
}
|
|
||||||
if !utils.IsTimeZero(beginTime) {
|
|
||||||
sql += ` AND order_settle_at > ?`
|
|
||||||
sqlParams = append(sqlParams, beginTime)
|
|
||||||
}
|
|
||||||
if !utils.IsTimeZero(endTime) {
|
|
||||||
sql += ` AND order_settle_at < ?`
|
|
||||||
sqlParams = append(sqlParams, endTime)
|
|
||||||
}
|
|
||||||
if isEarning != -1 {
|
|
||||||
sql += ` AND is_earning = ?`
|
|
||||||
sqlParams = append(sqlParams, isEarning)
|
|
||||||
}
|
|
||||||
err = GetRows(db, &orders, sql, sqlParams)
|
|
||||||
return orders, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetUnionOrdersByIDs(db *DaoDB, vendorOrderIDs []string, vendorID int) (orders []*model.UnionOrder, err error) {
|
|
||||||
if len(vendorOrderIDs) == 0 {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
sql := `
|
|
||||||
SELECT *
|
|
||||||
FROM union_order
|
|
||||||
WHERE 1 = 1
|
|
||||||
`
|
|
||||||
sqlParams := []interface{}{}
|
|
||||||
if len(vendorOrderIDs) > 0 {
|
|
||||||
sql += ` AND vendor_order_id IN (` + GenQuestionMarks(len(vendorOrderIDs)) + `)`
|
|
||||||
sqlParams = append(sqlParams, vendorOrderIDs)
|
|
||||||
}
|
|
||||||
if vendorID != 0 {
|
|
||||||
sql += ` AND vendor_id = ?`
|
|
||||||
sqlParams = append(sqlParams, vendorID)
|
|
||||||
}
|
|
||||||
err = GetRows(db, &orders, sql, sqlParams)
|
|
||||||
return orders, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetMyUnionOrders(db *DaoDB, userID string, statuss []int, vendorID, offset, pageSize int) (page *model.PagedInfo, err error) {
|
|
||||||
var orders []*model.UnionOrder
|
|
||||||
sql := `
|
|
||||||
SELECT SQL_CALC_FOUND_ROWS a.*
|
|
||||||
FROM union_order a
|
|
||||||
WHERE 1 = 1
|
|
||||||
`
|
|
||||||
sqlParams := []interface{}{}
|
|
||||||
if vendorID != -1 {
|
|
||||||
sql += ` AND a.vendor_id = ?`
|
|
||||||
sqlParams = append(sqlParams, vendorID)
|
|
||||||
}
|
|
||||||
if len(statuss) > 0 {
|
|
||||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
|
||||||
sqlParams = append(sqlParams, statuss)
|
|
||||||
}
|
|
||||||
if userID != "" {
|
|
||||||
sql += ` AND a.user_id = ?`
|
|
||||||
sqlParams = append(sqlParams, userID)
|
|
||||||
}
|
|
||||||
sql += " ORDER BY a.created_at DESC"
|
|
||||||
sql += " LIMIT ? OFFSET ?"
|
|
||||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
|
||||||
sqlParams = append(sqlParams, pageSize, offset)
|
|
||||||
txDB, _ := Begin(db)
|
|
||||||
defer Commit(db, txDB)
|
|
||||||
if err = GetRowsTx(txDB, &orders, sql, sqlParams...); err == nil {
|
|
||||||
page = &model.PagedInfo{
|
|
||||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
|
||||||
Data: orders,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return page, err
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetUnionOrdersPageResult struct {
|
|
||||||
model.UnionOrder
|
|
||||||
Name string `json:"name"`
|
|
||||||
Moble string `json:"moble"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetUnionOrdersPage(db *DaoDB, vendorIDs, statuss []int, beginTime, endTime time.Time, keyword string, offset, pageSize int) (page *model.PagedInfo, err error) {
|
|
||||||
var orders []*GetUnionOrdersPageResult
|
|
||||||
sql := `
|
|
||||||
SELECT SQL_CALC_FOUND_ROWS a.*, b.name, b.mobile
|
|
||||||
FROM union_order a
|
|
||||||
LEFT JOIN user b ON a.user_id = b.user_id
|
|
||||||
WHERE 1 = 1
|
|
||||||
`
|
|
||||||
sqlParams := []interface{}{}
|
|
||||||
if len(vendorIDs) > 0 {
|
|
||||||
sql += ` AND a.vendor_id IN (` + GenQuestionMarks(len(vendorIDs)) + `)`
|
|
||||||
sqlParams = append(sqlParams, vendorIDs)
|
|
||||||
}
|
|
||||||
if len(statuss) > 0 {
|
|
||||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
|
||||||
sqlParams = append(sqlParams, statuss)
|
|
||||||
}
|
|
||||||
if !utils.IsTimeZero(beginTime) {
|
|
||||||
sql += ` AND a.order_settle_at > ?`
|
|
||||||
sqlParams = append(sqlParams, beginTime)
|
|
||||||
}
|
|
||||||
if !utils.IsTimeZero(endTime) {
|
|
||||||
sql += ` AND a.order_settle_at < ?`
|
|
||||||
sqlParams = append(sqlParams, endTime)
|
|
||||||
}
|
|
||||||
if keyword != "" {
|
|
||||||
keywordLike := "%" + keyword + "%"
|
|
||||||
sql += ` AND (b.name LIKE ? OR b.mobile LIKE ? OR a.vendor_order_id LIKE ? OR a.goods_name LIKE ? OR a.comment LIKE ?)`
|
|
||||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike)
|
|
||||||
}
|
|
||||||
sql += " LIMIT ? OFFSET ?"
|
|
||||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
|
||||||
sqlParams = append(sqlParams, pageSize, offset)
|
|
||||||
txDB, _ := Begin(db)
|
|
||||||
defer Commit(db, txDB)
|
|
||||||
if err = GetRowsTx(txDB, &orders, sql, sqlParams...); err == nil {
|
|
||||||
page = &model.PagedInfo{
|
|
||||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
|
||||||
Data: orders,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return page, err
|
|
||||||
}
|
|
||||||
@@ -381,19 +381,6 @@ func GetUserAllWaitCashPrice(db *DaoDB, userID string) (price int, err error) {
|
|||||||
return result.Price, err
|
return result.Price, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUserAllWaitRealCashPrice(db *DaoDB, userID string) (price int, err error) {
|
|
||||||
var result = &GetUserAllWaitCashPriceResult{}
|
|
||||||
sql := `
|
|
||||||
SELECT SUM(pay_price) price FROM ` + "`order`" + ` WHERE user_id = ? AND status = ? AND type = ?
|
|
||||||
`
|
|
||||||
sqlParams := []interface{}{
|
|
||||||
userID,
|
|
||||||
model.OrderStatusWait4Pay,
|
|
||||||
model.OrderTypeCash,
|
|
||||||
}
|
|
||||||
err = GetRow(db, &result, sql, sqlParams)
|
|
||||||
return result.Price, err
|
|
||||||
}
|
|
||||||
func GetUserUnionBind(db *DaoDB, userID string, vendorID int, unionID string) (userBinds []*model.UserUnionBind, err error) {
|
func GetUserUnionBind(db *DaoDB, userID string, vendorID int, unionID string) (userBinds []*model.UserUnionBind, err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT * FROM user_union_bind WHERE deleted_at = ?
|
SELECT * FROM user_union_bind WHERE deleted_at = ?
|
||||||
|
|||||||
Reference in New Issue
Block a user