| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package acquirer_mkt_qr
- import (
- "context"
- "encoding/json"
- "git.i2edu.net/i2/i2-bill-api/internal/logic/user"
- "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 {
- return &types.Response{500, err.Error(), nil}, nil
- }
- bean := new(model.I2billAcquirerMktQrXorm)
- err = json.Unmarshal(body, bean)
- if err != nil {
- return &types.Response{500, err.Error(), nil}, nil
- }
- erpId, err := user.GetAcquirePerm(userId, l.svcCtx.Transformer, l.svcCtx.DB)
- if err != nil {
- return &types.Response{500, err.Error(), nil}, nil
- }
- if erpId == "" {
- return &types.Response{500, "请先申请兼职", nil}, nil
- }
- sql := `
- select
- qr.qudao_id,activity_id,school_id
- from
- i2bill_acquirer_mkt_qr qr
- inner join
- i2bill_mkt_part_time_user part
- on
- qr.user_id = part_user.id
- where
- part.mk_id = ? and qr.del_flag = 0 and part.del_flag = 0`
- acquirers, err := l.svcCtx.DB.SQL(sql, erpId).Query().List()
- if err != nil {
- return &types.Response{500, err.Error(), nil}, nil
- }
- if len(acquirers) == 0 {
- return &types.Response{500, "请选择渠道", nil}, nil
- }
- if bean.Id != 0 {
- bean.QudaoId, _ = acquirers[0]["qudao_id"].(int64)
- bean.ActivityId, _ = acquirers[0]["activity_id"].(int64)
- bean.SchoolId, _ = acquirers[0]["school_id"].(int64)
- }
- bean.QudaoId, _ = acquirers[0]["qudao_id"].(int64)
- bean.ActivityId, _ = acquirers[0]["activity_id"].(int64)
- bean.SchoolId, _ = acquirers[0]["school_id"].(int64)
- bean.UserId = userId
- bean.CreateTime = time.Now()
- bean.LastUpdateTime = bean.CreateTime
- bean.CreateBy = bean.UserId
- bean.LastUpdateBy = bean.CreateBy
- 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
- }
|