Browse Source

用户体系备份

wangchuanjin 2 years ago
parent
commit
02b693fb41
2 changed files with 14 additions and 35 deletions
  1. 7 8
      entity/db.go
  2. 7 27
      service/user.go

+ 7 - 8
entity/db.go

@@ -6,12 +6,11 @@ import (
 )
 
 var (
-	Mgo               mongodb.MongodbSim
-	Mysql             *mysql.Mysql
-	BaseMysql         *mysql.Mysql
-	UserTable         = "base_user" //用户表
-	UserSnapshotTable = "base_user_snapshot"
-	BasePerson        = "base_person"   //自然人表
-	BaseAccount       = "base_account"  //账户表
-	BasePosition      = "base_position" //职位表
+	Mgo          mongodb.MongodbSim
+	Mysql        *mysql.Mysql
+	BaseMysql    *mysql.Mysql
+	UserTable    = "base_user"     //用户表
+	BasePerson   = "base_person"   //自然人表
+	BaseAccount  = "base_account"  //账户表
+	BasePosition = "base_position" //职位表
 )

+ 7 - 27
service/user.go

@@ -180,33 +180,13 @@ func UserUpdates(this *UserIdReq) bool {
 }
 
 func UserDels(this *UserIdReq) bool {
-	ok := false
-	userData := entity.BaseMysql.FindOne(entity.UserTable, map[string]interface{}{"id": this.Id}, "", "")
-	if userData != nil && len(*userData) > 0 {
-		flag := entity.BaseMysql.ExecTx("", func(tx *sql.Tx) bool {
-			thisdata := *userData
-			ok1 := entity.BaseMysql.DeleteByTx(tx, entity.UserTable, map[string]interface{}{"id": this.Id})
-			snapshot := entity.BaseMysql.InsertByTx(tx, entity.UserSnapshotTable, map[string]interface{}{
-				"appid":       thisdata["appid"],
-				"user_id":     this.Id,
-				"phone":       thisdata["phone"],
-				"nickname":    thisdata["nickname"],
-				"headimg":     thisdata["headimg"],
-				"company":     thisdata["company"],
-				"position":    thisdata["position"],
-				"password":    thisdata["password"],
-				"s_openid":    thisdata["s_openid"],
-				"a_openid":    thisdata["a_openid"],
-				"unionid":     thisdata["unionid"],
-				"create_time": time.Now().Format("2006-01-02 15:04:05"),
-			})
-			return ok1 && snapshot > 0
-		})
-		if flag {
-			ok = true
-		}
-	}
-	return ok
+	return entity.BaseMysql.ExecTx("", func(tx *sql.Tx) bool {
+		_, e1 := entity.BaseMysql.ExecBySqlByTx(tx, `select * into base_user_backup from base_user where id=?`, this.Id)
+		_, e2 := entity.BaseMysql.ExecBySqlByTx(tx, `select * into base_position_backup from base_position where user_id=?`, this.Id)
+		_, e3 := entity.BaseMysql.ExecBySqlByTx(tx, `select a.* into base_person_backup from base_person a inner join base_user b on (b.id=? and a.id=b.person_id)`, this.Id)
+		_, e4 := entity.BaseMysql.ExecBySqlByTx(tx, `select a.* into base_account_backup from base_account a inner join base_user b on (b.id=? and a.person_id=b.person_id)`, this.Id)
+		return e1 == nil && e2 == nil && e3 == nil && e4 == nil
+	})
 }
 
 //