|
@@ -2,9 +2,7 @@ package system
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"fmt"
|
|
"fmt"
|
|
|
- "log"
|
|
|
|
|
"time"
|
|
"time"
|
|
|
- "xorm.io/core"
|
|
|
|
|
"xorm.io/xorm"
|
|
"xorm.io/xorm"
|
|
|
"xps/datamodels"
|
|
"xps/datamodels"
|
|
|
"xps/viewmodels"
|
|
"xps/viewmodels"
|
|
@@ -20,9 +18,7 @@ func NewAccountRepo(engine *xorm.Engine) *AccountRepo {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (d *AccountRepo) GetAccountByName(accountName string) *viewmodels.AccountInfo {
|
|
|
|
|
- data := &viewmodels.AccountInfo{}
|
|
|
|
|
-
|
|
|
|
|
|
|
+func (d *AccountRepo) GetAccountByName(accountName string)(*viewmodels.AccountInfo, error) {
|
|
|
sqlSelect := ` SELECT A.oc_id,
|
|
sqlSelect := ` SELECT A.oc_id,
|
|
|
B.oc_type_id,
|
|
B.oc_type_id,
|
|
|
B.oc_name,
|
|
B.oc_name,
|
|
@@ -42,27 +38,24 @@ func (d *AccountRepo) GetAccountByName(accountName string) *viewmodels.AccountIn
|
|
|
A.account_intro,
|
|
A.account_intro,
|
|
|
A.wx_id,
|
|
A.wx_id,
|
|
|
A.is_fixed `
|
|
A.is_fixed `
|
|
|
- sqlFrom := ` FROM account AS A
|
|
|
|
|
- LEFT JOIN oc AS B ON (A.oc_id = B.oc_id )
|
|
|
|
|
- `
|
|
|
|
|
- sqlWhere := `WHERE A.deleted_flag = 0 `
|
|
|
|
|
|
|
+ sqlFrom := ` FROM account AS A
|
|
|
|
|
+ LEFT JOIN oc AS B ON (A.oc_id = B.oc_id ) `
|
|
|
|
|
+ sqlWhere := ` WHERE A.deleted_flag = 0 `
|
|
|
|
|
|
|
|
if accountName != "" {
|
|
if accountName != "" {
|
|
|
- sqlWhere += ` AND A.account_name like ` + "'%" + accountName + "%'"
|
|
|
|
|
|
|
+ sqlWhere += ` AND A.account_name like ` + "'%" + accountName + "%'"
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //err2 := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).OrderBy("role_id DESC").Limit(pageSize, pageStart).Find(&datalist)
|
|
|
|
|
|
|
+ data := &viewmodels.AccountInfo{}
|
|
|
ok, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Get(data)
|
|
ok, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Get(data)
|
|
|
-
|
|
|
|
|
if !ok && err != nil {
|
|
if !ok && err != nil {
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
} else {
|
|
} else {
|
|
|
- return data
|
|
|
|
|
|
|
+ return data, nil
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (d *AccountRepo) GetAccountByCode(code string) (*viewmodels.AccountInfo, error) {
|
|
func (d *AccountRepo) GetAccountByCode(code string) (*viewmodels.AccountInfo, error) {
|
|
|
- data := &viewmodels.AccountInfo{}
|
|
|
|
|
sqlSelect := ` SELECT A.oc_id,
|
|
sqlSelect := ` SELECT A.oc_id,
|
|
|
B.oc_type_id,
|
|
B.oc_type_id,
|
|
|
B.oc_name,
|
|
B.oc_name,
|
|
@@ -82,14 +75,15 @@ func (d *AccountRepo) GetAccountByCode(code string) (*viewmodels.AccountInfo, er
|
|
|
A.account_intro,
|
|
A.account_intro,
|
|
|
A.wx_id,
|
|
A.wx_id,
|
|
|
A.is_fixed `
|
|
A.is_fixed `
|
|
|
- sqlFrom := ` FROM account AS A
|
|
|
|
|
|
|
+ sqlFrom := ` FROM account AS A
|
|
|
LEFT JOIN oc AS B ON (A.oc_id = B.oc_id ) `
|
|
LEFT JOIN oc AS B ON (A.oc_id = B.oc_id ) `
|
|
|
sqlWhere := ` WHERE A.deleted_flag = 0 `
|
|
sqlWhere := ` WHERE A.deleted_flag = 0 `
|
|
|
sqlWhere += ` AND (A.account_name = ` + "'" + code + "'"
|
|
sqlWhere += ` AND (A.account_name = ` + "'" + code + "'"
|
|
|
sqlWhere += ` OR A.account_phone = ` + "'" + code + "'"
|
|
sqlWhere += ` OR A.account_phone = ` + "'" + code + "'"
|
|
|
sqlWhere += ` OR A.account_mail = ` + "'" + code + "'"
|
|
sqlWhere += ` OR A.account_mail = ` + "'" + code + "'"
|
|
|
sqlWhere += ` OR A.account_staff_no = ` + "'" + code + "')"
|
|
sqlWhere += ` OR A.account_staff_no = ` + "'" + code + "')"
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ data := &viewmodels.AccountInfo{}
|
|
|
ok, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Get(data)
|
|
ok, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Get(data)
|
|
|
if !ok && err != nil {
|
|
if !ok && err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
@@ -97,9 +91,7 @@ func (d *AccountRepo) GetAccountByCode(code string) (*viewmodels.AccountInfo, er
|
|
|
return data, nil
|
|
return data, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (d *AccountRepo) GetById(ocId int64, accountId int64) *viewmodels.AccountInfo {
|
|
|
|
|
- var user = &viewmodels.AccountInfo{}
|
|
|
|
|
-
|
|
|
|
|
|
|
+func (d *AccountRepo) GetById(ocId int64, accountId int64)(*viewmodels.AccountInfo, error){
|
|
|
sqlSelect := ` SELECT A.oc_id,
|
|
sqlSelect := ` SELECT A.oc_id,
|
|
|
B.oc_type_id,
|
|
B.oc_type_id,
|
|
|
B.oc_name,
|
|
B.oc_name,
|
|
@@ -123,20 +115,17 @@ func (d *AccountRepo) GetById(ocId int64, accountId int64) *viewmodels.AccountIn
|
|
|
LEFT JOIN oc AS B ON (A.oc_id = B.oc_id ) `
|
|
LEFT JOIN oc AS B ON (A.oc_id = B.oc_id ) `
|
|
|
sqlWhere := ` WHERE A.deleted_flag = 0 AND A.oc_id = ` + fmt.Sprintf("%d", ocId)
|
|
sqlWhere := ` WHERE A.deleted_flag = 0 AND A.oc_id = ` + fmt.Sprintf("%d", ocId)
|
|
|
sqlWhere += ` AND A.account_id = ` + fmt.Sprintf("%d", accountId)
|
|
sqlWhere += ` AND A.account_id = ` + fmt.Sprintf("%d", accountId)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ user := &viewmodels.AccountInfo{}
|
|
|
has, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Get(user)
|
|
has, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Get(user)
|
|
|
-
|
|
|
|
|
if !has || err != nil {
|
|
if !has || err != nil {
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
} else {
|
|
} else {
|
|
|
- return user
|
|
|
|
|
|
|
+ return user, nil
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (d *AccountRepo) GetList(ocId int64) ([]viewmodels.AccountInfo, error) {
|
|
func (d *AccountRepo) GetList(ocId int64) ([]viewmodels.AccountInfo, error) {
|
|
|
- datalist := make([]viewmodels.AccountInfo, 0)
|
|
|
|
|
-
|
|
|
|
|
sqlSelect := ` SELECT A.oc_id,
|
|
sqlSelect := ` SELECT A.oc_id,
|
|
|
B.oc_type_id,
|
|
B.oc_type_id,
|
|
|
B.oc_name,
|
|
B.oc_name,
|
|
@@ -156,16 +145,17 @@ func (d *AccountRepo) GetList(ocId int64) ([]viewmodels.AccountInfo, error) {
|
|
|
A.account_intro,
|
|
A.account_intro,
|
|
|
A.wx_id,
|
|
A.wx_id,
|
|
|
A.is_fixed `
|
|
A.is_fixed `
|
|
|
- sqlFrom := ` FROM account AS A
|
|
|
|
|
|
|
+ sqlFrom := ` FROM account AS A
|
|
|
LEFT JOIN oc AS B ON (A.oc_id = B.oc_id ) `
|
|
LEFT JOIN oc AS B ON (A.oc_id = B.oc_id ) `
|
|
|
sqlWhere := ` WHERE A.deleted_flag = 0 `
|
|
sqlWhere := ` WHERE A.deleted_flag = 0 `
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ datalist := make([]viewmodels.AccountInfo, 0)
|
|
|
err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Asc("account_id").Find(&datalist)
|
|
err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Asc("account_id").Find(&datalist)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return datalist, nil
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- return datalist, nil
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (d *AccountRepo) Create(data *datamodels.Account) error {
|
|
func (d *AccountRepo) Create(data *datamodels.Account) error {
|
|
@@ -174,7 +164,10 @@ func (d *AccountRepo) Create(data *datamodels.Account) error {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (d *AccountRepo) Update(ocId, accountId int64, data *datamodels.Account) error {
|
|
func (d *AccountRepo) Update(ocId, accountId int64, data *datamodels.Account) error {
|
|
|
- _, err := d.engine.ID(core.PK{ocId, accountId}).Update(data)
|
|
|
|
|
|
|
+ _, err := d.engine.
|
|
|
|
|
+ Where("oc_id = ?", ocId).
|
|
|
|
|
+ Where("account_id = ?", accountId).
|
|
|
|
|
+ Update(data)
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -189,24 +182,54 @@ func (d *AccountRepo) Delete(m map[string]interface{}) error {
|
|
|
DeletedBy: deletedBy,
|
|
DeletedBy: deletedBy,
|
|
|
DeletedAt: time.Now(),
|
|
DeletedAt: time.Now(),
|
|
|
}
|
|
}
|
|
|
- _, err := d.engine.ID(core.PK{ocId, accountId}).Update(data)
|
|
|
|
|
|
|
+ _, err := d.engine.
|
|
|
|
|
+ Where("oc_id = ?", ocId).
|
|
|
|
|
+ Where("account_id = ?", accountId).
|
|
|
|
|
+ Update(data)
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (d *AccountRepo) IsUserNameExist(ocId int64, accountName string) bool {
|
|
|
|
|
- count, err := d.engine.Where("deleted_flag = 0").Where("account_name = ?", accountName).Count(new(datamodels.Account))
|
|
|
|
|
|
|
+func (d *AccountRepo) IsUserNameExist(ocId int64, accountName string) (bool, error) {
|
|
|
|
|
+ count, err := d.engine.
|
|
|
|
|
+ Where("deleted_flag = 0").
|
|
|
|
|
+ Where("account_name = ?", accountName).
|
|
|
|
|
+ Count(new(datamodels.Account))
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- log.Fatal(err)
|
|
|
|
|
- return true
|
|
|
|
|
|
|
+ return false, err
|
|
|
}
|
|
}
|
|
|
- return count > 0
|
|
|
|
|
|
|
+ return count > 0, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (d *AccountRepo) IsUserPhoneExist(ocId int64, accountPhone string) bool {
|
|
|
|
|
- count, err := d.engine.Where("deleted_flag = 0").Where("account_phone = ?", accountPhone).Count(new(datamodels.Account))
|
|
|
|
|
|
|
+func (d *AccountRepo) IsUserPhoneExist(ocId int64, accountPhone string)(bool, error){
|
|
|
|
|
+ count, err := d.engine.
|
|
|
|
|
+ Where("deleted_flag = 0").
|
|
|
|
|
+ Where("account_phone = ?", accountPhone).
|
|
|
|
|
+ Count(new(datamodels.Account))
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- log.Fatal(err)
|
|
|
|
|
- return true
|
|
|
|
|
|
|
+ return true, err
|
|
|
}
|
|
}
|
|
|
- return count > 0
|
|
|
|
|
|
|
+ return count > 0, nil
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+func (d *AccountRepo) IsStaffNoExist(ocId int64, staffNo string)(bool, error){
|
|
|
|
|
+ count, err := d.engine.
|
|
|
|
|
+ Where("deleted_flag = 0").
|
|
|
|
|
+ Where("account_staff_no = ?", staffNo).
|
|
|
|
|
+ Count(new(datamodels.Account))
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return true, err
|
|
|
|
|
+ }
|
|
|
|
|
+ return count > 0, nil
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (d *AccountRepo) IsEmailExist(ocId int64, email string)(bool, error) {
|
|
|
|
|
+ count, err := d.engine.
|
|
|
|
|
+ Where("deleted_flag = 0").
|
|
|
|
|
+ Where("account_email = ?", email).
|
|
|
|
|
+ Count(new(datamodels.Account))
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return true, err
|
|
|
|
|
+ }
|
|
|
|
|
+ return count > 0, nil
|
|
|
|
|
+}
|