package service import ( "database/sql" "time" "bp.jydev.jianyu360.cn/BaseService/userCenter/entity" . "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter" ) func UserAdd(this *UserAddReq) *ExamineResp { userId := entity.Mysql.Insert(entity.UserTable, map[string]interface{}{ "appid": this.Appid, "phone": this.Phone, "nickname": this.Nickname, "headimg": this.Headimg, "company": this.Company, "position": this.Position, "password": this.Password, "openid": this.Openid, "unionid": this.Unionid, "create_time": time.Now().Format("2006-01-02 15:04:05"), }) status := 0 if userId > 0 { status = 1 } return &ExamineResp{ ErrorCode: 1, ErrorMsg: "成功", Data: &ExamineData{Status: int64(status)}, } } func UserUpdate(this *UserIdReq) *ExamineResp { ok := UserUpdates(this) status := 0 if ok { status = 1 } return &ExamineResp{ ErrorCode: 1, ErrorMsg: "成功", Data: &ExamineData{Status: int64(status)}, } } func UserDel(this *UserIdReq) *ExamineResp { ok := UserDels(this) status := 0 if ok { status = 1 } return &ExamineResp{ ErrorCode: 1, ErrorMsg: "成功", Data: &ExamineData{Status: int64(status)}, } } func UserUpdates(this *UserIdReq) bool { ok := false flag := entity.Mysql.ExecTx("", func(tx *sql.Tx) bool { set := map[string]interface{}{} if this.Phone != "" { set["phone"] = this.Phone } if this.Nickname != "" { set["nickname"] = this.Nickname } if this.Headimg != "" { set["headimg"] = this.Headimg } if this.Company != "" { set["company"] = this.Company } if this.Position != "" { set["position"] = this.Position } if this.Password != "" { set["password"] = this.Password } if this.Openid != "" { set["openid"] = this.Openid } if this.Unionid != "" { set["unionid"] = this.Unionid } ok1 := entity.Mysql.UpdateByTx(tx, entity.UserTable, map[string]interface{}{"id": this.Id}, set) snapshot := entity.Mysql.InsertByTx(tx, entity.UserSnapshotTable, map[string]interface{}{ "appid": this.Appid, "user_id": this.Id, "phone": this.Phone, "nickname": this.Nickname, "headimg": this.Headimg, "company": this.Company, "position": this.Position, "password": this.Password, "openid": this.Openid, "unionid": this.Unionid, "create_time": time.Now().Format("2006-01-02 15:04:05"), }) return ok1 && snapshot > 0 }) if flag { ok = true } return ok } func UserDels(this *UserIdReq) bool { ok := false userData := entity.Mysql.FindOne(entity.UserTable, map[string]interface{}{"id": this.Id}, "", "") if userData != nil && len(*userData) > 0 { flag := entity.Mysql.ExecTx("", func(tx *sql.Tx) bool { thisdata := *userData ok1 := entity.Mysql.DeleteByTx(tx, entity.UserTable, map[string]interface{}{"id": this.Id}) snapshot := entity.Mysql.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"], "openid": thisdata["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 }