From 0128c61d38f3ddd8de3547edfd77e94eb14d9ddd Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Mon, 3 Aug 2020 11:39:32 +0800 Subject: [PATCH] fix:bug --- controllers/client/lottery.go | 4 ++-- controllers/client/order_entry.go | 19 +++++++++++++------ controllers/pc/lottery_draw.go | 5 ----- models/customer_order.go | 4 ++++ models/lottery_draw_record.go | 27 +++++++++++++-------------- services/lottery/lottery.go | 27 ++++++++++++++------------- 6 files changed, 46 insertions(+), 40 deletions(-) diff --git a/controllers/client/lottery.go b/controllers/client/lottery.go index 20fea65..2520bbd 100644 --- a/controllers/client/lottery.go +++ b/controllers/client/lottery.go @@ -49,8 +49,8 @@ func (t *LotteryCtl) CashLottery() { exist, err := record.GetByUserPrizeId(prizeId) t.CheckErr(err) t.Assert(exist, code.MSG_LOTTERY_DRAW_RECORD_NOT_EXIST, "中奖记录不存在") - record.Name = name - record.Phone = phone + record.UserName = name + record.UserPhone = phone record.WxNo = wxNo record.Address = address record.Status = 1 diff --git a/controllers/client/order_entry.go b/controllers/client/order_entry.go index e18597d..7afca58 100644 --- a/controllers/client/order_entry.go +++ b/controllers/client/order_entry.go @@ -277,16 +277,23 @@ func (t *OrderEntryCtl) ManualOrder() { s.Rollback() t.CheckErr(err) } - user := models.User{ - Phone: param.Phone, - Nickname: param.Name, - Password: utils.RandomStr(6), - } - _, err = s.InsertOne(&user) + user := models.User{} + exist, err = s.Where("is_delete=0 and phone=?", param.Phone).NoAutoCondition().Get(&user) if err != nil { s.Rollback() t.CheckErr(err) } + if !exist { + user.Phone = param.Phone + user.Nickname = param.Name + user.Password = utils.RandomStr(8) + _, err = s.InsertOne(&user) + if err != nil { + s.Rollback() + t.CheckErr(err) + } + } + // 校验库存 goods := make([]*models.CustomerGoods, 0) err = s.Where("is_delete=0").In("id", goodIds).Find(&goods) diff --git a/controllers/pc/lottery_draw.go b/controllers/pc/lottery_draw.go index 6d37a01..be1e0df 100644 --- a/controllers/pc/lottery_draw.go +++ b/controllers/pc/lottery_draw.go @@ -220,11 +220,6 @@ func (t *LotteryDrawCtl) Users() { ruleId := t.MustGetInt("lottery_draw_rule_id") customerId := t.GetAccountId() - //customer := new(models.Customer) - //exist, err := models.Get(customer, customerId) - //t.CheckErr(err) - //t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") - activity := new(models.Activity) exist, err := models.Get(activity, activityId) t.CheckErr(err) diff --git a/models/customer_order.go b/models/customer_order.go index 897b9fc..61739a8 100644 --- a/models/customer_order.go +++ b/models/customer_order.go @@ -59,6 +59,10 @@ func (t *CustomerOrder) TableName() string { return CustomerOrderTableName } +func (t *CustomerOrder) Alias(name string) string { + return Alias(t, name) +} + func (t *CustomerOrder) GetByOutTradeNO(outTradeNo string) (bool, error) { return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", outTradeNo).Get(t) } diff --git a/models/lottery_draw_record.go b/models/lottery_draw_record.go index 2fb3862..e55be2c 100644 --- a/models/lottery_draw_record.go +++ b/models/lottery_draw_record.go @@ -9,24 +9,23 @@ import ( const LotteryDrawRecordTableName = TableNamePrefix + "lottery_draw_record" type LotteryDrawRecord struct { - Id int `json:"id" xorm:"pk autoincr"` - ActivityId int `json:"activity_id" xorm:"not null comment('主活动id')"` - RehearsalId int `json:"rehearsal_id" xorm:"not null comment('彩排id/0正式')"` + Id int `json:"id" xorm:"pk autoincr not null INT(11)"` + ActivityId int `json:"activity_id" xorm:"not null comment('主活动id') INT(11)"` + RehearsalId int `json:"rehearsal_id" xorm:"not null comment('彩排id/0正式') INT(11)"` UserPrizeId int `json:"user_prize_id" xorm:"not null comment('用户奖品id') INT(11)"` - LotteryDrawActivityId int `json:"lottery_draw_activity_id" xorm:"not null comment('抽奖活动id')"` - LotteryDrawRuleId int `json:"lottery_draw_rule_id" xorm:"not null comment('抽奖规则id') BIGINT(20)"` - LotteryDrawRuleLadderId int `json:"lottery_draw_rule_ladder_id" xorm:"not null comment('规则阶梯id')"` + LotteryDrawActivityId int `json:"lottery_draw_activity_id" xorm:"not null comment('抽奖活动id') INT(11)"` + LotteryDrawRuleId int `json:"lottery_draw_rule_id" xorm:"not null comment('抽奖规则id') INT(20)"` + LotteryDrawRuleLadderId int `json:"lottery_draw_rule_ladder_id" xorm:"not null comment('规则阶梯id') INT(11)"` ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"` - UserId int `json:"user_id" xorm:"not null comment('用户id')"` + UserId int `json:"user_id" xorm:"not null comment('用户id') INT(11)"` + AreaId int `json:"area_id" xorm:"not null default(0) comment('地区id') INT(11)"` RollNum int `json:"roll_num" xrom:"not null default 0 comment('滚动次数') INT(11)"` - UserName string `json:"user_name" description:"用户名" xorm:"not null comment('用户名')"` - UserPhone string `json:"user_phone" description:"电话" xorm:"not null comment('电话号码')"` - PrizeName string `json:"prize_name" description:"奖品名字" xorm:"not null comment('奖品名字')"` - AreaName string `json:"area_name" description:"名字" xorm:"not null comment('地区名字')"` - AreaId int `json:"area_id" xorm:"not null default(0) comment('地区id')"` + UserName string `json:"user_name" xorm:"not null comment('用户名') VARCHAR(128)"` + UserPhone string `json:"user_phone" xorm:"not null comment('电话号码') VARCHAR(128)"` + PrizeName string `json:"prize_name" xorm:"not null comment('奖品名字') VARCHAR(128)"` + AreaName string `json:"area_name" xorm:"not null comment('地区名字') VARCHAR(128)"` + EntryPersonName string `json:"entry_person_name" xorm:"not null default '' comment('录入人员名单') VARCHAR(128)"` Status int `json:"status" xorm:"not null default 0 comment('是否已经兑奖0否1是') TINYINT(1)"` - Name string `json:"name" xorm:"not null default '' comment('姓名') VARCHAR(128)"` - Phone string `json:"phone" xorm:"not null default '' comment('电话号码') VARCHAR(128)"` WxNo string `json:"wx_no" xorm:"not null default '' comment('微信号') VARCHAR(128)"` Address string `json:"address" xorm:"not null default '' comment('地址') VARCHAR(128)"` IsDelete bool `json:"-" xorm:"default(0)"` diff --git a/services/lottery/lottery.go b/services/lottery/lottery.go index e2c6718..a25e2ba 100644 --- a/services/lottery/lottery.go +++ b/services/lottery/lottery.go @@ -64,20 +64,20 @@ func GetLotteryUserIds(repeat string, activityId, ruleId, ladderId, rehearsalId, } type LotteryListResult struct { - LotteryDrawActivityId int `json:"lottery_draw_activity_id"` - LotteryDrawRuleId int `json:"lottery_draw_rule_id"` + LotteryDrawActivityId int `json:"lottery_draw_activity_id"` + LotteryDrawRuleId int `json:"lottery_draw_rule_id"` LotteryDrawActivityName string `json:"lottery_draw_name"` LotteryDrawLadders []*LotteryLadderResult `json:"lottery_draw_ladders"` - PrizeNumber int `json:"prize_number"` + PrizeNumber int `json:"prize_number"` } type LotteryLadderResult struct { - LotteryDrawRuleId int `json:"-"` - LotteryDrawLadderId int `json:"lottery_draw_ladder_id"` + LotteryDrawRuleId int `json:"-"` + LotteryDrawLadderId int `json:"lottery_draw_ladder_id"` Status string `json:"status"` PrizeName string `json:"prize_name"` PrizeImg string `json:"prize_img"` - PrizeNumber int `json:"prize_number"` + PrizeNumber int `json:"prize_number"` } func GetLotteryAndLadder(activityId, rehearsalId, archId interface{}) ([]*LotteryListResult, error) { @@ -139,7 +139,7 @@ func GetLotteryAndLadder(activityId, rehearsalId, archId interface{}) ([]*Lotter } type LotteryUsersResult struct { - UserId int `json:"user_id"` + UserId int `json:"user_id"` Username string `json:"username"` Avatar string `json:"avatar"` } @@ -176,16 +176,17 @@ func GetLotteryUsersResult(areaId, activityId, rehearsalId, archId interface{}, } type WinnersResult struct { - UserId int `json:"user_id"` - UserName string `json:"user_name"` - UserPhone string `json:"user_phone"` - Avatar string `json:"avatar"` - PrizeName string `json:"prize_name"` + UserId int `json:"user_id"` + UserName string `json:"user_name"` + UserPhone string `json:"user_phone"` + Avatar string `json:"avatar"` + PrizeName string `json:"prize_name"` + EntryPersonName string `json:"entry_person_name"` } func GetWinnersResult(ruleId, rehearsalId, archId interface{}) ([]*WinnersResult, error) { result := make([]*WinnersResult, 0) - err := core.GetXormAuto().Table(new(models.LotteryDrawRecord)).Alias("r"). + err := core.GetXormAuto().Table(&models.LotteryDrawRecord{}).Alias("r"). Join("LEFT", new(models.User).Alias("u"), "u.id=r.user_id"). Where("r.is_delete=0 and r.lottery_draw_rule_id=? and r.rehearsal_id=? and r.arch_id=?", ruleId, rehearsalId, archId).Find(&result)