|
@@ -19,7 +19,7 @@ import (
|
|
|
"gorm.io/gorm"
|
|
|
)
|
|
|
|
|
|
-func CreateUserProduct(appId string, productArr []map[string]interface{}, buyType int) (status int, haveProductId string, err error) {
|
|
|
+func CreateUserProduct(appId string, productArr []map[string]interface{}, buyType int) (status int, haveProductId string, errArr []error) {
|
|
|
//取出用户锁
|
|
|
lock.MainLock.Lock()
|
|
|
userLock := lock.UserLockMap[appId]
|
|
@@ -28,6 +28,7 @@ func CreateUserProduct(appId string, productArr []map[string]interface{}, buyTyp
|
|
|
defer userLock.Unlock()
|
|
|
var errs error
|
|
|
haveProductId = "" //已经购买过的产品id
|
|
|
+ //var errArr = make([]error, 0)
|
|
|
for _, val := range productArr {
|
|
|
productId := utils.IntAll(val["productId"])
|
|
|
costModel := utils.IntAll(val["costModel"])
|
|
@@ -48,14 +49,16 @@ func CreateUserProduct(appId string, productArr []map[string]interface{}, buyTyp
|
|
|
//查询产品信息,获取购买时候产品单价、试用次数
|
|
|
err := db.GetSFISDB().Where("id = ?", productId).Find(&product).Error
|
|
|
if err != nil {
|
|
|
+ errArr = append(errArr, err)
|
|
|
global.Logger.Error("CreateUserProduct查询product表出错:", zap.Any("err:", err))
|
|
|
- return 0, haveProductId, err
|
|
|
+ return 0, haveProductId, errArr
|
|
|
}
|
|
|
historyUnitPrice := product.UnitPrice
|
|
|
err = db.GetSFISDB().Where("product_id = ? and app_id = ?", productId, appId).Find(&userProductInfo).Error
|
|
|
if err != nil {
|
|
|
+ errArr = append(errArr, err)
|
|
|
global.Logger.Error("CreateUserProduct查询user_product表出错:", zap.Any("err:", err))
|
|
|
- return 0, haveProductId, err
|
|
|
+ return 0, haveProductId, errArr
|
|
|
}
|
|
|
//用户第一次购买产品
|
|
|
if userProductInfo.ID == 0 {
|
|
@@ -121,6 +124,7 @@ func CreateUserProduct(appId string, productArr []map[string]interface{}, buyTyp
|
|
|
return nil
|
|
|
})
|
|
|
if errs != nil {
|
|
|
+ errArr = append(errArr, errs)
|
|
|
global.Logger.Info("用户已购买产品失败:", zap.Any("appId:", appId), zap.Any("productId:", productId))
|
|
|
continue
|
|
|
}
|
|
@@ -130,10 +134,9 @@ func CreateUserProduct(appId string, productArr []map[string]interface{}, buyTyp
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
- return 1, haveProductId, nil
|
|
|
+ return 1, haveProductId, errArr
|
|
|
}
|
|
|
|
|
|
-
|
|
|
func UserProductList(appId string, c *gin.Context) (userProduct []model.UserProduct, err error) {
|
|
|
//userProduct := []model.UserProduct{}
|
|
|
err = db.GetSFISDB().Where("app_id = ? ", appId).Find(&userProduct).Error
|