Merge pull request 'test' (#26) from test into master
Reviewed-on: https://git.oa00.com/recook/backend_v2/pulls/26master
commit
f6150e5159
@ -0,0 +1,70 @@
|
||||
package setting
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"recook/internal/libs/bean"
|
||||
"recook/internal/v2/lib/back"
|
||||
"recook/internal/v2/logic/manage/setting"
|
||||
"recook/tools"
|
||||
)
|
||||
|
||||
type Invite struct {
|
||||
}
|
||||
type PageItem struct {
|
||||
}
|
||||
|
||||
// Lists 返回邀请码
|
||||
func (*Invite) Lists(c *gin.Context) {
|
||||
args := bean.Page{}
|
||||
err := tools.Params(&args, c)
|
||||
if err != nil {
|
||||
back.Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
lists, total := setting.InviteLogic.Lists(args)
|
||||
back.Suc(c, "操作成功", bean.ResultLists{
|
||||
List: lists,
|
||||
Total: int(total),
|
||||
})
|
||||
}
|
||||
|
||||
type arsgInviteCreateInvite struct {
|
||||
NowTime string
|
||||
}
|
||||
|
||||
// Gen 创建邀请码
|
||||
func (*Invite) Gen(c *gin.Context) {
|
||||
args := arsgInviteCreateInvite{}
|
||||
err := tools.Params(&args, c)
|
||||
if err != nil {
|
||||
back.Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
if err := setting.InviteLogic.Gen(args.NowTime); err != nil {
|
||||
back.Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
back.Suc(c, "操作成功", nil)
|
||||
}
|
||||
|
||||
type arsgInviteCancellation struct {
|
||||
InviteId int64
|
||||
}
|
||||
|
||||
func (*Invite) Cancellation(c *gin.Context) {
|
||||
args := arsgInviteCancellation{}
|
||||
err := tools.Params(&args, c)
|
||||
if err != nil {
|
||||
back.Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
if args.InviteId == 0 {
|
||||
back.Fail(c, "参数错误")
|
||||
return
|
||||
}
|
||||
if err := setting.InviteLogic.Cancellation(args.InviteId); err != nil {
|
||||
back.Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
back.Suc(c, "操作成功", nil)
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package copartner
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"recook/internal/back"
|
||||
"recook/internal/v2/logic/wxapp/copartner"
|
||||
"recook/tools"
|
||||
)
|
||||
|
||||
type Company struct {
|
||||
}
|
||||
type argsCompanyAdd struct {
|
||||
InviteNo string `binding:"required" label:"邀请码"` // 邀请码
|
||||
copartner.CompanyInfo
|
||||
}
|
||||
|
||||
// Add @Title 添加合伙人
|
||||
func (*Company) Add(c *gin.Context) {
|
||||
var args argsCompanyAdd
|
||||
if err := tools.Params(&args, c); err != nil {
|
||||
back.Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
if err := copartner.CopartnerLogic.Very(args.InviteNo); err != nil {
|
||||
back.Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
if err := copartner.CompanyLogic.Add(args.CompanyInfo); err != nil {
|
||||
back.Fail(c, err.Error())
|
||||
} else {
|
||||
back.Suc(c, "ok", "")
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package copartner
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"recook/internal/v2/lib/back"
|
||||
"recook/internal/v2/logic/wxapp/copartner"
|
||||
"recook/tools"
|
||||
)
|
||||
|
||||
type Copartner struct {
|
||||
}
|
||||
type argsCopartnerCode struct {
|
||||
InviteNo string `binding:"required" label:"邀请码"` // 邀请码
|
||||
}
|
||||
|
||||
// Very @Title 验证邀请码
|
||||
func (*Copartner) Very(c *gin.Context) {
|
||||
var args argsCopartnerCode
|
||||
if err := tools.Params(&args, c); err != nil {
|
||||
back.Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
if err := copartner.CopartnerLogic.Very(args.InviteNo); err != nil {
|
||||
back.Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
back.Suc(c, "ok", "")
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package setting
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"git.oa00.com/go/mysql"
|
||||
"recook/internal/libs/bean"
|
||||
"recook/internal/v2/logic/command"
|
||||
"recook/internal/v2/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
var InviteLogic = &inviteLogic{}
|
||||
|
||||
type inviteLogic struct {
|
||||
}
|
||||
type inviteItem struct {
|
||||
Id uint `json:"id"`
|
||||
Code string `json:"code"`
|
||||
CreateTime int64 `json:"create_time"`
|
||||
EndTime int64 `json:"end_time"`
|
||||
}
|
||||
|
||||
// Lists @Title 返回邀请码列表
|
||||
func (i *inviteLogic) Lists(page bean.Page) (lists []inviteItem, total int64) {
|
||||
lists = []inviteItem{}
|
||||
var inviteCodes []model.TopCode
|
||||
mysql.Db.Model(&inviteCodes).Count(&total)
|
||||
if page.HasPage(total) {
|
||||
mysql.Db.Offset(page.GetStart()).Limit(page.Limit).Find(&inviteCodes)
|
||||
for _, inviteCode := range inviteCodes {
|
||||
lists = append(lists, inviteItem{
|
||||
Id: inviteCode.Id,
|
||||
Code: inviteCode.Code,
|
||||
CreateTime: inviteCode.CreatedTime.Unix(),
|
||||
EndTime: inviteCode.EndTime.Unix(),
|
||||
})
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Gen @Title 创建生成码
|
||||
func (i *inviteLogic) Gen(nowTime string) error {
|
||||
random := command.CommandLogic.Random(6)
|
||||
location, err := time.ParseInLocation("2006-01-02 15:04:05", nowTime, time.Local)
|
||||
if err != nil {
|
||||
return errors.New("时间格式错误")
|
||||
}
|
||||
inviete := model.TopCode{
|
||||
Code: random,
|
||||
CreatedTime: time.Now(),
|
||||
EndTime: location,
|
||||
}
|
||||
if mysql.Db.Create(&inviete).Error != nil {
|
||||
return errors.New("生成失败")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Cancellation @Title 作废邀请码
|
||||
func (i *inviteLogic) Cancellation(inviteId int64) error {
|
||||
inviete := model.TopCode{}
|
||||
if mysql.Db.Where("id = ?", inviteId).First(&inviete).Error != nil {
|
||||
return errors.New("邀请码不存在")
|
||||
}
|
||||
if mysql.Db.Model(&inviete).Update("end_time", time.Now()).Error != nil {
|
||||
return errors.New("作废失败")
|
||||
}
|
||||
return nil
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package copartner
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.oa00.com/go/mysql"
|
||||
"github.com/golangkit/formatime"
|
||||
"github.com/shopspring/decimal"
|
||||
"gorm.io/gorm"
|
||||
"recook/internal/v2/model/company"
|
||||
"recook/internal/v2/model/recook/user"
|
||||
)
|
||||
|
||||
var CompanyLogic = &companyLogic{}
|
||||
|
||||
type companyLogic struct {
|
||||
}
|
||||
type CompanyInfo struct {
|
||||
Phone string `binding:"required,len=11,startswith=1" label:"手机号"` //手机号
|
||||
NikeName string `binding:"required" label:"昵称"` //昵称
|
||||
BusinessLicense string `binding:"required" label:"印业执照"` //营业执照
|
||||
CorporationName string `binding:"required" label:"企业名"` //企业名
|
||||
TaxBillType string `binding:"required" label:"纳税类型"` //纳税类型
|
||||
Taxpayer string `binding:"required" label:"纳税识别号"` //纳税识别号
|
||||
OpeningBank string `binding:"required" label:"开户行"` //开户行
|
||||
BankAccount string `binding:"required" label:"银行账户"` //银行账户
|
||||
MakeTax decimal.Decimal `binding:"required" label:"开票税率"` //开票税率
|
||||
Linkman string `binding:"required" label:"联系人"` //联系人
|
||||
PEmail string `binding:"required" label:"联系人手机号或者邮箱"` //联系人手机号或者邮箱
|
||||
}
|
||||
|
||||
// Add @Title 添加合伙人
|
||||
func (c *companyLogic) Add(data CompanyInfo) error {
|
||||
userInfoModel := user.RecookUserInfoModel{Mobile: data.Phone}
|
||||
mysql.Db.Where(&userInfoModel).First(&userInfoModel)
|
||||
if userInfoModel.Id > 0 {
|
||||
return fmt.Errorf("手机已存在")
|
||||
}
|
||||
userInfo := user.RecookUserInfoModel{Nickname: data.NikeName}
|
||||
mysql.Db.Where(&userInfo).First(&userInfoModel)
|
||||
if userInfo.Id > 0 {
|
||||
return fmt.Errorf("昵称已存在")
|
||||
}
|
||||
companyInfo := company.Info{
|
||||
ShopName: data.NikeName,
|
||||
Mobile: data.Phone,
|
||||
BusinessPhoto: data.BusinessLicense,
|
||||
TaxBank: data.OpeningBank,
|
||||
TaxAccount: data.BankAccount,
|
||||
Tax: data.MakeTax,
|
||||
TaxType: data.TaxBillType,
|
||||
ContractEmail: data.PEmail,
|
||||
TaxNumber: data.Taxpayer,
|
||||
ContractName: data.Linkman,
|
||||
CompanyName: data.CorporationName,
|
||||
State: company.Wait,
|
||||
CreatedAt: formatime.NewSecondNow(),
|
||||
}
|
||||
return mysql.Db.Transaction(func(tx *gorm.DB) error {
|
||||
if tx.Create(&companyInfo).Error != nil {
|
||||
return errors.New("提交失败")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package copartner
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"git.oa00.com/go/mysql"
|
||||
"recook/internal/v2/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
var CopartnerLogic = &copartnerLogic{}
|
||||
|
||||
type copartnerLogic struct {
|
||||
}
|
||||
|
||||
// Very @Title 验证邀请码
|
||||
func (*copartnerLogic) Very(inviteNo string) error {
|
||||
topCode := model.TopCode{Code: inviteNo}
|
||||
if mysql.Db.Where(&topCode).First(&topCode).Error != nil {
|
||||
return errors.New("邀请码不存在")
|
||||
}
|
||||
if topCode.EndTime.Before(time.Now()) {
|
||||
return errors.New("邀请码过期")
|
||||
}
|
||||
return nil
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package copartner
|
||||
|
||||
var PersonalLogic = &personalLogic{}
|
||||
|
||||
type personalLogic struct {
|
||||
}
|
||||
|
||||
// Add @Title 添加合伙人-个人
|
||||
func (*personalLogic) Add(phone, nickname string) {
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// 邀请人的历史记录
|
||||
type InviteCode struct {
|
||||
ID int64 `gorm:"column:id" json:"id"`
|
||||
InviterUserID uint `gorm:"inviter_user_id" json:"inviterUserId"`
|
||||
InviterCode string `gorm:"column:inviter_code" json:"userId"`
|
||||
ExpiredAt time.Time `gorm:"column:expired_at" json:"expiredAt"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
|
||||
}
|
||||
|
||||
func (r *InviteCode) TableName() string {
|
||||
return "recook_invite_code"
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type TopCode struct {
|
||||
Id uint `gorm:"column:id;primary_key" json:"id"`
|
||||
Code string `gorm:"column:code" json:"code"`
|
||||
CreatedTime time.Time `gorm:"column:created_time" json:"createdTime"`
|
||||
EndTime time.Time `gorm:"column:end_time" json:"endTime"`
|
||||
UserId uint `gorm:"column:user_id" json:"userId"`
|
||||
}
|
||||
|
||||
func (r *TopCode) TableName() string {
|
||||
return "recook_user_top_code"
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"recook/internal/v2/controller/wxapp/copartner"
|
||||
"recook/internal/v2/router/middleware"
|
||||
)
|
||||
|
||||
// @Style recook总后台
|
||||
func routerWxapp(wxappRouter *gin.RouterGroup) {
|
||||
authorize := middleware.AppAuthorize()
|
||||
|
||||
copartnerRouter := wxappRouter.Group("copartner", authorize)
|
||||
{
|
||||
copartnerController := copartner.Copartner{}
|
||||
{
|
||||
copartnerRouter.POST("copartner/very", copartnerController.Very) //wxapp添加合伙人-公司
|
||||
}
|
||||
companyController := copartner.Company{}
|
||||
{
|
||||
copartnerRouter.POST("company/add", companyController.Add) //wxapp添加合伙人-公司
|
||||
}
|
||||
personalController := copartner.Personal{}
|
||||
{
|
||||
copartnerRouter.POST("personal/add", personalController.Add) // wxapp添加合伙人-个人
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue