|
|
@@ -3,7 +3,6 @@ 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"
|
|
|
@@ -34,55 +33,66 @@ func (l *AcquirerMktQrUpdateLogic) AcquirerMktQrUpdate(r *http.Request) (*types.
|
|
|
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
|
|
|
}
|
|
|
- erpId, err := user.GetAcquirePerm(userId, l.svcCtx.Transformer, l.svcCtx.DB)
|
|
|
+ userInfo, err := model.GetI2bilUserInfo(userId, 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
|
|
|
+ //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
|
|
|
}
|
|
|
- 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()
|
|
|
+ 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 len(acquirers) == 0 {
|
|
|
- return &types.Response{500, "请选择渠道", 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
|
|
|
}
|
|
|
- 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.LastUpdateBy = userId
|
|
|
+ bean.LastUpdateTime = time.Now()
|
|
|
+ bean.CreateBy = userId
|
|
|
+ bean.CreateTime = bean.LastUpdateTime
|
|
|
bean.DelFlag = 0
|
|
|
- bean.Qr = "test.jpg"
|
|
|
//生成二维码
|
|
|
+ bean.Qr = "test.jpg"
|
|
|
_, err = l.svcCtx.DB.Insert(bean)
|
|
|
if err != nil {
|
|
|
return &types.Response{500, err.Error(), nil}, nil
|