2024-01-30 03:52:56 +00:00
|
|
|
package logic
|
|
|
|
|
2024-01-30 09:39:04 +00:00
|
|
|
import (
|
2024-02-22 07:14:15 +00:00
|
|
|
"errors"
|
2024-01-30 09:39:04 +00:00
|
|
|
"exhibition-register/internal/dao"
|
2024-02-01 10:56:19 +00:00
|
|
|
"exhibition-register/internal/model"
|
2024-01-30 09:39:04 +00:00
|
|
|
"exhibition-register/pb/exhibition"
|
2024-02-01 10:56:19 +00:00
|
|
|
"exhibition-register/pkg/utils"
|
2024-02-20 06:10:29 +00:00
|
|
|
"fmt"
|
2025-03-05 03:38:51 +00:00
|
|
|
"time"
|
2024-01-30 09:39:04 +00:00
|
|
|
)
|
|
|
|
|
2024-01-30 03:52:56 +00:00
|
|
|
type IRegister interface {
|
2024-01-31 01:23:32 +00:00
|
|
|
CheckByPhone(in *exhibition.RegisterInfo) (out *exhibition.CheckPhoneResp, err error)
|
2024-02-23 03:24:24 +00:00
|
|
|
CheckIdCard(in *exhibition.RegisterInfo) (out *exhibition.CheckIdCardResp, err error)
|
2024-02-01 10:56:19 +00:00
|
|
|
SaveRegisterRecord(in *exhibition.RegisterInfo) (out *exhibition.SaveRegisterRecordResp, err error)
|
|
|
|
RegisterRecordList(in *exhibition.RecordListReq) (out *exhibition.RecordListResp, err error)
|
|
|
|
FindAllRecord() (out *exhibition.ExportRecordResp, err error)
|
2024-01-30 09:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewRegister() IRegister {
|
|
|
|
return &Register{}
|
2024-01-30 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Register struct {
|
|
|
|
}
|
2024-01-30 09:39:04 +00:00
|
|
|
|
2024-02-23 03:24:24 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-02-01 10:56:19 +00:00
|
|
|
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 {
|
2024-02-20 06:42:53 +00:00
|
|
|
var address string
|
|
|
|
address = fmt.Sprintf("%s%s", record.Address, record.Address1)
|
2024-02-01 10:56:19 +00:00
|
|
|
tmp := &exhibition.ExportInfo{
|
2024-02-18 03:10:07 +00:00
|
|
|
ArtistName: record.ArtistName,
|
|
|
|
Gender: record.Gender,
|
|
|
|
PhoneNum: record.PhoneNum,
|
|
|
|
IdCard: record.IdCard,
|
2024-02-20 06:10:29 +00:00
|
|
|
Address: address,
|
2024-02-18 03:10:07 +00:00
|
|
|
IdCardPhoto: record.IdCardPhoto,
|
|
|
|
IdCardBackPhoto: record.IdCardBackPhoto,
|
|
|
|
ArtistPhoto: record.ArtistPhoto,
|
2025-03-04 05:28:43 +00:00
|
|
|
ArtworkName: record.ArtworkName,
|
2025-03-05 03:38:51 +00:00
|
|
|
CreatedAt: time.Unix(int64(record.CreatedAt), 0).Format("2006-01-02 15:04:05"),
|
|
|
|
UpdatedAt: time.Unix(int64(record.UpdatedAt), 0).Format("2006-01-02 15:04:05"),
|
2024-02-01 10:56:19 +00:00
|
|
|
}
|
|
|
|
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{
|
2024-02-18 03:10:07 +00:00
|
|
|
Id: int32(item.ID),
|
|
|
|
Uuid: item.UUID,
|
|
|
|
ArtistName: item.ArtistName,
|
|
|
|
Gender: item.Gender,
|
|
|
|
PhoneNum: item.PhoneNum,
|
|
|
|
IdCard: item.IdCard,
|
|
|
|
Address: item.Address,
|
2024-02-20 06:10:29 +00:00
|
|
|
Address1: item.Address1,
|
2024-02-18 03:10:07 +00:00
|
|
|
IdCardPhoto: item.IdCardPhoto,
|
|
|
|
IdCardBackPhoto: item.IdCardBackPhoto,
|
|
|
|
ArtistPhoto: item.ArtistPhoto,
|
2024-09-10 01:48:15 +00:00
|
|
|
ArtworkFile: item.ArtworkFile,
|
2025-03-04 05:28:43 +00:00
|
|
|
ArtworkName: item.ArtworkName,
|
2025-03-05 03:38:51 +00:00
|
|
|
CreatedAt: time.Unix(int64(item.CreatedAt), 0).Format("2006-01-02 15:04:05"),
|
|
|
|
UpdatedAt: time.Unix(int64(item.UpdatedAt), 0).Format("2006-01-02 15:04:05"),
|
2024-02-01 10:56:19 +00:00
|
|
|
}
|
|
|
|
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{
|
2024-02-18 03:10:07 +00:00
|
|
|
ArtistName: in.ArtistName,
|
|
|
|
Gender: in.Gender,
|
|
|
|
PhoneNum: in.PhoneNum,
|
|
|
|
IdCard: in.IdCard,
|
|
|
|
Address: in.Address,
|
2024-02-20 06:10:29 +00:00
|
|
|
Address1: in.Address1,
|
2024-02-18 03:10:07 +00:00
|
|
|
IdCardPhoto: in.IdCardPhoto,
|
|
|
|
IdCardBackPhoto: in.IdCardBackPhoto,
|
|
|
|
ArtistPhoto: in.ArtistPhoto,
|
2024-09-10 01:48:15 +00:00
|
|
|
ArtworkFile: in.ArtworkFile,
|
2025-03-04 05:28:43 +00:00
|
|
|
ArtworkName: in.ArtworkName,
|
2024-02-01 10:56:19 +00:00
|
|
|
}
|
|
|
|
|
2024-02-02 09:05:34 +00:00
|
|
|
tmpRecord := &model.RegisterRecord{}
|
2024-02-01 10:56:19 +00:00
|
|
|
if in.Uuid != "" {
|
2024-02-22 07:14:15 +00:00
|
|
|
check, err := dao.CheckBy("phone_num", record.PhoneNum, in.Uuid)
|
2024-02-02 09:05:34 +00:00
|
|
|
if err != nil {
|
2024-02-01 10:56:19 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2024-02-22 07:14:15 +00:00
|
|
|
if check != nil {
|
|
|
|
return nil, errors.New("该手机号已经被注册!")
|
|
|
|
}
|
|
|
|
record.UUID = in.Uuid
|
|
|
|
registerRecord, err1 := dao.UpdateRegisterRecord(record)
|
|
|
|
if err1 != nil {
|
|
|
|
return nil, err1
|
|
|
|
}
|
2024-02-02 09:05:34 +00:00
|
|
|
tmpRecord = registerRecord
|
2024-02-01 10:56:19 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
record.UUID = utils.GetUUID()
|
2024-02-02 09:05:34 +00:00
|
|
|
registerRecord, err := dao.CreateRegisterRecord(record)
|
|
|
|
if err != nil {
|
2024-02-01 10:56:19 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2024-02-02 09:05:34 +00:00
|
|
|
tmpRecord = registerRecord
|
2024-02-01 10:56:19 +00:00
|
|
|
}
|
|
|
|
|
2024-02-02 09:05:34 +00:00
|
|
|
data := &exhibition.RegisterInfo{
|
2024-02-18 03:10:07 +00:00
|
|
|
Id: int32(tmpRecord.ID),
|
|
|
|
Uuid: tmpRecord.UUID,
|
|
|
|
ArtistName: tmpRecord.ArtistName,
|
|
|
|
Gender: tmpRecord.Gender,
|
|
|
|
PhoneNum: tmpRecord.PhoneNum,
|
|
|
|
IdCard: tmpRecord.IdCard,
|
|
|
|
Address: tmpRecord.Address,
|
2024-02-20 06:10:29 +00:00
|
|
|
Address1: tmpRecord.Address1,
|
2024-02-18 03:10:07 +00:00
|
|
|
IdCardPhoto: tmpRecord.IdCardPhoto,
|
|
|
|
IdCardBackPhoto: tmpRecord.IdCardBackPhoto,
|
|
|
|
ArtistPhoto: tmpRecord.ArtistPhoto,
|
2024-09-10 01:48:15 +00:00
|
|
|
ArtworkFile: tmpRecord.ArtworkFile,
|
2025-03-04 05:28:43 +00:00
|
|
|
ArtworkName: tmpRecord.ArtworkName,
|
2025-03-05 03:38:51 +00:00
|
|
|
CreatedAt: time.Unix(int64(tmpRecord.CreatedAt), 0).Format("2006-01-02 15:04:05"),
|
|
|
|
UpdatedAt: time.Unix(int64(tmpRecord.UpdatedAt), 0).Format("2006-01-02 15:04:05"),
|
2024-02-02 09:05:34 +00:00
|
|
|
}
|
|
|
|
out.Data = data
|
2024-02-01 10:56:19 +00:00
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CheckByPhone 通过手机号检索 存在的就返回数据
|
2024-01-31 01:23:32 +00:00
|
|
|
func (r *Register) CheckByPhone(in *exhibition.RegisterInfo) (out *exhibition.CheckPhoneResp, err error) {
|
2024-01-30 09:39:04 +00:00
|
|
|
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{
|
2024-02-18 03:10:07 +00:00
|
|
|
Id: int32(record.ID),
|
|
|
|
Uuid: record.UUID,
|
|
|
|
ArtistName: record.ArtistName,
|
|
|
|
Gender: record.Gender,
|
|
|
|
PhoneNum: record.PhoneNum,
|
|
|
|
IdCard: record.IdCard,
|
|
|
|
Address: record.Address,
|
2024-02-20 06:10:29 +00:00
|
|
|
Address1: record.Address1,
|
2024-02-18 03:10:07 +00:00
|
|
|
IdCardPhoto: record.IdCardPhoto,
|
|
|
|
IdCardBackPhoto: record.IdCardBackPhoto,
|
|
|
|
ArtistPhoto: record.ArtistPhoto,
|
2024-09-10 01:48:15 +00:00
|
|
|
ArtworkFile: record.ArtworkFile,
|
2025-03-04 07:06:05 +00:00
|
|
|
ArtworkName: record.ArtworkName,
|
2025-03-05 03:38:51 +00:00
|
|
|
CreatedAt: time.Unix(int64(record.CreatedAt), 0).Format("2006-01-02 15:04:05"),
|
|
|
|
UpdatedAt: time.Unix(int64(record.UpdatedAt), 0).Format("2006-01-02 15:04:05"),
|
2024-01-30 09:39:04 +00:00
|
|
|
}
|
|
|
|
out.Data = data
|
|
|
|
out.IsExist = true
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|