From 85f3c9009e6f583dc9bb6f590518ee52c0756eca Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 31 Oct 2019 16:38:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E5=95=86=E5=9F=8E=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E4=BF=AE=E6=94=B9=E9=97=A8=E5=BA=97=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E6=97=B6=EF=BC=8C=E7=94=B5=E8=AF=9D=E5=8F=B7=E7=A0=81?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E6=97=B6=EF=BC=8C=E4=B9=9F=E8=A6=81=E6=9F=A5?= =?UTF-8?q?=E5=88=86=E7=BB=84=20=E5=A4=9A=E4=BA=8E=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E9=97=A8=E5=BA=97=E5=8C=B9=E9=85=8D=E6=97=B6=EF=BC=8C=E5=8F=AA?= =?UTF-8?q?=E5=A4=84=E7=90=86=E7=AC=AC=E4=B8=80=E4=B8=AA=EF=BC=8C=E4=B8=94?= =?UTF-8?q?=E4=B8=8D=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/cs/weimob_order.go | 29 +++++++++++++++++++++++++++-- business/cs/weimob_order_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 business/cs/weimob_order_test.go diff --git a/business/cs/weimob_order.go b/business/cs/weimob_order.go index 32189ab8b..c5f0a0ac2 100644 --- a/business/cs/weimob_order.go +++ b/business/cs/weimob_order.go @@ -3,6 +3,7 @@ package cs import ( "git.rosy.net.cn/baseapi/platformapi/weimobapi" "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/authz/autils" "git.rosy.net.cn/jx-callback/business/jxstore/cms" "git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" @@ -45,8 +46,8 @@ func onOrderMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackRespons func changeStoreSkusByOrder(order *weimobapi.OrderDetail) { globals.SugarLogger.Debugf("changeStoreSkusByOrder order:%s", utils.Format4Output(order, true)) receiverMobile := order.DeliveryDetail.LogisticsDeliveryDetail.ReceiverMobile - if storeList, err := dao.GetStoreList(dao.GetDB(), nil, []string{receiverMobile}, ""); err == nil { - if len(storeList) == 1 { + if storeList, err := GetStoreList4Mobile(dao.GetDB(), []string{receiverMobile}); err == nil { + if len(storeList) >= 1 { var skuBindInfos []*cms.StoreSkuBindInfo storeID := storeList[0].ID globals.SugarLogger.Debugf("changeStoreSkusByOrder storeID:%d", storeID) @@ -77,3 +78,27 @@ func changeStoreSkusByOrder(order *weimobapi.OrderDetail) { globals.SugarLogger.Warnf("changeStoreSkusByOrder receiverMobile:%s failed with err:%v", receiverMobile, err) } } + +func GetStoreList4Mobile(db *dao.DaoDB, mobileList []string) (storeList []*model.Store, err error) { + sql := ` + SELECT t1.* + FROM store t1 + WHERE t1.deleted_at = ?` + sqlParams := []interface{}{ + utils.DefaultTimeValue, + } + if len(mobileList) > 0 { + questionMarks := dao.GenQuestionMarks(len(mobileList)) + sql += " AND (t1.tel1 IN (" + questionMarks + ") OR t1.tel2 IN (" + questionMarks + `) + OR (SELECT + COUNT(*) + FROM casbin_rule t2 + JOIN user t3 ON t3.user_id = t2.v0 AND t3.mobile IN (` + questionMarks + `) + WHERE t2.v1 = CONCAT(?, t1.id) + ) > 0) + ` + sqlParams = append(sqlParams, mobileList, mobileList, mobileList, autils.NewStoreBossRole(-1).GetFullName()) + } + err = dao.GetRows(db, &storeList, sql, sqlParams...) + return storeList, err +} diff --git a/business/cs/weimob_order_test.go b/business/cs/weimob_order_test.go new file mode 100644 index 000000000..4e91a3fa6 --- /dev/null +++ b/business/cs/weimob_order_test.go @@ -0,0 +1,24 @@ +package cs + +import ( + "testing" + + "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/model/dao" + "git.rosy.net.cn/jx-callback/globals/api2" + "git.rosy.net.cn/jx-callback/globals/testinit" +) + +func init() { + testinit.Init() + api2.Init() +} + +func TestGetStoreList4Mobile(t *testing.T) { + storeList, err := GetStoreList4Mobile(dao.GetDB(), []string{"18180948107"}) + if err != nil { + t.Fatal(err) + } + t.Log(utils.Format4Output(storeList, false)) + t.Log(len(storeList)) +}