作者 唐旭辉

代码清理

... ... @@ -182,7 +182,6 @@ func (subscriber *OrderLogSubscriber) SubscribedToEventTypes() []string {
event.UPDATE_BONUS_BY_GOOD_NUMBER_EVENT,
event.UPDATE_BONUS_BY_PARTENT_BONUS_PERCENT_EVENT,
event.UPDATE_ORDER_REMARK,
event.PAY_ORDER_GOOD_BONUS_EVENT,
event.BATCH_PAY_ORDER_GOOD_BONUS_EVENT,
}
}
... ...
... ... @@ -2,7 +2,6 @@ package service
import (
"fmt"
"time"
"github.com/astaxie/beego/logs"
... ... @@ -536,108 +535,108 @@ func (service OrderInfoService) deleteOldOrderGoods(newGoods []domain.OrderGood,
}
//Delivery 发货
func (service OrderInfoService) Delivery(cmd command.OrderDeliveryCommand) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
orderBaseRepository domain.OrderBaseRepository
orderGoodRepository domain.OrderGoodRepository
oldOrderData *domain.OrderBase
oldOrderGoods []domain.OrderGood
orderBaseDao *dao.OrderBaseDao
)
// func (service OrderInfoService) Delivery(cmd command.OrderDeliveryCommand) error {
// var (
// transactionContext, _ = factory.CreateTransactionContext(nil)
// err error
// )
// if err = transactionContext.StartTransaction(); err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
// var (
// orderBaseRepository domain.OrderBaseRepository
// orderGoodRepository domain.OrderGoodRepository
// oldOrderData *domain.OrderBase
// oldOrderGoods []domain.OrderGood
// orderBaseDao *dao.OrderBaseDao
// )
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
//获取旧的订单
oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
CompanyId: cmd.CompanyId,
OrderId: cmd.OrderId,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
}
if oldOrderData.OrderType != domain.OrderIntention {
return lib.ThrowError(lib.BUSINESS_ERROR, "订单类型已发生变更")
}
if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
//检查delivery_code是否重复
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId, cmd.OrderId); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
}
//获取旧的订单中的商品
oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
OrderId: cmd.OrderId,
CompanyId: cmd.CompanyId,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
}
for _, newGood := range cmd.Goods {
for i := range oldOrderGoods {
if newGood.Id != oldOrderGoods[i].Id {
continue
}
oldOrderGoods[i].GoodName = newGood.GoodName
oldOrderGoods[i].PlanGoodNumber = newGood.PlanGoodNumber
oldOrderGoods[i].Price = newGood.Price
oldOrderGoods[i].PartnerBonusPercent = newGood.PartnerBonusPercent
oldOrderGoods[i].Remark = newGood.Remark
err = oldOrderGoods[i].Compute()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
}
err = oldOrderGoods[i].CurrentBonusStatus.WartPayPartnerBonus(&oldOrderGoods[i])
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
}
}
}
oldOrderData.DeliveryCode = cmd.DeliveryCode
oldOrderData.DeliveryTime = time.Now()
oldOrderData.Goods = oldOrderGoods
//变更订单类型
oldOrderData.OrderType = domain.OrderReal
err = oldOrderData.Compute()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
}
err = orderBaseRepository.Save(oldOrderData)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
}
err = orderGoodRepository.Save(oldOrderGoods)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
// if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// //获取旧的订单
// oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
// CompanyId: cmd.CompanyId,
// OrderId: cmd.OrderId,
// })
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
// }
// if oldOrderData.OrderType != domain.OrderIntention {
// return lib.ThrowError(lib.BUSINESS_ERROR, "订单类型已发生变更")
// }
// if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
// }
// //检查delivery_code是否重复
// if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId, cmd.OrderId); err != nil {
// return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
// } else if ok {
// return lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
// }
// //获取旧的订单中的商品
// oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
// OrderId: cmd.OrderId,
// CompanyId: cmd.CompanyId,
// })
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
// }
// for _, newGood := range cmd.Goods {
// for i := range oldOrderGoods {
// if newGood.Id != oldOrderGoods[i].Id {
// continue
// }
// oldOrderGoods[i].GoodName = newGood.GoodName
// oldOrderGoods[i].PlanGoodNumber = newGood.PlanGoodNumber
// oldOrderGoods[i].Price = newGood.Price
// oldOrderGoods[i].PartnerBonusPercent = newGood.PartnerBonusPercent
// oldOrderGoods[i].Remark = newGood.Remark
// err = oldOrderGoods[i].Compute()
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
// }
// err = oldOrderGoods[i].CurrentBonusStatus.WartPayPartnerBonus(&oldOrderGoods[i])
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
// }
// }
// }
// oldOrderData.DeliveryCode = cmd.DeliveryCode
// oldOrderData.DeliveryTime = time.Now()
// oldOrderData.Goods = oldOrderGoods
// //变更订单类型
// oldOrderData.OrderType = domain.OrderReal
// err = oldOrderData.Compute()
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
// }
// err = orderBaseRepository.Save(oldOrderData)
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
// }
// err = orderGoodRepository.Save(oldOrderGoods)
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
// }
// err = transactionContext.CommitTransaction()
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// return nil
// }
//DisableOrEnable 开启关闭订单
func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand) error {
... ... @@ -684,100 +683,100 @@ func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand)
}
//UpdateGoodBouns 分红时,更新货品的分红相关的数值
func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
orderBaseRepository domain.OrderBaseRepository
orderGoodRepository domain.OrderGoodRepository
oldOrderData *domain.OrderBase
oldOrderGoods []domain.OrderGood
)
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
//获取旧的订单
oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
OrderId: cmd.Id,
CompanyId: cmd.CompanyId,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
}
if oldOrderData.OrderType != domain.OrderReal {
return lib.ThrowError(lib.BUSINESS_ERROR, fmt.Sprintf("指定的订单的订单类型发生变更"))
}
//获取旧的订单中的商品
oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
OrderId: cmd.Id,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
}
for _, newGood := range cmd.GoodBouns {
for i := range oldOrderGoods {
if newGood.GoodId != oldOrderGoods[i].Id {
continue
}
oldOrderGoods[i].UseGoodNumber = newGood.UseGoodNumber
oldOrderGoods[i].Remark = newGood.Remark
oldOrderGoods[i].BonusStatus = newGood.BounsStatus
err = oldOrderGoods[i].Compute()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
}
switch newGood.BounsStatus {
case domain.OrderGoodWaitPay:
err = oldOrderGoods[i].CurrentBonusStatus.WartPayPartnerBonus(&oldOrderGoods[i])
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
}
case domain.OrderGoodHasPay:
err = oldOrderGoods[i].CurrentBonusStatus.PayPartnerBonus(&oldOrderGoods[i])
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
}
default:
return lib.ThrowError(lib.ARG_ERROR, fmt.Sprintf("货品的支付状态错误"))
}
}
}
oldOrderData.Goods = oldOrderGoods
// func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) error {
// var (
// transactionContext, _ = factory.CreateTransactionContext(nil)
// err error
// )
// if err = transactionContext.StartTransaction(); err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
// var (
// orderBaseRepository domain.OrderBaseRepository
// orderGoodRepository domain.OrderGoodRepository
// oldOrderData *domain.OrderBase
// oldOrderGoods []domain.OrderGood
// )
// if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// //获取旧的订单
// oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
// OrderId: cmd.Id,
// CompanyId: cmd.CompanyId,
// })
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
// }
// if oldOrderData.OrderType != domain.OrderReal {
// return lib.ThrowError(lib.BUSINESS_ERROR, fmt.Sprintf("指定的订单的订单类型发生变更"))
// }
// //获取旧的订单中的商品
// oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
// OrderId: cmd.Id,
// })
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
// }
// for _, newGood := range cmd.GoodBouns {
// for i := range oldOrderGoods {
// if newGood.GoodId != oldOrderGoods[i].Id {
// continue
// }
// oldOrderGoods[i].UseGoodNumber = newGood.UseGoodNumber
// oldOrderGoods[i].Remark = newGood.Remark
// oldOrderGoods[i].BonusStatus = newGood.BounsStatus
// err = oldOrderGoods[i].Compute()
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
// }
// switch newGood.BounsStatus {
// case domain.OrderGoodWaitPay:
// err = oldOrderGoods[i].CurrentBonusStatus.WartPayPartnerBonus(&oldOrderGoods[i])
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
// }
// case domain.OrderGoodHasPay:
// err = oldOrderGoods[i].CurrentBonusStatus.PayPartnerBonus(&oldOrderGoods[i])
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
// }
// default:
// return lib.ThrowError(lib.ARG_ERROR, fmt.Sprintf("货品的支付状态错误"))
// }
// }
// }
// oldOrderData.Goods = oldOrderGoods
err = oldOrderData.Compute()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
}
err = orderBaseRepository.Save(oldOrderData)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
}
err = orderGoodRepository.Save(oldOrderGoods)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
// err = oldOrderData.Compute()
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
// }
// err = orderBaseRepository.Save(oldOrderData)
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
// }
// err = orderGoodRepository.Save(oldOrderGoods)
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
// }
// err = transactionContext.CommitTransaction()
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// return nil
}
// }
//PageListOrderBouns 获取订单的分红列表
func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrderBonusQuery) ([]map[string]interface{}, int, error) {
... ...
... ... @@ -4,7 +4,7 @@ import "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
const (
//支付订单中货品的分红
PAY_ORDER_GOOD_BONUS_EVENT string = "PayOrderGoodBonus"
//PAY_ORDER_GOOD_BONUS_EVENT string = "PayOrderGoodBonus"
BATCH_PAY_ORDER_GOOD_BONUS_EVENT string = "BatchPayOrderGoodBonus"
)
... ...
package domain
//类型为(orderType=OrderTypeBestShop) 海鲜干货的订单分红
//因页面上的对于该类型的订单分红状态处理方式 有别于原有的其他类型(OrderReal),所以单独提取出来
// OrderGoodWithBestshopBonusStatus 支付状态
// type OrderGoodWithBestshopBonusStatus interface {
// OrderGoodBonusStatus
// UpdateOrderGoodNumber(good *OrderGood, number int) error
// UpdatePertnerBonusPercent(good *OrderGood, percent float64) error
// }
// //OrderGoodWithBestshop 处理订单中商品的分红相关数据
// type OrderGoodWithBestshop struct {
// currentBonusStatus OrderGoodWithBestshopBonusStatus
// }
// func (o *OrderGoodWithBestshop) UpdateBonusByGoodNumber(good *OrderGood, number int) error {
// o.reset(good)
// if good.PlanGoodNumber < number {
// return fmt.Errorf("修改商品数量的值不能大于初始值%d", good.PlanGoodNumber)
// }
// err := o.currentBonusStatus.UpdateOrderGoodNumber(good, number)
// return err
// }
// func (o *OrderGoodWithBestshop) UpdateBonusByPertnerBonusPercent(good *OrderGood, percent float64) error {
// o.reset(good)
// err := o.currentBonusStatus.UpdatePertnerBonusPercent(good, percent)
// return err
// }
// func (o *OrderGoodWithBestshop) PayPartnerBonus(good *OrderGood) error {
// o.currentBonusStatus = OrderGoodBonusBestshopHasPay{}
// err := good.Compute()
// if err != nil {
// return errors.New("核算商品数据失败" + err.Error())
// }
// err = good.CurrentBonusStatus.PayPartnerBonus(good)
// return err
// }
// func (o *OrderGoodWithBestshop) reset(good *OrderGood) {
// switch good.BonusStatus {
// case OrderGoodWaitPay:
// o.currentBonusStatus = OrderGoodBonusBestshopWaitPay{}
// case OrderGoodHasPay:
// o.currentBonusStatus = OrderGoodBonusBestshopHasPay{}
// }
// return
// }
// //OrderGoodBonusBestshopWaitPay 货品支付状态:待支付
// type OrderGoodBonusBestshopWaitPay struct {
// OrderGoodBonusWaitPay
// }
// var _ OrderGoodWithBestshopBonusStatus = (*OrderGoodBonusBestshopWaitPay)(nil)
// func (waitPay OrderGoodBonusBestshopWaitPay) UpdateOrderGoodNumber(good *OrderGood, number int) error {
// good.UseGoodNumber = number
// //待支付状态计算
// err := good.Compute()
// if err != nil {
// return errors.New("核算商品数据失败" + err.Error())
// }
// err = good.CurrentBonusStatus.WartPayPartnerBonus(good)
// return err
// }
// func (waitPay OrderGoodBonusBestshopWaitPay) UpdatePertnerBonusPercent(good *OrderGood, percent float64) error {
// good.PartnerBonusPercent = percent
// //待支付状态计算
// err := good.Compute()
// if err != nil {
// return errors.New("核算商品数据失败" + err.Error())
// }
// err = good.CurrentBonusStatus.WartPayPartnerBonus(good)
// return err
// }
// //OrderGoodBonusBestshopHasPay 货品支付状态:已支付
// type OrderGoodBonusBestshopHasPay struct {
// OrderGoodBonusHasPay
// }
// var _ OrderGoodWithBestshopBonusStatus = (*OrderGoodBonusBestshopHasPay)(nil)
// func (hasPay OrderGoodBonusBestshopHasPay) UpdateOrderGoodNumber(good *OrderGood, number int) error {
// return errors.New("已支付分红的货品订单,不能修改货品数量")
// }
// func (hasPay OrderGoodBonusBestshopHasPay) UpdatePertnerBonusPercent(good *OrderGood, percent float64) error {
// return errors.New("已支付分红的货品订单,不能修改合伙人分红比例")
// }
... ... @@ -2,11 +2,7 @@ package dao
import (
"fmt"
"strings"
"time"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
... ... @@ -24,81 +20,81 @@ func NewBusinessBonusDao(transactionContext *transaction.TransactionContext) (*B
}
}
type CustomBusinessBonus struct {
Id int64
Bonus string
BonusNot string
BonusExpense string
BonusHas string
BonusStatus int8
PartnerName string
UpdateAt time.Time
}
// type CustomBusinessBonus struct {
// Id int64
// Bonus string
// BonusNot string
// BonusExpense string
// BonusHas string
// BonusStatus int8
// PartnerName string
// UpdateAt time.Time
// }
func (dao BusinessBonusDao) SearchBusinessBonus(partnerId int64, partnerNameMatch string,
companyId int64, limit int, offset int) ([]CustomBusinessBonus, error) {
sql := `SELECT business_bonus.id, business_bonus.bonus,business_bonus.bonus_not
,business_bonus.bonus_expense,business_bonus.bonus_status,business_bonus.update_at
,partner_info.partner_name,business_bonus.bonus_has
FROM business_bonus
JOIN partner_info ON business_bonus.partner_info_id=partner_info.id
WHERE business_bonus.is_disable=? AND business_bonus.company_id = ? `
partnerCondition := []string{}
allParam := []interface{}{domain.BUSINESS_BONUS_ENABLE, companyId}
if partnerId > 0 {
partnerCondition = append(partnerCondition, ` business_bonus.partner_info_id=? `)
allParam = append(allParam, partnerId)
}
if len(partnerNameMatch) > 0 {
allParam = append(allParam, "%"+partnerNameMatch+"%")
partnerCondition = append(partnerCondition, ` partner_info.partner_name like ? `)
}
if len(partnerCondition) > 0 {
sql += fmt.Sprintf(" AND (%s)", strings.Join(partnerCondition, " OR "))
}
sql += `ORDER BY business_bonus.id DESC limit ? OFFSET ? `
allParam = append(allParam, limit, offset)
tx := dao.transactionContext.PgTx
var (
result []CustomBusinessBonus
err error
)
_, err = tx.Query(&result, sql, allParam...)
return result, err
}
// func (dao BusinessBonusDao) SearchBusinessBonus(partnerId int64, partnerNameMatch string,
// companyId int64, limit int, offset int) ([]CustomBusinessBonus, error) {
// sql := `SELECT business_bonus.id, business_bonus.bonus,business_bonus.bonus_not
// ,business_bonus.bonus_expense,business_bonus.bonus_status,business_bonus.update_at
// ,partner_info.partner_name,business_bonus.bonus_has
// FROM business_bonus
// JOIN partner_info ON business_bonus.partner_info_id=partner_info.id
// WHERE business_bonus.is_disable=? AND business_bonus.company_id = ? `
// partnerCondition := []string{}
// allParam := []interface{}{domain.BUSINESS_BONUS_ENABLE, companyId}
// if partnerId > 0 {
// partnerCondition = append(partnerCondition, ` business_bonus.partner_info_id=? `)
// allParam = append(allParam, partnerId)
// }
// if len(partnerNameMatch) > 0 {
// allParam = append(allParam, "%"+partnerNameMatch+"%")
// partnerCondition = append(partnerCondition, ` partner_info.partner_name like ? `)
// }
// if len(partnerCondition) > 0 {
// sql += fmt.Sprintf(" AND (%s)", strings.Join(partnerCondition, " OR "))
// }
// sql += `ORDER BY business_bonus.id DESC limit ? OFFSET ? `
// allParam = append(allParam, limit, offset)
// tx := dao.transactionContext.PgTx
// var (
// result []CustomBusinessBonus
// err error
// )
// _, err = tx.Query(&result, sql, allParam...)
// return result, err
// }
func (dao BusinessBonusDao) CountBusinessBonus(partnerId int64, partnerNameMatch string,
companyId int64, limit int, offset int) (int, error) {
sql := `SELECT count(*)
FROM business_bonus
JOIN partner_info ON business_bonus.partner_info_id=partner_info.id
WHERE business_bonus.is_disable=? AND business_bonus.company_id = ? `
partnerCondition := []string{}
allParam := []interface{}{domain.BUSINESS_BONUS_ENABLE, companyId}
if partnerId > 0 {
partnerCondition = append(partnerCondition, ` business_bonus.partner_info_id=? `)
allParam = append(allParam, partnerId)
}
if len(partnerNameMatch) > 0 {
allParam = append(allParam, "%"+partnerNameMatch+"%")
partnerCondition = append(partnerCondition, ` partner_info.partner_name like ? `)
}
if len(partnerCondition) > 0 {
sql += fmt.Sprintf(" AND (%s)", strings.Join(partnerCondition, " OR "))
}
tx := dao.transactionContext.PgTx
var (
result int
err error
)
_, err = tx.Query(&result, sql, allParam...)
return result, err
}
// func (dao BusinessBonusDao) CountBusinessBonus(partnerId int64, partnerNameMatch string,
// companyId int64, limit int, offset int) (int, error) {
// sql := `SELECT count(*)
// FROM business_bonus
// JOIN partner_info ON business_bonus.partner_info_id=partner_info.id
// WHERE business_bonus.is_disable=? AND business_bonus.company_id = ? `
// partnerCondition := []string{}
// allParam := []interface{}{domain.BUSINESS_BONUS_ENABLE, companyId}
// if partnerId > 0 {
// partnerCondition = append(partnerCondition, ` business_bonus.partner_info_id=? `)
// allParam = append(allParam, partnerId)
// }
// if len(partnerNameMatch) > 0 {
// allParam = append(allParam, "%"+partnerNameMatch+"%")
// partnerCondition = append(partnerCondition, ` partner_info.partner_name like ? `)
// }
// if len(partnerCondition) > 0 {
// sql += fmt.Sprintf(" AND (%s)", strings.Join(partnerCondition, " OR "))
// }
// tx := dao.transactionContext.PgTx
// var (
// result int
// err error
// )
// _, err = tx.Query(&result, sql, allParam...)
// return result, err
// }
func (dao BusinessBonusDao) ExistBusinessBonus(userId int64) (bool, error) {
tx := dao.transactionContext.PgTx
ok, err := tx.Model(&models.BusinessBonus{}).
Where("partner_info_id=?", userId).
Exists()
return ok, err
}
// func (dao BusinessBonusDao) ExistBusinessBonus(userId int64) (bool, error) {
// tx := dao.transactionContext.PgTx
// ok, err := tx.Model(&models.BusinessBonus{}).
// Where("partner_info_id=?", userId).
// Exists()
// return ok, err
// }
... ...