|
|
@@ -2,10 +2,12 @@ package logic
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
- "fmt"
|
|
|
+ "encoding/base64"
|
|
|
"git.i2edu.net/i2/i2-bill-api/internal/svc"
|
|
|
"git.i2edu.net/i2/i2-bill-api/internal/types"
|
|
|
+ "git.i2edu.net/i2/i2-bill-api/internal/utils"
|
|
|
"git.i2edu.net/i2/i2-bill-api/model"
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
|
|
|
"git.i2edu.net/i2/go-zero/core/logx"
|
|
|
@@ -27,57 +29,67 @@ func NewAcquirerStudentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|
|
|
|
|
func (l *AcquirerStudentAddLogic) AcquirerStudentAdd(req types.EnrollAddReq) (*types.Response, error) {
|
|
|
// todo: add your logic here and delete this line
|
|
|
+ //解析id
|
|
|
+ sign, err := base64.StdEncoding.DecodeString(req.Sign)
|
|
|
+ if err != nil {
|
|
|
+ logx.Error(err.Error())
|
|
|
+ return &types.Response{500, "二维码已失效", nil}, nil
|
|
|
+ }
|
|
|
+ userIdByte, err := utils.AesDecrypt(sign, []byte(l.svcCtx.Config.AesSecret))
|
|
|
+ if err != nil {
|
|
|
+ logx.Error(err.Error())
|
|
|
+ return &types.Response{500, "二维码已失效", nil}, nil
|
|
|
+ }
|
|
|
+ userId, err := strconv.ParseInt(string(userIdByte), 10, 64)
|
|
|
+ if err != nil {
|
|
|
+ logx.Error(err.Error())
|
|
|
+ return &types.Response{500, err.Error(), nil}, nil
|
|
|
+ }
|
|
|
+ //是否有权限收单
|
|
|
+ erpId, err := model.GetAcquirePerm(userId, l.svcCtx.Transformer, l.svcCtx.DB)
|
|
|
+ if err != nil {
|
|
|
+ logx.Error(err.Error())
|
|
|
+ return &types.Response{500, err.Error(), nil}, nil
|
|
|
+ }
|
|
|
+ if erpId == "" {
|
|
|
+ return &types.Response{500, "二维码已失效", nil}, nil
|
|
|
+ }
|
|
|
//去重
|
|
|
stu, err := l.svcCtx.DB.SQL("select * from i2bill_acquirer_student where stu_phone = ? and DATE_FORMAT(create_time,'%Y-%m-%d') = ? ", req.StuPhone, time.Now().Format("2006-01-02")).Query().List()
|
|
|
if err != nil {
|
|
|
+ logx.Error(err.Error())
|
|
|
return &types.Response{500, err.Error(), nil}, nil
|
|
|
}
|
|
|
if len(stu) > 0 {
|
|
|
return &types.Response{500, "你今天已提交过信息,感谢你的填写", nil}, nil
|
|
|
}
|
|
|
- bean := new(model.I2billAcquirerStudent)
|
|
|
+ bean := new(model.I2billAcquirerStudentXorm)
|
|
|
bean.AgeGroup = int64(req.AgeGroup)
|
|
|
- bean.StuPhone.String = req.StuPhone
|
|
|
- bean.Address.String = req.Address
|
|
|
- bean.UserId.Int64 = int64(req.UserId)
|
|
|
- partUserSql := fmt.Sprintf("select * from %s where user_id = ? and del_flag = 0 and check_state = ?", "i2bill_mkt_part_time_user")
|
|
|
- res, err := l.svcCtx.DB.SQL(partUserSql, req.UserId, 57).Query().List()
|
|
|
+ bean.StuPhone = req.StuPhone
|
|
|
+ bean.Address = req.Address
|
|
|
+ bean.UserId = userId
|
|
|
+ //获取渠道收单信息
|
|
|
+ acquirerInfo, err := model.GetAcquirerMktQr(userId, l.svcCtx.DB)
|
|
|
if err != nil {
|
|
|
+ logx.Error(err.Error())
|
|
|
return &types.Response{500, err.Error(), nil}, nil
|
|
|
}
|
|
|
- if len(res) < 1 {
|
|
|
- return &types.Response{500, "无效二维码", nil}, nil
|
|
|
- }
|
|
|
- bean.MkId.String = res[0]["mk_id"].(string)
|
|
|
- bean.NetworkDetailId.Int64 = int64(req.NetworkId)
|
|
|
- bean.ActiveId.Int64 = int64(req.ActiveId)
|
|
|
- bean.DelFlag = 0
|
|
|
- bean.CheckState.Int64 = 54
|
|
|
- bean.StuName.String = req.Name
|
|
|
- bean.StuLinkPerson.String = req.StuLinkPerson
|
|
|
- bean.SchId.Int64 = int64(req.SchId)
|
|
|
- bean.CreateTime.Time = time.Now()
|
|
|
- sql := `INSERT INTO i2bill_acquirer_student (stu_link_person,stu_phone,create_time,mk_id,user_id,address,
|
|
|
- check_state,stu_name,age_group,sch_id,del_flag,network_detail_id,active_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)`
|
|
|
- var args []interface{}
|
|
|
- args = append(args, sql,
|
|
|
- bean.StuLinkPerson.String, bean.StuPhone.String,
|
|
|
- bean.CreateTime.Time, bean.MkId.String, bean.UserId.Int64,
|
|
|
- bean.Address.String, bean.CheckState.Int64, bean.StuName.String,
|
|
|
- bean.AgeGroup, bean.SchId.Int64, bean.DelFlag)
|
|
|
- if req.NetworkId != 0 {
|
|
|
- args = append(args, req.NetworkId)
|
|
|
- } else {
|
|
|
- args = append(args, 1058)
|
|
|
- }
|
|
|
- if req.ActiveId != 0 {
|
|
|
- args = append(args, req.ActiveId)
|
|
|
- } else {
|
|
|
- args = append(args, nil)
|
|
|
+ if acquirerInfo.Id == 0 {
|
|
|
+ return &types.Response{500, "二维码已失效", nil}, nil
|
|
|
}
|
|
|
|
|
|
- _, err = l.svcCtx.DB.Exec(args...)
|
|
|
+ bean.MkId = erpId
|
|
|
+ bean.NetworkDetailId = acquirerInfo.QudaoId
|
|
|
+ bean.ActiveId = acquirerInfo.ActivityId
|
|
|
+ bean.DelFlag = 0
|
|
|
+ bean.CheckState = 54
|
|
|
+ bean.StuName = req.StuName
|
|
|
+ bean.StuLinkPerson = req.StuLinkPerson
|
|
|
+ bean.SchId = int64(req.SchId)
|
|
|
+ bean.CreateTime = time.Now()
|
|
|
+ _, err = l.svcCtx.DB.Insert(bean)
|
|
|
if err != nil {
|
|
|
+ logx.Error(err.Error())
|
|
|
return &types.Response{500, err.Error(), nil}, nil
|
|
|
}
|
|
|
return &types.Response{200, "", nil}, nil
|