| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package acquirer_mkt_qr
- import (
- "context"
- "encoding/json"
- "git.i2edu.net/i2/i2-bill-api/model"
- "io/ioutil"
- "net/http"
- "time"
- "git.i2edu.net/i2/i2-bill-api/internal/svc"
- "git.i2edu.net/i2/i2-bill-api/internal/types"
- "git.i2edu.net/i2/go-zero/core/logx"
- )
- type AcquirerMktQrUpdateLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewAcquirerMktQrUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) AcquirerMktQrUpdateLogic {
- return AcquirerMktQrUpdateLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
- }
- func (l *AcquirerMktQrUpdateLogic) AcquirerMktQrUpdate(r *http.Request) (*types.Response, error) {
- // todo: add your logic here and delete this line
- userId := l.svcCtx.GetUserIdByJwt(l.ctx)
- body, err := ioutil.ReadAll(r.Body)
- if err != nil {
- logx.Error(err.Error())
- return &types.Response{500, err.Error(), nil}, nil
- }
- bean := new(model.I2billAcquirerMktQrXorm)
- err = json.Unmarshal(body, bean)
- if err != nil {
- logx.Error(err.Error())
- return &types.Response{500, err.Error(), nil}, nil
- }
- userInfo, err := model.GetI2bilUserInfo(userId, l.svcCtx.DB)
- if err != nil {
- logx.Error(err.Error())
- return &types.Response{500, err.Error(), nil}, nil
- }
- //mk
- if userInfo.ErpId != "" {
- erpId, err := model.GetErpUser("", userInfo.ErpId, l.svcCtx.Transformer)
- if err != nil {
- logx.Error(err.Error())
- return &types.Response{500, err.Error(), nil}, nil
- }
- if erpId == "" {
- return &types.Response{500, "未找到mk用户", nil}, nil
- }
- } else {
- //兼职
- partUser, err := model.GetPartTimeXormByUserId(userId, l.svcCtx.DB)
- if err != nil {
- logx.Error(err.Error())
- return &types.Response{500, err.Error(), nil}, nil
- }
- if partUser.Id == 0 {
- return &types.Response{500, "请先申请成为兼职", nil}, nil
- }
- bean.QudaoId = 1058
- bean.ActivityId = 0
- }
- acquirersQr := new(model.I2billAcquirerMktQrXorm)
- _, err = l.svcCtx.DB.Where("user_id = ? and del_flag = 0", userId).Get(acquirersQr)
- if err != nil {
- logx.Error(err.Error())
- return &types.Response{500, err.Error(), nil}, nil
- }
- if acquirersQr.Id != 0 {
- bean.LastUpdateTime = time.Now()
- bean.LastUpdateBy = userId
- _, err = l.svcCtx.DB.ID(acquirersQr.Id).AllCols().Update(bean)
- if err != nil {
- logx.Error(err.Error())
- return &types.Response{500, err.Error(), nil}, nil
- }
- return &types.Response{200, "", nil}, nil
- }
- bean.LastUpdateBy = userId
- bean.LastUpdateTime = time.Now()
- bean.CreateBy = userId
- bean.CreateTime = bean.LastUpdateTime
- bean.DelFlag = 0
- //生成二维码
- bean.Qr = "test.jpg"
- _, err = l.svcCtx.DB.Insert(bean)
- if err != nil {
- return &types.Response{500, err.Error(), nil}, nil
- }
- return &types.Response{200, "", nil}, nil
- }
|