|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package zyos_go_coupon
-
- import (
- "code.fnuoos.com/go_rely_warehouse/zyos_go_coupon.git/db"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_coupon.git/db/model"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_coupon.git/e"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_coupon.git/md"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_coupon.git/utils"
- "fmt"
- "time"
- "xorm.io/xorm"
- )
-
- //额度添加
- func AddCoupon(session *xorm.Session, req *md.CouponCheckRequest) error {
- if req.PvdType == "" {
- req.PvdType = "ordinary"
- }
- //查出该用户有的券额
- list, err := db.GetCouponUserTotalByOne(session, utils.StrToInt(req.Uid), req.PvdType)
- if err != nil {
- return err
- } else if list == nil {
- list = &model.CommCouponUserTotal{
- Uid: utils.StrToInt(req.Uid),
- CreateAt: time.Now(),
- UpdateAt: time.Now(),
- PvdType: req.PvdType,
- }
- }
- LeaveCouponAmountValue := list.LeaveCouponAmountValue
- list.LeaveCouponAmountValue = utils.Float64ToStr(utils.FloatFormat(utils.StrToFloat64(list.LeaveCouponAmountValue)+utils.StrToFloat64(req.CouponAmount), 2))
- ordType := 4
- if req.Type == "" {
- list.CouponAmountValue = utils.Float64ToStr(utils.FloatFormat(utils.StrToFloat64(list.CouponAmountValue)+utils.StrToFloat64(req.CouponAmount), 2))
- }
- if req.Type == "refund" {
- ordType = 5
- }
- has, err := db.CouponUserTotalByInsertWithUpdate(session, list)
-
- if has == 0 || err != nil {
- fmt.Println(err)
- return err
- }
- //写入明细
- var tmp = &model.CommCouponUserOrd{
- Uid: list.Uid,
- PayMethod: 0,
- OrdType: ordType,
- UsePvd: list.UsePvd,
- PackageId: 0,
- CouponAmountValue: req.CouponAmount,
- PayAmountValue: "",
- Discount: "",
- PayAmount: "",
- CreateAt: time.Now(),
- UpdateAt: time.Now(),
- PvdType: list.PvdType,
- GoodsType: req.Pvd,
- Gid: req.Gid,
- GoodsTitle: req.GoodsTitle,
- BeforeAmout: LeaveCouponAmountValue,
- AfterAmout: list.LeaveCouponAmountValue,
- }
- bools := db.CouponUserOrdByInsert(session, tmp)
- if bools == false {
- return e.NewErr(400, "失败")
- }
- return nil
- }
|