소스 검색

feat:运营商数据定制与分析

wangchuanjin 1 년 전
부모
커밋
ffa2126d49
1개의 변경된 파일9개의 추가작업 그리고 15개의 파일을 삭제
  1. 9 15
      service/service.go

+ 9 - 15
service/service.go

@@ -56,25 +56,19 @@ func AddUsePerson(this *entmanageapplication.AddUsePersonReq) *entmanageapplicat
 				}
 				//
 				entUserId, _ := strconv.Atoi(v)
-				data := JyMysql.FindOne(EntnichePower, map[string]interface{}{"ent_user_id": entUserId}, "", "")
-				if common.ObjToString((*sourceData)["product_type"]) != YYSSJDZYFX && data != nil && len(*data) > 0 {
-					dataStatus := common.IntAll((*data)["status"])
-					wait_empower_id := common.Int64All((*data)["wait_empower_id"])
-					if dataStatus == -1 {
-						ok = JyMysql.Update(EntnichePower, map[string]interface{}{"ent_user_id": entUserId}, map[string]interface{}{"wait_empower_id": this.WaitEmpowerId, "status": 1, "update_time": timeStr})
-					} else {
-						resdata := JyMysql.FindOne(EntnicheWaitEmpower, map[string]interface{}{"id": wait_empower_id}, "", "")
-						end_time := common.ObjToString((*resdata)["end_time"])
+				if common.ObjToString((*sourceData)["product_type"]) != YYSSJDZYFX {
+					datas := JyMysql.SelectBySql(`select a.end_time from `+EntnicheWaitEmpower+` a inner join `+EntnichePower+` b on (a.product_type<>? and b.ent_user_id=? and b.status=1 and a.id=b.wait_empower_id)`, YYSSJDZYFX, entUserId)
+					if datas != nil && len(*datas) > 0 {
+						end_time := common.ObjToString((*datas)[0]["end_time"])
 						res, _ := time.ParseInLocation("2006-01-02 15:04:05", end_time, time.Local)
-						if res.Unix() > time.Now().Unix() && common.ObjToString((*resdata)["product_type"]) != YYSSJDZYFX {
+						if res.Unix() > time.Now().Unix() {
 							msg = "人员已经拥有权限,请先删除原有权限"
 							code = int64(-1)
 							break
-						} else {
-							ok = JyMysql.Update(EntnichePower, map[string]interface{}{"ent_user_id": entUserId}, map[string]interface{}{"wait_empower_id": this.WaitEmpowerId, "status": 1, "update_time": timeStr})
 						}
 					}
-				} else {
+				}
+				if JyMysql.CountBySql(`select count(1) as count from `+EntnichePower+` where wait_empower_id=? and ent_id=? and ent_user_id=? and status=?`, this.WaitEmpowerId, this.EntId, entUserId, 1) == 0 {
 					id = JyMysql.Insert(EntnichePower, map[string]interface{}{
 						"wait_empower_id": this.WaitEmpowerId,
 						"ent_id":          this.EntId,
@@ -83,9 +77,9 @@ func AddUsePerson(this *entmanageapplication.AddUsePersonReq) *entmanageapplicat
 						"create_time":     timeStr,
 						"update_time":     timeStr,
 					})
+					JyMysql.UpdateOrDeleteBySql(`update `+EntnicheWaitEmpower+` set use_count = use_count + 1 where id = ?`, this.WaitEmpowerId)
+					addPower(this.WaitEmpowerId, entUserId, this.EntId)
 				}
-				JyMysql.UpdateOrDeleteBySql(`update `+EntnicheWaitEmpower+` set use_count = use_count + 1 where id = ?`, this.WaitEmpowerId)
-				addPower(this.WaitEmpowerId, entUserId, this.EntId)
 			}
 		}
 	}