供应商管理
This commit is contained in:
parent
b4c5fa5e2a
commit
667acc2224
|
@ -3,29 +3,31 @@ package basic
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"go-admin/app/admin/middleware"
|
||||||
"go-admin/app/admin/models"
|
"go-admin/app/admin/models"
|
||||||
orm "go-admin/common/global"
|
orm "go-admin/common/global"
|
||||||
"go-admin/logger"
|
"go-admin/logger"
|
||||||
|
"go-admin/tools"
|
||||||
"go-admin/tools/app"
|
"go-admin/tools/app"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SupplierCreateRequest struct {
|
type SupplierCreateRequest struct {
|
||||||
Name string `json:"name" binding:"required"`
|
Name string `json:"name" validate:"required"` //供应商名称
|
||||||
Contact string `json:"contact" binding:"required"`
|
Contact string `json:"contact" validate:"required"` //联系人
|
||||||
Tel string `json:"tel" binding:"required"`
|
Tel string `json:"tel" validate:"required"` //手机号
|
||||||
Address string `json:"address" binding:"required"`
|
Address string `json:"address" validate:"required"` //地址
|
||||||
OpeningBank string `json:"opening_bank" binding:"required"`
|
OpeningBank string `json:"opening_bank" validate:"required"` //开户行
|
||||||
BankAccount string `json:"bank_account" binding:"required"`
|
AccountHolder string `json:"account_holder"` //开户人
|
||||||
PaymentCycle uint32 `json:"payment_cycle" binding:"required"`
|
BankAccount string `json:"bank_account" validate:"required"` //银行卡号
|
||||||
TaxNumber string `json:"tax_number"`
|
PaymentCycle uint32 `json:"payment_cycle" validate:"required"` //支付周期
|
||||||
StoreIds string `json:"store_ids"`
|
TaxNumber string `json:"tax_number"` //税点
|
||||||
Landline string `json:"landline"`
|
Landline string `json:"landline"` //固话
|
||||||
Email string `json:"email"`
|
Email string `json:"email"` //邮箱
|
||||||
CompanyWebsite string `json:"company_website"`
|
CompanyWebsite string `json:"company_website"` //网站
|
||||||
Province string `json:"province" binding:"required"`
|
Province string `json:"province" validate:"required"` //省份
|
||||||
City string `json:"city" binding:"required"`
|
City string `json:"city" validate:"required"` //城市
|
||||||
Area string `json:"area" binding:"required"`
|
Area string `json:"area" validate:"required"` //地区
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupplierCreate 添加供应商
|
// SupplierCreate 添加供应商
|
||||||
|
@ -35,6 +37,13 @@ func SupplierCreate(c *gin.Context) {
|
||||||
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err := tools.Validate(req)
|
||||||
|
if err != nil {
|
||||||
|
app.Error(c, http.StatusBadRequest, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
supplier := &models.Supplier{
|
supplier := &models.Supplier{
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Contact: req.Contact,
|
Contact: req.Contact,
|
||||||
|
@ -47,9 +56,13 @@ func SupplierCreate(c *gin.Context) {
|
||||||
Landline: req.Landline,
|
Landline: req.Landline,
|
||||||
Email: req.Email,
|
Email: req.Email,
|
||||||
CompanyWebsite: req.CompanyWebsite,
|
CompanyWebsite: req.CompanyWebsite,
|
||||||
|
Province: req.Province,
|
||||||
|
City: req.City,
|
||||||
|
Area: req.Area,
|
||||||
|
CooperativeBusinessId: middleware.GetCooperativeBusinessId(c),
|
||||||
}
|
}
|
||||||
|
|
||||||
err := orm.Eloquent.Create(supplier).Error
|
err = orm.Eloquent.Create(supplier).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("[SupplierCreate]:create supplier err", logger.Field("err", err))
|
logger.Error("[SupplierCreate]:create supplier err", logger.Field("err", err))
|
||||||
app.Error(c, http.StatusInternalServerError, err, "操作失败")
|
app.Error(c, http.StatusInternalServerError, err, "操作失败")
|
||||||
|
@ -62,7 +75,7 @@ func SupplierCreate(c *gin.Context) {
|
||||||
|
|
||||||
type SupplierUpdateRequest struct {
|
type SupplierUpdateRequest struct {
|
||||||
SupplierCreateRequest
|
SupplierCreateRequest
|
||||||
Id uint32 `json:"id" binding:"required"`
|
Id uint32 `json:"id" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupplierUpdate 更新供应商
|
// SupplierUpdate 更新供应商
|
||||||
|
@ -111,6 +124,7 @@ func SupplierList(c *gin.Context) {
|
||||||
list, err := models.GetSupplier(models.GetSupplierRequest{
|
list, err := models.GetSupplier(models.GetSupplierRequest{
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Number: req.Number,
|
Number: req.Number,
|
||||||
|
CooperativeBusinessId: middleware.GetCooperativeBusinessId(c),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Error(c, http.StatusInternalServerError, err, "获取列表失败")
|
app.Error(c, http.StatusInternalServerError, err, "获取列表失败")
|
||||||
|
@ -133,7 +147,7 @@ func SupplierDetail(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app.OK(c, supplier, "")
|
app.OK(c, supplier, "ok")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,6 +164,6 @@ func SupplierDel(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app.OK(c, nil, "")
|
app.OK(c, nil, "删除成功")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package middleware
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"go-admin/app/admin/models"
|
||||||
mycasbin "go-admin/pkg/casbin"
|
mycasbin "go-admin/pkg/casbin"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
@ -39,3 +40,12 @@ func AuthCheckRole() gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCooperativeBusinessId 获取用户合作商id
|
||||||
|
func GetCooperativeBusinessId(c *gin.Context) uint32 {
|
||||||
|
u, b := c.Get("userInfo")
|
||||||
|
if !b {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return u.(*models.SysUserB).CooperativeBusinessId
|
||||||
|
}
|
||||||
|
|
|
@ -1511,7 +1511,7 @@ func ExpireMemberSMSSendDay(day uint32, nowTime time.Time) {
|
||||||
smsSend.Tel = users[i].Tel
|
smsSend.Tel = users[i].Tel
|
||||||
exist, err := QueryRecordExist(fmt.Sprintf("SELECT * FROM order_card WHERE uid = %d AND pay_status=2 AND card_status IN (1,2,3) ", users[i].Uid))
|
exist, err := QueryRecordExist(fmt.Sprintf("SELECT * FROM order_card WHERE uid = %d AND pay_status=2 AND card_status IN (1,2,3) ", users[i].Uid))
|
||||||
if err != nil || !exist {
|
if err != nil || !exist {
|
||||||
logger.Error(err.Error())
|
logger.Error("QueryRecordExist err", logger.Field("err", err), logger.Field("exists", exist))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
err = GtSendMessage([]string{users[i].Tel}, smsSend.Message)
|
err = GtSendMessage([]string{users[i].Tel}, smsSend.Message)
|
||||||
|
|
|
@ -26,6 +26,7 @@ type Supplier struct {
|
||||||
Landline string `json:"landline"` //固定电话
|
Landline string `json:"landline"` //固定电话
|
||||||
Email string `json:"email"` //邮件
|
Email string `json:"email"` //邮件
|
||||||
CompanyWebsite string `json:"company_website"` //网站
|
CompanyWebsite string `json:"company_website"` //网站
|
||||||
|
CooperativeBusinessId uint32 `json:"cooperative_business_id"` //合作商id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Supplier) TableName() string {
|
func (s *Supplier) TableName() string {
|
||||||
|
@ -48,6 +49,7 @@ func (s *Supplier) BeforeCreate(tx *gorm.DB) error {
|
||||||
type GetSupplierRequest struct {
|
type GetSupplierRequest struct {
|
||||||
Name string //供应商名称
|
Name string //供应商名称
|
||||||
Number string //供应商编号
|
Number string //供应商编号
|
||||||
|
CooperativeBusinessId uint32 //合作商id
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSupplier(req GetSupplierRequest) ([]*Supplier, error) {
|
func GetSupplier(req GetSupplierRequest) ([]*Supplier, error) {
|
||||||
|
@ -61,6 +63,8 @@ func GetSupplier(req GetSupplierRequest) ([]*Supplier, error) {
|
||||||
m = m.Where("number = ?", req.Number)
|
m = m.Where("number = ?", req.Number)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m = m.Where("cooperative_business_id = ?", req.CooperativeBusinessId)
|
||||||
|
|
||||||
err := m.
|
err := m.
|
||||||
Order("created_at desc").
|
Order("created_at desc").
|
||||||
Find(&list).
|
Find(&list).
|
||||||
|
|
|
@ -2,7 +2,6 @@ package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"gorm.io/gorm"
|
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -322,6 +321,9 @@ func (e *SysUser) SetPwd(pwd SysUserPwd) (Result bool, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *SysUser) GetByUserId(tx *gorm.DB, id interface{}) error {
|
func GetUserById(id uint32) *SysUserB {
|
||||||
return tx.First(e, id).Error
|
var u = new(SysUserB)
|
||||||
|
orm.Eloquent.Table("sys_user").Where("user_id", id).First(u)
|
||||||
|
|
||||||
|
return u
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user