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) *UserAddResp { userId := entity.BaseMysql.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, "s_openid": this.SOpenid, "a_openid": this.AOpenid, "unionid": this.Unionid, "create_time": time.Now().Format("2006-01-02 15:04:05"), }) status, msg := 0, "" if userId > 0 { status = 1 } else { msg = "新增用户失败" } return &UserAddResp{ ErrorCode: entity.SuccessCode, ErrorMsg: msg, Data: &UserAdds{Status: int64(status), Id: userId}, } } func UserUpdate(this *UserIdReq) *ExamineResp { ok := UserUpdates(this) status, msg := 0, "" if ok { status = 1 } else { msg = "更新用户失败" } return &ExamineResp{ ErrorCode: entity.SuccessCode, ErrorMsg: msg, Data: &ExamineData{Status: int64(status)}, } } func UserDel(this *UserIdReq) *ExamineResp { ok := UserDels(this) status, msg := 0, "" if ok { status = 1 } else { msg = "删除用户失败" } return &ExamineResp{ ErrorCode: entity.SuccessCode, ErrorMsg: msg, Data: &ExamineData{Status: int64(status)}, } } func UserUpdates(this *UserIdReq) bool { ok := false flag := entity.BaseMysql.ExecTx("", func(tx *sql.Tx) bool { set := map[string]interface{}{} if this.Phone != "" { set["phone"] = this.Phone } else { set["phone"] = "" } if this.Nickname != "" { set["nickname"] = this.Nickname } else { set["nickname"] = "" } if this.Headimg != "" { set["headimg"] = this.Headimg } else { set["headimg"] = "" } if this.Company != "" { set["company"] = this.Company } else { set["company"] = "" } if this.Position != "" { set["position"] = this.Position } else { set["position"] = "" } if this.Password != "" { set["password"] = this.Password } else { set["password"] = "" } if this.AOpenid != "" { set["a_openid"] = this.AOpenid } else { set["a_openid"] = "" } if this.SOpenid != "" { set["s_openid"] = this.SOpenid } else { set["s_openid"] = "" } if this.Unionid != "" { set["unionid"] = this.Unionid } else { set["unionid"] = "" } ok1 := entity.BaseMysql.UpdateByTx(tx, entity.UserTable, map[string]interface{}{"id": this.Id}, set) snapshot := entity.BaseMysql.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, "s_openid": this.SOpenid, "a_openid": this.AOpenid, "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.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 }