Commit cc0ffcd3 authored by chenweijian's avatar chenweijian

申请加入家族

parent 2fbe9c7f
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"gorm.io/gorm" "gorm.io/gorm"
"hilo-group/myerr" "hilo-group/myerr"
"hilo-group/myerr/bizerr"
"time" "time"
) )
...@@ -17,12 +18,14 @@ type GroupPowerApplyJoin struct { ...@@ -17,12 +18,14 @@ type GroupPowerApplyJoin struct {
} }
func InsertGroupPowerApplyJoin(model *domain.Model, userId, familyId uint64) error { func InsertGroupPowerApplyJoin(model *domain.Model, userId, familyId uint64) error {
nowTime := time.Now() sql := "insert into group_power_apply_join(user_id,group_power_id,is_accept) " +
sql := "insert into group_power_apply_join(user_id,group_power_id,is_accept,created_time,updated_time) " + "select ?, ?, ? where not exists (select id from group_power_apply_join where user_id=? and group_power_id=? and is_accept=0)"
"value(?,?,?,?,?) on duplicate key update is_accept=?,created_time=?,updated_time=?" result := model.Db.Exec(sql, userId, familyId, 0, userId, familyId)
err := model.Db.Exec(sql, userId, familyId, 0, nowTime, nowTime, 0, nowTime, nowTime).Error if result.Error != nil {
if err != nil { return myerr.WrapErr(result.Error)
return myerr.WrapErr(err) }
if result.RowsAffected <= 0 {
return myerr.WrapErr(bizerr.GroupPowerHaveAlreadyApply)
} }
return nil return nil
} }
......
...@@ -84,6 +84,7 @@ var ( ...@@ -84,6 +84,7 @@ var (
GroupPowerHaveNoJoin = myerr.NewBusinessCode(15011, "You have no joined power", myerr.BusinessData{}) // 还未加入国家势力 GroupPowerHaveNoJoin = myerr.NewBusinessCode(15011, "You have no joined power", myerr.BusinessData{}) // 还未加入国家势力
GroupPowerHaveNoPower = myerr.NewBusinessCode(15012, "You have no power", myerr.BusinessData{}) // 没有权限 GroupPowerHaveNoPower = myerr.NewBusinessCode(15012, "You have no power", myerr.BusinessData{}) // 没有权限
GroupPowerHaveNoApply = myerr.NewBusinessCode(15013, "User have no apply", myerr.BusinessData{}) // 没有找到申请 GroupPowerHaveNoApply = myerr.NewBusinessCode(15013, "User have no apply", myerr.BusinessData{}) // 没有找到申请
GroupPowerHaveAlreadyApply = myerr.NewBusinessCode(15014, "Already applied", myerr.BusinessData{}) // 已经申请过
TaskHasAward = myerr.NewBusinessCode(19001, "task has award", myerr.BusinessData{}) TaskHasAward = myerr.NewBusinessCode(19001, "task has award", myerr.BusinessData{})
......
...@@ -27,6 +27,6 @@ CREATE TABLE `group_power_apply_join` ( ...@@ -27,6 +27,6 @@ CREATE TABLE `group_power_apply_join` (
`updated_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `updated_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`is_accept` tinyint NOT NULL DEFAULT '0' COMMENT '是否已经接受', `is_accept` tinyint NOT NULL DEFAULT '0' COMMENT '是否已经接受',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `u_apply` (`user_id`,`group_power_id`) USING BTREE, KEY `group_power_id` (`group_power_id`),
KEY `group_power_id` (`group_power_id`) KEY `user_id` (`user_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='申请加入家族'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='申请加入家族';
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment