|
@@ -4,26 +4,56 @@ import (
|
|
|
"database/sql"
|
|
|
"time"
|
|
|
|
|
|
+ "app.yhyue.com/moapp/jybase/common"
|
|
|
+
|
|
|
"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"),
|
|
|
+ userId := int64(0)
|
|
|
+ ok := entity.BaseMysql.ExecTx("新增用户相关表字段", func(tx *sql.Tx) bool {
|
|
|
+ //自然人
|
|
|
+ personId := entity.BaseMysql.InsertByTx(tx, entity.BasePerson, map[string]interface{}{
|
|
|
+ "name": this.Nickname,
|
|
|
+ "headimg": this.Headimg,
|
|
|
+ "idcard": this.IdCard,
|
|
|
+ "address": this.Address,
|
|
|
+ "sex": this.Sex,
|
|
|
+ "contact": this.Phone,
|
|
|
+ "create_time": time.Now().Format("2006-01-02 15:04:05"),
|
|
|
+ "update_time": time.Now().Format("2006-01-02 15:04:05"),
|
|
|
+ })
|
|
|
+ //账户表
|
|
|
+ accountId := entity.BaseMysql.InsertByTx(tx, entity.BaseAccount, map[string]interface{}{
|
|
|
+ "person_id": personId,
|
|
|
+ "type": 0,
|
|
|
+ })
|
|
|
+ //用户表
|
|
|
+ baseUserId := entity.BaseMysql.InsertByTx(tx, entity.UserTable, map[string]interface{}{
|
|
|
+ "appid": this.Appid,
|
|
|
+ "person_id": personId,
|
|
|
+ "phone": this.Phone,
|
|
|
+ "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"),
|
|
|
+ "update_time": time.Now().Format("2006-01-02 15:04:05"),
|
|
|
+ })
|
|
|
+ //职位表
|
|
|
+ positionId := entity.BaseMysql.InsertByTx(tx, entity.BasePosition, map[string]interface{}{
|
|
|
+ "type": 0,
|
|
|
+ "account_id": accountId,
|
|
|
+ "user_id": baseUserId,
|
|
|
+ "person_name": this.Nickname,
|
|
|
+ })
|
|
|
+ userId = baseUserId
|
|
|
+ return personId > 0 && accountId > 0 && baseUserId > 0 && positionId > 0
|
|
|
})
|
|
|
+
|
|
|
status, msg := 0, ""
|
|
|
- if userId > 0 {
|
|
|
+ if userId > 0 && ok {
|
|
|
status = 1
|
|
|
} else {
|
|
|
msg = "新增用户失败"
|
|
@@ -114,22 +144,34 @@ func UserUpdates(this *UserIdReq) bool {
|
|
|
} else {
|
|
|
set["unionid"] = ""
|
|
|
}
|
|
|
+ //base_user
|
|
|
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
|
|
|
+ //查询出personid
|
|
|
+ ok2 := true
|
|
|
+ ok3 := true
|
|
|
+ rdata := entity.BaseMysql.SelectBySqlByTx(tx, `select person_id from base_user where id =?`, this.Id)
|
|
|
+ if rdata != nil && len(*rdata) > 0 {
|
|
|
+ person_id := common.Int64All((*rdata)[0]["person_id"])
|
|
|
+ ok2 = entity.BaseMysql.UpdateByTx(tx, entity.BasePerson, map[string]interface{}{
|
|
|
+ "id": person_id,
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "contact": this.Phone,
|
|
|
+ "name": this.Nickname,
|
|
|
+ "headimg": this.Headimg,
|
|
|
+ })
|
|
|
+ //获取accountid
|
|
|
+ mdata := entity.BaseMysql.SelectBySqlByTx(tx, `select id from base_account where person_id =?`, person_id)
|
|
|
+ if mdata != nil && len(*mdata) > 0 {
|
|
|
+ accountId := common.Int64All((*mdata)[0]["id"])
|
|
|
+ ok3 = entity.BaseMysql.UpdateByTx(tx, entity.BasePosition, map[string]interface{}{
|
|
|
+ "user_id": this.Id,
|
|
|
+ "account_id": accountId,
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "person_name": this.Nickname,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ok1 && ok2 && ok3
|
|
|
})
|
|
|
if flag {
|
|
|
ok = true
|
|
@@ -166,3 +208,51 @@ func UserDels(this *UserIdReq) bool {
|
|
|
}
|
|
|
return ok
|
|
|
}
|
|
|
+
|
|
|
+//
|
|
|
+
|
|
|
+/*
|
|
|
+ int64 error_code = 1;
|
|
|
+ string error_msg = 2;
|
|
|
+ int64 personId=3;//自然人id
|
|
|
+ int64 userAccountId=4;//个人账户id
|
|
|
+ int64 entAccountId =5; //企业账户id
|
|
|
+ int64 entUserAccountId =6;//企业雇员账户id
|
|
|
+ int64 userPositionId =7; // 个人职位id
|
|
|
+ int64 entUserPositionId =8;// 企业雇员职位id
|
|
|
+ string userName=9; //昵称
|
|
|
+
|
|
|
+*/
|
|
|
+func UserIdentity(this *UserIdentityReq) *UserIdentityResp {
|
|
|
+ resp := &UserIdentityResp{}
|
|
|
+ //个人账户
|
|
|
+ data := entity.BaseMysql.SelectBySql(`SELECT a.person_id personId,c.id userAccountId ,d.id userPositionId,b.name userName FROM base_user a
|
|
|
+ INNER JOIN base_person b ON a.person_id =b.id
|
|
|
+ INNER JOIN base_account c ON c.person_id = b.id AND c.type=0
|
|
|
+ INNER JOIN base_position d ON d.account_id = c.id AND d.user_id = a.id AND d.type=0
|
|
|
+ WHERE a.id =? AND a.appid =?`, this.BaseUserId, this.AppId)
|
|
|
+ if data != nil && len(*data) > 0 {
|
|
|
+ r := (*data)[0]
|
|
|
+ resp.PersonId = common.Int64All(r["personId"])
|
|
|
+ resp.UserAccountId = common.Int64All(r["userAccountId"])
|
|
|
+ resp.UserPositionId = common.Int64All(r["userPositionId"])
|
|
|
+ resp.UserName = common.ObjToString(r["userName"])
|
|
|
+ } else {
|
|
|
+ resp.ErrorCode = -1
|
|
|
+ resp.ErrorMsg = "暂无数据"
|
|
|
+ }
|
|
|
+ //企业账户
|
|
|
+ data2 := entity.BaseMysql.SelectBySql(`select c.id entUserAccountId ,d.id entUserPositionId, e.id entAccountId from base_user a
|
|
|
+ inner join base_person b on a.person_id =b.id
|
|
|
+ inner join base_account c on c.person_id = b.id and c.type=1
|
|
|
+ inner join base_position d on d.account_id = c.id and d.user_id = a.id and d.type=1
|
|
|
+ inner join base_account e on e.type=1 and (e.person_id is null or e.person_id =0)
|
|
|
+ where a.id =? and a.appid =? and c.ent_id =?`, this.BaseUserId, this.AppId, this.EntId)
|
|
|
+ if data2 != nil && len(*data2) > 0 {
|
|
|
+ r := (*data2)[0]
|
|
|
+ resp.EntAccountId = common.Int64All(r["entAccountId"])
|
|
|
+ resp.EntUserAccountId = common.Int64All(r["entUserAccountId"])
|
|
|
+ resp.EntUserPositionId = common.Int64All(r["entUserPositionId"])
|
|
|
+ }
|
|
|
+ return resp
|
|
|
+}
|