Prechádzať zdrojové kódy

erp权限校区,erp活动,修改二维码信息

icole 4 rokov pred
rodič
commit
2d9875d47a

+ 1 - 0
go.mod

@@ -7,6 +7,7 @@ go 1.16
 require (
 	git.i2edu.net/i2/go-zero v1.0.1-0.20210616091154-7fac117e009f
 	git.i2edu.net/i2/i2-bill-erp v0.0.0
+	github.com/boombuler/barcode v1.0.1 // indirect
 	github.com/clbanning/mxj v1.8.4 // indirect
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/go-sql-driver/mysql v1.6.0

+ 2 - 0
go.sum

@@ -35,6 +35,8 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
 github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4=
 github.com/bndr/gotabulate v1.1.2 h1:yC9izuZEphojb9r+KYL4W9IJKO/ceIO8HDwxMA24U4c=
 github.com/bndr/gotabulate v1.1.2/go.mod h1:0+8yUgaPTtLRTjf49E8oju7ojpU11YmXyvq1LbPAb3U=
+github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs=
+github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
 github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
 github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
 github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=

+ 19 - 2
internal/logic/acquirer_mkt_qr/acquirer_mkt_qr_get_logic.go

@@ -2,6 +2,7 @@ package acquirer_mkt_qr
 
 import (
 	"context"
+	"git.i2edu.net/i2/i2-bill-api/model"
 	"net/http"
 
 	"git.i2edu.net/i2/i2-bill-api/internal/svc"
@@ -26,6 +27,22 @@ 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
-
-	return &types.Response{}, nil
+	userId := l.svcCtx.GetUserIdByJwt(l.ctx)
+	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
+	}
+	qr, err := model.GetAcquirerMktQr(userId, l.svcCtx.DB)
+	if err != nil {
+		logx.Error(err.Error())
+		return &types.Response{500, err.Error(), nil}, nil
+	}
+	if qr.Id == 0 {
+		return &types.Response{500, "请先编辑收单二维码信息", nil}, nil
+	}
+	return &types.Response{200, "", qr}, nil
 }

+ 43 - 33
internal/logic/acquirer_mkt_qr/acquirer_mkt_qr_update_logic.go

@@ -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

+ 3 - 3
internal/logic/base_organ_school/get_erp_sch_perm_logic.go

