Compare commits
282 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e987ac99e | ||
|
|
99a073484b | ||
|
|
831a860ce2 | ||
|
|
610a7feeca | ||
|
|
6275b14570 | ||
|
|
b2bf89996f | ||
|
|
7b8be18bd6 | ||
|
|
14b55e118c | ||
|
|
fe59f8bca7 | ||
|
|
ede900560d | ||
|
|
376a5b89c2 | ||
|
|
cd3b091649 | ||
|
|
1df7d0b2c3 | ||
|
|
485e2ff3d7 | ||
|
|
898aca526d | ||
|
|
129a386f42 | ||
|
|
bbb9f2d906 | ||
|
|
1bc8826aac | ||
|
|
586490c31a | ||
|
|
a2a142e546 | ||
|
|
e138e49e27 | ||
|
|
9212f14ffd | ||
|
|
27379c8f3f | ||
|
|
331dd51255 | ||
|
|
29bb629928 | ||
|
|
a5652f24f3 | ||
|
|
299db632be | ||
|
|
dc8e726b26 | ||
|
|
4398b0dde6 | ||
|
|
404379287f | ||
|
|
1a5a0a798a | ||
|
|
2793c61436 | ||
|
|
bfd18f1e3c | ||
|
|
271889cb78 | ||
|
|
62722e26b9 | ||
|
|
ff8e97bb97 | ||
|
|
4a2213c856 | ||
|
|
4eb0810099 | ||
|
|
63fe824223 | ||
|
|
7ee376827b | ||
|
|
9ffc6dd32d | ||
|
|
80230993c6 | ||
|
|
7b4f62ad1c | ||
|
|
3555582349 | ||
|
|
1e220ea385 | ||
|
|
a5d516f340 | ||
|
|
690763db2c | ||
|
|
a7c6200601 | ||
|
|
396ab56265 | ||
|
|
4f0b158c7d | ||
|
|
c7fa7bce3d | ||
|
|
10736d0638 | ||
|
|
7a13c37ead | ||
|
|
782c970228 | ||
|
|
6eb1da80c8 | ||
|
|
c612b569e0 | ||
|
|
9dafa1729d | ||
|
|
e245405325 | ||
|
|
1e0194d4bb | ||
|
|
7881a34fec | ||
|
|
1e206d4af6 | ||
|
|
049a5ffc9f | ||
|
|
51390bf6ca | ||
|
|
c9f905b396 | ||
|
|
58f36787f5 | ||
|
|
e750422cee | ||
|
|
66516f7a47 | ||
|
|
8152b8daea | ||
|
|
6245d4fb61 | ||
|
|
fce2753666 | ||
|
|
d9ee8386a3 | ||
|
|
c41e99f7e0 | ||
|
|
74b18e1d4f | ||
|
|
3e064cf976 | ||
|
|
d082a3a70b | ||
|
|
0f6f54635e | ||
|
|
a84ad79665 | ||
|
|
a3ea6de99d | ||
|
|
4c37716fb1 | ||
|
|
a68affad2a | ||
|
|
4a0d0ee3df | ||
|
|
b30d35b72b | ||
|
|
7190d106ab | ||
|
|
174aacd231 | ||
|
|
f51c075891 | ||
|
|
4ed660ffe8 | ||
|
|
c3609b59b2 | ||
|
|
14fa03b586 | ||
|
|
8818dc957c | ||
|
|
123c0971da | ||
|
|
fec30ce3e7 | ||
|
|
0349b56a6f | ||
|
|
4266a5b0b9 | ||
|
|
c25bdc27f7 | ||
|
|
75ad109b81 | ||
|
|
035497d3ec | ||
|
|
23473d2648 | ||
|
|
80f26a9459 | ||
|
|
57da276469 | ||
|
|
b05b144bd9 | ||
|
|
eee17ff269 | ||
|
|
f8ee2f5508 | ||
|
|
001cf56863 | ||
|
|
4ae09764cb | ||
|
|
4759a2d6b5 | ||
|
|
7e2ac57300 | ||
|
|
c845eabe69 | ||
|
|
7efcd3a614 | ||
|
|
947a2a7ce4 | ||
|
|
26c613faad | ||
|
|
4df39d1d2b | ||
|
|
0a51e4bf7c | ||
|
|
50fceedd10 | ||
|
|
fde4807f95 | ||
|
|
30ef1b3588 | ||
|
|
b7a86c9003 | ||
|
|
b47fba8d37 | ||
|
|
4a655509ed | ||
|
|
7d3537dbc0 | ||
|
|
c21e5ab383 | ||
|
|
4430003475 | ||
|
|
0e59a39006 | ||
|
|
e92ee33ee0 | ||
|
|
c25f161f99 | ||
|
|
886785acc2 | ||
|
|
11d389a871 | ||
|
|
af603074d5 | ||
|
|
ef78df0887 | ||
|
|
88dc9adaad | ||
|
|
5e92c69f64 | ||
|
|
04c761ba5f | ||
|
|
f324fe4ce4 | ||
|
|
5e15d68b9f | ||
|
|
9f61711154 | ||
|
|
6e8b14ab3b | ||
|
|
2d3f85dbea | ||
|
|
cf59208d7a | ||
|
|
fecfd2ffe4 | ||
|
|
2bf71c9fec | ||
|
|
0fcdc4b32c | ||
|
|
3671e373ce | ||
|
|
5fd9ff5093 | ||
|
|
32e4c45ef1 | ||
|
|
847bd705bb | ||
|
|
a7df6a480a | ||
|
|
5aa919b200 | ||
|
|
c79c8c77ca | ||
|
|
f9c4f9fa50 | ||
|
|
c1b2f097c2 | ||
|
|
08e71bd933 | ||
|
|
2ca1dc93c2 | ||
|
|
46e8de37f8 | ||
|
|
7c92f47be5 | ||
|
|
24262f3812 | ||
|
|
7fbd055c47 | ||
|
|
25dce9601d | ||
|
|
46e420a892 | ||
|
|
12d6688b6f | ||
|
|
12c1f633cc | ||
|
|
b94de1d201 | ||
|
|
59cc2d4ffd | ||
|
|
1facd77f78 | ||
|
|
902a245674 | ||
|
|
2fd881f172 | ||
|
|
fb3027b34d | ||
|
|
0145f18912 | ||
|
|
c4068f4dfc | ||
|
|
b002522cf0 | ||
|
|
d55fe9f988 | ||
|
|
a0a859cf77 | ||
|
|
7e251151c6 | ||
|
|
802366f44c | ||
|
|
647ed0a861 | ||
|
|
7c968cb91c | ||
|
|
1677bbbee3 | ||
|
|
fd69d4dda0 | ||
|
|
26f5087072 | ||
|
|
97a48e5267 | ||
|
|
38b2a5363b | ||
|
|
9aafc7da9a | ||
|
|
c0388be7c5 | ||
|
|
7284949cd7 | ||
|
|
d083ca165e | ||
|
|
b020d4bf11 | ||
|
|
ce62b2d01a | ||
|
|
ddfdd6c5c2 | ||
|
|
dc0f14021d | ||
|
|
faf6d4ff91 | ||
|
|
688c17613c | ||
|
|
19229449d4 | ||
|
|
467d9b1456 | ||
|
|
3f34e06eae | ||
|
|
ae1ee4d1cb | ||
|
|
572a14d171 | ||
|
|
cf3d09b39a | ||
|
|
41f36bd16c | ||
|
|
3af00e3aad | ||
|
|
a920e1fe80 | ||
|
|
7a1fb943de | ||
|
|
27655b80a5 | ||
|
|
1690888782 | ||
|
|
2ef51857b5 | ||
|
|
e7460cabc5 | ||
|
|
f588a2be99 | ||
|
|
3ab96bce79 | ||
|
|
49e72ab6bf | ||
|
|
da91dbf2d7 | ||
|
|
24974efe5f | ||
|
|
a25a63b316 | ||
|
|
335d981dee | ||
|
|
5e493288f0 | ||
|
|
60277b42d4 | ||
|
|
39e0999481 | ||
|
|
a5d4a1c5d1 | ||
|
|
754749ff4d | ||
|
|
295d790dab | ||
|
|
c20d156e19 | ||
|
|
a7315eeb12 | ||
|
|
8a0d844adb | ||
|
|
2574622760 | ||
|
|
cc5eb45624 | ||
|
|
9aac434f1a | ||
|
|
9ad4d52352 | ||
|
|
2131a724a6 | ||
|
|
3fa0cbdfe7 | ||
|
|
0584eeb643 | ||
|
|
c89c320ee9 | ||
|
|
2ee949830a | ||
|
|
1697a85de6 | ||
|
|
85868a322e | ||
|
|
a85684bb96 | ||
|
|
43b6c24919 | ||
|
|
c5863204c8 | ||
|
|
349d760a50 | ||
|
|
8374e410f4 | ||
|
|
3aec25bbdd | ||
|
|
92b6d309e4 | ||
|
|
aa0eee9812 | ||
|
|
89e48b0979 | ||
|
|
585eb0e0de | ||
|
|
58fba95c0f | ||
|
|
c650ae418d | ||
|
|
0ed3d3afa7 | ||
|
|
1df97c4106 | ||
|
|
99300a8715 | ||
|
|
5a54d537b5 | ||
|
|
20fbd266f4 | ||
|
|
a1abcff2d5 | ||
|
|
052c1362e0 | ||
|
|
30a41b59f4 | ||
|
|
7ae08dea69 | ||
|
|
457bfbf6d0 | ||
|
|
21ab3d159e | ||
|
|
749de1b0e9 | ||
|
|
5418ace2fc | ||
|
|
e54e865ce5 | ||
|
|
97cc8cce0d | ||
|
|
ee02691601 | ||
|
|
466ca12c91 | ||
|
|
b336512a5b | ||
|
|
cfcab79a6d | ||
|
|
2cc0e81445 | ||
|
|
408efdb631 | ||
|
|
df481cd2b5 | ||
|
|
f2f7928068 | ||
|
|
cb0f8c2001 | ||
|
|
829b00d3c8 | ||
|
|
5bbcda5b5f | ||
|
|
1b213dc31f | ||
|
|
bfe94e735a | ||
|
|
8993e48ae9 | ||
|
|
fda538ce92 | ||
|
|
e09d175fa8 | ||
|
|
e1e735ff46 | ||
|
|
179f3f1146 | ||
|
|
940af4b622 | ||
|
|
dedef13719 | ||
|
|
f2178a7548 | ||
|
|
537fa7b7ea | ||
|
|
e4c5cfba61 | ||
|
|
5b79b92566 | ||
|
|
c2c9f99c68 |
@@ -10,8 +10,8 @@ import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"github.com/dchest/captcha"
|
||||
@@ -340,18 +340,6 @@ func AddAuthBind(user IUser, newAuthInfo *AuthInfo) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func AddAuthBindWithMobile(authInfo *AuthInfo, mobile string) (err error) {
|
||||
if handler := authers[authInfo.AuthBindInfo.Type]; handler != nil {
|
||||
user, _ := dao.GetUserByID(dao.GetDB(), "mobile", mobile)
|
||||
authInfo.AuthBindInfo.UserID = user.UserID
|
||||
//handler.UnbindAuth(user.GetID(), newAuthInfo.GetAuthType(), newAuthInfo.GetAuthTypeID(), user.GetName())
|
||||
err = handler.AddAuthBind(authInfo.AuthBindInfo, user.GetName())
|
||||
} else {
|
||||
err = ErrIllegalAuthType
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func UnbindAuth(userID, authType, authTypeID, userName string) (err error) {
|
||||
globals.SugarLogger.Debugf("UnbindAuth userID:%s, authType:%s, authTypeID:%s, userName:%s", userID, authType, authTypeID, userName)
|
||||
if handler := authers[authType]; handler != nil {
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package alipay
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/alipayapi"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
const (
|
||||
AuthType = "alipaycode"
|
||||
)
|
||||
|
||||
type Auther struct {
|
||||
authprovider.DefAuther
|
||||
}
|
||||
|
||||
var (
|
||||
AutherObj *Auther
|
||||
)
|
||||
|
||||
func init() {
|
||||
AutherObj = new(Auther)
|
||||
auth2.RegisterAuther(AuthType, AutherObj)
|
||||
}
|
||||
|
||||
func (a *Auther) VerifySecret(dummy, code string) (authBindEx *auth2.AuthBindEx, err error) {
|
||||
globals.SugarLogger.Debugf("VerifySecret dummy:%s, code:%s", dummy, code)
|
||||
tokenInfo, err := api.AliPayAPI.SystemAuthToken(alipayapi.GrantTypeCode, code, "")
|
||||
if err == nil {
|
||||
userInfo, err2 := api.AliPayAPI.UserInfoShare(tokenInfo.AccessToken)
|
||||
if err = err2; err == nil {
|
||||
if authBindEx, err = a.UnionFindAuthBind(AuthType, api.AliPayAPI.GetAppID(), nil, userInfo.UserID, "", userInfo); err == nil {
|
||||
authBindEx.UserHint = &auth2.UserBasic{
|
||||
Name: userInfo.NickName,
|
||||
Avatar: userInfo.Avatar,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return authBindEx, err
|
||||
}
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package dingding
|
||||
|
||||
const (
|
||||
AuthTypeStaff = "ddstaff" // 钉钉企业登录
|
||||
AuthTypeQRCode = "ddqrcode"
|
||||
)
|
||||
@@ -1,37 +0,0 @@
|
||||
package dingding
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
type QRCodeAuther struct {
|
||||
authprovider.DefAuther
|
||||
}
|
||||
|
||||
var (
|
||||
AutherObjQRCode *QRCodeAuther
|
||||
)
|
||||
|
||||
func init() {
|
||||
AutherObjQRCode = new(QRCodeAuther)
|
||||
auth2.RegisterAuther(AuthTypeQRCode, AutherObjQRCode)
|
||||
}
|
||||
|
||||
func (a *QRCodeAuther) VerifySecret(dummy, code string) (authBindEx *auth2.AuthBindEx, err error) {
|
||||
globals.SugarLogger.Debugf("dingding qrcode VerifySecret code:%s", code)
|
||||
|
||||
userQRInfo, err := api.DingDingQRCodeAPI.GetUserInfoByCode(code)
|
||||
if err == nil {
|
||||
globals.SugarLogger.Debugf("dingding qrcode VerifySecret code:%s, userQRInfo:%s", code, utils.Format4Output(userQRInfo, false))
|
||||
if authBindEx, err = a.UnionFindAuthBind(AuthTypeQRCode, api.DingDingQRCodeAPI.GetAppID(), []string{AuthTypeStaff, AuthTypeQRCode}, userQRInfo.OpenID, userQRInfo.UnionID, userQRInfo); err == nil {
|
||||
authBindEx.UserHint = &auth2.UserBasic{
|
||||
Name: userQRInfo.Nickname,
|
||||
}
|
||||
}
|
||||
}
|
||||
return authBindEx, err
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package dingding
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
type StaffAuther struct {
|
||||
authprovider.DefAuther
|
||||
}
|
||||
|
||||
var (
|
||||
AutherObjStaff *StaffAuther
|
||||
)
|
||||
|
||||
func init() {
|
||||
AutherObjStaff = new(StaffAuther)
|
||||
auth2.RegisterAuther(AuthTypeStaff, AutherObjStaff)
|
||||
}
|
||||
|
||||
func (a *StaffAuther) VerifySecret(dummy, code string) (authBindEx *auth2.AuthBindEx, err error) {
|
||||
globals.SugarLogger.Debugf("dingding staff VerifySecret code:%s", code)
|
||||
|
||||
userID, err := api.DingDingAPI.GetUserID(code)
|
||||
if err == nil {
|
||||
userDetail, err2 := api.DingDingAPI.GetUserDetail(userID.UserID)
|
||||
if err = err2; err == nil {
|
||||
if authBindEx, err = a.UnionFindAuthBind(AuthTypeStaff, api.DingDingQRCodeAPI.GetAppID(), []string{AuthTypeStaff, AuthTypeQRCode}, userID.UserID, utils.Interface2String(userDetail["unionid"]), userDetail); err == nil {
|
||||
authBindEx.UserHint = &auth2.UserBasic{
|
||||
UserID2: userID.UserID,
|
||||
Mobile: utils.Interface2String(userDetail["mobile"]),
|
||||
Email: utils.Interface2String(userDetail["email"]),
|
||||
Name: utils.Interface2String(userDetail["name"]),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return authBindEx, err
|
||||
}
|
||||
|
||||
func (a *StaffAuther) GetUserType() (userType int8) {
|
||||
return model.UserTypeOperator
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
aliyunsmsclient "github.com/KenmyZhang/aliyun-communicate"
|
||||
)
|
||||
|
||||
const (
|
||||
AuthType = auth2.AuthTypeMobile
|
||||
TestVerifyCode = "123456"
|
||||
)
|
||||
|
||||
var (
|
||||
warningMap = map[string]int{
|
||||
"isv.AMOUNT_NOT_ENOUGH": 1,
|
||||
"isv.ACCOUNT_ABNORMAL": 1,
|
||||
"isv.OUT_OF_SERVICE": 1,
|
||||
"isv.DAY_LIMIT_CONTROL": 1,
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
ErrVerifyCodeIsWrong = errors.New("验证码错")
|
||||
)
|
||||
|
||||
type Auther struct {
|
||||
authprovider.DefAuther
|
||||
}
|
||||
|
||||
var (
|
||||
AutherObj *Auther
|
||||
)
|
||||
|
||||
func init() {
|
||||
AutherObj = new(Auther)
|
||||
auth2.RegisterAuther(AuthType, AutherObj)
|
||||
}
|
||||
|
||||
// 特殊接口
|
||||
func (a *Auther) SendVerifyCode(mobileNumber string) (verifyCode string, err error) {
|
||||
verifyCode = fmt.Sprintf("%06d", rand.Intn(1000000))
|
||||
globals.SugarLogger.Debugf("SendVerifyCode code: %v", verifyCode)
|
||||
// a.GenerateVerifyCode(mobileNumber)
|
||||
smsClient := aliyunsmsclient.New("http://dysmsapi.aliyuncs.com/")
|
||||
response, err := smsClient.Execute(globals.AliKey, globals.AliSecret, mobileNumber, globals.SMSSignName, globals.SMSMobileVerifyTemplate, string(utils.MustMarshal(map[string]interface{}{
|
||||
"code": verifyCode,
|
||||
})))
|
||||
a.SaveVerifyCode(mobileNumber, verifyCode)
|
||||
if err == nil && response.Code == aliyunsmsclient.ResponseCodeOk {
|
||||
// a.SaveVerifyCode(mobileNumber, verifyCode)
|
||||
} else {
|
||||
if err == nil {
|
||||
if warningMap[response.Code] == 1 {
|
||||
globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with response:%s", mobileNumber, utils.Format4Output(response, false))
|
||||
} else {
|
||||
globals.SugarLogger.Infof("SendVerifyCode mobileNumber:%s failed with response:%s", mobileNumber, utils.Format4Output(response, false))
|
||||
}
|
||||
err = fmt.Errorf("发送短信出错:%s", response.Message)
|
||||
} else {
|
||||
globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with error:%v", mobileNumber, err)
|
||||
}
|
||||
}
|
||||
return verifyCode, err
|
||||
}
|
||||
|
||||
func (a *Auther) VerifySecret(mobileNumber, code string) (authBindEx *auth2.AuthBindEx, err error) {
|
||||
globals.SugarLogger.Debugf("VerifySecret mobileNumber:%s, code:%s", mobileNumber, code)
|
||||
def := &authprovider.DefAuther{}
|
||||
err = ErrVerifyCodeIsWrong
|
||||
savedVerifyCode := def.LoadVerifyCode(mobileNumber)
|
||||
if code == auth2.InternalAuthSecret ||
|
||||
auth2.TestMobileMap[mobileNumber] == 1 && code == TestVerifyCode || (code != "" && savedVerifyCode != "" && code == savedVerifyCode) {
|
||||
// || a.VerifyCode(mobileNumber, code)
|
||||
err = nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 此函数为空
|
||||
func (a *Auther) AddAuthBind(authBindEx *auth2.AuthBindEx, userName string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// 此函数为空
|
||||
func (a *Auther) UnbindAuth(userID, authType, authTypeID, userName string) (err error) {
|
||||
return err
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
package password
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
const (
|
||||
AuthType = auth2.AuthTypePassword
|
||||
)
|
||||
|
||||
type Auther struct {
|
||||
authprovider.DefAuther
|
||||
}
|
||||
|
||||
var (
|
||||
AutherObj *Auther
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUserAndPassNotMatch = errors.New("用户名密码不匹配")
|
||||
)
|
||||
|
||||
func init() {
|
||||
AutherObj = new(Auther)
|
||||
auth2.RegisterAuther(AuthType, AutherObj)
|
||||
}
|
||||
|
||||
func (a *Auther) VerifySecret(userID, passMD5 string) (authBindEx *auth2.AuthBindEx, err error) {
|
||||
globals.SugarLogger.Debugf("localpass VerifySecret userID:%s", userID)
|
||||
var authBind *model.AuthBind
|
||||
if authBind, err = dao.GetAuthBind(dao.GetDB(), model.AuthBindTypeAuth, AuthType, userID); err == nil {
|
||||
if err = a.checkPassword(authBind, passMD5); err == nil {
|
||||
authBindEx = &auth2.AuthBindEx{
|
||||
AuthBind: *authBind,
|
||||
}
|
||||
}
|
||||
} else if dao.IsNoRowsError(err) {
|
||||
err = auth2.ErrUserAuthTypeNotExist
|
||||
}
|
||||
return authBindEx, err
|
||||
}
|
||||
|
||||
// 特殊接口
|
||||
func (a *Auther) ChangePassword(userID, userName, oldPassMD5, newPassMD5 string) (err error) {
|
||||
var authBind *model.AuthBind
|
||||
db := dao.GetDB()
|
||||
salt := utils.GetUUID()
|
||||
encryptPwd := a.encryptPassword(newPassMD5, salt)
|
||||
if authBind, err = dao.GetAuthBind(db, model.AuthBindTypeAuth, AuthType, userID); err == nil {
|
||||
if err = a.checkPassword(authBind, oldPassMD5); err == nil || authBind.AuthSecret == "" { // 如果原密码为空,不判断原密码,代表重置密码
|
||||
_, err = dao.UpdateEntityLogically(db, authBind, map[string]interface{}{
|
||||
"AuthSecret": encryptPwd,
|
||||
"AuthSecret2": salt,
|
||||
}, userName, nil)
|
||||
}
|
||||
} else if dao.IsNoRowsError(err) {
|
||||
err = a.AddAuthBind(&auth2.AuthBindEx{
|
||||
AuthBind: model.AuthBind{
|
||||
UserID: userID,
|
||||
Type: AuthType,
|
||||
AuthID: userID,
|
||||
AuthSecret: encryptPwd,
|
||||
AuthSecret2: salt,
|
||||
},
|
||||
}, userName)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *Auther) encryptPassword(password, salt string) string {
|
||||
return fmt.Sprintf("%x", sha1.Sum([]byte(password+salt)))
|
||||
}
|
||||
|
||||
func (a *Auther) checkPassword(authBind *model.AuthBind, passMD5 string) (err error) {
|
||||
if authBind.AuthSecret != a.encryptPassword(passMD5, authBind.AuthSecret2) {
|
||||
return ErrUserAndPassNotMatch
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
package weixin
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
const (
|
||||
AuthTypeWeixin = "wxqrcode" // 微信扫码
|
||||
AuthTypeMP = "weixinsns" // 公众号
|
||||
AuthTypeWXNative = "wxnative" // 微信APP
|
||||
AuthTypeWxApp = "weixinapp" //app微信登录
|
||||
)
|
||||
|
||||
type Auther struct {
|
||||
authprovider.DefAuther
|
||||
authType string
|
||||
}
|
||||
|
||||
var (
|
||||
AutherObjWX *Auther
|
||||
AutherObjMP *Auther
|
||||
AutherObjNative *Auther
|
||||
AutherObjApp *Auther
|
||||
)
|
||||
|
||||
var (
|
||||
ErrStateIsWrong = errors.New("登录state非法")
|
||||
)
|
||||
|
||||
func init() {
|
||||
AutherObjWX = &Auther{
|
||||
authType: AuthTypeWeixin,
|
||||
}
|
||||
auth2.RegisterAuther(AuthTypeWeixin, AutherObjWX)
|
||||
|
||||
AutherObjMP = &Auther{
|
||||
authType: AuthTypeMP,
|
||||
}
|
||||
auth2.RegisterAuther(AuthTypeMP, AutherObjMP)
|
||||
|
||||
AutherObjNative = &Auther{
|
||||
authType: AuthTypeWXNative,
|
||||
}
|
||||
auth2.RegisterAuther(AuthTypeWXNative, AutherObjNative)
|
||||
|
||||
AutherObjApp = &Auther{
|
||||
authType: AuthTypeWxApp,
|
||||
}
|
||||
auth2.RegisterAuther(AuthTypeWxApp, AutherObjApp)
|
||||
}
|
||||
|
||||
func (a *Auther) VerifySecret(id, secret string) (authBindEx *auth2.AuthBindEx, err error) {
|
||||
globals.SugarLogger.Debugf("weixin VerifySecret id:%s secret:%s", secret, secret)
|
||||
var openID, accessToken string
|
||||
if a.authType != AuthTypeWXNative {
|
||||
state := id
|
||||
code := secret
|
||||
if state == "" {
|
||||
token, err2 := a.getAPI().SNSRetrieveToken(code)
|
||||
if err = err2; err == nil {
|
||||
openID = token.OpenID
|
||||
accessToken = token.AccessToken
|
||||
}
|
||||
} else {
|
||||
err = ErrStateIsWrong
|
||||
}
|
||||
} else {
|
||||
openID = id
|
||||
accessToken = secret
|
||||
}
|
||||
if err == nil {
|
||||
wxUserinfo, err2 := a.getAPI().SNSGetUserInfo(accessToken, openID)
|
||||
if err = err2; err == nil {
|
||||
if authBindEx, err = a.UnionFindAuthBind(a.authType, a.getAPI().GetAppID(), []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini, AuthTypeWXNative, AuthTypeWxApp}, wxUserinfo.OpenID, wxUserinfo.UnionID, wxUserinfo); err == nil {
|
||||
authBindEx.UserHint = &auth2.UserBasic{
|
||||
Name: wxUserinfo.NickName,
|
||||
Avatar: wxUserinfo.HeadImgURL,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return authBindEx, err
|
||||
}
|
||||
|
||||
func (a *Auther) getAPI() *weixinapi.API {
|
||||
if a.authType == AuthTypeWeixin {
|
||||
return api.WeixinPageAPI
|
||||
}
|
||||
if a.authType == AuthTypeWxApp {
|
||||
return api.WeixinApp
|
||||
}
|
||||
return api.WeixinAPI
|
||||
}
|
||||
|
||||
func (a *Auther) GetUserType() (userType int8) {
|
||||
return model.UserTypeStoreBoss
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package weixin
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
const (
|
||||
AuthTypeMini = "weixinmini" // 小程序
|
||||
)
|
||||
|
||||
type MiniAuther struct {
|
||||
authprovider.DefAuther
|
||||
}
|
||||
|
||||
var (
|
||||
ErrAuthTypeShouldBeMini = errors.New("当前操作要求是小程序登录方式")
|
||||
)
|
||||
|
||||
var (
|
||||
AutherObjMini *MiniAuther
|
||||
)
|
||||
|
||||
func init() {
|
||||
AutherObjMini = new(MiniAuther)
|
||||
auth2.RegisterAuther(AuthTypeMini, AutherObjMini)
|
||||
}
|
||||
|
||||
func (a *MiniAuther) VerifySecret(dummy, jsCode string) (authBindEx *auth2.AuthBindEx, err error) {
|
||||
globals.SugarLogger.Debugf("weixin mini VerifySecret jsCode:%s", jsCode)
|
||||
|
||||
appID, jsCode := SplitJsCode(jsCode)
|
||||
sessionInfo, err := getWxApp(appID).SNSCode2Session(jsCode)
|
||||
if err == nil {
|
||||
sessionKey := sessionInfo.SessionKey
|
||||
sessionInfo.SessionKey = ""
|
||||
if authBindEx, err = a.UnionFindAuthBind(AuthTypeMini, getWxApp(appID).GetAppID(), []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini, AuthTypeWXNative}, sessionInfo.OpenID, sessionInfo.UnionID, sessionInfo); err == nil {
|
||||
authBindEx.UserData = sessionKey
|
||||
}
|
||||
}
|
||||
return authBindEx, err
|
||||
}
|
||||
|
||||
// 特殊接口
|
||||
func (a *MiniAuther) DecryptData(authInfo *auth2.AuthInfo, jsCode, encryptedData, iv string) (decryptedDataBase64 string, err error) {
|
||||
globals.SugarLogger.Debugf("weixin mini DecryptData jsCode:%s, encryptedData:%s, iv:%s", jsCode, encryptedData, iv)
|
||||
var sessionKey string
|
||||
appID, jsCode := SplitJsCode(jsCode)
|
||||
if jsCode != "" {
|
||||
sessionInfo, err := getWxApp(appID).SNSCode2Session(jsCode)
|
||||
if err == nil {
|
||||
// if authBindEx, err := a.UnionFindAuthBind(AuthTypeMini, getWxApp(appID).GetAppID(), []string{AuthTypeMini}, sessionInfo.OpenID, "", nil); err == nil {
|
||||
// if authBindEx.UserID != authInfo.GetID() {
|
||||
// return "", fmt.Errorf("jsCode与token不匹配")
|
||||
// }
|
||||
// } else {
|
||||
// return "", err
|
||||
// }
|
||||
sessionKey = sessionInfo.SessionKey
|
||||
} else {
|
||||
return "", err
|
||||
}
|
||||
} else {
|
||||
if authInfo.AuthBindInfo.Type != AuthTypeMini {
|
||||
return "", ErrAuthTypeShouldBeMini
|
||||
}
|
||||
sessionKey = authInfo.AuthBindInfo.UserData.(string)
|
||||
}
|
||||
// decryptedData, err := ProxySNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||
decryptedData, err := weixinapi.SNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// authInfo.AuthBindInfo.UserData = sessionKey
|
||||
return string(decryptedData), nil
|
||||
}
|
||||
|
||||
func (a *MiniAuther) GetUserType() (userType int8) {
|
||||
return model.UserTypeStoreBoss
|
||||
}
|
||||
|
||||
func getWxApp(appID string) (miniApi *weixinapi.API) {
|
||||
miniApi = api.WeixinMiniAPI
|
||||
return miniApi
|
||||
}
|
||||
|
||||
func SplitJsCode(jsCode string) (appID, realJsCode string) {
|
||||
list := strings.Split(jsCode, ",")
|
||||
if len(list) == 2 {
|
||||
appID = list[0]
|
||||
realJsCode = list[1]
|
||||
} else if len(list) == 1 {
|
||||
realJsCode = jsCode
|
||||
} else {
|
||||
globals.SugarLogger.Warnf("SplitJsCode abnormal jsCode:%s", jsCode)
|
||||
}
|
||||
return appID, realJsCode
|
||||
}
|
||||
|
||||
func ComposeJsCode(appID, jsCode string) (composedCode string) {
|
||||
composedCode = strings.Join([]string{
|
||||
appID,
|
||||
jsCode,
|
||||
}, ",")
|
||||
return composedCode
|
||||
}
|
||||
|
||||
// func ProxySNSCode2Session(jsCode string) (sessionInfo *weixinapi.SessionInfo, err error) {
|
||||
// miniApi := api.WeixinMiniAPI
|
||||
// list := strings.Split(jsCode, ",")
|
||||
// if len(list) >= 2 && len(list[0]) == len("wx4b5930c13f8b1170") {
|
||||
// if list[0] == api.WeixinMiniAppID2 {
|
||||
// miniApi = api.WeixinMiniAPI2
|
||||
// }
|
||||
// miniApi = getWxApp(list[0])
|
||||
// jsCode = strings.Join(list[1:], ",")
|
||||
// }
|
||||
// sessionInfo, err = miniApi.SNSCode2Session(jsCode)
|
||||
// return sessionInfo, err
|
||||
// }
|
||||
|
||||
// func ProxySNSDecodeMiniProgramData(encryptedData, sessionKey, iv string) (decryptedData []byte, err error) {
|
||||
// globals.SugarLogger.Debugf("ProxySNSDecodeMiniProgramData, encryptedData:%s, sessionKey:%s, iv:%s", encryptedData, sessionKey, iv)
|
||||
// decryptedData, err = api.WeixinMiniAPI.SNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||
// return decryptedData, err
|
||||
// }
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/authz"
|
||||
"git.rosy.net.cn/jx-callback/business/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
|
||||
func GetRoleDescription(name string, storeID int) (description string) {
|
||||
|
||||
@@ -1,171 +0,0 @@
|
||||
package casbinauth
|
||||
|
||||
import (
|
||||
jxmodel "git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/astaxie/beego/client/orm"
|
||||
"github.com/casbin/casbin/model"
|
||||
"github.com/casbin/casbin/persist"
|
||||
)
|
||||
|
||||
type Adapter struct {
|
||||
}
|
||||
|
||||
// finalizer is the destructor for Adapter.
|
||||
func finalizer(a *Adapter) {
|
||||
}
|
||||
|
||||
func NewAdapter() *Adapter {
|
||||
return &Adapter{}
|
||||
}
|
||||
|
||||
func loadPolicyLine(line jxmodel.CasbinRule, model model.Model) {
|
||||
lineText := line.PType
|
||||
if line.V0 != "" {
|
||||
lineText += ", " + line.V0
|
||||
}
|
||||
if line.V1 != "" {
|
||||
lineText += ", " + line.V1
|
||||
}
|
||||
if line.V2 != "" {
|
||||
lineText += ", " + line.V2
|
||||
}
|
||||
if line.V3 != "" {
|
||||
lineText += ", " + line.V3
|
||||
}
|
||||
if line.V4 != "" {
|
||||
lineText += ", " + line.V4
|
||||
}
|
||||
if line.V5 != "" {
|
||||
lineText += ", " + line.V5
|
||||
}
|
||||
|
||||
persist.LoadPolicyLine(lineText, model)
|
||||
}
|
||||
|
||||
func (a *Adapter) LoadPolicy(model model.Model) error {
|
||||
var lines []jxmodel.CasbinRule
|
||||
o := orm.NewOrm()
|
||||
_, err := o.QueryTable("casbin_rule").Limit(-1).All(&lines)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, line := range lines {
|
||||
loadPolicyLine(line, model)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func savePolicyLine(ptype string, rule []string) jxmodel.CasbinRule {
|
||||
line := jxmodel.CasbinRule{}
|
||||
|
||||
line.PType = ptype
|
||||
if len(rule) > 0 {
|
||||
line.V0 = rule[0]
|
||||
}
|
||||
if len(rule) > 1 {
|
||||
line.V1 = rule[1]
|
||||
}
|
||||
if len(rule) > 2 {
|
||||
line.V2 = rule[2]
|
||||
}
|
||||
if len(rule) > 3 {
|
||||
line.V3 = rule[3]
|
||||
}
|
||||
if len(rule) > 4 {
|
||||
line.V4 = rule[4]
|
||||
}
|
||||
if len(rule) > 5 {
|
||||
line.V5 = rule[5]
|
||||
}
|
||||
|
||||
return line
|
||||
}
|
||||
|
||||
func (a *Adapter) clearAll(o orm.Ormer) (err error) {
|
||||
_, err = o.Raw(`
|
||||
DELETE t1
|
||||
FROM casbin_rule t1
|
||||
`).Exec()
|
||||
return err
|
||||
}
|
||||
|
||||
// SavePolicy saves policy to database.
|
||||
func (a *Adapter) SavePolicy(model model.Model) error {
|
||||
globals.SugarLogger.Debugf("SavePolicy")
|
||||
o := orm.NewOrm()
|
||||
|
||||
a.clearAll(o)
|
||||
var lines []jxmodel.CasbinRule
|
||||
|
||||
for ptype, ast := range model["p"] {
|
||||
for _, rule := range ast.Policy {
|
||||
line := savePolicyLine(ptype, rule)
|
||||
lines = append(lines, line)
|
||||
}
|
||||
}
|
||||
|
||||
for ptype, ast := range model["g"] {
|
||||
for _, rule := range ast.Policy {
|
||||
line := savePolicyLine(ptype, rule)
|
||||
lines = append(lines, line)
|
||||
}
|
||||
}
|
||||
|
||||
_, err := o.InsertMulti(len(lines), lines)
|
||||
return err
|
||||
}
|
||||
|
||||
// AddPolicy adds a policy rule to the storage.
|
||||
func (a *Adapter) AddPolicy(sec string, ptype string, rule []string) error {
|
||||
o := orm.NewOrm()
|
||||
line := savePolicyLine(ptype, rule)
|
||||
_, err := o.Insert(&line)
|
||||
return err
|
||||
}
|
||||
|
||||
// RemovePolicy removes a policy rule from the storage.
|
||||
func (a *Adapter) RemovePolicy(sec string, ptype string, rule []string) error {
|
||||
o := orm.NewOrm()
|
||||
line := savePolicyLine(ptype, rule)
|
||||
_, err := o.Delete(&line, "p_type", "v0", "v1", "v2", "v3", "v4", "v5")
|
||||
return err
|
||||
}
|
||||
|
||||
// RemoveFilteredPolicy removes policy rules that match the filter from the storage.
|
||||
func (a *Adapter) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error {
|
||||
line := jxmodel.CasbinRule{}
|
||||
|
||||
line.PType = ptype
|
||||
filter := []string{}
|
||||
filter = append(filter, "p_type")
|
||||
if fieldIndex <= 0 && 0 < fieldIndex+len(fieldValues) {
|
||||
line.V0 = fieldValues[0-fieldIndex]
|
||||
filter = append(filter, "v0")
|
||||
}
|
||||
if fieldIndex <= 1 && 1 < fieldIndex+len(fieldValues) {
|
||||
line.V1 = fieldValues[1-fieldIndex]
|
||||
filter = append(filter, "v1")
|
||||
}
|
||||
if fieldIndex <= 2 && 2 < fieldIndex+len(fieldValues) {
|
||||
line.V2 = fieldValues[2-fieldIndex]
|
||||
filter = append(filter, "v2")
|
||||
}
|
||||
if fieldIndex <= 3 && 3 < fieldIndex+len(fieldValues) {
|
||||
line.V3 = fieldValues[3-fieldIndex]
|
||||
filter = append(filter, "v3")
|
||||
}
|
||||
if fieldIndex <= 4 && 4 < fieldIndex+len(fieldValues) {
|
||||
line.V4 = fieldValues[4-fieldIndex]
|
||||
filter = append(filter, "v4")
|
||||
}
|
||||
if fieldIndex <= 5 && 5 < fieldIndex+len(fieldValues) {
|
||||
line.V5 = fieldValues[5-fieldIndex]
|
||||
filter = append(filter, "v5")
|
||||
}
|
||||
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Delete(&line, filter...)
|
||||
return err
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package casbinauth
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/authz"
|
||||
"git.rosy.net.cn/jx-callback/business/authz/autils"
|
||||
"github.com/casbin/casbin"
|
||||
"github.com/casbin/casbin/errors"
|
||||
)
|
||||
|
||||
type CasbinAuthz struct {
|
||||
enforcer *casbin.SyncedEnforcer
|
||||
}
|
||||
|
||||
func New(modelFile string) (authObj authz.IAuthz, err error) {
|
||||
obj := &CasbinAuthz{}
|
||||
obj.enforcer, err = casbin.NewSyncedEnforcer(modelFile, NewAdapter())
|
||||
return obj, err
|
||||
}
|
||||
|
||||
func (c *CasbinAuthz) AddRole4User(userID string, r *authz.RoleInfo) (err error) {
|
||||
_, err = c.enforcer.AddRoleForUser(userID, r.GetFullName())
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *CasbinAuthz) DeleteRole4User(userID string, r *authz.RoleInfo) (err error) {
|
||||
_, err = c.enforcer.DeleteRoleForUser(userID, r.GetFullName())
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *CasbinAuthz) GetUserRoleList(userID string) (roleList []*authz.RoleInfo, err error) {
|
||||
roleNameList, err := c.enforcer.GetRolesForUser(userID)
|
||||
if err == nil && len(roleNameList) > 0 {
|
||||
roleList = autils.FullRoleName2RoleList(roleNameList)
|
||||
}
|
||||
return roleList, err
|
||||
}
|
||||
|
||||
func (c *CasbinAuthz) GetRoleUserList(r *authz.RoleInfo) (userIDList []string, err error) {
|
||||
// globals.SugarLogger.Debug(roleFullName)
|
||||
userIDList, err = c.enforcer.GetUsersForRole(r.GetFullName())
|
||||
if err == errors.ERR_NAME_NOT_FOUND {
|
||||
err = nil
|
||||
}
|
||||
return userIDList, err
|
||||
}
|
||||
|
||||
// func (c *CasbinAuthz) GetAllRoleList() (roleList []*authz.RoleInfo) {
|
||||
// return authz.FullRoleName2RoleList(c.enforcer.GetAllRoles())
|
||||
// }
|
||||
91
business/dao/dao_print.go
Normal file
91
business/dao/dao_print.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
// QueryUserPrinter 查询用户打印机
|
||||
func QueryUserPrinter(userId, printNo string) (*model.Printer, error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM printer
|
||||
WHERE 1 = 1 AND deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
|
||||
if printNo != "" {
|
||||
sql += " AND print_no = ?"
|
||||
sqlParams = append(sqlParams, printNo)
|
||||
}
|
||||
if userId != "" {
|
||||
sql += " AND user_id = ?"
|
||||
sqlParams = append(sqlParams, userId)
|
||||
}
|
||||
var printer = &model.Printer{}
|
||||
err := GetRow(GetDB(), &printer, sql, sqlParams)
|
||||
return printer, err
|
||||
}
|
||||
|
||||
func GetPrinters(db *DaoDB, appID int, printNo string, status, statusNeq int) (printers []*model.Printer, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM printer
|
||||
WHERE 1 = 1 AND deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if appID != 0 {
|
||||
sql += " AND app_id = ?"
|
||||
sqlParams = append(sqlParams, appID)
|
||||
}
|
||||
if printNo != "" {
|
||||
sql += " AND print_no = ?"
|
||||
sqlParams = append(sqlParams, printNo)
|
||||
}
|
||||
if status != 0 {
|
||||
sql += " AND status = ?"
|
||||
sqlParams = append(sqlParams, status)
|
||||
}
|
||||
if statusNeq != 0 {
|
||||
sql += " AND status <> ?"
|
||||
sqlParams = append(sqlParams, statusNeq)
|
||||
}
|
||||
err = GetRows(db, &printers, sql, sqlParams)
|
||||
|
||||
globals.SugarLogger.Debugf("======printers==== %s", utils.Format4Output(printers, false))
|
||||
return printers, err
|
||||
}
|
||||
|
||||
func GetPrintMsgs(db *DaoDB, printNo, msgID string, status, statusNeq int) (printMsgs []*model.PrintMsg, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM print_msg
|
||||
WHERE 1 = 1 AND deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if status != model.PrintMsgAll {
|
||||
sql += " AND status = ?"
|
||||
sqlParams = append(sqlParams, status)
|
||||
}
|
||||
if statusNeq != model.PrintMsgAll {
|
||||
sql += " AND status <> ?"
|
||||
sqlParams = append(sqlParams, statusNeq)
|
||||
}
|
||||
if printNo != "" {
|
||||
sql += " AND print_no = ?"
|
||||
sqlParams = append(sqlParams, printNo)
|
||||
}
|
||||
if msgID != "" {
|
||||
sql += " AND msg_id = ?"
|
||||
sqlParams = append(sqlParams, msgID)
|
||||
}
|
||||
err = GetRows(db, &printMsgs, sql, sqlParams)
|
||||
return printMsgs, err
|
||||
}
|
||||
25
business/dao/dao_print_setting.go
Normal file
25
business/dao/dao_print_setting.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func GetPrintSetting(printNo string) (*model.PrintSettingObj, error) {
|
||||
sql := ` SELECT * FROM print_setting WHERE print_no = ? and deleted_at = ? `
|
||||
sqlParams := []interface{}{
|
||||
printNo,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
|
||||
var printSetting *model.PrintSetting
|
||||
if err := GetRow(GetDB(), &printSetting, sql, sqlParams...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if printSetting == nil {
|
||||
return nil, errors.New("数据查询异常")
|
||||
}
|
||||
|
||||
return model.UnMarshalString2Json(printSetting)
|
||||
}
|
||||
34
business/dao/dao_print_temp.go
Normal file
34
business/dao/dao_print_temp.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
// SelectUserDefaultTemp 查询用户默认模板
|
||||
func SelectUserDefaultTemp(userId string, tempType string) (*model.SystemTemp, bool, error) {
|
||||
var result *model.SystemTemp
|
||||
if err := GetRow(GetDB(), &result, `SELECT * FROM system_temp WHERE user_id = ? AND temp_type = ? AND is_use = ? AND deleted_at = ? ORDER BY created_at desc `, []interface{}{userId, tempType, 1, utils.DefaultTimeValue}...); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
return result, true, nil
|
||||
}
|
||||
|
||||
// QuerySystemTemp 查询系统模板
|
||||
func QuerySystemTemp() (*model.SystemTemp, error) {
|
||||
var result []*model.SystemTemp
|
||||
if err := GetRows(GetDB(), &result, `SELECT * FROM system_temp WHERE user_id = ? AND temp_type = ? AND is_use = ? AND deleted_at = ? ORDER BY created_at desc `, []interface{}{"system_user", "user_store", 1, utils.DefaultTimeValue}...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(result) > 0 {
|
||||
return result[0], nil
|
||||
}
|
||||
return nil, errors.New("模板获取异常")
|
||||
}
|
||||
|
||||
// AddTemp 添加模板数据
|
||||
func AddTemp(param *model.SystemTemp) error {
|
||||
return CreateEntity(GetDB(), param)
|
||||
}
|
||||
19
business/dao/dao_user_test.go
Normal file
19
business/dao/dao_user_test.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetUsers(t *testing.T) {
|
||||
aa := "{\"title\":\"<center><b>京西菜市</b></center><br><center>手机买菜上京西</center><br><center>极速到家送惊喜</center><br>--------------------------------<br>\",\"divider\":\"--------------------------------<br>\",\"payOrderTime\":\"<left>下单时间:%s</left>\",\"trySendTime\":\"<left>预计送达时间:%s</left>\",\"consigneeName\":\"<left>客户名称:%s</left>\",\"consigneeMobile\":\"<left>客户电话:%s</left>\",\"consigneeAddress\":\"<left>客户地址:%s</left>\",\"buyerComment\":\"<left>客户备注:%s</left>\",\"qrcOrder\":\"<qrl>%s</qrl>\",\"goodsListDetail\":\"商品列表:<br>品名 数量 单价 小计<br>--------------------------------<br>\",\"skuName\":\"<b>%s</b><br>\",\"skuNumber\":\"<b>x%s</b>\",\"skuPrice\":\"<b>¥%s</b>\",\"skuAllPrice\":\"<b>¥%s</b>\",\"skuUpc\":\"upc码: %s<br>\",\"allSkuTypeCount\":\"<br><br><b>共 %s 种\",\"allSkuCount\":\" %s 件商品</b><br>\",\"storeName\":\"<center><b>商品质量问题请联系:</b></center><br><center><b>%s:\",\"storeTel\":\"%s</b></center><br><br>更多信息请关注官方微信:\",\"officialName\":\"<b>%s</b><br><br><br>--------------------------------<br>--------------------------------<br><br>\"}"
|
||||
|
||||
conte := make(map[string]string, 0)
|
||||
|
||||
if err := json.Unmarshal([]byte(aa), &conte); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Log(utils.Format4Output(conte, false))
|
||||
}
|
||||
@@ -142,66 +142,6 @@ func GetOperateEvents(db *DaoDB, name string, apiFunctions []string, operateType
|
||||
return operateEventExt, totalCount, err
|
||||
}
|
||||
|
||||
func GetImMessageRecord(db *DaoDB, groupID int, userID, toUserID string, storeID, vendorID int, fromTime, toTime time.Time, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
||||
var msg []*model.ImMessageRecord
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS *
|
||||
FROM im_message_record
|
||||
WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if groupID != 0 {
|
||||
sql += " AND group_id = ?"
|
||||
sqlParams = append(sqlParams, groupID)
|
||||
if groupID == model.SysGroupID {
|
||||
sql += " AND to_user_id = ?"
|
||||
sqlParams = append(sqlParams, toUserID)
|
||||
}
|
||||
}
|
||||
if userID != "" {
|
||||
sql += " AND user_id = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if storeID != 0 {
|
||||
sql += " AND store_id = ?"
|
||||
sqlParams = append(sqlParams, storeID)
|
||||
}
|
||||
if vendorID >= 0 {
|
||||
sql += " AND vendor_id = ?"
|
||||
sqlParams = append(sqlParams, vendorID)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += " AND created_at >= ?"
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += " AND created_at <= ?"
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
sql += `
|
||||
ORDER BY created_at DESC
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &msg, sql, sqlParams); err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
// Data: msg,
|
||||
}
|
||||
for _, v := range msg {
|
||||
if user, err := GetUser(db, v.UserID); err == nil {
|
||||
v.UserInfo = user
|
||||
}
|
||||
}
|
||||
pagedInfo.Data = msg
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
type GetMessageGroupsResult struct {
|
||||
model.MessageGroup
|
||||
Avatar string `json:"avatar"`
|
||||
19
business/dao/print_activation.go
Normal file
19
business/dao/print_activation.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func CheckHeard(printNo string) (bool, error) {
|
||||
var data *model.PrintActivation
|
||||
err := GetRow(GetDB(), &data, `SELECT * FROM print_activation WHERE print_no = ?`, []interface{}{printNo}...)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if data == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
42
business/dao/print_bind_store.go
Normal file
42
business/dao/print_bind_store.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
// QueryPrintBindStore 查询绑定门店
|
||||
func QueryPrintBindStore(printNo string) ([]*model.PrintBindStore, error) {
|
||||
var data []*model.PrintBindStore
|
||||
if err := GetRows(GetDB(), &data, `SELECT * FROM print_bind_store WHERE print_no = ?`, []interface{}{printNo}...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// BindStoreList 绑定门店信息
|
||||
func BindStoreList(req *model.AddPrinterParam, userId string) error {
|
||||
param := &model.PrintBindStore{
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
StoreID: req.StoreId,
|
||||
StoreName: req.Name,
|
||||
StoreVendor: 9, // 绑定平台,全平台
|
||||
PrintNo: req.PrintNo,
|
||||
StoreStatus: 1, // 门店开启
|
||||
BindStatus: 1, // 绑定状态
|
||||
}
|
||||
if userId != "" {
|
||||
param.UserId = userId
|
||||
} else {
|
||||
param.UserId = "system"
|
||||
}
|
||||
return CreateEntity(GetDB(), param)
|
||||
}
|
||||
|
||||
// DeleteStoreList 删除绑定门店
|
||||
func DeleteStoreList(printNo string, storeId string) error {
|
||||
sql := ` DELETE FROM print_bind_store WHERE print_no = ? AND store_id = ? `
|
||||
_, err := ExecuteSQL(GetDB(), sql, []interface{}{printNo, storeId}...)
|
||||
return err
|
||||
}
|
||||
539
business/dao/print_temp_utils.go
Normal file
539
business/dao/print_temp_utils.go
Normal file
@@ -0,0 +1,539 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-print/globals"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var SystemTempObj map[string]*model.SystemTemp
|
||||
|
||||
func Init() {
|
||||
SystemTempObj = make(map[string]*model.SystemTemp, 0)
|
||||
sysTempList, err := QuerySystemTemp()
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debug("query system temp err :", err)
|
||||
return
|
||||
}
|
||||
SystemTempObj[sysTempList.TempSize] = sysTempList
|
||||
|
||||
//now := time.Now()
|
||||
//param := &model.SystemTemp{
|
||||
// CreatedAt: &now,
|
||||
// UpdatedAt: &now,
|
||||
// LastOperator: "system",
|
||||
// DeletedAt: &utils.DefaultTimeValue,
|
||||
// TempName: "",
|
||||
// TempRank: model.SystemTempKey,
|
||||
// Temp: "",
|
||||
// UserId: "system_user",
|
||||
// TempType: model.TempTypeMerchant,
|
||||
// TempSize: model.SystemTempSizeBig,
|
||||
// PrintSn: "system",
|
||||
// IsUse: 1,
|
||||
//}
|
||||
|
||||
// 初始化大字体模板
|
||||
//if _, v := temp[model.SystemTempSizeBig]; !v {
|
||||
// param.TempName = "system" + model.SystemTempSizeBig
|
||||
// param.Temp = model.SystemTempValue
|
||||
// if err := AddTemp(param); err != nil {
|
||||
// globals.SugarLogger.Debug("init system temp err :", err)
|
||||
// }
|
||||
// SystemTempObj[model.SystemTempSizeBig] = param
|
||||
//}
|
||||
|
||||
// 初始化中字体模板
|
||||
//if _, v := temp[model.SystemTempSizeMedium]; !v {
|
||||
// param.TempName = "system" + model.SystemTempSizeMedium
|
||||
// medium := strings.Replace(model.SystemTempValue, "<b>", "<hb>", -1)
|
||||
// medium2 := strings.Replace(medium, "</b>", "</hb>", -1)
|
||||
// param.Temp = medium2
|
||||
// param.TempSize = model.SystemTempSizeMedium
|
||||
// param.IsUse = 2
|
||||
// if err := AddTemp(param); err != nil {
|
||||
// globals.SugarLogger.Debug("init system temp err :", err)
|
||||
// }
|
||||
// SystemTempObj[model.SystemTempSizeMedium] = param
|
||||
//}
|
||||
|
||||
// 初始化小字体模板
|
||||
//if _, v := temp[model.SystemTempSizeSmall]; !v {
|
||||
// param.TempName = "system" + model.SystemTempSizeSmall
|
||||
// medium := strings.Replace(model.SystemTempValue, "<b>", " ", -1)
|
||||
// medium2 := strings.Replace(medium, "</b>", " ", -1)
|
||||
// param.Temp = medium2
|
||||
// param.TempSize = model.SystemTempSizeSmall
|
||||
// param.IsUse = 2
|
||||
// if err := AddTemp(param); err != nil {
|
||||
// globals.SugarLogger.Debug("init system temp err :", err)
|
||||
// }
|
||||
// SystemTempObj[model.SystemTempSizeSmall] = param
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
// MakePrintMsgOnTemp 将打印数据渲染到模板当中
|
||||
func MakePrintMsgOnTemp(param map[string]string, userId string) (string, error) {
|
||||
// 查询用户默认模板,不存在则使用系统默认模板
|
||||
userTemp := &model.SystemTemp{}
|
||||
userTemp, isHave, err := SelectUserDefaultTemp(userId, model.TempTypeMerchantUser)
|
||||
if err != nil || !isHave {
|
||||
userTemp, err = QuerySystemTemp()
|
||||
}
|
||||
if userTemp == nil || !isHave || err != nil {
|
||||
if userTemp.TempType != "" {
|
||||
userTemp = SystemTempObj[userTemp.TempSize]
|
||||
} else {
|
||||
userTemp = SystemTempObj[model.SystemTempSizeBig]
|
||||
}
|
||||
}
|
||||
// 需要打印数据
|
||||
printMsg := ""
|
||||
printValue := make([]interface{}, 0, 0)
|
||||
userTempMap := make(map[string]string, 0)
|
||||
if err := json.Unmarshal([]byte(userTemp.Temp), &userTempMap); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for _, v := range strings.Split(userTemp.TempRank, ",") {
|
||||
switch v {
|
||||
case "skuName", "skuNumber", "skuPrice", "skuAllPrice", "allSkuTypeCount", "allSkuCount", "skuUpc", "userPayMoney":
|
||||
continue
|
||||
case "goodsListDetail":
|
||||
printMsg += userTempMap[v]
|
||||
skuList := make([]*model.SkuListPrintOrder, 0, 0)
|
||||
if err := json.Unmarshal([]byte(param["skuList"]), &skuList); err != nil {
|
||||
return "", err
|
||||
}
|
||||
for i := 0; i < len(skuList); i++ {
|
||||
printMsg += userTempMap["skuName"]
|
||||
printMsg += userTempMap["skuNumber"]
|
||||
printMsg += userTempMap["skuPrice"]
|
||||
printMsg += userTempMap["skuAllPrice"]
|
||||
printValue = append(printValue, skuList[i].SkuName, skuList[i].SkuCount, skuList[i].SalePrice, skuList[i].TotalCountPrice)
|
||||
if skuList[i].Upc != "" {
|
||||
printMsg += userTempMap["skuUpc"]
|
||||
printValue = append(printValue, skuList[i].Upc)
|
||||
}
|
||||
|
||||
}
|
||||
printMsg += userTempMap["allSkuTypeCount"]
|
||||
printValue = append(printValue, param["allSkuTypeCount"])
|
||||
printMsg += userTempMap["allSkuCount"]
|
||||
printValue = append(printValue, param["allSkuCount"])
|
||||
printMsg += userTempMap["userPayMoney"]
|
||||
printValue = append(printValue, param["userPayMoney"])
|
||||
case "businessType":
|
||||
if param[v] == "2" { // 是预订单
|
||||
printMsg += userTempMap[v]
|
||||
printValue = append(printValue, param[v])
|
||||
}
|
||||
case "divider":
|
||||
printMsg += userTempMap[v]
|
||||
case "title":
|
||||
printMsg += userTempMap[v]
|
||||
case "qrcOrder": // 老版打印机展示不要
|
||||
//printMsg += userTempMap[v]
|
||||
//printValue = append(printValue, param[v])
|
||||
printMsg += `<b>%s #%s</b>`
|
||||
printValue = append(printValue, param["vendorName"], param["vendorOrderNo"])
|
||||
default:
|
||||
printMsg += userTempMap[v]
|
||||
printValue = append(printValue, param[v])
|
||||
}
|
||||
|
||||
}
|
||||
return strings.Replace(fmt.Sprintf(strings.Replace(printMsg, "\n", "", -1), printValue...), "\\n", "\r\n", -1), nil
|
||||
//}
|
||||
}
|
||||
|
||||
// MakePrintMsgOnTempVoice 制作平台语音
|
||||
func MakePrintMsgOnTempVoice(param map[string]string, setting *model.PrintSettingObj, userId string) (string, error) {
|
||||
// 打订单
|
||||
if param[model.OrderStatusPrint] != "" {
|
||||
// 订单提示设置
|
||||
printMsg, err := PrinterOrderVoice(param, setting, userId)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debug("err Unmarshal userTemp.printMsg", err)
|
||||
return "", err
|
||||
}
|
||||
return printMsg, nil
|
||||
}
|
||||
// 打运单
|
||||
if param[model.WayBillStatusPrint] != "" {
|
||||
switch param[model.WayBillStatusPrint] {
|
||||
case utils.Int2Str(model.WaybillStatusCourierAssigned): // 分配骑手
|
||||
return PrintWayBillOrderStatus(param, setting), nil
|
||||
case utils.Int2Str(model.WaybillStatusDeliverReminder): // 催单
|
||||
printVoiceMsg := ``
|
||||
printVoiceValue := make([]interface{}, 0, 0)
|
||||
//printVoiceMsg, printVoiceValue = SyntheticSpeech(printVoiceMsg, printVoiceValue, param)
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.ReminderOrderVoice)
|
||||
return strings.Replace(fmt.Sprintf(strings.Replace(printVoiceMsg, "\n", "", -1), printVoiceValue...), "\\n", "\r\n", -1), nil
|
||||
case utils.Int2Str(model.WaybillStatusDelivered): // 送达
|
||||
printVoiceMsg := ``
|
||||
printVoiceValue := make([]interface{}, 0, 0)
|
||||
//printVoiceMsg, printVoiceValue = SyntheticSpeech(printVoiceMsg, printVoiceValue, param)
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.FinialsOrderVoice)
|
||||
return strings.Replace(fmt.Sprintf(strings.Replace(printVoiceMsg, "\n", "", -1), printVoiceValue...), "\\n", "\r\n", -1), nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 门店状态
|
||||
if param[model.StoreStatusPrint] != "" {
|
||||
return PrintStoreStatus(param, setting), nil
|
||||
}
|
||||
|
||||
// 进店咨询
|
||||
if param[model.EnterTheStorePrint] != "" && setting.VoiceSetting.ConsultingPrint == model.SettingOpen {
|
||||
return `<sound>19</sound>`, nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// PrinterOrderVoice 打印机订单提示设置
|
||||
func PrinterOrderVoice(param map[string]string, setting *model.PrintSettingObj, userId string) (string, error) {
|
||||
var (
|
||||
printVoiceMsg string //语音信息
|
||||
printVoiceValue = make([]interface{}, 0, 0)
|
||||
textMsg string // 文本信息
|
||||
err error
|
||||
)
|
||||
|
||||
// 订单状态
|
||||
switch param[model.OrderStatusPrint] {
|
||||
// 新订单(待接单)
|
||||
case utils.Int2Str(model.OrderStatusNew): // utils.Int2Str(model.OrderStatusFinishedPickup), utils.Int2Str(model.OrderStatusAccepted)
|
||||
//if param[model.OrderStatusPrint] != utils.Int2Str(model.OrderStatusNew) && param[model.VendorIDPrint] == utils.Int64ToStr(model.VendorIDMTWM) {
|
||||
// return "", err
|
||||
//}
|
||||
//if param[model.OrderStatusPrint] == utils.Int2Str(model.OrderStatusFinishedPickup) && param[model.VendorIDPrint] == utils.Int64ToStr(model.VendorIDEBAI) {
|
||||
// return "", err
|
||||
//}
|
||||
// 称谓设置/平台语音设置
|
||||
if setting.CallNameSetting == 64 || setting.CallNameSetting == 65 || setting.CallNameSetting == 66 {
|
||||
// 老板
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, setting.CallNameSetting)
|
||||
}
|
||||
// 订单设置
|
||||
if setting.PrintSetting.WaitOrderPrint == model.SettingOpen { // 打印订单
|
||||
textMsg, err = MakePrintMsgOnTemp(param, userId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
if setting.VoiceSetting.WaitOrderVoice == model.SettingOpen { // 订单通知
|
||||
printVoiceMsg += `<sound>%d</sound>` // 你来新订单了
|
||||
printVoiceValue = append(printVoiceValue, model.NewOrderVoice)
|
||||
}
|
||||
// 申请取消
|
||||
case utils.Int2Str(model.ApplyOrderCancel):
|
||||
// 称谓设置/平台语音设置
|
||||
if setting.CallNameSetting == 64 || setting.CallNameSetting == 65 || setting.CallNameSetting == 66 {
|
||||
// 老板
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, setting.CallNameSetting)
|
||||
}
|
||||
// 订单设置
|
||||
if setting.PrintSetting.ApplyUserCancelOrder == model.SettingOpen { // 申请取消打印
|
||||
rejection := ``
|
||||
rejectionValue := make([]interface{}, 0, 0)
|
||||
rejection += `<center><b>客户申请取消订单:</b></center><br>`
|
||||
rejection += `<center><b>订单号: %s</b></center><br>`
|
||||
rejection += `<center><b>订单来源: %s # %s</b></center><br>`
|
||||
rejection += `<center><b>取消时间: %s</b></center><br>`
|
||||
rejectionValue = append(rejectionValue, param[model.OrderNoPrint], param[model.VendorNamePrint], param[model.VendorOrderNoPrint], utils.Time2DateStr(time.Now()))
|
||||
textMsg = strings.Replace(fmt.Sprintf(strings.Replace(rejection, "\n", "", -1), rejectionValue...), "\\n", "\r\n", -1)
|
||||
}
|
||||
if setting.VoiceSetting.ApplyUserOrderCancelVoice == model.SettingOpen { // 申请取消语音
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.ApplyCancelVoice)
|
||||
//printVoiceMsg, printVoiceValue = SyntheticSpeech(printVoiceMsg, printVoiceValue, param)
|
||||
}
|
||||
// 申请退货
|
||||
case utils.Int2Str(model.ApplyOrderRefundGoods):
|
||||
// 称谓设置/平台语音设置
|
||||
if setting.CallNameSetting == 64 || setting.CallNameSetting == 65 || setting.CallNameSetting == 66 {
|
||||
// 老板
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, setting.CallNameSetting)
|
||||
}
|
||||
rejection := ``
|
||||
rejectionValue := make([]interface{}, 0, 0)
|
||||
rejection += `<center><b>客户申请退货:</b></center><br>`
|
||||
rejection += `<center><b>订单号: %s</b></center><br>`
|
||||
rejection += `<center><b>订单来源: %s # %s</b></center><br>`
|
||||
rejection += `<center><b>原因: %s</b></center><br>`
|
||||
rejectionValue = append(rejectionValue, param[model.OrderNoPrint], param[model.VendorNamePrint], param[model.VendorOrderNoPrint], param[model.RejectionReasonPrint])
|
||||
textMsg = strings.Replace(fmt.Sprintf(strings.Replace(rejection, "\n", "", -1), rejectionValue...), "\\n", "\r\n", -1)
|
||||
|
||||
if setting.VoiceSetting.ApplyRefundGoodsVoice == model.SettingOpen { // 申请退货语音
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.ApplyReturnGoodsVoice)
|
||||
// printVoiceMsg, printVoiceValue = SyntheticSpeech(printVoiceMsg, printVoiceValue, param)
|
||||
}
|
||||
// 申请退款
|
||||
case utils.Int2Str(model.ApplyOrderRefund):
|
||||
// 称谓设置/平台语音设置
|
||||
if setting.CallNameSetting == 64 || setting.CallNameSetting == 65 || setting.CallNameSetting == 66 {
|
||||
// 老板
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, setting.CallNameSetting)
|
||||
}
|
||||
// 订单设置
|
||||
if setting.PrintSetting.ApplyUserRefund == model.SettingOpen { // 取消退款订单
|
||||
textMsg, err = MakePrintMsgOnTemp(param, userId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
if setting.VoiceSetting.ApplyRefundOrderVoice == model.SettingOpen {
|
||||
//printVoiceMsg, printVoiceValue = SyntheticSpeech(printVoiceMsg, printVoiceValue, param)
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.ApplyRefundVoice)
|
||||
}
|
||||
// 取消打印
|
||||
|
||||
case utils.Int2Str(model.OrderStatusRejection): // 拒收
|
||||
// 称谓设置/平台语音设置
|
||||
if setting.CallNameSetting == 64 || setting.CallNameSetting == 65 || setting.CallNameSetting == 66 {
|
||||
// 老板
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, setting.CallNameSetting)
|
||||
}
|
||||
//if setting.VoiceSetting.CustomerRejectionVoice == model.SettingOpen && setting.SystemVoice == model.SettingOpen {
|
||||
// // 暂无语音打印
|
||||
//}
|
||||
// 拒收暂无语音设置,使用文本提示
|
||||
if setting.PrintSetting.CustomerRejectionPrint == model.SettingOpen { // 客户拒收打印
|
||||
rejection := ``
|
||||
rejectionValue := make([]interface{}, 0, 0)
|
||||
rejection += `<center><b>客户拒收信息:</b></center><br>`
|
||||
rejection += `<center><b>订单号: %s</b></center><br>`
|
||||
rejection += `<center><b>订单来源: %s # %s</b></center><br>`
|
||||
rejection += `<center><b>拒收原因: %s</b></center><br>`
|
||||
rejectionValue = append(rejectionValue, param[model.OrderNoPrint], param[model.VendorNamePrint], param[model.VendorOrderNoPrint], param[model.RejectionReasonPrint])
|
||||
textMsg = strings.Replace(fmt.Sprintf(strings.Replace(rejection, "\n", "", -1), rejectionValue...), "\\n", "\r\n", -1)
|
||||
}
|
||||
|
||||
case utils.Int2Str(model.OrderStatusCustomerService): // 客服退款
|
||||
// 称谓设置/平台语音设置
|
||||
if setting.CallNameSetting == 64 || setting.CallNameSetting == 65 || setting.CallNameSetting == 66 {
|
||||
// 老板
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, setting.CallNameSetting)
|
||||
}
|
||||
if setting.VoiceSetting.CusterRefundVoice == model.SettingOpen {
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.BusinessResponsibilityVoice)
|
||||
}
|
||||
if setting.PrintSetting.CusterRefundPrint == model.SettingOpen {
|
||||
rejection := ``
|
||||
rejectionValue := make([]interface{}, 0, 0)
|
||||
rejection += `<center><b>客服退款详情:</b></center><br>`
|
||||
rejection += `<center><b>订单号: %s</b></center><br>`
|
||||
rejection += `<center><b>订单来源: %s # %s</b></center><br>`
|
||||
rejection += `<center><b>退款原因: %s</b></center><br>`
|
||||
rejection += `<center><b>退款时间: %s</b></center><br>`
|
||||
rejectionValue = append(rejectionValue, param[model.OrderNoPrint], param[model.VendorNamePrint], param[model.VendorOrderNoPrint], param[model.CustcareRefundReasonPrint], utils.Time2DateStr(time.Now()))
|
||||
textMsg = strings.Replace(fmt.Sprintf(strings.Replace(rejection, "\n", "", -1), rejectionValue...), "\\n", "\r\n", -1)
|
||||
}
|
||||
case utils.Int2Str(model.OrderStatusCanceled), utils.Int2Str(model.CancelOrderSuccess): // 取消订单成功
|
||||
// 称谓设置/平台语音设置
|
||||
if setting.CallNameSetting == 64 || setting.CallNameSetting == 65 || setting.CallNameSetting == 66 {
|
||||
// 老板
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, setting.CallNameSetting)
|
||||
if setting.VoiceSetting.RefundGoodsVoice == model.SettingOpen {
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.CancelOrderVoice)
|
||||
}
|
||||
}
|
||||
if setting.PrintSetting.CusterRefundPrint == model.SettingOpen {
|
||||
rejection := ``
|
||||
rejectionValue := make([]interface{}, 0, 0)
|
||||
rejection += `<center><b>订单取消成功:</b></center><br>`
|
||||
rejection += `<center><b>订单号: %s</b></center><br>`
|
||||
rejection += `<center><b>订单来源: %s # %s</b></center><br>`
|
||||
rejection += `<center><b>取消原因: %s</b></center><br>`
|
||||
rejection += `<center><b>取消成功时间: %s</b></center><br>`
|
||||
rejectionValue = append(rejectionValue, param[model.OrderNoPrint], param[model.VendorNamePrint], param[model.VendorOrderNoPrint], param[model.CustcareRefundReasonPrint], utils.Time2DateStr(time.Now()))
|
||||
textMsg = strings.Replace(fmt.Sprintf(strings.Replace(rejection, "\n", "", -1), rejectionValue...), "\\n", "\r\n", -1)
|
||||
}
|
||||
case utils.Int2Str(model.BusinessCancelOrder): // 商家取消打印
|
||||
// 称谓设置/平台语音设置
|
||||
if setting.CallNameSetting == 64 || setting.CallNameSetting == 65 || setting.CallNameSetting == 66 {
|
||||
// 老板
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, setting.CallNameSetting)
|
||||
}
|
||||
if setting.PrintSetting.BusinessOrderCancel == model.SettingOpen {
|
||||
rejection := ``
|
||||
rejectionValue := make([]interface{}, 0, 0)
|
||||
rejection += `<center><b>商家侧取消订单:</b></center><br>`
|
||||
rejection += `<center><b>订单号: %s</b></center><br>`
|
||||
rejection += `<center><b>订单来源: %s # %s</b></center><br>`
|
||||
rejection += `<center><b>取消原因: %s</b></center><br>`
|
||||
rejection += `<center><b>取消成功时间: %s</b></center><br>`
|
||||
rejectionValue = append(rejectionValue, param[model.OrderNoPrint], param[model.VendorNamePrint], param[model.VendorOrderNoPrint], param[model.CustcareRefundReasonPrint], utils.Time2DateStr(time.Now()))
|
||||
textMsg = strings.Replace(fmt.Sprintf(strings.Replace(rejection, "\n", "", -1), rejectionValue...), "\\n", "\r\n", -1)
|
||||
}
|
||||
case utils.Int2Str(model.OrderRefundMoneySuccess): // 订单退款成功打印
|
||||
// 称谓设置/平台语音设置
|
||||
if setting.CallNameSetting == 64 || setting.CallNameSetting == 65 || setting.CallNameSetting == 66 {
|
||||
// 老板
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, setting.CallNameSetting)
|
||||
}
|
||||
if setting.PrintSetting.OrderCancelSuccess == model.SettingOpen {
|
||||
rejection := ``
|
||||
rejectionValue := make([]interface{}, 0, 0)
|
||||
rejection += `<center><b>退款成功:</b></center><br>`
|
||||
rejection += `<center><b>订单号: %s</b></center><br>`
|
||||
rejection += `<center><b>订单来源: %s # %s</b></center><br>`
|
||||
rejectionValue = append(rejectionValue, param[model.OrderNoPrint], param[model.VendorNamePrint], param[model.VendorOrderNoPrint])
|
||||
textMsg = strings.Replace(fmt.Sprintf(strings.Replace(rejection, "\n", "", -1), rejectionValue...), "\\n", "\r\n", -1)
|
||||
}
|
||||
}
|
||||
|
||||
voice := strings.Replace(fmt.Sprintf(strings.Replace(printVoiceMsg, "\n", "", -1), printVoiceValue...), "\\n", "\r\n", -1)
|
||||
return voice + textMsg, nil
|
||||
}
|
||||
|
||||
// PrintWayBillOrderStatus 打印运单类通知消息
|
||||
func PrintWayBillOrderStatus(param map[string]string, setting *model.PrintSettingObj) string {
|
||||
var (
|
||||
printVoiceMsg string //语音信息
|
||||
printVoiceValue = make([]interface{}, 0, 0)
|
||||
textMsg string // 文本信息
|
||||
textMsgValue = make([]interface{}, 0, 0) // 文本信息
|
||||
)
|
||||
|
||||
switch param[model.WayBillStatusPrint] {
|
||||
case utils.Int2Str(model.WaybillStatusAccepted), utils.Int2Str(model.WaybillStatusCourierAssigned): // 分配骑手
|
||||
if setting.PrintSetting.RiderTakeOrder == model.SettingOpen { // 打印订单
|
||||
textMsg += `<center><b>接单骑手信息:</b></center><br>`
|
||||
textMsg += `<center><b>骑手姓名: %s</b></center><br>`
|
||||
textMsg += `<center><b>骑手电话: %s</b></center><br>`
|
||||
textMsg += `<center><b>接单时间: %s</b></center><br>`
|
||||
textMsg += `<center><b>订单来源: %s</b></center><br>`
|
||||
textMsg += `<center><b>单号: #%s</b></center><br>`
|
||||
textMsgValue = append(textMsgValue, param[model.RiderNamePrint], param[model.RiderPhonePrint], utils.Time2DateStr(time.Now()), param[model.VendorNamePrint], param[model.VendorOrderNoPrint])
|
||||
}
|
||||
}
|
||||
if setting.VoiceSetting.RiderTakeOrderVoice == model.SettingOpen { // 骑手接单语音通知
|
||||
printVoiceMsg += `<sound>%d</sound><sound>%d</sound>` // 骑手已经接单了
|
||||
printVoiceValue = append(printVoiceValue, model.RiderGetOrderVoice)
|
||||
}
|
||||
|
||||
msg := strings.Replace(fmt.Sprintf(strings.Replace(textMsg, "\n", "", -1), textMsgValue...), "\\n", "\r\n", -1)
|
||||
voice := strings.Replace(fmt.Sprintf(strings.Replace(printVoiceMsg, "\n", "", -1), printVoiceValue...), "\\n", "\r\n", -1)
|
||||
return voice + msg
|
||||
}
|
||||
|
||||
// PrintStoreStatus 打印门店状态
|
||||
func PrintStoreStatus(param map[string]string, setting *model.PrintSettingObj) string {
|
||||
var (
|
||||
printVoiceMsg string //语音信息
|
||||
printVoiceValue = make([]interface{}, 0, 0)
|
||||
textMsg string // 文本信息
|
||||
textMsgValue = make([]interface{}, 0, 0)
|
||||
)
|
||||
|
||||
switch utils.Str2Int(param[model.StoreStatusPrint]) {
|
||||
case -9: // 丢失授权
|
||||
var voice string
|
||||
if setting.VoiceSetting.LoseAuthorization == model.SettingOpen {
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.LoseTokenVoice)
|
||||
voice = strings.Replace(fmt.Sprintf(strings.Replace(printVoiceMsg, "\n", "", -1), printVoiceValue...), "\\n", "\r\n", -1)
|
||||
}
|
||||
|
||||
textMsg += `<left><b>门店丢失授权通知</b></left><br>`
|
||||
textMsg += `<left><b>门店:%s</b></left><br>`
|
||||
textMsg += `<left><b>平台:%s</b></left><br>`
|
||||
textMsg += `<left><b>下线时间:%s</b></left><br>`
|
||||
textMsg += `<left><b>授权丢失,将无法继续打压订单!!!!</b></left><br>`
|
||||
textMsgValue = append(textMsgValue, param[model.StoreNamePrint], param[model.VendorNamePrint], utils.Time2DateStr(time.Now()))
|
||||
msg := strings.Replace(fmt.Sprintf(strings.Replace(textMsg, "\n", "", -1), textMsgValue...), "\\n", "\r\n", -1)
|
||||
return voice + msg
|
||||
default:
|
||||
// 离线打印文本开启
|
||||
textMsg += `<center><b>门店下线通知</b></center><br>`
|
||||
textMsg += `<center><b>门店:%s</b></center><br>`
|
||||
textMsg += `<center><b>平台:%s</b></center><br>`
|
||||
textMsg += `<center><b>下线时间:%s</b></center><br>`
|
||||
textMsgValue = append(textMsgValue, param[model.StoreNamePrint], param[model.VendorNamePrint], utils.Time2DateStr(time.Now()))
|
||||
// 离线打印语音开启
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.StoreOfflineVoice)
|
||||
voice := strings.Replace(fmt.Sprintf(strings.Replace(printVoiceMsg, "\n", "", -1), printVoiceValue...), "\\n", "\r\n", -1)
|
||||
msg := strings.Replace(fmt.Sprintf(strings.Replace(textMsg, "\n", "", -1), textMsgValue...), "\\n", "\r\n", -1)
|
||||
|
||||
return voice + msg
|
||||
}
|
||||
}
|
||||
|
||||
// SyntheticSpeech 合成语音 (美团xxx号订单)
|
||||
func SyntheticSpeech(printVoiceMsg string, printVoiceValue []interface{}, param map[string]string) (string, []interface{}) {
|
||||
printVoiceMsg += `<sound>%d</sound>` // 美团
|
||||
switch param[model.VendorIDPrint] {
|
||||
case utils.Int2Str(model.VendorIDJD): // 京东
|
||||
printVoiceValue = append(printVoiceValue, model.JdVoice)
|
||||
case utils.Int2Str(model.VendorIDMTWM): // 美团
|
||||
printVoiceValue = append(printVoiceValue, model.MtVoice)
|
||||
case utils.Int2Str(model.VendorIDELM): // 饿了么
|
||||
printVoiceValue = append(printVoiceValue, model.ElmVoice)
|
||||
case utils.Int2Str(model.VendorIDEBAI): // 饿百
|
||||
printVoiceValue = append(printVoiceValue, model.ElmVoice)
|
||||
case utils.Int2Str(model.VendorIDJDShop): // 京东商城
|
||||
printVoiceValue = append(printVoiceValue, model.JdToHose)
|
||||
case utils.Int2Str(model.VendorIDTT): // 抖音
|
||||
// 暂无
|
||||
}
|
||||
if param[model.VendorOrderNoPrint] != "" {
|
||||
switch len(param[model.VendorOrderNoPrint]) {
|
||||
case 1:
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.NumberVoiceMap[param[model.VendorOrderNoPrint]])
|
||||
case 2:
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.NumberVoiceMap[param[model.VendorOrderNoPrint][:1]+"0"])
|
||||
if param[model.VendorOrderNoPrint][1:] != "0" {
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.NumberVoiceMap[param[model.VendorOrderNoPrint][1:]])
|
||||
}
|
||||
case 3:
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.NumberVoiceMap[param[model.VendorOrderNoPrint][0:1]+"00"])
|
||||
if param[model.VendorOrderNoPrint][1:2] == "0" && param[model.VendorOrderNoPrint][2:] == "0" {
|
||||
|
||||
} else if param[model.VendorOrderNoPrint][1:2] == "0" && param[model.VendorOrderNoPrint][2:] != "0" {
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.NumberVoiceMap[param[model.VendorOrderNoPrint][1:2]])
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.NumberVoiceMap[param[model.VendorOrderNoPrint][2:]])
|
||||
} else if param[model.VendorOrderNoPrint][1:2] != "0" && param[model.VendorOrderNoPrint][2:] == "0" {
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.NumberVoiceMap[param[model.VendorOrderNoPrint][1:2]+"0"])
|
||||
} else if param[model.VendorOrderNoPrint][1:2] != "0" && param[model.VendorOrderNoPrint][2:] != "0" {
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.NumberVoiceMap[param[model.VendorOrderNoPrint][1:2]+"0"])
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.NumberVoiceMap[param[model.VendorOrderNoPrint][2:]])
|
||||
}
|
||||
}
|
||||
}
|
||||
printVoiceMsg += `<sound>%d</sound>`
|
||||
printVoiceValue = append(printVoiceValue, model.OrderNoVoice)
|
||||
return printVoiceMsg, printVoiceValue
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
"git.rosy.net.cn/jx-callback/business/authz/autils"
|
||||
"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/legacymodel"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api2"
|
||||
)
|
||||
|
||||
// todo 是否需要将Store.MarketManPhone与OperatorPhone成角色?
|
||||
|
||||
func TransferLegacyWeixins(mobile string) (err error) {
|
||||
globals.SugarLogger.Debugf("TransferLegacyWeixins mobile:%s", mobile)
|
||||
if !globals.EnableWXAuth2 || globals.DisableWXAuth1 {
|
||||
return nil
|
||||
}
|
||||
remark4Transfer := "transfer"
|
||||
// DELETE t1
|
||||
// FROM auth_bind t1
|
||||
// WHERE t1.remark = 'transfer';
|
||||
|
||||
// DELETE t1
|
||||
// FROM user t1
|
||||
// WHERE t1.remark = 'transfer';
|
||||
|
||||
// TRUNCATE TABLE casbin_rule;
|
||||
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
FROM weixins t1
|
||||
LEFT JOIN user t2 ON t2.mobile = t1.tel
|
||||
LEFT JOIN auth_bind t3 ON t3.auth_id = t1.openid AND t3.type = 'weixinsns'
|
||||
LEFT JOIN auth_bind t4 ON t4.auth_id = t1.openid_mini AND t4.type = 'weixinmini'
|
||||
WHERE`
|
||||
sqlParams := []interface{}{}
|
||||
if mobile != "" {
|
||||
remark4Transfer = "transfer2"
|
||||
sql += " t1.tel = ?"
|
||||
sqlParams = append(sqlParams, mobile)
|
||||
} else {
|
||||
sql += " t2.id IS NULL OR (t1.openid <> '' AND t3.id IS NULL) OR (t1.openid_mini <> '' AND t4.id IS NULL)"
|
||||
}
|
||||
sql += " ORDER BY t1.parentid;"
|
||||
var weixinList []*legacymodel.WeiXins
|
||||
db := dao.GetDB()
|
||||
err = dao.GetRows(db, &weixinList, sql, sqlParams...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
parentMap := make(map[int]*legacymodel.WeiXins)
|
||||
for _, v := range weixinList {
|
||||
if v.ParentID == -1 {
|
||||
parentMap[v.ID] = v
|
||||
} else {
|
||||
if parentMap[v.ParentID] != nil {
|
||||
v.JxStoreID = parentMap[v.ParentID].JxStoreID
|
||||
}
|
||||
}
|
||||
if v.Tel != "" {
|
||||
user := &model.User{
|
||||
UserID2: v.Tel,
|
||||
Name: v.NickName,
|
||||
Mobile: &v.Tel,
|
||||
Type: model.UserTypeStoreBoss,
|
||||
Remark: remark4Transfer,
|
||||
}
|
||||
if user.Name == "" {
|
||||
user.Name = user.GetMobile()
|
||||
}
|
||||
userList, _, err2 := dao.GetUsers(db, 0, "", "", nil, nil, []string{v.Tel}, 0, -1)
|
||||
if err = err2; err != nil {
|
||||
return err
|
||||
}
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(user, false))
|
||||
if len(userList) == 0 {
|
||||
err = CreateUser(user, v.LastOperator)
|
||||
} else {
|
||||
user = userList[0]
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if v.OpenID != "" {
|
||||
auth2.AddAuthBind(user, &auth2.AuthInfo{
|
||||
AuthBindInfo: &auth2.AuthBindEx{
|
||||
AuthBind: model.AuthBind{
|
||||
Type: weixin.AuthTypeMP,
|
||||
AuthID: v.OpenID,
|
||||
AuthID2: v.OpenIDUnion,
|
||||
Remark: remark4Transfer,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
if v.OpenIDMini != "" {
|
||||
auth2.AddAuthBind(user, &auth2.AuthInfo{
|
||||
AuthBindInfo: &auth2.AuthBindEx{
|
||||
AuthBind: model.AuthBind{
|
||||
Type: weixin.AuthTypeMini,
|
||||
AuthID: v.OpenIDMini,
|
||||
AuthID2: v.OpenIDUnion,
|
||||
Remark: remark4Transfer,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
if v.JxStoreID > 0 { // 运营就不加到门店老板组里了
|
||||
if user.Type&model.UserTypeOperator == 0 {
|
||||
api2.RoleMan.AddRole4User(user.GetID(), autils.NewStoreBossRole(v.JxStoreID))
|
||||
}
|
||||
} else {
|
||||
if mobile != "" {
|
||||
rList, err2 := api2.RoleMan.GetUserRoleList(user.GetID())
|
||||
if err = err2; err == nil {
|
||||
for _, role := range rList {
|
||||
if role.StoreID > 0 {
|
||||
api2.RoleMan.DeleteRole4User(user.GetID(), autils.NewStoreBossRole(role.StoreID))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -1,29 +1,18 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtunionapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/tbunionapi"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/ejyapi"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals/api2"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/authz/autils"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"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"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -54,60 +43,36 @@ func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
||||
"buildTime": buildTimeStr,
|
||||
"gitCommit": gitCommit,
|
||||
"metaData": map[string]interface{}{
|
||||
"vendorTypeName": model.VendorTypeName,
|
||||
"vendorName": model.VendorChineseNames,
|
||||
"vendorImg": model.VendorImg,
|
||||
"vendorColors": model.VendorColors,
|
||||
"vendorTypeName": model.VendorTypeName,
|
||||
"vendorName": model.VendorChineseNames,
|
||||
//"vendorImg": model.VendorImg,
|
||||
//"vendorColors": model.VendorColors,
|
||||
"orderStatus": model.OrderStatusName,
|
||||
"waybillStatus": model.WaybillStatusName,
|
||||
"orderTypeName": model.OrderTypeName,
|
||||
"taskStatusName": tasksch.TaskStatusName,
|
||||
"storeMsgSendStatusName": model.StoreMsgSendStatusName,
|
||||
"shopChineseNames": model.ShopChineseNames,
|
||||
"printerVendorInfo": model.PrinterVendorInfo,
|
||||
"purchaseVendorInfo": model.PurchaseVendorInfo,
|
||||
"afsReasonTypeName": model.AfsReasonTypeName,
|
||||
"afsAppealTypeName": model.AfsAppealTypeName,
|
||||
"actTypeName": model.ActTypeName,
|
||||
"actStatusName": model.ActStatusName,
|
||||
"actCreateTypeName": model.ActCreateTypeName,
|
||||
"configTypeName": model.ConfigTypeName,
|
||||
"userTypeName": model.UserTypeName,
|
||||
"payStatusName": model.PayStatusName,
|
||||
"refundStatusName": model.RefundStatusName,
|
||||
"complaintReasons": model.ComplaintReasons,
|
||||
"supplementType": model.SupplementTypeName,
|
||||
"operateType": model.OperateTypeName,
|
||||
"apiFunctionName": model.ApiFunctionName,
|
||||
"vendorStatus": model.VendorStatus,
|
||||
"jobLimitCountType": `[{
|
||||
"id":` + utils.Int2Str(model.JobLimitCountTypePO) +
|
||||
`,"value": "每人一次"
|
||||
},{
|
||||
"id":` + utils.Int2Str(model.JobLimitCountTypePDO) +
|
||||
`,"value": "每人每天一次"
|
||||
},{
|
||||
"id":` + utils.Int2Str(model.JobLimitCountTypePWO) +
|
||||
`,"value": "每人每周一次"
|
||||
},{
|
||||
"id":` + utils.Int2Str(model.JobLimitCountTypeNoLimit) +
|
||||
`,"value": "不限次"
|
||||
}]`,
|
||||
"billTypeNames": model.BillTypeNames,
|
||||
"deliveryStatusName": model.DeliveryStatusName,
|
||||
"cashbackName": model.CashbackName,
|
||||
"consumeName": model.ConsumeName,
|
||||
"txWaybillNames": model.TxWaybillNames,
|
||||
"unionActTypeNames": map[int]map[int]interface{}{
|
||||
model.VendorIDMTWM: map[int]interface{}{
|
||||
mtunionapi.ActTypeQB: "券包推广",
|
||||
},
|
||||
model.VendorIDTB: map[int]interface{}{
|
||||
tbunionapi.TbElmActTypeBDH: "本地化",
|
||||
},
|
||||
model.VendorIDPDD: map[int]interface{}{
|
||||
1: "进行中的活动",
|
||||
},
|
||||
//model.VendorIDTB: map[int]interface{}{
|
||||
// tbunionapi.TbElmActTypeBDH: "本地化",
|
||||
//},
|
||||
//model.VendorIDPDD: map[int]interface{}{
|
||||
// 1: "进行中的活动",
|
||||
//},
|
||||
model.VendorIDJDShop: map[int]interface{}{
|
||||
2: "进行中",
|
||||
},
|
||||
@@ -154,15 +119,6 @@ func GetPlaces(ctx *jxcontext.Context, keyword string, includeDisabled bool, par
|
||||
return places, dao.GetRows(nil, &places, sql, sqlParams)
|
||||
}
|
||||
|
||||
func GetCoordinateDistrictCode(ctx *jxcontext.Context, lng, lat float64) (code int, err error) {
|
||||
return api.AutonaviAPI.GetCoordinateDistrictCode(lng, lat), nil
|
||||
}
|
||||
|
||||
func GetCoordinateCityInfo(ctx *jxcontext.Context, lng, lat float64) (name string, err error) {
|
||||
name, _ = api.AutonaviAPI.GetCoordinateCityInfo(lng, lat)
|
||||
return name, err
|
||||
}
|
||||
|
||||
func SendMsg2Somebody(ctx *jxcontext.Context, mobileNum, verifyCode, msgType, msgContent string) (err error) {
|
||||
|
||||
return err
|
||||
@@ -187,47 +143,6 @@ func AddConfig(ctx *jxcontext.Context, key, configType, value string) (err error
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) {
|
||||
// if err = checkConfig(model.SyncFlagDeletedMask, configType, key, ""); err != nil {
|
||||
// return err
|
||||
// }
|
||||
db := dao.GetDB()
|
||||
switch configType {
|
||||
case model.ConfigTypePricePack:
|
||||
|
||||
case model.ConfigTypeFreightPack:
|
||||
|
||||
case model.ConfigTypeBank:
|
||||
//todo
|
||||
return fmt.Errorf("暂不支持删除银行")
|
||||
case model.ConfigTypeRole:
|
||||
errList := errlist.New()
|
||||
userIDs, err2 := api2.RoleMan.GetRoleUserList(autils.NewRole(key, 0))
|
||||
if err = err2; err == nil && len(userIDs) > 0 {
|
||||
userList, totalCount, err2 := dao.GetUsers(dao.GetDB(), 0, "", "", userIDs, nil, nil, 0, -1)
|
||||
if err = err2; err == nil && totalCount > 0 {
|
||||
// todo
|
||||
// err = fmt.Errorf("还有人员在使用角色:%s,人员信息:%s", key, utils.MustMarshal(utils.Struct2Map(userList, "compact")))
|
||||
err = fmt.Errorf("还有人员在使用角色:%s,人员信息:%s", key, utils.Format4Output(userList, false))
|
||||
}
|
||||
}
|
||||
errList.AddErr(err)
|
||||
|
||||
errList.AddErr(err)
|
||||
err = errList.GetErrListAsOne()
|
||||
}
|
||||
if err == nil {
|
||||
_, err = dao.DeleteEntityLogically(db, &model.NewConfig{}, nil, ctx.GetUserName(), map[string]interface{}{
|
||||
"Key": key,
|
||||
"Type": configType,
|
||||
})
|
||||
}
|
||||
if configType == model.ConfigTypeSys && err == nil {
|
||||
// err = onSysConfigChanged(key, "")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (hint string, err error) {
|
||||
if key == "" {
|
||||
return "", fmt.Errorf("修改配置必须给定key")
|
||||
@@ -268,106 +183,3 @@ func UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (hint s
|
||||
func QueryConfigs(key, configType, keyword string) (configList []*model.NewConfig, err error) {
|
||||
return dao.QueryConfigs(dao.GetDB(), key, configType, keyword)
|
||||
}
|
||||
|
||||
func InitStation(ctx *jxcontext.Context) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
stationMap = make(map[string]*model.StationInfo)
|
||||
stationEjyMap = make(map[string]*ejyapi.GetStationListResult)
|
||||
addList []*model.StationInfo
|
||||
updateList []*model.StationInfo
|
||||
deleteList []*model.StationInfo
|
||||
)
|
||||
api.EjyAPI.SetTimestamp(time.Now().Unix())
|
||||
if stations, err := dao.GetStationList(db); len(stations) > 0 && err == nil {
|
||||
for _, v := range stations {
|
||||
stationMap[v.StationID] = v
|
||||
}
|
||||
}
|
||||
if getStationListResult, err := api.EjyAPI.GetStationList(); len(getStationListResult) > 0 && err == nil {
|
||||
for _, v := range getStationListResult {
|
||||
stationEjyMap[v.StationID] = v
|
||||
if stationMap[v.StationID] == nil {
|
||||
addList = append(addList, EjyStationToStationInfo(v))
|
||||
} else {
|
||||
updateList = append(updateList, stationMap[v.StationID])
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, v := range stationMap {
|
||||
if stationEjyMap[v.StationID] == nil {
|
||||
deleteList = append(deleteList, v)
|
||||
}
|
||||
}
|
||||
task := tasksch.NewParallelTask("InitStation", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
step := batchItemList[0].(int)
|
||||
switch step {
|
||||
case 0:
|
||||
if len(addList) > 0 {
|
||||
err = dao.CreateMultiEntities(db, addList)
|
||||
}
|
||||
case 1:
|
||||
if len(updateList) > 0 {
|
||||
task := tasksch.NewParallelTask("updateList", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
station := batchItemList[0].(*model.StationInfo)
|
||||
dao.UpdateEntity(db, station)
|
||||
return retVal, err
|
||||
}, updateList)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
case 2:
|
||||
if len(deleteList) > 0 {
|
||||
task := tasksch.NewParallelTask("deleteList", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
station := batchItemList[0].(*model.StationInfo)
|
||||
dao.DeleteEntity(db, station)
|
||||
return retVal, err
|
||||
}, deleteList)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, []int{0, 1, 2})
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
return err
|
||||
}
|
||||
|
||||
func EjyStationToStationInfo(station *ejyapi.GetStationListResult) (stationInfo *model.StationInfo) {
|
||||
stationInfo = &model.StationInfo{
|
||||
StationID: station.StationID,
|
||||
StationName: station.StationName,
|
||||
ProvinceName: station.ProvinceName,
|
||||
ProvinceID: station.ProvinceID,
|
||||
CityName: station.CityName,
|
||||
Latitude: utils.Str2Float64(station.Latitude),
|
||||
Longitude: utils.Str2Float64(station.Longitude),
|
||||
Location: station.Location,
|
||||
StarNum: station.StarNum,
|
||||
Phone: station.Phone,
|
||||
StationPic: station.StationPic,
|
||||
StationBannerPic: station.StationBannerPic,
|
||||
District: station.District,
|
||||
CityID: station.CityID,
|
||||
StationType: station.StationType,
|
||||
}
|
||||
if station.Prices != nil {
|
||||
if data, err := json.Marshal(station.Prices); err == nil {
|
||||
stationInfo.Prices = string(data)
|
||||
}
|
||||
}
|
||||
if station.Adverts != nil {
|
||||
if data, err := json.Marshal(station.Adverts); err == nil {
|
||||
stationInfo.Adverts = string(data)
|
||||
}
|
||||
}
|
||||
return stationInfo
|
||||
}
|
||||
|
||||
func GetStationList(ctx *jxcontext.Context, stationName string, cityCode int, lat, lng float64, oilCode string, sortType, offset, pageSize int) (pageInfo *model.PagedInfo, err error) {
|
||||
return dao.GetStationInfoList(dao.GetDB(), stationName, cityCode, lat, lng, oilCode, sortType, offset, pageSize)
|
||||
}
|
||||
|
||||
11
business/jxstore/cms/conn_test.go
Normal file
11
business/jxstore/cms/conn_test.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConn(t *testing.T) {
|
||||
err := DelPrinterSeq(1000, "120220915001012")
|
||||
fmt.Println(err)
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,10 +4,10 @@ import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"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/dao"
|
||||
)
|
||||
|
||||
type MessageStatusExt struct {
|
||||
|
||||
@@ -1,286 +0,0 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/event"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/financial"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func CreateOrder(ctx *jxcontext.Context, type1, orderType int, way string, price int, lng, lat float64) (orderID, errCode string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
order *model.Order
|
||||
DayTimeBegin, DayTimeEnd = jxutils.GetDayTime()
|
||||
)
|
||||
if err = auth2.CheckWeixinminiAuthBind(ctx.GetUserID()); err != nil {
|
||||
return "", errCode, err
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if type1 == model.OrderTypeCash {
|
||||
//如果用户没有对应账单信息就给他生成一条
|
||||
userBill, err := dao.GetUserBill(db, ctx.GetUserID(), "")
|
||||
if userBill == nil {
|
||||
err = financial.AddUserBill(txDB, jxutils.GenBillID(), ctx.GetUserID())
|
||||
}
|
||||
if userBill.AccountBalance < price {
|
||||
return "", model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("用户余额不足!")
|
||||
}
|
||||
//用户一天只能提现一次
|
||||
billExpends, err := dao.GetBillExpend(db, ctx.GetUserID(), model.BillTypeCash, DayTimeBegin, DayTimeEnd)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
if len(billExpends) > 0 {
|
||||
return "", "", fmt.Errorf("抱歉,一天只能提现一次!")
|
||||
}
|
||||
}
|
||||
address, dCode, cCode, err := getAddressInfoFromCoord(db, lng, lat)
|
||||
order = &model.Order{
|
||||
OrderID: utils.Int64ToStr(jxutils.GenOrderNo()),
|
||||
UserID: ctx.GetUserID(),
|
||||
Type: type1,
|
||||
OrderType: orderType,
|
||||
Way: way,
|
||||
Status: model.OrderStatusWait4Pay,
|
||||
PayPrice: price,
|
||||
Lng: lng,
|
||||
Lat: lat,
|
||||
Address: address,
|
||||
DistrictCode: dCode,
|
||||
CityCode: cCode,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(order, ctx.GetUserName())
|
||||
if err = dao.CreateEntityTx(txDB, order); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
return order.OrderID, errCode, err
|
||||
}
|
||||
|
||||
func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType string) (result *financial.WxPayParam, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
order = &model.Order{
|
||||
OrderID: orderID,
|
||||
}
|
||||
payHandler = &financial.PayHandler{
|
||||
PayType: payType,
|
||||
Ctx: ctx,
|
||||
VendorPayType: vendorPayType,
|
||||
}
|
||||
)
|
||||
globals.SugarLogger.Debugf("pay begin……")
|
||||
err = dao.GetEntity(db, order, "OrderID")
|
||||
if order.ID == 0 {
|
||||
return result, fmt.Errorf("未找到此订单!")
|
||||
}
|
||||
payHandler.Order = order
|
||||
//如果用户没有对应账单信息就给他生成一条
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
||||
if userBill == nil {
|
||||
err = financial.AddUserBill(txDB, jxutils.GenBillID(), order.UserID)
|
||||
}
|
||||
err = payHandler.CreatePay(txDB)
|
||||
dao.Commit(db, txDB)
|
||||
globals.SugarLogger.Debugf("result : %v", utils.Format4Output(payHandler.WxPayParam, false))
|
||||
return payHandler.WxPayParam, err
|
||||
}
|
||||
|
||||
func Cash(ctx *jxcontext.Context, orderID string, payType int, vendorPayType string) (errCode string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
order = &model.Order{
|
||||
OrderID: orderID,
|
||||
}
|
||||
payHandler = &financial.PayHandler{
|
||||
PayType: payType,
|
||||
Ctx: ctx,
|
||||
VendorPayType: vendorPayType,
|
||||
}
|
||||
)
|
||||
err = dao.GetEntity(db, order, "OrderID")
|
||||
if err != nil {
|
||||
return errCode, err
|
||||
}
|
||||
if order.ID == 0 {
|
||||
return errCode, fmt.Errorf("未找到此订单!")
|
||||
}
|
||||
payHandler.Order = order
|
||||
err = payHandler.CreateRefund()
|
||||
return errCode, err
|
||||
}
|
||||
|
||||
func GetOrders(ctx *jxcontext.Context, orderID, userID string, orderType int, cityCodes []int, fromTime, toTime, keyword string, offset, pageSize int) (pageInfo *model.PagedInfo, err error) {
|
||||
return dao.GetOrders(dao.GetDB(), orderID, userID, orderType, cityCodes, utils.Str2Time(fromTime), utils.Str2Time(toTime), keyword, offset, pageSize)
|
||||
}
|
||||
|
||||
func FinishedCashOrders(ctx *jxcontext.Context, orderIDs []string) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
for _, orderID := range orderIDs {
|
||||
order := &model.Order{
|
||||
OrderID: orderID,
|
||||
}
|
||||
dao.GetEntity(db, order, "OrderID")
|
||||
if order.ID != 0 && order.Status == model.OrderStatusWait4Pay {
|
||||
order.PayFinishedAt = time.Now()
|
||||
order.Comment = "手动转账"
|
||||
order.Status = model.OrderStatusFinished
|
||||
dao.UpdateEntity(db, order, "PayFinishedAt", "Comment", "Status")
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func GetPayStatistics(ctx *jxcontext.Context, userID string, pop int, cityCodes []int, mobile, fromTime, toTime string, consumeTypes []int) (getPayStatisticsResult *dao.GetPayStatisticsResult, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
return dao.GetPayStatistics(db, userID, pop, cityCodes, mobile, utils.Str2Time(fromTime), utils.Str2Time(toTime), consumeTypes)
|
||||
}
|
||||
|
||||
func GetManageStatisticsImg(ctx *jxcontext.Context, cityCodes []int, fromTime, toTime string, jobIDs []int) (getManageStatistics []*dao.GetManageStatisticsResult, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
fromTimeT = utils.Str2Time(fromTime)
|
||||
toTimeT = utils.Str2Time(toTime)
|
||||
)
|
||||
for i := 1; i < utils.Float64TwoInt(toTimeT.Sub(fromTimeT).Hours()/24)+1; i++ {
|
||||
getManageStatisticsResult, _ := dao.GetManageStatistics(db, cityCodes, fromTimeT.AddDate(0, 0, i-1), jobIDs)
|
||||
getManageStatistics = append(getManageStatistics, getManageStatisticsResult)
|
||||
}
|
||||
return getManageStatistics, err
|
||||
}
|
||||
|
||||
func GetManageStatisticsJob(ctx *jxcontext.Context, cityCodes []int, fromTime, toTime string, jobIDs []int, offset, pageSize int) (paged *model.PagedInfo, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
return dao.GetManageStatisticsJob(db, cityCodes, utils.Str2Time(fromTime), utils.Str2Time(toTime), jobIDs, offset, pageSize)
|
||||
}
|
||||
|
||||
func NewUnionOrder(unionOrder *model.UnionOrder, orderStatus *model.UnionOrderStatus) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
userID string
|
||||
)
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
userBinds, err := dao.GetUserUnionBind(db, "", unionOrder.VendorID, unionOrder.PID)
|
||||
if err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return err
|
||||
}
|
||||
if len(userBinds) == 0 {
|
||||
userID = unionOrder.PID
|
||||
} else {
|
||||
userID = userBinds[0].UserID
|
||||
}
|
||||
unionOrder.UserID = userID
|
||||
dao.WrapAddIDCULEntity(unionOrder, jxcontext.AdminCtx.GetUserName())
|
||||
if err = dao.CreateEntityTx(txDB, unionOrder); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return err
|
||||
}
|
||||
dao.WrapAddIDCULEntity(orderStatus, jxcontext.AdminCtx.GetUserName())
|
||||
if err = dao.CreateEntityTx(txDB, orderStatus); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return err
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
//发消息
|
||||
if err == nil {
|
||||
orderMessage(unionOrder)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func ChangeUnionOrder(unionOrder *model.UnionOrder, orderStatus *model.UnionOrderStatus) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
globals.SugarLogger.Debugf("ChangeUnionOrder1, unionorder: %v", utils.Format4Output(unionOrder, true))
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
unionOrder.Status = orderStatus.Status
|
||||
globals.SugarLogger.Debugf("ChangeUnionOrder2, unionorder: %v", utils.Format4Output(unionOrder, true))
|
||||
if _, err = dao.UpdateEntityTx(txDB, unionOrder, "Status"); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
fmt.Println("err1", err)
|
||||
return err
|
||||
}
|
||||
dao.WrapAddIDCULEntity(orderStatus, jxcontext.AdminCtx.GetUserName())
|
||||
if err = dao.CreateEntityTx(txDB, orderStatus); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
fmt.Println("err2", err)
|
||||
return err
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
//发消息
|
||||
if err == nil {
|
||||
orderMessage(unionOrder)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func orderMessage(unionOrder *model.UnionOrder) {
|
||||
content := new(strings.Builder)
|
||||
content.WriteString("您有[")
|
||||
content.WriteString(model.VendorChineseNames[unionOrder.VendorID])
|
||||
content.WriteString("]平台的推广订单:")
|
||||
content.WriteString(unionOrder.VendorOrderID)
|
||||
content.WriteString("。")
|
||||
content.WriteString(model.UnionOrderStatusName[unionOrder.Status])
|
||||
content.WriteString("。预计返佣:")
|
||||
content.WriteString(jxutils.IntPrice2StandardString(int64(unionOrder.PromotionAmount)))
|
||||
content.WriteString("元。")
|
||||
event.SendSysMessageSimple(content.String(), unionOrder.UserID)
|
||||
}
|
||||
|
||||
func GetMyUnionOrders(ctx *jxcontext.Context, statuss []int, vendorID, offset, pageSize int) (page *model.PagedInfo, err error) {
|
||||
return dao.GetMyUnionOrders(dao.GetDB(), ctx.GetUserID(), statuss, vendorID, offset, pageSize)
|
||||
}
|
||||
|
||||
func GetUnionOrders(ctx *jxcontext.Context, vendorIDs, statuss []int, beginTime, endTime, keyword string, offset, pageSize int) (page *model.PagedInfo, err error) {
|
||||
return dao.GetUnionOrdersPage(dao.GetDB(), vendorIDs, statuss, utils.Str2Time(beginTime), utils.Str2Time(endTime), keyword, offset, pageSize)
|
||||
}
|
||||
@@ -1,287 +0,0 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"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/dao"
|
||||
)
|
||||
|
||||
func GetMenu(ctx *jxcontext.Context, userID string) (menus []*model.Menu, err error) {
|
||||
if userID == "" {
|
||||
return dao.GetMenu(dao.GetDB(), "", 0, userID)
|
||||
} else {
|
||||
return dao.GetMenuWithUser(dao.GetDB(), "", 0, userID)
|
||||
}
|
||||
}
|
||||
|
||||
func AddMenu(ctx *jxcontext.Context, menu *model.Menu) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
if menu == nil {
|
||||
return fmt.Errorf("添加失败!menu nil")
|
||||
}
|
||||
if menu.Name == "" || menu.Level == 0 {
|
||||
return fmt.Errorf("添加失败!menu 名称和等级必须有值!")
|
||||
}
|
||||
menus, err := dao.GetMenu(db, menu.Name, menu.Level, "")
|
||||
if len(menus) > 0 {
|
||||
return fmt.Errorf("添加失败!已存在相同名称的 menu name : %v", menu.Name)
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
dao.WrapAddIDCULDEntity(menu, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, menu)
|
||||
dao.Commit(db, txDB)
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateMenu(ctx *jxcontext.Context, menuID int, payload map[string]interface{}, isDelete bool) (num int64, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
menu := &model.Menu{}
|
||||
menu.ID = menuID
|
||||
err = dao.GetEntity(db, menu)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if !isDelete {
|
||||
valid := dao.StrictMakeMapByStructObject(payload, menu, ctx.GetUserName())
|
||||
if len(valid) > 0 {
|
||||
if num, err = dao.UpdateEntityLogically(db, menu, valid, ctx.GetUserName(), nil); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
menu.DeletedAt = time.Now()
|
||||
num, err = dao.UpdateEntity(db, menu, "DeletedAt")
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
return num, err
|
||||
}
|
||||
|
||||
func GetRole(ctx *jxcontext.Context) (roles []*model.Role, err error) {
|
||||
return dao.GetRole(dao.GetDB(), "")
|
||||
}
|
||||
|
||||
func AddRole(ctx *jxcontext.Context, name string) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
roles, err := dao.GetRole(db, name)
|
||||
if len(roles) > 0 {
|
||||
return fmt.Errorf("添加失败!已存在相同名称的 role name : %v", name)
|
||||
}
|
||||
role := &model.Role{
|
||||
Name: name,
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
dao.WrapAddIDCULDEntity(role, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, role)
|
||||
dao.Commit(db, txDB)
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateRole(ctx *jxcontext.Context, roleID int, name string, isDelete bool) (num int64, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
if roleID == 1 {
|
||||
return 0, fmt.Errorf("管理员不允许修改!")
|
||||
}
|
||||
role := &model.Role{}
|
||||
role.ID = roleID
|
||||
err = dao.GetEntity(db, role)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if !isDelete {
|
||||
role.Name = name
|
||||
role.UpdatedAt = time.Now()
|
||||
role.LastOperator = ctx.GetUserName()
|
||||
num, err = dao.UpdateEntity(db, role, "Name", "UpdatedAt", "LastOperator")
|
||||
} else {
|
||||
role.DeletedAt = time.Now()
|
||||
num, err = dao.UpdateEntity(db, role, "DeletedAt")
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
return num, err
|
||||
}
|
||||
|
||||
func GetUserRole(ctx *jxcontext.Context, userID string) (userRoles []*model.UserRole, err error) {
|
||||
return dao.GetUserRole(dao.GetDB(), []string{userID}, nil)
|
||||
}
|
||||
|
||||
func UpdateUserRole(ctx *jxcontext.Context, userIDs []string, roleIDs []int) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
roleIDMap = make(map[int]int)
|
||||
nowRoleIDMap = make(map[int]int)
|
||||
userRoleMap = make(map[string][]int)
|
||||
addUserRoleMap = make(map[string][]int)
|
||||
deleteUserRoleMap = make(map[string][]int)
|
||||
)
|
||||
for _, v := range roleIDs {
|
||||
roleIDMap[v] = 1
|
||||
}
|
||||
userRoles, err := dao.GetUserRole(db, userIDs, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(userRoles) > 0 {
|
||||
for _, v := range userRoles {
|
||||
userRoleMap[v.UserID] = append(userRoleMap[v.UserID], v.RoleID)
|
||||
}
|
||||
}
|
||||
for _, userID := range userIDs {
|
||||
nowRoleIDs := userRoleMap[userID]
|
||||
for _, nowRoleID := range nowRoleIDs {
|
||||
if roleIDMap[nowRoleID] == 0 {
|
||||
deleteUserRoleMap[userID] = append(deleteUserRoleMap[userID], nowRoleID)
|
||||
}
|
||||
nowRoleIDMap[nowRoleID] = 1
|
||||
}
|
||||
for _, roleID := range roleIDMap {
|
||||
if nowRoleIDMap[roleID] == 0 {
|
||||
addUserRoleMap[userID] = append(addUserRoleMap[userID], roleID)
|
||||
}
|
||||
}
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if len(addUserRoleMap) > 0 {
|
||||
for userID, roleIDs := range addUserRoleMap {
|
||||
for _, roleID := range roleIDs {
|
||||
userRole := &model.UserRole{
|
||||
UserID: userID,
|
||||
RoleID: roleID,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(userRole, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, userRole)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(deleteUserRoleMap) > 0 {
|
||||
for userID, roleIDs := range deleteUserRoleMap {
|
||||
for _, roleID := range roleIDs {
|
||||
userRoles, _ := dao.GetUserRole(db, []string{userID}, []int{roleID})
|
||||
if len(userRoles) > 0 {
|
||||
userRoles[0].DeletedAt = time.Now()
|
||||
userRoles[0].LastOperator = ctx.GetUserName()
|
||||
_, err = dao.UpdateEntity(db, userRoles[0], "DeletedAt", "LastOperator")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
return err
|
||||
}
|
||||
|
||||
func GetRoleMenu(ctx *jxcontext.Context, roleID int) (roleMenus []*model.RoleMenu, err error) {
|
||||
return dao.GetRoleMenu(dao.GetDB(), []int{roleID}, nil)
|
||||
}
|
||||
|
||||
func UpdateRoleMenu(ctx *jxcontext.Context, roleIDs, menuIDs []int) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
menuIDMap = make(map[int]int)
|
||||
nowMenuIDMap = make(map[int]int)
|
||||
roleMenuMap = make(map[int][]int)
|
||||
addRoleMenuMap = make(map[int][]int)
|
||||
deleteRoleMenuMap = make(map[int][]int)
|
||||
)
|
||||
for _, v := range menuIDs {
|
||||
menuIDMap[v] = 1
|
||||
}
|
||||
roleMenus, err := dao.GetRoleMenu(db, roleIDs, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(roleMenus) > 0 {
|
||||
for _, v := range roleMenus {
|
||||
roleMenuMap[v.RoleID] = append(roleMenuMap[v.RoleID], v.MenuID)
|
||||
}
|
||||
}
|
||||
for _, roleID := range roleIDs {
|
||||
nowMenuIDs := roleMenuMap[roleID]
|
||||
for _, nowMenuID := range nowMenuIDs {
|
||||
if menuIDMap[nowMenuID] == 0 {
|
||||
deleteRoleMenuMap[roleID] = append(deleteRoleMenuMap[roleID], nowMenuID)
|
||||
}
|
||||
nowMenuIDMap[nowMenuID] = 1
|
||||
}
|
||||
for _, menuID := range menuIDMap {
|
||||
if nowMenuIDMap[menuID] == 0 {
|
||||
addRoleMenuMap[menuID] = append(addRoleMenuMap[menuID], menuID)
|
||||
}
|
||||
}
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if len(addRoleMenuMap) > 0 {
|
||||
for roleID, menuIDs := range addRoleMenuMap {
|
||||
for _, menuID := range menuIDs {
|
||||
roleMenu := &model.RoleMenu{
|
||||
RoleID: roleID,
|
||||
MenuID: menuID,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(roleMenu, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, roleMenu)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(deleteRoleMenuMap) > 0 {
|
||||
for roleID, menuIDs := range deleteRoleMenuMap {
|
||||
for _, menuID := range menuIDs {
|
||||
roleMenus, _ := dao.GetRoleMenu(db, []int{roleID}, []int{menuID})
|
||||
if len(roleMenus) > 0 {
|
||||
roleMenus[0].DeletedAt = time.Now()
|
||||
roleMenus[0].LastOperator = ctx.GetUserName()
|
||||
_, err = dao.UpdateEntity(db, roleMenus[0], "DeletedAt", "LastOperator")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
return err
|
||||
}
|
||||
467
business/jxstore/cms/print.go
Normal file
467
business/jxstore/cms/print.go
Normal file
@@ -0,0 +1,467 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"net"
|
||||
"regexp"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
sounda = "sounda" //提示音a
|
||||
soundb = "soundb" //提示音b
|
||||
soundc = "soundc" //提示音c
|
||||
soundd = "soundd" //提示音d
|
||||
sounde = "sounde" //报警音e
|
||||
soundf = "soundf" //报警音f
|
||||
soundg = "soundg" //报警音g
|
||||
)
|
||||
|
||||
type PrintInfo struct {
|
||||
PrintNo string
|
||||
AppID int
|
||||
}
|
||||
|
||||
var (
|
||||
regexpMobile = regexp.MustCompile("^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\\d{8}$")
|
||||
soundMap = map[string]string{
|
||||
"sounda": "sounda",
|
||||
"soundb": "soundb",
|
||||
"soundc": "soundc",
|
||||
"soundd": "soundd",
|
||||
"sounde": "sounde",
|
||||
"soundf": "soundf",
|
||||
"soundg": "soundg",
|
||||
}
|
||||
)
|
||||
|
||||
func AddPrinter(appID int, printers []*model.AddPrinterParam) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
errs []error
|
||||
)
|
||||
if len(printers) > 50 {
|
||||
return fmt.Errorf("一次最多只能绑定50台!")
|
||||
}
|
||||
for _, v := range printers {
|
||||
if printers2, _ := dao.GetPrinters(db, appID, v.PrintNo, 0, 0); len(printers2) > 0 {
|
||||
// 代表打印机已经在小程序注册了,查询打印机授权门店
|
||||
bindStoreList, err := dao.QueryPrintBindStore(v.PrintNo)
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Errorf("QueryPrintBindStore err : %v ", err))
|
||||
continue
|
||||
}
|
||||
if len(bindStoreList) >= 5 {
|
||||
errs = append(errs, fmt.Errorf("当前打印机绑定门店数据超过五个,无法继续绑定"))
|
||||
continue
|
||||
}
|
||||
have := false
|
||||
userId := ""
|
||||
for _, bsl := range bindStoreList {
|
||||
if bsl.StoreID == v.StoreId {
|
||||
have = true
|
||||
userId = bsl.UserId
|
||||
}
|
||||
}
|
||||
if !have {
|
||||
if err := dao.BindStoreList(printers[0], userId); err != nil {
|
||||
errs = append(errs, fmt.Errorf("BindStoreList err : %v ", err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
//验证
|
||||
if err = checkPrinterInfo(v.PrintNo, v.Name, "", "", 0); err != nil {
|
||||
errs = append(errs, err)
|
||||
continue
|
||||
}
|
||||
// 检查心跳
|
||||
exits, err := dao.CheckHeard(v.PrintNo)
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Errorf("CheckHeard err : %v ", err))
|
||||
continue
|
||||
}
|
||||
if !exits {
|
||||
errs = append(errs, fmt.Errorf("打印机未激活,请激活后在绑定"))
|
||||
continue
|
||||
}
|
||||
|
||||
printer := &model.Printer{
|
||||
AppID: appID,
|
||||
PrintNo: v.PrintNo,
|
||||
Name: v.Name,
|
||||
IccID: "",
|
||||
Status: model.PrinterStatusOffline,
|
||||
Sound: "sounda",
|
||||
PrintKey: v.SIM,
|
||||
IsOnline: 0,
|
||||
Volume: 1,
|
||||
FlowFlag: 0,
|
||||
OfflineCount: 0,
|
||||
UserId: "system_user",
|
||||
}
|
||||
|
||||
// 创建打印机
|
||||
if err := InitPrint(printer, v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
err = jxutils.BuildErr(errs)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func InitPrint(printer *model.Printer, printParam *model.AddPrinterParam) error {
|
||||
txDb, _ := dao.Begin(dao.GetDB())
|
||||
// 创建打印机
|
||||
dao.WrapAddIDCULDEntity(printer, "")
|
||||
if err := dao.CreateEntityTx(txDb, printer); err != nil {
|
||||
txDb.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
// 赋予打印机默认配置
|
||||
day := time.Now()
|
||||
param, err := MarshalJson2String(&model.PrintSetting{
|
||||
CreatedAt: day,
|
||||
UpdatedAt: day,
|
||||
DeletedAt: utils.DefaultTimeValue,
|
||||
PrintNo: printer.PrintNo,
|
||||
CallNameSetting: 64, // 老板
|
||||
BusinessOffLineVoice: 1, // 离线开关
|
||||
BalanceNotEnoughVoice: 1, // 余额不足
|
||||
EveryDayGreetVoice: 1, // 问好
|
||||
BusinessPrintNum: 1, // 商户侧打印次数
|
||||
CustomerPrintNum: 1, // 用户侧打印次数
|
||||
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := dao.CreateEntityTx(txDb, param); err != nil {
|
||||
txDb.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
// 初始化打印机账户
|
||||
if err := dao.CreateEntityTx(txDb, &model.PrintBill{
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
PrintNo: param.PrintNo,
|
||||
PrintBalance: 20000,
|
||||
UserId: "system",
|
||||
}); err != nil {
|
||||
txDb.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
// 初始化绑定信息
|
||||
if err := dao.BindStoreList(printParam, ""); err != nil {
|
||||
txDb.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
defer txDb.Commit()
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalJson2String 工具类
|
||||
func MarshalJson2String(param *model.PrintSetting) (*model.PrintSetting, error) {
|
||||
// 语音设置
|
||||
voiceSetting := &model.VoiceSettingDetail{
|
||||
WaitOrderVoice: model.SettingOpen,
|
||||
RiderTakeOrderVoice: model.SettingOpen,
|
||||
ApplyUserOrderCancelVoice: model.SettingOpen,
|
||||
ApplyRefundOrderVoice: model.SettingOpen,
|
||||
ApplyRefundGoodsVoice: model.SettingOpen,
|
||||
RefundGoodsVoice: model.SettingOpen,
|
||||
ConfirmGoodsVoice: model.SettingOpen,
|
||||
SuccessGoodsVoice: model.SettingOpen,
|
||||
ConsultingPrint: model.SettingOpen,
|
||||
ReminderVoice: model.SettingOpen,
|
||||
CustomerRejectionVoice: model.SettingOpen,
|
||||
CusterRefundVoice: model.SettingOpen,
|
||||
LoseAuthorization: model.SettingOpen,
|
||||
}
|
||||
customerVoiceSettingByte, err := json.Marshal(voiceSetting)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
param.VoiceSetting = string(customerVoiceSettingByte)
|
||||
|
||||
// 打印设置
|
||||
printSetting := &model.PrintSettingDetail{
|
||||
UserOrderCancel: model.SettingOpen,
|
||||
RefundOrder: model.SettingOpen,
|
||||
BusinessOrderCancel: model.SettingOpen,
|
||||
RiderTakeOrder: model.SettingOpen,
|
||||
CusterRefundPrint: model.SettingOpen,
|
||||
WaitOrderPrint: model.SettingOpen,
|
||||
ApplyUserCancelOrder: model.SettingOpen,
|
||||
ApplyUserRefund: model.SettingOpen,
|
||||
OrderCancelSuccess: model.SettingOpen,
|
||||
}
|
||||
pickingSettingByte, err := json.Marshal(printSetting)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
param.PrintSetting = string(pickingSettingByte)
|
||||
return param, nil
|
||||
}
|
||||
|
||||
func checkPrinterInfo(printNo, name, sound, sim string, volume int) (err error) {
|
||||
if printNo != "" {
|
||||
|
||||
}
|
||||
if sim != "" {
|
||||
//if regexpMobile.FindString(sim) == "" {
|
||||
return fmt.Errorf("暂不支持修改sim卡号码!print_no : %v ", printNo)
|
||||
//}
|
||||
}
|
||||
if volume != 0 {
|
||||
if volume <= 0 || volume > 5 {
|
||||
return fmt.Errorf("请输入正确的音量1-5!print_no : %v ", printNo)
|
||||
}
|
||||
}
|
||||
if sound != "" {
|
||||
if soundMap[sound] == "" {
|
||||
return fmt.Errorf("请输入正确的提示音!print_no : %v ", printNo)
|
||||
}
|
||||
}
|
||||
if name != "" {
|
||||
if len(name) > 255 {
|
||||
return fmt.Errorf("打印机备注不能超过255个字符!print_no : %v ", printNo)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func DelPrinter(appID int, printNos []string, storeId string) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
errs []error
|
||||
)
|
||||
for _, v := range printNos {
|
||||
if printers, _ := dao.GetPrinters(db, appID, v, 0, 0); len(printers) == 0 {
|
||||
errs = append(errs, fmt.Errorf("该应用下未找到该打印机!print_no : %v ", v))
|
||||
continue
|
||||
} else {
|
||||
if err := dao.DeleteStoreList(printers[0].PrintNo, storeId); err != nil {
|
||||
errs = append(errs, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
err = jxutils.BuildErr(errs)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdatePrinter(appID int, printNo string, name, sim, sound *string, volume *int) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
fields []string
|
||||
)
|
||||
//看有没有
|
||||
if printers, _ := dao.GetPrinters(db, appID, printNo, 0, 0); len(printers) == 0 {
|
||||
return fmt.Errorf("该应用下未找到该打印机!print_no : %v", printNo)
|
||||
} else {
|
||||
if name != nil {
|
||||
if *name != "" {
|
||||
if len(*name) > 20 {
|
||||
return fmt.Errorf("打印机备注不能超过20个字符!print_no : %v ", printNo)
|
||||
}
|
||||
}
|
||||
if printers[0].Name != *name {
|
||||
printers[0].Name = *name
|
||||
fields = append(fields, "name")
|
||||
}
|
||||
}
|
||||
if sim != nil {
|
||||
if *sim != "" {
|
||||
//if regexpMobile.FindString(*sim) == "" {
|
||||
return fmt.Errorf("暂不支持修改sim卡号码!print_no : %v ", printNo)
|
||||
//}
|
||||
}
|
||||
//if printers[0].SIM != *sim {
|
||||
// printers[0].SIM = *sim
|
||||
// fields = append(fields, "sim")
|
||||
//}
|
||||
}
|
||||
if sound != nil {
|
||||
if *sound != "" {
|
||||
if soundMap[*sound] == "" {
|
||||
return fmt.Errorf("请输入正确的提示音!print_no : %v ", printNo)
|
||||
}
|
||||
}
|
||||
if printers[0].Sound != *sound {
|
||||
printers[0].Sound = *sound
|
||||
fields = append(fields, "sound")
|
||||
}
|
||||
}
|
||||
if volume != nil {
|
||||
if *volume <= 0 || *volume > 5 {
|
||||
return fmt.Errorf("请输入正确的音量 1-5!print_no : %v ", printNo)
|
||||
}
|
||||
if printers[0].Volume != *volume {
|
||||
printers[0].Volume = *volume
|
||||
fields = append(fields, "volume")
|
||||
}
|
||||
}
|
||||
if _, err = dao.UpdateEntity(db, printers[0], fields...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func DelPrinterSeq(appID int, printNo string) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
//看有没有
|
||||
if printers, _ := dao.GetPrinters(db, appID, printNo, 0, 0); len(printers) == 0 {
|
||||
return fmt.Errorf("该应用下未找到该打印机!print_no : %v", printNo)
|
||||
} else {
|
||||
printMsgs, _ := dao.GetPrintMsgs(db, printNo, "", model.PrintMsgAll, model.PrintMsgSuccess)
|
||||
for _, v := range printMsgs {
|
||||
v.DeletedAt = time.Now()
|
||||
if _, err = dao.UpdateEntity(db, v, "DeletedAt"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 简历连接
|
||||
conn, err := net.Dial("tcp", "www.jxcs.net:8000")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
clearPrint := fmt.Sprintf(`{"print_no_clear":%s}`, printNo)
|
||||
// 发送数据
|
||||
if _, err := conn.Write([]byte(clearPrint)); err != nil {
|
||||
return err
|
||||
}
|
||||
// 等待数据
|
||||
buf := make([]byte, 1024)
|
||||
n, err := conn.Read(buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if string(buf[:n]) != "ok" {
|
||||
return errors.New("缓存清理失败")
|
||||
}
|
||||
defer conn.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
func DoPrintMsg(appID int, msgID, printNo, content string, orderNo string) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
//打印机必须绑定在该应用下才能打印
|
||||
if printers, _ := dao.GetPrinters(db, appID, printNo, 0, 0); len(printers) == 0 {
|
||||
return fmt.Errorf("未在该应用下获取到此打印机!print_no %v", printNo)
|
||||
}
|
||||
printMsg := &model.PrintMsg{
|
||||
PrintNo: printNo,
|
||||
Content: content,
|
||||
OrderNo: orderNo,
|
||||
MsgID: msgID,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(printMsg, "")
|
||||
if err = dao.CreateEntity(db, printMsg); err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
type GetPrintMsgResult struct {
|
||||
MsgID string `json:"msg_id"` //消息ID
|
||||
PrintNo string `json:"print_no"` //打印机编号
|
||||
OrderNo string `json:"order_no"` //订单序号
|
||||
Content string `json:"content"` //订单内容
|
||||
Status int `json:"status"` //打印状态
|
||||
Comment string `json:"comment"` //失败原因
|
||||
}
|
||||
|
||||
func GetPrintMsg(appID int, msgID string) (printMsg *GetPrintMsgResult, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
if printMsgs, _ := dao.GetPrintMsgs(db, "", msgID, model.PrintMsgAll, model.PrintMsgAll); len(printMsgs) > 0 {
|
||||
result := printMsgs[0]
|
||||
printMsg = &GetPrintMsgResult{
|
||||
MsgID: result.MsgID,
|
||||
PrintNo: result.PrintNo,
|
||||
OrderNo: result.OrderNo,
|
||||
Content: result.Content,
|
||||
Status: result.Status,
|
||||
Comment: result.Comment,
|
||||
}
|
||||
return printMsg, err
|
||||
} else {
|
||||
return printMsg, fmt.Errorf("未找到该消息!msg_id :%v", msgID)
|
||||
}
|
||||
}
|
||||
|
||||
func GetPrinterStatus(appID int, printNo string) (status int, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
//看有没有
|
||||
if printers, _ := dao.GetPrinters(db, appID, printNo, 0, 0); len(printers) == 0 {
|
||||
return status, fmt.Errorf("该应用下未找到该打印机!print_no : %v", printNo)
|
||||
} else {
|
||||
return printers[0].Status + printers[0].IsOnline, nil // 当两个值都唯一时->在线正常
|
||||
server := "print.jxcs.net:8000"
|
||||
tcpAddr, err := net.ResolveTCPAddr("tcp4", server)
|
||||
if err != nil {
|
||||
//os.Exit(1)
|
||||
return status, err
|
||||
}
|
||||
conn, err := net.DialTCP("tcp", nil, tcpAddr)
|
||||
if err != nil {
|
||||
return status, err
|
||||
}
|
||||
status = connHandler(conn, &PrintInfo{
|
||||
PrintNo: printNo,
|
||||
AppID: appID,
|
||||
})
|
||||
return status, nil
|
||||
}
|
||||
}
|
||||
|
||||
func connHandler(c net.Conn, printInfo *PrintInfo) (status int) {
|
||||
defer c.Close()
|
||||
//缓冲
|
||||
buf := make([]byte, 1024)
|
||||
data, _ := json.Marshal(printInfo)
|
||||
//写入数据
|
||||
c.Write(data)
|
||||
//服务器端返回的数据写入buf
|
||||
n, _ := c.Read(buf)
|
||||
status = utils.Str2Int(string(buf[:n]))
|
||||
//服务器端回传的信息
|
||||
fmt.Println("server response:", string(buf[:n]))
|
||||
return status
|
||||
}
|
||||
|
||||
//#region 打印机拼装模板
|
||||
|
||||
// QueryPrinterSetting 查询用户设置
|
||||
func QueryPrinterSetting() {
|
||||
|
||||
}
|
||||
|
||||
//#endregion 打印机
|
||||
@@ -1,66 +0,0 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"net"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
textChan chan string
|
||||
)
|
||||
|
||||
func TestTemp() {
|
||||
server := "127.0.0.1:8000"
|
||||
tcpAddr, err := net.ResolveTCPAddr("tcp4", server)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println("tcpaddr", utils.Format4Output(tcpAddr, true))
|
||||
conn, err := net.DialTCP("tcp", nil, tcpAddr)
|
||||
if err != nil {
|
||||
fmt.Println("Dial err:", err)
|
||||
return
|
||||
}
|
||||
textChan = make(chan string, 10)
|
||||
connHandler(conn)
|
||||
}
|
||||
|
||||
func TestTemp2(data string) {
|
||||
textChan <- data
|
||||
}
|
||||
|
||||
func connHandler(c net.Conn) {
|
||||
//接收终端输入
|
||||
//reader := bufio.NewReader(os.Stdin)
|
||||
//缓冲
|
||||
//buf := make([]byte, 1024)
|
||||
fmt.Println("Please input data...")
|
||||
go func() {
|
||||
for {
|
||||
//读取终端输入直到读取到\n
|
||||
//input, err := reader.ReadString('\n')
|
||||
//if err != nil {
|
||||
// fmt.Println("ReadString err:", err)
|
||||
// return
|
||||
//}
|
||||
s := <-textChan
|
||||
//写入数据
|
||||
n, err := c.Write([]byte(s))
|
||||
if err != nil {
|
||||
fmt.Println("Write err:", err, n)
|
||||
return
|
||||
}
|
||||
//服务器端返回的数据写入buf
|
||||
//cnt, err := c.Read(buf)
|
||||
//if err != nil {
|
||||
// fmt.Println("Read err:", err)
|
||||
// return
|
||||
//}
|
||||
//服务器端回传的信息
|
||||
//fmt.Println("server response:", string(buf[0:cnt]))
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -2,27 +2,14 @@ package cms
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/smsmsg"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/event"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/financial"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/dingding"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jsonerr"
|
||||
"git.rosy.net.cn/jx-callback/business/dao"
|
||||
"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/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -61,18 +48,6 @@ type JdUserStruct struct {
|
||||
type UserProvider struct {
|
||||
}
|
||||
|
||||
func (*UserProvider) GetUser(authID, authIDType string) (user auth2.IUser) {
|
||||
globals.SugarLogger.Debugf("GetUser, authID:%s, authIDType:%s", authID, authIDType)
|
||||
fieldName := authTypeFieldMap[authIDType]
|
||||
if fieldName != "" {
|
||||
user2, err := dao.GetUserByID(dao.GetDB(), fieldName, authID)
|
||||
if err == nil {
|
||||
user = user2 // 这样写的原因是golang nil的比较问题
|
||||
}
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
||||
func (*UserProvider) UpdateUserMobile(userID string, mobile string) (err error) {
|
||||
_, err = dao.UpdateEntityLogically(dao.GetDB(), &model.User{}, map[string]interface{}{
|
||||
"Mobile": mobile,
|
||||
@@ -121,91 +96,6 @@ func (*UserProvider) UpdateLastLogin(userID string, lastLoginType, fromIP string
|
||||
return err
|
||||
}
|
||||
|
||||
func init() {
|
||||
auth2.Init(userProvider)
|
||||
}
|
||||
|
||||
func RegisterUserWithMobile(ctx *jxcontext.Context, user *model.User, mobileVerifyCode string, inAuthInfo, manTokenInfo *auth2.AuthInfo) (outAuthInfo *auth2.AuthInfo, err error) {
|
||||
var mobileAuth *auth2.AuthInfo
|
||||
fakeMobile := false
|
||||
createName := ctx.GetRealRemoteIP()
|
||||
authType := auth2.AuthTypeMobile
|
||||
if manTokenInfo != nil && mobileVerifyCode == "" {
|
||||
_, err2 := dao.GetUserByID(dao.GetDB(), "user_id", manTokenInfo.GetID())
|
||||
if err = err2; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if utils.Pointer2String(user.Mobile) == "" {
|
||||
return nil, fmt.Errorf("管理员添加必须指定用户手机号")
|
||||
}
|
||||
mobileVerifyCode = auth2.InternalAuthSecret
|
||||
fakeMobile = true
|
||||
createName = manTokenInfo.GetName()
|
||||
}
|
||||
|
||||
if mobileVerifyCode != "" {
|
||||
if fakeMobile {
|
||||
mobileAuth, err = auth2.LoginInternal(ctx.Context, auth2.AuthTypeMobile, user.GetMobile(), auth2.UserIDMobile, mobileVerifyCode)
|
||||
} else {
|
||||
mobileAuth, err = auth2.Login(ctx.Context, auth2.AuthTypeMobile, user.GetMobile(), auth2.UserIDMobile, mobileVerifyCode)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if mobileAuth != nil && !mobileAuth.IsUserEmpty() {
|
||||
return nil, jsonerr.New(mobileAuth, model.ErrCodeJsonUserAlreadyExist)
|
||||
|
||||
// auth2.RemoveUserInfo(mobileAuth.Token)
|
||||
// if newAuthInfo, err := auth2.BindUser(mobileAuth, user); err == nil {
|
||||
// globals.SugarLogger.Debugf("testRegisterUserWithMobile", utils.Format4Output(mobileAuth, false), utils.Format4Output(newAuthInfo, false))
|
||||
// return nil, jsonerr.New(newAuthInfo, model.ErrCodeJsonUserAlreadyExist)
|
||||
// } else {
|
||||
// return nil, err
|
||||
// }
|
||||
}
|
||||
} else if inAuthInfo != nil {
|
||||
// user.Mobile = nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("短信验证码与其它认证方式至少要指定一种")
|
||||
}
|
||||
|
||||
if inAuthInfo != nil {
|
||||
createName += "," + inAuthInfo.GetAuthID()
|
||||
authType = inAuthInfo.GetAuthType()
|
||||
if user.Avatar == "" {
|
||||
user.Avatar = inAuthInfo.GetAvatar()
|
||||
}
|
||||
}
|
||||
if err = CreateUser(user, utils.LimitUTF8StringLen(createName, 32)); err == nil {
|
||||
userProvider.UpdateLastLogin(user.GetID(), authType, ctx.GetRealRemoteIP())
|
||||
// TryAddStoreBossRole4User(ctx, user)
|
||||
if mobileAuth != nil {
|
||||
if outAuthInfo, err = auth2.BindUser(mobileAuth, user); err == nil && inAuthInfo != nil {
|
||||
err = auth2.AddAuthBind(&outAuthInfo.UserBasic, inAuthInfo)
|
||||
}
|
||||
} else {
|
||||
outAuthInfo, err = auth2.BindUser(inAuthInfo, user)
|
||||
}
|
||||
//给用户添加一条账单记录
|
||||
err = AddUserBill(user)
|
||||
} else if dao.IsDuplicateError(err) {
|
||||
err = auth2.ErrUserID2AlreadyExist
|
||||
}
|
||||
return outAuthInfo, err
|
||||
}
|
||||
|
||||
func AddUserBill(user *model.User) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
userBill := &model.UserBill{
|
||||
BillID: jxutils.GenBillID(),
|
||||
UserID: user.UserID,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(userBill, jxcontext.AdminCtx.GetUserName())
|
||||
return dao.CreateEntity(db, userBill)
|
||||
}
|
||||
|
||||
func GetUserBindAuthInfo(ctx *jxcontext.Context) (authList []*model.AuthBind, err error) {
|
||||
authInfo, err := ctx.GetV2AuthInfo()
|
||||
if err == nil {
|
||||
@@ -214,34 +104,6 @@ func GetUserBindAuthInfo(ctx *jxcontext.Context) (authList []*model.AuthBind, er
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func CreateUser(user *model.User, creatorName string) (err error) {
|
||||
globals.SugarLogger.Debugf("CreateUser user:%s, creatorName:%s", utils.Format4Output(user, true), creatorName)
|
||||
|
||||
if user == nil || user.UserID2 == "" || user.Name == "" {
|
||||
return ErrUserIDAndNameMustGiven
|
||||
}
|
||||
if user.GetMobile() == "" {
|
||||
user.Mobile = nil
|
||||
}
|
||||
if user.GetEmail() == "" {
|
||||
user.Email = nil
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(user, creatorName)
|
||||
user.UserID = utils.GetUUID()
|
||||
user.Status = model.UserStatusNormal
|
||||
//推广码
|
||||
popCode := ""
|
||||
for {
|
||||
popCode = jxutils.GenRandomString(6)
|
||||
user2, _ := dao.GetUserByID(dao.GetDB(), "pop_code", popCode)
|
||||
if user2 == nil {
|
||||
user.PopCode = popCode
|
||||
break
|
||||
}
|
||||
}
|
||||
return dao.CreateEntity(nil, user)
|
||||
}
|
||||
|
||||
func DisableUser(ctx *jxcontext.Context, userID string) (err error) {
|
||||
userName := ctx.GetUserName()
|
||||
if _, err = dao.UpdateEntityLogically(dao.GetDB(), &model.User{}, map[string]interface{}{
|
||||
@@ -253,527 +115,3 @@ func DisableUser(ctx *jxcontext.Context, userID string) (err error) {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func OnDingDingMsg(msg map[string]interface{}) (callbackResponse *dingdingapi.CallbackResponse) {
|
||||
eventType := utils.Interface2String(msg[dingdingapi.KeyEventType])
|
||||
if eventType == dingdingapi.CBTagUserLeaveOrg {
|
||||
var (
|
||||
authBind *model.AuthBind
|
||||
err error
|
||||
)
|
||||
db := dao.GetDB()
|
||||
for _, userID := range msg[dingdingapi.KeyUserID].([]interface{}) {
|
||||
userIDStr := utils.Interface2String(userID)
|
||||
globals.SugarLogger.Debugf("OnDingDingMsg dingding user:%s left company", userIDStr)
|
||||
if authBind, err = dao.GetAuthBind(db, model.AuthBindTypeAuth, dingding.AuthTypeStaff, userIDStr); err == nil { // 直接找到了
|
||||
globals.SugarLogger.Debugf("OnDingDingMsg dingding user:%s, userID:%s left company", userIDStr, authBind.UserID)
|
||||
if err = DisableUser(jxcontext.AdminCtx, authBind.UserID); err != nil {
|
||||
globals.SugarLogger.Errorf("OnDingDingMsg failed with error:%v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return api.DingDingAPI.Err2CallbackResponse(nil)
|
||||
}
|
||||
|
||||
func GetUsers(ctx *jxcontext.Context, keyword string, userID string, pop int, mobile string, fromTime, toTime string, timeType int, cityCodes, consumeTypes []int, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
||||
return dao.GetUsers2(dao.GetDB(), keyword, userID, pop, mobile, utils.Str2Time(fromTime), utils.Str2Time(toTime), timeType, cityCodes, consumeTypes, offset, pageSize)
|
||||
}
|
||||
|
||||
func GetUser(ctx *jxcontext.Context, userID string) (user *model.GetUserResult, err error) {
|
||||
return dao.GetUser(dao.GetDB(), userID)
|
||||
}
|
||||
|
||||
func checkUserType(userID string, userType int8) (err error) {
|
||||
userList, _, err := dao.GetUsers(dao.GetDB(), 0, "", "", []string{userID}, nil, nil, 0, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(userList) == 0 {
|
||||
return fmt.Errorf("找不到用户:%s", userID)
|
||||
}
|
||||
if userList[0].Type&userType == 0 {
|
||||
return fmt.Errorf("用户:%s不能用于当前操作", userID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getAddressInfoFromCoord(db *dao.DaoDB, lng, lat float64) (formattedAddress string, districtCode, cityCode int, err error) {
|
||||
regeoInfo, err := api.AutonaviAPI.GeoCodeRegeoSingle(lng, lat, 0, false, nil, 0, 0)
|
||||
if err == nil {
|
||||
formattedAddress = regeoInfo.FormattedAddress
|
||||
districtCode = int(utils.Str2Int64WithDefault(regeoInfo.AddressComponent.Adcode, 0))
|
||||
if districtCode == 0 {
|
||||
err = fmt.Errorf("坐标lng:%f,lat:%f找不到位置信息", lng, lat)
|
||||
} else if districtInfo, err2 := dao.GetPlaceByCode(db, districtCode); err2 == nil {
|
||||
cityCode = districtInfo.ParentCode
|
||||
}
|
||||
}
|
||||
return formattedAddress, districtCode, cityCode, err
|
||||
}
|
||||
|
||||
func AddMyDeliveryAddress(ctx *jxcontext.Context, address *model.UserDeliveryAddress) (outAddress *dao.UserDeliveryAddressEx, err error) {
|
||||
globals.SugarLogger.Debugf("AddMyDeliveryAddress address:%s", utils.Format4Output(address, true))
|
||||
_, address.UserID = ctx.GetMobileAndUserID()
|
||||
out, err := AddUserDeliveryAddress(ctx, address)
|
||||
list, _, err := dao.QueryUserDeliveryAddress(dao.GetDB(), int64(out.ID), nil, 0, 0, -1)
|
||||
globals.SugarLogger.Debugf("AddMyDeliveryAddress2 address:%s, err:%v", utils.Format4Output(address, true), err)
|
||||
return list[0], err
|
||||
}
|
||||
|
||||
func DeleteUserDeliveryAddress(ctx *jxcontext.Context, userID string, addressID int) (err error) {
|
||||
num, err := dao.DeleteEntityLogically(dao.GetDB(), &model.UserDeliveryAddress{}, nil, ctx.GetUserName(), map[string]interface{}{
|
||||
model.FieldID: addressID,
|
||||
"UserID": userID,
|
||||
})
|
||||
if err == nil {
|
||||
if num == 0 {
|
||||
err = fmt.Errorf("地址ID:%d不存在", addressID)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteMyDeliveryAddress(ctx *jxcontext.Context, addressID int) (err error) {
|
||||
_, userID := ctx.GetMobileAndUserID()
|
||||
return DeleteUserDeliveryAddress(ctx, userID, addressID)
|
||||
}
|
||||
|
||||
func UpdateUserDeliveryAddress(ctx *jxcontext.Context, userID string, addressID int, payload map[string]interface{}) (err error) {
|
||||
if userID == "" {
|
||||
return fmt.Errorf("操作用户配送地址时必须指定UserID")
|
||||
}
|
||||
address := &model.UserDeliveryAddress{
|
||||
UserID: userID,
|
||||
}
|
||||
address.ID = addressID
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetEntity(db, address, model.FieldID, "UserID"); err == nil {
|
||||
var outAddress *model.UserDeliveryAddress
|
||||
valid := dao.StrictMakeMapByStructObject2(payload, address, &outAddress, ctx.GetUserName())
|
||||
delete(valid, "autoAddress")
|
||||
delete(valid, "districtCode")
|
||||
delete(valid, "cityCode")
|
||||
if len(valid) > 0 {
|
||||
if valid["lng"] != nil || valid["lat"] != nil {
|
||||
valid["autoAddress"], valid["districtCode"], valid["cityCode"], err = getAddressInfoFromCoord(db, outAddress.Lng, outAddress.Lat)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if utils.ForceInterface2Int64(valid["isDefault"]) == 1 {
|
||||
if err = dao.ClearUserDeliveryAddressDefault(db, userID, 0); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err = dao.UpdateEntityLogically(db, address, valid, ctx.GetUserName(), nil); err == nil {
|
||||
dao.Commit(db, txDB)
|
||||
} else {
|
||||
dao.Rollback(db, txDB)
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateMyDeliveryAddress(ctx *jxcontext.Context, addressID int, payload map[string]interface{}) (err error) {
|
||||
_, userID := ctx.GetMobileAndUserID()
|
||||
return UpdateUserDeliveryAddress(ctx, userID, addressID, payload)
|
||||
}
|
||||
|
||||
func QueryUserDeliveryAddress(ctx *jxcontext.Context, userIDs []string, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
||||
addressList, totalCount, err := dao.QueryUserDeliveryAddress(dao.GetDB(), 0, userIDs, 0, offset, pageSize)
|
||||
if err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: totalCount,
|
||||
Data: addressList,
|
||||
}
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
func QueryMyDeliveryAddress(ctx *jxcontext.Context, addType int) (addressList []*dao.UserDeliveryAddressEx, err error) {
|
||||
_, userID := ctx.GetMobileAndUserID()
|
||||
addressList, _, err = dao.QueryUserDeliveryAddress(dao.GetDB(), 0, []string{userID}, addType, 0, model.UnlimitedPageSize)
|
||||
return addressList, err
|
||||
}
|
||||
|
||||
func AddUserDeliveryAddress(ctx *jxcontext.Context, address *model.UserDeliveryAddress) (outAddress *model.UserDeliveryAddress, err error) {
|
||||
globals.SugarLogger.Debugf("AddUserDeliveryAddress1 address:%s", utils.Format4Output(address, true))
|
||||
if address.UserID == "" {
|
||||
return nil, fmt.Errorf("操作用户配送地址时必须指定UserID")
|
||||
}
|
||||
db := dao.GetDB()
|
||||
lng := address.Lng
|
||||
lat := address.Lat
|
||||
address.AutoAddress, address.DistrictCode, address.CityCode, err = getAddressInfoFromCoord(db, lng, lat)
|
||||
if err == nil {
|
||||
globals.SugarLogger.Debugf("AddUserDeliveryAddress2 address:%s", utils.Format4Output(address, true))
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
dao.WrapAddIDCULDEntity(address, ctx.GetUserName())
|
||||
if address.IsDefault == 1 {
|
||||
if err = dao.ClearUserDeliveryAddressDefault(db, address.UserID, 0); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err = dao.CreateEntity(db, address); err == nil {
|
||||
dao.Commit(db, txDB)
|
||||
outAddress = address
|
||||
} else {
|
||||
dao.Rollback(db, txDB)
|
||||
}
|
||||
}
|
||||
globals.SugarLogger.Debugf("AddUserDeliveryAddress3 address:%s", utils.Format4Output(address, true))
|
||||
return outAddress, err
|
||||
}
|
||||
|
||||
func SaveUserCart(ctx *jxcontext.Context, userID string, storeID int, cartItems []*model.UserCartItem) (err error) {
|
||||
if userID == "" || storeID == 0 {
|
||||
return fmt.Errorf("用户与门店必须要指定")
|
||||
}
|
||||
for _, v := range cartItems {
|
||||
v.UserID = userID
|
||||
v.StoreID = storeID
|
||||
dao.WrapAddIDCULEntity(v, userID)
|
||||
}
|
||||
db := dao.GetDB()
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
_, err = dao.ExecuteSQL(db, `
|
||||
DELETE t1
|
||||
FROM user_cart_item t1
|
||||
WHERE t1.user_id = ? AND t1.store_id = ?
|
||||
`, userID, storeID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(cartItems) > 0 {
|
||||
err = dao.CreateMultiEntities(db, cartItems)
|
||||
}
|
||||
if err == nil {
|
||||
dao.Commit(db, txDB)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func LoadUserCart(ctx *jxcontext.Context, userID string, storeIDs []int) (cartItems []*model.UserCartItem, err error) {
|
||||
if userID == "" || len(storeIDs) == 0 {
|
||||
return nil, fmt.Errorf("用户与门店必须要指定")
|
||||
}
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
FROM user_cart_item t1
|
||||
WHERE t1.user_id = ? AND t1.store_id IN (` + dao.GenQuestionMarks(len(storeIDs)) + `)
|
||||
ORDER BY t1.sku_id
|
||||
`
|
||||
err = dao.GetRows(dao.GetDB(), &cartItems, sql, userID, storeIDs)
|
||||
return cartItems, err
|
||||
}
|
||||
|
||||
func GetSelfInfo(ctx *jxcontext.Context) (getSelfInfoResult *dao.GetSelfInfoResult, err error) {
|
||||
tokenInfo, err := auth2.GetTokenInfo(ctx.GetToken())
|
||||
if err == nil {
|
||||
if getSelfInfoResult, err = dao.GetUserByIDWithMembers(dao.GetDB(), "user_id", tokenInfo.GetID()); err == nil {
|
||||
if userMembers, err3 := dao.GetUserMember(dao.GetDB(), getSelfInfoResult.User.UserID, 0); err3 == nil {
|
||||
getSelfInfoResult.UserMembers = userMembers
|
||||
} else {
|
||||
err = err3
|
||||
}
|
||||
if price, err := dao.GetUserAllWaitCashPrice(dao.GetDB(), getSelfInfoResult.User.UserID); err == nil {
|
||||
getSelfInfoResult.WaitCashPrice = price
|
||||
}
|
||||
if price, err := dao.GetUserAllWaitRealCashPrice(dao.GetDB(), getSelfInfoResult.User.UserID); err == nil {
|
||||
getSelfInfoResult.WaitRealCashPrice = price
|
||||
}
|
||||
}
|
||||
}
|
||||
return getSelfInfoResult, err
|
||||
}
|
||||
|
||||
func RefreshUserMemberStatus(ctx *jxcontext.Context) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
userMembers, err := dao.GetUserMember(db, "", 0)
|
||||
for _, userMember := range userMembers {
|
||||
if time.Now().Sub(userMember.EndAt) > 0 {
|
||||
userMember.DeletedAt = time.Now()
|
||||
dao.UpdateEntity(db, userMember, "DeletedAt")
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func InvestMember(ctx *jxcontext.Context, memberID int, userID string, isFree bool) (errCode string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
memberCards []*model.MemberCard
|
||||
memberCard *model.MemberCard
|
||||
userIDReal string
|
||||
)
|
||||
if !isFree {
|
||||
userIDReal = ctx.GetUserID()
|
||||
} else {
|
||||
userIDReal = userID
|
||||
}
|
||||
userMembers, err := dao.GetUserMember(db, userIDReal, model.MemberTypeNormal)
|
||||
configList, err := dao.QueryConfigs(db, model.ConfigTypeName[model.ConfigTypeMemberCard], model.ConfigTypeMemberCard, "")
|
||||
userBill, err := dao.GetUserBill(db, userIDReal, "")
|
||||
if len(configList) <= 0 {
|
||||
return "", fmt.Errorf("未找到会员卡配置!")
|
||||
}
|
||||
config := configList[0]
|
||||
err = jxutils.Strings2Objs(config.Value, &memberCards)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
for _, v := range memberCards {
|
||||
if v.ID == memberID {
|
||||
memberCard = v
|
||||
}
|
||||
}
|
||||
if !isFree {
|
||||
//验证微信绑定
|
||||
if err = auth2.CheckWeixinminiAuthBind(userIDReal); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if userBill.AccountBalance < memberCard.Price {
|
||||
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("用户余额不足,请充值!")
|
||||
}
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
//证明已经开了会员了,相当于续费
|
||||
if len(userMembers) > 0 {
|
||||
userMember := userMembers[0]
|
||||
if memberID == model.MemberCardTypeMonth {
|
||||
userMember.EndAt = userMember.EndAt.AddDate(0, 1, 0)
|
||||
} else {
|
||||
userMember.EndAt = userMember.EndAt.AddDate(1, 0, 0)
|
||||
}
|
||||
if _, err = dao.UpdateEntity(db, userMember, "EndAt"); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
userMember2 := &model.UserMember{
|
||||
UserID: userIDReal,
|
||||
MemberType: model.MemberTypeNormal,
|
||||
MemberTypeID: memberID,
|
||||
}
|
||||
if memberID == model.MemberCardTypeMonth {
|
||||
userMember2.EndAt = time.Now().AddDate(0, 1, 0)
|
||||
} else {
|
||||
userMember2.EndAt = time.Now().AddDate(1, 0, 0)
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(userMember2, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(db, userMember2); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return
|
||||
}
|
||||
}
|
||||
if !isFree {
|
||||
//支出明细
|
||||
if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypeMember, memberCard.Price, 0); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return
|
||||
}
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
return errCode, err
|
||||
}
|
||||
|
||||
func UpdateUser(ctx *jxcontext.Context, payload map[string]interface{}) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
userID string
|
||||
)
|
||||
if payload["userID"] != nil {
|
||||
userID = payload["userID"].(string)
|
||||
} else {
|
||||
userID = ctx.GetUserID()
|
||||
}
|
||||
user := &model.User{
|
||||
UserID: userID,
|
||||
}
|
||||
dao.GetEntity(db, user, "UserID")
|
||||
if payload["lng"] != nil && payload["lat"] != nil {
|
||||
if address, districtCode, cityCode, err := getAddressInfoFromCoord(db, utils.MustInterface2Float64(payload["lng"]), utils.MustInterface2Float64(payload["lat"])); err == nil {
|
||||
delete(payload, "lng")
|
||||
delete(payload, "lat")
|
||||
payload["address"] = address
|
||||
payload["districtCode"] = districtCode
|
||||
payload["cityCode"] = cityCode
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
//暂时用这个字段作为更新他的推广人
|
||||
if payload["popCode"] != nil {
|
||||
if user, err := dao.GetUserByID(db, "pop_code", payload["popCode"].(string)); err == nil {
|
||||
if user != nil {
|
||||
payload["popUser"] = user.UserID
|
||||
delete(payload, "popCode")
|
||||
} else {
|
||||
return fmt.Errorf("未查询到此推广人!%v", payload["popCode"])
|
||||
}
|
||||
}
|
||||
}
|
||||
valid := dao.StrictMakeMapByStructObject(payload, user, ctx.GetUserName())
|
||||
if len(valid) > 0 {
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if _, err = dao.UpdateEntityByKV(db, user, valid, nil); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return err
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
}
|
||||
if payload["popUser"] != nil {
|
||||
// InvestMemberAndUpdate := func(user *model.User) (err error) {
|
||||
// if _, err = InvestMember(ctx, 1, user.UserID, true); err == nil {
|
||||
|
||||
// }
|
||||
// user.PopFlag = model.YES
|
||||
// _, err = dao.UpdateEntity(db, user, "PopFlag")
|
||||
// return err
|
||||
// }
|
||||
user2, err2 := dao.GetUserByID(db, "user_id", payload["popUser"].(string))
|
||||
err = err2
|
||||
do := func(user *model.User, flag bool) (err error) {
|
||||
if user.PopCount%4 == 0 && user.PopFlag == model.NO {
|
||||
if _, err = InvestMember(ctx, 1, user.UserID, true); err == nil {
|
||||
//发短信,公众号消息通知
|
||||
smsmsg.SendSMSMsg([]string{*user.Mobile}, globals.SMSSignName, globals.SMSPopSuccessTemplate, nil)
|
||||
// weixinmsg.SendMsgToUser(userID, templateID, data)
|
||||
event.SendSysMessageSimple("您好,您已成功邀请4人加入我们,成功免费获得1个月会员!", user.UserID)
|
||||
}
|
||||
user.PopFlag = model.YES
|
||||
dao.UpdateEntity(db, user, "PopFlag")
|
||||
|
||||
if flag {
|
||||
if users, _, err := dao.GetUsers(db, 0, "", user.UserID, nil, nil, nil, 0, 999); err == nil {
|
||||
for _, v := range users {
|
||||
v.PopedFlag = model.YES
|
||||
dao.UpdateEntity(db, v, "PopedFlag")
|
||||
}
|
||||
}
|
||||
_, err = event.CreateMessageGroup(ctx, user.UserID, "", "", 5, 100)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
if user2 != nil {
|
||||
user2.PopCount++
|
||||
messageGroupsResult, err3 := dao.GetMessageGroups(db, user2.UserID, 0, model.GroupTypeMulit, false, "")
|
||||
err = err3
|
||||
//如果他已经有群了,被邀请人直接进群
|
||||
//如果他没群,在邀请到4个人的时候,自动创一个群,所有被邀请人打上标志
|
||||
if len(messageGroupsResult) > 0 {
|
||||
err = event.AddMessageGroup(ctx, messageGroupsResult[0].GroupID, user.UserID)
|
||||
//邀请过4人直接开通一个月会员
|
||||
do(user2, false)
|
||||
} else {
|
||||
//邀请过4人直接开通一个月会员并创建群组
|
||||
do(user2, true)
|
||||
}
|
||||
dao.UpdateEntity(db, user2, "PopCount")
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func AcceptAddGroup(ctx *jxcontext.Context, flag int) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
userID = ctx.GetUserID()
|
||||
)
|
||||
user, err := dao.GetUserByID(db, "user_id", userID)
|
||||
if user == nil {
|
||||
return fmt.Errorf("获取用户信息失败!")
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if user.PopedFlag == model.NO {
|
||||
return fmt.Errorf("获取用户邀请信息失败")
|
||||
}
|
||||
//同意加入
|
||||
if flag == model.YES {
|
||||
//1、找到这个人的邀请人
|
||||
//2、这个邀请人有群就直接进,没群就加入失败了
|
||||
messageGroupsResult, err := dao.GetMessageGroups(db, user.PopUser, 0, model.GroupTypeMulit, false, "")
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取邀请人群信息失败! %v", err)
|
||||
}
|
||||
if len(messageGroupsResult) > 0 {
|
||||
err = event.AddMessageGroup(ctx, messageGroupsResult[0].GroupID, user.UserID)
|
||||
} else {
|
||||
return fmt.Errorf("获取邀请人群信息失败!")
|
||||
}
|
||||
}
|
||||
//同步同意都清标志
|
||||
user.PopedFlag = model.NO
|
||||
dao.UpdateEntity(db, user, "PopedFlag")
|
||||
return err
|
||||
}
|
||||
|
||||
type GetUserSerachKeywordResult struct {
|
||||
AllSpan []*model.UserSearch `json:"allSpan"`
|
||||
UserSpan []*model.UserSearch `json:"userSpan"`
|
||||
}
|
||||
|
||||
func GetUserSerachKeyword(ctx *jxcontext.Context) (getUserSerachKeywordResult *GetUserSerachKeywordResult, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
userID = ctx.GetUserID()
|
||||
userSearchAll []*model.UserSearch
|
||||
userSearch []*model.UserSearch
|
||||
)
|
||||
getUserSerachKeywordResult = &GetUserSerachKeywordResult{}
|
||||
sql := `
|
||||
SELECT keyword, SUM(count) count FROM user_search WHERE created_at > ? GROUP BY 1 ORDER BY SUM(count) DESC LIMIT 20
|
||||
`
|
||||
sqlParams := []interface{}{time.Now().AddDate(0, -1, 0)}
|
||||
err = dao.GetRows(db, &userSearchAll, sql, sqlParams)
|
||||
getUserSerachKeywordResult.AllSpan = userSearchAll
|
||||
sql2 := `
|
||||
SELECT keyword, SUM(count) count FROM user_search WHERE created_at > ? AND user_id = ? GROUP BY 1 ORDER BY SUM(count) DESC LIMIT 20
|
||||
`
|
||||
sqlParams2 := []interface{}{time.Now().AddDate(0, -1, 0), userID}
|
||||
err = dao.GetRows(db, &userSearch, sql2, sqlParams2)
|
||||
getUserSerachKeywordResult.UserSpan = userSearch
|
||||
return getUserSerachKeywordResult, err
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/autonavi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"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/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/financial"
|
||||
"git.rosy.net.cn/jx-callback/business/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"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/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -24,161 +19,12 @@ var (
|
||||
"UpdateUser": "UpdateUser",
|
||||
}
|
||||
regexpToken = regexp.MustCompile(`,"token":".*"`)
|
||||
wsClient = &WSClient{}
|
||||
//广播频道(通道)
|
||||
broadcast = make(chan *model.ImMessageRecord)
|
||||
)
|
||||
|
||||
const (
|
||||
sysMessageTitle = ""
|
||||
)
|
||||
|
||||
//连接的客户端,吧每个客户端都放进来
|
||||
type WSClient struct {
|
||||
Clients map[int]map[string]*websocket.Conn
|
||||
ClientsHeart map[string]*websocket.Conn
|
||||
s *sync.RWMutex
|
||||
}
|
||||
|
||||
func init() {
|
||||
clients := make(map[int]map[string]*websocket.Conn)
|
||||
clientsHeart := make(map[string]*websocket.Conn)
|
||||
wsClient.Clients = clients
|
||||
wsClient.ClientsHeart = clientsHeart
|
||||
wsClient.s = new(sync.RWMutex)
|
||||
go handleMessages()
|
||||
}
|
||||
|
||||
//广播推送消息
|
||||
func handleMessages() {
|
||||
for {
|
||||
//读取通道中的消息
|
||||
msg := <-broadcast
|
||||
if msg.GroupID == 0 {
|
||||
// globals.SugarLogger.Debugf("heart %v", utils.Format4Output(msg, false))
|
||||
if wsClient.ClientsHeart[msg.UserID] != nil {
|
||||
if err := wsClient.ClientsHeart[msg.UserID].WriteJSON(&model.ImMessageRecord{
|
||||
Key: "pang",
|
||||
}); err != nil {
|
||||
globals.SugarLogger.Debugf("heart client.WriteJSON error: %v", err)
|
||||
wsClient.ClientsHeart[msg.UserID].Close() //关闭
|
||||
delete(wsClient.ClientsHeart, msg.UserID)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("clients len %v", len(wsClient.Clients))
|
||||
//循环map客户端
|
||||
for userID, client := range wsClient.Clients[msg.GroupID] {
|
||||
//把通道中的消息发送给客户端
|
||||
user, err := dao.GetUser(dao.GetDB(), msg.UserID)
|
||||
if err == nil {
|
||||
msg.UserInfo = user
|
||||
}
|
||||
globals.SugarLogger.Debugf("msg %v", utils.Format4Output(msg, false))
|
||||
if msg.CreatedAt == utils.ZeroTimeValue {
|
||||
msg.CreatedAt = time.Now()
|
||||
}
|
||||
err = client.WriteJSON(msg)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("client.WriteJSON error: %v", err)
|
||||
client.Close() //关闭
|
||||
delete(wsClient.Clients[msg.GroupID], userID)
|
||||
// delete(clients, client) //删除map中的客户端
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ImMessage(userID string, ws *websocket.Conn) (err error) {
|
||||
var (
|
||||
clientUser = make(map[string]*websocket.Conn)
|
||||
db = dao.GetDB()
|
||||
)
|
||||
//将当前客户端放入map中
|
||||
messageGroups, _ := dao.GetUserMessageGroups(dao.GetDB(), userID)
|
||||
if len(messageGroups) == 0 {
|
||||
return
|
||||
}
|
||||
wsClient.s.Lock()
|
||||
clientUser[userID] = ws
|
||||
wsClient.ClientsHeart[userID] = ws
|
||||
for _, v := range messageGroups {
|
||||
if len(wsClient.Clients[v.GroupID]) > 0 {
|
||||
wsClient.Clients[v.GroupID][userID] = ws
|
||||
} else {
|
||||
wsClient.Clients[v.GroupID] = clientUser
|
||||
}
|
||||
}
|
||||
wsClient.s.Unlock()
|
||||
globals.SugarLogger.Debugf("userID :%v ,clients :%v", userID, utils.Format4Output(wsClient.Clients, false))
|
||||
|
||||
var s *model.ImMessageRecord
|
||||
for {
|
||||
//接收客户端的消息
|
||||
err := ws.ReadJSON(&s)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("页面可能断开啦 ws.ReadJSON error: %v", err.Error())
|
||||
for k, _ := range wsClient.Clients {
|
||||
delete(wsClient.Clients[k], userID)
|
||||
}
|
||||
delete(wsClient.ClientsHeart, userID)
|
||||
// delete(clients, ws) //删除map中的客户端
|
||||
break //结束循环
|
||||
} else {
|
||||
//接受消息 业务逻辑
|
||||
broadcast <- s
|
||||
if s.GroupID != 0 {
|
||||
if s.GroupID != model.SysGroupID {
|
||||
//发聊天消息时,这个组所有的成员包括创建者都在userIDs里
|
||||
userIDs := []string{}
|
||||
if results, err := dao.GetMessageGroups(db, "", s.GroupID, 0, true, ""); err == nil {
|
||||
for _, v := range results {
|
||||
userIDs = append(userIDs, v.UserID)
|
||||
for _, vv := range v.MessageGroupMembers {
|
||||
userIDs = append(userIDs, vv.UserID)
|
||||
}
|
||||
}
|
||||
}
|
||||
//如果这些人不在这个组的ws池子里就打上未读标记
|
||||
for _, v := range userIDs {
|
||||
if wsClient.ClientsHeart[v] == nil {
|
||||
messageGroupReads, _ := dao.GetMessageGroupRead(db, v, s.GroupID)
|
||||
for _, vv := range messageGroupReads {
|
||||
vv.UnReadCount++
|
||||
dao.UpdateEntity(db, vv, "UnReadCount")
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if wsClient.ClientsHeart[s.ToUserID] == nil {
|
||||
messageGroupReads, _ := dao.GetMessageGroupRead(db, s.ToUserID, s.GroupID)
|
||||
for _, vv := range messageGroupReads {
|
||||
vv.UnReadCount++
|
||||
dao.UpdateEntity(db, vv, "UnReadCount")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
utils.CallFuncAsync(func() {
|
||||
if s.GroupID != 0 {
|
||||
dao.WrapAddIDCULDEntity(s, "")
|
||||
dao.CreateEntity(db, s)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
ws.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
func GetOnlineUserCount() (count int) {
|
||||
wsClient.s.RLock()
|
||||
count = len(wsClient.ClientsHeart)
|
||||
wsClient.s.RUnlock()
|
||||
return count
|
||||
}
|
||||
|
||||
func AddOperateEvent(ctx *jxcontext.Context, accessUUID, jsonData string, errCode, errMsg string, useTime int, apiFunctionSpec string) (err error) {
|
||||
var (
|
||||
apiFunction string
|
||||
@@ -283,506 +129,3 @@ func GetOperateEvents(ctx *jxcontext.Context, name string, apiFunctions []string
|
||||
}
|
||||
return pageInfo, err
|
||||
}
|
||||
|
||||
func CreateMessageGroup(ctx *jxcontext.Context, userID, userID2, groupName string, dividePercentage, quitPrice int) (messageGroupResult *dao.GetMessageGroupsResult, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
groupID int
|
||||
)
|
||||
for {
|
||||
groupID = jxutils.GenRand6()
|
||||
temp := &model.MessageGroup{
|
||||
GroupID: groupID,
|
||||
}
|
||||
dao.GetEntity(db, temp, "GroupID")
|
||||
if temp.UserID == "" {
|
||||
break
|
||||
}
|
||||
}
|
||||
if userID2 != "" {
|
||||
messageGroups, err := dao.GetMessageGroups(db, userID, 0, model.GroupTypeSingle, true, userID2)
|
||||
if len(messageGroups) > 0 && len(messageGroups[0].MessageGroupMembers) > 0 {
|
||||
return messageGroups[0], err
|
||||
}
|
||||
user, err := dao.GetUserByID(db, "user_id", userID2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user == nil {
|
||||
return nil, fmt.Errorf("无法找到要联系的用户!")
|
||||
}
|
||||
messageGroup := &model.MessageGroup{
|
||||
GroupID: groupID,
|
||||
UserID: userID,
|
||||
// Name: user.Name,
|
||||
Type: model.GroupTypeSingle,
|
||||
MaxCount: 2,
|
||||
}
|
||||
messageGroupMember := &model.MessageGroupMember{
|
||||
GroupID: groupID,
|
||||
MemberUserID: userID2,
|
||||
Type: model.GroupMemberTypeNormal,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(messageGroup, ctx.GetUserName())
|
||||
dao.WrapAddIDCULDEntity(messageGroupMember, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, messageGroup)
|
||||
err = dao.CreateEntity(db, messageGroupMember)
|
||||
if err == nil {
|
||||
messageGroupRead := &model.MessageGroupRead{
|
||||
GroupID: groupID,
|
||||
UserID: userID,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(messageGroupRead, ctx.GetUserName())
|
||||
messageGroupRead2 := messageGroupRead
|
||||
messageGroupRead2.UserID = userID2
|
||||
dao.CreateEntity(db, messageGroupRead)
|
||||
if err = dao.CreateEntity(db, messageGroupRead2); err == nil {
|
||||
if messageGroupReads, err := dao.GetMessageGroupRead(db, userID2, model.SysGroupID); len(messageGroupReads) == 0 && err == nil {
|
||||
messageGroupRead := &model.MessageGroupRead{
|
||||
GroupID: model.SysGroupID,
|
||||
UserID: userID2,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(messageGroupRead, ctx.GetUserName())
|
||||
dao.CreateEntity(db, messageGroupRead)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
userMembers, err := dao.GetUserMember(db, userID, model.MemberTypeNormal)
|
||||
messageGroupsResult, err := dao.GetMessageGroups(db, userID, 0, model.GroupTypeMulit, false, "")
|
||||
messageGroupMembers, err := dao.GetMessageGroupMembers(db, 0, model.GroupTypeMulit, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(userMembers) == 0 {
|
||||
return nil, fmt.Errorf("抱歉,只有会员才能创建群聊!")
|
||||
}
|
||||
if len(messageGroupsResult) > 0 {
|
||||
return nil, fmt.Errorf("您已经有群组了,请勿重复创建!群号为:%d", messageGroupsResult[0].GroupID)
|
||||
}
|
||||
if len(messageGroupMembers) > 0 {
|
||||
return nil, fmt.Errorf("您已加入了[%v]群,请先退出后再创建!", messageGroupMembers[0].GroupID)
|
||||
}
|
||||
messageGroup := &model.MessageGroup{
|
||||
GroupID: groupID,
|
||||
UserID: userID,
|
||||
Name: groupName,
|
||||
Type: model.GroupTypeMulit,
|
||||
MaxCount: 2000,
|
||||
DividePercentage: dividePercentage,
|
||||
QuitPrice: quitPrice,
|
||||
}
|
||||
user, err := dao.GetUserByID(db, "user_id", userID)
|
||||
if groupName == "" {
|
||||
messageGroup.Name = user.Name + "的集团"
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(messageGroup, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(db, messageGroup); err == nil {
|
||||
messageGroupRead := &model.MessageGroupRead{
|
||||
GroupID: groupID,
|
||||
UserID: userID,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(messageGroupRead, ctx.GetUserName())
|
||||
dao.CreateEntity(db, messageGroupRead)
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
if messageGroupReads, err := dao.GetMessageGroupRead(db, userID, model.SysGroupID); len(messageGroupReads) == 0 && err == nil {
|
||||
messageGroupRead := &model.MessageGroupRead{
|
||||
GroupID: model.SysGroupID,
|
||||
UserID: userID,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(messageGroupRead, ctx.GetUserName())
|
||||
dao.CreateEntity(db, messageGroupRead)
|
||||
}
|
||||
}
|
||||
return messageGroupResult, err
|
||||
}
|
||||
|
||||
func GetMessageGroupByUser(ctx *jxcontext.Context, userID string) (messageGroupResult []*dao.GetMessageGroupsResult, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
messageGroups, err := dao.GetMessageGroups(db, "", model.SysGroupID, 0, false, "")
|
||||
messageGroups2, err := dao.GetMessageGroups(db, userID, 0, 0, true, "")
|
||||
messageGroups = append(messageGroups, messageGroups2...)
|
||||
messageGroupMembers, err := dao.GetMessageGroupMembers(db, 0, 0, userID)
|
||||
for _, v := range messageGroupMembers {
|
||||
if messageGroupList, err := dao.GetMessageGroups(db, "", v.GroupID, 0, false, ""); err == nil {
|
||||
messageGroups = append(messageGroups, messageGroupList...)
|
||||
}
|
||||
}
|
||||
for _, v := range messageGroups {
|
||||
//是这个人创建的群聊,如果是单聊就返回对方的头像
|
||||
if v.Type == model.GroupTypeSingle {
|
||||
var userID2 string
|
||||
if v.UserID == userID {
|
||||
userID2 = v.MessageGroupMembers[0].MemberUserID
|
||||
} else {
|
||||
userID2 = userID
|
||||
}
|
||||
if user, err := dao.GetUserByID(db, "user_id", userID2); err == nil {
|
||||
v.Avatar = user.Avatar
|
||||
v.Name = user.Name
|
||||
}
|
||||
}
|
||||
var (
|
||||
imMessageRecord *model.ImMessageRecord
|
||||
sql string
|
||||
sqlParams = []interface{}{}
|
||||
)
|
||||
if v.GroupID != model.SysGroupID {
|
||||
//最后一条记录和时间和人
|
||||
sql = `
|
||||
SELECT * FROM im_message_record WHERE group_id = ? ORDER BY created_at DESC LIMIT 1
|
||||
`
|
||||
sqlParams = append(sqlParams, v.GroupID)
|
||||
} else {
|
||||
//最后一条记录和时间和人
|
||||
sql = `
|
||||
SELECT * FROM im_message_record WHERE group_id = ? AND to_user_id = ? ORDER BY created_at DESC LIMIT 1
|
||||
`
|
||||
sqlParams = append(sqlParams, v.GroupID, userID)
|
||||
}
|
||||
if err = dao.GetRow(db, &imMessageRecord, sql, sqlParams); err == nil {
|
||||
v.LastTime = imMessageRecord.CreatedAt
|
||||
v.LastContent = imMessageRecord.Content
|
||||
v.LastMessageType = imMessageRecord.MessageType
|
||||
if user3, err := dao.GetUserByID(db, "user_id", imMessageRecord.UserID); err == nil {
|
||||
v.LastUserName = user3.Name
|
||||
}
|
||||
} else {
|
||||
err = nil
|
||||
}
|
||||
//该用户各组的未读消息数
|
||||
var unReadCount int
|
||||
if messageGroupReads, err := dao.GetMessageGroupRead(db, userID, v.GroupID); err == nil && len(messageGroupReads) > 0 {
|
||||
for _, vv := range messageGroupReads {
|
||||
unReadCount += vv.UnReadCount
|
||||
}
|
||||
}
|
||||
v.UnReadMessageCount = unReadCount
|
||||
}
|
||||
return messageGroups, err
|
||||
}
|
||||
|
||||
func AddMessageGroup(ctx *jxcontext.Context, groupID int, userID string) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
messageGroupMembers, err := dao.GetMessageGroupMembers(db, groupID, 0, userID)
|
||||
messageGroupMembers3, err := dao.GetMessageGroupMembers(db, 0, 0, userID)
|
||||
messageGroupsResult, err := dao.GetMessageGroups(db, userID, groupID, model.GroupTypeMulit, false, "")
|
||||
messageGroupsResult2, err := dao.GetMessageGroups(db, "", groupID, model.GroupTypeMulit, false, "")
|
||||
messageGroupsResult3, err := dao.GetMessageGroups(db, userID, 0, model.GroupTypeMulit, false, "")
|
||||
messageGroupMembers2, err := dao.GetMessageGroupMembers(db, groupID, 0, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(messageGroupMembers) > 0 {
|
||||
return fmt.Errorf("此用户已经在该群组中了!")
|
||||
}
|
||||
if len(messageGroupMembers3) > 0 {
|
||||
return fmt.Errorf("您已经有群组[%v]了,不能申请加入其它群!", messageGroupMembers3[0].GroupID)
|
||||
}
|
||||
if len(messageGroupsResult) > 0 {
|
||||
return fmt.Errorf("请不要加入自己创建的群!")
|
||||
}
|
||||
if len(messageGroupsResult2) > 0 && len(messageGroupMembers2) > 0 {
|
||||
if len(messageGroupMembers2)+1 > messageGroupsResult2[0].MaxCount {
|
||||
return fmt.Errorf("抱歉该群组已经满员了!")
|
||||
}
|
||||
}
|
||||
if len(messageGroupsResult3) > 0 {
|
||||
return fmt.Errorf("您已经拥有[%v]群了,不能再加入其它群!", messageGroupsResult3[0].GroupID)
|
||||
}
|
||||
|
||||
messageGroupMember := &model.MessageGroupMember{
|
||||
GroupID: groupID,
|
||||
MemberUserID: userID,
|
||||
Type: model.GroupMemberTypeNormal,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(messageGroupMember, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(db, messageGroupMember); err == nil {
|
||||
messageGroupRead := &model.MessageGroupRead{
|
||||
GroupID: groupID,
|
||||
UserID: userID,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(messageGroupRead, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(db, messageGroupRead); err == nil {
|
||||
if messageGroupReads, err := dao.GetMessageGroupRead(db, userID, model.SysGroupID); len(messageGroupReads) == 0 && err == nil {
|
||||
messageGroupRead := &model.MessageGroupRead{
|
||||
GroupID: model.SysGroupID,
|
||||
UserID: userID,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(messageGroupRead, ctx.GetUserName())
|
||||
dao.CreateEntity(db, messageGroupRead)
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateMessageGroup(ctx *jxcontext.Context, groupID int, payload map[string]interface{}) (num int64, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
messageGroup = &model.MessageGroup{
|
||||
GroupID: groupID,
|
||||
}
|
||||
)
|
||||
if err = dao.GetEntity(db, messageGroup, "GroupID"); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if messageGroup.UserID != ctx.GetUserID() {
|
||||
return 0, fmt.Errorf("只有群主才能修改群信息!")
|
||||
}
|
||||
valid := dao.StrictMakeMapByStructObject(payload, messageGroup, ctx.GetUserName())
|
||||
if len(valid) > 0 {
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if num, err = dao.UpdateEntityLogically(db, messageGroup, valid, ctx.GetUserName(), nil); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return 0, err
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
func DeleteMessageGroup(ctx *jxcontext.Context, groupID int, userID string, flag bool) (errCode string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
messageGroup = &model.MessageGroup{
|
||||
GroupID: groupID,
|
||||
}
|
||||
)
|
||||
if err = dao.GetEntity(db, messageGroup, "GroupID"); err != nil {
|
||||
return errCode, err
|
||||
}
|
||||
//解散群
|
||||
if flag {
|
||||
if messageGroup.UserID != ctx.GetUserID() {
|
||||
return errCode, fmt.Errorf("只有群主才能解散群!")
|
||||
}
|
||||
messageGroup.DeletedAt = time.Now()
|
||||
messageGroup.LastOperator = ctx.GetUserName()
|
||||
dao.UpdateEntity(db, messageGroup, "DeletedAt", "LastOperator")
|
||||
messageGroupMembers, _ := dao.GetMessageGroupMembers(db, groupID, 0, "")
|
||||
for _, v := range messageGroupMembers {
|
||||
v.DeletedAt = time.Now()
|
||||
v.LastOperator = ctx.GetUserName()
|
||||
dao.UpdateEntity(db, v, "DeletedAt", "LastOperator")
|
||||
}
|
||||
} else {
|
||||
//token中用户与传入user不一致就判定为踢人
|
||||
if ctx.GetUserID() != userID {
|
||||
if messageGroup.UserID != ctx.GetUserID() {
|
||||
messageGroupMembers, err := dao.GetMessageGroupMembers(db, groupID, 0, ctx.GetUserID())
|
||||
if err != nil {
|
||||
return errCode, err
|
||||
}
|
||||
if messageGroupMembers[0].Type == model.GroupMemberTypeNormal {
|
||||
return errCode, fmt.Errorf("只有创建者和管理员才能踢人!")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quitPrice := messageGroup.QuitPrice
|
||||
userBill, err := dao.GetUserBill(db, userID, "")
|
||||
userBillGroupMaster, err := dao.GetUserBill(db, messageGroup.UserID, "")
|
||||
if err != nil {
|
||||
return errCode, err
|
||||
}
|
||||
if userBill.AccountBalance < quitPrice {
|
||||
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("用户余额不足,请充值!")
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
//账户支出
|
||||
if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypeQuitGroup, quitPrice, 0); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return errCode, err
|
||||
}
|
||||
//群主收到退团金额
|
||||
if err = financial.AddIncomeUpdateAccount(txDB, userBillGroupMaster, model.BillTypeQuitGroup, quitPrice, 0); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return errCode, err
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
}
|
||||
messageGroupMembers, err := dao.GetMessageGroupMembers(db, groupID, 0, userID)
|
||||
if err != nil {
|
||||
return errCode, err
|
||||
}
|
||||
messageGroupMembers[0].DeletedAt = time.Now()
|
||||
messageGroupMembers[0].LastOperator = ctx.GetUserName()
|
||||
dao.UpdateEntity(db, messageGroupMembers[0], "DeletedAt", "LastOperator")
|
||||
}
|
||||
return errCode, err
|
||||
}
|
||||
|
||||
func TransferMessageGroupMaster(ctx *jxcontext.Context, groupID int, userID string) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
messageGroup = &model.MessageGroup{
|
||||
GroupID: groupID,
|
||||
}
|
||||
)
|
||||
if err = dao.GetEntity(db, messageGroup, "GroupID"); err != nil {
|
||||
return err
|
||||
}
|
||||
if messageGroup.UserID != ctx.GetUserID() {
|
||||
return fmt.Errorf("只有群主才能转让群主!")
|
||||
}
|
||||
//群主换成选的那个人
|
||||
messageGroup.UserID = userID
|
||||
messageGroup.LastOperator = ctx.GetUserName()
|
||||
//之前那个群成员换成之前的群主
|
||||
messageGroupMembers, err := dao.GetMessageGroupMembers(db, groupID, 0, userID)
|
||||
if err != nil && len(messageGroupMembers) == 0 {
|
||||
return err
|
||||
}
|
||||
messageGroupMember := messageGroupMembers[0]
|
||||
messageGroupMember.MemberUserID = ctx.GetUserID()
|
||||
messageGroupMember.LastOperator = ctx.GetUserName()
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if _, err = dao.UpdateEntity(db, messageGroup, "UserID", "LastOperator"); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return err
|
||||
}
|
||||
if _, err = dao.UpdateEntity(db, messageGroupMember, "MemberUserID", "LastOperator"); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return err
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
return err
|
||||
}
|
||||
|
||||
func SendSysMessageSimple(content, toUserID string) (err error) {
|
||||
return SendSysMessage(jxcontext.AdminCtx, &model.ImMessageRecord{
|
||||
Content: sysMessageTitle + " " + content,
|
||||
ToUserID: toUserID,
|
||||
GroupID: model.SysGroupID,
|
||||
MessageType: 1, // 普通文字消息
|
||||
})
|
||||
}
|
||||
|
||||
func SendSysMessage(ctx *jxcontext.Context, imMessageRecord *model.ImMessageRecord) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
userID = imMessageRecord.ToUserID
|
||||
groupID = imMessageRecord.GroupID
|
||||
)
|
||||
if groupID != model.SysGroupID {
|
||||
return fmt.Errorf("只能给系统组发消息!")
|
||||
}
|
||||
imMessageRecord.CreatedAt = time.Now()
|
||||
imMessageRecord.LastOperator = ctx.GetUserName()
|
||||
imMessageRecord.DeletedAt = utils.DefaultTimeValue
|
||||
imMessageRecord.UpdatedAt = utils.DefaultTimeValue
|
||||
imMessageRecord.Seq = time.Now().Unix()
|
||||
err = dao.CreateEntity(db, imMessageRecord)
|
||||
if userID == "" {
|
||||
//循环map客户端
|
||||
for _, client := range wsClient.Clients[groupID] {
|
||||
globals.SugarLogger.Debugf("msg %v", utils.Format4Output(imMessageRecord, false))
|
||||
err = client.WriteJSON(imMessageRecord)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("client.WriteJSON error: %v", err)
|
||||
client.Close() //关闭
|
||||
// delete(wsClient.Clients[msg.GroupID], userID)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
client := wsClient.Clients[groupID][userID]
|
||||
globals.SugarLogger.Debugf("msg %v", utils.Format4Output(imMessageRecord, false))
|
||||
if client == nil {
|
||||
return
|
||||
}
|
||||
err = client.WriteJSON(imMessageRecord)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("client.WriteJSON error: %v", err)
|
||||
client.Close() //关闭
|
||||
// delete(wsClient.Clients[msg.GroupID], userID)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteMessageRecord(ctx *jxcontext.Context) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
sql := `
|
||||
DELETE FROM im_message_record WHERE created_at < ? AND group_id <> ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
time.Now().AddDate(0, 0, -3), model.SysGroupID,
|
||||
}
|
||||
_, err = dao.ExecuteSQL(db, sql, sqlParams)
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateUserMessageGroupRead(ctx *jxcontext.Context, reads []*model.MessageGroupRead) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
userID = ctx.GetUserID()
|
||||
)
|
||||
for _, v := range reads {
|
||||
if messageReads, err := dao.GetMessageGroupRead(db, userID, v.GroupID); err == nil {
|
||||
if len(messageReads) > 0 {
|
||||
messageReads[0].UnReadCount += v.UnReadCount
|
||||
dao.UpdateEntity(db, messageReads[0], "UnReadCount")
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
type GetUserStatisticsResult struct {
|
||||
RegisterUserCount int `json:"registerUserCount"` //注册数
|
||||
OnlineUserCount int `json:"onlineUserCount"` //在线用户数
|
||||
ConsumeUserCount int `json:"consumeUserCount"` //消费用户数
|
||||
MemberUserCount int `json:"memberUserCount"` //会员用户数
|
||||
}
|
||||
|
||||
func GetUserStatistics(ctx *jxcontext.Context) (getUserStatisticsResult *GetUserStatisticsResult, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
getUserStatisticsResult = &GetUserStatisticsResult{}
|
||||
sql := `
|
||||
SELECT a.member_user_count, b.consume_user_count FROM
|
||||
( SELECT DISTINCT COUNT(a.user_id) member_user_count
|
||||
FROM user a
|
||||
JOIN user_member b ON a.user_id = b.user_id AND b.deleted_at = ? )a,
|
||||
( SELECT DISTINCT COUNT(a.user_id) consume_user_count
|
||||
FROM user a
|
||||
JOIN ` + "`order`" + `b ON a.user_id = b.user_id AND b.status = ?)b
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue, model.OrderStatusFinished,
|
||||
}
|
||||
err = dao.GetRow(db, &getUserStatisticsResult, sql, sqlParams)
|
||||
paged, _ := dao.GetUsers2(db, "", "", 0, "", utils.ZeroTimeValue, utils.ZeroTimeValue, 0, nil, nil, 0, -1)
|
||||
getUserStatisticsResult.RegisterUserCount = paged.TotalCount
|
||||
getUserStatisticsResult.OnlineUserCount = GetOnlineUserCount()
|
||||
return getUserStatisticsResult, err
|
||||
}
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
package financial
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"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/dao"
|
||||
"github.com/astaxie/beego/client/orm"
|
||||
"time"
|
||||
)
|
||||
|
||||
func AddBillIncome(txDB orm.TxOrmer, billID int64, billType, incomePrice, jobID int) (err error) {
|
||||
billIncome := &model.BillIncome{
|
||||
BillID: billID,
|
||||
Type: billType,
|
||||
IncomePrice: incomePrice,
|
||||
JobID: jobID,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(billIncome, jxcontext.AdminCtx.GetUserName())
|
||||
return dao.CreateEntityTx(txDB, billIncome)
|
||||
}
|
||||
|
||||
func AddBillExpend(txDB orm.TxOrmer, billID int64, billType, expendPrice, jobID int) (err error) {
|
||||
billExpend := &model.BillExpend{
|
||||
BillID: billID,
|
||||
Type: billType,
|
||||
ExpendPrice: expendPrice,
|
||||
JobID: jobID,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(billExpend, jxcontext.AdminCtx.GetUserName())
|
||||
return dao.CreateEntityTx(txDB, billExpend)
|
||||
}
|
||||
func AddUserBill(txDB orm.TxOrmer, billID int64, userID string) (err error) {
|
||||
userBillInsert := &model.UserBill{
|
||||
BillID: billID,
|
||||
UserID: userID,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(userBillInsert, jxcontext.AdminCtx.GetUserName())
|
||||
return dao.CreateEntityTx(txDB, userBillInsert)
|
||||
}
|
||||
|
||||
func AddUserBillDb(db *dao.DaoDB, billID int64, userID string) (err error) {
|
||||
userBillInsert := &model.UserBill{
|
||||
BillID: billID,
|
||||
UserID: userID,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(userBillInsert, jxcontext.AdminCtx.GetUserName())
|
||||
return dao.CreateEntity(db, userBillInsert)
|
||||
}
|
||||
|
||||
func GetUserBillDetail(ctx *jxcontext.Context, userID, fromTime, toTime string, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
||||
return dao.GetUserBillDetail(dao.GetDB(), userID, utils.Str2Time(fromTime), utils.Str2Time(toTime), pageSize, offset)
|
||||
}
|
||||
|
||||
func AddExpendUpdateAccount(txDB orm.TxOrmer, userBill *model.UserBill, billType, price, jobID int) (err error) {
|
||||
//1、账户支出增加一条记录
|
||||
err = AddBillExpend(txDB, userBill.BillID, billType, price, jobID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//2、账户表余额减少相应值
|
||||
userBill.AccountBalance -= price
|
||||
_, err = dao.UpdateEntityTx(txDB, userBill, "AccountBalance")
|
||||
return err
|
||||
}
|
||||
|
||||
func AddIncomeUpdateAccount(txDB orm.TxOrmer, userBill *model.UserBill, billType, price, jobID int) (err error) {
|
||||
//2、账户收入增加一条记录
|
||||
err = AddBillIncome(txDB, userBill.BillID, billType, price, jobID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//1、根据任务剩余数量退钱到账户余额中
|
||||
userBill.AccountBalance += price
|
||||
_, err = dao.UpdateEntityTx(txDB, userBill, "AccountBalance")
|
||||
return err
|
||||
}
|
||||
|
||||
func SettleUnionOrders(ctx *jxcontext.Context, vendorIDs []int) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
unionOrderVendorMap map[int][]*model.UnionOrder //key 为平台ID
|
||||
unionOrderMap map[string]map[int][]*model.UnionOrder //key为userID,整个map把每个User的不同平台的订单放一起
|
||||
settleOrders []*model.UnionOrderSettle
|
||||
)
|
||||
unionOrderVendorMap = make(map[int][]*model.UnionOrder)
|
||||
unionOrderMap = make(map[string]map[int][]*model.UnionOrder)
|
||||
unionOrders, err := dao.GetUnionOrders(db, vendorIDs, []int{model.UnionOrderStatusFinish}, utils.ZeroTimeValue, utils.ZeroTimeValue, model.NO)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range unionOrders {
|
||||
if _, ok := unionOrderMap[v.UserID]; ok {
|
||||
if _, ol := unionOrderVendorMap[v.VendorID]; ol {
|
||||
unionOrderMap[v.UserID][v.VendorID] = append(unionOrderMap[v.UserID][v.VendorID], v)
|
||||
} else {
|
||||
unionOrderMap[v.UserID][v.VendorID] = []*model.UnionOrder{v}
|
||||
}
|
||||
} else {
|
||||
unionOrderVendorMap[v.VendorID] = []*model.UnionOrder{v}
|
||||
unionOrderMap[v.UserID] = unionOrderVendorMap
|
||||
}
|
||||
}
|
||||
for userID, v := range unionOrderMap {
|
||||
var (
|
||||
billID int64
|
||||
)
|
||||
userBill, _ := dao.GetUserBill(db, userID, "")
|
||||
if userBill == nil {
|
||||
billID = jxutils.GenBillID()
|
||||
AddUserBillDb(db, billID, userID)
|
||||
} else {
|
||||
billID = userBill.BillID
|
||||
}
|
||||
for vendorID, vv := range v {
|
||||
var (
|
||||
sumPrice, count int
|
||||
)
|
||||
for _, unionOrder := range vv {
|
||||
count++
|
||||
sumPrice += unionOrder.PromotionAmount
|
||||
}
|
||||
unionOrderSettle := &model.UnionOrderSettle{
|
||||
BillID: billID,
|
||||
VendorID: vendorID,
|
||||
Issue: jxutils.GetIssue(),
|
||||
EarningPrice: sumPrice,
|
||||
OrderCount: count,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(unionOrderSettle, ctx.GetUserName())
|
||||
settleOrders = append(settleOrders, unionOrderSettle)
|
||||
//err = dao.CreateEntity(db, unionOrderSettle)
|
||||
}
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
for _, v := range settleOrders {
|
||||
//插入结算表
|
||||
if err = dao.CreateEntityTx(txDB, v); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return err
|
||||
}
|
||||
//更新用户账户
|
||||
userBill, _ := dao.GetUserBill(db, "", utils.Int64ToStr(v.BillID))
|
||||
if err = AddIncomeUpdateAccount(txDB, userBill, model.BillTypeUnionShare, v.EarningPrice, 0); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return err
|
||||
}
|
||||
}
|
||||
//修改订单结算标志
|
||||
for _, v := range unionOrders {
|
||||
v.IsEarning = model.YES
|
||||
v.UpdatedAt = time.Now()
|
||||
if _, err = dao.UpdateEntityTx(txDB, v, "IsEarning", "UpdatedAt"); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return err
|
||||
}
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
return err
|
||||
}
|
||||
@@ -1,362 +0,0 @@
|
||||
package financial
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/md5"
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/astaxie/beego/client/orm"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/tonglianpayapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/wxpayapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
const (
|
||||
sigKey = "sign"
|
||||
sigTypeMd5 = "MD5"
|
||||
sigTypeSha256 = "HMAC-SHA256"
|
||||
)
|
||||
|
||||
var (
|
||||
payMap = map[string]*wxpayapi.API{
|
||||
"weixinapp": api.WxpayAPI,
|
||||
"weixinmini": api.WxpayAPI2,
|
||||
}
|
||||
)
|
||||
|
||||
func (p *PayHandler) CreatePay(txDB orm.TxOrmer) (err error) {
|
||||
switch p.PayType {
|
||||
case model.PayTypeTL:
|
||||
param := &tonglianpayapi.CreateUnitorderOrderParam{
|
||||
Trxamt: int(p.Order.PayPrice),
|
||||
NotifyUrl: globals.TLPayNotifyURL,
|
||||
Reqsn: p.Order.OrderID,
|
||||
PayType: p.VendorPayType,
|
||||
}
|
||||
if p.VendorPayType == tonglianpayapi.PayTypeWxXcx {
|
||||
if authInfo, err := p.Ctx.GetV2AuthInfo(); err == nil && authInfo.GetAuthType() == weixin.AuthTypeWxApp {
|
||||
param.Acct = authInfo.GetAuthID()
|
||||
}
|
||||
}
|
||||
result, err := api.TLpayAPI.CreateUnitorderOrder(param)
|
||||
if err == nil {
|
||||
var result2 tonglianpayapi.PayInfo
|
||||
json.Unmarshal([]byte(result.PayInfo), &result2)
|
||||
p.Order.PrepayID = result2.Package[strings.LastIndex(result2.Package, "=")+1 : len(result2.Package)]
|
||||
p.Order.TransactionID = result.TrxID
|
||||
_, err = dao.UpdateEntityTx(txDB, p.Order, "PrepayID", "TransactionID")
|
||||
}
|
||||
case model.PayTypeWX:
|
||||
param := &wxpayapi.CreateOrderParam{
|
||||
OutTradeNo: p.Order.OrderID,
|
||||
Body: "冲天猴儿App账户充值",
|
||||
NotifyURL: globals.WxpayNotifyURL,
|
||||
SpbillCreateIP: p.Ctx.GetRealRemoteIP(),
|
||||
TradeType: p.VendorPayType,
|
||||
TotalFee: p.Order.PayPrice,
|
||||
TimeStart: wxpayapi.Time2PayTime(time.Now()),
|
||||
// ProfitSharing: wxpayapi.OptYes,
|
||||
}
|
||||
authBinds, err := dao.GetUserBindAuthInfo(dao.GetDB(), p.Ctx.GetUserID(), model.AuthBindTypeAuth, []string{p.Order.Way}, "", "", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(authBinds) == 0 {
|
||||
return fmt.Errorf("未绑定微信认证方式!")
|
||||
}
|
||||
param.OpenID = authBinds[0].AuthID
|
||||
result, err2 := payMap[p.Order.Way].CreateUnifiedOrder(param)
|
||||
if err2 == nil {
|
||||
param2 := make(map[string]interface{})
|
||||
param2["prepayid"] = result.PrepayID
|
||||
param2["noncestr"] = utils.GetUUID()
|
||||
param2["timestamp"] = time.Now().Unix()
|
||||
param2["package"] = "Sign=WXPay"
|
||||
param2["partnerid"] = result.MchID
|
||||
param2["appid"] = result.AppID
|
||||
sign := signParam(sigTypeMd5, param2)
|
||||
wxPay := &WxPayParam{
|
||||
Prepayid: param2["prepayid"].(string),
|
||||
Noncestr: param2["noncestr"].(string),
|
||||
Timestamp: utils.Int64ToStr(utils.MustInterface2Int64(param2["timestamp"])),
|
||||
Package: param2["package"].(string),
|
||||
Partnerid: param2["partnerid"].(string),
|
||||
Appid: param2["appid"].(string),
|
||||
Sign: sign,
|
||||
}
|
||||
p.WxPayParam = wxPay
|
||||
p.Order.PrepayID = result.PrepayID
|
||||
p.Order.Comment = result.CodeURL
|
||||
_, err = dao.UpdateEntityTx(txDB, p.Order, "PrepayID", "Comment")
|
||||
} else {
|
||||
return err2
|
||||
}
|
||||
default:
|
||||
err = fmt.Errorf("支付方式:%d当前不支持", p.PayType)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func signParam(signType string, params map[string]interface{}) (sig string) {
|
||||
var valueList []string
|
||||
for k, v := range params {
|
||||
if k != sigKey {
|
||||
if str := fmt.Sprint(v); str != "" {
|
||||
valueList = append(valueList, fmt.Sprintf("%s=%s", k, str))
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Sort(sort.StringSlice(valueList))
|
||||
valueList = append(valueList, fmt.Sprintf("key=%s", globals.WxpayAppKey))
|
||||
sig = strings.Join(valueList, "&")
|
||||
var binSig []byte
|
||||
if signType == sigTypeSha256 {
|
||||
mac := hmac.New(sha256.New, []byte(globals.WxpayAppKey))
|
||||
mac.Write([]byte(sig))
|
||||
binSig = mac.Sum(nil)
|
||||
} else {
|
||||
binSig2 := md5.Sum([]byte(sig))
|
||||
binSig = binSig2[:]
|
||||
}
|
||||
sig = fmt.Sprintf("%X", binSig)
|
||||
// baseapi.SugarLogger.Debug(sig)
|
||||
return sig
|
||||
}
|
||||
|
||||
func (p *PayHandler) CreateRefund() (err error) {
|
||||
switch p.PayType {
|
||||
case model.PayTypeTL:
|
||||
case model.PayTypeWX:
|
||||
//企业付款(提现)
|
||||
if p.VendorPayType == model.VendorPayTypeCompanyPay {
|
||||
// param := &wxpayapi.TransfersParam{
|
||||
// PartnerTradeNo: p.Order.OrderID,
|
||||
// CheckName: wxpayapi.CheckName,
|
||||
// Desc: "冲天猴儿app提现到账",
|
||||
// SpbillCreateIP: p.Ctx.GetRealRemoteIP(),
|
||||
// }
|
||||
// //1元以下免费,以上收取对应城市手续费
|
||||
// place, err := dao.GetPlaceByCode(dao.GetDB(), p.Order.CityCode)
|
||||
// if err != nil || place == nil {
|
||||
// return fmt.Errorf("未找到该城市!code:%v", p.Order.CityCode)
|
||||
// }
|
||||
// if p.Order.PayPrice < 100 {
|
||||
// param.Amount = p.Order.PayPrice
|
||||
// } else {
|
||||
// param.Amount = p.Order.PayPrice * place.DividePercentage / 100 //手续费
|
||||
// }
|
||||
// if authInfo, err := p.Ctx.GetV2AuthInfo(); err == nil {
|
||||
// param.OpenID = authInfo.GetAuthID()
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("CreateRefund wx param: %v", utils.Format4Output(param, false))
|
||||
// result, err2 := payMap[p.Order.Way].Transfers(param)
|
||||
// if err2 == nil {
|
||||
// p.Order.PayFinishedAt = utils.Str2Time(result.PaymentTime)
|
||||
// p.Order.Comment = result.DeviceInfo
|
||||
// p.Order.OriginalData = utils.Format4Output(result, true)
|
||||
// if result.ReturnMsg == "" {
|
||||
// p.Order.Status = model.OrderStatusFinished
|
||||
// } else {
|
||||
// p.Order.Status = model.OrderStatusCanceled
|
||||
// }
|
||||
// dao.UpdateEntity(dao.GetDB(), p.Order)
|
||||
// if result.ReturnMsg == "" {
|
||||
// err = OnCashFinished(p.Order)
|
||||
// }
|
||||
// } else {
|
||||
// return err2
|
||||
// }
|
||||
err = OnCashFinished(p.Order)
|
||||
} else if p.VendorPayType == model.VendorPayTypeTransferAccount {
|
||||
p.Order.PayFinishedAt = time.Now()
|
||||
p.Order.Comment = "手动转账"
|
||||
p.Order.Status = model.OrderStatusFinished
|
||||
if _, err := dao.UpdateEntity(dao.GetDB(), p.Order); err == nil {
|
||||
err = OnCashFinished(p.Order)
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func OnTLPayCallback(call *tonglianpayapi.CallBackResult) (err error) {
|
||||
globals.SugarLogger.Debugf("OnTLPayCallback msg:%s", utils.Format4Output(call, true))
|
||||
switch call.TrxCode {
|
||||
case tonglianpayapi.MsgTypePay:
|
||||
err = onTLpayFinished(call)
|
||||
case tonglianpayapi.MsgTypeRefund:
|
||||
err = onTLpayRefund(call)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
||||
order := &model.Order{
|
||||
OrderID: call.CusorderID,
|
||||
}
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetEntity(db, order, "OrderID"); err == nil {
|
||||
if order.Status != model.OrderStatusWait4Pay {
|
||||
globals.SugarLogger.Debugf("already pay msg:%s, err:%v", utils.Format4Output(call, true), err)
|
||||
return err
|
||||
}
|
||||
loc, _ := time.LoadLocation("Local")
|
||||
t1, _ := time.ParseInLocation("20060102150405", call.PayTime, loc)
|
||||
order.PayFinishedAt = t1
|
||||
// order.TransactionID = call.ChnlTrxID
|
||||
order.OriginalData = utils.Format4Output(call, true)
|
||||
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
order.Status = model.OrderStatusFinished
|
||||
} else {
|
||||
order.Status = model.OrderStatusCanceled
|
||||
}
|
||||
dao.UpdateEntity(db, order)
|
||||
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
err = OnPayFinished(order)
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("onTLpayFinished msg:%s, err:%v", utils.Format4Output(call, true), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func onTLpayRefund(call *tonglianpayapi.CallBackResult) (err error) {
|
||||
// orderPayRefund := &model.OrderPayRefund{
|
||||
// RefundID: call.CusorderID,
|
||||
// }
|
||||
// db := dao.GetDB()
|
||||
// if err = dao.GetEntity(db, orderPayRefund, "RefundID"); err == nil {
|
||||
// if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
// orderPayRefund.Status = model.RefundStatusYes
|
||||
// } else {
|
||||
// orderPayRefund.Status = model.RefundStatusFailed
|
||||
// }
|
||||
// orderPayRefund.OriginalData = utils.Format4Output(call, true)
|
||||
// dao.UpdateEntity(db, orderPayRefund)
|
||||
// } else if dao.IsNoRowsError(err) {
|
||||
// globals.SugarLogger.Warnf("收到异常的退款事件, call:%s", utils.Format4Output(call, true))
|
||||
// }
|
||||
|
||||
// orderPay := &model.OrderPay{
|
||||
// VendorOrderID: orderPayRefund.VendorOrderID,
|
||||
// VendorID: jxutils.GetPossibleVendorIDFromVendorOrderID(orderPayRefund.VendorOrderID),
|
||||
// PayType: model.PayTypeWX,
|
||||
// Status: model.PayStatusYes,
|
||||
// }
|
||||
// orderPay.DeletedAt = utils.DefaultTimeValue
|
||||
// if err = dao.GetEntity(db, orderPay, "VendorOrderID", "VendorID", "PayType", "Status", "DeletedAt"); err == nil {
|
||||
// orderPay.Status = model.PayStatusRefund
|
||||
// dao.UpdateEntity(db, orderPay)
|
||||
// }
|
||||
return err
|
||||
}
|
||||
|
||||
// func RefundOrderByTL(ctx *jxcontext.Context, orderPay *model.OrderPay, refundID string, refundFee int, refundDesc string) (orderPayRefund *model.OrderPayRefund, err error) {
|
||||
// result, err := api.TLpayAPI.PayRefund(&tonglianpayapi.PayRefundParam{
|
||||
// Trxamt: refundFee,
|
||||
// Reqsn: utils.GetUUID(),
|
||||
// Remark: refundDesc,
|
||||
// OldTrxID: orderPay.TransactionID,
|
||||
// })
|
||||
// if err == nil {
|
||||
// orderPayRefund = &model.OrderPayRefund{
|
||||
// RefundID: refundID,
|
||||
// VendorRefundID: result.TrxID,
|
||||
// VendorOrderID: orderPay.VendorOrderID,
|
||||
// VendorID: orderPay.VendorID,
|
||||
// Status: model.RefundStatusNo,
|
||||
// TransactionID: orderPay.TransactionID,
|
||||
// RefundFee: refundFee,
|
||||
// RefundCreatedAt: time.Now(),
|
||||
// }
|
||||
// dao.WrapAddIDCULDEntity(orderPayRefund, ctx.GetUserName())
|
||||
// db := dao.GetDB()
|
||||
// if result.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
// orderPayRefund.Status = model.RefundStatusYes
|
||||
// } else {
|
||||
// orderPayRefund.Status = model.RefundStatusFailed
|
||||
// }
|
||||
// orderPayRefund.OriginalData = utils.Format4Output(result, true)
|
||||
// dao.CreateEntity(db, orderPayRefund)
|
||||
|
||||
// orderPay.Status = model.PayStatusRefund
|
||||
// dao.UpdateEntity(db, orderPay)
|
||||
// }
|
||||
// return orderPayRefund, err
|
||||
// }
|
||||
|
||||
func OnWxPayCallback(msg *wxpayapi.CallbackMsg) (err error) {
|
||||
globals.SugarLogger.Debugf("OnWxPayCallback msg:%s", utils.Format4Output(msg, true))
|
||||
switch msg.MsgType {
|
||||
case wxpayapi.MsgTypePay:
|
||||
err = onWxpayFinished(msg.Data.(*wxpayapi.PayResultMsg))
|
||||
case wxpayapi.MsgTypeRefund:
|
||||
// err = onWxpayRefund(msg.Data.(*wxpayapi.RefundResultMsg))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func onWxpayFinished(msg *wxpayapi.PayResultMsg) (err error) {
|
||||
order := &model.Order{
|
||||
OrderID: msg.OutTradeNo,
|
||||
}
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetEntity(db, order, "OrderID"); err == nil {
|
||||
order.PayFinishedAt = wxpayapi.PayTime2Time(msg.TimeEnd)
|
||||
order.TransactionID = msg.TransactionID
|
||||
order.OriginalData = utils.Format4Output(msg, true)
|
||||
if msg.ResultCode == wxpayapi.ResponseCodeSuccess {
|
||||
order.Status = model.OrderStatusFinished
|
||||
} else {
|
||||
order.Status = model.OrderStatusCanceled
|
||||
}
|
||||
dao.UpdateEntity(db, order)
|
||||
if msg.ResultCode == wxpayapi.ResponseCodeSuccess {
|
||||
err = OnPayFinished(order)
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("onWxpayFinished msg:%s, err:%v", utils.Format4Output(msg, true), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// func onWxpayRefund(msg *wxpayapi.RefundResultMsg) (err error) {
|
||||
// orderPayRefund := &model.OrderPayRefund{
|
||||
// RefundID: msg.ReqInfoObj.OutRefundNo,
|
||||
// }
|
||||
// db := dao.GetDB()
|
||||
// if err = dao.GetEntity(db, orderPayRefund, "RefundID"); err == nil {
|
||||
// if msg.ResultCode == wxpayapi.ResponseCodeSuccess {
|
||||
// orderPayRefund.Status = model.RefundStatusYes
|
||||
// } else {
|
||||
// orderPayRefund.Status = model.RefundStatusFailed
|
||||
// }
|
||||
// orderPayRefund.OriginalData = utils.Format4Output(msg, true)
|
||||
// dao.UpdateEntity(db, orderPayRefund)
|
||||
// } else if dao.IsNoRowsError(err) {
|
||||
// globals.SugarLogger.Warnf("收到异常的退款事件, msg:%s", utils.Format4Output(msg, true))
|
||||
// }
|
||||
|
||||
// orderPay := &model.OrderPay{
|
||||
// VendorOrderID: orderPayRefund.VendorOrderID,
|
||||
// VendorID: jxutils.GetPossibleVendorIDFromVendorOrderID(orderPayRefund.VendorOrderID),
|
||||
// PayType: model.PayTypeWX,
|
||||
// Status: model.PayStatusYes,
|
||||
// }
|
||||
// orderPay.DeletedAt = utils.DefaultTimeValue
|
||||
// if err = dao.GetEntity(db, orderPay, "VendorOrderID", "VendorID", "PayType", "Status", "DeletedAt"); err == nil {
|
||||
// orderPay.Status = model.PayStatusRefund
|
||||
// dao.UpdateEntity(db, orderPay)
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
@@ -1,106 +0,0 @@
|
||||
package financial
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
"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/dao"
|
||||
)
|
||||
|
||||
type PayHandler struct {
|
||||
PayType int `json:"-"` //支付方式
|
||||
Ctx *jxcontext.Context
|
||||
Order *model.Order
|
||||
VendorPayType string
|
||||
|
||||
WxPayParam *WxPayParam `json:"wxPayParam"`
|
||||
}
|
||||
|
||||
type WxPayParam struct {
|
||||
Prepayid string `json:"prepayid"`
|
||||
Noncestr string `json:"noncestr"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Package string `json:"package"`
|
||||
Partnerid string `json:"partnerid"`
|
||||
Appid string `json:"appid"`
|
||||
Sign string `json:"sign"`
|
||||
}
|
||||
|
||||
type PayHandlerInterface interface {
|
||||
CreatePay() (err error)
|
||||
CreateRefund() (err error)
|
||||
}
|
||||
|
||||
func OnPayFinished(order *model.Order) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
globals.SugarLogger.Debugf("OnPayFinished begin modify account order: %v", utils.Format4Output(order, false))
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
//如果用户没有对应账单信息就给他生成一条
|
||||
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
||||
if userBill == nil {
|
||||
globals.SugarLogger.Debugf("OnPayFinished 未找到该用户的账单 order: %v", utils.Format4Output(order, false))
|
||||
return fmt.Errorf("未找到该用户的账单!%v", order.UserID)
|
||||
}
|
||||
//根据订单类型来操作账户
|
||||
switch order.Type {
|
||||
case model.OrderTypePay:
|
||||
//如果是账户充值(发布任务等)
|
||||
//账户收入
|
||||
if err = AddIncomeUpdateAccount(txDB, userBill, model.BillTypeInvest, order.PayPrice, 0); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
}
|
||||
default:
|
||||
globals.SugarLogger.Debugf("OnPayFinished 暂不支持此订单类型 order: %v", utils.Format4Output(order, false))
|
||||
return fmt.Errorf("暂不支持此订单类型!")
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
globals.SugarLogger.Debugf("OnPayFinished end modify account ...")
|
||||
return err
|
||||
}
|
||||
|
||||
func OnCashFinished(order *model.Order) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
globals.SugarLogger.Debugf("OnCashFinished begin modify account order: %v", utils.Format4Output(order, false))
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
//如果用户没有对应账单信息就给他生成一条
|
||||
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
||||
if userBill == nil {
|
||||
globals.SugarLogger.Debugf("OnCashFinished 未找到该用户的账单 order: %v", utils.Format4Output(order, false))
|
||||
return fmt.Errorf("未找到该用户的账单!%v", order.UserID)
|
||||
}
|
||||
//根据订单类型来操作账户
|
||||
switch order.Type {
|
||||
case model.OrderTypeCash:
|
||||
//如果是账户提现
|
||||
//账户支出
|
||||
if err = AddExpendUpdateAccount(txDB, userBill, model.BillTypeCash, order.PayPrice, 0); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
}
|
||||
default:
|
||||
globals.SugarLogger.Debugf("OnPayFinished 暂不支持此订单类型 order: %v", utils.Format4Output(order, false))
|
||||
return fmt.Errorf("暂不支持此订单类型!")
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
globals.SugarLogger.Debugf("OnCashFinished end modify account ...")
|
||||
return err
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
package initdata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/autonavi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"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/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
func TruncateTable(db *dao.DaoDB, tableName string) (err error) {
|
||||
_, err = dao.ExecuteSQL(db, "TRUNCATE TABLE "+tableName)
|
||||
return err
|
||||
}
|
||||
|
||||
func insertPlace(ctx *jxcontext.Context, db *dao.DaoDB, parent *autonavi.District, placeList []*autonavi.District) (err error) {
|
||||
for _, v := range placeList {
|
||||
if v.Level <= autonavi.DistrictLevelDistrict {
|
||||
place := &model.Place{
|
||||
Code: int(utils.Str2Int64(v.Adcode)),
|
||||
Name: v.Name,
|
||||
Level: int8(v.Level),
|
||||
TelCode: v.CityCode,
|
||||
Enabled: 1,
|
||||
}
|
||||
if parent != nil {
|
||||
place.ParentCode = int(utils.Str2Int64(parent.Adcode))
|
||||
}
|
||||
dao.WrapAddIDCULEntity(place, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(db, place); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = insertPlace(ctx, db, v, v.Districts); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func InitPlace(ctx *jxcontext.Context) (err error) {
|
||||
placeList, err2 := api.AutonaviAPI.GetDistricts(autonavi.DistrictLevelDistrict, "")
|
||||
if err = err2; err != nil {
|
||||
return err
|
||||
}
|
||||
placeList = placeList[0].Districts
|
||||
db := dao.GetDB()
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
if _, err = dao.ExecuteSQL(db, `
|
||||
DELETE t1
|
||||
FROM place t1
|
||||
WHERE code < 9000000;
|
||||
`); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = insertPlace(ctx, db, nil, placeList); err != nil {
|
||||
return err
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
return err
|
||||
}
|
||||
|
||||
func UploadImg4Vendors(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// db := dao.GetDB()
|
||||
// rootTask := tasksch.NewSeqTask("合并SkuName图片至DataResource", ctx,
|
||||
// func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
// switch step {
|
||||
// case 0: // 计算SkuName中缺失的hashCode(注意是DescImg不是Img)
|
||||
// var skuNameList []*model.SkuName
|
||||
// if err = dao.GetRows(db, &skuNameList, `
|
||||
// SELECT t1.*
|
||||
// FROM sku_name t1
|
||||
// WHERE t1.desc_img <> '' AND t1.img_hash_code = ''
|
||||
// `); err == nil && len(skuNameList) > 0 {
|
||||
// calcTask := tasksch.NewParallelTask("UploadImg4Vendors calc hashCode",
|
||||
// tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError).SetParallelCount(5), ctx,
|
||||
// func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
// skuName := batchItemList[0].(*model.SkuName)
|
||||
// _, skuName.ImgHashCode, err = jxutils.DownloadFileByURL(skuName.DescImg)
|
||||
// if err == nil {
|
||||
// dao.UpdateEntity(db, skuName, "ImgHashCode")
|
||||
// }
|
||||
// return retVal, err
|
||||
// }, skuNameList)
|
||||
// tasksch.HandleTask(calcTask, task, false).Run()
|
||||
// _, err = calcTask.GetResult(0)
|
||||
// }
|
||||
// case 1: // 从SkuName添加缺失的图片至DataResource
|
||||
// _, err = dao.ExecuteSQL(db, `
|
||||
// INSERT INTO data_resource(created_at, updated_at, last_operator, hash_code,
|
||||
// resource_type, name, main_url, ebai_url, qiniu_url, use_type)
|
||||
// SELECT t1.created_at, t1.created_at, t1.last_operator, t1.img_hash_code,
|
||||
// CASE
|
||||
// WHEN INSTR(t1.desc_img, ".jpg") > 0 OR INSTR(t1.desc_img, ".jpeg") > 0 THEN
|
||||
// 'image/jpeg'
|
||||
// WHEN INSTR(t1.desc_img, ".png") > 0 OR INSTR(t1.desc_img, ".peg") > 0 THEN
|
||||
// 'image/png'
|
||||
// WHEN INSTR(t1.desc_img, ".gif") THEN
|
||||
// 'image/gif'
|
||||
// ELSE
|
||||
// ''
|
||||
// END resource_type,
|
||||
// CONCAT(t1.name, '_desc'), desc_img main_url, t1.desc_img_ebai ebai_url,
|
||||
// IF(INSTR(t1.desc_img, "image.jxc4.com") > 0, t1.desc_img, '') qiniu_url, 2
|
||||
// FROM sku_name t1
|
||||
// JOIN (
|
||||
// SELECT img_hash_code, MAX(id) id, COUNT(*) ct
|
||||
// FROM sku_name
|
||||
// WHERE img_hash_code <> '' AND desc_img <> ''
|
||||
// GROUP BY 1
|
||||
// ) t3 ON t3.id = t1.id
|
||||
// LEFT JOIN data_resource t2 ON (t2.main_url <> '' AND t2.main_url = t1.desc_img)
|
||||
// WHERE t1.desc_img <> '' AND t1.img_hash_code <> '' AND t2.id IS NULL;
|
||||
// `)
|
||||
// case 2: // 统一SkuName中同hashCode,不同图片地址至同一地址
|
||||
// _, err = dao.ExecuteSQL(db, `
|
||||
// UPDATE sku_name t1
|
||||
// JOIN data_resource t2 ON t2.hash_code = t1.img_hash_code AND t2.main_url <> ''
|
||||
// SET t1.desc_img = t2.main_url
|
||||
// WHERE t1.img_hash_code <> '' AND t1.desc_img <> t2.main_url;
|
||||
// `)
|
||||
// case 3: // 上传DataResource中缺失的平台图片
|
||||
// dataResList, err2 := dao.GetNeedUploadDataResource(db)
|
||||
// if err = err2; err == nil && len(dataResList) > 0 {
|
||||
// uploadTask := tasksch.NewParallelTask("批量上传图片至平台",
|
||||
// tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError).SetParallelCount(2), ctx,
|
||||
// func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
// dataRes := batchItemList[0].(*model.DataResource)
|
||||
// _, err = datares.UploadImage2Vendors(ctx, task, dataRes, nil, false)
|
||||
// return nil, err
|
||||
// }, dataResList)
|
||||
// tasksch.HandleTask(uploadTask, task, true).Run()
|
||||
// _, err = uploadTask.GetResult(0)
|
||||
// }
|
||||
// }
|
||||
// return result, err
|
||||
// }, 4)
|
||||
// tasksch.HandleTask(rootTask, nil, true).Run()
|
||||
// if !isAsync {
|
||||
// if _, err = rootTask.GetResult(0); err == nil {
|
||||
// hint = "1"
|
||||
// }
|
||||
// } else {
|
||||
// hint = rootTask.ID
|
||||
// }
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func getSkuNameKey(prefix, name, comment, specUnit, unit string, specQuality float32) string {
|
||||
return fmt.Sprintf("%s-%s-%f-%s-%s", prefix, name, specQuality, specUnit, unit)
|
||||
}
|
||||
@@ -1,59 +1,15 @@
|
||||
package misc
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/partner/pdd"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/event"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
var (
|
||||
dailyWorkTimeList = []string{
|
||||
"00:00:30",
|
||||
}
|
||||
stationTimeList = []string{
|
||||
"11:35:00",
|
||||
}
|
||||
)
|
||||
|
||||
func Init() {
|
||||
if globals.IsProductEnv() {
|
||||
|
||||
//拼多多订单轮询
|
||||
ScheduleTimerFuncByInterval(func() {
|
||||
pdd.GetUnionOrders()
|
||||
}, 5*time.Second, 5*time.Minute)
|
||||
|
||||
ScheduleTimerFunc("doDailyWork", doDailyWork, dailyWorkTimeList)
|
||||
|
||||
ScheduleTimerFunc("InitStation", func() {
|
||||
//同步油站信息
|
||||
cms.InitStation(jxcontext.AdminCtx)
|
||||
}, stationTimeList)
|
||||
}
|
||||
}
|
||||
|
||||
func doDailyWork() {
|
||||
globals.SugarLogger.Debug("doDailyWork")
|
||||
//刷新任务过期状态
|
||||
cms.RefreshJobStatus(jxcontext.AdminCtx)
|
||||
//刷新任务标签状态
|
||||
cms.RefreshJobSpan(jxcontext.AdminCtx)
|
||||
//刷新用户会员时间
|
||||
cms.RefreshUserMemberStatus(jxcontext.AdminCtx)
|
||||
//删除聊天记录
|
||||
event.DeleteMessageRecord(jxcontext.AdminCtx)
|
||||
//自动确认收货(刷新状态)
|
||||
cms.RefreshDropShippingJob(jxcontext.AdminCtx)
|
||||
//刷新京东快递
|
||||
cms.RefreshJdDelivery(jxcontext.AdminCtx)
|
||||
}
|
||||
|
||||
// 按时间序列循环
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package jds
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdunionapi"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/partner"
|
||||
"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"
|
||||
)
|
||||
|
||||
type UnionHandler struct {
|
||||
}
|
||||
|
||||
var (
|
||||
unionHandler *UnionHandler
|
||||
)
|
||||
|
||||
func init() {
|
||||
partner.UnionHandlerMap[model.VendorIDJDShop] = unionHandler
|
||||
}
|
||||
|
||||
func getAPI() (apiobj *jdunionapi.API) {
|
||||
if configs, err := dao.QueryConfigs(dao.GetDB(), "jdunionCookie", model.ConfigTypeCookie, ""); err == nil {
|
||||
api.JdUnionAPI.SetCookieWithStr(configs[0].Value)
|
||||
}
|
||||
return api.JdUnionAPI
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package jds
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/partner"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
)
|
||||
|
||||
func (s *UnionHandler) ShareUnionLink(ctx *jxcontext.Context, linkType, unionActID int, sID, userID string, resourceType int, goodsID string) (link string, err error) {
|
||||
|
||||
return "jds", err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionActList(ctx *jxcontext.Context, actType int) (actList []*partner.ActivityList, err error) {
|
||||
if result, err2 := getAPI().ListActivitys(); err2 == nil {
|
||||
for _, v := range result {
|
||||
act := &partner.ActivityList{
|
||||
ActID: v.Activityid,
|
||||
ActName: v.Activityname,
|
||||
ActDes: v.Remark,
|
||||
Ratio: "11%",
|
||||
Img: v.Imageurl,
|
||||
}
|
||||
act.DateBegin = utils.Str2Time(v.Activitystartdate)
|
||||
act.DateEnd = utils.Str2Time(v.Activityenddate)
|
||||
actList = append(actList, act)
|
||||
}
|
||||
} else {
|
||||
err = err2
|
||||
}
|
||||
return actList, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) CreateUnionPosition(ctx *jxcontext.Context, userID string) (sID string, err error) {
|
||||
return sID, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionMatterList(ctx *jxcontext.Context, vendorCatID, keyword string, page, pageSize, sortType int, listID string) (list *partner.MatterList, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionMatterDetail(ctx *jxcontext.Context, goodsID string) (result *partner.GoodsDetail, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionMatterListRcmmd(ctx *jxcontext.Context, goodsID string, rcmmdType, offset, pageSize int) (result *partner.MatterList, err error) {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package mt
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtunionapi"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/partner"
|
||||
"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"
|
||||
)
|
||||
|
||||
type UnionHandler struct {
|
||||
}
|
||||
|
||||
var (
|
||||
unionHandler *UnionHandler
|
||||
)
|
||||
|
||||
func init() {
|
||||
partner.UnionHandlerMap[model.VendorIDMTWM] = unionHandler
|
||||
}
|
||||
|
||||
func getAPI() (apiobj *mtunionapi.API) {
|
||||
if configs, err := dao.QueryConfigs(dao.GetDB(), "mtunionCookie", model.ConfigTypeCookie, ""); err == nil {
|
||||
api.MtUnionAPI.SetCookieWithStr(configs[0].Value)
|
||||
}
|
||||
return api.MtUnionAPI
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
package mt
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtunionapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/partner"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"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/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
orderStatusMap = map[int]int{
|
||||
mtunionapi.MtUnionOrderStatusPay: model.UnionOrderStatusPay,
|
||||
mtunionapi.MtUnionOrderStatusFinished: model.UnionOrderStatusFinish,
|
||||
mtunionapi.MtUnionOrderStatusCanceled: model.UnionOrderStatusFail,
|
||||
}
|
||||
)
|
||||
|
||||
func (s *UnionHandler) ShareUnionLink(ctx *jxcontext.Context, linkType, unionActID int, sID, userID string, resourceType int, goodsID string) (link string, err error) {
|
||||
if linkType == partner.LinkTypeWeiXinMini {
|
||||
if qrCode, err := api.MtUnionAPI.MiniCode(unionActID, sID); err == nil {
|
||||
if qrCode != "" {
|
||||
return qrCode, err
|
||||
}
|
||||
}
|
||||
return
|
||||
} else {
|
||||
return api.MtUnionAPI.GenerateLink(unionActID, linkType, sID)
|
||||
}
|
||||
return link, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionActList(ctx *jxcontext.Context, actType int) (actList []*partner.ActivityList, err error) {
|
||||
if result, err2 := getAPI().ActivityList(actType, 20, 0); err2 == nil {
|
||||
for _, v := range result {
|
||||
act := &partner.ActivityList{
|
||||
ActID: v.ID,
|
||||
ActName: v.ActName,
|
||||
ActDes: v.ActDes,
|
||||
Ratio: v.Ratio,
|
||||
ActSrc: v.ActSrc,
|
||||
Img: v.URL,
|
||||
}
|
||||
if v.DateBound != "" {
|
||||
act.DateBegin = utils.Str2Time(v.DateBound[:strings.LastIndex(v.DateBound, "至")-1])
|
||||
act.DateEnd = utils.Str2Time(v.DateBound[strings.LastIndex(v.DateBound, "至")+4:])
|
||||
}
|
||||
actList = append(actList, act)
|
||||
}
|
||||
} else {
|
||||
err = err2
|
||||
}
|
||||
return actList, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) CreateUnionPosition(ctx *jxcontext.Context, userID string) (sID string, err error) {
|
||||
return sID, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionMatterList(ctx *jxcontext.Context, vendorCatID, keyword string, page, pageSize, sortType int, listID string) (list *partner.MatterList, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionMatterDetail(ctx *jxcontext.Context, goodsID string) (result *partner.GoodsDetail, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionMatterListRcmmd(ctx *jxcontext.Context, goodsID string, rcmmdType, offset, pageSize int) (result *partner.MatterList, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func OnCallback(call *mtunionapi.CallBackResult) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
if order, err2 := api.MtUnionAPI.Rtnotify(call.Orderid, call.Type); order != nil && err2 == nil {
|
||||
unionOrders, err3 := dao.GetUnionOrdersByIDs(db, []string{order.Order.Orderid}, model.VendorIDPDD)
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
if err3 != nil {
|
||||
return err3
|
||||
}
|
||||
orderStatus := &model.UnionOrderStatus{
|
||||
VendorOrderID: order.Order.Orderid,
|
||||
VendorID: model.VendorIDMTWM,
|
||||
Status: mtunionOrderStatus2Jx(order.Order.Status),
|
||||
VendorStatus: utils.Int2Str(order.Order.Status),
|
||||
OrderStatusAt: time.Unix(utils.Str2Int64(order.Order.Modtime), 0),
|
||||
}
|
||||
if len(order.Refund) > 0 {
|
||||
orderStatus.Comment = "售后完成"
|
||||
}
|
||||
//change
|
||||
jxutils.CallMsgHandler(func() {
|
||||
if len(unionOrders) > 0 {
|
||||
if unionOrders[0].Status != orderStatus.Status {
|
||||
cms.ChangeUnionOrder(unionOrders[0], orderStatus)
|
||||
}
|
||||
} else {
|
||||
//new
|
||||
unionOrder := &model.UnionOrder{
|
||||
VendorOrderID: order.Order.Orderid,
|
||||
VendorID: model.VendorIDMTWM,
|
||||
Status: mtunionOrderStatus2Jx(order.Order.Status),
|
||||
PID: order.Order.Sid,
|
||||
PayPrice: int(jxutils.StandardPrice2Int(utils.Str2Float64(order.Order.Direct))),
|
||||
//PromotionAmount: int(jxutils.StandardPrice2Int(utils.Str2Float64(order.Coupon[0].Profit))),
|
||||
GoodsName: order.Order.Smstitle,
|
||||
GoodsID: order.Order.Dealid,
|
||||
OrderCreateAt: time.Unix(utils.Str2Int64(order.Order.Paytime), 0),
|
||||
OrderPayAt: time.Unix(utils.Str2Int64(order.Order.Paytime), 0),
|
||||
OrderReceiveAt: time.Unix(utils.Str2Int64(order.Order.Modtime), 0),
|
||||
//OrderSettleAt: time.Unix(utils.Str2Int64(order.Coupon[0].Usetime), 0),
|
||||
}
|
||||
if len(order.Coupon) > 0 {
|
||||
unionOrder.PromotionAmount = int(jxutils.StandardPrice2Int(utils.Str2Float64(order.Coupon[0].Profit)))
|
||||
unionOrder.OrderSettleAt = time.Unix(utils.Str2Int64(order.Coupon[0].Usetime), 0)
|
||||
}
|
||||
cms.NewUnionOrder(unionOrder, orderStatus)
|
||||
}
|
||||
}, jxutils.ComposeUniversalOrderID(order.Order.Orderid, model.VendorIDMTWM))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func mtunionOrderStatus2Jx(status int) (jxstatus int) {
|
||||
return orderStatusMap[status]
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
package partner
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
)
|
||||
|
||||
var (
|
||||
UnionHandlerMap map[int]UnionInterface
|
||||
)
|
||||
|
||||
const (
|
||||
LinkTypeWeiXinMini = 5 //微信小程序二维码
|
||||
LinTypeH5 = 1 //h5链接
|
||||
LinTypeDeepLink = 2 //deeplink(唤起)链接
|
||||
LinTypeInto = 3 //中间页唤起链接
|
||||
LinTypeWx = 4 //微信小程序唤起路径
|
||||
|
||||
ShareTypeOther = 1 //分享给别人
|
||||
ShareTypeOwn = 2 //自己领
|
||||
|
||||
MtUnionJxSID = "000000001"
|
||||
|
||||
//排序参数,正数升序,负数倒序
|
||||
JxSortTypeYJ = 1 //佣金比
|
||||
JxSortTypeXL = 2 //销量
|
||||
JxSortTypeJG = 3 //价格
|
||||
)
|
||||
|
||||
type UnionOrderInfo struct {
|
||||
SID string `json:"sid"`
|
||||
Profit int64 `json:"profit"` //订单实际返佣金额
|
||||
VendorID int `json:"vendorID"`
|
||||
}
|
||||
|
||||
type ActivityList struct {
|
||||
ActID int `json:"actID"`
|
||||
ActName string `json:"actName"`
|
||||
ActDes string `json:"actDes"`
|
||||
Ratio string `json:"ratio"` //返现比?
|
||||
DateBegin time.Time `json:"dateBegin"`
|
||||
DateEnd time.Time `json:"dateEnd"`
|
||||
ActSrc string `json:"actSrc"` //物料?
|
||||
Img string `json:"img"` //活动图
|
||||
}
|
||||
|
||||
type GoodsDetail struct {
|
||||
GoodsList
|
||||
MainImg string `json:"mainImg"`
|
||||
Imgs string `json:"imgs"`
|
||||
StoreImg string `json:"storeImg"` //店铺图片
|
||||
StoreName string `json:"storeName"` //店铺名
|
||||
LgstTxt string `json:"lgstTxt"` //物流分
|
||||
DescTxt string `json:"descTxt"` //描述分
|
||||
ServTxt string `json:"servTxt"` //服务分
|
||||
}
|
||||
|
||||
type GoodsDetail2 struct {
|
||||
MainImg string `json:"mainImg"`
|
||||
Imgs string `json:"imgs"`
|
||||
StoreImg string `json:"storeImg"` //店铺图片
|
||||
StoreName string `json:"storeName"` //店铺名
|
||||
Tpwd string `json:"tpwd"` //淘口令 非苹果ios14以上版本的设备(即其他ios版本、Android系统等),可以用此淘口令正常在复制到手淘打开
|
||||
//针对苹果ios14及以上版本的苹果设备,手淘将按照示例值信息格式读取淘口令(需包含:数字+羊角符+url,
|
||||
//识别规则可能根据ios情况变更)。如需更改淘口令内文案、url等内容,请务必先验证更改后的淘口令在手淘可被识别打开!
|
||||
TpwdIOS14 string `json:"tpwdIOS14"`
|
||||
UrlL string `json:"urlL"` //推广地址长链
|
||||
UrlS string `json:"urlS"` //推广地址短链
|
||||
}
|
||||
|
||||
type GoodsList struct {
|
||||
GoodsID string `json:"goodsID"`
|
||||
GoodsName string `json:"goodsName"`
|
||||
Img string `json:"img"`
|
||||
CouponDiscount int `json:"couponDiscount"` //优惠券
|
||||
CouponRemainQuantity int `json:"couponRemainQuantity"` //优惠券剩余数量
|
||||
MinNormalPrice int `json:"minNormalPrice"` //最小购买价格
|
||||
SalesCount string `json:"salesCount"` //销量
|
||||
PromotionRate int `json:"promotionRate"` //佣金比例,千分比
|
||||
GoodsDetail *GoodsDetail2 `json:"goodsDetail"` //淘宝用
|
||||
}
|
||||
|
||||
type MatterList struct {
|
||||
GoodsList []*GoodsList
|
||||
VendorID int `json:"vendorID"`
|
||||
ListID string `json:"listID"`
|
||||
TotalCount int `json:"totalCount"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
UnionHandlerMap = make(map[int]UnionInterface)
|
||||
}
|
||||
|
||||
type UnionInterface interface {
|
||||
ShareUnionLink(ctx *jxcontext.Context, linkType, unionActID int, sID, userID string, resourceType int, goodsID string) (link string, err error)
|
||||
GetUnionActList(ctx *jxcontext.Context, actType int) (result []*ActivityList, err error)
|
||||
CreateUnionPosition(ctx *jxcontext.Context, userID string) (sID string, err error)
|
||||
GetUnionMatterList(ctx *jxcontext.Context, vendorCatID, keyword string, page, pageSize, sortType int, listID string) (result *MatterList, err error)
|
||||
GetUnionMatterDetail(ctx *jxcontext.Context, goodsID string) (result *GoodsDetail, err error)
|
||||
GetUnionMatterListRcmmd(ctx *jxcontext.Context, goodsID string, rcmmdType, offset, pageSize int) (result *MatterList, err error)
|
||||
}
|
||||
|
||||
func GetHandler(vendorID int) UnionInterface {
|
||||
return UnionHandlerMap[vendorID]
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package pdd
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/pddapi"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/partner"
|
||||
"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"
|
||||
)
|
||||
|
||||
type UnionHandler struct {
|
||||
}
|
||||
|
||||
var (
|
||||
unionHandler *UnionHandler
|
||||
)
|
||||
|
||||
func init() {
|
||||
partner.UnionHandlerMap[model.VendorIDPDD] = unionHandler
|
||||
}
|
||||
|
||||
func getAPI() (apiobj *pddapi.API) {
|
||||
if configs, err := dao.QueryConfigs(dao.GetDB(), "pddCookie", model.ConfigTypeCookie, ""); err == nil {
|
||||
api.PddAPI.SetCookieWithStr(configs[0].Value)
|
||||
}
|
||||
return api.PddAPI
|
||||
}
|
||||
@@ -1,280 +0,0 @@
|
||||
package pdd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/pddapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/partner"
|
||||
"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/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
sortTypeMap = map[int]int{
|
||||
0: 0, //综合排序
|
||||
partner.JxSortTypeYJ: 1, //按佣金比率升序;
|
||||
-partner.JxSortTypeYJ: 2, //按佣金比例降序;
|
||||
partner.JxSortTypeJG: 3, //按价格升序;
|
||||
-partner.JxSortTypeJG: 4, //按价格降序;
|
||||
partner.JxSortTypeXL: 5, //按销量升序;
|
||||
-partner.JxSortTypeXL: 6, //按销量降序;
|
||||
}
|
||||
|
||||
orderStatusMap = map[int]int{
|
||||
pddapi.OrderStatusPay: model.UnionOrderStatusPay,
|
||||
pddapi.OrderStatus1: model.UnionOrderStatusPay,
|
||||
pddapi.OrderStatusTakeOver: model.UnionOrderStatusTakeOver,
|
||||
pddapi.OrderStatusAuditOver: model.UnionOrderStatusAuditOver,
|
||||
pddapi.OrderStatusAuditFail: model.UnionOrderStatusFail,
|
||||
pddapi.OrderStatusEaring: model.UnionOrderStatusFinish,
|
||||
}
|
||||
)
|
||||
|
||||
func (s *UnionHandler) ShareUnionLink(ctx *jxcontext.Context, linkType, unionActID int, sID, userID string, resourceType int, goodsID string) (link string, err error) {
|
||||
//传了goodsID表示是商品分享
|
||||
if goodsID != "" {
|
||||
authBindFlag, err := api.PddAPI.MemberAuthorityQuery(sID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if result, err := api.PddAPI.GoodsPromotionURLGen(sID, goodsID, !authBindFlag); err == nil {
|
||||
switch linkType {
|
||||
case partner.LinTypeH5:
|
||||
return result.MobileURL, err
|
||||
case partner.LinTypeWx:
|
||||
return result.WeAppInfo.PagePath, err
|
||||
default:
|
||||
return link, fmt.Errorf("暂不支持此链接类型!")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if result, err := api.PddAPI.ResourceURLGen(sID, resourceType); err == nil {
|
||||
switch linkType {
|
||||
case partner.LinkTypeWeiXinMini:
|
||||
return "", err
|
||||
case partner.LinTypeH5:
|
||||
return result.SingleURLList.URL, err
|
||||
case partner.LinTypeWx:
|
||||
return result.WeAppInfo.PagePath, err
|
||||
default:
|
||||
return link, fmt.Errorf("暂不支持此链接类型!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return link, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionActList(ctx *jxcontext.Context, actType int) (actList []*partner.ActivityList, err error) {
|
||||
if result, err2 := getAPI().ActivityOperationList(); err2 == nil {
|
||||
for _, v := range result {
|
||||
act := &partner.ActivityList{
|
||||
ActID: v.ID,
|
||||
ActName: v.Name,
|
||||
ActDes: v.Description,
|
||||
Ratio: "未知",
|
||||
ActSrc: v.Fileurl,
|
||||
Img: v.Bannerimage,
|
||||
DateBegin: utils.Str2Time(v.Starttime),
|
||||
DateEnd: utils.Str2Time(v.Endtime),
|
||||
}
|
||||
actList = append(actList, act)
|
||||
}
|
||||
}
|
||||
return actList, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) CreateUnionPosition(ctx *jxcontext.Context, userID string) (sID string, err error) {
|
||||
if sID, err = api.PddAPI.GoodsOPidGenerate(userID); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return sID, err
|
||||
}
|
||||
|
||||
func jxSortType2PddSortType(jxSortType int) (sortType int) {
|
||||
return sortTypeMap[jxSortType]
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionMatterList(ctx *jxcontext.Context, vendorCatID, keyword string, page, pageSize, sortType int, listID string) (list *partner.MatterList, err error) {
|
||||
var (
|
||||
goodsList []*partner.GoodsList
|
||||
)
|
||||
list = &partner.MatterList{}
|
||||
params := &pddapi.GoodsSearchParam{
|
||||
CatID: utils.Str2Int(vendorCatID),
|
||||
Keyword: keyword,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
SortType: jxSortType2PddSortType(sortType),
|
||||
ListID: listID,
|
||||
}
|
||||
//-1表示是拼多多的精选
|
||||
if vendorCatID == "-1" {
|
||||
params.ActivityTags = []int{pddapi.GoodsActTagBYBT, pddapi.GoodsActTagJXBK, pddapi.GoodsActTagMS, pddapi.GoodsActTagPPGY, pddapi.GoodsActTagPPHB, pddapi.GoodsActTagQWBT, pddapi.GoodsActTagTZTJ}
|
||||
}
|
||||
if goods, err2 := api.PddAPI.GoodsSearch(params); err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
list.ListID = goods.ListID
|
||||
list.TotalCount = goods.TotalCount
|
||||
list.VendorID = model.VendorIDPDD
|
||||
for _, v := range goods.GoodsList {
|
||||
good := &partner.GoodsList{
|
||||
GoodsID: v.GoodsSign,
|
||||
GoodsName: v.GoodsName,
|
||||
Img: v.GoodsThumbnailURL,
|
||||
CouponDiscount: v.CouponDiscount,
|
||||
CouponRemainQuantity: v.CouponRemainQuantity,
|
||||
MinNormalPrice: v.MinNormalPrice,
|
||||
SalesCount: v.SalesTip,
|
||||
PromotionRate: v.PromotionRate,
|
||||
}
|
||||
goodsList = append(goodsList, good)
|
||||
}
|
||||
list.GoodsList = goodsList
|
||||
}
|
||||
return list, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionMatterDetail(ctx *jxcontext.Context, goodsID string) (result *partner.GoodsDetail, err error) {
|
||||
result = &partner.GoodsDetail{}
|
||||
if goods, err2 := api.PddAPI.GoodsDetail(goodsID); err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
result.GoodsID = goods.GoodsSign
|
||||
result.GoodsName = goods.GoodsName
|
||||
result.Img = goods.GoodsThumbnailURL
|
||||
result.CouponDiscount = goods.CouponDiscount
|
||||
result.MinNormalPrice = goods.MinNormalPrice
|
||||
result.CouponRemainQuantity = goods.CouponRemainQuantity
|
||||
result.SalesCount = goods.SalesTip
|
||||
result.Imgs = strings.Join(goods.GoodsGalleryUrls, ",")
|
||||
result.MainImg = goods.GoodsImageURL
|
||||
result.StoreImg = goods.MallImgURL
|
||||
result.StoreName = goods.MallName
|
||||
result.LgstTxt = goods.LgstTxt
|
||||
result.DescTxt = goods.DescTxt
|
||||
result.ServTxt = goods.ServTxt
|
||||
result.PromotionRate = goods.PromotionRate
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionMatterListRcmmd(ctx *jxcontext.Context, goodsID string, rcmmdType, offset, pageSize int) (list *partner.MatterList, err error) {
|
||||
var (
|
||||
goodsList []*partner.GoodsList
|
||||
)
|
||||
list = &partner.MatterList{}
|
||||
if goods, err2 := api.PddAPI.GoodsRecommendGet(goodsID, rcmmdType, offset, pageSize); err2 != nil {
|
||||
return nil, err2
|
||||
} else {
|
||||
list.ListID = goods.ListID
|
||||
list.TotalCount = goods.Total
|
||||
list.VendorID = model.VendorIDPDD
|
||||
for _, v := range goods.List {
|
||||
good := &partner.GoodsList{
|
||||
GoodsID: v.GoodsSign,
|
||||
GoodsName: v.GoodsName,
|
||||
Img: v.GoodsThumbnailURL,
|
||||
CouponDiscount: v.CouponDiscount,
|
||||
CouponRemainQuantity: v.CouponRemainQuantity,
|
||||
MinNormalPrice: v.MinNormalPrice,
|
||||
SalesCount: v.SalesTip,
|
||||
PromotionRate: v.PromotionRate,
|
||||
}
|
||||
goodsList = append(goodsList, good)
|
||||
}
|
||||
list.GoodsList = goodsList
|
||||
}
|
||||
return list, err
|
||||
}
|
||||
|
||||
func GetUnionOrders() {
|
||||
var (
|
||||
page = 1
|
||||
pageSize = 50
|
||||
db = dao.GetDB()
|
||||
orderIDs []string
|
||||
unionOrderIDsMap map[string]*model.UnionOrder
|
||||
)
|
||||
orders, err := api.PddAPI.OrderListIncrementGet(time.Now().Add(-time.Minute*5).Unix(), time.Now().Unix(), page, pageSize)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range orders {
|
||||
orderIDs = append(orderIDs, v.OrderSn)
|
||||
}
|
||||
unionOrders, err := dao.GetUnionOrdersByIDs(db, orderIDs, model.VendorIDPDD)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
unionOrderIDsMap = make(map[string]*model.UnionOrder)
|
||||
for _, v := range unionOrders {
|
||||
unionOrderIDsMap[v.VendorOrderID] = v
|
||||
}
|
||||
task := tasksch.NewParallelTask("GetUnionOrders1", tasksch.NewParallelConfig().SetIsContinueWhenError(true), jxcontext.AdminCtx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
order := batchItemList[0].(*pddapi.OrderListIncrementGetResult)
|
||||
detail, err := api.PddAPI.OrderDetailGet(order.OrderSn)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
orderStatus := &model.UnionOrderStatus{
|
||||
VendorOrderID: detail.OrderSn,
|
||||
VendorID: model.VendorIDPDD,
|
||||
Status: pddOrderStatus2Jx(detail.OrderStatus),
|
||||
VendorStatus: utils.Int2Str(detail.OrderStatus),
|
||||
OrderStatusAt: time.Unix(int64(detail.OrderModifyAt), 0),
|
||||
}
|
||||
if detail.ReturnStatus == 1 {
|
||||
orderStatus.Comment = "售后中"
|
||||
} else if detail.ReturnStatus == 2 {
|
||||
orderStatus.Comment = "售后完成"
|
||||
orderStatus.Status = model.UnionOrderStatusFail
|
||||
}
|
||||
//change
|
||||
jxutils.CallMsgHandler(func() {
|
||||
globals.SugarLogger.Debugf("GetUnionOrders pdd, orderstatus: %v", utils.Format4Output(orderStatus, true))
|
||||
if unionOrderIDsMap[order.OrderSn] != nil {
|
||||
globals.SugarLogger.Debugf("GetUnionOrders pdd, unionorders: %v", utils.Format4Output(unionOrderIDsMap[order.OrderSn], true))
|
||||
if unionOrderIDsMap[order.OrderSn].Status != orderStatus.Status {
|
||||
cms.ChangeUnionOrder(unionOrderIDsMap[order.OrderSn], orderStatus)
|
||||
}
|
||||
} else {
|
||||
//new
|
||||
unionOrder := &model.UnionOrder{
|
||||
VendorOrderID: detail.OrderSn,
|
||||
VendorID: model.VendorIDPDD,
|
||||
Status: pddOrderStatus2Jx(detail.OrderStatus),
|
||||
PID: detail.Pid,
|
||||
PayPrice: detail.OrderAmount,
|
||||
PromotionAmount: detail.PromotionAmount,
|
||||
GoodsName: detail.GoodsName,
|
||||
GoodsID: detail.GoodsSign,
|
||||
GoodsImg: detail.GoodsThumbnailURL,
|
||||
OrderCreateAt: time.Unix(int64(order.OrderCreateTime), 0),
|
||||
OrderPayAt: time.Unix(int64(order.OrderPayTime), 0),
|
||||
OrderReceiveAt: time.Unix(int64(order.OrderReceiveTime), 0),
|
||||
OrderSettleAt: time.Unix(int64(order.OrderSettleTime), 0),
|
||||
Comment: order.FailReason,
|
||||
}
|
||||
cms.NewUnionOrder(unionOrder, orderStatus)
|
||||
}
|
||||
}, jxutils.ComposeUniversalOrderID(order.OrderSn, model.VendorIDPDD))
|
||||
return retVal, err
|
||||
}, orders)
|
||||
tasksch.HandleTask(task, nil, false).Run()
|
||||
task.GetID()
|
||||
}
|
||||
|
||||
func pddOrderStatus2Jx(status int) (jxstatus int) {
|
||||
return orderStatusMap[status]
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package taobao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/tbunionapi"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/partner"
|
||||
"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"
|
||||
)
|
||||
|
||||
type UnionHandler struct {
|
||||
}
|
||||
|
||||
var (
|
||||
unionHandler *UnionHandler
|
||||
)
|
||||
|
||||
func init() {
|
||||
partner.UnionHandlerMap[model.VendorIDTB] = unionHandler
|
||||
}
|
||||
|
||||
func getAPI() (apiobj *tbunionapi.API) {
|
||||
if configs, err := dao.QueryConfigs(dao.GetDB(), "tbunionCookie", model.ConfigTypeCookie, ""); err == nil {
|
||||
api.TbUnionAPI.SetCookieWithStr(configs[0].Value)
|
||||
}
|
||||
return api.TbUnionAPI
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
package taobao
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/tbunionapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/partner"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
sortTypeMap = map[int]string{
|
||||
0: "", //综合排序
|
||||
partner.JxSortTypeYJ: "tk_total_commi_asc", //按佣金比率升序;
|
||||
-partner.JxSortTypeYJ: "tk_total_commi_des", //按佣金比例降序;
|
||||
partner.JxSortTypeJG: "price_asc", //按价格升序;
|
||||
-partner.JxSortTypeJG: "price_des", //按价格降序;
|
||||
partner.JxSortTypeXL: "total_sales_asc", //按销量升序;
|
||||
-partner.JxSortTypeXL: "total_sales_des", //按销量降序;
|
||||
}
|
||||
)
|
||||
|
||||
func (s *UnionHandler) ShareUnionLink(ctx *jxcontext.Context, linkType, unionActID int, sID, userID string, resourceType int, goodsID string) (link string, err error) {
|
||||
if result, err2 := api.TbUnionAPI.ActivityInfoGet(userID, utils.Int2Str(unionActID), utils.Str2Int64(sID)); err2 == nil {
|
||||
switch linkType {
|
||||
case partner.LinkTypeWeiXinMini:
|
||||
return result.Data.WxQrcodeURL, err
|
||||
case partner.LinTypeH5:
|
||||
return result.Data.ClickURL, err
|
||||
case partner.LinTypeWx:
|
||||
return result.Data.WxMiniprogramPath, err
|
||||
default:
|
||||
return link, fmt.Errorf("暂不支持此链接类型!")
|
||||
}
|
||||
}
|
||||
return link, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionActList(ctx *jxcontext.Context, actType int) (actList []*partner.ActivityList, err error) {
|
||||
if result, err2 := getAPI().GatewayUnionpub(); err2 == nil {
|
||||
for _, v := range result {
|
||||
act := &partner.ActivityList{
|
||||
ActID: utils.Str2Int(v.Pageid),
|
||||
ActName: v.Pagename,
|
||||
ActDes: v.Eventenname,
|
||||
Ratio: "6%",
|
||||
ActSrc: v.Pageurl,
|
||||
Img: v.Pagepicturl,
|
||||
DateBegin: utils.Str2Time(v.Pagestarttime),
|
||||
DateEnd: utils.Str2Time(v.Pageendtime),
|
||||
}
|
||||
actList = append(actList, act)
|
||||
}
|
||||
}
|
||||
return actList, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) CreateUnionPosition(ctx *jxcontext.Context, userID string) (sID string, err error) {
|
||||
return sID, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionMatterList(ctx *jxcontext.Context, vendorCatID, keyword string, page, pageSize, sortType int, listID string) (list *partner.MatterList, err error) {
|
||||
list = &partner.MatterList{
|
||||
VendorID: model.VendorIDTB,
|
||||
}
|
||||
var goodsList []*partner.GoodsList
|
||||
//传了keyword就是物料搜索
|
||||
//没传就是物料精选。。
|
||||
if keyword != "" {
|
||||
params := &tbunionapi.MaterialOptionalParam{
|
||||
Q: keyword,
|
||||
AdzoneID: tbunionapi.JxAdzoneID,
|
||||
PageNo: page,
|
||||
PageSize: pageSize,
|
||||
}
|
||||
if sortType != 0 {
|
||||
params.Sort = jxSortType2TbunionSortType(sortType)
|
||||
}
|
||||
if materResults, err := api.TbUnionAPI.MaterialOptional(params); err == nil {
|
||||
list.TotalCount = materResults.TotalResults
|
||||
for _, v := range materResults.ResultList {
|
||||
good := &partner.GoodsList{
|
||||
GoodsID: utils.Int64ToStr(v.ItemID),
|
||||
GoodsName: v.Title,
|
||||
Img: v.PictURL,
|
||||
CouponDiscount: utils.Str2Int(v.CouponAmount),
|
||||
CouponRemainQuantity: v.CouponRemainCount,
|
||||
MinNormalPrice: utils.Str2Int(v.ReservePrice),
|
||||
SalesCount: utils.Int2Str(v.Volume),
|
||||
PromotionRate: utils.Str2Int(v.CommissionRate),
|
||||
}
|
||||
good.GoodsDetail.MainImg = v.WhiteImage
|
||||
good.GoodsDetail.StoreName = v.ShopTitle
|
||||
good.GoodsDetail.Imgs = strings.Join(v.SmallImages, ",")
|
||||
good.GoodsDetail.UrlL = v.CouponShareURL
|
||||
if urlS, err2 := api.TbUnionAPI.SpreadGet(v.CouponShareURL); err2 == nil {
|
||||
good.GoodsDetail.UrlS = urlS
|
||||
}
|
||||
if tpwdCreateResult, err3 := api.TbUnionAPI.TpwdCreate(good.GoodsDetail.UrlL); err3 == nil {
|
||||
good.GoodsDetail.Tpwd = tpwdCreateResult.PasswordSimple
|
||||
good.GoodsDetail.TpwdIOS14 = tpwdCreateResult.Model
|
||||
}
|
||||
goodsList = append(goodsList, good)
|
||||
}
|
||||
list.GoodsList = goodsList
|
||||
}
|
||||
} else {
|
||||
if materResults, err := api.TbUnionAPI.OptimusMaterial(0, utils.Str2Int(vendorCatID), tbunionapi.JxAdzoneID, page, pageSize); err == nil {
|
||||
for _, v := range materResults {
|
||||
good := &partner.GoodsList{
|
||||
GoodsID: utils.Int64ToStr(v.ItemID),
|
||||
GoodsName: v.Title,
|
||||
Img: v.PictURL,
|
||||
CouponDiscount: v.CouponAmount,
|
||||
CouponRemainQuantity: v.CouponRemainCount,
|
||||
MinNormalPrice: utils.Str2Int(v.ReservePrice),
|
||||
SalesCount: utils.Int2Str(v.Volume),
|
||||
PromotionRate: utils.Str2Int(v.CommissionRate),
|
||||
}
|
||||
goodsDetail := &partner.GoodsDetail2{
|
||||
MainImg: v.WhiteImage,
|
||||
StoreName: v.ShopTitle,
|
||||
Imgs: strings.Join(v.SmallImages, ","),
|
||||
UrlL: v.CouponShareURL,
|
||||
}
|
||||
if urlS, err2 := api.TbUnionAPI.SpreadGet("https:" + v.CouponShareURL); err2 == nil {
|
||||
goodsDetail.UrlS = urlS
|
||||
}
|
||||
if tpwdCreateResult, err3 := api.TbUnionAPI.TpwdCreate("https:" + goodsDetail.UrlL); err3 == nil {
|
||||
goodsDetail.Tpwd = tpwdCreateResult.PasswordSimple
|
||||
goodsDetail.TpwdIOS14 = tpwdCreateResult.Model
|
||||
}
|
||||
good.GoodsDetail = goodsDetail
|
||||
goodsList = append(goodsList, good)
|
||||
}
|
||||
list.GoodsList = goodsList
|
||||
}
|
||||
}
|
||||
return list, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionMatterDetail(ctx *jxcontext.Context, goodsID string) (result *partner.GoodsDetail, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (s *UnionHandler) GetUnionMatterListRcmmd(ctx *jxcontext.Context, goodsID string, rcmmdType, offset, pageSize int) (list *partner.MatterList, err error) {
|
||||
list = &partner.MatterList{
|
||||
VendorID: model.VendorIDTB,
|
||||
}
|
||||
var goodsList []*partner.GoodsList
|
||||
if materResults, err := api.TbUnionAPI.OptimusMaterial(utils.Str2Int(goodsID), 13256, tbunionapi.JxAdzoneID, offset, pageSize); err == nil {
|
||||
for _, v := range materResults {
|
||||
good := &partner.GoodsList{
|
||||
GoodsID: utils.Int64ToStr(v.ItemID),
|
||||
GoodsName: v.Title,
|
||||
Img: v.PictURL,
|
||||
CouponDiscount: v.CouponAmount,
|
||||
CouponRemainQuantity: v.CouponRemainCount,
|
||||
MinNormalPrice: utils.Str2Int(v.ReservePrice),
|
||||
SalesCount: utils.Int2Str(v.Volume),
|
||||
PromotionRate: utils.Str2Int(v.CommissionRate),
|
||||
}
|
||||
goodsDetail := &partner.GoodsDetail2{
|
||||
MainImg: v.WhiteImage,
|
||||
StoreName: v.ShopTitle,
|
||||
Imgs: strings.Join(v.SmallImages, ","),
|
||||
UrlL: v.CouponShareURL,
|
||||
}
|
||||
if urlS, err2 := api.TbUnionAPI.SpreadGet("https:" + v.CouponShareURL); err2 == nil {
|
||||
goodsDetail.UrlS = urlS
|
||||
}
|
||||
if tpwdCreateResult, err3 := api.TbUnionAPI.TpwdCreate("https:" + goodsDetail.UrlL); err3 == nil {
|
||||
goodsDetail.Tpwd = tpwdCreateResult.PasswordSimple
|
||||
goodsDetail.TpwdIOS14 = tpwdCreateResult.Model
|
||||
}
|
||||
good.GoodsDetail = goodsDetail
|
||||
goodsList = append(goodsList, good)
|
||||
}
|
||||
list.GoodsList = goodsList
|
||||
}
|
||||
return list, err
|
||||
}
|
||||
|
||||
func jxSortType2TbunionSortType(sort int) (tbsort string) {
|
||||
return sortTypeMap[sort]
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/dao"
|
||||
"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/legacymodel"
|
||||
)
|
||||
|
||||
|
||||
@@ -9,14 +9,12 @@ import (
|
||||
"image/png"
|
||||
"net/http"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/dao"
|
||||
"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/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"github.com/qiniu/api.v7/storage"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -50,23 +48,24 @@ func Binary2Image(binaryData []byte, mimeType string) (img image.Image, outMimeT
|
||||
}
|
||||
|
||||
func GetQiniuUploadToken(ctx *jxcontext.Context, suffix, hashCode string) (upTokenInfo *UploadResTokenInfo, err error) {
|
||||
imgURL := ""
|
||||
if hashCode != "" {
|
||||
imgURL, _ = GetDataResource(ctx, hashCode)
|
||||
}
|
||||
|
||||
putPolicy := storage.PutPolicy{
|
||||
Scope: globals.QiniuBucket,
|
||||
Expires: qiniuTokenExpires,
|
||||
}
|
||||
upTokenInfo = &UploadResTokenInfo{
|
||||
Token: putPolicy.UploadToken(api.QiniuAPI),
|
||||
Expires: putPolicy.Expires,
|
||||
FileName: jxutils.GenPicFileName(suffix),
|
||||
Hit: imgURL != "",
|
||||
Img: imgURL,
|
||||
}
|
||||
return upTokenInfo, err
|
||||
//imgURL := ""
|
||||
//if hashCode != "" {
|
||||
// imgURL, _ = GetDataResource(ctx, hashCode)
|
||||
//}
|
||||
//
|
||||
//putPolicy := storage.PutPolicy{
|
||||
// Scope: globals.QiniuBucket,
|
||||
// Expires: qiniuTokenExpires,
|
||||
//}
|
||||
//upTokenInfo = &UploadResTokenInfo{
|
||||
// Token: putPolicy.UploadToken(api.QiniuAPI),
|
||||
// Expires: putPolicy.Expires,
|
||||
// FileName: jxutils.GenPicFileName(suffix),
|
||||
// Hit: imgURL != "",
|
||||
// Img: imgURL,
|
||||
//}
|
||||
//return upTokenInfo, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 此函数要求resBinary不能空,mimeType与hashCode必须是正确的
|
||||
@@ -108,10 +107,10 @@ func RegisterDataResource(ctx *jxcontext.Context, name, resourceURL, mimeType, h
|
||||
return dataRes, err
|
||||
}
|
||||
if imgType > 0 {
|
||||
if globals.EnableStoreWrite {
|
||||
// 忽略上传错误
|
||||
UploadImage2Vendors(ctx, nil, dataRes, resBinary, isAsyncUpload2Vendor)
|
||||
}
|
||||
//if globals.EnableStoreWrite {
|
||||
// 忽略上传错误
|
||||
UploadImage2Vendors(ctx, nil, dataRes, resBinary, isAsyncUpload2Vendor)
|
||||
//}
|
||||
}
|
||||
return dataRes, err
|
||||
}
|
||||
|
||||
@@ -7,17 +7,11 @@ import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals/api2"
|
||||
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/ebai"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm"
|
||||
)
|
||||
|
||||
func init() {
|
||||
testinit.Init()
|
||||
api2.Init()
|
||||
}
|
||||
|
||||
func TestGetQiniuUploadToken(t *testing.T) {
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package ddmsg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/dingding"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
func SendDDUserMessage(msgType, ddUserID, title, content string) (err error) {
|
||||
globals.SugarLogger.Debugf("SendDDUserMessage ddUserID:%s, title:%s", ddUserID, title)
|
||||
if globals.IsProductEnv() {
|
||||
if msgType == dingdingapi.MsgTyeText {
|
||||
err = api.DingDingAPI.CorpAsyncSendSimple(ddUserID, content)
|
||||
} else if msgType == dingdingapi.MsgTypeMarkdown {
|
||||
err = api.DingDingAPI.CorpAsyncSendMarkdown([]string{ddUserID}, nil, false, title, content)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func SendUserMessage(msgType, userID, title, content string) (err error) {
|
||||
globals.SugarLogger.Debugf("SendUserMessage userID:%s, title:%s", userID, title)
|
||||
authList, err := auth2.GetUserBindAuthInfo(userID)
|
||||
findOneMethod := false
|
||||
if err == nil {
|
||||
for _, auth := range authList {
|
||||
if auth.Type == dingding.AuthTypeStaff /*|| auth.Type == weixin.AuthTypeMP*/ {
|
||||
findOneMethod = true
|
||||
if len(content) > dingdingapi.MaxWorkContentLen {
|
||||
content = content[:dingdingapi.MaxWorkContentLen-4] + "..."
|
||||
}
|
||||
err = SendDDUserMessage(msgType, auth.AuthID, title, content)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if !findOneMethod {
|
||||
err = fmt.Errorf("用户[%s]找不到至少一个有效的通讯方式", userID)
|
||||
}
|
||||
if err != nil {
|
||||
globals.SugarLogger.Infof("SendUserMessage userID:%s, title:%s, content:%s failed with error:%v", userID, title, content, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func SendUsersMessage(msgType string, userIDs []string, title, content string) (err error) {
|
||||
errList := errlist.New()
|
||||
for _, userID := range userIDs {
|
||||
errList.AddErr(SendUserMessage(msgType, userID, title, content))
|
||||
}
|
||||
err = errList.GetErrListAsOne()
|
||||
return err
|
||||
}
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals/refutil"
|
||||
)
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
@@ -74,9 +73,10 @@ func New(notUsed interface{}, token string, w http.ResponseWriter, r *http.Reque
|
||||
// }
|
||||
}
|
||||
if err == model.ErrTokenIsInvalid {
|
||||
if !globals.IsProductEnv() {
|
||||
err = nil
|
||||
} else if token == RsmDefultToken {
|
||||
//if !globals.IsProductEnv() {
|
||||
// err = nil
|
||||
//} else
|
||||
if token == RsmDefultToken {
|
||||
err = nil
|
||||
} else {
|
||||
errCode = model.ErrCodeTokenIsInvalid
|
||||
@@ -162,14 +162,3 @@ func (ctx *Context) GetUserID() (userID string) {
|
||||
}
|
||||
return userID
|
||||
}
|
||||
|
||||
func (ctx *Context) GetFullUser() (user *model.User) {
|
||||
token := ctx.GetToken()
|
||||
authInfo, err2 := auth2.GetTokenInfo(token)
|
||||
if err2 == nil {
|
||||
if authInfo.TokenType == auth2.TokenTypeNormal {
|
||||
user, _ = dao.GetUserByID(dao.GetDB(), "user_id", authInfo.GetID())
|
||||
}
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package jxutils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/aes"
|
||||
"crypto/md5"
|
||||
"encoding/base64"
|
||||
@@ -14,15 +12,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/autonavi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/baseapi/utils/routinepool"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"github.com/qiniu/api.v7/storage"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -42,6 +34,14 @@ var (
|
||||
"image-star.elemecdn.com",
|
||||
},
|
||||
}
|
||||
|
||||
letterBytes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
flowUnitMap = map[string]string{
|
||||
"KB": "KB",
|
||||
"MB": "MB",
|
||||
"GB": "GB",
|
||||
}
|
||||
)
|
||||
|
||||
const fileExt = ".xlsx"
|
||||
@@ -57,69 +57,12 @@ func init() {
|
||||
orderNoBeginTimestamp = utils.Str2Time("2010-01-01 00:00:00").Unix()
|
||||
}
|
||||
|
||||
func GetSaleStoreIDFromAfsOrder(order *model.AfsOrder) (retVal int) {
|
||||
if order.JxStoreID > 0 {
|
||||
return order.JxStoreID
|
||||
func RandStringBytes(n int) string {
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
b[i] = letterBytes[rand.Intn(len(letterBytes))]
|
||||
}
|
||||
return order.StoreID
|
||||
}
|
||||
|
||||
func GetSkuIDFromOrderSkuFinancial(sku *model.OrderSkuFinancial) (skuID int) {
|
||||
if sku.JxSkuID > 0 {
|
||||
return sku.JxSkuID
|
||||
}
|
||||
return sku.SkuID
|
||||
}
|
||||
|
||||
func SplitUniversalOrderID(universalOrderID string) (orderID string, vendorID int) {
|
||||
index := strings.Index(universalOrderID, "|")
|
||||
if index != -1 {
|
||||
orderID = universalOrderID[:index]
|
||||
vendorID = int(utils.Str2Int64(universalOrderID[index+1:]))
|
||||
} else {
|
||||
if vendorID = GetPossibleVendorIDFromVendorOrderID(universalOrderID); vendorID == model.VendorIDUnknown {
|
||||
// globals.SugarLogger.Errorf("unkown order type:%v", universalOrderID)
|
||||
panic(fmt.Sprintf("unkown order type, orderID:%s", universalOrderID))
|
||||
}
|
||||
orderID = universalOrderID
|
||||
}
|
||||
return orderID, vendorID
|
||||
}
|
||||
|
||||
func GetPossibleVendorIDFromVendorOrderID(vendorOrderID string) (vendorID int) {
|
||||
vendorID = model.VendorIDUnknown
|
||||
if vendorOrderIDInt64 := utils.Str2Int64WithDefault(vendorOrderID, 0); vendorOrderIDInt64 > 0 {
|
||||
orderIDLen := len(vendorOrderID)
|
||||
// 5287873015048 13 wsc
|
||||
// 15380342248732 14 old ebai order
|
||||
// 800402581000221 15,16 jd order
|
||||
// 33437032333978492 17 mtwm order
|
||||
// 3022716176275221584 19 elm order, new ebai order
|
||||
|
||||
// 京东到家从2020年开始订单号的长度都会在现有基础上加一位,订单号的前两位取的是当年的最后两位数(如:2020取的20),以适应业务的发展。
|
||||
// 改造点:
|
||||
// 1、订单号位数变化,由原有15位数增加1位数调整为16位数,对接商家需检查是否有对订单号位数做长度校验。
|
||||
// 2、第一位数字发生变化,由原来9开头调整为当年年份后两位数如:2020年订单开头为20;
|
||||
if orderIDLen == len("925265130002541") || orderIDLen == len("1925265130002541") {
|
||||
vendorID = model.VendorIDJD
|
||||
} else if orderIDLen == len("3022716176275221584") {
|
||||
// vendorID = model.VendorIDELM
|
||||
vendorID = model.VendorIDEBAI // 饿百零售开放平台订单接口中订单ID“order_id”字段长度将调整为19位,和饿了么订单ID“eleme_order_id”字段格式保持一致。
|
||||
} else if orderIDLen == len("15380342248732") {
|
||||
if vendorOrderID[:2] == "88" {
|
||||
vendorID = model.VendorIDJX
|
||||
} else {
|
||||
vendorID = model.VendorIDEBAI
|
||||
}
|
||||
} else if orderIDLen == len("33437032333978492") {
|
||||
vendorID = model.VendorIDMTWM
|
||||
} else if orderIDLen == len("1000004390") {
|
||||
vendorID = model.VendorIDJX
|
||||
} else if orderIDLen == len("124557362562000001") || orderIDLen == len("13153183146800000100") {
|
||||
vendorID = model.VendorIDJDShop
|
||||
}
|
||||
}
|
||||
return vendorID
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func GenRand6() (num int) {
|
||||
@@ -141,85 +84,6 @@ func GenOrderNo() (orderNo int64) {
|
||||
return orderNo
|
||||
}
|
||||
|
||||
func GenJobOrderNo() (orderNo int64) {
|
||||
const prefix = 88
|
||||
const randPartNum = 1000
|
||||
orderNo = time.Now().Unix() - orderNoBeginTimestamp
|
||||
orderNo = orderNo * randPartNum
|
||||
md5Bytes := md5.Sum([]byte(utils.GetUUID()))
|
||||
randPart := 0
|
||||
for k, v := range md5Bytes {
|
||||
randPart += int(v) << ((k % 3) * 8)
|
||||
}
|
||||
orderNo += int64(randPart % randPartNum)
|
||||
orderNo += int64(math.Pow10(int(math.Log10(float64(orderNo)))+1)) * prefix
|
||||
return orderNo
|
||||
}
|
||||
|
||||
func GenBillID() (billID int64) {
|
||||
const prefix = 66
|
||||
const randPartNum = 100
|
||||
billID = time.Now().Unix() - orderNoBeginTimestamp
|
||||
billID = billID * randPartNum
|
||||
md5Bytes := md5.Sum([]byte(utils.GetUUID()))
|
||||
randPart := 0
|
||||
for k, v := range md5Bytes {
|
||||
randPart += int(v) << ((k % 3) * 8)
|
||||
}
|
||||
billID += int64(randPart % randPartNum)
|
||||
billID += int64(math.Pow10(int(math.Log10(float64(billID)))+1)) * prefix
|
||||
return billID
|
||||
}
|
||||
|
||||
func GenGroupID() (groupID int64) {
|
||||
const randPartNum = 100
|
||||
groupID = time.Now().Unix() - orderNoBeginTimestamp
|
||||
groupID = groupID * randPartNum
|
||||
md5Bytes := md5.Sum([]byte(utils.GetUUID()))
|
||||
randPart := 0
|
||||
for k, v := range md5Bytes {
|
||||
randPart += int(v) << ((k % 3) * 8)
|
||||
}
|
||||
groupID += int64(randPart % randPartNum)
|
||||
groupID += int64(math.Pow10(int(math.Log10(float64(groupID))) + 1))
|
||||
return groupID
|
||||
}
|
||||
|
||||
func GenAfsOrderNo() (orderNo int64) {
|
||||
const prefix = 80
|
||||
const randPartNum = 100
|
||||
orderNo = time.Now().Unix() - orderNoBeginTimestamp
|
||||
orderNo = orderNo * randPartNum
|
||||
md5Bytes := md5.Sum([]byte(utils.GetUUID()))
|
||||
randPart := 0
|
||||
for k, v := range md5Bytes {
|
||||
randPart += int(v) << ((k % 3) * 8)
|
||||
}
|
||||
orderNo += int64(randPart % randPartNum)
|
||||
orderNo += int64(math.Pow10(int(math.Log10(float64(orderNo)))+1)) * prefix
|
||||
return orderNo
|
||||
}
|
||||
|
||||
func GetPossibleVendorIDFromAfsOrderID(afsOrderID string) (vendorID int) {
|
||||
vendorID = model.VendorIDUnknown
|
||||
if afsOrderIDInt64 := utils.Str2Int64WithDefault(afsOrderID, 0); afsOrderIDInt64 > 0 {
|
||||
orderIDLen := len(afsOrderID)
|
||||
if orderIDLen == len("22586438") { // 8
|
||||
vendorID = model.VendorIDJD
|
||||
} else if orderIDLen == len("1413138834") { // 10
|
||||
vendorID = model.VendorIDEBAI
|
||||
} else if orderIDLen == len("29488498752") { // 11
|
||||
vendorID = model.VendorIDMTWM
|
||||
}
|
||||
}
|
||||
return vendorID
|
||||
}
|
||||
|
||||
func ComposeUniversalOrderID(orderID string, vendorID int) string {
|
||||
// return fmt.Sprintf("%s|%d", orderID, vendorID)
|
||||
return orderID // 当前用长度就能区分,先不加上vendorID
|
||||
}
|
||||
|
||||
// distance单位为米
|
||||
func ConvertDistanceToLogLat(lng, lat, distance, angle float64) (newLng, newLat float64) {
|
||||
oneDu := 111319.55 // 单位为米
|
||||
@@ -244,16 +108,6 @@ func EarthDistance(lng1, lat1, lng2, lat2 float64) float64 {
|
||||
return dist * radius
|
||||
}
|
||||
|
||||
// 返回结果单元为公里
|
||||
func WalkingDistance(lng1, lat1, lng2, lat2 float64) (distance float64) {
|
||||
if distance = api.AutonaviAPI.WalkingDistance(lng1, lat1, lng2, lat2); distance == 0 {
|
||||
distance = EarthDistance(lng1, lat1, lng2, lat2) * 1.4
|
||||
} else {
|
||||
distance /= 1000
|
||||
}
|
||||
return distance
|
||||
}
|
||||
|
||||
func StandardCoordinate2Int(value float64) int {
|
||||
return int(math.Round(value * 1000000))
|
||||
}
|
||||
@@ -262,25 +116,6 @@ func IntCoordinate2Standard(value int) float64 {
|
||||
return float64(value) / 1000000
|
||||
}
|
||||
|
||||
func IntCoordinate2MarsStandard(gpsLng, gpsLat int, coordinateType int) (marsLng, marsLat float64, err error) {
|
||||
marsLng = IntCoordinate2Standard(gpsLng)
|
||||
marsLat = IntCoordinate2Standard(gpsLat)
|
||||
coordSys := ""
|
||||
switch coordinateType {
|
||||
case model.CoordinateTypeGPS:
|
||||
coordSys = autonavi.CoordSysGPS
|
||||
case model.CoordinateTypeMars:
|
||||
return marsLng, marsLat, nil
|
||||
case model.CoordinateTypeBaiDu:
|
||||
coordSys = autonavi.CoordSysBaidu
|
||||
case model.CoordinateTypeMapbar:
|
||||
coordSys = autonavi.CoordSysMapbar
|
||||
default:
|
||||
panic(fmt.Sprintf("known coordinate type:%d", coordinateType))
|
||||
}
|
||||
return api.AutonaviAPI.CoordinateConvert(marsLng, marsLat, coordSys)
|
||||
}
|
||||
|
||||
func IntPrice2Standard(value int64) float64 {
|
||||
return float64(value) / 100
|
||||
}
|
||||
@@ -582,49 +417,6 @@ func Strings2Objs(strAndObjAddPairs ...interface{}) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func RefreshAfsOrderSkuRelated(afsOrder *model.AfsOrder) *model.AfsOrder {
|
||||
afsOrder.SkuUserMoney = 0
|
||||
afsOrder.PmSkuSubsidyMoney = 0
|
||||
for _, orderSku := range afsOrder.Skus {
|
||||
if orderSku.SkuID > math.MaxInt32 {
|
||||
orderSku.SkuID = orderSku.JxSkuID
|
||||
}
|
||||
afsOrder.SkuUserMoney += orderSku.UserMoney
|
||||
afsOrder.PmSkuSubsidyMoney += orderSku.PmSkuSubsidyMoney
|
||||
}
|
||||
return afsOrder
|
||||
}
|
||||
|
||||
func UploadExportContent(content []byte, key string) (downloadURL string, err error) {
|
||||
putPolicy := storage.PutPolicy{
|
||||
Scope: globals.QiniuBucket,
|
||||
Expires: 10 * 60,
|
||||
DeleteAfterDays: 1,
|
||||
}
|
||||
upToken := putPolicy.UploadToken(api.QiniuAPI)
|
||||
cfg := &storage.Config{}
|
||||
formUploader := storage.NewFormUploader(cfg)
|
||||
ret := storage.PutRet{}
|
||||
for i := 0; i < 3; i++ {
|
||||
if err = formUploader.Put(context.Background(), &ret, upToken, key, bytes.NewReader(content), int64(len(content)), &storage.PutExtra{}); err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
downloadURL = ComposeQiniuResURL(key)
|
||||
}
|
||||
return downloadURL, err
|
||||
}
|
||||
|
||||
func UploadExeclAndPushMsg(sheetList []*excel.Obj2ExcelSheetConfig, name string) (downloadURL, fileName string, err error) {
|
||||
excelBin := excel.Obj2Excel(sheetList)
|
||||
timeStr := utils.Int64ToStr(time.Now().Unix())
|
||||
fileName = name + timeStr + fileExt
|
||||
baseapi.SugarLogger.Debugf("WriteToExcel:save %s success", fileName)
|
||||
downloadURL, err = UploadExportContent(excelBin, fileName)
|
||||
return downloadURL, fileName, err
|
||||
}
|
||||
|
||||
func TaskResult2Hint(resultList []interface{}) (hint string) {
|
||||
strList := make([]string, len(resultList))
|
||||
for k, v := range resultList {
|
||||
@@ -820,25 +612,6 @@ func PKCS5UnPadding(origData []byte) []byte {
|
||||
return origData[:(length - unpadding)]
|
||||
}
|
||||
|
||||
//合成水印图
|
||||
func MixWatermarkImg(imgWatermark, img, positon string) (imgMix string) {
|
||||
baseURL := base64.URLEncoding.EncodeToString([]byte(imgWatermark))
|
||||
var imgUrl string
|
||||
if strings.Contains(img, "?") {
|
||||
imgUrl = img + "/imageView2/0/q/75|watermark/1/image/" + baseURL + "/dissolve/100/gravity/" + positon + "/dx/10/dy/10"
|
||||
} else {
|
||||
imgUrl = img + "?imageView2/0/q/75|watermark/1/image/" + baseURL + "/dissolve/100/gravity/" + positon + "/dx/10/dy/10"
|
||||
}
|
||||
if resBinary, _, err := DownloadFileByURL(imgUrl); err == nil {
|
||||
if downloadURL, err := UploadExportContent(resBinary, utils.Int64ToStr(time.Now().Unix())+img[strings.LastIndex(img, "/")+1:len(img)]); err == nil {
|
||||
if err == nil {
|
||||
return downloadURL
|
||||
}
|
||||
}
|
||||
}
|
||||
return imgMix
|
||||
}
|
||||
|
||||
func GetIssue() (issue int) {
|
||||
year, month, _ := time.Now().Date()
|
||||
return year*100 + int(month)
|
||||
@@ -900,3 +673,48 @@ func GetWeekTime() (weekTimeBegin, weekTimeEnd time.Time) {
|
||||
weekTimeEnd = weekTimeBegin.AddDate(0, 0, 7)
|
||||
return weekTimeBegin, weekTimeEnd
|
||||
}
|
||||
|
||||
func BuildErr(errs []error) (err error) {
|
||||
var errStr = strings.Builder{}
|
||||
for _, v := range errs {
|
||||
errStr.WriteString(v.Error())
|
||||
}
|
||||
return fmt.Errorf(errStr.String())
|
||||
}
|
||||
|
||||
func SplitFlowAndUnit(flowStr string) (flow float64, unit string) {
|
||||
for _, v := range flowUnitMap {
|
||||
if strings.Contains(flowStr, v) {
|
||||
return utils.Str2Float64WithDefault(flowStr[:len(flowStr)-2], 0), flowStr[len(flowStr)-2:]
|
||||
}
|
||||
}
|
||||
return flow, unit
|
||||
}
|
||||
|
||||
func Flow2KB(flow float64, unit string) (flowKB float64) {
|
||||
if unit == "KB" {
|
||||
return flow
|
||||
} else if unit == "MB" {
|
||||
return flow * 1024
|
||||
} else if unit == "GB" {
|
||||
return flow * 1024 * 1024
|
||||
}
|
||||
return flowKB
|
||||
}
|
||||
|
||||
func FlowKB2Other(flowKB float64) (flow float64, unit string) {
|
||||
if flowKB < 1024 {
|
||||
return flowKB, "KB"
|
||||
} else {
|
||||
flowMB := math.Round(flowKB / float64(1024))
|
||||
if flowMB < 1024 {
|
||||
return flowMB, "MB"
|
||||
} else {
|
||||
flowGB := math.Round(flowMB / float64(1024))
|
||||
if flowGB < 1024 {
|
||||
return flowGB, "GB"
|
||||
}
|
||||
}
|
||||
}
|
||||
return flow, unit
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package jxutils
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type ActStoreSkuMap struct {
|
||||
actStoreSkuMap map[int64]map[int]*model.ActStoreSku2
|
||||
}
|
||||
|
||||
// isActPrice为true表示是活动,false表示是结算
|
||||
func NewActStoreSkuMap(actStoreSkuList []*model.ActStoreSku2, isActPrice bool) (actMap *ActStoreSkuMap) {
|
||||
actMap = &ActStoreSkuMap{}
|
||||
actStoreSkuMap := make(map[int64]map[int]*model.ActStoreSku2)
|
||||
for _, v := range actStoreSkuList {
|
||||
index := Combine2Int(v.StoreID, v.SkuID)
|
||||
if actStoreSkuMap[index] == nil {
|
||||
actStoreSkuMap[index] = make(map[int]*model.ActStoreSku2)
|
||||
}
|
||||
if (isActPrice && v.ActualActPrice > 0 && (actStoreSkuMap[index][v.VendorID] == nil || actStoreSkuMap[index][v.VendorID].ActualActPrice > v.ActualActPrice)) ||
|
||||
(!isActPrice && v.EarningPrice > 0 && (actStoreSkuMap[index][v.VendorID] == nil || actStoreSkuMap[index][v.VendorID].EarningPrice > v.EarningPrice)) {
|
||||
actStoreSkuMap[index][v.VendorID] = v
|
||||
}
|
||||
}
|
||||
actMap.actStoreSkuMap = actStoreSkuMap
|
||||
return actMap
|
||||
}
|
||||
|
||||
func (a *ActStoreSkuMap) GetActStoreSku(storeID, skuID, vendorID int) (storeSku *model.ActStoreSku2) {
|
||||
index := Combine2Int(storeID, skuID)
|
||||
if a.actStoreSkuMap[index] != nil {
|
||||
if vendorID < 0 {
|
||||
for k := range a.actStoreSkuMap[index] {
|
||||
vendorID = k
|
||||
break
|
||||
}
|
||||
}
|
||||
storeSku = a.actStoreSkuMap[index][vendorID]
|
||||
}
|
||||
return storeSku
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/boombuler/barcode"
|
||||
"github.com/boombuler/barcode/code128"
|
||||
"github.com/boombuler/barcode/qr"
|
||||
@@ -97,20 +96,6 @@ func SplitStoreName(fullName, separator, defaultPrefix string) (prefix, bareName
|
||||
return TrimDecorationChar(prefix), TrimDecorationChar(bareName)
|
||||
}
|
||||
|
||||
func ComposeStoreName(bareName string, vendorID int) (fullName string) {
|
||||
bareName = TrimDecorationChar(strings.Trim(bareName, "-"))
|
||||
storeName := globals.StoreName
|
||||
if vendorID == model.VendorIDJD {
|
||||
fullName = storeName + "-" + bareName
|
||||
} else {
|
||||
if globals.IsMainProductEnv() && model.ShopChineseNames[vendorID] != "" {
|
||||
storeName = model.ShopChineseNames[vendorID]
|
||||
}
|
||||
fullName = storeName + "(" + bareName + ")"
|
||||
}
|
||||
return fullName
|
||||
}
|
||||
|
||||
func StrTime2JxOperationTime(strTime string, defValue int16) int16 {
|
||||
if timeValue, err := time.Parse("15:04:05", strTime); err == nil {
|
||||
return int16(timeValue.Hour()*100 + timeValue.Minute())
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/eventhub/syseventhub"
|
||||
"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/legacymodel"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
|
||||
|
||||
@@ -7,9 +7,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/ddmsg"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
@@ -486,20 +484,20 @@ func SendMessage(t *BaseTask) {
|
||||
time.Sleep(10 * time.Millisecond) // 等待GetResult中的isGetResultCalled赋值
|
||||
globals.SugarLogger.Debugf("BaseTask task ID:%s, name:%s finished, isGetResultCalled:%t", t.ID, t.Name, t.isGetResultCalled)
|
||||
if !t.isGetResultCalled && t.parent == nil && len(GetTasks(t.ID, TaskStatusBegin, TaskStatusEnd, 24, "")) > 0 {
|
||||
if authInfo, err := t.ctx.GetV2AuthInfo(); err == nil { // 这里应该是不管登录类型,直接以可能的方式发消息
|
||||
var content string
|
||||
taskDesc := fmt.Sprintf("你的异步任务[%s],ID[%s],开始于:%s,结束于:%s,", t.Name, t.ID, utils.Time2Str(t.CreatedAt), utils.Time2Str(t.TerminatedAt))
|
||||
content = fmt.Sprintf("%s执行%s", taskDesc, TaskStatusName[t.Status])
|
||||
if t.Error() == "" {
|
||||
noticeMsg := t.GetNoticeMsg()
|
||||
if noticeMsg != "" {
|
||||
content += ",通知消息:" + noticeMsg
|
||||
}
|
||||
} else {
|
||||
content += ",\n" + t.Error()
|
||||
}
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "异步任务完成", content)
|
||||
}
|
||||
//if authInfo, err := t.ctx.GetV2AuthInfo(); err == nil { // 这里应该是不管登录类型,直接以可能的方式发消息
|
||||
// var content string
|
||||
// taskDesc := fmt.Sprintf("你的异步任务[%s],ID[%s],开始于:%s,结束于:%s,", t.Name, t.ID, utils.Time2Str(t.CreatedAt), utils.Time2Str(t.TerminatedAt))
|
||||
// content = fmt.Sprintf("%s执行%s", taskDesc, TaskStatusName[t.Status])
|
||||
// if t.Error() == "" {
|
||||
// noticeMsg := t.GetNoticeMsg()
|
||||
// if noticeMsg != "" {
|
||||
// content += ",通知消息:" + noticeMsg
|
||||
// }
|
||||
// } else {
|
||||
// content += ",\n" + t.Error()
|
||||
// }
|
||||
// ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "异步任务完成", content)
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
package push
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/unipushapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
func pushToSingle(content, title string, storeID int) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
if !globals.IsProductEnv() {
|
||||
return
|
||||
}
|
||||
storePushs, err := dao.GetStorePushClient(db, storeID, "")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range storePushs {
|
||||
|
||||
status, err2 := api.PushAPI.PushToSingle(v.ClientID, false, &unipushapi.Notification{
|
||||
Title: title,
|
||||
Body: content,
|
||||
})
|
||||
if err = err2; err != nil {
|
||||
globals.SugarLogger.Debugf("NotifyNewOrder push error: [%v]", err)
|
||||
continue
|
||||
}
|
||||
if status == unipushapi.SuccessOffLine {
|
||||
_, err = api.PushAPI.PushToSingle(v.ClientID, true, &unipushapi.Notification{
|
||||
Body: content,
|
||||
})
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("NotifyNewOrder push2 error: [%v]", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func NotifyNewOrder(order *model.GoodsOrder) {
|
||||
globals.SugarLogger.Debugf("NotifyNewOrder push begin orderID :[%v]", order.VendorOrderID)
|
||||
sb := new(strings.Builder)
|
||||
sb.WriteString("老板,")
|
||||
sb.WriteString(order.ConsigneeName)
|
||||
sb.WriteString("购买了商品")
|
||||
sb.WriteString(getOrderDetailBrief(order))
|
||||
pushToSingle(sb.String(), "京西菜市新订单推送", jxutils.GetSaleStoreIDFromOrder(order))
|
||||
}
|
||||
|
||||
func getOrderDetailBrief(order *model.GoodsOrder) (brief string) {
|
||||
sb := new(strings.Builder)
|
||||
sb.WriteString(order.Skus[0].SkuName)
|
||||
sb.WriteString("等共")
|
||||
sb.WriteString(utils.Int2Str(order.Skus[0].Count))
|
||||
sb.WriteString("份(")
|
||||
sb.WriteString(jxutils.IntPrice2StandardString(order.Skus[0].SalePrice))
|
||||
sb.WriteString("元/份)等,预计收入")
|
||||
//TODO 2020-07-20 果园和菜市不同
|
||||
var price int64
|
||||
if beego.BConfig.RunMode == "jxgy" {
|
||||
price = order.EarningPrice
|
||||
} else {
|
||||
if order.EarningType == model.EarningTypePoints {
|
||||
price = order.ActualPayPrice
|
||||
} else {
|
||||
price = order.ShopPrice
|
||||
}
|
||||
}
|
||||
sb.WriteString(jxutils.IntPrice2StandardString(price))
|
||||
sb.WriteString("元")
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func NotifyAfsOrder(afsOrder *model.AfsOrder) (err error) {
|
||||
globals.SugarLogger.Debugf("NotifyAfsOrder push begin orderID :[%v]", afsOrder.VendorOrderID)
|
||||
pushToSingle("老板,您有新的售后单,请尽快处理!", "京西菜市售后单推送", jxutils.GetSaleStoreIDFromAfsOrder(afsOrder))
|
||||
return err
|
||||
}
|
||||
|
||||
func NotifyOrderCanceled(order *model.GoodsOrder) (err error) {
|
||||
title := fmt.Sprintf("老板,您的订单%s第%d号订单, %s被取消了!", model.VendorChineseNames[order.VendorID], order.OrderSeq, order.VendorOrderID)
|
||||
pushToSingle(title, "京西菜市取消单推送", jxutils.GetSaleStoreIDFromOrder(order))
|
||||
return err
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
package weixinmsg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
const (
|
||||
WX_TO_ORDER_PAGE_URL = "/#/?jxStoreId="
|
||||
WX_TO_STORE_SKU_PAGE_URL = "/#/shop?jxStoreId="
|
||||
WX_TO_SHOW_COMMENTS_DETAIL_URL = "/#/assess-list?jxStoreId=" //展示差评详情的页面
|
||||
WX_TO_SHOW_MSG = "/#/message-detail?msgID=%d&msgStatusID=%d"
|
||||
|
||||
WX_MINI_TO_ORDER_PAGE_URL = "pages/order-manager/main"
|
||||
WX_MINI_TO_STORE_SKU_PAGE_URL = "pages/goods-manager/main"
|
||||
WX_MINI_TO_SHOW_COMMENTS_DETAIL_URL = "pages/pagesStore/store-comment/main"
|
||||
WX_MINI_TO_SHOW_MSG = "pages/pagesStore/msg-page/main?msgID=%d&msgStatusID=%d"
|
||||
|
||||
//新订单模板消息文字颜色
|
||||
WX_NEW_ORDER_TEMPLATE_COLOR = "#173177"
|
||||
WX_HIGHLEVEL_TEMPLATE_COLOR = "#FF0000" //红色
|
||||
WX_HIGHLEVEL_TEMPLATE_COLOR2 = "#333333" //黑色
|
||||
WX_TEMPLATE_VENDERCOLOR_JDDJ = "#47B34F"
|
||||
WX_TEMPLATE_VENDERCOLOR_MT = "#F4A800"
|
||||
WX_TEMPLATE_VENDERCOLOR_ELM = "#0191EA" //蓝色
|
||||
WX_TEMPLATE_VENDERCOLOR_BAD_COMMENTS = "#4F4DA0"
|
||||
|
||||
WX_NEWORDER_TEMPLATE_ID = "_DtNGwmOeR6TkkTVUblxLIlkV2MAPOX57TkvfdqG6nY" //微信新订单推送
|
||||
WX_ADJUSTORDER_TEMPLATE_ID = "N5rmV2-PDf3opjkv23IdLc76VnFThr_uOKSh5FzT13M" //微信调整订单推送
|
||||
WX_MTPS_DELIVERY_GRABDONE_TEMPLATE_ID = "h4dkON6AgnHz1XmaksEUB_8Bcir4V8MSexUhC149pPE" //微信美团配送员接单推送
|
||||
WX_MTPS_DELIVERY_DONE_TEMPLATE_ID = "YXdCrQAHZlcZX1htYUiarrLmtkmKAjp7rynjwObgODo" //微信美团配送员配送完成推送
|
||||
WX_MTPS_UNABLE_DELIVER_TEMPLATE_ID = "ZFph5Hp7oLlrzVRXbsKIC_StmaBeB9Dlp4tlHeAmUQ8" //微信美团配送配送能力不足推送
|
||||
WX_MTPS_DELIVERY_EXCEPTION_TEMPLATE_ID = "RkfOFHgR1N75L4-a6Gv0DljpCsVfOHhLm_vyXh8MR-w" //微信美团配送异常推送
|
||||
WX_BAD_COMMENT_PUSH_TEMPLATE_ID = "NaMEzjctvVPQ9ishTI1dKpp5QSYV2FWcWftSSjDrpN8" //微信中差评消息推送
|
||||
|
||||
WX_DADA_DELIVERY_GRABDONE_TEMPLATE_ID = "h4dkON6AgnHz1XmaksEUB_8Bcir4V8MSexUhC149pPE" //微信达达众包配送员接单推送
|
||||
WX_DADA_DELIVERY_DONE_TEMPLATE_ID = "YXdCrQAHZlcZX1htYUiarrLmtkmKAjp7rynjwObgODo" //微信达达众包配送员配送完成推送
|
||||
|
||||
WX_SALE_BILL_TEMPLATE_ID = "eTUuFZMWH7IsVBfcxNMpmaHYaxRkUaD6zG8wSGJDcic"
|
||||
|
||||
WX_NORMAL_STORE_MSG_TEMPLATE_ID = "EUeIJEz2TLUAn4TU2EffOGYLd3dEaYndD_y6Sw9FcSU"
|
||||
WX_CHANGE_APPROVED_TEMPLATE_ID = "gIG2olBZtQbjXmp6doNB_dESu60By5xuXYOGxksLv3Y"
|
||||
WX_CHANGE_REJECTED_TEMPLATE_ID = "OBF4-d5inK95epHcUltpdb1zq9boVp2HESpASVRh1Oo"
|
||||
WX_ORDER_APPLY_CANCEL_TEMPLATE_ID = "e6urTtcm4PL0rgDMG_1qWNOwrE3Qxqcm_dx0kWWCmEI"
|
||||
WX_ORDER_ORDER_CANCELED_TEMPLATE_ID = "HXjuSAbIk77Xh18hjgwoxHzbciR9jX3Rn2CpLJz9dZw"
|
||||
WX_ORDER_CHANGE_INFO_TEMPLATE_ID = "cjmEQFEpvcOuBNqQpTfMU5FeBpGRbQh_gWKz-WPW8Ro"
|
||||
|
||||
WX_AFS_ORDER_WAIT4APPROVE_TEMPLATE_ID = "X29udtANvhX6x1Lyh-T40NGNjRXBbUj5oSBTfDhZAqU"
|
||||
WX_AFS_ORDER_STATUS_CHANGED_TEMPLATE_ID = "99T33rrXX0VboO1hljs4x8dDoLiSj3QX_rOikPHIXkg"
|
||||
|
||||
WS_NOTIFY_STORE_STATUS_CHHANGED_TEMPLATE_ID = "Fl0vOnBKTQqRFx3-shGKxdCnxMdQXNeODzgkuwd7oxw"
|
||||
|
||||
WX_STORE_ALERT_TEMPLATE_ID = "0AjzVl1wPl6iO4nFOS4IEsJYSzBymlT37DciIvcCOxE"
|
||||
)
|
||||
|
||||
var (
|
||||
VendorColors = map[int]string{
|
||||
model.VendorIDJD: WX_TEMPLATE_VENDERCOLOR_JDDJ,
|
||||
model.VendorIDMTWM: WX_TEMPLATE_VENDERCOLOR_MT,
|
||||
model.VendorIDELM: WX_TEMPLATE_VENDERCOLOR_ELM,
|
||||
model.VendorIDEBAI: WX_TEMPLATE_VENDERCOLOR_ELM,
|
||||
}
|
||||
testMiniProgramStoreMap = map[int]int{
|
||||
101089: 1,
|
||||
100888: 1,
|
||||
100204: 1,
|
||||
100205: 1,
|
||||
100147: 1,
|
||||
}
|
||||
debugOpenIDMap = map[string]int{
|
||||
"oYN_usk0AeGc_C6VEZfmFQP5VHMQ": 1, // 周小扬
|
||||
"oYN_ust9hXKEvEv0X6Mq6nlAWs_E": 1, // me
|
||||
"oYN_usqnpGVQ4xxlao_yybsbYJh4": 1, // 朱丹
|
||||
}
|
||||
)
|
||||
|
||||
func SmartMessageTemplateSend(userOpenID, templateID, downloadURL, miniPageURL string, data interface{}) (err error) {
|
||||
var miniProgram map[string]interface{}
|
||||
if miniPageURL != "" {
|
||||
miniProgram = map[string]interface{}{
|
||||
"appid": api.WeixinMiniAPI.GetAppID(),
|
||||
"pagepath": miniPageURL,
|
||||
}
|
||||
}
|
||||
globals.SugarLogger.Debugf("SmartMessageTemplateSend openID:%s, templateID:%s, downloadURL:%s, miniProgram:%s", userOpenID, templateID, downloadURL, utils.Format4Output(miniProgram, true))
|
||||
if globals.ReallySendWeixinMsg || debugOpenIDMap[userOpenID] == 1 {
|
||||
if err = api.WeixinAPI.CBMessageTemplateSend(userOpenID, templateID, downloadURL, miniProgram, data); err != nil {
|
||||
globals.SugarLogger.Debugf("SmartMessageTemplateSend openID:%s, templateID:%s, downloadURL:%s, miniProgram:%s, failed with error:%v", userOpenID, templateID, downloadURL, utils.Format4Output(miniProgram, true), err)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func SendMsgToUser(userID string, templateID string, data interface{}) (err error) {
|
||||
globals.SugarLogger.Debugf("SendMsgToUser userID:%d, templateID:%s", userID, templateID)
|
||||
authBinds, err := dao.GetUserBindAuthInfo(dao.GetDB(), userID, model.AuthBindTypeAuth, []string{"weixinsns"}, "", "", "wx2bb99eb5d2c9b82c")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
successCount := 0
|
||||
if len(authBinds) == 0 {
|
||||
return fmt.Errorf("此用户未找到微信认证方式!userID: %v", userID)
|
||||
}
|
||||
globals.SugarLogger.Debugf("SendMsgToUser userID:%d, openID:%s, templateID:%s", userID, authBinds[0].AuthID, templateID)
|
||||
if err2 := SmartMessageTemplateSend(authBinds[0].AuthID, templateID, "", "", data); err2 == nil {
|
||||
successCount++
|
||||
} else {
|
||||
err = err2
|
||||
}
|
||||
if successCount > 0 {
|
||||
err = nil // 只要成功一个都当成成功
|
||||
}
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("SendMsgToUser all failed userID:%d, templateID:%s, error:%v", userID, templateID, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package weixinmsg
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/globals/api2"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||
)
|
||||
|
||||
func init() {
|
||||
testinit.Init()
|
||||
api2.Init()
|
||||
}
|
||||
|
||||
func TestGetWeixinOpenIDsFromStoreID(t *testing.T) {
|
||||
openIDs := GetWeixinOpenIDsFromStoreID(100118)
|
||||
t.Log(utils.Format4Output(openIDs, false))
|
||||
}
|
||||
|
||||
func TestSendStoreMessage(t *testing.T) {
|
||||
_, err := SendStoreMessage(jxcontext.AdminCtx, "title", "content", []int{1}, false, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -1,261 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
ActTypeAll = -1
|
||||
ActSkuFake = 0 // 假活动,只用于存储活动结算信息
|
||||
ActSkuDirectDown = 3 // 直降
|
||||
ActSkuSecKill = 4 // 秒杀
|
||||
ActSkuDiscount = 5 // 折扣
|
||||
|
||||
ActDiscountTypePrice = 1 //折扣类型是最低价
|
||||
ActDiscountTypePercentage = 2 //折扣类型是最低折扣
|
||||
|
||||
TrendTypeUp = 1 //涨价趋势
|
||||
TrendTypeDown = 2 //降价趋势
|
||||
TrendTypeNothing = 0 //不变
|
||||
|
||||
ActOrderBegin = 10
|
||||
ActOrderMoneyOff = 11
|
||||
ActOrderMoneyOffCoupon = 12
|
||||
ActOrderReduceFreight = 13
|
||||
ActOrderReduceFreightCoupon = 14
|
||||
)
|
||||
|
||||
const (
|
||||
ActStatusNA = 0 // 未知
|
||||
ActStatusCreated = 1 // 需同步
|
||||
ActStatusCanceled = 2 // 需同步
|
||||
ActStatusEnded = 3 // 不需要同步,根据活动时间自动刷新的
|
||||
|
||||
ActCreateTypeAPI = 1
|
||||
ActCreateTypeCallback = 2
|
||||
ActCreateTypeSpider = 3
|
||||
|
||||
OverlapRuleNormal = 0 // 不允许重叠(重叠会报错)
|
||||
OverlapRuleReplace = 1 // 相同活动类型,或秒杀替换直降
|
||||
)
|
||||
|
||||
var (
|
||||
ActTypeName = map[int]string{
|
||||
ActSkuFake: "结算",
|
||||
ActSkuDirectDown: "直降",
|
||||
ActSkuSecKill: "秒杀",
|
||||
ActSkuDiscount: "折扣",
|
||||
}
|
||||
|
||||
ActStatusName = map[int]string{
|
||||
ActStatusNA: "未知",
|
||||
ActStatusCreated: "正常",
|
||||
ActStatusCanceled: "取消",
|
||||
ActStatusEnded: "结束",
|
||||
}
|
||||
|
||||
ActCreateTypeName = map[int]string{
|
||||
ActCreateTypeAPI: "API",
|
||||
ActCreateTypeCallback: "回调",
|
||||
ActCreateTypeSpider: "网页",
|
||||
}
|
||||
)
|
||||
|
||||
type Act struct {
|
||||
ModelIDCULD
|
||||
|
||||
Name string `orm:"size(64)" json:"name"`
|
||||
Advertising string `orm:"size(255)" json:"advertising"`
|
||||
Type int `json:"type"`
|
||||
Status int `json:"status"`
|
||||
LimitUser int `json:"limitUser"` // 是否按用户限制
|
||||
LimitDaily int `json:"limitDaily"` // 每日限购单数
|
||||
LimitCount int `json:"limitCount"` // 每单限购数量
|
||||
Source string `orm:"size(255)" json:"source"`
|
||||
CreateType int `json:"createType"`
|
||||
IsSpecial int8 `json:"isSpecial"` // 是否是特殊绑定活动
|
||||
OverlapRule int `json:"overlapRule"`
|
||||
PricePercentage int `json:"pricePercentage"` // 单品级活动才有效
|
||||
BeginAt time.Time `orm:"type(datetime);index" json:"beginAt"`
|
||||
EndAt time.Time `orm:"type(datetime);index" json:"endAt"`
|
||||
VendorMask int `json:"-"`
|
||||
Remark string `orm:"size(255)" json:"remark"`
|
||||
DiscountType int `json:"discountType"` //折扣类型,1为最低价,2为最低折扣
|
||||
DiscountValue1 int `json:"DiscountValue1"` //第一档折扣
|
||||
DiscountValue2 int `json:"DiscountValue2"` //第二档折扣
|
||||
}
|
||||
|
||||
// test
|
||||
func (*Act) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"Name", "Type", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
type ActMap struct {
|
||||
ModelIDCULD
|
||||
|
||||
ActID int `orm:"column(act_id)" json:"actID"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空
|
||||
|
||||
VendorActID string `orm:"column(vendor_act_id);size(48)" json:"vendorActID"`
|
||||
SyncStatus int8 `orm:"default(2)" json:"syncStatus"`
|
||||
|
||||
Remark string `orm:"size(1024)" json:"remark"`
|
||||
}
|
||||
|
||||
func (*ActMap) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"ActID", "VendorID", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
func (*ActMap) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"VendorActID", "VendorID", "DeletedAt"}, // 饿百,美团活动的VendorActID统一为空,不能设置为唯一索引
|
||||
}
|
||||
}
|
||||
|
||||
// 不建表
|
||||
type Act2 struct {
|
||||
MapID int `orm:"column(map_id)"`
|
||||
|
||||
Act
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空
|
||||
|
||||
VendorActID string `orm:"column(vendor_act_id);size(48)" json:"vendorActID"`
|
||||
SyncStatus int8 `orm:"default(2)" json:"syncStatus"`
|
||||
}
|
||||
|
||||
func (a *Act2) GetRealActName() string {
|
||||
if IsSyncStatusNeedCreate(a.SyncStatus) {
|
||||
return a.Name
|
||||
}
|
||||
return a.Name + "_" + utils.Int64ToStr(time.Now().Unix())
|
||||
}
|
||||
|
||||
type ActOrderRule struct {
|
||||
ModelIDCULD
|
||||
|
||||
ActID int `orm:"column(act_id)" json:"actID"`
|
||||
SalePrice int64 `orm:"" json:"salePrice"` // 满的价格
|
||||
DeductPrice int64 `orm:"" json:"deductPrice"` // 减的价格
|
||||
}
|
||||
|
||||
type ActStoreSku struct {
|
||||
ModelIDCULD
|
||||
|
||||
ActID int `orm:"column(act_id)" json:"actID"`
|
||||
|
||||
OriginalPrice int64 `orm:"" json:"originalPrice"` // 单品级活动用,创建活动时商品的原始京西价
|
||||
|
||||
// 以下字段,API中有效
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"`
|
||||
SkuID int `orm:"column(sku_id)" json:"skuID"`
|
||||
|
||||
PricePercentage int `orm:"" json:"pricePercentage"` // 单品级活动用,SKU级的价格比例,非0覆盖Act中的PricePercentage
|
||||
ActPrice int64 `orm:"" json:"actPrice"` // 单品级活动用,SKU级指定的价格,非0覆盖CustomPricePercentage与Act中的PricePercentage
|
||||
EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱
|
||||
Stock int `orm:"" json:"stock"` // 活动库存
|
||||
}
|
||||
|
||||
func (*ActStoreSku) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"ActID", "StoreID", "SkuID", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
type ActStoreSkuMap struct {
|
||||
ModelIDCULD
|
||||
|
||||
BindID int `orm:"column(bind_id)" json:"bindID"`
|
||||
ActID int `orm:"column(act_id)" json:"actID"`
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"`
|
||||
SkuID int `orm:"column(sku_id)" json:"skuID"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
|
||||
VendorActID string `orm:"column(vendor_act_id);size(48)" json:"vendorActID"`
|
||||
SyncStatus int8 `orm:"default(2)" json:"syncStatus"`
|
||||
VendorPrice int64 `json:"vendorPrice"` // 创建活动时的平台价格
|
||||
ActualActPrice int64 `json:"actualActPrice"` // 单品级活动用,创建活动时商品的活动价格
|
||||
EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱
|
||||
TrendType int `json:"trendType"` //折扣活动使用,涨跌趋势,1为涨,2为跌,0为不动
|
||||
TrendPrice int `json:"trendPrice"` //涨跌具体多少
|
||||
}
|
||||
|
||||
func (*ActStoreSkuMap) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"ActID", "BindID", "VendorID"},
|
||||
}
|
||||
}
|
||||
|
||||
func (*ActStoreSkuMap) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"ActID", "StoreID", "SkuID", "VendorID", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
// 不建表
|
||||
type ActStoreSku2 struct {
|
||||
MapID int `orm:"column(map_id)"`
|
||||
|
||||
Type int `json:"type"`
|
||||
DiscountType int `json:"discountType"`
|
||||
DiscountValue1 int `json:"discountValue1"`
|
||||
DiscountValue2 int `json:"discountValue2"`
|
||||
|
||||
ActStoreSku
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
|
||||
VendorActID string `orm:"column(vendor_act_id);size(48)" json:"vendorActID"`
|
||||
SyncStatus int8 `orm:"default(2)" json:"syncStatus"`
|
||||
VendorPrice int64 `json:"vendorPrice"` // 创建活动时的平台价格
|
||||
ActualActPrice int64 `json:"actualActPrice"` // 单品级活动用,创建活动时商品的活动价格
|
||||
|
||||
VendorStoreID string `orm:"column(vendor_store_id)" json:"vendorStoreID"`
|
||||
StoreName string `json:"storeName"`
|
||||
|
||||
VendorSkuID string `orm:"column(vendor_sku_id)" json:"vendorSkuID"`
|
||||
|
||||
SkuName string `json:"skuName"`
|
||||
|
||||
Prefix string `json:"-"`
|
||||
ExPrefix string
|
||||
ExPrefixBegin *time.Time
|
||||
ExPrefixEnd *time.Time
|
||||
SkuNameName string `orm:"column(sku_name_name)" json:"-"`
|
||||
Unit string `orm:"size(8)" json:"-"`
|
||||
SpecQuality float32 `json:"-"`
|
||||
SpecUnit string `json:"-"`
|
||||
Comment string `json:"-"`
|
||||
TrendType int `json:"trendType"` //折扣活动使用,涨跌趋势,1为涨,2为跌,0为不动
|
||||
TrendPrice int `json:"trendPrice"` //涨跌具体多少
|
||||
}
|
||||
|
||||
type StoreSkuAct struct {
|
||||
ModelIDCUL
|
||||
StoreID int `orm:"column(store_id)"`
|
||||
SkuID int `orm:"column(sku_id);index"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
|
||||
ActPercentage int `json:"actPercentage"` // 直降活动百分比
|
||||
SyncStatus int8 `orm:"default(2)" json:"syncStatus"`
|
||||
// ActID int `orm:"column(act_id);index" json:"actID"`
|
||||
VendorActID string `orm:"column(vendor_act_id);size(48);index" json:"vendorActID"`
|
||||
HintActID int `orm:"column(hint_act_id);size(48);index" json:"hintActID"`
|
||||
VendorActPrice int64 `json:"vendorActPrice"` // 保存数据用,实际的活动价
|
||||
Remark string `orm:"column(remark);size(1024)" json:"remark"`
|
||||
|
||||
// EarningActID int `orm:"column(earning_act_id);index" json:"earningActID"`
|
||||
// EarningPrice int64 `json:"earningPrice"`
|
||||
}
|
||||
|
||||
func (*StoreSkuAct) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"StoreID", "SkuID", "VendorID"},
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package model
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -35,23 +34,6 @@ type PagedInfo struct {
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type OrderFinancialExt struct {
|
||||
OrderFinancial
|
||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"` //
|
||||
OrderFinishedAt time.Time `orm:"type(datetime)" json:"orderFinishedAt"` // 订单妥投/完成时间
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"` // 外部系统里记录的 jxstoreid
|
||||
JxStoreID int `orm:"column(jx_store_id)" json:"jxStoreID"` // 根据VendorStoreID在本地系统里查询出来的 jxstoreid
|
||||
StoreName string `orm:"size(64)" json:"storeName"` //
|
||||
Status int `json:"status"` // 参见OrderStatus*相关的常量定义
|
||||
Skus []*OrderSkuFinancial `orm:"-" json:"skus"` // 正向订单购买商品列表
|
||||
Discounts []*OrderDiscountFinancial `orm:"-" json:"discounts"` // 正向订单享受优惠列表
|
||||
}
|
||||
|
||||
type OrderFinancialSkuExt struct {
|
||||
OrderSkuFinancial
|
||||
Image string `json:"image"`
|
||||
}
|
||||
|
||||
type ProductInfo struct {
|
||||
OriginalName string `json:"originalName"`
|
||||
OriginalSpec string `json:"originalSpec"`
|
||||
|
||||
@@ -12,20 +12,23 @@ const (
|
||||
VendorIDPurchaseBegin = 0
|
||||
VendorIDJD = 0
|
||||
VendorIDMTWM = 1
|
||||
VendorIDPDD = 2 //拼多多
|
||||
VendorIDELM = 2
|
||||
VendorIDEBAI = 3
|
||||
VendorIDTB = 4 //淘宝
|
||||
VendorIDJDShop = 5 //京东商城
|
||||
VendorIDJX = 9 // 这是一个假的京西VendorID
|
||||
VendorIDPurchaseEnd = 10
|
||||
VendorIDOther = 999 //其他平台
|
||||
VendorIDGD = 10
|
||||
VendorIDYB = 4 //银豹
|
||||
VendorIDJDShop = 5 //京东商城
|
||||
VendorIDWSC = 11 // 微盟微商城
|
||||
VendorIDPurchaseEnd = 11
|
||||
VendorIDJX = 9 // 这是一个假的京西VendorID
|
||||
VendorGoMei = 12 // 国美
|
||||
VendorIDTT = 14 // 抖音平台小程序
|
||||
|
||||
VendorIDWXPay = 51 // 微信支付
|
||||
|
||||
VendorIDDeliveryBegin = 101
|
||||
VendorIDDada = 101
|
||||
VendorIDMTPS = 102
|
||||
VendorIDFengNiao = 103
|
||||
VendorIDDada = 101 // 达达配送
|
||||
VendorIDMTPS = 102 // 美团配送
|
||||
VendorIDFengNiao = 103 // 蜂鸟配送
|
||||
VendorIDJDWL = 401 //京东物流
|
||||
VendorIDDeliveryEnd = 500
|
||||
|
||||
@@ -34,6 +37,7 @@ const (
|
||||
VendorIDXiaoWM = 202 // 外卖管家打印机
|
||||
VendorIDYiLianYun = 203 // 易联云
|
||||
VendorIDZhongWu = 204 // 中午云打印
|
||||
VendorIDJxprint = 205 // 京西打印
|
||||
VendorIDPrinterEnd = 300
|
||||
|
||||
VendorIDOthersBegin = 301
|
||||
@@ -48,6 +52,22 @@ const (
|
||||
VendorIDAutonavi = 321 // 高德导航
|
||||
VendorIDQiNiuCloud = 323 // 七牛云
|
||||
VendorIDShowAPI = 325 // 万维易源
|
||||
|
||||
// 美团配送门店配送方式
|
||||
MTWMStorePSWay1 = "1003" //美团跑腿(众包)
|
||||
MTWMStorePSWay2 = "1001" //专送(加盟)
|
||||
MTWMStorePSWay3 = "1002" //专送(自建)
|
||||
MTWMStorePSWay4 = "1004" //城市代理
|
||||
MTWMStorePSWay5 = "2002" //快送
|
||||
MTWMStorePSWay6 = "2010" //全城送
|
||||
MTWMStorePSWay7 = "0000" //商家自配
|
||||
MTWMStorePSWay8 = "3001" //混合送(专送+快送)
|
||||
MTWMStorePSWay9 = "30011002" //混合自建
|
||||
MTWMStorePSWay10 = "30011001" //混合加盟
|
||||
MTWMStorePSWay11 = "30012002" //混合快送
|
||||
MTWMStorePSWay12 = "0002" //趣生活美食配送
|
||||
MTWMStorePSWay13 = "0016" //达达快递
|
||||
MTWMStorePSWay14 = "0033" //E_代送
|
||||
)
|
||||
|
||||
type VendorInfo struct {
|
||||
@@ -65,22 +85,26 @@ var (
|
||||
VendorNames = map[int]string{
|
||||
VendorIDJD: "Jd",
|
||||
VendorIDMTWM: "Mtwm",
|
||||
VendorIDPDD: "Pdd",
|
||||
VendorIDELM: "Elm",
|
||||
VendorIDEBAI: "Ebai",
|
||||
VendorIDTB: "Tb",
|
||||
VendorIDWSC: "Wsc",
|
||||
VendorIDYB: "Yb",
|
||||
VendorIDJX: "Jx",
|
||||
VendorIDJDShop: "Jds",
|
||||
|
||||
VendorIDDada: "Dada",
|
||||
VendorIDMTPS: "Mtps",
|
||||
VendorIDDada: "Dada",
|
||||
VendorIDMTPS: "Mtps",
|
||||
VendorIDFengNiao: "Fn",
|
||||
|
||||
VendorIDFeiE: "Feie",
|
||||
VendorIDXiaoWM: "XiaoWM",
|
||||
VendorIDYiLianYun: "Yilianyun",
|
||||
VendorIDZhongWu: "ZhongWu",
|
||||
VendorIDJxprint: "Jx",
|
||||
|
||||
VendorIDQiNiuCloud: "Qiniu",
|
||||
VendorIDJDWL: "Jdwl",
|
||||
VendorGoMei: "GoMei",
|
||||
}
|
||||
|
||||
VendorTypeName = map[int]string{
|
||||
@@ -93,21 +117,23 @@ var (
|
||||
VendorChineseNames = map[int]string{
|
||||
VendorIDJD: "京东到家",
|
||||
VendorIDMTWM: "美团外卖",
|
||||
VendorIDPDD: "拼多多",
|
||||
VendorIDELM: "饿了么",
|
||||
VendorIDEBAI: "饿百新零售",
|
||||
VendorIDTB: "淘宝",
|
||||
VendorIDYB: "银豹",
|
||||
VendorIDJDShop: "京东商城",
|
||||
VendorIDWSC: "微盟微商城",
|
||||
VendorIDJX: "京西商城",
|
||||
VendorIDOther: "其他平台",
|
||||
|
||||
VendorIDDada: "达达众包",
|
||||
VendorIDMTPS: "美团配送",
|
||||
VendorIDJDWL: "京东物流",
|
||||
VendorIDDada: "达达众包",
|
||||
VendorIDMTPS: "美团配送",
|
||||
VendorIDJDWL: "京东物流",
|
||||
VendorIDFengNiao: "蜂鸟配送",
|
||||
|
||||
VendorIDFeiE: "飞鹅",
|
||||
VendorIDXiaoWM: "外卖管家",
|
||||
VendorIDYiLianYun: "易联云",
|
||||
VendorIDZhongWu: "中午云",
|
||||
VendorIDJxprint: "京西云",
|
||||
|
||||
VendorIDWXMP: "微信公众号",
|
||||
VendorIDWXQRCode: "微信扫码",
|
||||
@@ -119,21 +145,7 @@ var (
|
||||
VendorIDAutonavi: "高德导航",
|
||||
VendorIDQiNiuCloud: "七牛云",
|
||||
VendorIDShowAPI: "万维易源",
|
||||
}
|
||||
|
||||
VendorImg = map[int]string{
|
||||
VendorIDJD: "http://image.jxc4.com/image/b1bd587d98e82ad6405132b8da67a1db.tem.png",
|
||||
VendorIDMTWM: "http://image.jxc4.com/image/fb09e10a9c059aa6c133ff3e05c1dbbc.tem.png",
|
||||
VendorIDEBAI: "http://image.jxc4.com/image/28e654c72a2bd92c5d09fdab475f6288.tem.png",
|
||||
VendorIDJDShop: "http://image.jxc4.com/image/7c43ebbcbdbc0ef31fe028f680c0a7e3.tem.png",
|
||||
VendorIDOther: "http://image.jxc4.com/image/558382ba95573b9537fbb209cadbd031.tem.png",
|
||||
}
|
||||
|
||||
VendorColors = map[int]string{
|
||||
VendorIDJD: "#3CC518",
|
||||
VendorIDMTWM: "#FFB14A",
|
||||
VendorIDEBAI: "#E43428",
|
||||
VendorIDJDShop: "#51A7FC",
|
||||
VendorGoMei: "国美",
|
||||
}
|
||||
|
||||
VendorInfoMap = map[int]*VendorInfo{
|
||||
|
||||
229
business/model/api_config_2.go
Normal file
229
business/model/api_config_2.go
Normal file
@@ -0,0 +1,229 @@
|
||||
package model
|
||||
|
||||
//
|
||||
//// VendorIDJD, VendorIDMTWM与VendorIDELM的定义和老系统是兼容的
|
||||
//const (
|
||||
// VendorTypeUnknown = 0 // 未知
|
||||
// VendorTypePurchase = 1 // 购物平台
|
||||
// VendorTypeDelivery = 2 // 快递平台
|
||||
// VendorTypePrinter = 3 // 网络打印机
|
||||
// VendorTypeOthers = 9 // 其它
|
||||
//
|
||||
// VendorIDUnknown = -1
|
||||
// VendorIDPurchaseBegin = 0
|
||||
// VendorIDJD = 0
|
||||
// VendorIDMTWM = 1
|
||||
// VendorIDPDD = 2 //拼多多
|
||||
// VendorIDEBAI = 3
|
||||
// VendorIDTB = 4 //淘宝
|
||||
// VendorIDJDShop = 5 //京东商城
|
||||
// VendorIDJX = 9 // 这是一个假的京西VendorID
|
||||
// VendorIDPurchaseEnd = 10
|
||||
// VendorIDOther = 999 //其他平台
|
||||
//
|
||||
// VendorIDWXPay = 51 // 微信支付
|
||||
//
|
||||
// VendorIDDeliveryBegin = 101
|
||||
// VendorIDDada = 101
|
||||
// VendorIDMTPS = 102
|
||||
// VendorIDFengNiao = 103
|
||||
// VendorIDJDWL = 401 //京东物流
|
||||
// VendorIDDeliveryEnd = 500
|
||||
//
|
||||
// VendorIDPrinterBegin = 201
|
||||
// VendorIDFeiE = 201 // 飞鹅打印机
|
||||
// VendorIDXiaoWM = 202 // 外卖管家打印机
|
||||
// VendorIDYiLianYun = 203 // 易联云
|
||||
// VendorIDZhongWu = 204 // 中午云打印
|
||||
// VendorIDPrinterEnd = 300
|
||||
//
|
||||
// VendorIDOthersBegin = 301
|
||||
//
|
||||
// VendorIDWXMP = 301 // 微信公众号
|
||||
// VendorIDWXQRCode = 302 // 微信扫码
|
||||
// VendorIDWXMini = 303 // 微信小程序
|
||||
//
|
||||
// VendorIDDDH5MicroApp = 311 // 钉钉H5微应用
|
||||
// VendorIDDDMobileQRCode = 312 // 钉钉移动接入应用(登录)
|
||||
//
|
||||
// VendorIDAutonavi = 321 // 高德导航
|
||||
// VendorIDQiNiuCloud = 323 // 七牛云
|
||||
// VendorIDShowAPI = 325 // 万维易源
|
||||
//)
|
||||
//
|
||||
//type VendorInfo struct {
|
||||
// Name string `json:"name"`
|
||||
//
|
||||
// OrgCodeName string `json:"orgCodeName"`
|
||||
// Value1Name string `json:"value1Name,omitempty"`
|
||||
// Value2Name string `json:"value2Name,omitempty"`
|
||||
// Value3Name string `json:"value3Name,omitempty"`
|
||||
// Value4Name string `json:"value4Name,omitempty"`
|
||||
// Value5Name string `json:"value5Name,omitempty"`
|
||||
//}
|
||||
//
|
||||
//var (
|
||||
// VendorNames = map[int]string{
|
||||
// VendorIDJD: "Jd",
|
||||
// VendorIDMTWM: "Mtwm",
|
||||
// VendorIDPDD: "Pdd",
|
||||
// VendorIDEBAI: "Ebai",
|
||||
// VendorIDTB: "Tb",
|
||||
// VendorIDJX: "Jx",
|
||||
// VendorIDJDShop: "Jds",
|
||||
//
|
||||
// VendorIDDada: "Dada",
|
||||
// VendorIDMTPS: "Mtps",
|
||||
//
|
||||
// VendorIDFeiE: "Feie",
|
||||
// VendorIDXiaoWM: "XiaoWM",
|
||||
// VendorIDYiLianYun: "Yilianyun",
|
||||
// VendorIDZhongWu: "ZhongWu",
|
||||
//
|
||||
// VendorIDQiNiuCloud: "Qiniu",
|
||||
// VendorIDJDWL: "Jdwl",
|
||||
// }
|
||||
//
|
||||
// VendorTypeName = map[int]string{
|
||||
// VendorTypeUnknown: "未知",
|
||||
// VendorTypePurchase: "购物平台",
|
||||
// VendorTypeDelivery: "快递平台",
|
||||
// VendorTypeOthers: "其它",
|
||||
// }
|
||||
//
|
||||
// VendorChineseNames = map[int]string{
|
||||
// VendorIDJD: "京东到家",
|
||||
// VendorIDMTWM: "美团外卖",
|
||||
// VendorIDPDD: "拼多多",
|
||||
// VendorIDEBAI: "饿百新零售",
|
||||
// VendorIDTB: "淘宝",
|
||||
// VendorIDJDShop: "京东商城",
|
||||
// VendorIDJX: "京西商城",
|
||||
// VendorIDOther: "其他平台",
|
||||
//
|
||||
// VendorIDDada: "达达众包",
|
||||
// VendorIDMTPS: "美团配送",
|
||||
// VendorIDJDWL: "京东物流",
|
||||
//
|
||||
// VendorIDFeiE: "飞鹅",
|
||||
// VendorIDXiaoWM: "外卖管家",
|
||||
// VendorIDYiLianYun: "易联云",
|
||||
// VendorIDZhongWu: "中午云",
|
||||
//
|
||||
// VendorIDWXMP: "微信公众号",
|
||||
// VendorIDWXQRCode: "微信扫码",
|
||||
// VendorIDWXMini: "微信小程序",
|
||||
//
|
||||
// VendorIDDDH5MicroApp: "钉钉H5微应用",
|
||||
// VendorIDDDMobileQRCode: "钉钉移动接入应用(登录)",
|
||||
//
|
||||
// VendorIDAutonavi: "高德导航",
|
||||
// VendorIDQiNiuCloud: "七牛云",
|
||||
// VendorIDShowAPI: "万维易源",
|
||||
// }
|
||||
//
|
||||
// VendorImg = map[int]string{
|
||||
// VendorIDJD: "http://image.jxc4.com/image/b1bd587d98e82ad6405132b8da67a1db.tem.png",
|
||||
// VendorIDMTWM: "http://image.jxc4.com/image/fb09e10a9c059aa6c133ff3e05c1dbbc.tem.png",
|
||||
// VendorIDEBAI: "http://image.jxc4.com/image/28e654c72a2bd92c5d09fdab475f6288.tem.png",
|
||||
// VendorIDJDShop: "http://image.jxc4.com/image/7c43ebbcbdbc0ef31fe028f680c0a7e3.tem.png",
|
||||
// VendorIDOther: "http://image.jxc4.com/image/558382ba95573b9537fbb209cadbd031.tem.png",
|
||||
// }
|
||||
//
|
||||
// VendorColors = map[int]string{
|
||||
// VendorIDJD: "#3CC518",
|
||||
// VendorIDMTWM: "#FFB14A",
|
||||
// VendorIDEBAI: "#E43428",
|
||||
// VendorIDJDShop: "#51A7FC",
|
||||
// }
|
||||
//
|
||||
// VendorInfoMap = map[int]*VendorInfo{
|
||||
// VendorIDJD: &VendorInfo{
|
||||
// Name: "京东到家",
|
||||
// OrgCodeName: "商户代码",
|
||||
// Value1Name: "AppKey",
|
||||
// Value2Name: "AppSecret",
|
||||
// Value3Name: "Token",
|
||||
// Value4Name: "管理后台Cookie",
|
||||
// },
|
||||
// VendorIDMTWM: &VendorInfo{
|
||||
// Name: "美团外卖",
|
||||
// OrgCodeName: "AppID",
|
||||
// Value1Name: "Secret",
|
||||
// Value2Name: "回调URL",
|
||||
// },
|
||||
// VendorIDEBAI: &VendorInfo{
|
||||
// Name: "饿百联盟",
|
||||
// OrgCodeName: "商户代码",
|
||||
// Value1Name: "Source",
|
||||
// Value2Name: "Secret",
|
||||
// Value3Name: "管理后台Cookie",
|
||||
// },
|
||||
//
|
||||
// // VendorIDDada: &VendorInfo{
|
||||
// // Name: "达达快递",
|
||||
// // OrgCodeName: "商户ID",
|
||||
// // Value1Name: "app_key",
|
||||
// // Value2Name: "app_secret",
|
||||
// // },
|
||||
// // VendorIDMTPS: &VendorInfo{
|
||||
// // Name: "美团配送",
|
||||
// // OrgCodeName: "自编码",
|
||||
// // Value1Name: "Appkey",
|
||||
// // Value2Name: "Secret",
|
||||
// // },
|
||||
//
|
||||
// // VendorIDFeiE: &VendorInfo{
|
||||
// // Name: "飞鹅",
|
||||
// // OrgCodeName: "User",
|
||||
// // Value1Name: "Key",
|
||||
// // },
|
||||
// // VendorIDXiaoWM: &VendorInfo{
|
||||
// // Name: "外卖管家",
|
||||
// // OrgCodeName: "AppID",
|
||||
// // Value1Name: "AppKey",
|
||||
// // },
|
||||
// // VendorIDYiLianYun: &VendorInfo{
|
||||
// // Name: "易联云",
|
||||
// // OrgCodeName: "ClientID",
|
||||
// // Value1Name: "ClientSecret",
|
||||
// // },
|
||||
// }
|
||||
//)
|
||||
//
|
||||
//func GetVendorMask(vendorIDs ...int) (vendorMask int) {
|
||||
// for _, vendorID := range vendorIDs {
|
||||
// vendorMask |= 1 << uint(vendorID)
|
||||
// }
|
||||
// return vendorMask
|
||||
//}
|
||||
//
|
||||
//func GetVendorType(vendorID int) (vendorType int) {
|
||||
// if vendorID >= VendorIDPurchaseBegin && VendorIDPurchaseBegin <= VendorIDPurchaseEnd {
|
||||
// return VendorTypePurchase
|
||||
// } else if vendorID >= VendorIDPurchaseBegin && VendorIDPurchaseBegin <= VendorIDPurchaseEnd {
|
||||
// return VendorTypeDelivery
|
||||
// } else if vendorID >= VendorIDOthersBegin {
|
||||
// return VendorTypeOthers
|
||||
// }
|
||||
// return VendorTypeUnknown
|
||||
//}
|
||||
//
|
||||
//type AppKeyConfig struct {
|
||||
// ModelIDCULD
|
||||
// VendorID int `json:"vendorID"`
|
||||
// VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空
|
||||
//
|
||||
// Name string `orm:"size(32)" json:"name"`
|
||||
// Value1 string `orm:"size(1024)" json:"value1"`
|
||||
// Value2 string `orm:"size(1024)" json:"value2"`
|
||||
// Value3 string `orm:"size(1024)" json:"value3"`
|
||||
// Value4 string `orm:"size(1024)" json:"value4"`
|
||||
// Value5 string `orm:"size(1024)" json:"value5"`
|
||||
//}
|
||||
//
|
||||
//func (a *AppKeyConfig) TableUnique() [][]string {
|
||||
// return [][]string{
|
||||
// []string{"VendorID", "VendorOrgCode", "DeletedAt"},
|
||||
// }
|
||||
//}
|
||||
12
business/model/app.go
Normal file
12
business/model/app.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package model
|
||||
|
||||
type Apps struct {
|
||||
ModelIDCULD
|
||||
|
||||
UserID string `orm:"column(user_id)" json:"user_id"` //属于哪个账号的
|
||||
Mobile string `json:"mobile"` //手机号
|
||||
Name string `json:"name"` //应用名称
|
||||
Type int `json:"type"` //应用类型
|
||||
AppKey string `json:"app_key"` //Key
|
||||
Status int `json:"status"` //状态
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
package model
|
||||
|
||||
const (
|
||||
BillTypeDeposit = 10 //发布任务
|
||||
BillTypeJob = 11 //做任务实得
|
||||
BillTypeJobCancelOverdue = 12 //任务过期或取消
|
||||
BillTypeJobAuditUnPassWithCancelOverdue = 13 //任务不通过时,任务已取消或过期
|
||||
BillTypeSpJob = 14 //特殊任务扣除
|
||||
BillTypeDivide = 15 //群员做任务分成
|
||||
BillTypeJobDivide = 16 //做任务实得(被扣除分成后)
|
||||
BillTypeDropShipping = 17 //一件代发订单扣除
|
||||
BillTypeDropShippingDeposit = 18 //一件代发保证金
|
||||
BillTypeUnionShare = 19 //联盟任务分成
|
||||
|
||||
BillTypeMember = 20 //开通会员
|
||||
|
||||
BillTypeQuitGroup = 30 //退群
|
||||
|
||||
BillTypeJdWaybillOverWeight = 40 //京东物流超重扣款
|
||||
|
||||
BillTypeCash = 8 //提现
|
||||
BillTypeInvest = 6 //充值
|
||||
)
|
||||
|
||||
var (
|
||||
BillTypeNames = map[int]string{
|
||||
BillTypeDeposit: "发布任务",
|
||||
BillTypeJob: "做任务实得",
|
||||
BillTypeJobCancelOverdue: "任务过期或取消",
|
||||
BillTypeJobAuditUnPassWithCancelOverdue: "任务不通过时,任务已取消或过期",
|
||||
BillTypeSpJob: "特殊任务扣除",
|
||||
BillTypeDivide: "群员做任务分成",
|
||||
BillTypeJobDivide: "做任务实得(被扣除分成后)",
|
||||
BillTypeDropShipping: "一件代发订单收入/扣除",
|
||||
BillTypeDropShippingDeposit: "一件代发保证金",
|
||||
BillTypeMember: "开通会员",
|
||||
BillTypeQuitGroup: "退群",
|
||||
BillTypeJdWaybillOverWeight: "京东物流超重扣款",
|
||||
BillTypeCash: "提现",
|
||||
BillTypeInvest: "充值",
|
||||
}
|
||||
)
|
||||
|
||||
//账单收入表
|
||||
type BillIncome struct {
|
||||
ModelIDCUL
|
||||
|
||||
BillID int64 `orm:"column(bill_id)" json:"billID"` //账单ID
|
||||
JobID int `orm:"column(job_id)" json:"jobID"` //任务ID
|
||||
Type int `json:"type"` //收入类型
|
||||
IncomePrice int `json:"incomePrice"` //收入金额
|
||||
}
|
||||
|
||||
func (v *BillIncome) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"BillID"},
|
||||
[]string{"CreatedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
//账单支出表
|
||||
type BillExpend struct {
|
||||
ModelIDCUL
|
||||
|
||||
BillID int64 `orm:"column(bill_id)" json:"billID"` //账单ID
|
||||
JobID int `orm:"column(job_id)" json:"jobID"` //任务ID
|
||||
Type int `json:"type"` //支出类型
|
||||
ExpendPrice int `json:"expendPrice"` //支出金额
|
||||
}
|
||||
|
||||
func (v *BillExpend) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"BillID"},
|
||||
[]string{"CreatedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
//用户账单表
|
||||
type UserBill struct {
|
||||
ModelIDCULD
|
||||
|
||||
BillID int64 `orm:"column(bill_id)" json:"billID"` //账单ID
|
||||
UserID string `orm:"column(user_id)" json:"userID"` //用户ID
|
||||
AccountBalance int `json:"accountBalance"` //账户余额
|
||||
}
|
||||
|
||||
func (v *UserBill) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"UserID"},
|
||||
}
|
||||
}
|
||||
|
||||
func (v *UserBill) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"BillID"},
|
||||
[]string{"CreatedAt"},
|
||||
[]string{"AccountBalance"},
|
||||
}
|
||||
}
|
||||
|
||||
type UnionOrderSettle struct {
|
||||
ModelIDCUL
|
||||
|
||||
BillID int64 `orm:"column(bill_id)" json:"billID"` //账单ID
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"` //平台ID
|
||||
Issue int `json:"issue"` //期数
|
||||
EarningPrice int `json:"earningPrice"` //结算金额
|
||||
OrderCount int `json:"orderCount"` //当期有效推广订单数量
|
||||
Comment string `json:"comment"` //备注
|
||||
}
|
||||
|
||||
func (v *UnionOrderSettle) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"BillID", "VendorID", "Issue"},
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package model
|
||||
|
||||
type CasbinRule struct {
|
||||
ID int `orm:"column(id)" json:"id"`
|
||||
PType string
|
||||
V0 string `orm:"index"`
|
||||
V1 string `orm:"index"`
|
||||
V2 string
|
||||
V3 string
|
||||
V4 string
|
||||
V5 string
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -25,12 +22,14 @@ var (
|
||||
},
|
||||
}
|
||||
|
||||
ShopChineseNames = map[int]string{
|
||||
VendorIDJD: globals.StoreName,
|
||||
VendorIDMTWM: globals.StoreNameMtwm,
|
||||
VendorIDEBAI: globals.StoreNameEbai,
|
||||
VendorIDJX: fmt.Sprintf("%s商城", globals.StoreName),
|
||||
}
|
||||
//ShopChineseNames = map[int]string{
|
||||
// VendorIDJD: globals.StoreName,
|
||||
// VendorIDMTWM: globals.StoreNameMtwm,
|
||||
// VendorIDELM: globals.StoreNameEbai,
|
||||
// VendorIDEBAI: globals.StoreNameEbai,
|
||||
// VendorIDJX: fmt.Sprintf("%s商城", globals.StoreName),
|
||||
// VendorIDWSC: "微盟微商城",
|
||||
//}
|
||||
|
||||
OrderStatusName = map[int]string{
|
||||
OrderStatusMsg: "通知消息",
|
||||
@@ -75,6 +74,7 @@ var (
|
||||
WaybillStatusPending: "压单",
|
||||
WaybillStatusAcceptCanceled: "取消接受",
|
||||
WaybillStatusAccepted: "已接单",
|
||||
WaybillStatusCourierAssigned: "已分配骑手",
|
||||
WaybillStatusCourierArrived: "已到店",
|
||||
WaybillStatusApplyFailedGetGoods: "取货失败待审核",
|
||||
WaybillStatusAgreeFailedGetGoods: "取货失败",
|
||||
@@ -90,15 +90,6 @@ var (
|
||||
OrderTypeAfsOrder: "售后单",
|
||||
}
|
||||
|
||||
UnionOrderStatusName = map[int]string{
|
||||
UnionOrderStatusNew: "新订单",
|
||||
UnionOrderStatusPay: "用户已支付",
|
||||
UnionOrderStatusTakeOver: "用户已确认收货",
|
||||
UnionOrderStatusAuditOver: "已审核",
|
||||
UnionOrderStatusFinish: "已完成(已结算)",
|
||||
UnionOrderStatusFail: "已退款(结算失败)",
|
||||
}
|
||||
|
||||
ComplaintReasons = map[int]string{
|
||||
ComplaintReasons1: "骑手态度恶劣",
|
||||
ComplaintReasons2: "骑手接单后未取货",
|
||||
@@ -123,6 +114,13 @@ var (
|
||||
// OperateCopyStoreSkus: "复制门店商品",
|
||||
}
|
||||
|
||||
//ThingTypeName = map[int]string{
|
||||
// ThingTypeCategory: "分类",
|
||||
// ThingTypeSku: "门店商品",
|
||||
// ThingTypeSkuName: "商品库",
|
||||
// ThingTypeStore: "门店",
|
||||
//}
|
||||
|
||||
ApiFunctionName = map[string]string{
|
||||
"UpdateStoresSkus": "门店商品管理",
|
||||
"UpdateStoresSkusSale": "门店商品可售状态修改",
|
||||
@@ -148,6 +146,7 @@ var (
|
||||
MultiStoresVendorMap = map[int]int{
|
||||
VendorIDJD: 1,
|
||||
VendorIDMTWM: 0,
|
||||
VendorIDELM: 0,
|
||||
VendorIDEBAI: 0,
|
||||
}
|
||||
|
||||
@@ -181,6 +180,11 @@ var (
|
||||
"打印机ID",
|
||||
"打印机密钥",
|
||||
},
|
||||
VendorIDJxprint: []string{
|
||||
VendorChineseNames[VendorIDJxprint],
|
||||
"打印机编号",
|
||||
"不填",
|
||||
},
|
||||
}
|
||||
AfsReasonTypeName = map[int]string{
|
||||
AfsReasonTypeGoodsQuality: "商品质量",
|
||||
@@ -204,14 +208,27 @@ var (
|
||||
0: "休息",
|
||||
1: "营业",
|
||||
}
|
||||
JobLimitCountType = map[int]string{
|
||||
JobLimitCountTypePO: "每人一次",
|
||||
JobLimitCountTypePDO: "每人一天一次",
|
||||
JobLimitCountTypePWO: "每人一周一次",
|
||||
JobLimitCountTypeNoLimit: "不限次",
|
||||
|
||||
UnionOrderStatusName = map[int]string{
|
||||
UnionOrderStatusNew: "新订单",
|
||||
UnionOrderStatusPay: "用户已支付",
|
||||
UnionOrderStatusTakeOver: "用户已确认收货",
|
||||
UnionOrderStatusAuditOver: "已审核",
|
||||
UnionOrderStatusFinish: "已完成(已结算)",
|
||||
UnionOrderStatusFail: "已退款(结算失败)",
|
||||
}
|
||||
)
|
||||
|
||||
//联盟订单状态
|
||||
const (
|
||||
UnionOrderStatusNew = 10 //已领券?还未支付
|
||||
UnionOrderStatusPay = 15 //已支付
|
||||
UnionOrderStatusTakeOver = 20 //确认收货,已收到货
|
||||
UnionOrderStatusAuditOver = 25 //审核成功,待结算
|
||||
UnionOrderStatusFinish = 110 //已结算
|
||||
UnionOrderStatusFail = 115 //审核失败,结算失败
|
||||
)
|
||||
|
||||
const (
|
||||
OrderTypeOrder = 1
|
||||
OrderTypeWaybill = 2
|
||||
@@ -266,10 +283,12 @@ const (
|
||||
|
||||
OrderStatusEndBegin = 100 // 以下的状态就是结束状态
|
||||
OrderStatusFinished = 110 // 订单已完成
|
||||
OrderStatusConfirm = 112 //一件代发订单确认收货
|
||||
OrderStatusCanceled = 115 // 订单已取消
|
||||
OrderStatusEndEnd = 120
|
||||
|
||||
OrderStatusRejection = 132 // 客户拒收
|
||||
OrderStatusCustomerService = 131 // 客服退款
|
||||
|
||||
AfsOrderStatusWait4Approve = 155 // 待审核售后单
|
||||
AfsOrderStatusNew = 160 // 已审核或不需要审核售后单
|
||||
AfsOrderStatusWait4ReceiveGoods = 165 // 退款退货的,需要商家确认收到货
|
||||
@@ -278,15 +297,19 @@ const (
|
||||
AfsOrderStatusFailed = 190 // 售后单失败
|
||||
)
|
||||
|
||||
//联盟订单状态
|
||||
const (
|
||||
UnionOrderStatusNew = 10 //已领券?还未支付
|
||||
UnionOrderStatusPay = 15 //已支付
|
||||
UnionOrderStatusTakeOver = 20 //确认收货,已收到货
|
||||
UnionOrderStatusAuditOver = 25 //审核成功,待结算
|
||||
ApplyOrderCancel = 140 // 申请取消
|
||||
ApplyOrderRefund = 130 // 申请退款
|
||||
ApplyOrderRefundGoods = 150 // 申请退款
|
||||
UserInStoreConsultingService = 160 // 进店咨询
|
||||
BusinessCancelOrder = 170 // 商家取消打印
|
||||
CancelOrderSuccess = 170 // 取消成功打印
|
||||
OrderRefundMoneySuccess = 180 // 退款成功打印
|
||||
)
|
||||
|
||||
UnionOrderStatusFinish = 110 //已结算
|
||||
UnionOrderStatusFail = 115 //审核失败,结算失败
|
||||
const (
|
||||
LockStatusUnlocked = 0
|
||||
LockStatusLocked = 1
|
||||
)
|
||||
|
||||
//投诉原因
|
||||
@@ -318,17 +341,20 @@ const (
|
||||
WaybillStatusRefuseFailedGetGoods = -70
|
||||
WaybillStatusUnknown = 0
|
||||
|
||||
WaybillStatusNew = 5
|
||||
WaybillStatusPending = 7
|
||||
WaybillStatusAcceptCanceled = 8
|
||||
WaybillStatusAccepted = 10
|
||||
WaybillStatusCourierArrived = 15 // 此状态是可选的,明确写出来是因为还是较重要的状态,但业务逻辑不应依赖此状态
|
||||
WaybillStatusNew = 5 // 新建订单
|
||||
WaybillStatusPending = 7 //
|
||||
WaybillStatusAcceptCanceled = 8 // 取消运单
|
||||
WaybillStatusAccepted = 10 // 分配骑手,正在接单
|
||||
WaybillStatusCourierAssigned = 12 //已分配骑手
|
||||
WaybillStatusCourierArrived = 15 // 此状态是可选的,明确写出来是因为还是较重要的状态,但业务逻辑不应依赖此状态
|
||||
|
||||
WaybillStatusApplyFailedGetGoods = 17 // 取货失败待审核
|
||||
WaybillStatusAgreeFailedGetGoods = 18 // 取货失败
|
||||
|
||||
WaybillStatusDelivering = 20
|
||||
WaybillStatusDeliverFailed = 22
|
||||
WaybillStatusDelivering = 20 // 配送中
|
||||
WaybillStatusDeliverFailed = 22 // 配送中失败
|
||||
|
||||
WaybillStatusDeliverReminder = 30 // 催单
|
||||
|
||||
WaybillStatusEndBegin = 100 // 以下的状态就是结束状态
|
||||
WaybillStatusDelivered = 105 // todo 这个应该改为110,与订单对应
|
||||
@@ -337,6 +363,11 @@ const (
|
||||
WaybillStatusEndEnd = 120
|
||||
)
|
||||
|
||||
const (
|
||||
BusinessTypeImmediate = 1
|
||||
BusinessTypeDingshida = 2
|
||||
)
|
||||
|
||||
var (
|
||||
ElmSkuPromotion = map[int]int{
|
||||
11: 1,
|
||||
@@ -344,6 +375,52 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
JdPlatformFeeRate = 10
|
||||
MtPlatformFeeRate = 10
|
||||
)
|
||||
|
||||
const (
|
||||
OrderDeliveryFlagMaskScheduleDisabled = 1 // 禁止三方配送调度
|
||||
OrderDeliveryFlagMaskPurcahseDisabled = 2 // 购物平台已不配送(一般为门店配送类型本身为自配送,或已经转自配送)
|
||||
|
||||
OrderDeliveryFlagMaskAutoPickup = 4 // 是否是自动拣货的
|
||||
|
||||
OrderDeliveryFlagMaskDada = 16 // 创建达达运单中
|
||||
OrderDeliveryFlagMaskMtps = 32 // 创建美团配送运单中
|
||||
)
|
||||
|
||||
const (
|
||||
WaybillDeliveryFlagMaskActiveCancel = 1 // 主动取消
|
||||
)
|
||||
|
||||
const (
|
||||
OrderFlagMaskPrinted = 1 // 已经打印
|
||||
|
||||
OrderFlagMaskUserApplyCancel = 6
|
||||
OrderFlagAgreeUserApplyCancel = 2
|
||||
OrderFlagRefuseUserApplyCancel = 6
|
||||
|
||||
OrderFlagMaskFailedGetGoods = 24
|
||||
OrderFlagAgreeFailedGetGoods = 8
|
||||
OrderFlagRefuseFailedGetGoods = 24
|
||||
|
||||
OrderFlagMaskFailedDeliver = 32
|
||||
OrderFlagMaskCallPMCourier = 64 // 取货失败后召唤平台配送
|
||||
OrderFlagMaskSetDelivered = 128 // 设置送达
|
||||
|
||||
OrderFlagMaskFake = 256 // 假订单,即刷单用的
|
||||
OrderFlagMaskTempJX = 512 // 临时京西订单
|
||||
)
|
||||
|
||||
const (
|
||||
AfsOrderFlagMaskUserRefund = 3 // 门店处理售后单申请
|
||||
AfsOrderFlagAgreeUserRefund = 1 // 门店同意售后单申请
|
||||
AfsOrderFlagRefuseUserRefund = 3 // 门店拒绝售后单申请
|
||||
|
||||
AfsOrderFlagMaskReturnGoods = 4 // 门店确认收到退货
|
||||
)
|
||||
|
||||
const (
|
||||
AfsAppealTypeRefund = 1 // 仅退款
|
||||
AfsAppealTypeReturnAndRefund = 2 // 退货退款
|
||||
@@ -364,6 +441,12 @@ const (
|
||||
AfsReasonNotOthers = 0 // 其它
|
||||
)
|
||||
|
||||
const (
|
||||
AfsTypeUnknown = 0 // 未知
|
||||
AfsTypePartRefund = 1 // 部分退款
|
||||
AfsTypeFullRefund = 2 // 全额退款
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultEarningPricePercentage = 70 // 门店缺省结算百分比
|
||||
|
||||
@@ -373,11 +456,39 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
YES = 1 //通用
|
||||
NO = 0
|
||||
DISABLED = -1
|
||||
YES = 1 //通用
|
||||
NO = 0
|
||||
DISABLED = -1
|
||||
B2BTag = "B2B"
|
||||
B2BNumberId = 10
|
||||
)
|
||||
|
||||
const (
|
||||
WeChatQrCode = "weChat"
|
||||
TiktokQrCode = "tiktok"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultName = "石锋"
|
||||
DefaultPhone = "18048531223"
|
||||
DefaultIdCard = "610126198012230014"
|
||||
)
|
||||
|
||||
func IsPurchaseVendorExist(vendorID int) bool {
|
||||
_, ok := VendorNames[vendorID]
|
||||
return ok && vendorID >= VendorIDPurchaseBegin && vendorID <= VendorIDPurchaseEnd
|
||||
}
|
||||
|
||||
func IsDeliveryVendorExist(vendorID int) bool {
|
||||
_, ok := VendorNames[vendorID]
|
||||
return ok && vendorID >= VendorIDDeliveryBegin && vendorID <= VendorIDDeliveryEnd
|
||||
}
|
||||
|
||||
func IsPrinterVendorExist(vendorID int) bool {
|
||||
_, ok := VendorNames[vendorID]
|
||||
return ok && vendorID >= VendorIDPrinterBegin && vendorID <= VendorIDPrinterEnd
|
||||
}
|
||||
|
||||
func IsOrderLockStatus(status int) bool {
|
||||
return status == OrderStatusLocked || status == OrderStatusApplyCancel
|
||||
}
|
||||
@@ -402,6 +513,15 @@ func IsVendorRemote(vendorID int) bool {
|
||||
return vendorID >= VendorIDJD && vendorID <= VendorIDEBAI
|
||||
}
|
||||
|
||||
func WaybillVendorID2Mask(vendorID int) (mask int8) {
|
||||
if vendorID == VendorIDDada {
|
||||
mask = OrderDeliveryFlagMaskDada
|
||||
} else if vendorID == VendorIDMTPS {
|
||||
mask = OrderDeliveryFlagMaskMtps
|
||||
}
|
||||
return mask
|
||||
}
|
||||
|
||||
func IsAfsOrderFinalStatus(status int) bool {
|
||||
return status >= AfsOrderStatusFinished && status <= AfsOrderStatusFailed
|
||||
}
|
||||
@@ -409,3 +529,405 @@ func IsAfsOrderFinalStatus(status int) bool {
|
||||
func IsWaybillFinalStatus(status int) bool {
|
||||
return status >= WaybillStatusEndBegin && status <= WaybillStatusEndEnd
|
||||
}
|
||||
|
||||
const (
|
||||
JXC4AppId = "wx4b5930c13f8b1170" // 京西菜市appId
|
||||
JXC4BusinessAppId = "wx08a5c2a8581414ff" // 京西商家appId
|
||||
JXC4TiktokAppId = "tta6a1d01c399f264201" // 抖音appID
|
||||
)
|
||||
|
||||
//package model
|
||||
//
|
||||
//import (
|
||||
// "git.rosy.net.cn/baseapi/platformapi/ebaiapi"
|
||||
// "git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
// "git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||
//)
|
||||
//
|
||||
//var (
|
||||
// PurchaseVendorInfo = map[int]map[string]interface{}{
|
||||
// VendorIDJD: map[string]interface{}{
|
||||
// "chineseName": VendorChineseNames[VendorIDJD],
|
||||
// "userApplyCancelWaitMinute": jdapi.UserApplyCancelWaitMinute,
|
||||
// },
|
||||
// VendorIDMTWM: map[string]interface{}{
|
||||
// "chineseName": VendorChineseNames[VendorIDMTWM],
|
||||
// "userApplyCancelWaitMinute": mtwmapi.UserApplyCancelWaitMinute,
|
||||
// },
|
||||
// VendorIDEBAI: map[string]interface{}{
|
||||
// "chineseName": VendorChineseNames[VendorIDEBAI],
|
||||
// "userApplyCancelWaitMinute": ebaiapi.UserApplyCancelWaitMinute,
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// OrderStatusName = map[int]string{
|
||||
// OrderStatusMsg: "通知消息",
|
||||
// OrderStatusWaybillTipChanged: "小费变动",
|
||||
// OrderStatusRefuseFailedGetGoods: "取货失败审核驳回",
|
||||
// OrderStatusAdjust: "订单调整完成",
|
||||
// OrderStatusApplyUrgeOrder: "催单",
|
||||
//
|
||||
// OrderStatusUnlocked: "解锁",
|
||||
// OrderStatusLocked: "锁定",
|
||||
// // OrderStatusApplyRefund: "申请退款",
|
||||
// OrderStatusUndoApplyCancel: "取消申请取消",
|
||||
// OrderStatusVendorRejectCancel: "拒绝取消",
|
||||
// OrderStatusVendorAgreeCancel: "同意取消",
|
||||
// OrderStatusApplyCancel: "申请取消",
|
||||
//
|
||||
// OrderStatusUnknown: "一般事件",
|
||||
//
|
||||
// OrderStatusWait4Pay: "待付款",
|
||||
// OrderStatusNew: "新订单",
|
||||
// OrderStatusWaitAccepted: "待接单",
|
||||
// OrderStatusAccepted: "待拣货",
|
||||
// OrderStatusFinishedPickup: "待配送",
|
||||
// OrderStatusApplyFailedGetGoods: "取货失败待审核",
|
||||
// OrderStatusAgreeFailedGetGoods: "取货失败",
|
||||
// OrderStatusDelivering: "配送中",
|
||||
// OrderStatusDeliverFailed: "投递失败",
|
||||
// OrderStatusFinished: "完成",
|
||||
// OrderStatusCanceled: "取消",
|
||||
//
|
||||
// AfsOrderStatusWait4Approve: "待审核",
|
||||
// AfsOrderStatusNew: "已审核",
|
||||
// AfsOrderStatusWait4ReceiveGoods: "退货待确认",
|
||||
// AfsOrderStatusReceivedGoods: "退货已收到",
|
||||
// AfsOrderStatusFinished: "售后成功",
|
||||
// AfsOrderStatusFailed: "售后失败",
|
||||
// }
|
||||
// WaybillStatusName = map[int]string{
|
||||
// WaybillStatusUnknown: "一般事件",
|
||||
//
|
||||
// WaybillStatusNew: "新运单",
|
||||
// WaybillStatusPending: "压单",
|
||||
// WaybillStatusAcceptCanceled: "取消接受",
|
||||
// WaybillStatusAccepted: "已接单",
|
||||
// WaybillStatusCourierArrived: "已到店",
|
||||
// WaybillStatusApplyFailedGetGoods: "取货失败待审核",
|
||||
// WaybillStatusAgreeFailedGetGoods: "取货失败",
|
||||
// WaybillStatusDelivering: "配送中",
|
||||
// WaybillStatusDeliverFailed: "投递失败",
|
||||
// WaybillStatusDelivered: "送达",
|
||||
// WaybillStatusCanceled: "取消",
|
||||
// WaybillStatusFailed: "失败",
|
||||
// }
|
||||
// OrderTypeName = map[int]string{
|
||||
// OrderTypeOrder: "订单",
|
||||
// OrderTypeWaybill: "运单",
|
||||
// OrderTypeAfsOrder: "售后单",
|
||||
// }
|
||||
//
|
||||
// UnionOrderStatusName = map[int]string{
|
||||
// UnionOrderStatusNew: "新订单",
|
||||
// UnionOrderStatusPay: "用户已支付",
|
||||
// UnionOrderStatusTakeOver: "用户已确认收货",
|
||||
// UnionOrderStatusAuditOver: "已审核",
|
||||
// UnionOrderStatusFinish: "已完成(已结算)",
|
||||
// UnionOrderStatusFail: "已退款(结算失败)",
|
||||
// }
|
||||
//
|
||||
// ComplaintReasons = map[int]string{
|
||||
// ComplaintReasons1: "骑手态度恶劣",
|
||||
// ComplaintReasons2: "骑手接单后未取货",
|
||||
// ComplaintReasons3: "骑手取货太慢",
|
||||
// ComplaintReasons4: "骑手送货太慢",
|
||||
// ComplaintReasons5: "货品未送达",
|
||||
// ComplaintReasons6: "货品有损坏",
|
||||
// ComplaintReasons7: "骑手违规收取顾客其他费用",
|
||||
// ComplaintReasons69: "骑手恶意取消订单",
|
||||
// ComplaintReasons71: "骑手提前点击取货/送达",
|
||||
// }
|
||||
//
|
||||
// SupplementTypeName = map[int]string{
|
||||
// BadAppraiseSupplement: "差评退款",
|
||||
// Coupon: "优惠券",
|
||||
// }
|
||||
//
|
||||
// OperateTypeName = map[int]string{
|
||||
// OperateAdd: "新增",
|
||||
// OperateUpdate: "修改",
|
||||
// OperateDelete: "删除",
|
||||
// // OperateCopyStoreSkus: "复制门店商品",
|
||||
// }
|
||||
//
|
||||
// ApiFunctionName = map[string]string{
|
||||
// "UpdateStoresSkus": "门店商品管理",
|
||||
// "UpdateStoresSkusSale": "门店商品可售状态修改",
|
||||
// "CopyStoreSkus": "京西门店商品复制到京西",
|
||||
// "UpdateStore": "门店管理-更新门店信息",
|
||||
// "CreateStore": "门店管理-创建门店",
|
||||
// "DeleteStore": "门店管理-删除门店",
|
||||
// "DeleteStoreVendorMap": "门店解绑",
|
||||
// "AddStoreVendorMap": "门店绑定",
|
||||
// "UpdateStoreVendorMap": "门店修改平台绑定信息",
|
||||
// "DeleteStoreCourierMap": "门店解绑三方配送平台",
|
||||
// "AddStoreCourierMap": "门店绑定三方配送平台",
|
||||
// "UpdateStoreCourierMap": "门店修改三方配送平台绑定信息",
|
||||
// "Login": "登录",
|
||||
// "RegisterUser": "注册",
|
||||
// "AutoPayForPopluarMan": "每日订单打款",
|
||||
// "SyncStoresQualify": "上传门店营业资质",
|
||||
// "CancelOrder": "取消订单",
|
||||
// "UpdateSku": "修改sku",
|
||||
// "UpdateSkuName": "修改skuName",
|
||||
// }
|
||||
//
|
||||
// MultiStoresVendorMap = map[int]int{
|
||||
// VendorIDJD: 1,
|
||||
// VendorIDMTWM: 0,
|
||||
// VendorIDEBAI: 0,
|
||||
// }
|
||||
//
|
||||
// ZXCityCodeMap = map[int]string{
|
||||
// 310100: "上海市",
|
||||
// 110100: "北京市",
|
||||
// 120100: "天津市",
|
||||
// 440300: "深圳市",
|
||||
// 500100: "重庆市",
|
||||
// 441900: "东莞",
|
||||
// }
|
||||
//
|
||||
// PrinterVendorInfo = map[int][]string{
|
||||
// VendorIDFeiE: []string{
|
||||
// VendorChineseNames[VendorIDFeiE],
|
||||
// "序列号",
|
||||
// "KEY",
|
||||
// },
|
||||
// VendorIDXiaoWM: []string{
|
||||
// VendorChineseNames[VendorIDXiaoWM],
|
||||
// "打印机编号",
|
||||
// "不填",
|
||||
// },
|
||||
// VendorIDYiLianYun: []string{
|
||||
// VendorChineseNames[VendorIDYiLianYun],
|
||||
// "终端号",
|
||||
// "密钥",
|
||||
// },
|
||||
// VendorIDZhongWu: []string{
|
||||
// VendorChineseNames[VendorIDZhongWu],
|
||||
// "打印机ID",
|
||||
// "打印机密钥",
|
||||
// },
|
||||
// }
|
||||
// AfsReasonTypeName = map[int]string{
|
||||
// AfsReasonTypeGoodsQuality: "商品质量",
|
||||
// AfsReasonTypeWrongGoods: "错误的商品",
|
||||
// AfsReasonTypeMissingGoods: "缺少部分商品",
|
||||
// AfsReasonTypeNoGoods: "全部商品未收到",
|
||||
// AfsReasonTypeDamagedGoods: "商品有损伤",
|
||||
// AfsReasonTypeGoodsQuantity: "缺斤少两",
|
||||
// AfsReasonTypeGoodsAbsent: "商家通知我缺货",
|
||||
// AfsReasonTypeGoodsNoSame: "商品与描述不符",
|
||||
// AfsReasonWrongPurchase: "误购",
|
||||
// AfsReasonNotReceivedIntime: "未在时效内送达",
|
||||
// AfsReasonNotOthers: "其它",
|
||||
// }
|
||||
// AfsAppealTypeName = map[int]string{
|
||||
// AfsAppealTypeRefund: "仅退款",
|
||||
// AfsAppealTypeReturnAndRefund: "退款", // 这个其实是退货退款,强制显示成退款
|
||||
// AfsAppealTypeNewGoods: "退款.", // 这个其实是重发商品,强制显示成退款
|
||||
// }
|
||||
// VendorStatus = map[int]string{
|
||||
// 0: "休息",
|
||||
// 1: "营业",
|
||||
// }
|
||||
//)
|
||||
//
|
||||
//const (
|
||||
// OrderTypeOrder = 1
|
||||
// OrderTypeWaybill = 2
|
||||
// OrderTypeAfsOrder = 3
|
||||
//)
|
||||
//
|
||||
//// https://blog.csdn.net/a13570320979/article/details/51366355
|
||||
//// 美团配送:
|
||||
//// 坐标类型,0:火星坐标(高德,腾讯地图均采用火星坐标) 1:百度坐标 (默认值为0)
|
||||
//// 京东:
|
||||
//// 收货人地址定位类型(buyerCoordType值为空或为1时,定位类型为gps,如为其他值时,定位类型为非gps类型。)
|
||||
//// 饿了么:
|
||||
//// 只支持高德坐标
|
||||
//// 达达:
|
||||
//// 只支持高德坐标
|
||||
//// 如下定义与美团配送兼容
|
||||
//const (
|
||||
// CoordinateTypeMars = 0 // 火星坐标,高德坐标,GCJ-02坐标系
|
||||
// CoordinateTypeBaiDu = 1 // 百度坐标,bd-09,在GCJ-02坐标系上再次偏移加密的坐标
|
||||
// CoordinateTypeMapbar = 2
|
||||
// CoordinateTypeGPS = 84 // 真实坐标,WGS-84原始坐标系
|
||||
//)
|
||||
//
|
||||
//const (
|
||||
// OrderStatusMsg = -100
|
||||
//
|
||||
// OrderStatusWaybillTipChanged = -80 // 订单小费变化
|
||||
//
|
||||
// OrderStatusRefuseFailedGetGoods = -70 // 取货失败审核驳回
|
||||
// OrderStatusAdjust = -65 // 原值-35 订单调整完成
|
||||
// OrderStatusApplyUrgeOrder = -55 // 原值-15
|
||||
//
|
||||
// OrderStatusUnlocked = -25
|
||||
// OrderStatusLocked = -20
|
||||
// OrderStatusUndoApplyCancel = -10
|
||||
// OrderStatusVendorRejectCancel = -7
|
||||
// OrderStatusVendorAgreeCancel = -6
|
||||
// OrderStatusApplyCancel = -5
|
||||
//
|
||||
// OrderStatusUnknown = 0
|
||||
// OrderStatusWait4Pay = 2 // 原值-60 下单待支付
|
||||
// OrderStatusWaitAccepted = 3 // 待接单,目前饿百用
|
||||
// OrderStatusNew = 5 // 新订单,实际是已经支付
|
||||
// OrderStatusAccepted = 10 // 已经接单,也即待出库,待拣货
|
||||
// OrderStatusFinishedPickup = 15 // 拣货完成
|
||||
//
|
||||
// OrderStatusApplyFailedGetGoods = 17 // 取货失败待审核
|
||||
// OrderStatusAgreeFailedGetGoods = 18 // 取货失败
|
||||
//
|
||||
// OrderStatusDelivering = 20 // 开始配送,配送员已取货,从这里开始就是运单消息了
|
||||
// OrderStatusDeliverFailed = 22 // 投递失败
|
||||
//
|
||||
// OrderStatusEndBegin = 100 // 以下的状态就是结束状态
|
||||
// OrderStatusFinished = 110 // 订单已完成
|
||||
// OrderStatusConfirm = 112 //一件代发订单确认收货
|
||||
// OrderStatusCanceled = 115 // 订单已取消
|
||||
// OrderStatusEndEnd = 120
|
||||
//
|
||||
// AfsOrderStatusWait4Approve = 155 // 待审核售后单
|
||||
// AfsOrderStatusNew = 160 // 已审核或不需要审核售后单
|
||||
// AfsOrderStatusWait4ReceiveGoods = 165 // 退款退货的,需要商家确认收到货
|
||||
// AfsOrderStatusReceivedGoods = 167 // 已确认收到货
|
||||
// AfsOrderStatusFinished = 180 // 售后单成功完成
|
||||
// AfsOrderStatusFailed = 190 // 售后单失败
|
||||
//)
|
||||
//
|
||||
////联盟订单状态
|
||||
//const (
|
||||
// UnionOrderStatusNew = 10 //已领券?还未支付
|
||||
// UnionOrderStatusPay = 15 //已支付
|
||||
// UnionOrderStatusTakeOver = 20 //确认收货,已收到货
|
||||
// UnionOrderStatusAuditOver = 25 //审核成功,待结算
|
||||
//
|
||||
// UnionOrderStatusFinish = 110 //已结算
|
||||
// UnionOrderStatusFail = 115 //审核失败,结算失败
|
||||
//)
|
||||
//
|
||||
////投诉原因
|
||||
//const (
|
||||
// ComplaintReasons1 = 1 //"骑手态度恶劣",
|
||||
// ComplaintReasons2 = 2 //"骑手接单后未取货"
|
||||
// ComplaintReasons3 = 3 //"骑手取货太慢",
|
||||
// ComplaintReasons4 = 4 //"骑手送货太慢",
|
||||
// ComplaintReasons5 = 5 //"货品未送达",
|
||||
// ComplaintReasons6 = 6 //"货品有损坏",
|
||||
// ComplaintReasons7 = 7 //"骑手违规收取顾客其他费用",
|
||||
// ComplaintReasons69 = 69 //"骑手恶意取消订单",
|
||||
// ComplaintReasons71 = 71 //"骑手提前点击取货/送达",
|
||||
//)
|
||||
//
|
||||
//const (
|
||||
// BadAppraiseSupplement = 1 //差评退款
|
||||
// Coupon = 2 //优惠券
|
||||
//)
|
||||
//
|
||||
//const (
|
||||
// OperateAdd = 2 //新增操作
|
||||
// OperateUpdate = 1 //修改操作
|
||||
// OperateDelete = 4 //删除操作
|
||||
// OperateCopyStoreSkus = 3 //复制门店商品
|
||||
//)
|
||||
//
|
||||
//const (
|
||||
// WaybillStatusRefuseFailedGetGoods = -70
|
||||
// WaybillStatusUnknown = 0
|
||||
//
|
||||
// WaybillStatusNew = 5
|
||||
// WaybillStatusPending = 7
|
||||
// WaybillStatusAcceptCanceled = 8
|
||||
// WaybillStatusAccepted = 10
|
||||
// WaybillStatusCourierArrived = 15 // 此状态是可选的,明确写出来是因为还是较重要的状态,但业务逻辑不应依赖此状态
|
||||
//
|
||||
// WaybillStatusApplyFailedGetGoods = 17 // 取货失败待审核
|
||||
// WaybillStatusAgreeFailedGetGoods = 18 // 取货失败
|
||||
//
|
||||
// WaybillStatusDelivering = 20
|
||||
// WaybillStatusDeliverFailed = 22
|
||||
//
|
||||
// WaybillStatusEndBegin = 100 // 以下的状态就是结束状态
|
||||
// WaybillStatusDelivered = 105 // todo 这个应该改为110,与订单对应
|
||||
// WaybillStatusCanceled = 115
|
||||
// WaybillStatusFailed = 120 // 这个状态存在的意义是区分于WaybillStatusCanceled,比如达达平台在这种状态下再次创建运单的方式不一样
|
||||
// WaybillStatusEndEnd = 120
|
||||
//)
|
||||
//
|
||||
//var (
|
||||
// ElmSkuPromotion = map[int]int{
|
||||
// 11: 1,
|
||||
// 200: 1,
|
||||
// }
|
||||
//)
|
||||
//
|
||||
//const (
|
||||
// AfsAppealTypeRefund = 1 // 仅退款
|
||||
// AfsAppealTypeReturnAndRefund = 2 // 退货退款
|
||||
// AfsAppealTypeNewGoods = 3 // 重发新商品(即京东到家的直赔)
|
||||
//)
|
||||
//
|
||||
//const (
|
||||
// AfsReasonTypeGoodsQuality = 1 // 商品质量
|
||||
// AfsReasonTypeWrongGoods = 2 // 错误的商品
|
||||
// AfsReasonTypeMissingGoods = 3 // 缺少部分商品
|
||||
// AfsReasonTypeNoGoods = 4 // 全部商品未收到
|
||||
// AfsReasonTypeDamagedGoods = 5 // 商品有损伤
|
||||
// AfsReasonTypeGoodsQuantity = 6 // 缺斤少两
|
||||
// AfsReasonTypeGoodsAbsent = 7 // 商家通知缺货
|
||||
// AfsReasonTypeGoodsNoSame = 8 // 商品与描述不符
|
||||
// AfsReasonWrongPurchase = 9 // 误购
|
||||
// AfsReasonNotReceivedIntime = 10 // 未在时效内送达
|
||||
// AfsReasonNotOthers = 0 // 其它
|
||||
//)
|
||||
//
|
||||
//const (
|
||||
// DefaultEarningPricePercentage = 70 // 门店缺省结算百分比
|
||||
//
|
||||
// MinVendorPricePercentage = 10
|
||||
// DefVendorPricePercentage = 100 // 平台缺省调价比例
|
||||
// MaxVendorPricePercentage = 400
|
||||
//)
|
||||
//
|
||||
//const (
|
||||
// YES = 1 //通用
|
||||
// NO = 0
|
||||
// DISABLED = -1
|
||||
//)
|
||||
//
|
||||
//func IsOrderLockStatus(status int) bool {
|
||||
// return status == OrderStatusLocked || status == OrderStatusApplyCancel
|
||||
//}
|
||||
//
|
||||
//func IsOrderUnlockStatus(status int) bool {
|
||||
// return status == OrderStatusUnlocked || status == OrderStatusUndoApplyCancel || status == OrderStatusVendorAgreeCancel || status == OrderStatusVendorRejectCancel
|
||||
//}
|
||||
//
|
||||
//func IsOrderMainStatus(status int) bool {
|
||||
// return status > OrderStatusUnknown
|
||||
//}
|
||||
//
|
||||
//func IsOrderFinalStatus(status int) bool {
|
||||
// return status >= OrderStatusEndBegin && status <= OrderStatusEndEnd
|
||||
//}
|
||||
//
|
||||
//func IsOrderImportantStatus(status int) bool {
|
||||
// return IsOrderMainStatus(status) || IsOrderLockStatus(status) || IsOrderUnlockStatus(status)
|
||||
//}
|
||||
//
|
||||
//func IsVendorRemote(vendorID int) bool {
|
||||
// return vendorID >= VendorIDJD && vendorID <= VendorIDEBAI
|
||||
//}
|
||||
//
|
||||
//func IsAfsOrderFinalStatus(status int) bool {
|
||||
// return status >= AfsOrderStatusFinished && status <= AfsOrderStatusFailed
|
||||
//}
|
||||
//
|
||||
//func IsWaybillFinalStatus(status int) bool {
|
||||
// return status >= WaybillStatusEndBegin && status <= WaybillStatusEndEnd
|
||||
//}
|
||||
|
||||
@@ -1,609 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type ActMapPureInfo struct {
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空
|
||||
VendorActID string `orm:"column(vendor_act_id);size(48)" json:"vendorActID"`
|
||||
SyncStatus int `orm:"default(2)" json:"syncStatus"`
|
||||
Remark string `orm:"column(map_remark)" json:"remark"`
|
||||
}
|
||||
|
||||
type ActVendorInfo struct {
|
||||
model.Act
|
||||
VendorList []*ActMapPureInfo `json:"vendorList"`
|
||||
}
|
||||
|
||||
type tActAndMap struct {
|
||||
model.Act
|
||||
MapID int `orm:"column(map_id)" json:"-"` // 内部使用,不暴露
|
||||
ActMapPureInfo
|
||||
}
|
||||
|
||||
type PagedActListInfo struct {
|
||||
TotalCount int `json:"totalCount"`
|
||||
Data []*ActVendorInfo `json:"data"`
|
||||
}
|
||||
|
||||
func GetActVendorInfo(db *DaoDB, actID int, vendorIDs []int) (actMap map[int]*model.Act2, err error) {
|
||||
leftOrEmpty := ""
|
||||
if len(vendorIDs) == 1 && vendorIDs[0] == -1 {
|
||||
leftOrEmpty = "LEFT"
|
||||
}
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT t1.*,
|
||||
t2.id map_id, t2.vendor_id, t2.vendor_org_code, t2.vendor_act_id, t2.sync_status
|
||||
FROM act t1
|
||||
%s JOIN act_map t2 ON t2.act_id = t1.id AND t2.deleted_at = ?`, leftOrEmpty)
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND t2.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
|
||||
sql += `
|
||||
WHERE t1.deleted_at = ? AND t1.id = ?`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, actID)
|
||||
|
||||
var actList []*model.Act2
|
||||
if err = GetRows(db, &actList, sql, sqlParams...); err == nil {
|
||||
actMap = make(map[int]*model.Act2)
|
||||
for _, v := range actList {
|
||||
if leftOrEmpty != "" {
|
||||
v.VendorID = -1
|
||||
}
|
||||
actMap[v.VendorID] = v
|
||||
}
|
||||
}
|
||||
return actMap, err
|
||||
}
|
||||
|
||||
func GetActStoreSkuVendorList(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs []int, keyword string, offset, pageSize int) (totalCount int, actStoreSkuList []*model.ActStoreSku2, err error) {
|
||||
// globals.SugarLogger.Debugf("GetActStoreSkuVendorList actID:%d", actID)
|
||||
// offset = jxutils.FormalizePageOffset(offset)
|
||||
// pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
|
||||
// leftOrEmpty := ""
|
||||
// if len(vendorIDs) == 1 && (vendorIDs[0] == -1 || vendorIDs[0] == model.VendorIDJX) {
|
||||
// leftOrEmpty = "LEFT"
|
||||
// }
|
||||
// sql := fmt.Sprintf(`
|
||||
// SELECT SQL_CALC_FOUND_ROWS
|
||||
// t1.*,
|
||||
// t2.id map_id, t2.vendor_id, t2.vendor_act_id, t2.sync_status, t2.actual_act_price, t2.vendor_price, t2.trend_type, t2.trend_price,
|
||||
// t3.vendor_store_id,
|
||||
// CASE t2.vendor_id
|
||||
// WHEN 0 THEN
|
||||
// t4m.vendor_thing_id
|
||||
// WHEN 1 THEN
|
||||
// t5.mtwm_id
|
||||
// WHEN 3 THEN
|
||||
// t5.ebai_id
|
||||
// ELSE
|
||||
// ''
|
||||
// END vendor_sku_id,
|
||||
// t4.comment, t4.spec_quality, t4.spec_unit,
|
||||
// t6.name store_name,
|
||||
// t7.name sku_name_name, t7.unit, t7.prefix, t7.ex_prefix, t7.ex_prefix_begin, t7.ex_prefix_end
|
||||
// FROM act_store_sku t1
|
||||
// %s JOIN act_store_sku_map t2 ON t2.act_id = ? AND t2.bind_id = t1.id AND t2.deleted_at = ?`, leftOrEmpty)
|
||||
// sqlParams := []interface{}{
|
||||
// actID,
|
||||
// utils.DefaultTimeValue,
|
||||
// }
|
||||
|
||||
// if len(vendorIDs) > 0 {
|
||||
// sql += " AND t2.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
// sqlParams = append(sqlParams, vendorIDs)
|
||||
// }
|
||||
// sql += `
|
||||
// LEFT JOIN store_map t3 ON t3.store_id = t1.store_id AND t3.vendor_id = t2.vendor_id AND t3.deleted_at = ?
|
||||
// JOIN sku t4 ON t4.id = t1.sku_id
|
||||
// LEFT JOIN thing_map t4m ON t4m.vendor_id = ? AND t4m.thing_id = t4.id AND t4m.thing_type = ? AND t4m.vendor_id = t2.vendor_id AND t4m.vendor_org_code = t3.vendor_org_code AND t4m.deleted_at = ?
|
||||
// LEFT JOIN store_sku_bind t5 ON t5.sku_id = t1.sku_id AND t5.store_id = t1.store_id AND t5.deleted_at = ?
|
||||
// LEFT JOIN store t6 ON t6.id = t1.store_id
|
||||
// JOIN sku_name t7 ON t7.id = t4.name_id
|
||||
// WHERE t1.act_id = ?
|
||||
// `
|
||||
// sqlParams = append(sqlParams,
|
||||
// utils.DefaultTimeValue,
|
||||
// model.VendorIDJD, model.ThingTypeSku, utils.DefaultTimeValue,
|
||||
// utils.DefaultTimeValue,
|
||||
// actID,
|
||||
// )
|
||||
// if keyword != "" {
|
||||
// keywordLike := "%" + keyword + "%"
|
||||
// sql += " AND (t7.name LIKE ? OR t6.name LIKE ?"
|
||||
// sqlParams = append(sqlParams, keywordLike, keywordLike)
|
||||
// if intKeyword := int(utils.Str2Int64WithDefault(keyword, 0)); intKeyword > 0 {
|
||||
// sql += " OR t1.sku_id = ? OR t1.store_id = ?"
|
||||
// sqlParams = append(sqlParams, intKeyword, intKeyword)
|
||||
// }
|
||||
// sql += ")"
|
||||
// }
|
||||
// if leftOrEmpty != "" {
|
||||
// sql += " AND t1.deleted_at = ?"
|
||||
// sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
// }
|
||||
// if len(storeIDs) > 0 {
|
||||
// sql += " AND t1.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
// sqlParams = append(sqlParams, storeIDs)
|
||||
// }
|
||||
// if len(skuIDs) > 0 {
|
||||
// sql += " AND t1.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
// sqlParams = append(sqlParams, skuIDs)
|
||||
// }
|
||||
// sql += " LIMIT ? OFFSET ?;"
|
||||
// sqlParams = append(sqlParams, pageSize, offset)
|
||||
// // globals.SugarLogger.Debug(sql)
|
||||
// // globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
|
||||
// // globals.SugarLogger.Debug(utils.Format4Output(actStoreSkuList, false))
|
||||
// Begin(db)
|
||||
// defer Commit(db)
|
||||
// if err = GetRows(db, &actStoreSkuList, sql, sqlParams...); err == nil {
|
||||
// totalCount = GetLastTotalRowCount(db)
|
||||
// }
|
||||
return totalCount, actStoreSkuList, err
|
||||
}
|
||||
|
||||
func GetActStoreSkuVendorInfo(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs []int) (actStoreSkuMap map[int][]*model.ActStoreSku2, err error) {
|
||||
leftOrEmpty := ""
|
||||
if len(vendorIDs) == 1 && vendorIDs[0] == -1 {
|
||||
leftOrEmpty = "LEFT"
|
||||
}
|
||||
_, actStoreSkuList, err := GetActStoreSkuVendorList(db, actID, vendorIDs, storeIDs, skuIDs, "", 0, -1)
|
||||
if err == nil {
|
||||
actStoreSkuMap = make(map[int][]*model.ActStoreSku2)
|
||||
for _, v := range actStoreSkuList {
|
||||
if leftOrEmpty != "" {
|
||||
v.VendorID = -1
|
||||
}
|
||||
actStoreSkuMap[v.VendorID] = append(actStoreSkuMap[v.VendorID], v)
|
||||
}
|
||||
}
|
||||
return actStoreSkuMap, err
|
||||
}
|
||||
|
||||
func QueryActs(db *DaoDB, actID int, offset, pageSize int, syncStatus int, keyword string, vendorID int, statusList, actTypeList, createTypeList []int,
|
||||
storeID int, skuIDs []int, cityCode int, beginAt, endAt, createdAtFrom, createdAtTo time.Time) (pagedInfo *PagedActListInfo, err error) {
|
||||
if actID == 0 && utils.IsTimeZero(createdAtFrom) && utils.IsTimeZero(beginAt) {
|
||||
return nil, fmt.Errorf("actID,createdAtFrom和beginAt中,至少要指定一个条件")
|
||||
}
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
isGetAll := offset == 0 && pageSize == model.UnlimitedPageSize
|
||||
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
DISTINCT t1.id
|
||||
FROM act t1`
|
||||
sqlParams := []interface{}{}
|
||||
if isGetAll {
|
||||
sql = `
|
||||
SELECT
|
||||
t1.*,
|
||||
t2.id map_id, t2.vendor_id, t2.vendor_act_id, t2.sync_status, t2.remark map_remark
|
||||
FROM act t1`
|
||||
}
|
||||
sql += " LEFT JOIN act_map t2 ON t2.act_id = t1.id AND t2.deleted_at = ?"
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
if syncStatus >= 0 {
|
||||
sql += " AND (t2.sync_status = ? OR t2.sync_status & ? <> 0)"
|
||||
sqlParams = append(sqlParams, syncStatus, syncStatus)
|
||||
}
|
||||
sql += `
|
||||
WHERE t1.deleted_at = ?`
|
||||
if syncStatus >= 0 {
|
||||
sql += " AND t2.id IS NOT NULL"
|
||||
}
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
keywordInt := int64(0)
|
||||
if keyword != "" {
|
||||
keywordLike := "%" + keyword + "%"
|
||||
sql += " AND ( t1.name LIKE ? OR t1.advertising LIKE ? OR t1.remark LIKE ? OR t2.vendor_act_id LIKE ?"
|
||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||
keywordInt = utils.Str2Int64WithDefault(keyword, 0)
|
||||
if keywordInt > 0 {
|
||||
sql += `
|
||||
OR t1.id = ?`
|
||||
sqlParams = append(sqlParams, keywordInt)
|
||||
}
|
||||
sql += ")"
|
||||
}
|
||||
if storeID > 0 || len(skuIDs) > 0 || cityCode > 0 {
|
||||
sql += ` AND (SELECT COUNT(*)
|
||||
FROM act_store_sku t2`
|
||||
if cityCode > 0 {
|
||||
sql += " JOIN store t3 ON t3.id = t2.store_id AND t3.city_code = ?"
|
||||
sqlParams = append(sqlParams, cityCode)
|
||||
}
|
||||
sql += `
|
||||
WHERE t2.act_id = t1.id AND t2.deleted_at = ?`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
if storeID > 0 {
|
||||
sql += " AND t2.store_id = ?"
|
||||
sqlParams = append(sqlParams, storeID)
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND t2.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
sql += ") > 0"
|
||||
}
|
||||
if actID > 0 {
|
||||
sql += " AND t1.id = ?"
|
||||
sqlParams = append(sqlParams, actID)
|
||||
}
|
||||
if vendorID >= 0 {
|
||||
sql += " AND t1.vendor_mask & ? <> 0"
|
||||
sqlParams = append(sqlParams, model.GetVendorMask(vendorID))
|
||||
}
|
||||
if len(statusList) > 0 {
|
||||
sql += " AND t1.status IN (" + GenQuestionMarks(len(statusList)) + ")"
|
||||
sqlParams = append(sqlParams, statusList)
|
||||
}
|
||||
if len(actTypeList) > 0 {
|
||||
sql += " AND t1.type IN (" + GenQuestionMarks(len(actTypeList)) + ")"
|
||||
sqlParams = append(sqlParams, actTypeList)
|
||||
}
|
||||
if len(createTypeList) > 0 {
|
||||
sql += " AND t1.create_type IN (" + GenQuestionMarks(len(createTypeList)) + ")"
|
||||
sqlParams = append(sqlParams, createTypeList)
|
||||
}
|
||||
if !utils.IsTimeZero(beginAt) {
|
||||
sql += " AND t1.begin_at <= ?"
|
||||
sqlParams = append(sqlParams, beginAt)
|
||||
}
|
||||
if !utils.IsTimeZero(endAt) {
|
||||
sql += " AND t1.end_at >= ?"
|
||||
sqlParams = append(sqlParams, endAt)
|
||||
}
|
||||
if !utils.IsTimeZero(createdAtFrom) {
|
||||
sql += " AND t1.created_at >= ?"
|
||||
sqlParams = append(sqlParams, createdAtFrom)
|
||||
}
|
||||
if !utils.IsTimeZero(createdAtTo) {
|
||||
sql += " AND t1.created_at <= ?"
|
||||
sqlParams = append(sqlParams, createdAtTo)
|
||||
}
|
||||
|
||||
pagedInfo = &PagedActListInfo{}
|
||||
if isGetAll {
|
||||
sql += `
|
||||
ORDER BY t1.id DESC, t2.vendor_id`
|
||||
} else {
|
||||
sql += `
|
||||
ORDER BY 1 DESC
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
var idList []int
|
||||
|
||||
txDB, _ := Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
// globals.SugarLogger.Debug(sql)
|
||||
if err = GetRowsTx(txDB, &idList, sql, sqlParams...); err != nil || len(idList) == 0 {
|
||||
Rollback(db, txDB)
|
||||
return pagedInfo, err
|
||||
}
|
||||
pagedInfo.TotalCount = GetLastTotalRowCountTx(txDB)
|
||||
Commit(db, txDB)
|
||||
|
||||
sql = `
|
||||
SELECT
|
||||
t1.*,
|
||||
t2.id map_id, t2.vendor_id, t2.vendor_org_code, t2.vendor_act_id, t2.sync_status, t2.remark map_remark
|
||||
FROM act t1
|
||||
LEFT JOIN act_map t2 ON t2.act_id = t1.id AND t2.deleted_at = ?
|
||||
WHERE t1.id IN (` + GenQuestionMarks(len(idList)) + `)`
|
||||
if syncStatus >= 0 {
|
||||
sql += " AND t2.id IS NOT NULL"
|
||||
}
|
||||
sql += `
|
||||
ORDER BY t1.id DESC, t2.vendor_id`
|
||||
sqlParams = []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
idList,
|
||||
}
|
||||
}
|
||||
var actList []*tActAndMap
|
||||
// globals.SugarLogger.Debug(sql)
|
||||
if err = GetRows(db, &actList, sql, sqlParams...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
actMap := make(map[int]*ActVendorInfo)
|
||||
for _, v := range actList {
|
||||
tmpAct := actMap[v.ID]
|
||||
if tmpAct == nil {
|
||||
tmpAct = &ActVendorInfo{
|
||||
Act: v.Act,
|
||||
}
|
||||
actMap[v.ID] = tmpAct
|
||||
pagedInfo.Data = append(pagedInfo.Data, tmpAct)
|
||||
}
|
||||
if v.MapID > 0 {
|
||||
tmpAct.VendorList = append(tmpAct.VendorList, &v.ActMapPureInfo)
|
||||
}
|
||||
}
|
||||
if isGetAll {
|
||||
pagedInfo.TotalCount = len(pagedInfo.Data)
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
func GetExistVendorActIDs(db *DaoDB, vendorID int) (vendorActIDs []string, err error) {
|
||||
// todo 不应该是全表扫描
|
||||
sql := `
|
||||
SELECT
|
||||
DISTINCT t1.vendor_act_id
|
||||
FROM act_store_sku_map t1
|
||||
WHERE t1.deleted_at = ? AND t1.vendor_id = ?`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
vendorID,
|
||||
}
|
||||
err = GetRows(db, &vendorActIDs, sql, sqlParams...)
|
||||
return vendorActIDs, err
|
||||
}
|
||||
|
||||
func GetEffectiveActStoreSkuInfo(db *DaoDB, actID int, vendorIDs []int, actType int, storeIDs, skuIDs []int, beginAt, endAt time.Time) (actStoreSkuList []*model.ActStoreSku2, err error) {
|
||||
if utils.IsTimeZero(beginAt) {
|
||||
return nil, fmt.Errorf("GeActStoreSkuInfo必须指定活动开始时间")
|
||||
}
|
||||
if utils.IsTimeZero(endAt) {
|
||||
endAt = beginAt
|
||||
}
|
||||
sql := `
|
||||
SELECT
|
||||
t1.type, t1.discount_type, t1.discount_value1, t1.discount_value2,
|
||||
t2.*,
|
||||
t3.actual_act_price, t3.sync_status, t3.vendor_price, t3.vendor_id, t3.trend_type, t3.trend_price
|
||||
FROM act t1
|
||||
JOIN act_store_sku t2 ON t2.act_id = t1.id AND t2.deleted_at = ?
|
||||
JOIN act_store_sku_map t3 ON t3.bind_id = t2.id AND t3.act_id = t1.id AND (t3.sync_status & ? = 0 OR t1.type = ?)
|
||||
JOIN act_map t4 ON t4.act_id = t1.id AND t4.vendor_id = t3.vendor_id AND t4.deleted_at = ? AND (t4.sync_status & ? = 0 OR t1.type = ?)
|
||||
WHERE t1.deleted_at = ? AND t1.status = ? AND NOT (t1.begin_at > ? OR t1.end_at < ?) AND t1.create_type = ?`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
|
||||
model.SyncFlagNewMask,
|
||||
model.ActSkuFake,
|
||||
|
||||
utils.DefaultTimeValue, model.SyncFlagNewMask, model.ActSkuFake,
|
||||
utils.DefaultTimeValue, model.ActStatusCreated, endAt, beginAt, model.ActCreateTypeAPI,
|
||||
}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND (t1.vendor_mask & ?) <> 0 AND t3.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
sqlParams = append(sqlParams, model.GetVendorMask(vendorIDs...), vendorIDs)
|
||||
}
|
||||
if actID > 0 {
|
||||
sql += " AND t1.id = ?"
|
||||
sqlParams = append(sqlParams, actID)
|
||||
}
|
||||
if actType != model.ActTypeAll {
|
||||
sql += " AND t1.type = ?"
|
||||
sqlParams = append(sqlParams, actType)
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND t2.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND t2.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
if globals.IsStoreSkuAct {
|
||||
sql += " AND t1.is_special = 0"
|
||||
}
|
||||
err = GetRows(db, &actStoreSkuList, sql, sqlParams...)
|
||||
return actStoreSkuList, err
|
||||
}
|
||||
|
||||
func GetEffectiveActStoreSkuInfo2(db *DaoDB, actID int, vendorIDs []int, actTypes []int, storeIDs, skuIDs []int, beginAt, endAt time.Time) (actStoreSkuList []*model.ActStoreSku2, err error) {
|
||||
if utils.IsTimeZero(beginAt) {
|
||||
return nil, fmt.Errorf("GeActStoreSkuInfo必须指定活动开始时间")
|
||||
}
|
||||
if utils.IsTimeZero(endAt) {
|
||||
endAt = beginAt
|
||||
}
|
||||
sql := `
|
||||
SELECT
|
||||
t1.type,
|
||||
t2.*,
|
||||
t3.actual_act_price, t3.sync_status, t3.vendor_price, t3.vendor_id
|
||||
FROM act t1
|
||||
JOIN act_store_sku t2 ON t2.act_id = t1.id AND t2.deleted_at = ?
|
||||
JOIN act_store_sku_map t3 ON t3.bind_id = t2.id AND t3.act_id = t1.id AND (t3.sync_status & ? = 0 OR t1.type = ?)
|
||||
JOIN act_map t4 ON t4.act_id = t1.id AND t4.vendor_id = t3.vendor_id AND t4.deleted_at = ? AND (t4.sync_status & ? = 0 OR t1.type = ?)
|
||||
WHERE t1.deleted_at = ? AND t1.status = ? AND NOT (t1.begin_at > ? OR t1.end_at < ?) AND t1.create_type = ?`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
|
||||
model.SyncFlagNewMask,
|
||||
model.ActSkuFake,
|
||||
|
||||
utils.DefaultTimeValue, model.SyncFlagNewMask, model.ActSkuFake,
|
||||
utils.DefaultTimeValue, model.ActStatusCreated, endAt, beginAt, model.ActCreateTypeAPI,
|
||||
}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND (t1.vendor_mask & ?) <> 0 AND t3.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
sqlParams = append(sqlParams, model.GetVendorMask(vendorIDs...), vendorIDs)
|
||||
}
|
||||
if actID > 0 {
|
||||
sql += " AND t1.id = ?"
|
||||
sqlParams = append(sqlParams, actID)
|
||||
}
|
||||
if len(actTypes) > 0 {
|
||||
sql += " AND t1.type IN (" + GenQuestionMarks(len(actTypes)) + ")"
|
||||
sqlParams = append(sqlParams, actTypes)
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND t2.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND t2.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
if globals.IsStoreSkuAct {
|
||||
sql += " AND t1.is_special = 0"
|
||||
}
|
||||
// globals.SugarLogger.Debug(sql)
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
|
||||
err = GetRows(db, &actStoreSkuList, sql, sqlParams...)
|
||||
return actStoreSkuList, err
|
||||
}
|
||||
|
||||
func UpdateActStatusByTime(db *DaoDB, refTime time.Time) (num int64, err error) {
|
||||
sql := `
|
||||
UPDATE act t1
|
||||
SET t1.status = ?
|
||||
WHERE t1.deleted_at = ? AND t1.status < ? AND t1.end_at < ?;`
|
||||
sqlParams := []interface{}{
|
||||
model.ActStatusEnded,
|
||||
utils.DefaultTimeValue,
|
||||
model.ActStatusCanceled,
|
||||
utils.Time2Date(refTime),
|
||||
}
|
||||
num, err = ExecuteSQL(db, sql, sqlParams...)
|
||||
return num, err
|
||||
}
|
||||
|
||||
// func ActStoreSkuMap2StoreSkuAct(actStoreSkuMap *model.ActStoreSkuMap, isCanceled bool) (storeSkuAct *model.StoreSkuAct) {
|
||||
// storeSkuAct = &model.StoreSkuAct{
|
||||
// StoreID: actStoreSkuMap.StoreID,
|
||||
// SkuID: actStoreSkuMap.SkuID,
|
||||
// VendorID: actStoreSkuMap.VendorID,
|
||||
// }
|
||||
// storeSkuAct.CreatedAt = actStoreSkuMap.CreatedAt
|
||||
// storeSkuAct.UpdatedAt = actStoreSkuMap.UpdatedAt
|
||||
// storeSkuAct.LastOperator = actStoreSkuMap.LastOperator
|
||||
|
||||
// if actStoreSkuMap.ActualActPrice > 0 {
|
||||
// if isCanceled || !utils.IsTimeZero(actStoreSkuMap.DeletedAt) {
|
||||
// storeSkuAct.ActID = 0
|
||||
// } else {
|
||||
// storeSkuAct.ActID = actStoreSkuMap.ActID
|
||||
// storeSkuAct.VendorActID = actStoreSkuMap.VendorActID
|
||||
// storeSkuAct.SyncStatus = actStoreSkuMap.SyncStatus
|
||||
// storeSkuAct.VendorPrice = actStoreSkuMap.VendorPrice
|
||||
// storeSkuAct.ActualActPrice = actStoreSkuMap.ActualActPrice
|
||||
// }
|
||||
// }
|
||||
// if actStoreSkuMap.EarningPrice > 0 {
|
||||
// if isCanceled || !utils.IsTimeZero(actStoreSkuMap.DeletedAt) {
|
||||
// storeSkuAct.EarningActID = 0
|
||||
// } else {
|
||||
// storeSkuAct.EarningActID = actStoreSkuMap.ActID
|
||||
// storeSkuAct.EarningPrice = actStoreSkuMap.EarningPrice
|
||||
// }
|
||||
// }
|
||||
// return storeSkuAct
|
||||
// }
|
||||
|
||||
func BatchUpdateActEntity(db *DaoDB, isCanceled bool, items []*KVUpdateItem) (num int64, err error) {
|
||||
return BatchUpdateEntityByKV(db, items)
|
||||
// if globals.IsStoreSkuAct {
|
||||
// Begin(db)
|
||||
// defer func() {
|
||||
// if r := recover(); r != nil || err != nil {
|
||||
// Rollback(db)
|
||||
// if r != nil {
|
||||
// panic(r)
|
||||
// }
|
||||
// }
|
||||
// }()
|
||||
|
||||
// for _, v := range items {
|
||||
// if actStoreSku, ok := v.Item.(*model.ActStoreSkuMap); ok {
|
||||
// for k1, v1 := range v.KVs {
|
||||
// refutil.SetObjFieldByName(actStoreSku, k1, v1)
|
||||
// }
|
||||
// if err = CreateOrUpdateActStoreSku(db, ActStoreSkuMap2StoreSkuAct(actStoreSku, isCanceled)); err != nil {
|
||||
// return 0, err
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// if _, err = BatchUpdateEntityByKV(db, items); err != nil {
|
||||
// return 0, err
|
||||
// }
|
||||
|
||||
// if globals.IsStoreSkuAct {
|
||||
// Commit(db)
|
||||
// }
|
||||
// return num, err
|
||||
}
|
||||
|
||||
func CreateOrUpdateActStoreSku(db *DaoDB, storeSkuAct *model.StoreSkuAct) (err error) {
|
||||
storeSkuActCopy := *storeSkuAct
|
||||
if err2 := GetEntity(db, &storeSkuActCopy, model.FieldStoreID, model.FieldSkuID, model.FieldVendorID); err2 == nil {
|
||||
storeSkuAct.ID = storeSkuActCopy.ID
|
||||
_, err = UpdateEntity(db, storeSkuAct)
|
||||
} else if IsNoRowsError(err2) {
|
||||
err = CreateEntity(db, storeSkuAct)
|
||||
} else {
|
||||
err = err2
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func GetStoresSkusAct(db *DaoDB, hintActID int, mustDirty bool, storeIDs, skuIDs, vendorIDs []int, mustHaveVendorActID bool, minActPercentage, maxActPercentage int) (storeSkuActList []*model.StoreSkuAct, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM store_sku_act t1
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if hintActID > 0 {
|
||||
sql += " AND t1.hint_act_id = ?"
|
||||
sqlParams = append(sqlParams, hintActID)
|
||||
}
|
||||
if mustDirty {
|
||||
sql += " AND (t1.sync_status <> 0 OR (t1.act_percentage = 0 AND t1.vendor_act_id <> '') OR (t1.act_percentage <> 0 AND t1.vendor_act_id = ''))"
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND t1.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND t1.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND t1.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
if mustHaveVendorActID {
|
||||
sql += " AND t1.vendor_act_id <> ''"
|
||||
}
|
||||
if minActPercentage > 0 {
|
||||
sql += " AND t1.act_percentage >= ?"
|
||||
sqlParams = append(sqlParams, minActPercentage)
|
||||
}
|
||||
if maxActPercentage > 0 {
|
||||
sql += " AND t1.act_percentage <= ?"
|
||||
sqlParams = append(sqlParams, maxActPercentage)
|
||||
}
|
||||
err = GetRows(db, &storeSkuActList, sql, sqlParams...)
|
||||
return storeSkuActList, err
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func TestGetEffectiveActStoreSkuInfo(t *testing.T) {
|
||||
type testData struct {
|
||||
ResultCount int
|
||||
|
||||
ActID int
|
||||
VendorIDs []int
|
||||
StoreIDs []int
|
||||
SkuIDs []int
|
||||
FromTime time.Time
|
||||
ToTime time.Time
|
||||
}
|
||||
for _, v := range []*testData{
|
||||
&testData{
|
||||
StoreIDs: []int{100190},
|
||||
SkuIDs: []int{23847},
|
||||
ResultCount: 1,
|
||||
FromTime: utils.Str2Time("2019-08-06 12:34:56"),
|
||||
ToTime: utils.Str2Time("2019-08-06 12:34:56"),
|
||||
},
|
||||
} {
|
||||
result, err := GetEffectiveActStoreSkuInfo(GetDB(), v.ActID, v.VendorIDs, model.ActTypeAll, v.StoreIDs, v.SkuIDs, v.FromTime, v.ToTime)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(result) != v.ResultCount {
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
t.Errorf("cond:%s, len(result):%d, v.ResultCount:%d", utils.Format4Output(v, false), len(result), v.ResultCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateActStatusByTime(t *testing.T) {
|
||||
_, err := UpdateActStatusByTime(GetDB(), time.Now().Add(-48*time.Hour))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetActStoreSkuVendorList(t *testing.T) {
|
||||
_, _, err := GetActStoreSkuVendorList(GetDB(), 18440, nil, nil, nil, "", 0, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func GetUserBill(db *DaoDB, userID, billID string) (userBill *model.UserBill, err error) {
|
||||
sql := `
|
||||
SELECT * FROM user_bill WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
if userID != "" {
|
||||
sql += ` AND user_id = ?`
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if billID != "" {
|
||||
sql += ` AND bill_id = ?`
|
||||
sqlParams = append(sqlParams, billID)
|
||||
}
|
||||
err = GetRow(db, &userBill, sql, sqlParams)
|
||||
return userBill, err
|
||||
}
|
||||
|
||||
func GetBillExpend(db *DaoDB, userID string, billType int, fromTime, toTime time.Time) (billExpends []*model.BillExpend, err error) {
|
||||
sql := `
|
||||
SELECT b.*
|
||||
FROM user_bill a
|
||||
LEFT JOIN bill_expend b ON b.bill_id = a.bill_id
|
||||
WHERE a.deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
if userID != "" {
|
||||
sql += ` AND a.user_id = ?`
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if billType != 0 {
|
||||
sql += ` AND b.type = ?`
|
||||
sqlParams = append(sqlParams, billType)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND b.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND b.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
err = GetRows(db, &billExpends, sql, sqlParams)
|
||||
return billExpends, err
|
||||
}
|
||||
|
||||
func GetBillIncome(db *DaoDB, jobID int, billID int64) (billIncomes []*model.BillIncome, err error) {
|
||||
sql := `
|
||||
SELECT b.*
|
||||
FROM user_bill a
|
||||
LEFT JOIN bill_income b ON b.bill_id = a.bill_id
|
||||
WHERE a.deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
if jobID != 0 {
|
||||
sql += ` AND b.job_id = ?`
|
||||
sqlParams = append(sqlParams, jobID)
|
||||
}
|
||||
if billID != 0 {
|
||||
sql += ` AND b.bill_id = ?`
|
||||
sqlParams = append(sqlParams, billID)
|
||||
}
|
||||
err = GetRows(db, &billIncomes, sql, sqlParams)
|
||||
return billIncomes, err
|
||||
}
|
||||
|
||||
type UserBillDetail struct {
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
LastOperator string `json:"lastOperator"`
|
||||
BillType int `json:"billType"`
|
||||
Price int `json:"price"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
func GetUserBillDetail(db *DaoDB, userID string, fromTime, toTime time.Time, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
||||
var userBillDetails []*UserBillDetail
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS k.* FROM (
|
||||
SELECT a.created_at, a.last_operator, a.type bill_type, a.income_price price, 'income' type
|
||||
FROM bill_income a
|
||||
JOIN user_bill b ON a.bill_id = b.bill_id AND b.user_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{userID}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
sql += `
|
||||
UNION ALL
|
||||
SELECT a.created_at, a.last_operator, a.type bill_type, a.expend_price price, 'expend' type
|
||||
FROM bill_expend a
|
||||
JOIN user_bill b ON a.bill_id = b.bill_id AND b.user_id = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, userID)
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
sql += `
|
||||
)k
|
||||
ORDER BY k.created_at LIMIT ? OFFSET ?
|
||||
`
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &userBillDetails, sql, sqlParams...); err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
Data: userBillDetails,
|
||||
}
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
@@ -1,582 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
const (
|
||||
sortTypeDistance = 1 //距离
|
||||
sortTypeTime = 2 //发布时间
|
||||
sortTypeAvgPrice = 4 //奖励高低
|
||||
)
|
||||
|
||||
func GetJobCategories(db *DaoDB, name string) (jobCategories []*model.JobCategory, err error) {
|
||||
sql := `
|
||||
SELECT * FROM job_category WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
if name != "" {
|
||||
sql += ` AND name LIKE ?`
|
||||
sqlParams = append(sqlParams, "%"+name+"%")
|
||||
}
|
||||
err = GetRows(db, &jobCategories, sql, sqlParams)
|
||||
return jobCategories, err
|
||||
}
|
||||
|
||||
type GetJobsResult struct {
|
||||
model.JobExt
|
||||
CategoryName string `json:"categoryName"` //分类名
|
||||
IndexImg string `json:"indexImg"` //任务封面
|
||||
Distance float64 `json:"distance"` //距用户距离
|
||||
}
|
||||
|
||||
func GetJobSteps(db *DaoDB, jobID int) (jobSteps []*model.JobStep, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM job_step
|
||||
WHERE job_id = ?
|
||||
AND deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{jobID, utils.DefaultTimeValue}
|
||||
err = GetRows(db, &jobSteps, sql, sqlParams)
|
||||
return jobSteps, err
|
||||
}
|
||||
|
||||
func GetJobImgs(db *DaoDB, jobID int) (jobImgs []*model.JobImg, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM job_img
|
||||
WHERE job_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{jobID}
|
||||
err = GetRows(db, &jobImgs, sql, sqlParams)
|
||||
return jobImgs, err
|
||||
}
|
||||
|
||||
func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs, types, cityCodes []int, includeStep bool, fromTime, toTime time.Time, lng, lat float64, cityCode, span int, keyword string, sortType, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
||||
var (
|
||||
jobs []*GetJobsResult
|
||||
sqlParams = []interface{}{lng, lat, utils.DefaultTimeValue, utils.DefaultTimeValue}
|
||||
)
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS a.*, b.name, getDistance(?, ?, CAST(a.lng AS DECIMAL(15,6))/1000000, CAST(a.lat AS DECIMAL(15,6))/1000000) distance
|
||||
FROM job a
|
||||
JOIN job_category b ON b.id = a.job_category_id AND b.deleted_at = ?
|
||||
WHERE a.deleted_at = ?
|
||||
`
|
||||
if cityCode > 0 {
|
||||
sql += " AND (a.job_city_code = ? OR a.job_city_code = ?)"
|
||||
sqlParams = append(sqlParams, cityCode, model.JobCountrywideCode)
|
||||
}
|
||||
if len(userIDs) > 0 {
|
||||
sql += ` AND a.user_id IN (` + GenQuestionMarks(len(userIDs)) + `)`
|
||||
sqlParams = append(sqlParams, userIDs)
|
||||
}
|
||||
if len(categoryIDs) > 0 {
|
||||
sql += ` AND a.job_category_id IN (` + GenQuestionMarks(len(categoryIDs)) + `)`
|
||||
sqlParams = append(sqlParams, categoryIDs)
|
||||
}
|
||||
if len(statuss) > 0 {
|
||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
||||
sqlParams = append(sqlParams, statuss)
|
||||
}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += ` AND a.vendor_id IN (` + GenQuestionMarks(len(vendorIDs)) + `)`
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
if len(types) > 0 {
|
||||
sql += ` AND a.type IN (` + GenQuestionMarks(len(types)) + `)`
|
||||
sqlParams = append(sqlParams, types)
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += ` AND a.job_city_code IN (` + GenQuestionMarks(len(cityCodes)) + `)`
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
if span != 0 {
|
||||
if span == model.JobSpanTop {
|
||||
sql += ` AND a.job_span_top = 1`
|
||||
} else {
|
||||
sql += ` AND a.job_span_recmd = 1`
|
||||
}
|
||||
}
|
||||
if keyword != "" {
|
||||
sql += ` AND (a.title LIKE ? OR a.content LIKE ? OR a.address LIKE ? OR b.name LIKE ?)`
|
||||
sqlParams = append(sqlParams, "%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%")
|
||||
}
|
||||
if sortType != 0 {
|
||||
if sortType == sortTypeDistance {
|
||||
sql += ` ORDER BY job_span_top DESC, top_seq, distance`
|
||||
} else if sortType == -sortTypeDistance {
|
||||
sql += ` ORDER BY job_span_top DESC, top_seq, distance DESC`
|
||||
} else if sortType == sortTypeAvgPrice {
|
||||
sql += ` ORDER BY job_span_top DESC, top_seq, a.avg_price`
|
||||
} else if sortType == -sortTypeAvgPrice {
|
||||
sql += ` ORDER BY job_span_top DESC, top_seq, a.avg_price DESC`
|
||||
} else if sortType == sortTypeTime {
|
||||
sql += ` ORDER BY job_span_top DESC, top_seq, a.created_at`
|
||||
} else if sortType == -sortTypeTime {
|
||||
sql += ` ORDER BY status DESC, job_span_top DESC, top_seq, a.created_at DESC`
|
||||
}
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &jobs, sql, sqlParams...); err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
// Data: jobs,
|
||||
}
|
||||
for _, v := range jobs {
|
||||
if includeStep {
|
||||
if jobSteps, err := GetJobSteps(db, v.ID); err == nil && len(jobSteps) > 0 {
|
||||
v.JobSteps = jobSteps
|
||||
}
|
||||
}
|
||||
if jobImgs, err := GetJobImgs(db, v.ID); err == nil && len(jobImgs) > 0 {
|
||||
v.JobImgs = jobImgs
|
||||
v.IndexImg = jobImgs[0].Img
|
||||
}
|
||||
}
|
||||
pagedInfo.Data = jobs
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
func GetJob(db *DaoDB, userIDs []string, categoryIDs, statuss, types []int, fromTime, toTime time.Time, includeStep bool) (job *model.Job, err error) {
|
||||
jobs, err := GetJobsNoPage(db, userIDs, categoryIDs, statuss, types, fromTime, toTime, 0, includeStep)
|
||||
if err != nil {
|
||||
return job, err
|
||||
}
|
||||
if len(jobs) == 0 {
|
||||
return job, fmt.Errorf("未查询到对应的京东快递任务!")
|
||||
}
|
||||
if data, err := json.Marshal(jobs[0]); err == nil {
|
||||
json.Unmarshal(data, &job)
|
||||
}
|
||||
return job, err
|
||||
}
|
||||
|
||||
func GetJobWithTitle(db *DaoDB, title string) (job *model.Job, err error) {
|
||||
sql := `
|
||||
SELECT * FROM job WHERE title = ? AND deleted_at = ? AND status = ?
|
||||
`
|
||||
sqlParams := []interface{}{title, utils.DefaultTimeValue, model.JobStatusDoing}
|
||||
err = GetRow(db, &job, sql, sqlParams)
|
||||
return job, err
|
||||
}
|
||||
|
||||
func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs, statuss, types []int, fromTime, toTime time.Time, span int, includeStep bool) (jobs []*GetJobsResult, err error) {
|
||||
sql := `
|
||||
SELECT a.*, b.name
|
||||
FROM job a
|
||||
JOIN job_category b ON b.id = a.job_category_id AND b.deleted_at = ?
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
if len(userIDs) > 0 {
|
||||
sql += ` AND a.user_id IN (` + GenQuestionMarks(len(userIDs)) + `)`
|
||||
sqlParams = append(sqlParams, userIDs)
|
||||
}
|
||||
if len(categoryIDs) > 0 {
|
||||
sql += ` AND a.job_category_id IN (` + GenQuestionMarks(len(categoryIDs)) + `)`
|
||||
sqlParams = append(sqlParams, categoryIDs)
|
||||
}
|
||||
if len(statuss) > 0 {
|
||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
||||
sqlParams = append(sqlParams, statuss)
|
||||
}
|
||||
if len(types) > 0 {
|
||||
sql += ` AND a.type IN (` + GenQuestionMarks(len(types)) + `)`
|
||||
sqlParams = append(sqlParams, types)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
if span != 0 {
|
||||
if span == model.JobSpanTop {
|
||||
sql += ` AND a.job_span_top = 1`
|
||||
} else {
|
||||
sql += ` AND a.job_span_recmd = 1`
|
||||
}
|
||||
}
|
||||
err = GetRows(db, &jobs, sql, sqlParams...)
|
||||
for _, v := range jobs {
|
||||
if includeStep {
|
||||
if jobSteps, err := GetJobSteps(db, v.ID); err == nil && len(jobSteps) > 0 {
|
||||
v.JobSteps = jobSteps
|
||||
}
|
||||
}
|
||||
if jobImgs, err := GetJobImgs(db, v.ID); err == nil && len(jobImgs) > 0 {
|
||||
v.JobImgs = jobImgs
|
||||
}
|
||||
}
|
||||
return jobs, err
|
||||
}
|
||||
|
||||
func GetJobDetail(db *DaoDB, jobID int) (job *GetJobsResult, err error) {
|
||||
sql := `
|
||||
SELECT a.*, b.name
|
||||
FROM job a
|
||||
JOIN job_category b ON b.id = a.job_category_id AND b.deleted_at = ?
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
if jobID != 0 {
|
||||
sql += ` AND a.id = ?`
|
||||
sqlParams = append(sqlParams, jobID)
|
||||
}
|
||||
err = GetRow(db, &job, sql, sqlParams...)
|
||||
if job != nil {
|
||||
if jobSteps, err := GetJobSteps(db, job.ID); err == nil && len(jobSteps) > 0 {
|
||||
job.JobSteps = jobSteps
|
||||
}
|
||||
if jobImgs, err := GetJobImgs(db, job.ID); err == nil && len(jobImgs) > 0 {
|
||||
job.JobImgs = jobImgs
|
||||
}
|
||||
} else {
|
||||
return job, fmt.Errorf("未查到到该任务!")
|
||||
}
|
||||
return job, err
|
||||
}
|
||||
|
||||
func GetJobOrdersNoPage(db *DaoDB, jobID int, jobOrderID int64, userID string, statusCompareStr string, fromTime, toTime time.Time, statuss []int) (jobOrders []*model.JobOrder, err error) {
|
||||
sql := `
|
||||
SELECT a.*
|
||||
FROM job_order a
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if jobID != 0 {
|
||||
sql += ` AND a.job_id = ?`
|
||||
sqlParams = append(sqlParams, jobID)
|
||||
}
|
||||
if jobOrderID != 0 {
|
||||
sql += ` AND a.job_order_id = ?`
|
||||
sqlParams = append(sqlParams, jobOrderID)
|
||||
}
|
||||
if userID != "" {
|
||||
sql += ` AND a.user_id = ?`
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if statusCompareStr != "" {
|
||||
sql += ` AND a.status ` + statusCompareStr
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
if len(statuss) > 0 {
|
||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
||||
sqlParams = append(sqlParams, statuss)
|
||||
}
|
||||
err = GetRows(db, &jobOrders, sql, sqlParams)
|
||||
return jobOrders, err
|
||||
}
|
||||
|
||||
type GetJobOrdersResult struct {
|
||||
model.JobOrder
|
||||
JobLimitAt int `json:"jobLimitAt"` //任务限时完成小时数
|
||||
AuditLimitAt int `json:"auditLimitAt"` //限时审核小时数
|
||||
JobOrderFinishAt time.Time `json:"jobOrderFinishAt"`
|
||||
JobOrderAuditFinishAt time.Time `json:"jobOrderAuditFinishAt"`
|
||||
JobIndexImg string `json:"jobIndexImg"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"` //推广平台
|
||||
AvgPrice int `json:"avgPrice"` //单个任务金额
|
||||
Title string `orm:"size(255)" json:"title"` //任务标题
|
||||
JobContent string `orm:"size(500)" json:"jobContent"`
|
||||
JobCategoryID int `orm:"column(job_category_id)" json:"jobCategoryID"`
|
||||
StoreURL string `orm:"column(store_url)" json:"storeURL"`
|
||||
}
|
||||
|
||||
func GetJobOrders(db *DaoDB, jobID int, jobOrderID int64, userID, jobUserID string, statusCompareStr string, fromTime, toTime time.Time, statuss []int, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
||||
var jobOrders []*GetJobOrdersResult
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS a.*, b.job_limit_at, b.vendor_id, b.avg_price, b.title, b.content job_content, b.audit_limit_at, b.job_category_id, b.store_url
|
||||
FROM job_order a
|
||||
JOIN job b ON a.job_id = b.id
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if jobID != 0 {
|
||||
sql += ` AND a.job_id = ?`
|
||||
sqlParams = append(sqlParams, jobID)
|
||||
}
|
||||
if jobOrderID != 0 {
|
||||
sql += ` AND a.job_order_id = ?`
|
||||
sqlParams = append(sqlParams, jobOrderID)
|
||||
}
|
||||
if userID != "" {
|
||||
sql += ` AND a.user_id = ?`
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if jobUserID != "" {
|
||||
sql += ` AND b.user_id = ?`
|
||||
sqlParams = append(sqlParams, jobUserID)
|
||||
}
|
||||
if statusCompareStr != "" {
|
||||
sql += ` AND a.status ` + statusCompareStr
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
if len(statuss) > 0 {
|
||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
||||
sqlParams = append(sqlParams, statuss)
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &jobOrders, sql, sqlParams...); err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
// Data: jobOrders,
|
||||
}
|
||||
for _, v := range jobOrders {
|
||||
if jobImgs, err := GetJobImgs(db, v.JobID); err == nil && len(jobImgs) > 0 {
|
||||
v.JobIndexImg = jobImgs[0].Img
|
||||
}
|
||||
v.JobOrderFinishAt = v.JobOrder.CreatedAt.Add(time.Duration(v.JobLimitAt) * time.Hour)
|
||||
v.JobOrderAuditFinishAt = v.JobOrder.SubmitAuditAt.Add(time.Duration(v.AuditLimitAt) * time.Hour)
|
||||
}
|
||||
pagedInfo.Data = jobOrders
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
func GetMtMember(db *DaoDB) (mtMember *model.MtMember, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM mt_member
|
||||
WHERE deleted_at = ?
|
||||
LIMIT 1
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
err = GetRow(db, &mtMember, sql, sqlParams)
|
||||
return mtMember, err
|
||||
}
|
||||
|
||||
func GetJobTimers(db *DaoDB, status int) (jobTimers []*model.JobTimer, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM job_timer
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if status != -1 {
|
||||
sql += ` AND status = ?`
|
||||
sqlParams = append(sqlParams, status)
|
||||
}
|
||||
err = GetRows(db, &jobTimers, sql, sqlParams)
|
||||
return jobTimers, err
|
||||
}
|
||||
|
||||
func GetMtMembers(db *DaoDB) (num int, err error) {
|
||||
var mtMembers []*model.MtMember
|
||||
sql := `
|
||||
SELECT * FROM mt_member WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
err = GetRows(db, &mtMembers, sql, sqlParams)
|
||||
num = len(mtMembers)
|
||||
return num, err
|
||||
}
|
||||
|
||||
func GetUserSearch(db *DaoDB, userID, keyword string) (userSearchs []*model.UserSearch, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM user_search
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if userID != "" {
|
||||
sql += " AND user_id = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if keyword != "" {
|
||||
sql += " AND keyword = ?"
|
||||
sqlParams = append(sqlParams, keyword)
|
||||
}
|
||||
err = GetRows(db, &userSearchs, sql, sqlParams)
|
||||
return userSearchs, err
|
||||
}
|
||||
|
||||
func GetStationList(db *DaoDB) (stations []*model.StationInfo, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM station_info
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
err = GetRows(db, &stations, sql, sqlParams)
|
||||
return stations, err
|
||||
}
|
||||
|
||||
func GetStationInfoList(db *DaoDB, stationName string, cityCode int, lat, lng float64, oilCode string, sortType, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
||||
var (
|
||||
stations []*model.StationInfo
|
||||
distanceFlag bool
|
||||
sqlParams = []interface{}{}
|
||||
)
|
||||
if lng != 0 && lat != 0 {
|
||||
distanceFlag = true
|
||||
}
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS *
|
||||
`
|
||||
if distanceFlag {
|
||||
sql += `, getDistance(?, ?, longitude, latitude) distance`
|
||||
sqlParams = append(sqlParams, lng, lat)
|
||||
}
|
||||
sql += `
|
||||
FROM station_info
|
||||
WHERE 1 = 1
|
||||
`
|
||||
if stationName != "" {
|
||||
sql += " AND station_name LIKE ?"
|
||||
sqlParams = append(sqlParams, "%"+stationName+"%")
|
||||
}
|
||||
if cityCode != 0 {
|
||||
sql += " AND city_id = ?"
|
||||
sqlParams = append(sqlParams, cityCode)
|
||||
}
|
||||
if oilCode != "" {
|
||||
sql += " AND POSITION(? IN prices) > 0"
|
||||
sqlParams = append(sqlParams, oilCode)
|
||||
}
|
||||
if sortType != 0 {
|
||||
if sortType == 1 {
|
||||
sql += " ORDER BY distance"
|
||||
} else if sortType == -1 {
|
||||
sql += " ORDER BY distance DESC"
|
||||
} else if sortType == 2 {
|
||||
sql += " ORDER BY star_num"
|
||||
} else if sortType == -2 {
|
||||
sql += " ORDER BY star_num DESC"
|
||||
}
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &stations, sql, sqlParams...); err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
// Data: stations,
|
||||
}
|
||||
for _, v := range stations {
|
||||
var oilInfo []*model.OilInfo
|
||||
json.Unmarshal([]byte(strings.ReplaceAll(v.Prices, "\\", "")), &oilInfo)
|
||||
v.OilInfo = oilInfo
|
||||
}
|
||||
if math.Abs(utils.Int2Float64(sortType)) == 3 {
|
||||
if oilCode != "" {
|
||||
for i := 0; i < len(stations); i++ {
|
||||
for j := 0; j < len(stations)-i-1; j++ {
|
||||
var (
|
||||
index int
|
||||
index2 int
|
||||
)
|
||||
for k, v := range stations[j].OilInfo {
|
||||
if v.OilCode == oilCode {
|
||||
index = k
|
||||
}
|
||||
}
|
||||
for k, v := range stations[j+1].OilInfo {
|
||||
if v.OilCode == oilCode {
|
||||
index2 = k
|
||||
}
|
||||
}
|
||||
if sortType == 3 {
|
||||
if utils.Str2Float64(stations[j].OilInfo[index].DiscountPrice) > utils.Str2Float64(stations[j+1].OilInfo[index2].DiscountPrice) {
|
||||
temp := stations[j]
|
||||
stations[j] = stations[j+1]
|
||||
stations[j+1] = temp
|
||||
}
|
||||
} else if sortType == -3 {
|
||||
if utils.Str2Float64(stations[j].OilInfo[index].DiscountPrice) < utils.Str2Float64(stations[j+1].OilInfo[index2].DiscountPrice) {
|
||||
temp := stations[j]
|
||||
stations[j] = stations[j+1]
|
||||
stations[j+1] = temp
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pagedInfo.Data = stations
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
func GetMaxJobTopSeq(db *DaoDB) (maxSeq int, err error) {
|
||||
Seq := &struct {
|
||||
TopSeq int
|
||||
}{}
|
||||
sql := `
|
||||
SELECT MAX(top_seq) top_seq FROM job WHERE deleted_at = ? AND status = ? AND job_span_top = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue, model.JobStatusDoing, 1}
|
||||
if err = GetRow(db, &Seq, sql, sqlParams); err == nil {
|
||||
return Seq.TopSeq, err
|
||||
}
|
||||
return maxSeq, err
|
||||
}
|
||||
|
||||
func GetMaxJobRecmdSeq(db *DaoDB) (maxSeq int, err error) {
|
||||
Seq := &struct {
|
||||
RecmdSeq int
|
||||
}{}
|
||||
sql := `
|
||||
SELECT MAX(recmd_seq) recmd_seq FROM job WHERE deleted_at = ? AND status = ? AND job_span_recmd = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue, model.JobStatusDoing, 1}
|
||||
if err = GetRow(db, &Seq, sql, sqlParams); err == nil {
|
||||
return Seq.RecmdSeq, err
|
||||
}
|
||||
return maxSeq, err
|
||||
}
|
||||
|
||||
func GetJobSpans(db *DaoDB) (jobSpans []*model.JobSpan, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM job_span
|
||||
WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
err = GetRows(db, &jobSpans, sql, sqlParams)
|
||||
return jobSpans, err
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func GetVendorMatterCategory(db *DaoDB, vendorID int) (vendorMatterCat []*model.VendorMatterCategory, err error) {
|
||||
sql := `
|
||||
SELECT * FROM vendor_matter_category WHERE deleted_at = ? AND vendor_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue, vendorID}
|
||||
err = GetRows(db, &vendorMatterCat, sql, sqlParams)
|
||||
return vendorMatterCat, err
|
||||
}
|
||||
@@ -1,654 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func GetDeliveryOrdersNoPage(db *DaoDB, userIDs []string, statuss []int, fromTime, toTime time.Time, isWeights []int) (dOrders []*model.DeliveryOrder, err error) {
|
||||
sql := `
|
||||
SELECT a.*
|
||||
FROM delivery_order a
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if len(userIDs) > 0 {
|
||||
sql += ` AND a.user_id IN (` + GenQuestionMarks(len(userIDs)) + `)`
|
||||
sqlParams = append(sqlParams, userIDs)
|
||||
}
|
||||
if len(statuss) > 0 {
|
||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
||||
sqlParams = append(sqlParams, statuss)
|
||||
}
|
||||
if len(isWeights) > 0 {
|
||||
sql += ` AND a.is_weight IN (` + GenQuestionMarks(len(isWeights)) + `)`
|
||||
sqlParams = append(sqlParams, isWeights)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
err = GetRows(db, &dOrders, sql, sqlParams)
|
||||
return dOrders, err
|
||||
}
|
||||
|
||||
type GetDeliveryOrdersResult struct {
|
||||
model.DeliveryOrder
|
||||
DeliverySendInfo *UserDeliveryAddressEx `json:"deliverySendInfo"`
|
||||
DeliveryReceiveInfo *UserDeliveryAddressEx `json:"deliveryReceiveInfo"`
|
||||
}
|
||||
|
||||
func GetDeliveryOrders(db *DaoDB, userIDs []string, statuss []int, fromTime, toTime time.Time, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
||||
var dOrders []*GetDeliveryOrdersResult
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS a.*
|
||||
FROM delivery_order a
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if len(userIDs) > 0 {
|
||||
sql += ` AND a.user_id IN (` + GenQuestionMarks(len(userIDs)) + `)`
|
||||
sqlParams = append(sqlParams, userIDs)
|
||||
}
|
||||
if len(statuss) > 0 {
|
||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
||||
sqlParams = append(sqlParams, statuss)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
sql += " ORDER BY a.created_at DESC"
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &dOrders, sql, sqlParams...); err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
// Data: dOrders,
|
||||
}
|
||||
for _, v := range dOrders {
|
||||
if addressList1, _, err := QueryUserDeliveryAddress(db, int64(v.DeliverySendID), nil, 0, 0, 0); err == nil && len(addressList1) > 0 {
|
||||
v.DeliverySendInfo = addressList1[0]
|
||||
} else {
|
||||
sendInfo := &UserDeliveryAddressEx{}
|
||||
sendInfo.ConsigneeName = v.SendName
|
||||
sendInfo.ConsigneeMobile = v.SendMobile
|
||||
sendInfo.Address = v.SendAddress
|
||||
sendInfo.AutoAddress = v.SendAutoAddress
|
||||
sendInfo.CityCode = v.SendCityCode
|
||||
sendInfo.DistrictCode = v.SendDistrictCode
|
||||
sendInfo.DetailAddress = v.SendDetailAddress
|
||||
sendInfo.Lng = v.SendLng
|
||||
sendInfo.Lat = v.SendLat
|
||||
v.DeliverySendInfo = sendInfo
|
||||
}
|
||||
if addressList2, _, err := QueryUserDeliveryAddress(db, int64(v.DeliveryReceiveID), nil, 0, 0, 0); err == nil && len(addressList2) > 0 {
|
||||
v.DeliveryReceiveInfo = addressList2[0]
|
||||
} else {
|
||||
receiveInfo := &UserDeliveryAddressEx{}
|
||||
receiveInfo.ConsigneeName = v.ReceiveName
|
||||
receiveInfo.ConsigneeMobile = v.ReceiveMobile
|
||||
receiveInfo.Address = v.ReceiveAddress
|
||||
receiveInfo.AutoAddress = v.ReceiveAutoAddress
|
||||
receiveInfo.CityCode = v.ReceiveCityCode
|
||||
receiveInfo.DistrictCode = v.ReceiveDistrictCode
|
||||
receiveInfo.DetailAddress = v.ReceiveDetailAddress
|
||||
receiveInfo.Lng = v.ReceiveLng
|
||||
receiveInfo.Lat = v.ReceiveLat
|
||||
v.DeliveryReceiveInfo = receiveInfo
|
||||
}
|
||||
}
|
||||
pagedInfo.Data = dOrders
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
type GetOrdersResult struct {
|
||||
model.Order
|
||||
UserName string `json:"userName"`
|
||||
Mobile string `json:"mobile"`
|
||||
}
|
||||
|
||||
func GetOrders(db *DaoDB, orderID, userID string, orderType int, cityCodes []int, fromTime, toTime time.Time, keyword string, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
||||
var orders []*GetOrdersResult
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS a.*, b.name user_name, b.mobile
|
||||
FROM ` + "`order`" + ` a
|
||||
JOIN user b ON b.user_id = a.user_id AND b.deleted_at = ?
|
||||
WHERE 1 = 1
|
||||
`
|
||||
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if orderID != "" {
|
||||
sql += ` AND a.order_id = ?`
|
||||
sqlParams = append(sqlParams, orderID)
|
||||
}
|
||||
if userID != "" {
|
||||
sql += ` AND a.user_id = ?`
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if orderType != 0 {
|
||||
sql += ` AND a.type = ?`
|
||||
sqlParams = append(sqlParams, orderType)
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += ` AND a.city_code IN (` + GenQuestionMarks(len(cityCodes)) + `)`
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at >= ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND a.created_at <= ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
if keyword != "" {
|
||||
sql += ` AND (b.mobile LIKE ? OR b.name LIKE ?)`
|
||||
sqlParams = append(sqlParams, "%"+keyword+"%", "%"+keyword+"%")
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &orders, sql, sqlParams); err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
Data: orders,
|
||||
}
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
type GetPayStatisticsResult struct {
|
||||
TotalPay int `json:"totalPay"` //支付总额
|
||||
CanCash int `json:"canCash"` //可提现(未提现+申请提现)
|
||||
AccountBalance int `json:"accountBalance"` //未提现(含保证金)
|
||||
SubmitCash int `json:"submitCash"` //申请提现
|
||||
Cashed int `json:"cashed"` //已经体现
|
||||
CashIncome int `json:"cashIncome"` //提现收益
|
||||
TotalIncome int `json:"totalIncome"` //收益总额
|
||||
MemberIncome int `json:"memberIncome"` //会员收益
|
||||
}
|
||||
|
||||
func getFromSql(orderType, status int, alies string, userID string, pop int, cityCodes []int, mobile string, fromTime, toTime time.Time, orderTypes []int) (sql string, sqlParams []interface{}) {
|
||||
sql += `
|
||||
(SELECT SUM(IFNULL(b.pay_price,0)) total_pay
|
||||
FROM user a
|
||||
JOIN ` + "`order` b " + `ON b.user_id = a.user_id AND b.type = ? AND b.status = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, orderType, status)
|
||||
if len(orderTypes) > 0 {
|
||||
sql += ` AND b.order_type IN (` + GenQuestionMarks(len(orderTypes)) + `)`
|
||||
sqlParams = append(sqlParams, orderTypes)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND b.created_at > ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND b.created_at < ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
if mobile != "" {
|
||||
if pop == 1 {
|
||||
sql += " JOIN user e ON e.moblie = ? AND a.pop_user = e.user_id"
|
||||
sqlParams = append(sqlParams, mobile)
|
||||
}
|
||||
}
|
||||
sql += `
|
||||
WHERE a.status = ? AND a.deleted_at = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, model.UserStatusNormal, utils.DefaultTimeValue)
|
||||
if userID != "" {
|
||||
if pop == 1 {
|
||||
sql += " AND a.pop_user = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
} else {
|
||||
sql += " AND a.user_id = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
}
|
||||
if mobile != "" {
|
||||
if pop == 0 {
|
||||
sql += " AND a.mobile = ?"
|
||||
sqlParams = append(sqlParams, mobile)
|
||||
}
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += ` AND a.city_code IN (` + GenQuestionMarks(len(cityCodes)) + `)`
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
sql += `) ` + alies
|
||||
return sql, sqlParams
|
||||
}
|
||||
|
||||
func GetPayStatistics(db *DaoDB, userID string, pop int, cityCodes []int, mobile string, fromTime, toTime time.Time, orderTypes []int) (getPayStatisticsResult *GetPayStatisticsResult, err error) {
|
||||
sqlParams := []interface{}{}
|
||||
sql := `SELECT t1.total_pay, t2.total_pay submit_cash, t3.total_pay cashed, t4.account_balance, t4.account_balance + t2.total_pay can_cash
|
||||
FROM `
|
||||
rSQL1, rSQLParams1 := getFromSql(model.OrderTypePay, model.OrderStatusFinished, "t1", userID, pop, cityCodes, mobile, fromTime, toTime, orderTypes)
|
||||
sql += rSQL1 + ","
|
||||
sqlParams = append(sqlParams, rSQLParams1...)
|
||||
rSQL2, rSQLParams2 := getFromSql(model.OrderTypeCash, model.OrderStatusWait4Pay, "t2", userID, pop, cityCodes, mobile, fromTime, toTime, orderTypes)
|
||||
sql += rSQL2 + ","
|
||||
sqlParams = append(sqlParams, rSQLParams2...)
|
||||
rSQL3, rSQLParams3 := getFromSql(model.OrderTypeCash, model.OrderStatusFinished, "t3", userID, pop, cityCodes, mobile, fromTime, toTime, orderTypes)
|
||||
sql += rSQL3 + ","
|
||||
sqlParams = append(sqlParams, rSQLParams3...)
|
||||
sql += `(SELECT SUM(IFNULL(b.account_balance,0)) account_balance
|
||||
FROM user a
|
||||
JOIN user_bill b ON a.user_id = b.user_id
|
||||
`
|
||||
if mobile != "" {
|
||||
if pop == 1 {
|
||||
sql += " JOIN user e ON e.moblie = ? AND a.pop_user = e.user_id"
|
||||
sqlParams = append(sqlParams, mobile)
|
||||
}
|
||||
}
|
||||
sql += `
|
||||
WHERE 1 = 1
|
||||
`
|
||||
if userID != "" {
|
||||
if pop == 1 {
|
||||
sql += " AND a.pop_user = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
} else {
|
||||
sql += " AND a.user_id = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
}
|
||||
if mobile != "" {
|
||||
if pop == 0 {
|
||||
sql += " AND a.mobile = ?"
|
||||
sqlParams = append(sqlParams, mobile)
|
||||
}
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += ` AND a.city_code IN (` + GenQuestionMarks(len(cityCodes)) + `)`
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
sql += `
|
||||
) t4`
|
||||
err = GetRow(db, &getPayStatisticsResult, sql, sqlParams)
|
||||
sqlParams2 := []interface{}{}
|
||||
getPayStatisticsResult1 := &GetPayStatisticsResult{}
|
||||
sql2 := `
|
||||
SELECT SUM(IFNULL(d.expend_price,0)) member_income
|
||||
FROM user a`
|
||||
if mobile != "" {
|
||||
if pop == 1 {
|
||||
sql2 += " JOIN user e ON e.moblie = ? AND a.pop_user = e.user_id"
|
||||
sqlParams2 = append(sqlParams2, mobile)
|
||||
}
|
||||
}
|
||||
sql2 += `
|
||||
LEFT JOIN user_bill c ON c.user_id = a.user_id
|
||||
LEFT JOIN bill_expend d ON d.bill_id = c.bill_id AND d.type = ?
|
||||
`
|
||||
sqlParams2 = append(sqlParams2, model.BillTypeMember)
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql2 += ` AND d.created_at > ?`
|
||||
sqlParams2 = append(sqlParams2, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql2 += ` AND d.created_at < ?`
|
||||
sqlParams2 = append(sqlParams2, toTime)
|
||||
}
|
||||
sql2 += `
|
||||
WHERE a.status = ? AND a.deleted_at = ?
|
||||
`
|
||||
sqlParams2 = append(sqlParams2, model.UserStatusNormal, utils.DefaultTimeValue)
|
||||
if len(cityCodes) > 0 {
|
||||
sql2 += ` AND a.city_code IN (` + GenQuestionMarks(len(cityCodes)) + `)`
|
||||
sqlParams2 = append(sqlParams2, cityCodes)
|
||||
}
|
||||
if mobile != "" {
|
||||
if pop == 0 {
|
||||
sql2 += " AND a.mobile = ?"
|
||||
sqlParams2 = append(sqlParams2, mobile)
|
||||
}
|
||||
}
|
||||
if userID != "" {
|
||||
if pop == 1 {
|
||||
sql2 += " AND a.pop_user = ?"
|
||||
sqlParams2 = append(sqlParams2, userID)
|
||||
} else {
|
||||
sql2 += " AND a.user_id = ?"
|
||||
sqlParams2 = append(sqlParams2, userID)
|
||||
}
|
||||
}
|
||||
err = GetRow(db, &getPayStatisticsResult1, sql2, sqlParams2)
|
||||
getPayStatisticsResult.MemberIncome = getPayStatisticsResult1.MemberIncome
|
||||
getPayStatisticsResult.CashIncome = getPayStatisticsResult.Cashed / 10
|
||||
getPayStatisticsResult.TotalIncome = getPayStatisticsResult.MemberIncome + getPayStatisticsResult.CashIncome
|
||||
return getPayStatisticsResult, err
|
||||
}
|
||||
|
||||
type GetManageStatisticsResult struct {
|
||||
Date time.Time `json:"date"` //日期
|
||||
BrowseCount int `json:"browseCount"` //点击次数
|
||||
AcceptCount int `json:"acceptCount"` //接受任务数
|
||||
FinishCount int `json:"finishCount"` //完成任务数
|
||||
CancelCount int `json:"cancelCount"` //取消任务数
|
||||
TotalCash int `json:"totalCash"` //返现总额
|
||||
InversionRate float64 `json:"inversionRate"` //转化率
|
||||
}
|
||||
|
||||
func getFromSqlManage(status int, alies string, cityCodes []int, jobTime, endTime time.Time, jobIDs []int) (sql string, sqlParams []interface{}) {
|
||||
sql += `
|
||||
(SELECT COUNT(b.id) count
|
||||
FROM job a
|
||||
JOIN job_order b ON a.id = b.job_id
|
||||
WHERE a.deleted_at = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
if status != 0 {
|
||||
sql += " AND b.status = ?"
|
||||
sqlParams = append(sqlParams, status)
|
||||
}
|
||||
if jobTime != utils.ZeroTimeValue {
|
||||
sql += " AND a.created_at > ?"
|
||||
sqlParams = append(sqlParams, jobTime)
|
||||
}
|
||||
if endTime != utils.ZeroTimeValue {
|
||||
sql += " AND a.created_at < ?"
|
||||
sqlParams = append(sqlParams, endTime)
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += ` AND a.job_city_code IN (` + GenQuestionMarks(len(cityCodes)) + `)`
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
if len(jobIDs) > 0 {
|
||||
sql += ` AND a.id IN (` + GenQuestionMarks(len(jobIDs)) + `)`
|
||||
sqlParams = append(sqlParams, jobIDs)
|
||||
}
|
||||
sql += ") " + alies
|
||||
return sql, sqlParams
|
||||
}
|
||||
|
||||
func getWhereSqlManage(cityCodes []int, jobTime, endTime time.Time, jobIDs []int) (sql string, sqlParams []interface{}) {
|
||||
if jobTime != utils.ZeroTimeValue {
|
||||
sql += " AND a.created_at > ?"
|
||||
sqlParams = append(sqlParams, jobTime)
|
||||
}
|
||||
if endTime != utils.ZeroTimeValue {
|
||||
sql += " AND a.created_at < ?"
|
||||
sqlParams = append(sqlParams, endTime)
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += ` AND a.job_city_code IN (` + GenQuestionMarks(len(cityCodes)) + `)`
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
if len(jobIDs) > 0 {
|
||||
sql += ` AND a.id IN (` + GenQuestionMarks(len(jobIDs)) + `)`
|
||||
sqlParams = append(sqlParams, jobIDs)
|
||||
}
|
||||
return sql, sqlParams
|
||||
}
|
||||
|
||||
func GetManageStatistics(db *DaoDB, cityCodes []int, jobTime time.Time, jobIDs []int) (getManageStatisticsResult *GetManageStatisticsResult, err error) {
|
||||
endTime := jobTime.AddDate(0, 0, 1)
|
||||
sqlParams := []interface{}{}
|
||||
sql := `
|
||||
SELECT t1.count accept_count, t2.count finish_count, t3.count cancel_count, t4.browse_count, t6.total_cash
|
||||
FROM
|
||||
`
|
||||
rSQL1, rSQLparams1 := getFromSqlManage(model.JobOrderStatusAccept, "t1", cityCodes, jobTime, endTime, jobIDs)
|
||||
sql += rSQL1 + ","
|
||||
sqlParams = append(sqlParams, rSQLparams1...)
|
||||
rSQL2, rSQLparams2 := getFromSqlManage(model.JobOrderStatusFinish, "t2", cityCodes, jobTime, endTime, jobIDs)
|
||||
sql += rSQL2 + ","
|
||||
sqlParams = append(sqlParams, rSQLparams2...)
|
||||
rSQL3, rSQLparams3 := getFromSqlManage(model.JobOrderStatusCancel, "t3", cityCodes, jobTime, endTime, jobIDs)
|
||||
sql += rSQL3 + ","
|
||||
sqlParams = append(sqlParams, rSQLparams3...)
|
||||
sql += `
|
||||
(SELECT SUM(a.browse_count) browse_count
|
||||
FROM job a
|
||||
JOIN job_order b ON a.id = b.job_id
|
||||
WHERE a.deleted_at = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
rSQL4, rSQLparams4 := getWhereSqlManage(cityCodes, jobTime, endTime, jobIDs)
|
||||
sql += rSQL4
|
||||
sqlParams = append(sqlParams, rSQLparams4...)
|
||||
sql += `
|
||||
) t4,
|
||||
`
|
||||
sql += `
|
||||
(SELECT t5.count * a.avg_price total_cash FROM job a,
|
||||
(SELECT COUNT(b.id) count, a.id
|
||||
FROM job a
|
||||
JOIN job_order b ON a.id = b.job_id
|
||||
WHERE a.deleted_at = ? AND b.status = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, model.JobOrderStatusFinish)
|
||||
rSQL5, rSQLparams5 := getWhereSqlManage(cityCodes, jobTime, endTime, jobIDs)
|
||||
sql += rSQL5
|
||||
sqlParams = append(sqlParams, rSQLparams5...)
|
||||
sql += `
|
||||
GROUP BY 2) t5
|
||||
WHERE a.id = t5.id
|
||||
)t6
|
||||
`
|
||||
GetRow(db, &getManageStatisticsResult, sql, sqlParams)
|
||||
if getManageStatisticsResult == nil {
|
||||
return &GetManageStatisticsResult{
|
||||
Date: jobTime,
|
||||
}, err
|
||||
} else {
|
||||
getManageStatisticsResult.Date = jobTime
|
||||
if getManageStatisticsResult.BrowseCount == 0 {
|
||||
getManageStatisticsResult.InversionRate = 0
|
||||
} else {
|
||||
getManageStatisticsResult.InversionRate = float64(getManageStatisticsResult.FinishCount) / float64(getManageStatisticsResult.BrowseCount)
|
||||
}
|
||||
return getManageStatisticsResult, err
|
||||
}
|
||||
}
|
||||
|
||||
type GetManageStatisticsJobResult struct {
|
||||
BrowseCount int `json:"browseCount"` //点击次数
|
||||
AcceptCount int `json:"acceptCount"` //接受任务数
|
||||
FinishCount int `json:"finishCount"` //完成任务数
|
||||
CancelCount int `json:"cancelCount"` //取消任务数
|
||||
TotalCash int `json:"totalCash"` //返现总额
|
||||
InversionRate float64 `json:"inversionRate"` //转化率
|
||||
Title string `json:"title"` //任务标题
|
||||
}
|
||||
|
||||
func GetManageStatisticsJob(db *DaoDB, cityCodes []int, fromTime, toTime time.Time, jobIDs []int, offset, pageSize int) (pageInfo *model.PagedInfo, err error) {
|
||||
var (
|
||||
sqlParams = []interface{}{}
|
||||
getManageStatisticsJobResult []*GetManageStatisticsJobResult
|
||||
)
|
||||
sql := `
|
||||
SELECT t1.count acceptCount, t2.count finish_count, t3.count cancel_count, a.browse_count, a.title, a.browse_count / t2.count inversion_rate, t4.total_cash
|
||||
FROM job a
|
||||
LEFT JOIN (SELECT job_id, COUNT(*) count FROM job_order WHERE status = ? GROUP BY 1) t1 ON t1.job_id = a.id
|
||||
LEFT JOIN (SELECT job_id, COUNT(*) count FROM job_order WHERE status = ? GROUP BY 1) t2 ON t2.job_id = a.id
|
||||
LEFT JOIN (SELECT job_id, COUNT(*) count FROM job_order WHERE status = ? GROUP BY 1) t3 ON t3.job_id = a.id
|
||||
`
|
||||
sql += `
|
||||
LEFT JOIN (SELECT COUNT(b.id) * a.avg_price total_cash, a.id
|
||||
FROM job a
|
||||
JOIN job_order b ON a.id = b.job_id AND b.status = ?
|
||||
GROUP BY 2) t4 ON t4.id = a.id
|
||||
`
|
||||
sqlParams = append(sqlParams, model.JobOrderStatusAccept, model.JobOrderStatusFinish, model.JobOrderStatusCancel, model.JobOrderStatusFinish)
|
||||
sql += " WHERE a.deleted_at = ?"
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
rSQL, rSQLparams := getWhereSqlManage(cityCodes, fromTime, toTime, jobIDs)
|
||||
sql += rSQL
|
||||
sqlParams = append(sqlParams, rSQLparams...)
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
err = GetRowsTx(txDB, &getManageStatisticsJobResult, sql, sqlParams)
|
||||
if err == nil {
|
||||
pageInfo = &model.PagedInfo{
|
||||
Data: getManageStatisticsJobResult,
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
}
|
||||
}
|
||||
return pageInfo, err
|
||||
}
|
||||
|
||||
func GetUnionOrders(db *DaoDB, vendorIDs, statuss []int, beginTime, endTime time.Time, isEarning int) (orders []*model.UnionOrder, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM union_order
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += ` AND vendor_id IN (` + GenQuestionMarks(len(vendorIDs)) + `)`
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
if len(statuss) > 0 {
|
||||
sql += ` AND status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
||||
sqlParams = append(sqlParams, statuss)
|
||||
}
|
||||
if !utils.IsTimeZero(beginTime) {
|
||||
sql += ` AND order_settle_at > ?`
|
||||
sqlParams = append(sqlParams, beginTime)
|
||||
}
|
||||
if !utils.IsTimeZero(endTime) {
|
||||
sql += ` AND order_settle_at < ?`
|
||||
sqlParams = append(sqlParams, endTime)
|
||||
}
|
||||
if isEarning != -1 {
|
||||
sql += ` AND is_earning = ?`
|
||||
sqlParams = append(sqlParams, isEarning)
|
||||
}
|
||||
err = GetRows(db, &orders, sql, sqlParams)
|
||||
return orders, err
|
||||
}
|
||||
|
||||
func GetUnionOrdersByIDs(db *DaoDB, vendorOrderIDs []string, vendorID int) (orders []*model.UnionOrder, err error) {
|
||||
if len(vendorOrderIDs) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM union_order
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if len(vendorOrderIDs) > 0 {
|
||||
sql += ` AND vendor_order_id IN (` + GenQuestionMarks(len(vendorOrderIDs)) + `)`
|
||||
sqlParams = append(sqlParams, vendorOrderIDs)
|
||||
}
|
||||
if vendorID != 0 {
|
||||
sql += ` AND vendor_id = ?`
|
||||
sqlParams = append(sqlParams, vendorID)
|
||||
}
|
||||
err = GetRows(db, &orders, sql, sqlParams)
|
||||
return orders, err
|
||||
}
|
||||
|
||||
func GetMyUnionOrders(db *DaoDB, userID string, statuss []int, vendorID, offset, pageSize int) (page *model.PagedInfo, err error) {
|
||||
var orders []*model.UnionOrder
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS a.*
|
||||
FROM union_order a
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if vendorID != -1 {
|
||||
sql += ` AND a.vendor_id = ?`
|
||||
sqlParams = append(sqlParams, vendorID)
|
||||
}
|
||||
if len(statuss) > 0 {
|
||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
||||
sqlParams = append(sqlParams, statuss)
|
||||
}
|
||||
if userID != "" {
|
||||
sql += ` AND a.user_id = ?`
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
sql += " ORDER BY a.created_at DESC"
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &orders, sql, sqlParams...); err == nil {
|
||||
page = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
Data: orders,
|
||||
}
|
||||
}
|
||||
return page, err
|
||||
}
|
||||
|
||||
type GetUnionOrdersPageResult struct {
|
||||
model.UnionOrder
|
||||
Name string `json:"name"`
|
||||
Moble string `json:"moble"`
|
||||
}
|
||||
|
||||
func GetUnionOrdersPage(db *DaoDB, vendorIDs, statuss []int, beginTime, endTime time.Time, keyword string, offset, pageSize int) (page *model.PagedInfo, err error) {
|
||||
var orders []*GetUnionOrdersPageResult
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS a.*, b.name, b.mobile
|
||||
FROM union_order a
|
||||
LEFT JOIN user b ON a.user_id = b.user_id
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += ` AND a.vendor_id IN (` + GenQuestionMarks(len(vendorIDs)) + `)`
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
if len(statuss) > 0 {
|
||||
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
|
||||
sqlParams = append(sqlParams, statuss)
|
||||
}
|
||||
if !utils.IsTimeZero(beginTime) {
|
||||
sql += ` AND a.order_settle_at > ?`
|
||||
sqlParams = append(sqlParams, beginTime)
|
||||
}
|
||||
if !utils.IsTimeZero(endTime) {
|
||||
sql += ` AND a.order_settle_at < ?`
|
||||
sqlParams = append(sqlParams, endTime)
|
||||
}
|
||||
if keyword != "" {
|
||||
keywordLike := "%" + keyword + "%"
|
||||
sql += ` AND (b.name LIKE ? OR b.mobile LIKE ? OR a.vendor_order_id LIKE ? OR a.goods_name LIKE ? OR a.comment LIKE ?)`
|
||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &orders, sql, sqlParams...); err == nil {
|
||||
page = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
Data: orders,
|
||||
}
|
||||
}
|
||||
return page, err
|
||||
}
|
||||
@@ -1,437 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type UserDeliveryAddressEx struct {
|
||||
model.UserDeliveryAddress
|
||||
|
||||
UserName string `json:"userName"`
|
||||
CityName string `json:"cityName"`
|
||||
DistrictName string `json:"districtName"`
|
||||
ParentCode int `json:"parentCode"`
|
||||
}
|
||||
|
||||
type GetSelfInfoResult struct {
|
||||
model.User
|
||||
model.UserBill
|
||||
WaitCashPrice int `json:"waitCashPrice"`
|
||||
WaitRealCashPrice int `json:"waitRealCashPrice"`
|
||||
UserMembers []*model.UserMember `json:"userMembers"`
|
||||
PopedUserName string `json:"popedUserName"`
|
||||
UnReadMessageCount int `json:"unReadMessageCount"`
|
||||
}
|
||||
|
||||
func GetUserByID(db *DaoDB, fieldName, fieldValue string) (user *model.User, err error) {
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT *
|
||||
FROM user t1
|
||||
WHERE t1.deleted_at = ? AND t1.status = ? AND t1.%s = ?
|
||||
`, fieldName)
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
model.UserStatusNormal,
|
||||
fieldValue,
|
||||
}
|
||||
// globals.SugarLogger.Debugf("GetUserByID sql:%s, sqlParams:%s", sql, utils.Format4Output(sqlParams, false))
|
||||
err = GetRow(db, &user, sql, sqlParams...)
|
||||
return user, err
|
||||
}
|
||||
|
||||
func GetUserByIDWithMembers(db *DaoDB, fieldName, fieldValue string) (getSelfInfoResult *GetSelfInfoResult, err error) {
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT t1.*, t2.bill_id, t2.account_balance, t3.name pop_user_name
|
||||
FROM user t1
|
||||
JOIN user_bill t2 ON t2.user_id = t1.user_id AND t2.deleted_at = ?
|
||||
LEFT JOIN user t3 ON t3.user_id = t1.pop_user
|
||||
WHERE t1.deleted_at = ? AND t1.status = ? AND t1.%s = ?
|
||||
`, fieldName)
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
model.UserStatusNormal,
|
||||
fieldValue,
|
||||
}
|
||||
// globals.SugarLogger.Debugf("GetUserByID sql:%s, sqlParams:%s", sql, utils.Format4Output(sqlParams, false))
|
||||
err = GetRow(db, &getSelfInfoResult, sql, sqlParams...)
|
||||
if messageGroupReads, err := GetMessageGroupRead(db, getSelfInfoResult.User.UserID, 0); err == nil {
|
||||
var unReadCount int
|
||||
for _, v := range messageGroupReads {
|
||||
unReadCount += v.UnReadCount
|
||||
}
|
||||
getSelfInfoResult.UnReadMessageCount = unReadCount
|
||||
}
|
||||
return getSelfInfoResult, err
|
||||
}
|
||||
|
||||
func GetUsers(db *DaoDB, userType int, keyword, popUser string, userIDs, userID2s, mobiles []string, offset, pageSize int) (userList []*model.User, totalCount int, err error) {
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
if userType == 0 {
|
||||
userType = 255
|
||||
}
|
||||
sqlParams := []interface{}{}
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
t1.*
|
||||
FROM user t1
|
||||
WHERE t1.status = 1 AND t1.deleted_at = ?`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
if len(userIDs) > 0 {
|
||||
sql += " AND t1.user_id IN (" + GenQuestionMarks(len(userIDs)) + ")"
|
||||
sqlParams = append(sqlParams, userIDs)
|
||||
}
|
||||
if len(userID2s) > 0 {
|
||||
sql += " AND t1.user_id2 IN (" + GenQuestionMarks(len(userID2s)) + ")"
|
||||
sqlParams = append(sqlParams, userID2s)
|
||||
}
|
||||
if len(mobiles) > 0 {
|
||||
sql += " AND t1.mobile IN (" + GenQuestionMarks(len(mobiles)) + ")"
|
||||
sqlParams = append(sqlParams, mobiles)
|
||||
}
|
||||
if popUser != "" {
|
||||
sql += " AND t1.pop_user = ?"
|
||||
sqlParams = append(sqlParams, popUser)
|
||||
}
|
||||
if keyword != "" {
|
||||
keywordLike := "%" + keyword + "%"
|
||||
sql += " AND (t1.user_id LIKE ? OR t1.user_id2 LIKE ? OR t1.mobile LIKE ? OR t1.email LIKE ? OR t1.name LIKE ?)"
|
||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &userList, sql, sqlParams...); err == nil {
|
||||
totalCount = GetLastTotalRowCountTx(txDB)
|
||||
}
|
||||
return userList, totalCount, err
|
||||
}
|
||||
|
||||
func GetUsers2(db *DaoDB, keyword string, userID string, pop int, mobile string, fromTime, toTime time.Time, timeType int, cityCodes, consumeTypes []int, offset, pageSize int) (pageInfo *model.PagedInfo, err error) {
|
||||
var (
|
||||
userList []*model.User
|
||||
)
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams := []interface{}{}
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS DISTINCT
|
||||
a.*
|
||||
FROM user a`
|
||||
for _, v := range consumeTypes {
|
||||
switch v {
|
||||
case model.ConsumeTypePublishJob:
|
||||
sql += " JOIN job b ON b.user_id = a.user_id"
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
if timeType == 2 {
|
||||
sql += " AND b.created_at > ?"
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
if timeType == 2 {
|
||||
sql += " AND b.created_at < ?"
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
}
|
||||
case model.ConsumeTypeMember:
|
||||
sql += " JOIN user_member c ON c.user_id = a.user_id"
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
if timeType == 2 {
|
||||
sql += " AND c.created_at > ?"
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
if timeType == 2 {
|
||||
sql += " AND c.created_at < ?"
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
}
|
||||
case model.ConsumeTypeDelivery:
|
||||
sql += " JOIN delivery_order d ON d.user_id = a.user_id"
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
if timeType == 2 {
|
||||
sql += " AND d.created_at > ?"
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
if timeType == 2 {
|
||||
sql += " AND d.created_at < ?"
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sql += `
|
||||
WHERE a.status = 1 AND a.deleted_at = ?`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
if userID != "" {
|
||||
if pop == 1 {
|
||||
sql += " AND a.pop_user = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
} else {
|
||||
sql += " AND a.user_id = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += " AND a.city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")"
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
if mobile != "" {
|
||||
sql += " AND a.mobile = ?"
|
||||
sqlParams = append(sqlParams, mobile)
|
||||
}
|
||||
if keyword != "" {
|
||||
keywordLike := "%" + keyword + "%"
|
||||
sql += " AND (a.user_id LIKE ? OR a.mobile LIKE ? OR a.email LIKE ? OR a.name LIKE ?)"
|
||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
if timeType == 1 {
|
||||
sql += " AND a.created_at > ?"
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
if timeType == 1 {
|
||||
sql += " AND a.created_at < ?"
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &userList, sql, sqlParams...); err == nil {
|
||||
pageInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCountTx(txDB),
|
||||
Data: userList,
|
||||
}
|
||||
}
|
||||
return pageInfo, err
|
||||
}
|
||||
|
||||
func GetUser(db *DaoDB, userID string) (user *model.GetUserResult, err error) {
|
||||
sqlParams := []interface{}{}
|
||||
sql := `
|
||||
SELECT
|
||||
t1.*, IF(t2.accept_order_count is NULL, 0, t2.accept_order_count) accept_order_count, IF(t3.finished_order_count is NULL, 0, t3.finished_order_count) finished_order_count
|
||||
FROM user t1
|
||||
LEFT JOIN (SELECT user_id, COUNT(user_id) accept_order_count FROM job_order WHERE user_id = ? GROUP BY 1)t2 ON t2.user_id = t1.user_id
|
||||
LEFT JOIN (SELECT user_id, COUNT(user_id) finished_order_count FROM job_order WHERE user_id = ? AND status = ? GROUP BY 1)t3 ON t3.user_id = t1.user_id
|
||||
WHERE t1.status = ? AND t1.deleted_at = ? AND t1.user_id = ? `
|
||||
sqlParams = append(sqlParams, userID, userID, model.JobOrderStatusFinish, model.YES, utils.DefaultTimeValue, userID)
|
||||
err = GetRow(db, &user, sql, sqlParams...)
|
||||
return user, err
|
||||
}
|
||||
|
||||
func DeleteUsers(db *DaoDB, userIDs []string) (num int64, err error) {
|
||||
if len(userIDs) > 0 {
|
||||
sql := `
|
||||
UPDATE user t1
|
||||
JOIN auth_bind t2 ON t2.user_id = t1.user_id
|
||||
SET
|
||||
t1.deleted_at = ?,
|
||||
t2.deleted_at = ?
|
||||
WHERE t1.user_id IN (` + GenQuestionMarks(len(userIDs)) + ");"
|
||||
now := time.Now()
|
||||
sqlParams := []interface{}{
|
||||
now,
|
||||
now,
|
||||
userIDs,
|
||||
}
|
||||
num, err = ExecuteSQL(db, sql, sqlParams...)
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
func QueryUserDeliveryAddress(db *DaoDB, addressID int64, userIDs []string, addType int, offset, pageSize int) (addressList []*UserDeliveryAddressEx, totalCount int, err error) {
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
t1.*,
|
||||
t2.name user_name,
|
||||
district.name district_name,
|
||||
city.name city_name,
|
||||
cp.code parent_code
|
||||
FROM user_delivery_address t1
|
||||
LEFT JOIN user t2 ON t2.user_id = t1.user_id
|
||||
LEFT JOIN place district ON district.code = t1.district_code
|
||||
LEFT JOIN place city ON city.code = t1.city_code
|
||||
LEFT JOIN place cp ON cp.code = city.parent_code
|
||||
WHERE t1.deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if addressID > 0 {
|
||||
sql += " AND t1.id = ? "
|
||||
sqlParams = append(sqlParams, addressID)
|
||||
}
|
||||
if len(userIDs) > 0 {
|
||||
sql += " AND t1.user_id IN (" + GenQuestionMarks(len(userIDs)) + ")"
|
||||
sqlParams = append(sqlParams, userIDs)
|
||||
}
|
||||
if addType != 0 {
|
||||
sql += " AND t1.type = ? "
|
||||
sqlParams = append(sqlParams, addType)
|
||||
}
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sql += `
|
||||
ORDER BY t1.is_default DESC, t1.consignee_name
|
||||
LIMIT ? OFFSET ?`
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRowsTx(txDB, &addressList, sql, sqlParams...); err == nil {
|
||||
totalCount = GetLastTotalRowCountTx(txDB)
|
||||
}
|
||||
return addressList, totalCount, err
|
||||
}
|
||||
|
||||
func ClearUserDeliveryAddressDefault(db *DaoDB, userID string, defAddressID int) (err error) {
|
||||
sql := `
|
||||
UPDATE user_delivery_address t1
|
||||
SET t1.is_default = 0
|
||||
WHERE t1.deleted_at = ? AND t1.user_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
userID,
|
||||
}
|
||||
if defAddressID > 0 {
|
||||
sql += " AND t1.id <> ?"
|
||||
sqlParams = append(sqlParams, defAddressID)
|
||||
}
|
||||
_, err = ExecuteSQL(db, sql, sqlParams...)
|
||||
return err
|
||||
}
|
||||
|
||||
func GetUserOrderSMS(db *DaoDB, mobile, name string) (userOrderSms *model.UserOrderSms, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM user_order_sms
|
||||
WHERE 1=1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if mobile != "" {
|
||||
sql += " AND mobile = ?"
|
||||
sqlParams = append(sqlParams, mobile)
|
||||
}
|
||||
if name != "" {
|
||||
sql += " AND name like ?"
|
||||
sqlParams = append(sqlParams, "%"+name+"%")
|
||||
}
|
||||
err = GetRow(db, &userOrderSms, sql, sqlParams)
|
||||
return userOrderSms, err
|
||||
}
|
||||
|
||||
func GetUserMember(db *DaoDB, userID string, memberType int) (userMembers []*model.UserMember, err error) {
|
||||
sql := `
|
||||
SELECT a.*
|
||||
FROM user_member a
|
||||
WHERE a.deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
if userID != "" {
|
||||
sql += " AND a.user_id = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if memberType != 0 {
|
||||
sql += " AND a.member_type = ?"
|
||||
sqlParams = append(sqlParams, memberType)
|
||||
}
|
||||
err = GetRows(db, &userMembers, sql, sqlParams)
|
||||
return userMembers, err
|
||||
}
|
||||
|
||||
type GetUserAllWaitCashPriceResult struct {
|
||||
UserID string `orm:"column(user_id)" json:"userID"`
|
||||
Price int `json:"price"`
|
||||
}
|
||||
|
||||
func GetUserAllWaitCashPrice(db *DaoDB, userID string) (price int, err error) {
|
||||
var result = &GetUserAllWaitCashPriceResult{}
|
||||
sql := `
|
||||
SELECT SUM(IF(d.id IS NOT NULL, IF(d.divide_percentage = 0, b.avg_price, b.avg_price*(100-d.divide_percentage)/100),b.avg_price)) price, a.user_id
|
||||
FROM job_order a
|
||||
JOIN job b ON a.job_id = b.id
|
||||
LEFT JOIN message_group_member c ON a.user_id = c.member_user_id
|
||||
LEFT JOIN message_group d ON d.group_id = c.group_id AND d.type = ?
|
||||
WHERE a.user_id = ?
|
||||
AND a.status = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
model.GroupTypeMulit,
|
||||
userID,
|
||||
model.JobOrderStatusWaitAudit,
|
||||
}
|
||||
err = GetRow(db, &result, sql, sqlParams)
|
||||
return result.Price, err
|
||||
}
|
||||
|
||||
func GetUserAllWaitRealCashPrice(db *DaoDB, userID string) (price int, err error) {
|
||||
var result = &GetUserAllWaitCashPriceResult{}
|
||||
sql := `
|
||||
SELECT SUM(pay_price) price FROM ` + "`order`" + ` WHERE user_id = ? AND status = ? AND type = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
userID,
|
||||
model.OrderStatusWait4Pay,
|
||||
model.OrderTypeCash,
|
||||
}
|
||||
err = GetRow(db, &result, sql, sqlParams)
|
||||
return result.Price, err
|
||||
}
|
||||
func GetUserUnionBind(db *DaoDB, userID string, vendorID int, unionID string) (userBinds []*model.UserUnionBind, err error) {
|
||||
sql := `
|
||||
SELECT * FROM user_union_bind WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if userID != "" {
|
||||
sql += " AND user_id = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if vendorID != -1 {
|
||||
sql += " AND vendor_id = ?"
|
||||
sqlParams = append(sqlParams, vendorID)
|
||||
}
|
||||
if unionID != "" {
|
||||
sql += " AND union_id = ?"
|
||||
sqlParams = append(sqlParams, unionID)
|
||||
}
|
||||
err = GetRows(db, &userBinds, sql, sqlParams)
|
||||
return userBinds, err
|
||||
}
|
||||
|
||||
func GetUserUnionBindImg(db *DaoDB, unionID, actID string) (userBinds *model.UserUnionBindImg, err error) {
|
||||
sql := `
|
||||
SELECT * FROM user_union_bind_img WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if unionID != "" {
|
||||
sql += " AND union_id = ?"
|
||||
sqlParams = append(sqlParams, unionID)
|
||||
}
|
||||
if actID != "" {
|
||||
sql += " AND act_id = ?"
|
||||
sqlParams = append(sqlParams, actID)
|
||||
}
|
||||
err = GetRow(db, &userBinds, sql, sqlParams)
|
||||
return userBinds, err
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
func TestGetUsers(t *testing.T) {
|
||||
userList, _, err := GetUsers(GetDB(), 0, "", nil, nil, []string{"18180948107"}, 0, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(userList, false))
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func GetMenu(db *DaoDB, name string, level int, userID string) (menus []*model.Menu, err error) {
|
||||
sqlParams := []interface{}{}
|
||||
sql := `
|
||||
SELECT DISTINCT a.*
|
||||
FROM menu a
|
||||
`
|
||||
if userID != "" {
|
||||
sql += `
|
||||
JOIN menu d ON d.parent_id = a.id
|
||||
JOIN user_role b ON b.user_id = ?
|
||||
JOIN role_menu c ON c.menu_id = d.id AND c.role_id = b.role_id
|
||||
`
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
sql += " WHERE a.deleted_at = ?"
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
if name != "" {
|
||||
sql += " AND a.name LIKE ?"
|
||||
sqlParams = append(sqlParams, "%"+name+"%")
|
||||
}
|
||||
if level != 0 {
|
||||
sql += " AND a.level = ?"
|
||||
sqlParams = append(sqlParams, level)
|
||||
}
|
||||
err = GetRows(db, &menus, sql, sqlParams)
|
||||
return menus, err
|
||||
}
|
||||
|
||||
func GetMenuWithUser(db *DaoDB, name string, level int, userID string) (menus []*model.Menu, err error) {
|
||||
sql := `
|
||||
SELECT DISTINCT b.* FROM (
|
||||
SELECT a.id,a.parent_id
|
||||
FROM menu a
|
||||
JOIN user_role b ON b.user_id = ?
|
||||
JOIN role_menu c ON c.menu_id = a.id AND c.role_id = b.role_id
|
||||
WHERE a.deleted_at = ?)a
|
||||
JOIN menu b ON (b.id = a.id OR b.id = a.parent_id)
|
||||
`
|
||||
sqlParams := []interface{}{userID, utils.DefaultTimeValue}
|
||||
err = GetRows(db, &menus, sql, sqlParams)
|
||||
return menus, err
|
||||
}
|
||||
|
||||
func GetRole(db *DaoDB, name string) (roles []*model.Role, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM role
|
||||
WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if name != "" {
|
||||
sql += " AND name LIKE ?"
|
||||
sqlParams = append(sqlParams, "%"+name+"%")
|
||||
}
|
||||
err = GetRows(db, &roles, sql, sqlParams)
|
||||
return roles, err
|
||||
}
|
||||
|
||||
func GetUserRole(db *DaoDB, userIDs []string, roleIDs []int) (userRoles []*model.UserRole, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM user_role
|
||||
WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if len(userIDs) > 0 {
|
||||
sql += " AND user_id IN (" + GenQuestionMarks(len(userIDs)) + ")"
|
||||
sqlParams = append(sqlParams, userIDs)
|
||||
}
|
||||
if len(roleIDs) > 0 {
|
||||
sql += " AND role_id IN (" + GenQuestionMarks(len(roleIDs)) + ")"
|
||||
sqlParams = append(sqlParams, roleIDs)
|
||||
}
|
||||
err = GetRows(db, &userRoles, sql, sqlParams)
|
||||
return userRoles, err
|
||||
}
|
||||
|
||||
func GetRoleMenu(db *DaoDB, roleIDs, menuIDs []int) (roleMenus []*model.RoleMenu, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM role_menu
|
||||
WHERE deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if len(roleIDs) > 0 {
|
||||
sql += " AND role_id IN (" + GenQuestionMarks(len(roleIDs)) + ")"
|
||||
sqlParams = append(sqlParams, roleIDs)
|
||||
}
|
||||
if len(menuIDs) > 0 {
|
||||
sql += " AND menu_id IN (" + GenQuestionMarks(len(menuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, menuIDs)
|
||||
}
|
||||
err = GetRows(db, &roleMenus, sql, sqlParams)
|
||||
return roleMenus, err
|
||||
}
|
||||
@@ -5,21 +5,17 @@ import "errors"
|
||||
const (
|
||||
ErrorCodeIgnore = "ignore"
|
||||
|
||||
ErrCodeSuccess = "0"
|
||||
ErrCodePoint = "1"
|
||||
ErrCodeGeneralFailed = "-1"
|
||||
ErrCodeTokenIsInvalid = "-2"
|
||||
ErrCodeUserNotExist = "-3"
|
||||
ErrCodeUserAlreadyExist = "-4" // 用户已经存在错,但不能成功登录
|
||||
ErrCodeSuccess = "0"
|
||||
ErrCodeGeneralFailed = "-1"
|
||||
ErrCodeTokenIsInvalid = "-2"
|
||||
|
||||
ErrCodeJsonActSkuConflict = "-101" // 这个错误号表示description中的是一个json对象,不是错误文本
|
||||
ErrCodeJsonActPriceTooLarger = "-102" // 这个错误号表示description中的是一个json对象,不是错误文本
|
||||
ErrCodeJsonActEarningPriceIsZero = "-103"
|
||||
ErrCodeJsonUserAlreadyExist = "-104" // 用户已经存在错,且能成功登录
|
||||
ErrCodeJsonSyncErr = "-105"
|
||||
ErrCodeJsonSyncErr = "-105"
|
||||
|
||||
ErrCodeAccountBalanceNotEnough = "-201" //余额不足
|
||||
ErrCodeNotAuthBindWeixin = "-202" //没有绑定微信认证方式
|
||||
ErrCodeOpenAPIParamErrMethod = "-1001" //参数错误,method
|
||||
ErrCodeOpenAPIParamErrTimeStamp = "-1002" //参数错误,timestamp
|
||||
ErrCodeOpenAPIParamErrSign = "-1003" //参数错误,sign
|
||||
|
||||
ErrCodeOpenAPIParamErrNormal = "-1000" //api非通用参数错误
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -1,340 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/txcloudapi"
|
||||
)
|
||||
|
||||
const (
|
||||
JobStatusDoing = 0 //正在进行中
|
||||
JobStatusFinished = 1 //任务所有都被完成
|
||||
JobStatusFailed = -1 //任务发布失败
|
||||
JobStatusOverdue = -2 //任务过期
|
||||
|
||||
JobLimitCountTypePO = 1 //每人一次
|
||||
JobLimitCountTypePDO = 2 //每人每天一次
|
||||
JobLimitCountTypePWO = 3 //每人每周一次
|
||||
JobLimitCountTypeNoLimit = 4 //不限制
|
||||
|
||||
JobOrderStatusSpec = 1 //特殊状态(联盟任务)
|
||||
JobOrderStatusAccept = 5
|
||||
JobOrderStatusWaitAudit = 10
|
||||
JobOrderStatusAuditPass = 15
|
||||
JobOrderStatusAuditUnPass = 20
|
||||
JobOrderStatusFinish = 110
|
||||
JobOrderStatusCancel = 115
|
||||
|
||||
JobTimerTypeAccept = 1 //接受任务
|
||||
JobTimerTypeSubmit = 2 //交任务
|
||||
JobTimerTypeDropShipping = 3 //一件代发限时发货
|
||||
|
||||
JobTimerStatusWait = 0 //正在进行
|
||||
JobTimerStatusFinish = 1 //定时任务已完成
|
||||
|
||||
JobTypeNormal = 0 //普通任务
|
||||
JobTypeMtMember = 1 //美团会员任务
|
||||
JobTypeJdDelivery = 2 //京东快递任务
|
||||
JobTypeOther = 3 //其他任务(可能是存储信息用的
|
||||
|
||||
JobCashbackPrice = 1 //返现类型固定返现
|
||||
JobCashbackPercentage = 2 //返现类型比例返现
|
||||
|
||||
JobCategoryIDwmtg = 3 //任务类型外卖推广
|
||||
JobCategoryIDOther = 4 //其他任务类型
|
||||
JobCategoryIDDropShipping = 5 //一件代发
|
||||
JobCategoryIDUnion = 6 //联盟任务
|
||||
|
||||
JobSpanTop = 1 //置顶
|
||||
JobSpanRecommend = 2 //推荐
|
||||
|
||||
JobCountrywideCode = 999
|
||||
)
|
||||
|
||||
const (
|
||||
/*消费类型*/
|
||||
ConsumeTypePublishJob = 1 //发任务
|
||||
ConsumeTypeMember = 2 //充会员
|
||||
ConsumeTypeDelivery = 3 //发快递
|
||||
)
|
||||
|
||||
var (
|
||||
DeliveryStatusName = map[int]string{
|
||||
OrderStatusNew: "上门取件中",
|
||||
OrderStatusDelivering: "配送中",
|
||||
OrderStatusFinished: "已妥投",
|
||||
OrderStatusCanceled: "已取消",
|
||||
}
|
||||
|
||||
CashbackName = map[int]string{
|
||||
JobCashbackPrice: "固定返现",
|
||||
JobCashbackPercentage: "比例返现",
|
||||
}
|
||||
|
||||
ConsumeName = map[int]string{
|
||||
ConsumeTypePublishJob: "发任务",
|
||||
ConsumeTypeMember: "充会员",
|
||||
ConsumeTypeDelivery: "发快递",
|
||||
}
|
||||
|
||||
TxWaybillNames = map[int]string{
|
||||
txcloudapi.StatusErr: "单号或代码错误",
|
||||
txcloudapi.StatusNull: "暂无轨迹",
|
||||
txcloudapi.StatusAccept: "快递收件",
|
||||
txcloudapi.StatusDelivering: "在途中",
|
||||
txcloudapi.StatusFinished: "已签收",
|
||||
txcloudapi.StatusProblem: "问题件 (派件不成功或要求择日派送)",
|
||||
txcloudapi.StatusException: "疑难件(收件人拒绝签收,地址有误或不能送达派送区域,收费等原因无法正常派送)",
|
||||
txcloudapi.StatusFailed: "退件签收",
|
||||
}
|
||||
)
|
||||
|
||||
type Job struct {
|
||||
ModelIDCULD
|
||||
|
||||
UserID string `orm:"column(user_id)" json:"userID"` //发布人ID
|
||||
JobCategoryID int `orm:"column(job_category_id)" json:"jobCategoryID"` //任务类型
|
||||
JobSpanTop int `json:"jobSpanTop"` //置顶标签
|
||||
TopSeq int `json:"topSeq"` //置顶顺序
|
||||
JobSpanRecmd int `json:"jobSpanRecmd"` //推荐标签
|
||||
RecmdSeq int `json:"recmdSeq"` //推荐顺序
|
||||
Title string `orm:"size(255)" json:"title"` //任务标题
|
||||
Content string `orm:"size(500)" json:"content"` //任务内容
|
||||
Count int `json:"count"` //任务数量
|
||||
SurplusCount int `json:"surplusCount"` //剩余数量
|
||||
AvgPrice int `json:"avgPrice"` //单个任务金额或预估金额
|
||||
DropShippingSkuPrice int `json:"dropShippingSkuPrice"` //一件代发任务商品价格
|
||||
Percentage int `json:"percentage"` //如果是比例返现,返现比例
|
||||
CashbackType int `json:"cashbackType"` //返现方式,1为固定返现,2为比例返现
|
||||
TotalPrice int `json:"totalPrice"` //任务总金额
|
||||
Status int `json:"status"` //任务状态
|
||||
Address string `orm:"size(500)" json:"address"` //门店地址
|
||||
Lng int `json:"lng"` //乘了10的6次方
|
||||
Lat int `json:"lat"` //乘了10的6次方
|
||||
JobLng float64 `json:"jobLng"` //任务发布地址
|
||||
JobLat float64 `json:"jobLat"` //任务发布地址
|
||||
JobCityCode int `json:"jobCityCode"` //任务所属城市,999代表全国
|
||||
DropShippingAt int `json:"dropShippingAt"` //承诺一件代发几天内发货,小时数
|
||||
JobLimitAt int `json:"jobLimitAt"` //任务限时完成小时数
|
||||
AuditLimitAt int `json:"auditLimitAt"` //任务审核限时小时数
|
||||
FinishedAt *time.Time `orm:"null" json:"finishedAt"` //接单截止日期
|
||||
LimitCountType int `json:"limitCountType"` //任务限次类型,1为每人一次,2为每人每天一次,3为每人每周一次,4为不限制
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"` //推广平台
|
||||
StoreURL string `orm:"column(store_url)" json:"storeURL"` //门店链接
|
||||
SkuURL string `orm:"column(sku_url)" json:"skuURL"` //商品优惠券链接
|
||||
Type int `json:"type"` //任务类型,0为普通任务,1为特殊任务
|
||||
BrowseCount int `json:"browseCount"` //任务浏览量,点一下加一下
|
||||
UnionImg string `json:"unionImg"` //联盟任务分享链接的背景图
|
||||
UnionQrcodePosition string `json:"unionQrcodePosition"` //联盟任务分享链接的二维码图的方位
|
||||
UnionActID string `orm:"column(union_act_id)" json:"unionActID"` //联盟任务ID
|
||||
// JobSteps []*JobStep `orm:"-" json:"jobSteps"`
|
||||
// JobImgs []*JobImg `orm:"-" json:"jobImgs"`
|
||||
}
|
||||
|
||||
func (v *Job) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"UserID"},
|
||||
[]string{"CreatedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
type JobExt struct {
|
||||
FinishedAtStr string `json:"finishedAtStr"` //接单截止日期
|
||||
Job
|
||||
JobSteps []*JobStep `orm:"-" json:"jobSteps"`
|
||||
JobImgs []*JobImg `orm:"-" json:"jobImgs"`
|
||||
}
|
||||
|
||||
type JobImg struct {
|
||||
ModelIDCUL
|
||||
|
||||
JobID int `orm:"column(job_id)" json:"jobID"` //任务ID
|
||||
Img string `orm:"size(500)" json:"img"` //图片
|
||||
}
|
||||
|
||||
func (v *JobImg) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"JobID"},
|
||||
}
|
||||
}
|
||||
|
||||
type JobCategory struct {
|
||||
ModelIDCULD
|
||||
|
||||
Name string `orm:"size(48)" json:"name"` //类型名称
|
||||
Img string `orm:"size(500)" json:"img"` //类型图片
|
||||
}
|
||||
|
||||
func (v *JobCategory) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"Name"},
|
||||
}
|
||||
}
|
||||
|
||||
type JobStep struct {
|
||||
ModelIDCULD
|
||||
|
||||
JobID int `orm:"column(job_id)" json:"jobID"` //任务ID
|
||||
StepCount int `json:"stepCount"` //步骤数
|
||||
Content string `orm:"size(500)" json:"content"` //步骤内容
|
||||
Img string `orm:"size(500)" json:"img"` //步骤图片
|
||||
Type int `json:"type"` //步骤类型,1为任务步骤,2为收集信息
|
||||
}
|
||||
|
||||
func (v *JobStep) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"JobID"},
|
||||
}
|
||||
}
|
||||
|
||||
type JobOrder struct {
|
||||
ModelIDCUL
|
||||
|
||||
JobID int `orm:"column(job_id)" json:"jobID"` //任务ID
|
||||
JobOrderID int64 `orm:"column(job_order_id)" json:"jobOrderID"` //任务订单号
|
||||
UserID string `orm:"column(user_id)" json:"userID"` //接任务人ID
|
||||
Status int `json:"status"` //任务订单状态,接单,待审核,已审核,已结算等
|
||||
SubmitAuditAt time.Time `json:"submitAuditTime"` //提交审核日期
|
||||
AuditAt time.Time `json:"auditAt"` //审核日期
|
||||
Content string `josn:"content"` //任务审核内容
|
||||
Imgs string `json:"imgs"` //任务审核图片
|
||||
Comment string `json:"comment"` //审核理由
|
||||
UserActualPrice int `json:"userActualPrice"` //用户订单实际支付(用户自填)
|
||||
|
||||
DropShippingCount int `json:"dropShippingCount"` //一件代发购买商品数量
|
||||
DropShippingDeliveryID int `orm:"column(drop_shipping_delivery_id)" json:"dropShippingDeliveryID"`
|
||||
DropShippingName string `json:"dropShippingName"`
|
||||
DropShippingMobile string `json:"dropShippingMobile"`
|
||||
DropShippingAddress string `json:"dropShippingAddress"`
|
||||
DropShippingDetailAddress string `json:"dropShippingDetailAddress"`
|
||||
DropShippingLng float64 `json:"dropShippingLng"`
|
||||
DropShippingLat float64 `json:"dropShippingLat"`
|
||||
DropShippingAutoAddress string `json:"dropShippingAutoAddress"`
|
||||
DropShippingCityCode int `json:"dropShippingCityCode"`
|
||||
DropShippingDistrictCode int `json:"dropShippingDistrictCode"`
|
||||
VendorWaybillID string `orm:"column(vendor_waybill_id)" json:"vendorWaybillID"` //运单号
|
||||
WaybillInfo string `orm:"type(text)" json:"waybillInfo"` //物流信息
|
||||
WaybillQueryTime time.Time `json:"waybillQueryTime"` //上次查询时间
|
||||
WaybillStatus int `json:"waybillStatus"` //运单状态(一件代发)
|
||||
DropShippingConfirmTime time.Time `orm:"type(datetime);null" json:"dropShippingConfirmTime"` //确认收货时间
|
||||
DropShippingConfirmUser string `json:"dropShippingConfirmUser"` //确认收货人
|
||||
}
|
||||
|
||||
func (v *JobOrder) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"JobID"},
|
||||
[]string{"JobOrderID"},
|
||||
[]string{"UserID"},
|
||||
}
|
||||
}
|
||||
|
||||
type JobTimer struct {
|
||||
ModelIDCUL
|
||||
|
||||
JobID int `orm:"column(job_id)" json:"jobID"` //任务ID
|
||||
JobOrderID int64 `orm:"column(job_order_id)" json:"jobOrderID"` //任务订单号
|
||||
Type int `json:"type"` //定时任务类型,1为接受任务,2为提交审核
|
||||
Status int `json:"status"` //定时任务的状态,0表示正在进行,1表示已经结束
|
||||
StartAt time.Time `json:"startAt"` //定时任务开始时间
|
||||
LimitAt int `json:"limitAt"` //定时任务时长(小时数)
|
||||
}
|
||||
|
||||
func (v *JobTimer) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"JobID"},
|
||||
[]string{"JobOrderID"},
|
||||
}
|
||||
}
|
||||
|
||||
type JobSpan struct {
|
||||
ModelIDCULD
|
||||
|
||||
JobID int `orm:"column(job_id)" json:"jobID"` //任务ID
|
||||
EndAt *time.Time `json:"endAt"` //生效时间范围
|
||||
SpanType int `json:"spanType"` //1为置顶,2为推荐
|
||||
}
|
||||
|
||||
func (v *JobSpan) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"JobID", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
type MtMember struct {
|
||||
ModelIDCULD
|
||||
|
||||
URL string `orm:"column(url)" json:"url"` //网址
|
||||
ExpiryDate time.Time `json:"expiryDate"` //有效期
|
||||
ShortLink string `json:"shortLink"` //密钥?
|
||||
}
|
||||
|
||||
func (v *MtMember) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"URL"},
|
||||
}
|
||||
}
|
||||
|
||||
func (v *MtMember) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
type StationInfo struct {
|
||||
ModelIDCUL
|
||||
|
||||
StationID string `orm:"column(station_id)" json:"stationID"`
|
||||
StationName string `json:"stationName"`
|
||||
ProvinceName string `json:"provinceName"`
|
||||
ProvinceID int `orm:"column(province_id)" json:"provinceID"`
|
||||
CityName string `json:"cityName"`
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
Location string `json:"location"`
|
||||
StarNum string `json:"starNum"`
|
||||
Phone string `json:"phone"`
|
||||
StationPic string `json:"stationPic"`
|
||||
StationBannerPic string `json:"stationBannerPic"`
|
||||
Prices string `orm:"type(text)" json:"prices"`
|
||||
Adverts string `orm:"type(text)" json:"adverts"`
|
||||
District string `json:"district"`
|
||||
CityID int `orm:"column(city_id)" json:"cityID"`
|
||||
StationType int `json:"stationType"`
|
||||
Distance float64 `json:"distance"`
|
||||
OilInfo []*OilInfo `orm:"-" json:"oilInfo"`
|
||||
}
|
||||
|
||||
func (v *StationInfo) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"StationID"},
|
||||
}
|
||||
}
|
||||
|
||||
func (v *StationInfo) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"CityID", "ProvinceID"},
|
||||
}
|
||||
}
|
||||
|
||||
type OilInfo struct {
|
||||
OilID string `json:"oilId"`
|
||||
StationPrice string `json:"stationPrice"`
|
||||
OilType string `json:"oilType"`
|
||||
DiscountPrice string `json:"discountPrice"`
|
||||
CountryPrice string `json:"countryPrice"`
|
||||
OilgunCodes []string `json:"oilgunCodes"`
|
||||
OilCode string `json:"oilCode"`
|
||||
}
|
||||
|
||||
type AddressDistinguish struct {
|
||||
ModelIDCUL
|
||||
|
||||
Address string `json:"address"`
|
||||
Info string `orm:"type(text)" json:"info"`
|
||||
}
|
||||
|
||||
func (v *AddressDistinguish) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"Address"},
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package legacymodel
|
||||
|
||||
import "time"
|
||||
|
||||
type BlackClient struct {
|
||||
ID int `orm:"column(id)"`
|
||||
Mobile string `orm:"size(16);unique"`
|
||||
Name string `orm:"size(8)"`
|
||||
Note string `orm:"size(256)"`
|
||||
CreatedAt time.Time `orm:"auto_now_add;type(datetime);null"`
|
||||
UpdatedAt time.Time `orm:"auto_now;type(datetime);null"`
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package legacymodel
|
||||
|
||||
type Config struct {
|
||||
Id int
|
||||
Thirdparty string `orm:"size(20);unique" json:"key"`
|
||||
Token string `orm:"size(300)" json:"value"`
|
||||
Date string `orm:"size(30)" json:"date"`
|
||||
LastOperator string `orm:"size(32)" json:"lastOperator"` // 最后操作员
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package legacymodel
|
||||
|
||||
import "git.rosy.net.cn/jx-callback/business/model"
|
||||
|
||||
type EbaiShopLicence struct {
|
||||
model.ModelIDCUL
|
||||
|
||||
ShopName string
|
||||
Licence string
|
||||
Address string
|
||||
Owner string
|
||||
Tel string
|
||||
LicenceName string
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package legacymodel
|
||||
|
||||
import "time"
|
||||
|
||||
type JxBadComments struct {
|
||||
Id int `json:"id" orm:"column(id)"`
|
||||
CreatedAt time.Time `orm:"auto_now_add;type(datetime);null" json:"createdAt"`
|
||||
OrderId string `json:"order_id" orm:"column(order_id);size(25);unique" description:"订单ID"`
|
||||
Jxstoreid string `json:"jxstoreid" orm:"column(jxstoreid);size(11);index" description:"京西门店ID"`
|
||||
Userphone string `json:"userPhone" orm:"column(userphone);size(255);null" description:"评价的用户的联系方式"`
|
||||
Status int `json:"status" orm:"column(status)" description:"当前评论的状态(0:未解决 1:已解决)"`
|
||||
Maxmodifytime int `json:"maxModifyTime" orm:"column(maxmodifytime);null" description:"评论可修改的最大时间"`
|
||||
OrderFlag string `json:"order_flag" orm:"column(order_flag);size(255);null" description:"订单类别(0:京东 1:美团 2:饿了么)"`
|
||||
|
||||
Createtime string `json:"createTime" orm:"column(createtime);size(255);null;index" description:"评论的创建时间"`
|
||||
Score int `json:"score4" orm:"column(score)" description:"评论的星级"`
|
||||
Scorecontent string `json:"score4Content" orm:"column(scorecontent);size(255);null" description:"评论的内容"`
|
||||
Vendertags string `json:"venderTags" orm:"column(vendertags);size(255);null" description:"评论的标签"`
|
||||
Msg string `json:"-" orm:"column(msg);type(text)" description:"未解决差评的原始信息"`
|
||||
|
||||
Updatetime string `json:"updateTime" orm:"column(updatetime);size(255);null" description:"评论的修改时间"`
|
||||
UpdatedScore int `json:"updatedScore" orm:"column(updated_score);null" description:"更改后的分数"`
|
||||
UpdatedScorecontent string `json:"updatedScoreContent" orm:"column(updated_scorecontent);size(255);null" description:"更改后的评论信息"`
|
||||
UpdatedVendertags string `json:"updatedVenderTags" orm:"column(updated_vendertags);size(255);null" description:"更改后的标签信息"`
|
||||
UpdatedMsg string `json:"-" orm:"column(updated_msg);type(text);null" description:"解决后的差评的原始信息"`
|
||||
|
||||
LastPushTime string `json:"-" orm:"column(last_push_time);size(255);null" description:"上一次推送的时间"`
|
||||
PushNo int `json:"-" orm:"column(push_no);null" description:"推送次数"`
|
||||
}
|
||||
|
||||
func (*JxBadComments) TableName() string {
|
||||
return "jx_bad_comments"
|
||||
}
|
||||
|
||||
// type JxBadComments2 struct {
|
||||
// Id int `json:"id" orm:"column(id)"`
|
||||
// CreatedAt time.Time `orm:"auto_now_add;type(datetime);null" json:"createdAt"`
|
||||
// OrderId string `json:"order_id" orm:"column(order_id);size(25);unique" description:"订单ID"`
|
||||
// Jxstoreid string `json:"jxstoreid" orm:"column(jxstoreid);size(11);index" description:"京西门店ID"`
|
||||
// Userphone string `json:"userPhone" orm:"column(userphone);size(255);null" description:"评价的用户的联系方式"`
|
||||
// Status int `json:"status" orm:"column(status)" description:"当前评论的状态(0:未解决 1:已解决)"`
|
||||
// Createtime string `json:"createTime" orm:"column(createtime);size(255);null" description:"评论的创建时间"`
|
||||
// Maxmodifytime int `json:"maxModifyTime" orm:"column(maxmodifytime);null" description:"评论可修改的最大时间"`
|
||||
// Score int `json:"score4" orm:"column(score)" description:"评论的星级"`
|
||||
// Scorecontent string `json:"score4Content" orm:"column(scorecontent);size(255);null" description:"评论的内容"`
|
||||
// Vendertags string `json:"venderTags" orm:"column(vendertags);size(255);null" description:"评论的标签"`
|
||||
// Updatetime string `json:"updateTime" orm:"column(updatetime);size(255);null" description:"评论的修改时间"`
|
||||
// UpdatedScore int `json:"updatedScore" orm:"column(updated_score);null" description:"更改后的分数"`
|
||||
// UpdatedScorecontent string `json:"updatedScoreContent" orm:"column(updated_scorecontent);size(255);null" description:"更改后的评论信息"`
|
||||
// UpdatedVendertags string `json:"updatedVenderTags" orm:"column(updated_vendertags);size(255);null" description:"更改后的标签信息"`
|
||||
// OrderFlag string `json:"order_flag" orm:"column(order_flag);size(255);null" description:"订单类别(0:京东 1:美团 2:饿了么)"`
|
||||
// Msg string `json:"-" orm:"column(msg);type(text)" description:"未解决差评的原始信息"`
|
||||
// UpdatedMsg string `json:"-" orm:"column(updated_msg);type(text);null" description:"解决后的差评的原始信息"`
|
||||
// LastPushTime string `json:"-" orm:"column(last_push_time);size(255);null" description:"上一次推送的时间"`
|
||||
// PushNo int `json:"-" orm:"column(push_no);null" description:"推送次数"`
|
||||
// }
|
||||
@@ -1,23 +0,0 @@
|
||||
package legacymodel
|
||||
|
||||
import "time"
|
||||
|
||||
type StoreBill struct {
|
||||
Id int `orm:"column(id);auto" json:"id"`
|
||||
Date time.Time `orm:"column(date);type(datetime)" json:"date"`
|
||||
Url string `orm:"column(url);size(255)" json:"url"`
|
||||
StoreId int `orm:"column(store_id)" json:"storeId"`
|
||||
BillName string `orm:"column(bill_name);size(30)" json:"billName"`
|
||||
ShopName string `orm:"size(30)" json:"shopName"`
|
||||
BillTitle string `orm:"size(255)" json:"billTitle"`
|
||||
}
|
||||
|
||||
func (t *StoreBill) TableName() string {
|
||||
return "store_bill"
|
||||
}
|
||||
|
||||
func (*StoreBill) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"StoreId", "Date"},
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package legacymodel
|
||||
|
||||
import "time"
|
||||
|
||||
type WeiXins struct {
|
||||
ID int `orm:"column(id)" json:"id"`
|
||||
CreatedAt time.Time `orm:"auto_now_add;type(datetime);null" json:"createdAt"`
|
||||
UpdatedAt time.Time `orm:"auto_now;type(datetime);null" json:"updatedAt"`
|
||||
LastOperator string `orm:"size(32)" json:"lastOperator"` // 最后操作员
|
||||
JxStoreID int `orm:"column(jxstoreid);index" json:"storeID"`
|
||||
OpenID string `orm:"column(openid);size(70);unique;null" json:"openID"`
|
||||
OpenIDMini string `orm:"column(openid_mini);size(70);unique;null" json:"openIDMini"`
|
||||
OpenIDUnion string `orm:"column(openid_union);size(70);unique;null" json:"openIDUnion"`
|
||||
Tel string `orm:"size(15);null;unique" json:"tel"`
|
||||
ParentID int `orm:"column(parentid);default(-1);index" json:"parentID"`
|
||||
NickName string `orm:"column(nickname);size(30)" json:"nickname"`
|
||||
}
|
||||
|
||||
func (*WeiXins) TableName() string {
|
||||
return "weixins"
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package model
|
||||
|
||||
type VendorMatterCategory struct {
|
||||
ModelIDCULD
|
||||
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
CategoryID string `orm:"column(category_id)" json:"categoryID"`
|
||||
CategoryName string `json:"categoryName"`
|
||||
ParentID int `orm:"column(parent_id)" json:"parentID"`
|
||||
Level int `json:"level"`
|
||||
}
|
||||
|
||||
func (v *VendorMatterCategory) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"VendorID", "CategoryID"},
|
||||
}
|
||||
}
|
||||
@@ -59,17 +59,16 @@ func (*MessageStatus) TableIndex() [][]string {
|
||||
type ImMessageRecord struct {
|
||||
ModelIDCULD
|
||||
|
||||
UserID string `orm:"size(48);column(user_id)" json:"userID"` //发消息的userID
|
||||
GroupID int `orm:"column(group_id)" json:"groupID"` //组ID
|
||||
Content string `orm:"type(text)" json:"content"` //消息内容
|
||||
MessageType int `json:"messageType"` //消息类型,1文字,2图片,3音频
|
||||
Seq int64 `json:"seq"`
|
||||
Weight int `json:"weight"`
|
||||
Height int `json:"height"`
|
||||
AudioLength string `json:"audioLength"`
|
||||
Key string `orm:"-" json:"key"`
|
||||
ToUserID string `orm:"size(48);column(to_user_id)" json:"toUserID"` //收消息的userID
|
||||
UserInfo *GetUserResult `orm:"-" json:"userInfo"`
|
||||
UserID string `orm:"size(48);column(user_id)" json:"userID"` //发消息的userID
|
||||
GroupID int `orm:"column(group_id)" json:"groupID"` //组ID
|
||||
Content string `orm:"type(text)" json:"content"` //消息内容
|
||||
MessageType int `json:"messageType"` //消息类型,1文字,2图片,3音频
|
||||
Seq int64 `json:"seq"`
|
||||
Weight int `json:"weight"`
|
||||
Height int `json:"height"`
|
||||
AudioLength string `json:"audioLength"`
|
||||
Key string `orm:"-" json:"key"`
|
||||
ToUserID string `orm:"size(48);column(to_user_id)" json:"toUserID"` //收消息的userID
|
||||
}
|
||||
|
||||
func (*ImMessageRecord) TableIndex() [][]string {
|
||||
|
||||
@@ -2,182 +2,33 @@ package model
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
PayTypeWX = 1 // 微信支付
|
||||
PayTypeTL = 2 // 通联宝支付
|
||||
|
||||
PayStatusNo = 0
|
||||
PayStatusYes = 1
|
||||
PayStatusFailed = 2
|
||||
PayStatusCanceled = 3
|
||||
PayStatusRefund = 4
|
||||
|
||||
RefundStatusNo = 0
|
||||
RefundStatusYes = 1
|
||||
RefundStatusFailed = 2
|
||||
|
||||
VendorPayTypeCompanyPay = "companyPay" //企业付款
|
||||
VendorPayTypeTransferAccount = "transferAccount" //手动转账
|
||||
)
|
||||
|
||||
const (
|
||||
OrderTypePay = 1 //支付
|
||||
OrderTypeCash = 2 //提现
|
||||
|
||||
OrderTypePublishJob = 1 //发布任务
|
||||
OrderTpyeMember = 2 //充值会员
|
||||
OrderTypeDelivery = 3 //发快递
|
||||
OrderTpyeDropShipping = 4 //一件代发交钱
|
||||
)
|
||||
|
||||
var (
|
||||
PayStatusName = map[int]string{
|
||||
PayStatusNo: "待支付",
|
||||
PayStatusYes: "已支付",
|
||||
PayStatusFailed: "支付失败",
|
||||
PayStatusCanceled: "支付取消",
|
||||
PayStatusRefund: "已退款",
|
||||
}
|
||||
|
||||
RefundStatusName = map[int]string{
|
||||
RefundStatusNo: "待退款",
|
||||
RefundStatusYes: "已退款",
|
||||
RefundStatusFailed: "退款失败",
|
||||
}
|
||||
)
|
||||
|
||||
type Order struct {
|
||||
ModelIDCUL
|
||||
|
||||
OrderID string `orm:"column(order_id)" json:"orderID"` //订单号
|
||||
UserID string `orm:"column(user_id);size(48)" json:"userID"` //用户ID
|
||||
Type int `json:"type"`
|
||||
OrderType int `json:"orderType"` //订单类型
|
||||
Way string `json:"way"` //weixinapp ,weixinmini
|
||||
type PayOrder struct {
|
||||
ID int64 `orm:"column(id)" json:"id"`
|
||||
CreatedAt time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"`
|
||||
OrderID string `orm:"column(order_id)" json:"orderID"` //订单号
|
||||
UserID string `orm:"column(user_id);size(48)" json:"userID"` //用户ID
|
||||
OrderType string `json:"orderType"` //订单类型,流量充值等
|
||||
TypeID string `orm:"column(type_id)" json:"type_id"` //类型ID,充流量就是套餐对应的id
|
||||
Origin string `json:"origin"` //订单来源,小程序,开放后台
|
||||
Status int `json:"status"` //订单状态,待支付2,已支付5,支付成功110,支付失败115
|
||||
PayPrice int `json:"payPrice"` //支付金额
|
||||
TransactionID string `orm:"column(transaction_id);size(48)" json:"transactionID"` // 支付成功后,支付方生成的事务ID
|
||||
PayFinishedAt time.Time `orm:"type(datetime);null" json:"payFinishedAt"`
|
||||
PrepayID string `orm:"column(prepay_id);size(48)" json:"prepayID"` // 下单后,支付前,支付方生成的事务ID
|
||||
OriginalData string `orm:"type(text)" json:"-"`
|
||||
Comment string `orm:"size(255)" json:"comment"` //备注
|
||||
Lng float64 `json:"lng"`
|
||||
Lat float64 `json:"lat"`
|
||||
CityCode int `orm:"default(0)" json:"cityCode"` //提交订单时用户所在城市
|
||||
DistrictCode int `orm:"default(0)" json:"districtCode"`
|
||||
Address string `orm:"size(255)" json:"address"`
|
||||
Comment string `orm:"size(255)" json:"comment"` //备注
|
||||
ThingID string `orm:"column(thing_id)" json:"thing_id"` //订单充值项目ID,充流量就是iccid
|
||||
}
|
||||
|
||||
func (v *Order) TableUnique() [][]string {
|
||||
func (v *PayOrder) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"OrderID"},
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Order) TableIndex() [][]string {
|
||||
func (v *PayOrder) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"CreatedAt"},
|
||||
[]string{"UserID"},
|
||||
}
|
||||
}
|
||||
|
||||
type DeliveryOrder struct {
|
||||
ModelIDCUL
|
||||
|
||||
VendorWaybillID string `orm:"column(vendor_waybill_id)" json:"vendorWaybillID"` //运单号
|
||||
UserID string `orm:"column(user_id);size(48)" json:"userID"` //用户ID
|
||||
DeliverySendID int `orm:"column(delivery_send_id)" json:"deliverySendID"` //寄件人地址ID
|
||||
SendName string `json:"sendName"`
|
||||
SendMobile string `json:"sendMobile"`
|
||||
SendAddress string `json:"sendAddress"`
|
||||
SendDetailAddress string `json:"sendDetailAddress"`
|
||||
SendLng float64 `json:"sendLng"`
|
||||
SendLat float64 `json:"sendLat"`
|
||||
SendAutoAddress string `json:"sendAutoAddress"`
|
||||
SendCityCode int `json:"sendCityCode"`
|
||||
SendDistrictCode int `json:"sendDistrictCode"`
|
||||
DeliveryReceiveID int `orm:"column(delivery_receive_id)" json:"deliveryReceiveID"` //取件人地址ID(收货人)\
|
||||
ReceiveName string `json:"receiveName"`
|
||||
ReceiveMobile string `json:"receiveMobile"`
|
||||
ReceiveAddress string `json:"receiveAddress"`
|
||||
ReceiveDetailAddress string `json:"receiveDetailAddress"`
|
||||
ReceiveLng float64 `json:"receiveLng"`
|
||||
ReceiveLat float64 `json:"receiveLat"`
|
||||
ReceiveAutoAddress string `json:"receiveAutoAddress"`
|
||||
ReceiveCityCode int `json:"receiveCityCode"`
|
||||
ReceiveDistrictCode int `json:"receiveDistrictCode"`
|
||||
Status int `json:"status"` //运单状态
|
||||
PayPrice int `json:"payPrice"` //支付金额
|
||||
OrderFinishedAt time.Time `json:"orderFinishedAt"` //订单完成时间
|
||||
Weight float64 `json:"weight"` //订单重量,单位kg
|
||||
Vloumn float64 `json:"vloumn"` //订单体积,单位立方cm
|
||||
Description string `json:"description"` //订单商品描述
|
||||
PickUpStartTime time.Time `json:"pickUpStartTime"` //预约取件开始时间
|
||||
PickUpEndTime time.Time `json:"pickUpEndTime"` //预约取件结束时间
|
||||
PackageCount int `json:"packageCount"` //包裹数
|
||||
ActualWeight float64 `json:"actualWeight"` //实际重量
|
||||
IsWeight int `json:"isWeight"` //0代表未验重,1代表验重通过,2代表不通过
|
||||
DiffPrice int `json:"diffPrice"` //如果超重了,扣除的差额
|
||||
Comment string `orm:"size(255)" json:"comment"` //备注
|
||||
JobOrderID string `orm:"column(job_order_id)" json:"jobOrderID"`
|
||||
}
|
||||
|
||||
func (v *DeliveryOrder) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"VendorWaybillID"},
|
||||
}
|
||||
}
|
||||
|
||||
func (v *DeliveryOrder) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"CreatedAt"},
|
||||
[]string{"UserID"},
|
||||
}
|
||||
}
|
||||
|
||||
//联盟订单
|
||||
type UnionOrder struct {
|
||||
ModelIDCUL
|
||||
|
||||
VendorOrderID string `orm:"column(vendor_order_id)" json:"vendorOrderID"` //订单号
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"` //平台ID
|
||||
UserID string `orm:"column(user_id);size(48)" json:"userID"` //用户ID
|
||||
Status int `json:"status"` //订单状态
|
||||
PayPrice int `json:"payPrice"` //支付金额
|
||||
PromotionAmount int `json:"promotionAmount"` //佣金金额
|
||||
GoodsName string `orm:"size(255)" json:"goodsName"` //商品名
|
||||
GoodsID string `orm:"column(goods_id)" json:"goodsID"` //商品ID
|
||||
GoodsImg string `json:"goodsImg"` //商品图
|
||||
OrderCreateAt time.Time `json:"orderCreateAt"` //下单时间
|
||||
OrderPayAt time.Time `json:"orderPayAt"` //支付时间
|
||||
OrderReceiveAt time.Time `json:"orderReceiveAt"` //收货时间
|
||||
OrderSettleAt time.Time `json:"orderSettleAt"` //结算时间
|
||||
PID string `orm:"column(p_id)" json:"pID"` //推广位ID
|
||||
IsEarning int `json:"isEarning"` //是否结算此订单,1表示已结算了
|
||||
Comment string `orm:"size(255)" json:"comment"` //备注
|
||||
}
|
||||
|
||||
func (v *UnionOrder) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"VendorOrderID", "VendorID"},
|
||||
}
|
||||
}
|
||||
|
||||
func (v *UnionOrder) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"OrderCreateAt"},
|
||||
[]string{"UserID"},
|
||||
}
|
||||
}
|
||||
|
||||
//联盟订单轨迹
|
||||
type UnionOrderStatus struct {
|
||||
ModelIDCUL
|
||||
|
||||
VendorOrderID string `orm:"column(vendor_order_id)" json:"vendorOrderID"` //订单号
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"` //平台ID
|
||||
Status int `json:"status"` //订单状态
|
||||
VendorStatus string `json:"vendorStatus"` //平台状态
|
||||
OrderStatusAt time.Time `json:"orderStatusAt"` //更新时间
|
||||
Comment string `orm:"size(255)" json:"comment"` //备注
|
||||
}
|
||||
|
||||
@@ -1,188 +0,0 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type OrderFinancial struct {
|
||||
ModelIDCUL
|
||||
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"` // 平台id
|
||||
VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` // 订单ID
|
||||
VendorOrderID2 string `orm:"column(vendor_order_id2);size(48);index" json:"vendorOrderID2"` // 订单ID2,饿百独有
|
||||
// DeliveryConfirmTime time.Time `orm:"type(datetime);index" json:"deliveryConfirmTime"` // 订单妥投/完成时间
|
||||
ShopPriceMoney int64 `json:"shopPriceMoney"` // 门店价-左右商品在京西的价格总和(报价模式会用到)0
|
||||
SalePriceMoney int64 `json:"salePriceMoney"` // 商品标价总额(用户下单满减之前的商品售价)+
|
||||
ActualPayMoney int64 `json:"actualPayMoney"` // 用户实际支付金额0
|
||||
TotalDiscountMoney int64 `json:"totalDiscountMoney"` // 订单总优惠(订单主体+运费)-
|
||||
DiscountMoney int64 `json:"discountMoney"` // 订单主体优惠0
|
||||
PointsDeductionMoney int64 `json:"pointsDeductionMoney"` // 积分抵扣金额0
|
||||
ReceivableFreight int64 `json:"receivableFreight"` // 订单应收运费0
|
||||
FreightMoney int64 `json:"freightMoney"` // 用户支付运费0
|
||||
FreightDiscountMoney int64 `json:"freightDiscountMoney"` // 订单运费优惠(商家设置满减discountType == 8)0
|
||||
PmFreightDiscountMoney int64 `json:"pmFreightDiscountMoney"` // 订单运费优惠(平台运费优惠discountType == 7/12/15)+
|
||||
DistanceFreightMoney int64 `json:"distanceFreightMoney"` // 订单远距离费-
|
||||
FreightTipsMoney int64 `json:"freightTipsMoney"` // 订单小费-
|
||||
DonationMoney int64 `json:"donationMoney"` // 公益捐款-
|
||||
SelfDeliveryDiscountMoney int64 `json:"selfDeliveryDiscountMoney"` // 平台承担运费补贴(商家自送)+
|
||||
PmSkuSubsidyMoney int64 `json:"pmSkuSubsidyMoney"` // 平台对单条sku补贴的金额
|
||||
PmSubsidyMoney int64 `json:"pmSubsidyMoney"` // 平台活动补贴(订单主体活动补贴+订单单条sku补贴)1+
|
||||
BoxMoney int64 `json:"boxMoney"` // order餐盒费1+
|
||||
SkuBoxMoney int64 `json:"skuBoxMoney"` // sku餐盒费
|
||||
PmMoney int64 `json:"pmMoney"` // 平台费1-
|
||||
ShopMoney int64 `json:"shopMoney"` // 应结金额-第三方平台结算给京西的金额M
|
||||
ShopMoneyByCal int64 `json:"shopMoneyByCal"` // 应结金额-通过公式计算平台结给京西的金额M
|
||||
JxPmMoney int64 `json:"jxPmMoney"` // 京西平台费-
|
||||
JxFreightMoney int64 `json:"jxFreightMoney"` // 转自送-->美团/达达订单产生运费0
|
||||
JxFreightMoneyByShop int64 `json:"jxFreightMoneyByShop"` // 转自送-->美团/达达订单产生运费,由商家承担的部分-
|
||||
JxSubsidyMoney int64 `json:"jxSubsidyMoney"` // 京西总补贴
|
||||
JxSkuSubsidyMoney int64 `json:"jxSkuSubsidyMoney"` // 京西补贴给单条sku的金额
|
||||
JxShopMoney int64 `json:"jxShopMoney"` // 店铺应结金额-京西结算给店铺的金额M
|
||||
DownFlag int8 `json:"downFlag"` // 0--正常单, 1--降级单
|
||||
Skus []*OrderSkuFinancial `orm:"-" json:"skus"` // 正向订单购买商品列表
|
||||
Discounts []*OrderDiscountFinancial `orm:"-" json:"discounts"` // 正向订单享受优惠列表
|
||||
}
|
||||
|
||||
func (o *OrderFinancial) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"VendorOrderID", "VendorID"},
|
||||
}
|
||||
}
|
||||
|
||||
type OrderDiscountFinancial struct {
|
||||
ModelIDCUL
|
||||
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` // 订单ID
|
||||
VendorOrderID2 string `orm:"column(vendor_order_id2);size(48);index" json:"vendorOrderID2"` // 订单ID2,饿百独有
|
||||
VendorActivityID string `orm:"column(vendor_activity_id);size(48)" json:"vendorActivityID"` // 活动ID 活动ID的存在,使原本的通过城市/下单时间-活动时间/金额……一系列匹配来确认活动归属的费时且准确度低的行为有了改变的可能--通过编码精确定位
|
||||
Type string `orm:"size(48)" json:"type"` // 活动type 美团订单存在不同的活动,活动ID是一样的,type不一样 如订单34399553040365354
|
||||
// ActivityName string `orm:"size(255)" json:"activityName"` // 活动名
|
||||
// ActivityMoney int64 `json:"activityMoney"` // 优惠金额
|
||||
// Remark string `orm:"size(255)" json:"remark"` // 备注
|
||||
}
|
||||
|
||||
// 设置主键 "VendorOrderID", "DiscountCode", "VendorID" 一个订单不可能享受同一优惠2次
|
||||
func (o *OrderDiscountFinancial) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"VendorOrderID", "VendorActivityID", "Type", "VendorID"},
|
||||
}
|
||||
}
|
||||
|
||||
type AfsOrder struct {
|
||||
ModelIDCUL
|
||||
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` // 关联原始订单ID
|
||||
VendorOrderID2 string `orm:"column(vendor_order_id2);size(48);index" json:"vendorOrderID2"` // 关联原始订单ID2,饿百独有
|
||||
AfsOrderID string `orm:"column(afs_order_id);size(48)" json:"afsOrderID"` // 售后订单ID
|
||||
AfsCreatedAt time.Time `orm:"type(datetime);null;index" json:"afsCreatedAt"` // 售后单生成时间
|
||||
AfsFinishedAt time.Time `orm:"type(datetime);null;index" json:"afsFinishedAt"` // 售后单结束时间
|
||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"` // 外部系统里记录的storeid
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"` // 接口返回的京西门店ID
|
||||
JxStoreID int `orm:"column(jx_store_id)" json:"jxStoreID"` // 根据VendorStoreID在本地系统里查询出来的 jxstoreid
|
||||
|
||||
// IsNeedApprove int8 `json:"isNeedApprove"` // 售后单是否需要商家审核
|
||||
Status int `json:"status"`
|
||||
VendorStatus string `orm:"size(255)" json:"vendorStatus"`
|
||||
ReasonType int8 `json:"reasonType"` // 售后原因
|
||||
VendorReasonType string `orm:"size(255)" json:"vendorReasonType"` // 原始售后原因
|
||||
ReasonDesc string `orm:"size(1024)" json:"reasonDesc"` // 售后原因描述
|
||||
ReasonImgList string `orm:"size(1024)" json:"reasonImgList"` // 售后描述图片
|
||||
AppealType int8 `json:"appealType"` // 售后方式
|
||||
VendorAppealType string `orm:"size(255)" json:"vendorAppealType"` // 原始售后方式
|
||||
Flag int `json:"flag"`
|
||||
RefundType int8 `json:"refundType"`
|
||||
RefuseReason string `orm:"size(1024)" json:"refuseReason"`
|
||||
|
||||
SkuUserMoney int64 `json:"skuUserMoney"` // 用户支付菜品金额
|
||||
FreightUserMoney int64 `json:"freightUserMoney"` // 用户支付运费金额
|
||||
AfsFreightMoney int64 `json:"afsFreightMoney"` // 退货取件费
|
||||
BoxMoney int64 `json:"boxMoney"` // 应退包装费金额
|
||||
TongchengFreightMoney int64 `json:"tongchengFreightMoney"` // 退货单产生的同城送费用
|
||||
SkuBoxMoney int64 `json:"skuBoxMoney"` // 应退订单餐盒费
|
||||
PmSubsidyMoney int64 `json:"pmSubsidyMoney"` // 平台总补贴金额
|
||||
PmSkuSubsidyMoney int64 `json:"pmSkuSubsidyMoney"` // 平台sku补贴金额
|
||||
PmRefundMoney int64 `json:"pmRefundMoney"` // 订单取消后可能存在佣金减少,平台退回部分金额的情况
|
||||
RefundMoney int64 `json:"refundMoney"` // 平台扣款总额 1
|
||||
RefundMoneyByCal int64 `json:"refundMoneyByCal"` // 平台扣款总额-通过公式计算平台扣除京西的金额M
|
||||
// JxSkuMoney int64 `json:"jxSkuMoney"` // 京西补贴金额,现阶段是平台扣京西多少钱,京西扣商家多少钱,暂不考虑撤回京西补贴
|
||||
Skus []*OrderSkuFinancial `orm:"-" json:"skus"`
|
||||
VendorOrgCode string `orm:"size(64)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空
|
||||
}
|
||||
|
||||
func (o *AfsOrder) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"AfsOrderID", "VendorID"},
|
||||
}
|
||||
}
|
||||
|
||||
type OrderSkuFinancial struct {
|
||||
ModelIDCUL
|
||||
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"` // 平台id
|
||||
VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` // 关联原始订单ID
|
||||
AfsOrderID string `orm:"column(afs_order_id);size(48)" json:"afsOrderID"` // 售后单ID
|
||||
IsAfsOrder int8 `json:"isAfsOrder"` // 0--正向单, 1--售后单
|
||||
|
||||
// ConfirmTime time.Time `orm:"type(datetime)" json:"confirmTime"` // 订单生成/完成时间
|
||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"` // 外部系统里记录的storeid
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"` // 接口返回的京西门店ID
|
||||
JxStoreID int `orm:"column(jx_store_id)" json:"jxStoreID"` // 根据VendorStoreID在本地系统里查询出来的 jxstoreid
|
||||
VendorSkuID string `orm:"column(vendor_sku_id);size(48)" json:"vendorSkuID"` // 平台skuid
|
||||
SkuID int `orm:"column(sku_id)" json:"skuID"` // 平台返回的京西skuid
|
||||
JxSkuID int `orm:"column(jx_sku_id)" json:"jxSkuID"` // 京西skuid
|
||||
PromotionType int `json:"promotionType"` // 商品级别促销类型 (1、无优惠;2、秒杀(已经下线);3、单品直降;4、限时抢购;1202、加价购;1203、满赠(标识商品);6、买赠(买A送B,标识B);9999、表示一个普通商品参与捆绑促销,设置的捆绑类型;9998、表示一个商品参与了捆绑促销,并且还参与了其他促销类型;9997、表示一个商品参与了捆绑促销,但是金额拆分不尽,9996:组合购,8001:轻松购会员价,8:第二件N折,9:拼团促销)
|
||||
Name string `orm:"size(255)" json:"name"` // 商品名
|
||||
ShopPrice int64 `json:"shopPrice"` // 门店标价
|
||||
SalePrice int64 `json:"salePrice"` // 售卖价
|
||||
Count int `json:"count"` // 订单下单数量
|
||||
SkuBoxMoney int64 `json:"skuBoxMoney"` // sku餐盒费(美团/饿百的单条sku存在这个概念)
|
||||
UserMoney int64 `json:"userMoney"` // 用户支付金额
|
||||
PmSubsidyMoney int64 `json:"pmSubsidyMoney"` // 平台补贴总金额
|
||||
PmSkuSubsidyMoney int64 `json:"pmSkuSubsidyMoney"` // 平台补贴sku金额
|
||||
PmDeductionsMoney int64 `json:"pmDeductionsMoney"` // 单条sku需要承担的平台扣费金额
|
||||
ShopMoney int64 `json:"shopMoney"` // 应结金额-第三方平台结算给京西的金额M
|
||||
ShopMoneyByCal int64 `json:"shopMoneyByCal"` // 应结金额-通过公式计算平台结给京西的金额M
|
||||
|
||||
JxSubsidyMoney int64 `json:"jxSubsidyMoney"` // 京西总补贴
|
||||
JxSkuSubsidyMoney int64 `json:"jxSkuSubsidyMoney"` // 京西补贴,针对单品活动补贴
|
||||
JxDeductionsMoney int64 `json:"jxDeductionsMoney"` // 单条sku需要承担的京西扣费金额
|
||||
JxShopMoney int64 `json:"jxShopMoney"` // 店铺应结金额-京西结算给店铺的金额M
|
||||
RefundMoney int64 `json:"refundMoney"` // 平台扣款总额 暂时无用
|
||||
RefundMoneyByCal int64 `json:"refundMoneyByCal"` // 平台扣款总额-通过公式计算平台扣除京西的金额M
|
||||
// CreatedAt time.Time `orm:"type(datetime);index" json:"createdAt"` // 订单创建时间
|
||||
// JxSkuMoney int64 `json:"jxSkuMoney"` // 京西补贴金额,现阶段是平台扣京西多少钱,京西扣商家多少钱,暂不考虑撤回京西补贴
|
||||
// SkuType int `json:"-"` // 当前如果为gift就为1,否则缺省为0
|
||||
StoreSubID int `orm:"column(store_sub_id)" json:"storeSubID"` // 当前这个字段被当成活动ID用
|
||||
StoreSubName string `orm:"size(64)" json:"storeSubName"` // 当前这个字段被用作vendorActType
|
||||
}
|
||||
|
||||
// todo
|
||||
// func (o *OrderSkuFinancial) TableUnique() [][]string {
|
||||
// return [][]string{
|
||||
// []string{"AfsOrderID", "VendorSkuID", "VendorID", "IsAfsOrder"},
|
||||
// }
|
||||
// }
|
||||
|
||||
func (o *OrderSkuFinancial) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"VendorOrderID", "VendorSkuID"},
|
||||
[]string{"AfsOrderID", "VendorSkuID"},
|
||||
[]string{"AfsOrderID", "JxSkuID"},
|
||||
}
|
||||
}
|
||||
|
||||
// type ActivityForSku struct {
|
||||
// ModelIDCUL
|
||||
|
||||
// CityName string `json:"cityName"` // 活动所在城市
|
||||
// VendorID int `orm:"column(vendor_id)" json:"vendorID"` // 平台id
|
||||
// ActivityCreatedAt time.Time `orm:"type(datetime);index" json:"activityCreatedAt"` // 活动开始时间时间
|
||||
// ActivityEndAt time.Time `orm:"type(datetime);index" json:"activityEndAt"` // 活动结束时间
|
||||
// VendorSkuID string `orm:"column(vendor_sku_id)" json:"vendorSkuID"` // 平台skuid
|
||||
// SkuID int `orm:"column(sku_id)" json:"skuID"` // 平台返回的京西skuid
|
||||
// JxSkuID int `orm:"column(jx_sku_id)" json:"jxSkuID"` // 京西本地系统查询到的skuid
|
||||
// ActivityPrice int64 `json:"activityPrice"` // 活动价格
|
||||
// JxSubsidy int64 `json:"jxSubsidy"` // 京西补贴
|
||||
// ManagerSubsidy int64 `json:"managerSubsidy"` // 城市经理补贴
|
||||
// Remark string `json:"remark"` // 备注
|
||||
// }
|
||||
95
business/model/print.go
Normal file
95
business/model/print.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package model
|
||||
|
||||
const (
|
||||
PrinterStatusOnlineWithoutPaper = 2 //在线缺纸
|
||||
PrinterStatusOnline = 1 //在线正常
|
||||
PrinterStatusOffline = -1 //离线
|
||||
PrinterStatusNoFlow = -2 //当月流量超30m了
|
||||
|
||||
PrintMsgAlreadySend = 2 //已经发出打印消息
|
||||
PrintMsgSuccess = 1 //打印成功
|
||||
PrintMsgWait = 0 //待打印
|
||||
PrintMsgFail = -1 //打印失败(打印机报出)
|
||||
PrintMsgErr = -2 //京西报出
|
||||
PrintMsgAll = -9
|
||||
)
|
||||
|
||||
type AddPrinterParam struct {
|
||||
PrintNo string `json:"print_no"` //打印机编号
|
||||
Name string `json:"name"` //打印机备注名
|
||||
SIM string `json:"sim"` //sim卡号-电话号码,接受验证的电话
|
||||
StoreId int64 `json:"store_id"` // 门店id
|
||||
}
|
||||
|
||||
type Printer struct {
|
||||
ModelIDCULD
|
||||
|
||||
AppID int `orm:"column(app_id)" json:"app_id" db:"app_id"` //应用编号
|
||||
PrintNo string `json:"print_no" db:"print_no"` //打印机编号
|
||||
PrintKey string `json:"print_key" db:"print_key"` //打印机识别码
|
||||
Name string `json:"name" db:"name"` //打印机备注名
|
||||
Status int `json:"status" db:"status"` //打印机状态
|
||||
IsOnline int `json:"is_online" db:"is_online"` //1在线,0离线
|
||||
IccID string `orm:"column(icc_id)" json:"IccID" db:"icc_id"` //sim卡号
|
||||
Sound string `json:"sound" db:"sound"` //声音类型 sounda ,b,c,d,e,f,g
|
||||
Volume int `json:"volume" db:"volume"` //音量,1-5 ,对应打印机2-10
|
||||
FlowFlag int `json:"flowFlag" db:"flow_flag"` //是否超流量了,1表示超了
|
||||
OfflineCount int `json:"offlineCount" db:"offline_count"` //掉线次数
|
||||
UserId string `orm:"column(user_id)" json:"user_id" db:"user_id"` //用户id
|
||||
}
|
||||
|
||||
func (v *Printer) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"PrintNo"},
|
||||
}
|
||||
}
|
||||
|
||||
type PrintMsg struct {
|
||||
ModelIDCULD
|
||||
|
||||
MsgID string `orm:"column(msg_id)" json:"msg_id" db:"msg_id"` //消息ID
|
||||
PrintNo string `json:"print_no" db:"print_no"` //打印机编号
|
||||
OrderNo string `json:"order_no" db:"order_no"` //订单序号
|
||||
Content string `orm:"type(text)" json:"content" db:"content"` //订单内容
|
||||
Status int `json:"status" db:"status"` //打印状态
|
||||
Comment string `json:"comment" db:"comment"` //失败原因
|
||||
ContentEncryption string `orm:"type(text)" json:"content_encryption" db:"content_encryption"` //订单类容进制文件
|
||||
}
|
||||
|
||||
func (v *PrintMsg) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"PrintNo"},
|
||||
}
|
||||
}
|
||||
|
||||
//流量支出
|
||||
type SimFlowExpend struct {
|
||||
ModelIDCUL
|
||||
|
||||
IccID string `orm:"column(icc_id)" json:"iccID" db:"icc_id"` //sim卡iccid
|
||||
Flow float64 `json:"flow" db:"flow"` //流量数
|
||||
FlowUnit string `json:"flowUnit" db:"flow_unit"` //流量单位
|
||||
}
|
||||
|
||||
func (v *SimFlowExpend) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"IccID"},
|
||||
}
|
||||
}
|
||||
|
||||
//流量划入
|
||||
type SimFlowIncome struct {
|
||||
ModelIDCUL
|
||||
|
||||
IccID string `orm:"column(icc_id)" json:"iccID" db:"icc_id"` //sim卡iccid
|
||||
Flow float64 `json:"flow" db:"flow"` //流量数
|
||||
FlowUnit string `json:"flowUnit" db:"flow_unit"` //流量单位
|
||||
IncomeType int `json:"incomeType" db:"income_type"` //1 表示系统每月自动划转,2 表示商户自己冲的
|
||||
OrderID string `orm:"column(order_id)" json:"order_id" db:"order_id"` //订单号
|
||||
}
|
||||
|
||||
func (v *SimFlowIncome) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"IccID"},
|
||||
}
|
||||
}
|
||||
16
business/model/print_activation.go
Normal file
16
business/model/print_activation.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// PrintActivation 打印机激活记录
|
||||
type PrintActivation struct {
|
||||
ID int `orm:"column(id)" json:"id" db:"id"`
|
||||
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
||||
PrintNo string `orm:"type(varchar);size(32);index" json:"print_no" db:"print_no"` // 打印机编号
|
||||
}
|
||||
|
||||
func (v *PrintActivation) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"PrintNo"},
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user