You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
5.5 KiB
Go

8 months ago
package logic
8 months ago
import (
7 months ago
"errors"
8 months ago
"exhibition-register/internal/dao"
8 months ago
"exhibition-register/internal/model"
8 months ago
"exhibition-register/pb/exhibition"
8 months ago
"exhibition-register/pkg/utils"
7 months ago
"fmt"
8 months ago
)
8 months ago
type IRegister interface {
8 months ago
CheckByPhone(in *exhibition.RegisterInfo) (out *exhibition.CheckPhoneResp, err error)
7 months ago
CheckIdCard(in *exhibition.RegisterInfo) (out *exhibition.CheckIdCardResp, err error)
8 months ago
SaveRegisterRecord(in *exhibition.RegisterInfo) (out *exhibition.SaveRegisterRecordResp, err error)
RegisterRecordList(in *exhibition.RecordListReq) (out *exhibition.RecordListResp, err error)
FindAllRecord() (out *exhibition.ExportRecordResp, err error)
8 months ago
}
func NewRegister() IRegister {
return &Register{}
8 months ago
}
type Register struct {
}
8 months ago
7 months ago
func (r *Register) CheckIdCard(in *exhibition.RegisterInfo) (out *exhibition.CheckIdCardResp, err error) {
out = &exhibition.CheckIdCardResp{}
check, err1 := dao.CheckBy("id_card", in.IdCard, "")
if err1 != nil {
return nil, err1
}
if check != nil {
return nil, errors.New("该身份证号已被" + check.PhoneNum + "注册!")
}
return out, nil
}
8 months ago
func (r *Register) FindAllRecord() (out *exhibition.ExportRecordResp, err error) {
out = &exhibition.ExportRecordResp{}
allRecord, err := dao.AllRecord()
if err != nil {
return nil, err
}
if len(allRecord) > 0 {
for _, record := range allRecord {
7 months ago
var address string
address = fmt.Sprintf("%s%s", record.Address, record.Address1)
8 months ago
tmp := &exhibition.ExportInfo{
7 months ago
ArtistName: record.ArtistName,
Gender: record.Gender,
PhoneNum: record.PhoneNum,
IdCard: record.IdCard,
7 months ago
Address: address,
7 months ago
IdCardPhoto: record.IdCardPhoto,
IdCardBackPhoto: record.IdCardBackPhoto,
ArtistPhoto: record.ArtistPhoto,
CreatedAt: record.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: record.UpdatedAt.Format("2006-01-02 15:04:05"),
8 months ago
}
out.Data = append(out.Data, tmp)
}
}
return
}
func (r *Register) RegisterRecordList(in *exhibition.RecordListReq) (out *exhibition.RecordListResp, err error) {
out = &exhibition.RecordListResp{}
recordList, total, err := dao.RecordList(in)
if err != nil {
return nil, err
}
if total > 0 {
for _, item := range recordList {
tmp := &exhibition.RegisterInfo{
7 months ago
Id: int32(item.ID),
Uuid: item.UUID,
ArtistName: item.ArtistName,
Gender: item.Gender,
PhoneNum: item.PhoneNum,
IdCard: item.IdCard,
Address: item.Address,
7 months ago
Address1: item.Address1,
7 months ago
IdCardPhoto: item.IdCardPhoto,
IdCardBackPhoto: item.IdCardBackPhoto,
ArtistPhoto: item.ArtistPhoto,
CreatedAt: item.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: item.UpdatedAt.Format("2006-01-02 15:04:05"),
8 months ago
}
out.Data = append(out.Data, tmp)
}
out.Count = int32(total)
}
return out, err
}
func (r *Register) SaveRegisterRecord(in *exhibition.RegisterInfo) (out *exhibition.SaveRegisterRecordResp, err error) {
out = &exhibition.SaveRegisterRecordResp{}
record := &model.RegisterRecord{
7 months ago
ArtistName: in.ArtistName,
Gender: in.Gender,
PhoneNum: in.PhoneNum,
IdCard: in.IdCard,
Address: in.Address,
7 months ago
Address1: in.Address1,
7 months ago
IdCardPhoto: in.IdCardPhoto,
IdCardBackPhoto: in.IdCardBackPhoto,
ArtistPhoto: in.ArtistPhoto,
8 months ago
}
8 months ago
tmpRecord := &model.RegisterRecord{}
8 months ago
if in.Uuid != "" {
7 months ago
check, err := dao.CheckBy("phone_num", record.PhoneNum, in.Uuid)
8 months ago
if err != nil {
8 months ago
return nil, err
}
7 months ago
if check != nil {
return nil, errors.New("该手机号已经被注册!")
}
record.UUID = in.Uuid
registerRecord, err1 := dao.UpdateRegisterRecord(record)
if err1 != nil {
return nil, err1
}
8 months ago
tmpRecord = registerRecord
8 months ago
} else {
record.UUID = utils.GetUUID()
8 months ago
registerRecord, err := dao.CreateRegisterRecord(record)
if err != nil {
8 months ago
return nil, err
}
8 months ago
tmpRecord = registerRecord
8 months ago
}
8 months ago
data := &exhibition.RegisterInfo{
7 months ago
Id: int32(tmpRecord.ID),
Uuid: tmpRecord.UUID,
ArtistName: tmpRecord.ArtistName,
Gender: tmpRecord.Gender,
PhoneNum: tmpRecord.PhoneNum,
IdCard: tmpRecord.IdCard,
Address: tmpRecord.Address,
7 months ago
Address1: tmpRecord.Address1,
7 months ago
IdCardPhoto: tmpRecord.IdCardPhoto,
IdCardBackPhoto: tmpRecord.IdCardBackPhoto,
ArtistPhoto: tmpRecord.ArtistPhoto,
CreatedAt: tmpRecord.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: tmpRecord.UpdatedAt.Format("2006-01-02 15:04:05"),
8 months ago
}
out.Data = data
8 months ago
return out, nil
}
// CheckByPhone 通过手机号检索 存在的就返回数据
8 months ago
func (r *Register) CheckByPhone(in *exhibition.RegisterInfo) (out *exhibition.CheckPhoneResp, err error) {
8 months ago
out = &exhibition.CheckPhoneResp{}
record, err := dao.CheckByPhone(in.PhoneNum)
if err != nil {
return nil, err
}
if record == nil {
out.IsExist = false
return out, nil
}
data := &exhibition.RegisterInfo{
7 months ago
Id: int32(record.ID),
Uuid: record.UUID,
ArtistName: record.ArtistName,
Gender: record.Gender,
PhoneNum: record.PhoneNum,
IdCard: record.IdCard,
Address: record.Address,
7 months ago
Address1: record.Address1,
7 months ago
IdCardPhoto: record.IdCardPhoto,
IdCardBackPhoto: record.IdCardBackPhoto,
ArtistPhoto: record.ArtistPhoto,
CreatedAt: record.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: record.UpdatedAt.Format("2006-01-02 15:04:05"),
8 months ago
}
out.Data = data
out.IsExist = true
return out, nil
}