Просмотр исходного кода

新增兼职二维码,修正收单角色切换二维码更新

icole 4 лет назад
Родитель
Сommit
60d46b693b

+ 1 - 0
etc/i2bill-api.yaml

@@ -15,6 +15,7 @@ Weixin:
   Appid: wxb8a763ab9e81d0cb
   Secret: 95dc14b89d32fe91709bba8916f30f74
   SharePage: pages/stuInput/stuInput
+  SharePtPage: pages/addPtUser/addPtUser
 JwtAuth:
   AccessSecret: 6hy789iu87
   AccessExpire: 604800

+ 13 - 0
i2bill.api

@@ -197,6 +197,19 @@ service i2bill-api {
 	
 	@handler  MktPartTimeUserGet
 	get /api/v1/part_time_user/get  returns(Response)
+	
+}
+
+@server(
+	group: mkt_qr
+)
+
+service i2bill-api {
+	@handler MktQrAdd
+	post /api/v1/mkt_qr/add returns(Response)
+	
+	@handler MktQrGet
+	get /api/v1/mkt_qr/get returns(Response)
 }
 
 // 收单模块

+ 4 - 3
internal/config/config.go

@@ -7,9 +7,10 @@ import (
 )
 
 type Weixin struct {
-	Appid     string
-	Secret    string
-	SharePage string
+	Appid       string
+	Secret      string
+	SharePage   string
+	SharePtPage string
 }
 type Config struct {
 	rest.RestConf

+ 16 - 0
internal/handler/routes.go

@@ -13,6 +13,7 @@ import (
 	mkt_active "git.i2edu.net/i2/i2-bill-api/internal/handler/mkt_active"
 	mkt_network_detail "git.i2edu.net/i2/i2-bill-api/internal/handler/mkt_network_detail"
 	mkt_part_time_user "git.i2edu.net/i2/i2-bill-api/internal/handler/mkt_part_time_user"
+	mkt_qr "git.i2edu.net/i2/i2-bill-api/internal/handler/mkt_qr"
 	sys_optionset "git.i2edu.net/i2/i2-bill-api/internal/handler/sys_optionset"
 	system "git.i2edu.net/i2/i2-bill-api/internal/handler/system"
 	user "git.i2edu.net/i2/i2-bill-api/internal/handler/user"
@@ -99,6 +100,21 @@ func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
 		rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret),
 	)
 
