Skip to content

Commit

Permalink
Merge branch 'feat/coupon' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
sjatsh committed Nov 7, 2023
2 parents bd9b239 + 32d64b9 commit d4be6ac
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 378 deletions.
8 changes: 6 additions & 2 deletions cache/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ func (r *RedisCache) UnLockWithRedis(accountId string) error {
return nil
}

func (r *RedisCache) Lock(key string) error {
ret := r.Red.SetNX(lock+key, 1, time.Second*lockTime)
func (r *RedisCache) Lock(key string, expirations ...time.Duration) error {
expiration := time.Second * lockTime
if len(expirations) > 0 {
expiration = expirations[0]
}
ret := r.Red.SetNX(lock+key, 1, expiration)
if err := ret.Err(); err != nil {
return fmt.Errorf("redis set order nx-->%s", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion dao/t_coupon_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (d *DbDao) UpdateCouponSetInfo(setInfo *tables.CouponSetInfo) error {
}

func (d *DbDao) GetUnPaidCouponSetByAccId(accId string) (res tables.CouponSetInfo, err error) {
if err = d.db.Where("account_id = ? and status = ?", accId, tables.CouponSetInfoStatusDefault).First(&res).Error; err != nil {
if err = d.db.Where("account_id = ? and status = ?", accId, tables.CouponSetInfoStatusNormal).First(&res).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
err = nil
return
Expand Down
22 changes: 14 additions & 8 deletions dao/t_order_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (d *DbDao) UpdateOrderPayStatusOkWithSmtRecord(paymentInfo tables.PaymentIn
return
}

func (d *DbDao) UpdateOrderPayStatusOkWithCouponSetInfo(paymentInfo tables.PaymentInfo, setInfo tables.CouponSetInfo) (rowsAffected int64, e error) {
func (d *DbDao) UpdateOrderPayStatusOkWithCoupon(paymentInfo tables.PaymentInfo, setInfo *tables.CouponSetInfo, coupons []tables.CouponInfo) (rowsAffected int64, e error) {
e = d.db.Transaction(func(tx *gorm.DB) error {
tmpTx := tx.Model(tables.OrderInfo{}).
Where("order_id=? AND pay_status=?",
Expand All @@ -104,7 +104,7 @@ func (d *DbDao) UpdateOrderPayStatusOkWithCouponSetInfo(paymentInfo tables.Payme
return tmpTx.Error
}
rowsAffected = tmpTx.RowsAffected
log.Info("UpdateOrderPayStatusOkWithCouponSetInfo:", rowsAffected, paymentInfo.OrderId)
log.Info("UpdateOrderPayStatusOkWithCoupon:", rowsAffected, paymentInfo.OrderId)

if err := tx.Clauses(clause.Insert{
Modifier: "IGNORE",
Expand Down Expand Up @@ -134,12 +134,10 @@ func (d *DbDao) UpdateOrderPayStatusOkWithCouponSetInfo(paymentInfo tables.Payme
return nil
}

if err := tx.Model(tables.CouponSetInfo{}).
Where("cid=?", setInfo.Cid).
Updates(map[string]interface{}{
"order_id": paymentInfo.OrderId,
"status": tables.CouponSetInfoStatusPaid,
}).Error; err != nil {
if err := tx.Create(setInfo).Error; err != nil {
return err
}
if err := tx.Create(&coupons).Error; err != nil {
return err
}
return nil
Expand Down Expand Up @@ -303,3 +301,11 @@ func (d *DbDao) UpdateOrderStatusToFailForUnconfirmedPayHash(orderId, payHash st
return nil
})
}

func (d *DbDao) GetPendingOrderByAccIdAndActionType(accountId string, actionType tables.ActionType) (order tables.OrderInfo, err error) {
err = d.db.Where("accountId=? and action_type=? and order_status=?", accountId, actionType, tables.OrderStatusDefault).First(&order).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
err = nil
}
return
}
259 changes: 0 additions & 259 deletions http_server/handle/coupon_create.go

This file was deleted.

Loading

0 comments on commit d4be6ac

Please sign in to comment.