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

74 lines
2.4 KiB

package store
import (
"github.com/gin-gonic/gin"
"log"
"recook/internal/back"
"recook/internal/dbc"
"recook/internal/model/store"
"recook/tools"
)
type createStoreParam struct {
Name string `json:"name" validator:"required"` // 门店名称
BusinessLicenseNum string `json:"businessLicenseNum" validator:"required"` // 营业执照号
BusinessLicenseAddress string `json:"businessLicenseAddress" validator:"required"` // 营业执照号详细地址
EffectiveStartTime string `json:"effectiveStartTime" validator:"required"` // 营业执照有效期开始时间
EffectiveEndTime string `json:"effectiveEndTime" validator:"required"` // 营业执照有效期结束时间 长期填写长期
BusinessScope string `json:"businessScope" validator:"required"` // 经营范围
LegalRepresentativeName string `json:"legalRepresentativeName" validator:"required"` // 法人姓名
LegalRepresentativeIdNum string `json:"legalRepresentativeIdNum" validator:"required"` // 法人身份证号码
Mobile string `json:"mobile" validator:"required"`
Password string `json:"password" validator:"required"`
}
func CreateStore(c *gin.Context) {
var p createStoreParam
if err := tools.Params(&p, c); err != nil {
back.Fail(c, err.Error())
log.Print(err)
return
}
var info store.Account
dbc.DB.First(&info, "mobile=?", p.Mobile)
if info.ID > 0 {
back.Fail(c, "该手机号用户已注册过")
return
}
tx := dbc.DB.Begin()
{
storeInfo := store.Information{
Name: p.Name,
BusinessLicenseNum: p.BusinessLicenseNum,
BusinessLicenseAddress: p.BusinessLicenseAddress,
EffectiveStartTime: p.EffectiveStartTime,
EffectiveEndTime: p.EffectiveEndTime,
BusinessScope: p.BusinessScope,
LegalRepresentativeName: p.LegalRepresentativeName,
LegalRepresentativeIdNum: p.LegalRepresentativeIdNum,
}
if err := tx.Create(&storeInfo).Error; err != nil {
tx.Rollback()
back.Err(c, err.Error())
return
}
one := store.Account{
StoreId: storeInfo.ID,
Mobile: p.Mobile,
Password: tools.MD5(p.Password),
Token: "",
Role: 0,
}
if err := tx.Create(&one).Error; err != nil {
tx.Rollback()
back.Err(c, err.Error())
return
}
}
tx.Commit()
back.Suc(c, "", nil)
}