+	engine.AddRoutes(
+		[]rest.Route{
+			{
+				Method:  http.MethodPost,
+				Path:    "/api/v1/mkt_qr/add",
+				Handler: mkt_qr.MktQrAddHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodGet,
+				Path:    "/api/v1/mkt_qr/get",
+				Handler: mkt_qr.MktQrGetHandler(serverCtx),
+			},
+		},
+	)
+
 	engine.AddRoutes(
 		[]rest.Route{
 			{

+ 6 - 1
internal/logic/acquirer_mkt_qr/acquirer_mkt_qr_get_logic.go

@@ -31,7 +31,7 @@ func NewAcquirerMktQrGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) A
 func (l *AcquirerMktQrGetLogic) AcquirerMktQrGet(r *http.Request) (*types.Response, error) {
 	// todo: add your logic here and delete this line
 	userId := l.svcCtx.GetUserIdByJwt(l.ctx)
-	erpUser, err := model.GetAcquirePerm(userId, l.svcCtx.Transformer, l.svcCtx.DB)
+	erpUser, err := model.GetAcquirePermInfo(userId, l.svcCtx.Transformer, l.svcCtx.DB)
 	if err != nil {
 		logx.Error(err.Error())
 		return &types.Response{500, err.Error(), nil}, nil
@@ -47,6 +47,11 @@ func (l *AcquirerMktQrGetLogic) AcquirerMktQrGet(r *http.Request) (*types.Respon
 	if qr.Id == 0 {
 		return &types.Response{200, "请先编辑收单二维码信息", nil}, nil
 	}
+
+	if erpUser.Role != qr.Role {
+		return &types.Response{200, "请先重新编辑收单二维码信息", nil}, nil
+	}
+
 	qr.Qr = strings.TrimLeft(qr.Qr, "/")
 	domain := strings.TrimRight(l.svcCtx.Config.AliYunOss.FileUrl, "/")
 	qr.Qr = domain + "/" + qr.Qr

+ 5 - 1
internal/logic/acquirer_mkt_qr/acquirer_mkt_qr_update_logic.go

@@ -60,6 +60,7 @@ func (l *AcquirerMktQrUpdateLogic) AcquirerMktQrUpdate(r *http.Request) (*types.
 		if erpUser == nil || erpUser.UserId == "" {
 			return &types.Response{500, "未找到mk用户", nil}, nil
 		}
+		bean.Role = 2
 		//ty = "mk"
 	} else {
 		//兼职
@@ -86,6 +87,8 @@ func (l *AcquirerMktQrUpdateLogic) AcquirerMktQrUpdate(r *http.Request) (*types.
 		bean.CallType = 1007
 		bean.MaType = 1445
 		bean.NetworkDetailId = 1058
+		bean.ActivityId = 0
+		bean.Role = 1
 	}
 	acquirersQr := new(model.I2billAcquirerMktQrXorm)
 	_, err = l.svcCtx.DB.Where("user_id = ? and del_flag = 0", userId).Get(acquirersQr)
@@ -102,7 +105,8 @@ func (l *AcquirerMktQrUpdateLogic) AcquirerMktQrUpdate(r *http.Request) (*types.
 		acquirersQr.CallType = bean.CallType
 		acquirersQr.MaType = bean.MaType
 		acquirersQr.NetworkDetailId = bean.NetworkDetailId
-		_, err = l.svcCtx.DB.ID(acquirersQr.Id).Cols("school_id", "activity_id", "quao_yji", "call_type", "ma_type", "network_detail_id", "last_update_time", "last_update_by").Update(acquirersQr)
+		acquirersQr.Role = bean.Role
+		_, err = l.svcCtx.DB.ID(acquirersQr.Id).Cols("school_id", "activity_id", "quao_yji", "call_type", "ma_type", "network_detail_id", "last_update_time", "last_update_by", "role").Update(acquirersQr)
 		if err != nil {
 			logx.Error(err.Error())
 			return &types.Response{500, err.Error(), nil}, nil

+ 2 - 9
internal/logic/acquirer_student/acquirer_student_add_logic.go

@@ -27,24 +27,17 @@ 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 := hex.DecodeString(req.Sign)
 	sign := req.Sign
 	if sign == "" {
 		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(sign, 10, 64)
 	if err != nil {
 		logx.Error(err.Error())
 		return &types.Response{500, err.Error(), nil}, nil
 	}
 	//是否有权限收单
-	erpUser, err := model.GetAcquirePerm(userId, l.svcCtx.Transformer, l.svcCtx.DB)
+	erpUser, err := model.GetAcquirePermInfo(userId, l.svcCtx.Transformer, l.svcCtx.DB)
 	if err != nil {
 		logx.Error(err.Error())
 		return &types.Response{500, err.Error(), nil}, nil
@@ -79,7 +72,7 @@ func (l *AcquirerStudentAddLogic) AcquirerStudentAdd(req types.EnrollAddReq) (*t
 		logx.Error(err.Error())
 		return &types.Response{500, err.Error(), nil}, nil
 	}
-	if acquirerInfo.Id == 0 {
+	if acquirerInfo.Id == 0 || acquirerInfo.Role != erpUser.Role {
 		return &types.Response{500, "二维码已失效", nil}, nil
 	}
 	bean.LoadSchId = acquirerInfo.SchoolId

+ 2 - 2
internal/logic/logic_test.go

@@ -12,10 +12,10 @@ import (
 func TestCreateJWT(t *testing.T) {
 	l := new(auth.LoginByWeixinLogic)
 	payloads := map[string]interface{}{
-		"userId":     12,
+		"userId":     37,
 		"sessionKey": "sessionKey",
 	}
-	fmt.Println(l.CreateJWT(1626053028, "6hy789iu87", payloads, 604800))
+	fmt.Println(l.CreateJWT(1626224284, "6hy789iu87", payloads, 604800))
 }
 
 func TestRflect(t *testing.T) {

+ 14 - 0
internal/logic/mkt_part_time_user/mkt_part_time_user_add_logic.go

@@ -2,6 +2,7 @@ package mkt_part_time_user
 
 import (
 	"context"
+	"fmt"
 	"git.i2edu.net/i2/i2-bill-api/model"
 	"time"
 
@@ -46,6 +47,19 @@ func (l *PartTimeUserAddLogic) PartTimeUserAdd(req types.PartTimeUserAddRequest)
 		}
 		return &types.Response{Code: 500, Msg: "你已经是兼职人员:", Data: nil}, nil
 	}
+	mkid := req.MkId
+	if len(req.MkId) >= 36 {
+		mkid = fmt.Sprintf("%s-%s-%s-%s", req.MkId[0:7], req.MkId[7:11], req.MkId[11:15], req.MkId[15:])
+	}
+
+	erpRes, err := model.GetErpUser("", mkid, l.svcCtx.Transformer)
+	if err != nil {
+		logx.Error(err.Error())
+		return &types.Response{Code: 500, Msg: err.Error(), Data: nil}, nil
+	}
+	if erpRes == nil {
+		return &types.Response{Code: 500, Msg: "二维码已失效", Data: nil}, nil
+	}
 	bean = &model.I2billMktPartTimeUser{
 		CreateTime:     time.Now(),
 		LastUpdateTime: time.Now(),

+ 105 - 0
internal/logic/mkt_qr/mkt_qr_add_logic.go

@@ -0,0 +1,105 @@
+package mk_qr
+
+import (
+	"context"
+	"encoding/json"
+	"fmt"
+	"git.i2edu.net/i2/i2-bill-api/model"
+	"io/ioutil"
+	"net/http"
+	"strings"
+	"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 MktQrAddLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewMktQrAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) MktQrAddLogic {
+	return MktQrAddLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *MktQrAddLogic) MktQrAdd(r *http.Request) (*types.Response, error) {
+	// todo: add your logic here and delete this line
+	type Mk struct {
+		MkId string `json:"mk_id"`
+	}
+	body, err := ioutil.ReadAll(r.Body)
+	defer r.Body.Close()
+	if err != nil {
+		return &types.Response{500, err.Error(), nil}, nil
+	}
+	var mk = new(Mk)
+	err = json.Unmarshal(body, mk)
+	if err != nil {
+		return &types.Response{500, err.Error(), nil}, nil
+	}
+	mk_id := mk.MkId
+	if mk_id == "" {
+		return &types.Response{500, "mk_id 不能为空", nil}, nil
+	}
+	erpRes, err := model.GetErpUser("", mk_id, l.svcCtx.Transformer)
+	if err != nil {
+		logx.Error(err.Error())
+		return &types.Response{Code: 500, Msg: err.Error(), Data: nil}, nil
+	}
+	if erpRes == nil {
+		return &types.Response{500, "权限不足", nil}, nil
+	}
+	bean := new(model.I2billMktQr)
+	_, err = l.svcCtx.DB.Where("mk_id = ? and del_flag = 0", mk_id).Get(bean)
+	if err != nil {
+		return &types.Response{500, err.Error(), nil}, nil
+	}
+	bean.MkId = mk_id
+	mk_id = strings.ReplaceAll(mk_id, "-", "")
+	if len(mk_id) > 32 {
+		return &types.Response{500, "mk_id 格式错误", nil}, nil
+	}
+	sceneStr := fmt.Sprintf("%s", mk_id)
+	atr, err := l.svcCtx.Wechat.GenQrCode(sceneStr, l.svcCtx.Config.Weixin.SharePtPage)
+	if err != nil {
+		logx.Error(err.Error())
+		return &types.Response{500, err.Error(), nil}, nil
+	}
+	if atr == nil || atr.Url == "" {
+		return &types.Response{500, "二维码生成失败", nil}, nil
+	}
+	_, err = l.svcCtx.DB.Insert(atr)
+	if err != nil {
+		logx.Error(err.Error())
+		return &types.Response{500, err.Error(), nil}, nil
+	}
+	if bean.Id != 0 {
+		bean.Qr = atr.Url
+		_, err = l.svcCtx.DB.ID(bean.Id).Cols("qr").Update(bean)
+		if err != nil {
+			logx.Error(err.Error())
+			return &types.Response{500, err.Error(), nil}, nil
+		}
+	} else {
+		bean.Qr = atr.Url
+		bean.CreateTime = time.Now()
+		bean.DelFlag = 0
+		_, err = l.svcCtx.DB.Insert(bean)
+		if err != nil {
+			logx.Error(err.Error())
+			return &types.Response{500, err.Error(), nil}, nil
+		}
+	}
+	bean.Qr = strings.TrimLeft(bean.Qr, "/")
+	domain := strings.TrimRight(l.svcCtx.Config.AliYunOss.FileUrl, "/")
+	bean.Qr = domain + "/" + bean.Qr
+	return &types.Response{200, "", bean}, nil
+}

+ 44 - 0
internal/logic/mkt_qr/mkt_qr_get_logic.go

@@ -0,0 +1,44 @@
+package mk_qr
+
+import (
+	"context"
+	"git.i2edu.net/i2/i2-bill-api/model"
+	"net/http"
+	"strings"
+
+	"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 MktQrGetLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewMktQrGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) MktQrGetLogic {
+	return MktQrGetLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *MktQrGetLogic) MktQrGet(r *http.Request) (*types.Response, error) {
+	// todo: add your logic here and delete this line
+	r.ParseForm()
+	mk_id := r.Form.Get("mk_id")
+	bean := new(model.I2billMktQr)
+	_, err := l.svcCtx.DB.Where("mk_id = ? and del_flag = 0", mk_id).Get(bean)
+	if err != nil {
+		return &types.Response{500, err.Error(), nil}, nil
+	}
+	if bean.Qr != "" {
+		bean.Qr = strings.TrimLeft(bean.Qr, "/")
+		domain := strings.TrimRight(l.svcCtx.Config.AliYunOss.FileUrl, "/")
+		bean.Qr = domain + "/" + bean.Qr
+	}
+	return &types.Response{200, "", bean}, nil
+}

+ 1 - 0
model/i2bill_acquirer_mkt_qr.sql

@@ -16,5 +16,6 @@ CREATE TABLE `i2bill_acquirer_mkt_qr`  (
   `create_by` int(11)  NULL DEFAULT NULL,
   `last_update_time` datetime(0) NULL DEFAULT NULL,
   `last_update_by` int(11) NULL DEFAULT NULL,
+  `role` int(11)  NULL DEFAULT NULL COMMENT '1-兼职2-mk',
   PRIMARY KEY (`id`) USING BTREE
 ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic;

+ 2 - 0
model/i2bill_acquirer_mkt_qr_model.go

@@ -48,6 +48,7 @@ type (
 		NetworkDetailId sql.NullInt64  `db:"network_detail_id" json:"network_detail_id"` //渠道四级
 		DelFlag         sql.NullInt64  `db:"del_flag" json:"del_flag"`
 		CreateTime      sql.NullTime   `db:"create_time" json:"create_time"`
+		Role            sql.NullInt64  `db:"role" json:"role"` //1-兼职2-mk
 	}
 	I2billAcquirerMktQrXorm struct {
 		SchoolId        int64     `json:"school_id"`
@@ -64,6 +65,7 @@ type (
 		NetworkDetailId int64     `json:"network_detail_id"` //渠道四级
 		DelFlag         int64     `json:"del_flag"`
 		CreateTime      time.Time `json:"create_time"`
+		Role            int64     `json:"role"` //1-兼职2-mk
 	}
 )
 

+ 10 - 0
model/i2bill_mkt_qr.sql

@@ -0,0 +1,10 @@
+--mk 兼职二维码--
+DROP TABLE IF EXISTS `i2bill_mkt_qr`;
+CREATE TABLE `i2bill_mkt_qr`  (
+  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
+  `qr` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci not NULL DEFAULT "" COMMENT '二维码url',
+  `mk_id` varchar(36) NOT NULL,
+  `del_flag` int(11)  NOT NULL DEFAULT 0,
+  `create_time` datetime(0) NOT NULL,
+  PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic;

+ 85 - 0
model/i2bill_mkt_qr_model.go

@@ -0,0 +1,85 @@
+package model
+
+import (
+	"database/sql"
+	"fmt"
+	"strings"
+	"time"
+
+	"git.i2edu.net/i2/go-zero/core/stores/sqlc"
+	"git.i2edu.net/i2/go-zero/core/stores/sqlx"
+	"git.i2edu.net/i2/go-zero/core/stringx"
+	"git.i2edu.net/i2/go-zero/tools/goctl/model/sql/builderx"
+)
+
+var (
+	i2billMktQrFieldNames          = builderx.RawFieldNames(&I2billMktQr{})
+	i2billMktQrRows                = strings.Join(i2billMktQrFieldNames, ",")
+	i2billMktQrRowsExpectAutoSet   = strings.Join(stringx.Remove(i2billMktQrFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
+	i2billMktQrRowsWithPlaceHolder = strings.Join(stringx.Remove(i2billMktQrFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
+)
+
+type (
+	I2billMktQrModel interface {
+		Insert(data I2billMktQr) (sql.Result, error)
+		FindOne(id int64) (*I2billMktQr, error)
+		Update(data I2billMktQr) error
+		Delete(id int64) error
+	}
+
+	defaultI2billMktQrModel struct {
+		conn  sqlx.SqlConn
+		table string
+	}
+
+	I2billMktQr struct {
+		MkId       string    `db:"mk_id" json:"mk_id"`
+		DelFlag    int64     `db:"del_flag" json:"del_flag"`
+		CreateTime time.Time `db:"create_time" json:"create_time"`
+		Id         int64     `db:"id" json:"id"` // 主键
+		Qr         string    `db:"qr" json:"qr"` // 二维码url
+	}
+)
+
+func NewI2billMktQrModel(conn sqlx.SqlConn) I2billMktQrModel {
+	return &defaultI2billMktQrModel{
+		conn:  conn,
+		table: "`i2bill_mkt_qr`",
+	}
+}
+
+func (t *I2billMktQr) TableName() string {
+	return "i2bill_mkt_qr"
+}
+
+func (m *defaultI2billMktQrModel) Insert(data I2billMktQr) (sql.Result, error) {
+	query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, i2billMktQrRowsExpectAutoSet)
+	ret, err := m.conn.Exec(query, data.MkId, data.DelFlag, data.Qr)
+	return ret, err
+}
+
+func (m *defaultI2billMktQrModel) FindOne(id int64) (*I2billMktQr, error) {
+	query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", i2billMktQrRows, m.table)
+	var resp I2billMktQr
+	err := m.conn.QueryRow(&resp, query, id)
+	switch err {
+	case nil:
+		return &resp, nil
+	case sqlc.ErrNotFound:
+		return nil, ErrNotFound
+	default:
+		return nil, err
+	}
+}
+
+func (m *defaultI2billMktQrModel) Update(data I2billMktQr) error {
+	query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, i2billMktQrRowsWithPlaceHolder)
+	_, err := m.conn.Exec(query, data.MkId, data.DelFlag, data.Qr, data.Id)
+	return err
+}
+
+func (m *defaultI2billMktQrModel) Delete(id int64) error {
+	query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
+	_, err := m.conn.Exec(query, id)
+	return err
+}

+ 38 - 0
model/i2bill_user_model.go

@@ -241,6 +241,44 @@ func GetAcquirePerm(userId int64, rpcClient transformclient.Transform, engine *x
 	return GetErpUser(user.Mobile, "", rpcClient)
 }
 
+type AcquirePermInfo struct {
+	*transform.GetErpRoleRes
+	Role int64 // 1 兼职,2mk
+}
+
+func GetAcquirePermInfo(userId int64, rpcClient transformclient.Transform, engine *xorm.Engine) (*AcquirePermInfo, error) {
+	//mk
+	user, err := GetI2bilUserInfo(userId, engine)
+	if err != nil {
+		return nil, err
+	}
+
+	erpInfo, err := GetErpUser(user.Mobile, "", rpcClient)
+	if err != nil {
+		return nil, err
+	}
+	if erpInfo != nil && erpInfo.UserId != "" {
+		return &AcquirePermInfo{erpInfo, 2}, nil
+	}
+
+	//兼职
+	partUser, err := GetPartTimeXormByUserId(userId, engine)
+	if err != nil {
+		return nil, err
+	}
+	if partUser.Id != 0 && partUser.MkId != "" {
+
+		erpInfo, err := GetErpUser("", partUser.MkId, rpcClient)
+		if err != nil {
+			return nil, err
+		}
+		if erpInfo != nil && erpInfo.UserId != "" {
+			return &AcquirePermInfo{erpInfo, 2}, nil
+		}
+	}
+	return nil, nil
+}
+
 func GetErpUser(mobile string, erpUserId string, rpcClient transformclient.Transform) (*transform.GetErpRoleRes, error) {
 	ctx := context.Background()
 	in := new(transform.GetErpRoleReq)