|
@@ -36,12 +36,21 @@ func (b *base_power) FindMyPowers(appid string, user_id, ent_id int64) *[]*base_
|
|
}
|
|
}
|
|
|
|
|
|
//查找我的权益
|
|
//查找我的权益
|
|
-func (b *base_power) FindMyPower(appid, function_code string, user_id, ent_id int64) *[]*base_power {
|
|
|
|
|
|
+func (b *base_power) FindMyPowersByFc(appid, function_code string, user_id, ent_id int64) *[]*base_power {
|
|
now := NowFormat(Date_Full_Layout)
|
|
now := NowFormat(Date_Full_Layout)
|
|
list := Mysql_BaseService.SelectBySql(`select * from base_power where appid=? and function_code=? and ((power_type=1 and power_ofid=?) or (power_type=2 and power_ofid=?)) and end_time>? and status=1 order by power_type`, appid, function_code, user_id, ent_id, now)
|
|
list := Mysql_BaseService.SelectBySql(`select * from base_power where appid=? and function_code=? and ((power_type=1 and power_ofid=?) or (power_type=2 and power_ofid=?)) and end_time>? and status=1 order by power_type`, appid, function_code, user_id, ent_id, now)
|
|
return JsonUnmarshal(list, &[]*base_power{}).(*[]*base_power)
|
|
return JsonUnmarshal(list, &[]*base_power{}).(*[]*base_power)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+//查找我最新一条的权益,没有过期限制
|
|
|
|
+func (b *base_power) FindMyLastPowerByFc(appid, function_code string, user_id, ent_id int64) *base_power {
|
|
|
|
+ list := Mysql_BaseService.SelectBySql(`select * from base_power where appid=? and function_code=? and ((power_type=1 and power_ofid=?) or (power_type=2 and power_ofid=?)) order by update_time desc limit 1`, appid, function_code, user_id, ent_id)
|
|
|
|
+ if len(*list) == 0 {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+ return JsonUnmarshal((*list)[0], &base_power{}).(*base_power)
|
|
|
|
+}
|
|
|
|
+
|
|
//查找我的权益,加锁
|
|
//查找我的权益,加锁
|
|
func (b *base_power) FindMyPowerForUpdate(id int64) *base_power {
|
|
func (b *base_power) FindMyPowerForUpdate(id int64) *base_power {
|
|
list := Mysql_BaseService.SelectBySql(`select * from base_power where id=? for update wait 5`, id)
|
|
list := Mysql_BaseService.SelectBySql(`select * from base_power where id=? for update wait 5`, id)
|
|
@@ -60,16 +69,17 @@ func (b *base_power) OpenPower(goods_spec_id int64, appid, goods_code string, us
|
|
ok1 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b
|
|
ok1 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b
|
|
on (a.appid=? and a.power_type=2 and a.power_ofid=? and a.status=1 and b.appid=? and b.goods_code=? and b.spec_id=? and a.function_code=b.function_code)
|
|
on (a.appid=? and a.power_type=2 and a.power_ofid=? and a.status=1 and b.appid=? and b.goods_code=? and b.spec_id=? and a.function_code=b.function_code)
|
|
inner join base_function c on (c.appid=? and c.status=1 and c.power_type=1 and c.code=a.function_code)
|
|
inner join base_function c on (c.appid=? and c.status=1 and c.power_type=1 and c.code=a.function_code)
|
|
- set a.status=0`, appid, ent_id, appid, goods_code, goods_spec_id, appid) > -1
|
|
|
|
|
|
+ set a.status=0,update_time=?`, appid, ent_id, appid, goods_code, goods_spec_id, appid, NowFormat(Date_Full_Layout)) > -1
|
|
}
|
|
}
|
|
//用户互斥的功能失效掉
|
|
//用户互斥的功能失效掉
|
|
if user_id > 0 {
|
|
if user_id > 0 {
|
|
ok2 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b
|
|
ok2 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b
|
|
on (a.appid=? and a.power_type=1 and a.power_ofid=? and a.status=1 and b.appid=? and b.goods_code=? and b.spec_id=? and a.function_code=b.function_code)
|
|
on (a.appid=? and a.power_type=1 and a.power_ofid=? and a.status=1 and b.appid=? and b.goods_code=? and b.spec_id=? and a.function_code=b.function_code)
|
|
inner join base_function c on (c.appid=? and c.status=1 and c.power_type=1 and c.code=a.function_code)
|
|
inner join base_function c on (c.appid=? and c.status=1 and c.power_type=1 and c.code=a.function_code)
|
|
- set a.status=0`, appid, user_id, appid, goods_code, goods_spec_id, appid) > -1
|
|
|
|
|
|
+ set a.status=0,update_time=?`, appid, user_id, appid, goods_code, goods_spec_id, appid, NowFormat(Date_Full_Layout)) > -1
|
|
}
|
|
}
|
|
power_values, empower_values, wait_empower_values := []interface{}{}, []interface{}{}, []interface{}{}
|
|
power_values, empower_values, wait_empower_values := []interface{}{}, []interface{}{}, []interface{}{}
|
|
|
|
+ nowFormat := NowFormat(Date_Full_Layout)
|
|
for _, bgs := range *bgss {
|
|
for _, bgs := range *bgss {
|
|
if bgs.Base_goods_spec_powers == nil {
|
|
if bgs.Base_goods_spec_powers == nil {
|
|
continue
|
|
continue
|
|
@@ -104,18 +114,25 @@ func (b *base_power) OpenPower(goods_spec_id int64, appid, goods_code string, us
|
|
logx.Error(appid, goods_code, goods_spec_id, v.Function_code, "无效的cycle", v.Cycle)
|
|
logx.Error(appid, goods_code, goods_spec_id, v.Function_code, "无效的cycle", v.Cycle)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
- start_time, end_time := NowFormat(Date_Full_Layout), FormatDate(&end, Date_Full_Layout)
|
|
|
|
|
|
+ start_time, end_time := nowFormat, FormatDate(&end, Date_Full_Layout)
|
|
power_values = append(power_values, start_time, end_time)
|
|
power_values = append(power_values, start_time, end_time)
|
|
use_count := buy_num
|
|
use_count := buy_num
|
|
if bgs.Calculation_type == 2 {
|
|
if bgs.Calculation_type == 2 {
|
|
use_count = buy_num * v.Use_count
|
|
use_count = buy_num * v.Use_count
|
|
}
|
|
}
|
|
- power_values = append(power_values, use_count, use_count, v.Limit_strategy, v.Strategy_count, 1, NowFormat(Date_Full_Layout))
|
|
|
|
|
|
+ surplus_count := use_count
|
|
|
|
+ if v.Base_function.Function_type == 2 {
|
|
|
|
+ lastPower := b.FindMyLastPowerByFc(appid, v.Function_code, user_id, ent_id)
|
|
|
|
+ if lastPower != nil {
|
|
|
|
+ surplus_count = lastPower.Surplus_count
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ power_values = append(power_values, use_count, surplus_count, v.Limit_strategy, v.Strategy_count, 1, nowFormat, nowFormat)
|
|
//
|
|
//
|
|
if v.Power_type == 2 && v.Power_count == -1 && Base_ent_empower.Count(appid, v.Function_code, ent_id) == 0 {
|
|
if v.Power_type == 2 && v.Power_count == -1 && Base_ent_empower.Count(appid, v.Function_code, ent_id) == 0 {
|
|
- empower_values = append(empower_values, appid, ent_id, 0, v.Function_code, NowFormat(Date_Full_Layout))
|
|
|
|
|
|
+ empower_values = append(empower_values, appid, ent_id, 0, v.Function_code, nowFormat)
|
|
} else if v.Power_type == 2 && v.Power_count > 0 {
|
|
} else if v.Power_type == 2 && v.Power_count > 0 {
|
|
- wait_empower_values = append(wait_empower_values, appid, v.Id, ent_id, start_time, end_time, use_count, v.Power_count, v.Limit_strategy, NowFormat(Date_Full_Layout))
|
|
|
|
|
|
+ wait_empower_values = append(wait_empower_values, appid, v.Id, ent_id, start_time, end_time, use_count, v.Power_count, v.Limit_strategy, nowFormat)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -123,7 +140,7 @@ func (b *base_power) OpenPower(goods_spec_id int64, appid, goods_code string, us
|
|
logx.Error(appid, goods_code, goods_spec_id, user_id, ent_id, "没有找到需要开通的权益")
|
|
logx.Error(appid, goods_code, goods_spec_id, user_id, ent_id, "没有找到需要开通的权益")
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
- v1, v2 := Mysql_BaseService.InsertBatchByTx(tx, "base_power", []string{"appid", "goods_spec_power_id", "function_code", "power_type", "power_ofid", "start_time", "end_time", "use_count", "surplus_count", "limit_strategy", "strategy_count", "status", "create_time"}, power_values)
|
|
|
|
|
|
+ v1, v2 := Mysql_BaseService.InsertBatchByTx(tx, "base_power", []string{"appid", "goods_spec_power_id", "function_code", "power_type", "power_ofid", "start_time", "end_time", "use_count", "surplus_count", "limit_strategy", "strategy_count", "status", "create_time", "update_time"}, power_values)
|
|
ok3 := true
|
|
ok3 := true
|
|
if len(empower_values) > 0 {
|
|
if len(empower_values) > 0 {
|
|
v3, v4 := Mysql_BaseService.InsertBatchByTx(tx, "base_ent_empower", []string{"appid", "ent_id", "ent_user_id", "function_code", "create_time"}, empower_values)
|
|
v3, v4 := Mysql_BaseService.InsertBatchByTx(tx, "base_ent_empower", []string{"appid", "ent_id", "ent_user_id", "function_code", "create_time"}, empower_values)
|
|
@@ -145,12 +162,12 @@ func (b *base_power) CancelPower(appid, goods_code string, spec_id, user_id, ent
|
|
if user_id > 0 {
|
|
if user_id > 0 {
|
|
ok1 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b
|
|
ok1 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b
|
|
on (a.appid=? and a.power_type=1 and a.power_ofid=? and a.status=1 and b.appid=? and b.goods_code=? and b.spec_id=? and b.power_type=1 and a.function_code=b.function_code)
|
|
on (a.appid=? and a.power_type=1 and a.power_ofid=? and a.status=1 and b.appid=? and b.goods_code=? and b.spec_id=? and b.power_type=1 and a.function_code=b.function_code)
|
|
- set a.status=-1`, appid, user_id, appid, goods_code, spec_id) > 0
|
|
|
|
|
|
+ set a.status=-1,update_time=?`, appid, user_id, appid, goods_code, spec_id, NowFormat(Date_Full_Layout)) > 0
|
|
}
|
|
}
|
|
if ent_id > 0 {
|
|
if ent_id > 0 {
|
|
ok2 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b
|
|
ok2 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b
|
|
on (a.appid=? and a.power_type=2 and a.power_ofid=? and a.status=1 and b.appid=? and b.goods_code=? and b.spec_id=? and b.power_type=2 and a.function_code=b.function_code)
|
|
on (a.appid=? and a.power_type=2 and a.power_ofid=? and a.status=1 and b.appid=? and b.goods_code=? and b.spec_id=? and b.power_type=2 and a.function_code=b.function_code)
|
|
- set a.status=-1`, appid, ent_id, appid, goods_code, spec_id) > 0
|
|
|
|
|
|
+ set a.status=-1,update_time=?`, appid, ent_id, appid, goods_code, spec_id, NowFormat(Date_Full_Layout)) > 0
|
|
}
|
|
}
|
|
return ok1 || ok2
|
|
return ok1 || ok2
|
|
})
|
|
})
|