feat:完善项目信息
This commit is contained in:
@ -3,33 +3,13 @@ package api
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/controller/user"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/session"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type User struct{}
|
||||
|
||||
type (
|
||||
// userSettledForm 入驻平台参数
|
||||
userSettledForm struct {
|
||||
api.ImageForm
|
||||
Name string `json:"name" form:"name"`
|
||||
Code string `json:"code" form:"code"`
|
||||
config.Area
|
||||
Introduce string `json:"introduce" form:"introduce"`
|
||||
Industrys []string `json:"industrys" form:"industrys"` // 行业领域
|
||||
Keywords []string `json:"keywords" form:"keywords"`
|
||||
}
|
||||
// userBankForm 银行平台信息参数
|
||||
userBankForm struct {
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
IDCard string `json:"id_card" form:"id_card" binding:"required"`
|
||||
BackCard string `json:"back_card" form:"back_card" binding:"required"`
|
||||
BackName string `json:"back_name" form:"back_name" binding:"required"`
|
||||
Captcha string `json:"captcha" form:"captcha" binding:"required"`
|
||||
}
|
||||
)
|
||||
type ()
|
||||
|
||||
func (*User) Info(c *gin.Context) {
|
||||
data := user.NewInstance()(api.GetSession()(c).(*session.Enterprise)).Info()
|
||||
@ -73,12 +53,17 @@ func (*User) IdentitySwitch(c *gin.Context) {
|
||||
|
||||
func (*User) Back(c *gin.Context) {
|
||||
data, err := user.NewBank()(api.GetSession()(c).(*session.Enterprise)).List()
|
||||
api.APIResponse(err, data)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*User) BackBind(c *gin.Context) {
|
||||
form := new(userBankForm)
|
||||
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
IDCard string `json:"id_card" form:"id_card" binding:"required"`
|
||||
BackCard string `json:"back_card" form:"back_card" binding:"required"`
|
||||
BackName string `json:"back_name" form:"back_name" binding:"required"`
|
||||
Captcha string `json:"captcha" form:"captcha" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
@ -86,7 +71,7 @@ func (*User) BackBind(c *gin.Context) {
|
||||
err := user.NewBank()(api.GetSession()(c).(*session.Enterprise)).Bind(&user.BankParams{
|
||||
Name: form.Name, IDCard: form.IDCard, BankCard: form.BackCard, BankName: form.BackName,
|
||||
}, form.Captcha)
|
||||
api.APIResponse(err)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*User) BackUnbind(c *gin.Context) {
|
||||
@ -97,16 +82,52 @@ func (*User) BackUnbind(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err := user.NewBank()(api.GetSession()(c).(*session.Enterprise)).Unbind(form.Convert())
|
||||
api.APIResponse(err)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*User) Patent(c *gin.Context) {
|
||||
func (*User) Bill(c *gin.Context) {
|
||||
form := &struct {
|
||||
Title string `json:"title" form:"title"`
|
||||
OrderNo string `json:"order_no" form:"order_no"`
|
||||
CreatedAt string `json:"created_at" form:"created_at"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := user.NewBill()(api.GetSession()(c).(*session.Enterprise)).Instance(form.OrderNo, form.CreatedAt,
|
||||
form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*User) BillTicket(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := user.NewBill()(api.GetSession()(c).(*session.Enterprise)).Ticket(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*User) BillTicketIssue(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
Kind int `json:"kind" form:"kind" binding:"required"`
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
DutyParagraph string `json:"duty_paragraph" form:"duty_paragraph" binding:"required"`
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||||
Email string `json:"email" form:"email" binding:"required"`
|
||||
Address string `json:"address" form:"address"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewBill()(api.GetSession()(c).(*session.Enterprise)).TicketIssue(form.Convert(), &user.BillTicketParams{
|
||||
Kind: form.Kind, Name: form.Name, DutyParagraph: form.DutyParagraph, Mobile: form.Mobile,
|
||||
Email: form.Email, Address: form.Address,
|
||||
})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
124
app/api/enterprise/controller/user/bill.go
Normal file
124
app/api/enterprise/controller/user/bill.go
Normal file
@ -0,0 +1,124 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Bill struct {
|
||||
*session.Enterprise
|
||||
}
|
||||
|
||||
type BillHandle func(session *session.Enterprise) *Bill
|
||||
|
||||
type (
|
||||
// BillTicketInfo 账单发票信息
|
||||
BillTicketInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.UserBillTicket
|
||||
}
|
||||
// BillTicketParams 账单发票参数信息
|
||||
BillTicketParams struct {
|
||||
Kind int
|
||||
Name, DutyParagraph, Mobile, Email, Address string
|
||||
}
|
||||
)
|
||||
|
||||
// Instance 账单信息
|
||||
func (c *Bill) Instance(orderNo, createdAt string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mUserBill := model.NewUserBill()
|
||||
|
||||
where := []*model2.ModelWhere{
|
||||
model2.NewWhere("b.uid", c.UID),
|
||||
}
|
||||
if orderNo != "" {
|
||||
where = append(where, model2.NewWhere("b.order_no", orderNo))
|
||||
}
|
||||
if createdAt != "" {
|
||||
where = append(where, model2.NewWhereSectionAt("b.created_at", strings.Split(createdAt, " ~ "))...)
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mUserBill.Bill(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &controller.ReturnPages{Data: out, Count: count}, nil
|
||||
}
|
||||
|
||||
// Ticket 发票信息
|
||||
func (c *Bill) Ticket(id uint64) (*BillTicketInfo, error) {
|
||||
mUserBillTicket := model.NewUserBillTicket()
|
||||
|
||||
isExist, err := model2.FirstWhere(mUserBillTicket.UserBillTicket, model2.NewWhere("user_bill_id", id))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, nil
|
||||
}
|
||||
return &BillTicketInfo{
|
||||
ID: mUserBillTicket.GetEncodeID(),
|
||||
UserBillTicket: mUserBillTicket.UserBillTicket,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TicketIssue 发票开具
|
||||
func (c *Bill) TicketIssue(id uint64, params *BillTicketParams) error {
|
||||
mUserBill := model.NewUserBill()
|
||||
mUserBill.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mUserBill.UserBill, []string{"id", "bill_id", "user_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,账单信息不存在或已被删除")
|
||||
} else if mUserBill.UID != c.UID {
|
||||
return errors.New("操作错误,不可开具他人账单发票信息")
|
||||
}
|
||||
// 用户账单信息
|
||||
mUserBillTicket := model.NewUserBillTicket()
|
||||
|
||||
var count int64
|
||||
|
||||
if err = model2.Count(mUserBillTicket.UserBillTicket, &count, model2.NewWhere("user_bill_id", mUserBill.ID)); err != nil {
|
||||
return err
|
||||
} else if count > 0 {
|
||||
return errors.New("操作错误,当前账单已开具发票")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
mUserBillTicket.UserBillID = mUserBill.ID
|
||||
mUserBillTicket.Kind = model2.UserBillTicketKind(params.Kind)
|
||||
mUserBillTicket.Name = params.Name
|
||||
mUserBillTicket.DutyParagraph = params.DutyParagraph
|
||||
mUserBillTicket.Mobile = params.Mobile
|
||||
mUserBillTicket.Email = params.Email
|
||||
mUserBillTicket.Address = params.Address
|
||||
|
||||
if err = model2.Create(mUserBillTicket.UserBillTicket, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mBillInstance := model.NewBillInstance()
|
||||
mBillInstance.ID = mUserBill.BillID
|
||||
|
||||
return model2.Updates(mBillInstance.BillInstance, map[string]interface{}{
|
||||
"status": model2.BillInstanceStatusForApply, "updated_at": time.Now(),
|
||||
}, tx)
|
||||
})
|
||||
}
|
||||
|
||||
func NewBill() BillHandle {
|
||||
return func(session *session.Enterprise) *Bill {
|
||||
return &Bill{session}
|
||||
}
|
||||
}
|
11
app/api/enterprise/model/bill_instance.go
Normal file
11
app/api/enterprise/model/bill_instance.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type BillInstance struct {
|
||||
*model.BillInstance
|
||||
}
|
||||
|
||||
func NewBillInstance() *BillInstance {
|
||||
return &BillInstance{model.NewBillInstance()}
|
||||
}
|
45
app/api/enterprise/model/user_bill.go
Normal file
45
app/api/enterprise/model/user_bill.go
Normal file
@ -0,0 +1,45 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type UserBill struct {
|
||||
*model.UserBill
|
||||
}
|
||||
|
||||
// UserBillInfo 用户账单信息
|
||||
type UserBillInfo struct {
|
||||
model.Model
|
||||
model.BillInstanceBasic
|
||||
}
|
||||
|
||||
// Bill 账单信息
|
||||
func (m *UserBill) Bill(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*UserBillInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS u").
|
||||
Select("u.id", "b.order_no", "b.kind", "b.amount", "b.number", "b.status", "b.remark").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS b ON u.bill_id = b.id",
|
||||
model.NewBillInstance().TableName())).
|
||||
Where("u.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*UserBillInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("u.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewUserBill() *UserBill {
|
||||
return &UserBill{model.NewUserBill()}
|
||||
}
|
11
app/api/enterprise/model/user_bill_ticket.go
Normal file
11
app/api/enterprise/model/user_bill_ticket.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type UserBillTicket struct {
|
||||
*model.UserBillTicket
|
||||
}
|
||||
|
||||
func NewUserBillTicket() *UserBillTicket {
|
||||
return &UserBillTicket{model.NewUserBillTicket()}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package common
|
||||
|
||||
type Model struct {
|
||||
TableName string
|
||||
}
|
||||
|
||||
type Option func(model *Model)
|
||||
|
||||
func withModel(tableName string) Option {
|
||||
return func(model *Model) {
|
||||
model.TableName = tableName
|
||||
}
|
||||
}
|
||||
|
||||
func NewModel(option ...Option) *Model {
|
||||
out := new(Model)
|
||||
|
||||
for _, v := range option {
|
||||
v(out)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func Test() {
|
||||
NewModel(withModel(""))
|
||||
}
|
@ -1,11 +1,37 @@
|
||||
package model
|
||||
|
||||
// BillInstance 账单信息数据模型
|
||||
type BillInstance struct {
|
||||
Model
|
||||
BillInstanceBasic
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
// BillInstanceBasic 账单基本信息
|
||||
type BillInstanceBasic struct {
|
||||
OrderNo string `gorm:"column:order_no;type:varchar(30);default:'';comment:订单号" json:"order_no"`
|
||||
Kind string `gorm:"column:kind;type:varchar(20);default:'';comment:账单类型" json:"kind"`
|
||||
Amount float64 `gorm:"column:amount;type:decimal(10,2);default:0;comment:账单金额" json:"amount"`
|
||||
Number float64 `gorm:"column:number;type:decimal(10,2);default:0;comment:账单数量" json:"number"`
|
||||
Status BillInstanceStatus `gorm:"column:status;type:tinyint(1);default:0;comment:账单状态" json:"status"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);default:'';comment:账单备注" json:"remark"`
|
||||
}
|
||||
|
||||
// BillInstanceStatus 账单状态
|
||||
type BillInstanceStatus int
|
||||
|
||||
const (
|
||||
// BillInstanceStatusForInit 初始化
|
||||
BillInstanceStatusForInit BillInstanceStatus = iota
|
||||
// BillInstanceStatusForApply 申请中
|
||||
BillInstanceStatusForApply
|
||||
// BillInstanceStatusForProcessing 处理中
|
||||
BillInstanceStatusForProcessing
|
||||
// BillInstanceStatusForProcessed 已处理
|
||||
BillInstanceStatusForProcessed
|
||||
)
|
||||
|
||||
func (m *BillInstance) TableName() string {
|
||||
return "bill_instance"
|
||||
}
|
||||
|
18
app/common/model/user_bill.go
Normal file
18
app/common/model/user_bill.go
Normal file
@ -0,0 +1,18 @@
|
||||
package model
|
||||
|
||||
// UserBill 用户账单数据模型
|
||||
type UserBill struct {
|
||||
Model
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
BillID uint64 `gorm:"column:bill_id;type:int(11);default:0;comment:账单ID" json:"bill_id"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
func (m *UserBill) TableName() string {
|
||||
return "user_bill"
|
||||
}
|
||||
|
||||
func NewUserBill() *UserBill {
|
||||
return &UserBill{}
|
||||
}
|
33
app/common/model/user_bill_ticket.go
Normal file
33
app/common/model/user_bill_ticket.go
Normal file
@ -0,0 +1,33 @@
|
||||
package model
|
||||
|
||||
// UserBillTicket 用户账单发票数据模型
|
||||
type UserBillTicket struct {
|
||||
Model
|
||||
UserBillID uint64 `gorm:"column:user_bill_id;type:int(11);default:0;comment:用户账单ID" json:"user_bill_id"`
|
||||
Kind UserBillTicketKind `gorm:"column:kind;type:tinyint(1);default:1;comment:税号" json:"kind"`
|
||||
Name string `gorm:"column:name;type:varchar(30);default:'';comment:税号" json:"name"`
|
||||
DutyParagraph string `gorm:"column:duty_paragraph;type:varchar(30);default:'';comment:税号" json:"duty_paragraph"`
|
||||
Mobile string `gorm:"column:mobile;type:varchar(15);default:'';comment:联系电话" json:"mobile"`
|
||||
Email string `gorm:"column:email;type:varchar(50);default:'';comment:邮件地址" json:"email"`
|
||||
Address string `gorm:"column:address;type:varchar(255);default:'';comment:详细地址" json:"address"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
// UserBillTicketKind 用户账单发票类型
|
||||
type UserBillTicketKind int
|
||||
|
||||
const (
|
||||
// UserBillTicketKindForOrdinary 普通发票
|
||||
UserBillTicketKindForOrdinary UserBillTicketKind = iota + 1
|
||||
// UserBillTicketKindForSpecial 专票
|
||||
UserBillTicketKindForSpecial
|
||||
)
|
||||
|
||||
func (m *UserBillTicket) TableName() string {
|
||||
return "user_bill_ticket"
|
||||
}
|
||||
|
||||
func NewUserBillTicket() *UserBillTicket {
|
||||
return &UserBillTicket{}
|
||||
}
|
Reference in New Issue
Block a user