...
|
...
|
@@ -21,6 +21,7 @@ func (repository *PushDeviceRepository) Save(device *domain.UpdateDeviceRequest) |
|
|
DeviceToken: strings.TrimSpace(device.DeviceToken),
|
|
|
CreateAt: time.Now(),
|
|
|
UpdateAt: time.Now(),
|
|
|
ProjectMasterKey: device.ProjectKey,
|
|
|
}
|
|
|
_, err := o.Insert(m)
|
|
|
return err
|
...
|
...
|
@@ -29,7 +30,9 @@ func (repository *PushDeviceRepository) Save(device *domain.UpdateDeviceRequest) |
|
|
func (repository *PushDeviceRepository) FindOne(queryOptions map[string]interface{}) (*domain.Device, error) {
|
|
|
o := orm.NewOrm()
|
|
|
model := new(models.PushDeviceInfo)
|
|
|
qs := o.QueryTable(model.TableName()).Filter("uid", queryOptions["uid"])
|
|
|
qs := o.QueryTable(model.TableName()).
|
|
|
Filter("uid", queryOptions["uid"]).
|
|
|
Filter("project_master_key", queryOptions["project_master_key"])
|
|
|
err := qs.One(model)
|
|
|
if err != nil {
|
|
|
if err == orm.ErrNoRows {
|
...
|
...
|
@@ -44,7 +47,7 @@ func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{} |
|
|
o := orm.NewOrm()
|
|
|
model := new(models.PushDeviceInfo)
|
|
|
var ms []*models.PushDeviceInfo
|
|
|
qs := o.QueryTable(model.TableName()).Filter("uid__in", queryOptions["receivers"]).Filter("is_active", 1)
|
|
|
qs := o.QueryTable(model.TableName()).Filter("uid__in", queryOptions["receivers"]).Filter("is_active", 1).Filter("project_master_key", queryOptions["project_master_key"])
|
|
|
qs.All(&ms)
|
|
|
if len(ms) == 0 {
|
|
|
return
|
...
|
...
|
@@ -56,17 +59,17 @@ func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{} |
|
|
return
|
|
|
}
|
|
|
|
|
|
func (repository *PushDeviceRepository) UpdateDevice(uid int64, clientId, deviceToken string) error {
|
|
|
func (repository *PushDeviceRepository) UpdateDevice(uid int64, clientId, deviceToken string, projectKey string) error {
|
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
//更新其他绑定这个client_id的设备 is_active=0
|
|
|
_, err := o.Raw("UPDATE push_device_info SET update_at=now(),is_active=0 where client_id=? and is_active=1", clientId).Exec()
|
|
|
_, err := o.Raw("UPDATE push_device_info SET update_at=now(),is_active=0 where client_id=? and is_active=1 and project_master_key=?", clientId, projectKey).Exec()
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
_, err = o.Raw("UPDATE push_device_info SET client_id=?,device_token = ?,update_at=now(),is_active=1 where uid=?", clientId, deviceToken, uid).Exec()
|
|
|
_, err = o.Raw("UPDATE push_device_info SET client_id=?,device_token = ?,update_at=now(),is_active=1 where uid=? and project_master_key=?", clientId, deviceToken, uid, projectKey).Exec()
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
return err
|
...
|
...
|
|