Kaynağa Gözat

修改创建项目

yuliang1112 2 yıl önce
ebeveyn
işleme
065b3915fc

+ 19 - 17
db/default.go

@@ -581,14 +581,13 @@ func GetTaskDefaultDataList(ctx context.Context, projectID string, pageSize, pag
 
 func GetTaskTerminatingList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) ([]*http_model.TaskTerminatingInfo, int64, error) {
 	db := GetReadDB(ctx)
-
 	var taskIds1 []string
 	var totalTerminating int64
 	var TerminatingInfos []gorm_model.YoungeeContractInfo
 	db = db.Model(gorm_model.YoungeeContractInfo{})
-	err := db.Where("default_status = 3").Find(&TerminatingInfos).Error
+	err := db.Where("default_status = 3 AND project_id = ?", projectID).Find(&TerminatingInfos).Error
 	if err != nil {
-		logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
+		logrus.WithContext(ctx).Errorf("[GetTaskTerminatingList] error query mysql total, err:%+v", err)
 		return nil, 0, err
 	}
 	TerminatingMap := make(map[string]gorm_model.YoungeeContractInfo)
@@ -598,7 +597,7 @@ func GetTaskTerminatingList(ctx context.Context, projectID string, pageSize, pag
 	}
 
 	if err := db.Count(&totalTerminating).Error; err != nil {
-		logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
+		logrus.WithContext(ctx).Errorf("[GetTaskTerminatingList] error query mysql total, err:%+v", err)
 		return nil, 0, err
 	}
 
@@ -615,7 +614,7 @@ func GetTaskTerminatingList(ctx context.Context, projectID string, pageSize, pag
 		value := conditionValue.FieldByName(field.Name)
 		if tag == "default_status" {
 			if value.Interface() == int64(4) {
-				db = db.Where("cur_default_type = 9")
+				db1 = db1.Where("cur_default_type = 9")
 			}
 			continue
 		} else if !util.IsBlank(value) {
@@ -623,7 +622,10 @@ func GetTaskTerminatingList(ctx context.Context, projectID string, pageSize, pag
 				platform_nickname = fmt.Sprintf("%v", value.Interface())
 				continue
 			} else if tag == "project_id" || tag == "strategy_id" {
-				db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
+				if tag == "strategy_id" {
+					fmt.Println("strategy_id:", value.Interface())
+				}
+				db1 = db1.Debug().Where(fmt.Sprintf("%s = ?", tag), value.Interface())
 			}
 		}
 	}
@@ -632,7 +634,7 @@ func GetTaskTerminatingList(ctx context.Context, projectID string, pageSize, pag
 	// 查询总数
 	var totalTask int64
 	if err := db1.Count(&totalTask).Error; err != nil {
-		logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
+		logrus.WithContext(ctx).Errorf("[GetTaskTerminatingList] error query mysql total, err:%+v", err)
 		return nil, 0, err
 	}
 	db1.Order("task_id").Find(&taskInfos)
@@ -658,7 +660,7 @@ func GetTaskTerminatingList(ctx context.Context, projectID string, pageSize, pag
 	err = db1.Order("task_id").Limit(int(limit)).Offset(int(offset)).Error
 
 	if err != nil {
-		logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
+		logrus.WithContext(ctx).Errorf("[GetTaskTerminatingList] error query mysql total, err:%+v", err)
 		return nil, 0, err
 	}
 
@@ -695,7 +697,7 @@ func GetTaskTerminatedList(ctx context.Context, projectID string, pageSize, page
 	// 根据Project条件过滤
 	conditionType := reflect.TypeOf(conditions).Elem()
 	conditionValue := reflect.ValueOf(conditions).Elem()
-	var platform_nickname string = ""
+	var platformNickname string = ""
 	for i := 0; i < conditionType.NumField(); i++ {
 		field := conditionType.Field(i)
 		tag := field.Tag.Get("condition")
@@ -708,7 +710,7 @@ func GetTaskTerminatedList(ctx context.Context, projectID string, pageSize, page
 			continue
 		} else if !util.IsBlank(value) {
 			if tag == "platform_nickname" {
-				platform_nickname = fmt.Sprintf("%v", value.Interface())
+				platformNickname = fmt.Sprintf("%v", value.Interface())
 				continue
 			} else if tag == "project_id" || tag == "strategy_id" {
 				db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
@@ -720,7 +722,7 @@ func GetTaskTerminatedList(ctx context.Context, projectID string, pageSize, page
 	// 查询总数
 	var totalTask int64
 	if err := db.Count(&totalTask).Error; err != nil {
-		logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
+		logrus.WithContext(ctx).Errorf("[GetTaskTerminatedList] error query mysql total, err:%+v", err)
 		return nil, 0, err
 	}
 	db.Order("task_id").Find(&taskInfos)
@@ -738,7 +740,7 @@ func GetTaskTerminatedList(ctx context.Context, projectID string, pageSize, page
 	db1 = db1.Model(gorm_model.YoungeeContractInfo{}).Where("task_id IN ? AND (default_status = 1 OR default_status = 4)", taskIds)
 	err1 := db1.Find(&TerminatedInfos).Error
 	if err1 != nil {
-		logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql find, err:%+v", err1)
+		logrus.WithContext(ctx).Errorf("[GetTaskTerminatedList] error query mysql find, err:%+v", err1)
 		return nil, 0, err1
 	}
 	TerminatedMap := make(map[string]gorm_model.YoungeeContractInfo)
@@ -748,7 +750,7 @@ func GetTaskTerminatedList(ctx context.Context, projectID string, pageSize, page
 	// 查询总数
 	var totalTerminated int64
 	if err := db1.Count(&totalTerminated).Error; err != nil {
-		logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
+		logrus.WithContext(ctx).Errorf("[GetTaskTerminatedList] error query mysql total, err:%+v", err)
 		return nil, 0, err
 	}
 	var misNum int64
@@ -765,7 +767,7 @@ func GetTaskTerminatedList(ctx context.Context, projectID string, pageSize, page
 	err := db.Order("task_id").Limit(int(limit)).Offset(int(offset)).Error
 
 	if err != nil {
-		logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
+		logrus.WithContext(ctx).Errorf("[GetTaskTerminatedList] error query mysql total, err:%+v", err)
 		return nil, 0, err
 	}
 
@@ -782,11 +784,11 @@ func GetTaskTerminatedList(ctx context.Context, projectID string, pageSize, page
 	taskTerminateds = pack.TaskTerminatedToTaskInfo(TaskTerminateds)
 
 	for _, v := range taskTerminateds {
-		if platform_nickname == "" {
+		if platformNickname == "" {
 			newTaskTerminateds = append(newTaskTerminateds, v)
-		} else if strings.Contains(v.PlatformNickname, platform_nickname) {
+		} else if strings.Contains(v.PlatformNickname, platformNickname) {
 			newTaskTerminateds = append(newTaskTerminateds, v)
-		} else if strings.Contains(conv.MustString(v.TaskID, ""), platform_nickname) {
+		} else if strings.Contains(conv.MustString(v.TaskID, ""), platformNickname) {
 			newTaskTerminateds = append(newTaskTerminateds, v)
 		} else {
 			totalTask--

+ 102 - 0
db/enterprise.go

@@ -2,8 +2,13 @@ package db
 
 import (
 	"context"
+	"fmt"
+	"github.com/caixw/lib.go/conv"
+	log "github.com/sirupsen/logrus"
 	"gorm.io/gorm"
+	"time"
 	"youngee_m_api/model/gorm_model"
+	"youngee_m_api/util"
 )
 
 //企业ID查找
@@ -37,3 +42,100 @@ func UpdateEnterpriseBalance(ctx context.Context, EnterpriseID string, balance f
 
 	return &enterprise.Balance, nil
 }
+
+func MakeRechargeId(ctx context.Context, EnterpriseID string) string {
+	db := GetReadDB(ctx)
+	// 1、年月日
+	year := time.Now().Year()
+	month := time.Now().Month()
+	day := time.Now().Day()
+	yearData, _ := util.GetDayNum("year", year)
+	monthData, _ := util.GetDayNum("month", int(month))
+	dayData, _ := util.GetDayNum("day", day)
+	sum := 0
+	sum += dayData + monthData
+	leap := 0
+	if (yearData%400 == 0) || ((yearData%4 == 0) && (yearData%100 != 0)) {
+		leap = 1
+	}
+	if (leap == 1) && (monthData > 2) {
+		sum += 1
+	}
+	last := ""
+	rechargeIdPrefix := "8" + EnterpriseID[len(EnterpriseID)-2:] + conv.MustString(sum, "")
+	var rechargeIdLast string
+	err := db.Model(gorm_model.YounggeeRechargeRecord{}).Select("recharge_id").Where("recharge_id like ?", rechargeIdPrefix+"%").
+		Last(&rechargeIdLast).Error
+	if err != nil {
+		last = "0"
+	} else {
+		last = rechargeIdLast[len(rechargeIdLast)-2:]
+	}
+	var lastInt int
+	lastInt = conv.MustInt(last, 0)
+	if lastInt+1 < 10 {
+		last = "0" + conv.MustString(conv.MustInt(last, 0)+1, "")
+	} else {
+		last = conv.MustString(conv.MustInt(last, 0)+1, "")
+	}
+	return rechargeIdPrefix + last
+}
+
+// RechargeAmount 在线充值
+func RechargeAmount(ctx context.Context, EnterpriseID string, Amount float64, phone string) error {
+	db := GetReadDB(ctx)
+	fmt.Println("Amount前:", Amount)
+	err := db.Model(gorm_model.Enterprise{}).Where("enterprise_id", EnterpriseID).
+		Updates(map[string]interface{}{"balance": gorm.Expr("balance + ?", Amount), "available_balance": gorm.Expr("available_balance + ?", Amount)}).Error
+	if err != nil {
+		return err
+	}
+	rechargeId := MakeRechargeId(ctx, EnterpriseID)
+	err = db.Model(gorm_model.YounggeeRechargeRecord{}).Create(&gorm_model.YounggeeRechargeRecord{
+		RechargeID:         rechargeId,
+		RechargeAmount:     Amount,
+		EnterpriseID:       EnterpriseID,
+		Status:             2,
+		InvoiceStatus:      2,
+		CommitAt:           time.Now(),
+		RechargeMethod:     3,
+		TransferVoucherUrl: "--",
+		Phone:              phone,
+		ConfirmAt:          time.Now(),
+	}).Error
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// TransferToPublic 对公转账
+func TransferToPublic(ctx context.Context, Amount float64, EnterpriseID string, transferVoucherUrl string) error {
+	phone := GetPhoneByEnterpriseID(ctx, EnterpriseID)
+	db := GetReadDB(ctx)
+	rechargeId := MakeRechargeId(ctx, EnterpriseID)
+	fmt.Println("Amount:", Amount)
+	err := db.Model(gorm_model.YounggeeRechargeRecord{}).Create(&gorm_model.YounggeeRechargeRecord{
+		RechargeID:         rechargeId,
+		RechargeAmount:     Amount,
+		EnterpriseID:       EnterpriseID,
+		Status:             1,
+		InvoiceStatus:      1,
+		CommitAt:           time.Now(),
+		Phone:              phone,
+		RechargeMethod:     1,
+		TransferVoucherUrl: transferVoucherUrl,
+		ConfirmAt:          time.Now(),
+	}).Error
+	if err != nil {
+		return err
+	}
+	db1 := GetReadDB(ctx)
+	err = db1.Model(gorm_model.Enterprise{}).Where("enterprise_id = ?", EnterpriseID).Updates(
+		map[string]interface{}{"recharging": gorm.Expr("recharging + ?", Amount)}).Error
+	if err != nil {
+		log.Println("[TransferToPublic] recharging modify failed:", err)
+		return err
+	}
+	return nil
+}

+ 17 - 11
db/finance.go

@@ -256,17 +256,21 @@ func GetInvoiceRecords(ctx context.Context, req *http_model.InvoiceRecordsReques
 		logrus.WithContext(ctx).Errorf("[GetInvoiceRecords] error query mysql limit, err:%+v", err)
 		return nil, err
 	}
-	var enterpriseIds []string
-	for _, invoiceRecord := range invoiceRecords {
-		enterpriseIds = append(enterpriseIds, invoiceRecord.EnterpriseID)
-	}
-	util.RemoveStrRepByMap(enterpriseIds)
 	enterpriseIdToUserInfoMap := make(map[string]gorm_model.Enterprise)
-	db1 := GetReadDB(ctx)
-	for _, v := range enterpriseIds {
-		enterpriseInfo := gorm_model.Enterprise{}
-		db1.Model(gorm_model.Enterprise{}).Where("enterprise_id = ?", v).Find(&enterpriseInfo)
-		enterpriseIdToUserInfoMap[v] = enterpriseInfo
+	regionAddressMap := make(map[string]string)
+	for _, invoiceRecord := range invoiceRecords {
+		if _, ok := enterpriseIdToUserInfoMap[invoiceRecord.EnterpriseID]; !ok {
+			db1 := GetReadDB(ctx)
+			enterpriseInfo := gorm_model.Enterprise{}
+			db1.Model(gorm_model.Enterprise{}).Where("enterprise_id = ?", invoiceRecord.EnterpriseID).Find(&enterpriseInfo)
+			enterpriseIdToUserInfoMap[invoiceRecord.EnterpriseID] = enterpriseInfo
+		}
+		if _, ok := regionAddressMap[invoiceRecord.EnterpriseID]; !ok {
+			db1 := GetReadDB(ctx)
+			var regionCode string
+			db1.Model(gorm_model.YounggeeInvoiceAddress{}).Select("region_code").Where("enterprise_id = ?", invoiceRecord.EnterpriseID).Find(&regionCode)
+			regionAddressMap[invoiceRecord.EnterpriseID] = GetRegion(ctx, conv.MustInt(regionCode, 0))
+		}
 	}
 	var InvoiceRecords []*http_model.InvoiceRecordsPreviews
 	for _, invoiceRecord := range invoiceRecords {
@@ -274,6 +278,7 @@ func GetInvoiceRecords(ctx context.Context, req *http_model.InvoiceRecordsReques
 		InvoiceRecord.BillingId = invoiceRecord.BillingID
 		InvoiceRecord.InvoiceInfo = invoiceRecord.InvoiceSnap
 		InvoiceRecord.AddressInfo = invoiceRecord.AddressSnap
+		InvoiceRecord.InvoiceAddress = regionAddressMap[invoiceRecord.EnterpriseID]
 		InvoiceRecord.InvoiceType = invoiceRecord.InvoiceType
 		InvoiceRecord.Amount = invoiceRecord.InvoiceAmount
 		InvoiceRecord.Phone = invoiceRecord.Phone
@@ -356,7 +361,7 @@ func GetRechargeRecords(ctx context.Context, req *http_model.GetRechargeRecordsR
 	offset := req.PageSize * req.PageNum // assert pageNum start with 0
 	err := db.Limit(int(limit)).Offset(int(offset)).Find(&rechargeRecords).Error
 	if err != nil {
-		logrus.WithContext(ctx).Errorf("[GetInvoiceRecords] error query mysql limit, err:%+v", err)
+		logrus.WithContext(ctx).Errorf("[GetRechargeRecords] error query mysql limit, err:%+v", err)
 		return nil, err
 	}
 	var enterpriseIds []string
@@ -377,6 +382,7 @@ func GetRechargeRecords(ctx context.Context, req *http_model.GetRechargeRecordsR
 		RechargeRecord.RechargeId = rechargeRecord.RechargeID
 		RechargeRecord.EnterpriseID = rechargeRecord.EnterpriseID
 		RechargeRecord.RechargeAmount = rechargeRecord.RechargeAmount
+		fmt.Println(rechargeRecord.RechargeAmount)
 		RechargeRecord.ConfirmAt = conv.MustString(rechargeRecord.ConfirmAt, "")[:19]
 		RechargeRecord.CommitAt = conv.MustString(rechargeRecord.CommitAt, "")[:19]
 		RechargeRecord.Phone = rechargeRecord.Phone

+ 3 - 0
db/talent.go

@@ -2,6 +2,7 @@ package db
 
 import (
 	"context"
+	"fmt"
 	"github.com/caixw/lib.go/conv"
 	"github.com/sirupsen/logrus"
 	"gorm.io/gorm"
@@ -126,6 +127,8 @@ func GetRegion(ctx context.Context, regionCode int) string {
 	cityCode := conv.MustString(regionCode, "")[0:4] + "00"
 	var city *gorm_model.InfoRegion
 	db4.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", conv.MustInt(cityCode, 0)).First(&city)
+	fmt.Println("province,city,infoRegion Code :", provinceCode, cityCode, regionCode)
+	fmt.Println("province,city,infoRegion RegionName :", province.RegionName, city.RegionName, infoRegion.RegionName)
 	return province.RegionName + city.RegionName + infoRegion.RegionName
 }
 

+ 55 - 0
handler/queryOrderByTradeId.go

@@ -0,0 +1,55 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"youngee_m_api/consts"
+	"youngee_m_api/model/http_model"
+	"youngee_m_api/service"
+	"youngee_m_api/util"
+)
+
+func WrapQueryOrderByTradeIdHandler(ctx *gin.Context) {
+	handler := newQueryOrderByTradeIdHandler(ctx)
+	BaseRun(handler)
+}
+
+type QueryOrderByTradeIdHandler struct {
+	ctx  *gin.Context
+	req  *http_model.QueryOrderByTradeIdRequest
+	resp *http_model.CommonResponse
+}
+
+func (q QueryOrderByTradeIdHandler) getContext() *gin.Context {
+	return q.ctx
+}
+
+func (q QueryOrderByTradeIdHandler) getResponse() interface{} {
+	return q.resp
+}
+
+func (q QueryOrderByTradeIdHandler) getRequest() interface{} {
+	return q.req
+}
+
+func (q QueryOrderByTradeIdHandler) run() {
+	data, err := service.QueryOrderByOutTradeNo(q.req.TradeId)
+	if err != nil {
+		logrus.WithContext(q.ctx).Errorf("[QueryOrderByTradeIdHandler] error QueryOrderByOutTradeNo, err:%+v", err)
+		util.HandlerPackErrorResp(q.resp, consts.ErrorInternal, consts.DefaultToast)
+		return
+	}
+	q.resp.Data = data
+}
+
+func (q QueryOrderByTradeIdHandler) checkParam() error {
+	return nil
+}
+
+func newQueryOrderByTradeIdHandler(ctx *gin.Context) *QueryOrderByTradeIdHandler {
+	return &QueryOrderByTradeIdHandler{
+		ctx:  ctx,
+		req:  http_model.NewQueryOrderByTradeIdRequest(),
+		resp: http_model.NewQueryOrderByTradeIdResponse(),
+	}
+}

+ 58 - 0
handler/rechargeBalance.go

@@ -0,0 +1,58 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"youngee_m_api/consts"
+	"youngee_m_api/db"
+	"youngee_m_api/middleware"
+	"youngee_m_api/model/http_model"
+	"youngee_m_api/util"
+)
+
+func WrapRechargeBalanceHandler(ctx *gin.Context) {
+	handler := newRechargeBalanceHandler(ctx)
+	BaseRun(handler)
+}
+
+type RechargeBalanceHandler struct {
+	ctx  *gin.Context
+	req  *http_model.RechargeBalanceRequest
+	resp *http_model.CommonResponse
+}
+
+func (r RechargeBalanceHandler) getContext() *gin.Context {
+	return r.ctx
+}
+
+func (r RechargeBalanceHandler) getResponse() interface{} {
+	return r.resp
+}
+
+func (r RechargeBalanceHandler) getRequest() interface{} {
+	return r.req
+}
+
+func (r RechargeBalanceHandler) run() {
+	enterpriseID := r.req.EnterpriseId
+	phone := middleware.GetSessionAuth(r.ctx).Phone
+	err := db.RechargeAmount(r.ctx, enterpriseID, r.req.Amount, phone)
+	if err != nil {
+		logrus.WithContext(r.ctx).Errorf("[QueryOrderByTradeIdHandler] error QueryOrderByOutTradeNo, err:%+v", err)
+		util.HandlerPackErrorResp(r.resp, consts.ErrorInternal, consts.DefaultToast)
+		return
+	}
+	r.resp.Message = "充值成功"
+}
+
+func (r RechargeBalanceHandler) checkParam() error {
+	return nil
+}
+
+func newRechargeBalanceHandler(ctx *gin.Context) *RechargeBalanceHandler {
+	return &RechargeBalanceHandler{
+		ctx:  ctx,
+		req:  http_model.NewRechargeBalanceResponse(),
+		resp: http_model.NewRechargeBalanceRequest(),
+	}
+}

+ 57 - 0
handler/transferToPublic.go

@@ -0,0 +1,57 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"youngee_m_api/consts"
+	"youngee_m_api/db"
+	"youngee_m_api/model/http_model"
+	"youngee_m_api/util"
+)
+
+func WrapTransferToPublicHandler(ctx *gin.Context) {
+	handler := newTransferToPublicHandler(ctx)
+	BaseRun(handler)
+}
+
+type TransferToPublicHandler struct {
+	ctx  *gin.Context
+	req  *http_model.TransferToPublicRequest
+	resp *http_model.CommonResponse
+}
+
+func (t TransferToPublicHandler) getContext() *gin.Context {
+	return t.ctx
+}
+
+func (t TransferToPublicHandler) getResponse() interface{} {
+	return t.resp
+}
+
+func (t TransferToPublicHandler) getRequest() interface{} {
+	return t.req
+}
+
+func (t TransferToPublicHandler) run() {
+	enterpriseID := t.req.EnterpriseID
+	err := db.TransferToPublic(t.ctx, t.req.Amount, enterpriseID, t.req.TransferVoucherUrl)
+	if err != nil {
+		logrus.Errorf("[TransferToPublicHandler] call TransferToPublic err:%+v\n", err)
+		util.HandlerPackErrorResp(t.resp, consts.ErrorInternal, "")
+		logrus.Info("TransferToPublic fail,req:%+v", t.req)
+		return
+	}
+	t.resp.Message = "转账成功,请等待管理员确认"
+}
+
+func (t TransferToPublicHandler) checkParam() error {
+	return nil
+}
+
+func newTransferToPublicHandler(ctx *gin.Context) *TransferToPublicHandler {
+	return &TransferToPublicHandler{
+		ctx:  ctx,
+		req:  http_model.NewTransferToPublicRequest(),
+		resp: http_model.NewTransferToPubliceResponse(),
+	}
+}

+ 21 - 0
model/gorm_model/invoice_address.go

@@ -0,0 +1,21 @@
+package gorm_model
+
+// Code generated by sql2gorm. DO NOT EDIT.
+
+import (
+	"time"
+)
+
+type YounggeeInvoiceAddress struct {
+	AddressID    int       `gorm:"column:address_id;primary_key;AUTO_INCREMENT"` // 发票收件地址id
+	EnterpriseID string    `gorm:"column:enterprise_id;NOT NULL"`                // 企业id
+	Name         string    `gorm:"column:name;NOT NULL"`                         // 收件人姓名
+	RegionCode   string    `gorm:"column:region_code;NOT NULL"`                  // 所在地区编码
+	Address      string    `gorm:"column:address;NOT NULL"`                      // 详细地址
+	Phone        string    `gorm:"column:phone;NOT NULL"`                        // 手机号码
+	UpdateAt     time.Time `gorm:"column:update_at;NOT NULL"`                    // 创建时间
+}
+
+func (m *YounggeeInvoiceAddress) TableName() string {
+	return "younggee_invoice_address"
+}

+ 1 - 0
model/http_model/InvoiceRecordsRequest.go

@@ -19,6 +19,7 @@ type InvoiceRecordsPreviews struct {
 	Amount         float64 `json:"amount"`
 	InvoiceType    string  `json:"invoice_type"`
 	InvoiceInfo    string  `json:"invoice_info"`
+	InvoiceAddress string  `json:"invoice_address"`
 	AddressInfo    string  `json:"address_info"`
 	ShipmentNumber string  `json:"shipment_number"` // 物流单号
 	Phone          string  `json:"phone"`

+ 19 - 0
model/http_model/QueryOrderByTradeIdRequest.go

@@ -0,0 +1,19 @@
+package http_model
+
+type QueryOrderByTradeIdRequest struct {
+	TradeId string `json:"trade_id"`
+}
+
+type OrderStatus struct {
+	Status string `json:"status"`
+}
+
+func NewQueryOrderByTradeIdRequest() *QueryOrderByTradeIdRequest {
+	return new(QueryOrderByTradeIdRequest)
+}
+
+func NewQueryOrderByTradeIdResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(OrderStatus)
+	return resp
+}

+ 14 - 0
model/http_model/RechargeBalanceRequest.go

@@ -0,0 +1,14 @@
+package http_model
+
+type RechargeBalanceRequest struct {
+	Amount       float64 `json:"amount"`
+	EnterpriseId string  `json:"enterprise_id"`
+}
+
+func NewRechargeBalanceResponse() *RechargeBalanceRequest {
+	return new(RechargeBalanceRequest)
+}
+
+func NewRechargeBalanceRequest() *CommonResponse {
+	return new(CommonResponse)
+}

+ 29 - 0
model/http_model/RechargeRecordRequest.go

@@ -0,0 +1,29 @@
+package http_model
+
+type RechargeRecordRequest struct {
+	ConfirmAt string `json:"confirm_at"`
+	Method    int    `json:"method"`
+}
+
+type RechargeRecordData struct {
+	RechargeId         string `json:"recharge_id"`
+	RechargeAmount     string `json:"recharge_amount"`
+	RechargeAmountReal string `json:"recharge_amount_real"`
+	PayMethod          string `json:"pay_method"`
+	TransferVoucher    string `json:"transfer_voucher"`
+	ConfirmAt          string `json:"confirm_at"`
+}
+
+type RechargeRecordPreview struct {
+	RechargeRecordData []*RechargeRecordData `json:"recharge_record_data"`
+}
+
+func NewRechargeRecordRequest() *RechargeRecordRequest {
+	return new(RechargeRecordRequest)
+}
+
+func NewRechargeRecordResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(RechargeRecordPreview)
+	return resp
+}

+ 15 - 0
model/http_model/TransferToPublicRequest.go

@@ -0,0 +1,15 @@
+package http_model
+
+type TransferToPublicRequest struct {
+	EnterpriseID       string  `json:"enterprise_id"`
+	Amount             float64 `json:"amount"`
+	TransferVoucherUrl string  `json:"transfer_voucher_url"`
+}
+
+func NewTransferToPublicRequest() *TransferToPublicRequest {
+	return new(TransferToPublicRequest)
+}
+
+func NewTransferToPubliceResponse() *CommonResponse {
+	return new(CommonResponse)
+}

+ 5 - 1
route/init.go

@@ -43,7 +43,11 @@ func InitRoute(r *gin.Engine) {
 		m.POST("/product/find", handler.WrapFindProductHandler)
 		m.POST("/product/deletePhotoUrl", handler.WrapDeletePhotoUrlHandler) // 在数据库中删除图片url
 		m.POST("/pay/paysum", handler.WrapPaySumHandler)
-		m.POST("/pay/projectpay", handler.WrapProjectPayHandler) // 支付
+		m.POST("/pay/projectpay", handler.WrapProjectPayHandler)                   // 支付
+		m.POST("/pay/getCodeUrl", handler.WrapGetCodeUrlHandler)                   // 获取微信支付codeURL
+		m.POST("/pay/queryOrderByTradeId", handler.WrapQueryOrderByTradeIdHandler) // 根据交易id查询微信是否扫码付款
+		m.POST("/pay/rechargeBalance", handler.WrapRechargeBalanceHandler)         // 支付成功后修改企业余额
+		m.POST("/project/transferToPublic", handler.WrapTransferToPublicHandler)   // 对公转账
 		m.POST("/project/update", handler.WrapUpdateProjectHandler)
 		m.POST("/project/approve", handler.WrapApproveProjectHandler)
 		m.POST("/project/all", handler.WrapGetAllProjectHandler)

+ 2 - 2
service/auto_task.go

@@ -204,8 +204,8 @@ func AutoTask() error {
 	}
 	//定时任务
 	//spec := "*/30 * * * * ?" //cron表达式,每10秒一次
-	spec := "0 */1 * * * ?" //cron表达式,每一分钟执行一次
-	//spec := "0 0 * * * *" //每小时执行
+	//spec := "0 */1 * * * ?" //cron表达式,每一分钟执行一次
+	spec := "0 0 * * * *" //每小时执行
 	// 添加定时任务,
 	_, err := crontab.AddFunc("@midnight", taskKDStatus)
 	//_, err := crontab.AddFunc("*/30 * * * * ?", taskKDStatus)

+ 93 - 43
service/project.go

@@ -153,8 +153,12 @@ func (*project) GetProjectTaskList(ctx context.Context, projectID string, pageSi
 }
 
 func (*project) Create(ctx context.Context, newProject http_model.CreateProjectRequest, enterpriseID string) (*http_model.CreateProjectData, error) {
-	fmt.Println("newProject:", newProject)
-	RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
+	fmt.Printf("newProject:%+v\n", newProject)
+	fmt.Println("newProject.RecruitDdl:", newProject.RecruitDdl)
+	RecruitDdl := time.Time{} //赋零值
+	if newProject.RecruitDdl != "" {
+		RecruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
+	}
 	// 查询关联商品信息
 	product, err := db.GetProductByID(ctx, newProject.ProductID)
 	if err != nil {
@@ -201,27 +205,51 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
 		}
 		td = "0" + td
 	}
+	fmt.Printf("RecruitDdl:%+v\n", RecruitDdl)
 	if newProject.ProjectType == int64(1) {
-		projectInfo = gorm_model.ProjectInfo{
-			ProjectID:        conv.MustString(time.Now().Year(), "")[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000, ""),
-			ProjectName:      projectName,
-			ProjectStatus:    1,
-			ProjectType:      newProject.ProjectType,
-			TalentType:       newProject.TalentType,
-			ProjectPlatform:  newProject.ProjectPlatform,
-			ProjectForm:      newProject.ProjectForm,
-			RecruitDdl:       &RecruitDdl,
-			ProjectDetail:    newProject.ProjectDetail,
-			ContentType:      newProject.ContentType,
-			EnterpriseID:     enterpriseID,
-			ProductID:        newProject.ProductID,
-			FeeForm:          feeForms,
-			AutoTaskID:       conv.MustInt64(AutoTaskID, 0),
-			AutoDefaultID:    conv.MustInt64(AutoDefaultID, 0),
-			EstimatedCost:    ECost,
-			IsRead:           0,
-			ProductSnap:      string(productInfoToJson),
-			ProductPhotoSnap: string(productPhotosToJson),
+		if newProject.RecruitDdl == "" {
+			projectInfo = gorm_model.ProjectInfo{
+				ProjectID:        conv.MustString(time.Now().Year(), "")[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000, ""),
+				ProjectName:      projectName,
+				ProjectStatus:    1,
+				ProjectType:      newProject.ProjectType,
+				TalentType:       newProject.TalentType,
+				ProjectPlatform:  newProject.ProjectPlatform,
+				ProjectForm:      newProject.ProjectForm,
+				ProjectDetail:    newProject.ProjectDetail,
+				ContentType:      newProject.ContentType,
+				EnterpriseID:     enterpriseID,
+				ProductID:        newProject.ProductID,
+				FeeForm:          feeForms,
+				AutoTaskID:       conv.MustInt64(AutoTaskID, 0),
+				AutoDefaultID:    conv.MustInt64(AutoDefaultID, 0),
+				EstimatedCost:    ECost,
+				IsRead:           0,
+				ProductSnap:      string(productInfoToJson),
+				ProductPhotoSnap: string(productPhotosToJson),
+			}
+		} else {
+			projectInfo = gorm_model.ProjectInfo{
+				ProjectID:        conv.MustString(time.Now().Year(), "")[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000, ""),
+				ProjectName:      projectName,
+				ProjectStatus:    1,
+				ProjectType:      newProject.ProjectType,
+				TalentType:       newProject.TalentType,
+				ProjectPlatform:  newProject.ProjectPlatform,
+				ProjectForm:      newProject.ProjectForm,
+				RecruitDdl:       &RecruitDdl,
+				ProjectDetail:    newProject.ProjectDetail,
+				ContentType:      newProject.ContentType,
+				EnterpriseID:     enterpriseID,
+				ProductID:        newProject.ProductID,
+				FeeForm:          feeForms,
+				AutoTaskID:       conv.MustInt64(AutoTaskID, 0),
+				AutoDefaultID:    conv.MustInt64(AutoDefaultID, 0),
+				EstimatedCost:    ECost,
+				IsRead:           0,
+				ProductSnap:      string(productInfoToJson),
+				ProductPhotoSnap: string(productPhotosToJson),
+			}
 		}
 	} else {
 		projectInfo = gorm_model.ProjectInfo{
@@ -266,7 +294,7 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
 		}
 	}
 	// build
-	if newProject.ProjectType == int64(1) {
+	if newProject.ProjectType == int64(1) && newProject.RecruitStrategys != nil {
 		var recruitStrategys []gorm_model.RecruitStrategy
 		for _, strategy := range newProject.RecruitStrategys {
 			// 查询对应定价策略
@@ -303,12 +331,16 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
 }
 
 func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectRequest, enterpriseID string) (*http_model.UpdateProjectData, error) {
-	RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
+	//RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
+	RecruitDdl := time.Time{} //赋零值
+	if newProject.RecruitDdl != "" {
+		RecruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
+	}
 	oldProject, err3 := db.GetProjectDetail(ctx, newProject.ProjectID)
 	if err3 != nil {
 		return nil, err3
 	}
-	feeFrom := []string{}
+	var feeFrom []string
 	for _, strategy := range newProject.RecruitStrategys {
 		feeFrom = append(feeFrom, strconv.FormatInt(strategy.FeeForm, 10))
 	}
@@ -325,20 +357,38 @@ func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectR
 			ECost += tmpCost
 		}
 	}
-	feeFroms := strings.Join(feeFrom, ",")
+	feeForms := strings.Join(feeFrom, ",")
 	t := time.Now()
-	project := gorm_model.ProjectInfo{
-		ProjectID:     newProject.ProjectID,
-		RecruitDdl:    &RecruitDdl,
-		TalentType:    newProject.TalentType,
-		ContentType:   conv.MustInt64(newProject.ContentType, 0),
-		ProjectDetail: newProject.ProjectDetail,
-		ProjectForm:   conv.MustInt64(newProject.ProjectForm, 0),
-		EnterpriseID:  enterpriseID,
-		ProjectStatus: int64(newProject.ProjectStatus),
-		FeeForm:       feeFroms,
-		EstimatedCost: ECost,
-		SubmitAt:      &t,
+	project := gorm_model.ProjectInfo{}
+	if newProject.RecruitDdl == "" {
+		project = gorm_model.ProjectInfo{
+			ProjectType:   newProject.ProjectType,
+			ProjectID:     newProject.ProjectID,
+			TalentType:    newProject.TalentType,
+			ContentType:   conv.MustInt64(newProject.ContentType, 0),
+			ProjectDetail: newProject.ProjectDetail,
+			ProjectForm:   conv.MustInt64(newProject.ProjectForm, 0),
+			EnterpriseID:  enterpriseID,
+			ProjectStatus: int64(newProject.ProjectStatus),
+			FeeForm:       feeForms,
+			EstimatedCost: ECost,
+			SubmitAt:      &t,
+		}
+	} else {
+		project = gorm_model.ProjectInfo{
+			ProjectType:   newProject.ProjectType,
+			ProjectID:     newProject.ProjectID,
+			RecruitDdl:    &RecruitDdl,
+			TalentType:    newProject.TalentType,
+			ContentType:   conv.MustInt64(newProject.ContentType, 0),
+			ProjectDetail: newProject.ProjectDetail,
+			ProjectForm:   conv.MustInt64(newProject.ProjectForm, 0),
+			EnterpriseID:  enterpriseID,
+			ProjectStatus: int64(newProject.ProjectStatus),
+			FeeForm:       feeForms,
+			EstimatedCost: ECost,
+			SubmitAt:      &t,
+		}
 	}
 	projectID, err := db.UpdateProject(ctx, project)
 	if err != nil {
@@ -349,10 +399,10 @@ func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectR
 	if err != nil {
 		return nil, err
 	}
-	fmt.Printf("照片:\t %+v", newProject.ProjectPhotos)
+	fmt.Printf("照片:\t %+v\n", newProject.ProjectPhotos)
 	if len(newProject.ProjectPhotos) != 0 {
 		// 新增图片
-		projectPhotos := []gorm_model.ProjectPhoto{}
+		var projectPhotos []gorm_model.ProjectPhoto
 		for _, photo := range newProject.ProjectPhotos {
 			projectPhoto := gorm_model.ProjectPhoto{
 				ProjectID: project.ProjectID,
@@ -371,10 +421,10 @@ func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectR
 	if err != nil {
 		return nil, err
 	}
-	//fmt.Printf("策略:\t %+v", newProject.RecruitStrategys)
-	if newProject.RecruitStrategys != nil {
+	fmt.Printf("招募策略:%+v \n", newProject.RecruitStrategys)
+	if newProject.RecruitStrategys != nil && newProject.ProjectType == 1 {
 		// 新增策略
-		RecruitStrategys := []gorm_model.RecruitStrategy{}
+		var RecruitStrategys []gorm_model.RecruitStrategy
 		for _, Strategy := range newProject.RecruitStrategys {
 			// 查询对应定价策略
 			pricingStrategy, err := db.GetPricingStrategy(ctx, Strategy.FollowersLow, Strategy.FollowersUp, Strategy.FeeForm, oldProject.ProjectPlatform)

+ 43 - 0
service/wechatPay.go

@@ -63,3 +63,46 @@ func NativeApiServicePrepay(tradeId string, amount int64) (codeUrl string, err e
 	}
 	return *resp.CodeUrl, nil
 }
+
+func QueryOrderByOutTradeNo(tradeId string) (status string, err error) {
+
+	var (
+		mchID                      string = "1615933939"                               // 商户号
+		mchCertificateSerialNumber string = "33DDFEC51BF5412F663B9B56510FD567B625FC68" // 商户证书序列号
+		mchAPIv3Key                string = "fvV2xDHuM8ch3QagCkLChEMsikUTSNiI"         // 商户APIv3密钥
+	)
+
+	// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
+	mchPrivateKey, err := utils.LoadPrivateKeyWithPath("./apiclient_key.pem")
+	if err != nil {
+		log.Print("load merchant private key error")
+	}
+
+	ctx := context.Background()
+	// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
+	opts := []core.ClientOption{
+		option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
+	}
+	client, err := core.NewClient(ctx, opts...)
+	if err != nil {
+		log.Printf("new wechat pay client err:%s", err)
+	}
+
+	svc := native.NativeApiService{Client: client}
+	resp, result, err := svc.QueryOrderByOutTradeNo(ctx,
+		native.QueryOrderByOutTradeNoRequest{
+			OutTradeNo: core.String(tradeId),
+			Mchid:      core.String("1615933939"),
+		},
+	)
+
+	if err != nil {
+		// 处理错误
+		log.Printf("call QueryOrderByOutTradeNo err:%s", err)
+		return "", err
+	} else {
+		// 处理返回结果
+		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
+	}
+	return *resp.TradeState, nil
+}

+ 28 - 0
util/type.go

@@ -82,3 +82,31 @@ func RemoveStrRepByMap(slc []string) []string {
 	}
 	return result
 }
+
+func GetDayNum(inputType string, inputData int) (int, error) {
+	result := 0
+	switch inputType {
+	case "year":
+		if inputData < 1 {
+			fmt.Println("年份错误!")
+			break
+		}
+		result = inputData
+	case "month":
+		months := []int{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}
+		if (inputData <= 12) && (inputData < 0) {
+			fmt.Println("月份错误!")
+			break
+		}
+		result = months[inputData-1]
+	case "day":
+		if (inputData < 0) && (inputData > 31) {
+			fmt.Println("日期错误!")
+			break
+		}
+		result = inputData
+	default:
+		return 0, fmt.Errorf("输入参数非法:%s", inputType)
+	}
+	return result, nil
+}