@@ -2,7 +2,7 @@ package logic
 
 import (
 	"context"
-	"git.i2edu.net/i2/i2-bill-api/internal/logic/user"
+	"git.i2edu.net/i2/i2-bill-api/model"
 
 	"git.i2edu.net/i2/i2-bill-api/internal/svc"
 	"git.i2edu.net/i2/i2-bill-api/internal/types"
@@ -26,7 +26,7 @@ func NewGetErpSchPermLogic(ctx context.Context, svcCtx *svc.ServiceContext) GetE
 
 func (l *GetErpSchPermLogic) GetErpSchPerm() (*types.Response, error) {
 	// todo: add your logic here and delete this line
-	erpUserId, err := user.GetAcquirePerm(l.svcCtx.GetUserIdByJwt(l.ctx), l.svcCtx.Transformer, l.svcCtx.DB)
+	erpUserId, err := model.GetAcquirePerm(l.svcCtx.GetUserIdByJwt(l.ctx), l.svcCtx.Transformer, l.svcCtx.DB)
 	if err != nil {
 		logx.Error(err.Error())
 		return &types.Response{500, err.Error(), nil}, nil
@@ -34,7 +34,7 @@ func (l *GetErpSchPermLogic) GetErpSchPerm() (*types.Response, error) {
 	if erpUserId == "" {
 		return &types.Response{}, nil
 	}
-	school, err := user.GetUserSchoolPerm(erpUserId, l.svcCtx.Transformer, l.svcCtx.DB)
+	school, err := model.GetUserSchoolPerm(erpUserId, l.svcCtx.Transformer, l.svcCtx.DB)
 	if err != nil {
 		logx.Error(err.Error())
 		return &types.Response{500, err.Error(), nil}, nil

+ 0 - 63
internal/logic/user/user_erp_info.go

@@ -1,63 +0,0 @@
-package user
-
-import (
-	"context"
-	"errors"
-	"git.i2edu.net/i2/go-zero/core/logx"
-	"git.i2edu.net/i2/i2-bill-api/model"
-	"git.i2edu.net/i2/i2-bill-erp/transform"
-	"git.i2edu.net/i2/i2-bill-erp/transformclient"
-	"github.com/xormplus/xorm"
-	"strings"
-)
-
-func GetAcquirePerm(userId int64, rpcClient transformclient.Transform, engine *xorm.Engine) (string, error) {
-	//获取兼职
-	partUser := new(model.I2billMktPartTimeUser)
-	_, err := engine.SQL("select * from i2bill_mkt_part_time_user where del_flag = 0 and check_state = 57 and user_id = ?", userId).Get(partUser)
-	if err != nil {
-		return "", err
-	}
-	if partUser.Id != 0 {
-		return partUser.MkId, nil
-	}
-	//获取erp用户
-	user := new(model.User)
-	_, err = engine.SQL("select * from i2bill_user where del_flag = 0 and user_id = ?", userId).Get(user)
-	if err != nil {
-		return "", err
-	}
-	if user.Id == 0 {
-		logx.Error("用户不存在")
-		return "", errors.New("用户不存在")
-	}
-	ctx := context.Background()
-	in := new(transform.GetErpRoleReq)
-	in.Mobile = user.Mobile
-	erpRoles, err := rpcClient.GetErpRole(ctx, in)
-	if err != nil {
-		return "", err
-	}
-	//判定是不是 mk 还是 兼职
-	if erpRoles.UserId != "" {
-		roles := strings.Split(erpRoles.Role, ",")
-		for _, r := range roles {
-			if r == "LAMK" || r == "LAMKM" || r == "student/readingStudent" {
-				return erpRoles.UserId, nil
-			}
-		}
-
-	}
-	return "", nil
-}
-
-//获取校区权限
-func GetUserSchoolPerm(erpUserId string, rpcClient transformclient.Transform, engine *xorm.Engine) ([]*transform.OrganSchool, error) {
-	ctx := context.Background()
-	in := erpUserId
-	result, err := rpcClient.GetErpOrganSchPerByUserId(ctx, &transform.GetErpOrganSchPerByUserIdReq{UserId: in})
-	if err != nil {
-		return nil, err
-	}
-	return result.School, nil
-}

+ 26 - 0
internal/utils/utils.go

@@ -2,7 +2,11 @@ package utils
 
 import (
 	"database/sql"
+	"github.com/boombuler/barcode"
+	"github.com/boombuler/barcode/qr"
 	"hash/crc32"
+	"image/png"
+	"os"
 	"reflect"
 	"strconv"
 	"time"
@@ -127,3 +131,25 @@ func UnmarshalMysqlRow(row interface{}) map[string]interface{} {
 	}
 	return Row
 }
+
+//生成二维码
+func BuildBarcodeQr(url, dir string, width, height int) error {
+	code, err := qr.Encode(url, qr.M, qr.Unicode)
+	if err != nil {
+		return err
+	}
+	code, err = barcode.Scale(code, width, height)
+	if err != nil {
+		return err
+	}
+	file, err := os.Create(dir)
+	if err != nil {
+		return err
+	}
+	defer file.Close()
+	err = png.Encode(file, code)
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 7 - 0
model/i2bill_acquirer_mkt_qr_model.go

@@ -3,6 +3,7 @@ package model
 import (
 	"database/sql"
 	"fmt"
+	"github.com/xormplus/xorm"
 	"strings"
 	"time"
 
@@ -102,3 +103,9 @@ func (m *defaultI2billAcquirerMktQrModel) Delete(id int64) error {
 func (t *I2billAcquirerMktQrXorm) TableName() string {
 	return "i2bill_acquirer_mkt_qr"
 }
+
+func GetAcquirerMktQr(userId int64, engine *xorm.Engine) (*I2billAcquirerMktQrXorm, error) {
+	bean := new(I2billAcquirerMktQrXorm)
+	_, err := engine.Where("user_id = ? and del_flag = 0", userId).Get(bean)
+	return bean, err
+}

+ 28 - 1
model/i2bill_mkt_part_time_user_model.go

@@ -3,6 +3,7 @@ package model
 import (
 	"database/sql"
 	"fmt"
+	"github.com/xormplus/xorm"
 	"strings"
 	"time"
 
@@ -49,6 +50,23 @@ type (
 		CityId         int64     `db:"city_id" json:"city_id"` // 城市
 		CreateBy       string    `db:"create_by" json:"create_by"`
 	}
+	I2billMktPartTimeXorm struct {
+		CheckDesc      string    `db:"check_desc" json:"check_desc"` // 审核失败描述
+		UserId         int64     `db:"user_id" json:"user_id"`       // user_id
+		DelFlag        int64     `db:"del_flag" json:"del_flag"`
+		Name           string    `db:"name" json:"name"`
+		Sex            int64     `db:"sex" json:"sex"`
+		CheckState     int64     `db:"check_state" json:"check_state"` // 审核状态
+		CreateTime     time.Time `db:"create_time" json:"create_time"`
+		LastUpdateTime time.Time `db:"last_update_time" json:"last_update_time"`
+		LastUpdateBy   string    `db:"last_update_by" json:"last_update_by"`
+		Id             int64     `db:"id" json:"id"`
+		IponeNumber    string    `db:"ipone_number" json:"ipone_number"`
+		Target         int64     `db:"target" json:"target"`   // 目标人数
+		MkId           string    `db:"mk_id" json:"mk_id"`     // 所属erp mk id
+		CityId         int64     `db:"city_id" json:"city_id"` // 城市
+		CreateBy       string    `db:"create_by" json:"create_by"`
+	}
 )
 
 func NewI2billMktPartTimeUserModel(conn sqlx.SqlConn) I2billMktPartTimeUserModel {
@@ -58,7 +76,7 @@ func NewI2billMktPartTimeUserModel(conn sqlx.SqlConn) I2billMktPartTimeUserModel
 	}
 }
 
-func (t *I2billMktPartTimeUser) TableName() string {
+func (t *I2billMktPartTimeXorm) TableName() string {
 	return "i2bill_mkt_part_time_user"
 }
 
@@ -93,3 +111,12 @@ func (m *defaultI2billMktPartTimeUserModel) Delete(id int64) error {
 	_, err := m.conn.Exec(query, id)
 	return err
 }
+
+func GetPartTimeXormByUserId(userId int64, engine *xorm.Engine) (*I2billMktPartTimeXorm, error) {
+	partUser := new(I2billMktPartTimeXorm)
+	_, err := engine.SQL("select * from i2bill_mkt_part_time_user where del_flag = 0 and check_state = 57 and user_id = ?", userId).Get(partUser)
+	if err != nil {
+		return nil, err
+	}
+	return partUser, nil
+}

+ 84 - 1
model/i2bill_user_model.go

@@ -1,8 +1,12 @@
 package model
 
 import (
+	"context"
 	"database/sql"
 	"fmt"
+	"git.i2edu.net/i2/i2-bill-erp/transform"
+	"git.i2edu.net/i2/i2-bill-erp/transformclient"
+	"github.com/xormplus/xorm"
 	"strings"
 	"time"
 
@@ -70,7 +74,25 @@ func NewUserModel(conn sqlx.SqlConn, c cache.CacheConf) UserModel {
 	}
 }
 
-func (t *User) TableName() string {
+type UserXorm struct {
+	Mobile        string `json:"mobile"`
+	Avatar        string `json:"avatar"`
+	WeixinOpenid  string `json:"weixin_openid"`
+	Password      string `json:"password"`
+	Birthday      int64  `json:"birthday"`
+	RegisterTime  int64  `json:"register_time"`
+	LastLoginTime int64  `json:"last_login_time"`
+	Nickname      string `json:"nickname"`
+	Id            int64  `json:"id"`
+	ErpId         string `json:"erp_id"`
+	Username      string `json:"username"`
+	Gender        int64  `json:"gender"`
+	UserLevelId   int64  `json:"user_level_id"`
+	RegisterIp    string `json:"register_ip"`
+	LastLoginIp   string `json:"last_login_ip"`
+}
+
+func (t *UserXorm) TableName() string {
 	return "i2bill_user"
 }
 
@@ -190,3 +212,64 @@ func (m *defaultUserModel) SetWithExpire(key string, v interface{}, expire time.
 func (m *defaultUserModel) CacheStorage() Cache {
 	return m
 }
+
+//获取用户信息
+func GetI2bilUserInfo(userId int64, engine *xorm.Engine) (*UserXorm, error) {
+	user := new(UserXorm)
+	_, err := engine.SQL("select * from i2bill_user where id = ? and del_flag = 0", userId).Get(user)
+	if err != nil {
+		return nil, err
+	}
+	return user, nil
+}
+
+func GetAcquirePerm(userId int64, rpcClient transformclient.Transform, engine *xorm.Engine) (string, error) {
+
+	partUser, err := GetPartTimeXormByUserId(userId, engine)
+	if err != nil {
+		return "", err
+	}
+	if partUser.Id != 0 {
+		return GetErpUser("", partUser.MkId, rpcClient)
+	}
+
+	user, err := GetI2bilUserInfo(userId, engine)
+	if err != nil {
+		return "", err
+	}
+
+	return GetErpUser(user.Mobile, "", rpcClient)
+}
+
+func GetErpUser(mobile string, erpUserId string, rpcClient transformclient.Transform) (string, error) {
+	ctx := context.Background()
+	in := new(transform.GetErpRoleReq)
+	in.Mobile = mobile
+	in.UserId = erpUserId
+	erpRoles, err := rpcClient.GetErpRole(ctx, in)
+	if err != nil {
+		return "", err
+	}
+	//判定是不是 mk 还是 兼职
+	if erpRoles.UserId != "" {
+		roles := strings.Split(erpRoles.Role, ",")
+		for _, r := range roles {
+			if r == "LAMK" || r == "LAMKM" || r == "student/readingStudent" {
+				return erpRoles.UserId, nil
+			}
+		}
+
+	}
+	return "", nil
+}
+
+//获取校区权限
+func GetUserSchoolPerm(erpUserId string, rpcClient transformclient.Transform, engine *xorm.Engine) ([]*transform.OrganSchool, error) {
+	ctx := context.Background()
+	in := erpUserId
+	result, err := rpcClient.GetErpOrganSchPerByUserId(ctx, &transform.GetErpOrganSchPerByUserIdReq{UserId: in})
+	if err != nil {
+		return nil, err
+	}
+	return result.School, nil
+}