|
|
|
package jyy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"recook/internal/model/order"
|
|
|
|
jpush2 "recook/internal/v2/lib/jpush"
|
|
|
|
"recook/internal/v2/model/jpush"
|
|
|
|
"recook/internal/v2/model/jyy"
|
|
|
|
|
|
|
|
"git.oa00.com/go/mysql"
|
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ArgsLogisticsFee struct {
|
|
|
|
ID int `json:"order_id" validate:"required"`
|
|
|
|
Fee *decimal.Decimal `json:"fee"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o logic) SetFee(args ArgsLogisticsFee) error {
|
|
|
|
return mysql.Db.Transaction(func(tx *gorm.DB) error {
|
|
|
|
var od order.Information
|
|
|
|
tx.First(&od, "id = ?", args.ID)
|
|
|
|
if row := tx.Table((&order.Information{}).TableName()).
|
|
|
|
Where("id = ?", args.ID).
|
|
|
|
Where("can_pay = 0").Updates(map[string]interface{}{
|
|
|
|
"can_pay": true,
|
|
|
|
"express_total_fee": args.Fee.Abs(),
|
|
|
|
"actual_total_amount": gorm.Expr("actual_total_amount + ?", args.Fee.Abs()),
|
|
|
|
}).RowsAffected; row == 0 {
|
|
|
|
return errors.New("更新失败")
|
|
|
|
}
|
|
|
|
message := "物流费已确认, 请立即支付"
|
|
|
|
if e := tx.Create(&jyy.AppUserMessage{
|
|
|
|
UserID: int(od.UserID),
|
|
|
|
Message: message,
|
|
|
|
Kind: jyy.Order,
|
|
|
|
IsRead: false,
|
|
|
|
SubID: uint64(od.ID),
|
|
|
|
}).Error; e != nil {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
var ju jpush.JPush
|
|
|
|
mysql.Db.First(&ju, "user_id = ?", od.UserID)
|
|
|
|
if ju.RegistrationId != "" {
|
|
|
|
client := jpush2.GetClient()
|
|
|
|
client.PushMsgWithRegister(ju.RegistrationId, "物流费确认", message)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|