|
|
package client
import ( "hudongzhuanjia/controllers" "hudongzhuanjia/libs/filter" "hudongzhuanjia/models" bully_reward_service "hudongzhuanjia/services/bully_reward" pay_service "hudongzhuanjia/services/pay" "hudongzhuanjia/utils" "hudongzhuanjia/utils/code" "strings" "time"
"github.com/ouxuanserver/osmanthuswine/src/core" )
//打赏
type RewardCtl struct { controllers.AuthorCtl }
func (t *RewardCtl) Reward() { activityId := t.MustGetInt64("activity_id") content := t.MustGet("content") amount := t.MustGetDouble("amount") uid := t.MustGetUID()
if amount <= 0 { t.ERROR("打赏金额不能小于0", code.MSG_ERR_Param) return } //检查内容是否包含敏感
if ok, _ := filter.Validate(content); !ok { t.ERROR("内容包含敏感字", code.MSG_ERR) return }
activity := new(models.Activity) exist, err := models.GetById(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") //查询该活动的的打赏服务id
rewardServer := new(models.RewardServer) exist, err = rewardServer.GetByActivityId(activityId) t.CheckErr(err) t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
amount = utils.Float64CusDecimal(amount, 2)
//查询用户信息
user := new(models.User) exist, err = models.GetById(user, uid) t.CheckErr(err) t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
ip := strings.Split(t.Request.OriginRequest.RemoteAddr, ":") res, err := pay_service.UnifiedOrder("欧轩互动-打赏支付", ip[0], user.Openid, int64(amount*100), 2, user.Id, activityId) t.CheckErr(err)
_, err = core.GetXormAuto().InsertOne(&models.RewardHistory{ OutTradeNo: res["out_trade_no"].(string), RewardServerId: rewardServer.Id, CustomerId: t.MustGetCustomerId(), UserId: user.Id, Amount: amount, Content: content, RehearsalId: activity.RehearsalId, Status: -1, ReviewTime: 0, IsDelete: false, CreatedAt: time.Now(), UpdatedAt: time.Now(), }) t.CheckErr(err)
t.JSON(res) }
func (t *RewardCtl) List() { uid := t.MustGetUID() activityId := t.MustGetInt64("activity_id")
rs := new(models.RewardServer) exist, err := rs.GetByActivityId(activityId) t.CheckErr(err) t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
// todo: 检查订单
t.CheckErr(bully_reward_service.CheckRewardStatus(rs.Id))
list, err := bully_reward_service.GetRewardList(uid, rs.Id) t.CheckErr(err) t.JSON(map[string]interface{}{ "total": len(list), "list": list, }) }
|