- 将微信的备注改为店名相关的信息
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/mobile"
|
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/mobile"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
@@ -134,6 +135,7 @@ func BindMobile(token, mobileNum, code, nickname string) (err error) {
|
|||||||
err = auth.ConvertErr2NoUser(dao.UpdateWeiXinUser(dao.GetDB(), mobileNum, nickname, wxUserinfo.UnionID, wxUserinfo.OpenID, ""), mobileNum)
|
err = auth.ConvertErr2NoUser(dao.UpdateWeiXinUser(dao.GetDB(), mobileNum, nickname, wxUserinfo.UnionID, wxUserinfo.OpenID, ""), mobileNum)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
jxutils.HandleUserWXRemark(nil, mobileNum)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,6 +164,7 @@ func BindMobile2(openid, secret, mobileNum, verifyCode, nickname string) (loginI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
jxutils.HandleUserWXRemark(nil, mobileNum)
|
||||||
return loginInfo, err
|
return loginInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/mobile"
|
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/mobile"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/weixin"
|
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/weixin"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
@@ -15,13 +16,6 @@ import (
|
|||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StoreUserInfo struct {
|
|
||||||
legacymodel.WeiXins
|
|
||||||
ParentMobile string `json:"parentMobile"`
|
|
||||||
Members []*legacymodel.WeiXins `orm:"-" json:"members"`
|
|
||||||
MembersStr string `json:"-"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
LoginTypeFieldMap = map[string]string{
|
LoginTypeFieldMap = map[string]string{
|
||||||
mobile.LoginType: "tel",
|
mobile.LoginType: "tel",
|
||||||
@@ -30,7 +24,7 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetStoreUsers(ctx *jxcontext.Context, storeID int) (storeUserInfos []*StoreUserInfo, err error) {
|
func GetStoreUsers(ctx *jxcontext.Context, storeID int) (storeUserInfos []*dao.StoreUserInfo, err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
SELECT t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
||||||
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"parentID":', t2.parentid, ',"tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
|
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"parentID":', t2.parentid, ',"tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
|
||||||
@@ -51,61 +45,32 @@ func GetStoreUsers(ctx *jxcontext.Context, storeID int) (storeUserInfos []*Store
|
|||||||
return storeUserInfos, err
|
return storeUserInfos, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUserInfo(ctx *jxcontext.Context, mobile string) (storeUserInfo *StoreUserInfo, err error) {
|
func GetUserInfo(ctx *jxcontext.Context, mobile string) (storeUserInfo *dao.StoreUserInfo, err error) {
|
||||||
sql := `
|
return dao.GetUserStoreInfo(dao.GetDB(), "tel", mobile)
|
||||||
SELECT t1.id, IF(t3.id IS NULL, t1.jxstoreid, t3.jxstoreid) jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
|
||||||
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
|
|
||||||
FROM weixins t1
|
|
||||||
LEFT JOIN weixins t2 ON t2.parentid = t1.id
|
|
||||||
LEFT JOIN weixins t3 ON t1.parentid = t3.id
|
|
||||||
WHERE t1.tel = ?
|
|
||||||
GROUP BY 1,2,3,4,5,6,7;
|
|
||||||
`
|
|
||||||
storeUserInfo = new(StoreUserInfo)
|
|
||||||
if err = dao.GetRow(nil, storeUserInfo, sql, mobile); err == nil {
|
|
||||||
if storeUserInfo.MembersStr != "" {
|
|
||||||
err = utils.UnmarshalUseNumber([]byte(storeUserInfo.MembersStr), &storeUserInfo.Members)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return storeUserInfo, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSelfInfo(ctx *jxcontext.Context) (storeUserInfo *StoreUserInfo, err error) {
|
func GetSelfInfo(ctx *jxcontext.Context) (storeUserInfo *dao.StoreUserInfo, err error) {
|
||||||
loginInfo := ctx.GetLoginInfo()
|
loginInfo := ctx.GetLoginInfo()
|
||||||
if loginInfo == nil {
|
if loginInfo == nil {
|
||||||
return nil, auth.ErrAPINeedRealLogin
|
return nil, auth.ErrAPINeedRealLogin
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldName := LoginTypeFieldMap[loginInfo.GetAuthType()]
|
fieldName := LoginTypeFieldMap[loginInfo.GetAuthType()]
|
||||||
if fieldName == "" {
|
if fieldName == "" {
|
||||||
return nil, auth.ErrIllegalLoginType
|
return nil, auth.ErrIllegalLoginType
|
||||||
}
|
}
|
||||||
sql := fmt.Sprintf(`
|
return dao.GetUserStoreInfo(dao.GetDB(), fieldName, loginInfo.GetAuthID())
|
||||||
SELECT t1.id, IF(t3.id IS NULL, t1.jxstoreid, t3.jxstoreid) jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
|
||||||
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
|
|
||||||
FROM weixins t1
|
|
||||||
LEFT JOIN weixins t2 ON t2.parentid = t1.id
|
|
||||||
LEFT JOIN weixins t3 ON t1.parentid = t3.id
|
|
||||||
WHERE t1.%s = ?
|
|
||||||
GROUP BY 1,2,3,4,5,6,7;
|
|
||||||
`, fieldName)
|
|
||||||
storeUserInfo = new(StoreUserInfo)
|
|
||||||
if err = dao.GetRow(nil, storeUserInfo, sql, loginInfo.GetAuthID()); err == nil || err == orm.ErrNoRows { // todo
|
|
||||||
err = nil
|
|
||||||
if storeUserInfo.MembersStr != "" {
|
|
||||||
err = utils.UnmarshalUseNumber([]byte(storeUserInfo.MembersStr), &storeUserInfo.Members)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return storeUserInfo, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnbindMobile(ctx *jxcontext.Context, mobile string) (num int64, err error) {
|
func UnbindMobile(ctx *jxcontext.Context, mobile string) (num int64, err error) {
|
||||||
return dao.UpdateEntityByKV(nil, &legacymodel.WeiXins{}, map[string]interface{}{
|
db := dao.GetDB()
|
||||||
|
num, err = dao.UpdateEntityByKV(db, &legacymodel.WeiXins{}, map[string]interface{}{
|
||||||
"JxStoreID": 0,
|
"JxStoreID": 0,
|
||||||
"ParentID": -1,
|
"ParentID": -1,
|
||||||
}, map[string]interface{}{
|
}, map[string]interface{}{
|
||||||
"Tel": mobile,
|
"Tel": mobile,
|
||||||
})
|
})
|
||||||
|
jxutils.HandleUserWXRemark(db, mobile)
|
||||||
|
return num, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func BindMobile2Store(ctx *jxcontext.Context, mobile string, storeID int) (num int64, err error) {
|
func BindMobile2Store(ctx *jxcontext.Context, mobile string, storeID int) (num int64, err error) {
|
||||||
@@ -126,6 +91,7 @@ func BindMobile2Store(ctx *jxcontext.Context, mobile string, storeID int) (num i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
jxutils.HandleUserWXRemark(db, mobile)
|
||||||
return num, err
|
return num, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,6 +123,7 @@ func AddMobile2Mobile(ctx *jxcontext.Context, parentMobile, mobile string) (num
|
|||||||
err = fmt.Errorf("%s本身是成员", parentMobile)
|
err = fmt.Errorf("%s本身是成员", parentMobile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
jxutils.HandleUserWXRemark(db, mobile)
|
||||||
return num, err
|
return num, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -892,3 +892,26 @@ func PrintMsg(ctx *jxcontext.Context, vendorID int, id1, id2, msgTitle, msgConte
|
|||||||
}
|
}
|
||||||
return handler.PrintMsg(ctx, id1, id2, msgTitle, msgContent)
|
return handler.PrintMsg(ctx, id1, id2, msgTitle, msgContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UpdateAllWeiXinRemark(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
|
var weixinList []*legacymodel.WeiXins
|
||||||
|
if err = dao.GetRows(dao.GetDB(), &weixinList, `
|
||||||
|
SELECT *
|
||||||
|
FROM weixins
|
||||||
|
WHERE openid <> '' AND tel <> ''
|
||||||
|
`); err == nil {
|
||||||
|
rootTask := tasksch.NewParallelTask("刷新微信备注", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||||
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
|
weixins := batchItemList[0].(*legacymodel.WeiXins)
|
||||||
|
err = jxutils.HandleUserWXRemark(dao.GetDB(), weixins.Tel)
|
||||||
|
return nil, err
|
||||||
|
}, weixinList)
|
||||||
|
tasksch.ManageTask(rootTask).Run()
|
||||||
|
if !isAsync {
|
||||||
|
_, err = rootTask.GetResult(0)
|
||||||
|
} else {
|
||||||
|
hint = rootTask.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hint, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/baseapi/utils/routinepool"
|
"git.rosy.net.cn/baseapi/utils/routinepool"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -385,3 +386,31 @@ func Strings2Objs(strAndObjAddPairs ...interface{}) (err error) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HandleUserWXRemark(db *dao.DaoDB, mobile string) (err error) {
|
||||||
|
if db == nil {
|
||||||
|
db = dao.GetDB()
|
||||||
|
}
|
||||||
|
wxinfo, err := dao.GetUserStoreInfo(db, "tel", mobile)
|
||||||
|
if err == nil {
|
||||||
|
if wxinfo.OpenID != "" {
|
||||||
|
remark := ""
|
||||||
|
if wxinfo.JxStoreID > 0 {
|
||||||
|
store := &model.Store{}
|
||||||
|
store.ID = wxinfo.JxStoreID
|
||||||
|
if err = dao.GetEntity(db, store); err == nil {
|
||||||
|
city := &model.Place{
|
||||||
|
Code: store.CityCode,
|
||||||
|
}
|
||||||
|
if err = dao.GetEntity(db, city, "Code"); err == nil {
|
||||||
|
remark = city.Name + "-" + store.Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
err = api.WeixinAPI.CBUpdateRemark(wxinfo.OpenID, remark)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,19 @@
|
|||||||
package dao
|
package dao
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type StoreUserInfo struct {
|
||||||
|
legacymodel.WeiXins
|
||||||
|
ParentMobile string `json:"parentMobile"`
|
||||||
|
Members []*legacymodel.WeiXins `orm:"-" json:"members"`
|
||||||
|
MembersStr string `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
func CreateWeiXins(db *DaoDB, user *legacymodel.WeiXins) (err error) {
|
func CreateWeiXins(db *DaoDB, user *legacymodel.WeiXins) (err error) {
|
||||||
Begin(db)
|
Begin(db)
|
||||||
if err = CreateEntity(db, user); err != nil {
|
if err = CreateEntity(db, user); err != nil {
|
||||||
@@ -87,3 +97,22 @@ func UpdateWeiXinUser(db *DaoDB, tel, nickname, unionID, openID, miniOpenID stri
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetUserStoreInfo(db *DaoDB, fieldName, fieldValue string) (storeUserInfo *StoreUserInfo, err error) {
|
||||||
|
sql := fmt.Sprintf(`
|
||||||
|
SELECT t1.id, IF(t3.id IS NULL, t1.jxstoreid, t3.jxstoreid) jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
||||||
|
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
|
||||||
|
FROM weixins t1
|
||||||
|
LEFT JOIN weixins t2 ON t2.parentid = t1.id
|
||||||
|
LEFT JOIN weixins t3 ON t1.parentid = t3.id
|
||||||
|
WHERE t1.%s = ?
|
||||||
|
GROUP BY 1,2,3,4,5,6,7;
|
||||||
|
`, fieldName)
|
||||||
|
if err = GetRow(db, &storeUserInfo, sql, fieldValue); err == nil { // todo
|
||||||
|
err = nil
|
||||||
|
if storeUserInfo.MembersStr != "" {
|
||||||
|
err = utils.UnmarshalUseNumber([]byte(storeUserInfo.MembersStr), &storeUserInfo.Members)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return storeUserInfo, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,3 +31,11 @@ func TestUpdateWeiXinUser(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetUserStoreInfo(t *testing.T) {
|
||||||
|
user, err := GetUserStoreInfo(GetDB(), "tel", "18180948107")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
globals.SugarLogger.Debug(utils.Format4Output(user, false))
|
||||||
|
}
|
||||||
|
|||||||
@@ -180,3 +180,18 @@ func (c *InitDataController) PrintMsg() {
|
|||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 刷新微信备注
|
||||||
|
// @Description 刷新微信备注
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param isAsync formData bool false "是否异步操作"
|
||||||
|
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /UpdateAllWeiXinRemark [post]
|
||||||
|
func (c *InitDataController) UpdateAllWeiXinRemark() {
|
||||||
|
c.callUpdateAllWeiXinRemark(func(params *tInitdataUpdateAllWeiXinRemarkParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
retVal, err = tempop.UpdateAllWeiXinRemark(params.Ctx, params.IsAsync, params.IsContinueWhenError)
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -457,6 +457,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:InitDataController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:InitDataController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "UpdateAllWeiXinRemark",
|
||||||
|
Router: `/UpdateAllWeiXinRemark`,
|
||||||
|
AllowHTTPMethods: []string{"post"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:InitDataController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:InitDataController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:InitDataController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:InitDataController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "UploadWeimobImg4SkuName",
|
Method: "UploadWeimobImg4SkuName",
|
||||||
|
|||||||
Reference in New Issue
Block a user