@@ -0,0 +1,83 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
model2 "applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
func ExpressOrderRelateListByOid(Db *xorm.Engine, oid int64, pvd string) ([]*model2.OrdListRelate, error) { | |||
var ol []*model2.OrdListRelate | |||
err := Db.Where("oid=? and pvd=?", oid, pvd).Find(&ol) | |||
if err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
return ol, nil | |||
} | |||
func ExpressOrderListByNoSettledWithPage(Db *xorm.Engine, page int) ([]*model.ExpressOrder, error) { | |||
perPage := 500 | |||
startPlace := (page - 1) * perPage | |||
var o []*model.ExpressOrder | |||
err := Db.Where("settle_time =0 AND commission_time >0 and status=? and real_profit>0", "已完成").Limit(perPage, startPlace).Find(&o) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return o, nil | |||
} | |||
func GetExpressWithOid(eg *xorm.Engine, ordId string) *model.ExpressOrder { | |||
var data model.ExpressOrder | |||
get, _ := eg.Where(" oid=?", ordId).Get(&data) | |||
if get { | |||
return &data | |||
} | |||
return nil | |||
} | |||
func GetExpressWithWlOid(eg *xorm.Engine, ordId string) *model.ExpressOrder { | |||
var data model.ExpressOrder | |||
get, _ := eg.Where(" wl_oid=?", ordId).Get(&data) | |||
if get { | |||
return &data | |||
} | |||
return nil | |||
} | |||
func GetExpressWithOidSess(sess *xorm.Session, ordId string) *model.ExpressOrder { | |||
var data model.ExpressOrder | |||
get, _ := sess.Where(" oid=?", ordId).Get(&data) | |||
if get { | |||
return &data | |||
} | |||
return nil | |||
} | |||
func UpdateExpressSendOrd(engine *xorm.Engine, model *model.ExpressOrder, id interface{}, forceColums ...string) (int64, error) { | |||
var ( | |||
affected int64 | |||
err error | |||
) | |||
if forceColums != nil { | |||
affected, err = engine.Where("oid=?", id).Cols(forceColums...).Update(model) | |||
} else { | |||
affected, err = engine.Where("oid=?", id).Update(model) | |||
} | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} | |||
func UpdateExpressSendOrdSess(sess *xorm.Session, model *model.ExpressOrder, id interface{}, forceColums ...string) (int64, error) { | |||
var ( | |||
affected int64 | |||
err error | |||
) | |||
if forceColums != nil { | |||
affected, err = sess.Where("oid=?", id).Cols(forceColums...).Update(model) | |||
} else { | |||
affected, err = sess.Where("oid=?", id).Update(model) | |||
} | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} |
@@ -0,0 +1,50 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type ExpressOrder struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Uid int `json:"uid" xorm:"default 0 INT(11)"` | |||
Oid string `json:"oid" xorm:"VARCHAR(255)"` | |||
PvdOid string `json:"pvd_oid" xorm:"VARCHAR(255)"` | |||
CreateTime time.Time `json:"create_time" xorm:"DATETIME"` | |||
PayTime time.Time `json:"pay_time" xorm:"DATETIME"` | |||
SupplementPayTime time.Time `json:"supplement_pay_time" xorm:"comment('补交时间') DATETIME"` | |||
Money string `json:"money" xorm:"default 0.00000000 comment('第一次') DECIMAL(20,8)"` | |||
Profit string `json:"profit" xorm:"default 0.00000000 comment('利润') DECIMAL(20,8)"` | |||
RealProfit string `json:"real_profit" xorm:"default 0.00000000 comment('利润') DECIMAL(20,8)"` | |||
SupplementMoney string `json:"supplement_money" xorm:"default 0.00000000 DECIMAL(20,8)"` | |||
IsPay int `json:"is_pay" xorm:"default 0 INT(1)"` | |||
IsSupplementPay int `json:"is_supplement_pay" xorm:"default 0 INT(1)"` | |||
Status string `json:"status" xorm:"VARCHAR(255)"` | |||
Ext string `json:"ext" xorm:"TEXT"` | |||
IsRefund int `json:"is_refund" xorm:"default 0 INT(1)"` | |||
RefundTime time.Time `json:"refund_time" xorm:"DATETIME"` | |||
IsCancel int `json:"is_cancel" xorm:"default 0 INT(1)"` | |||
PayWay int `json:"pay_way" xorm:"default 0 INT(11)"` | |||
CommissionTime int `json:"commission_time" xorm:"default 0 INT(11)"` | |||
SettleTime int `json:"settle_time" xorm:"default 0 INT(11)"` | |||
CancelTime time.Time `json:"cancel_time" xorm:"DATETIME"` | |||
Info string `json:"info" xorm:"TEXT"` | |||
SendInfo string `json:"send_info" xorm:"TEXT"` | |||
WlOid string `json:"wl_oid" xorm:"VARCHAR(255)"` | |||
EmpName string `json:"emp_name" xorm:"VARCHAR(255)"` | |||
SenderPhone string `json:"sender_phone" xorm:"VARCHAR(255)"` | |||
ReceiverPhone string `json:"receiver_phone" xorm:"VARCHAR(255)"` | |||
CompanyCode string `json:"company_code" xorm:"VARCHAR(255)"` | |||
ExpressFirstAddPrice string `json:"express_first_add_price" xorm:"VARCHAR(255)"` | |||
ExpressSecondAddPrice string `json:"express_second_add_price" xorm:"VARCHAR(255)"` | |||
AgentPay int `json:"agent_pay" xorm:"default 0 INT(11)"` | |||
StationPay int `json:"station_pay" xorm:"default 0 INT(11)"` | |||
AgentPrice string `json:"agent_price" xorm:"default 0.00 comment('第一次') DECIMAL(20,2)"` | |||
StationPrice string `json:"station_price" xorm:"default 0.00 comment('第一次') DECIMAL(20,2)"` | |||
PlatformPrice string `json:"platform_price" xorm:"default 0.00 comment('第一次') DECIMAL(20,2)"` | |||
CreateMsg string `json:"create_msg" xorm:"TEXT"` | |||
ApiMsg string `json:"api_msg" xorm:"TEXT"` | |||
StationSupplementMoney string `json:"station_supplement_money" xorm:"default 0.00000000 DECIMAL(20,8)"` | |||
AgentSupplementMoney string `json:"agent_supplement_money" xorm:"default 0.00000000 DECIMAL(20,8)"` | |||
IsStationSupplementPay int `json:"is_station_supplement_pay" xorm:"default 0 INT(1)"` | |||
IsAgentSupplementPay int `json:"is_agent_supplement_pay" xorm:"default 0 INT(1)"` | |||
} |
@@ -0,0 +1,23 @@ | |||
package offical | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/offical/model" | |||
) | |||
func GetExpressWithWlOid(ordId string) *model.ExpressOrder { | |||
var data model.ExpressOrder | |||
get, _ := db.Db.Where(" wl_oid=?", ordId).Get(&data) | |||
if get { | |||
return &data | |||
} | |||
return nil | |||
} | |||
func GetExpressWithOid(ordId string) *model.ExpressOrder { | |||
var data model.ExpressOrder | |||
get, _ := db.Db.Where(" oid=?", ordId).Get(&data) | |||
if get { | |||
return &data | |||
} | |||
return nil | |||
} |
@@ -0,0 +1,19 @@ | |||
package offical | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/offical/model" | |||
) | |||
func MasterListCfgGetOneData(uid, key string) string { | |||
var cfgList model.MasterListCfg | |||
has, err := db.Db.Where("`k`=? and uid=?", key, uid).Get(&cfgList) | |||
if err != nil { | |||
return "" | |||
} | |||
if has == false { | |||
cfgList = model.MasterListCfg{Uid: uid, K: key} | |||
db.Db.InsertOne(&cfgList) | |||
} | |||
return cfgList.V | |||
} |
@@ -0,0 +1,15 @@ | |||
package offical | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/offical/model" | |||
) | |||
func GetUserAppList(uid string) *model.UserAppList { | |||
var data model.UserAppList | |||
get, err := db.Db.Where("uuid=?", uid).Get(&data) | |||
if get == false || err != nil { | |||
return nil | |||
} | |||
return &data | |||
} |
@@ -0,0 +1,7 @@ | |||
package model | |||
type ExpressAgentMoney struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Uid int `json:"uid" xorm:"default 0 comment('代理id') INT(11)"` | |||
Money string `json:"money" xorm:"default 0.00 DECIMAL(20,2)"` | |||
} |
@@ -0,0 +1,16 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type ExpressAgentMoneyFlow struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Uid int `json:"uid" xorm:"default 0 INT(11)"` | |||
Type int `json:"type" xorm:"default 0 comment('0收入 1支出') INT(1)"` | |||
Time time.Time `json:"time" xorm:"DATETIME"` | |||
Amount string `json:"amount" xorm:"default 0.00 DECIMAL(20,2)"` | |||
AfterAmount string `json:"after_amount" xorm:"default 0.00 DECIMAL(20,2)"` | |||
Oid string `json:"oid" xorm:"VARCHAR(255)"` | |||
Title string `json:"title" xorm:"VARCHAR(255)"` | |||
} |
@@ -0,0 +1,53 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type ExpressOrder struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Uid int `json:"uid" xorm:"default 0 INT(11)"` | |||
Mid int `json:"mid" xorm:"default 0 INT(11)"` | |||
AgentUid int `json:"agent_uid" xorm:"default 0 INT(11)"` | |||
Oid string `json:"oid" xorm:"VARCHAR(255)"` | |||
PvdOid string `json:"pvd_oid" xorm:"VARCHAR(255)"` | |||
CreateTime time.Time `json:"create_time" xorm:"DATETIME"` | |||
PayTime time.Time `json:"pay_time" xorm:"DATETIME"` | |||
SupplementPayTime time.Time `json:"supplement_pay_time" xorm:"comment('补交时间') DATETIME"` | |||
Money string `json:"money" xorm:"default 0.00000000 comment('第一次') DECIMAL(20,8)"` | |||
Profit string `json:"profit" xorm:"default 0.00000000 comment('利润') DECIMAL(20,8)"` | |||
RealProfit string `json:"real_profit" xorm:"default 0.00000000 comment('利润') DECIMAL(20,8)"` | |||
SupplementMoney string `json:"supplement_money" xorm:"default 0.00000000 DECIMAL(20,8)"` | |||
StationSupplementMoney string `json:"station_supplement_money" xorm:"default 0.00000000 DECIMAL(20,8)"` | |||
AgentSupplementMoney string `json:"agent_supplement_money" xorm:"default 0.00000000 DECIMAL(20,8)"` | |||
IsPay int `json:"is_pay" xorm:"default 0 INT(1)"` | |||
IsStationSupplementPay int `json:"is_station_supplement_pay" xorm:"default 0 INT(1)"` | |||
IsAgentSupplementPay int `json:"is_agent_supplement_pay" xorm:"default 0 INT(1)"` | |||
IsSupplementPay int `json:"is_agent_supplement_pay" xorm:"default 0 INT(1)"` | |||
Status string `json:"status" xorm:"VARCHAR(255)"` | |||
Ext string `json:"ext" xorm:"TEXT"` | |||
IsRefund int `json:"is_refund" xorm:"default 0 INT(1)"` | |||
RefundTime time.Time `json:"refund_time" xorm:"DATETIME"` | |||
IsCancel int `json:"is_cancel" xorm:"default 0 INT(1)"` | |||
PayWay int `json:"pay_way" xorm:"default 0 INT(11)"` | |||
CommissionTime int `json:"commission_time" xorm:"default 0 INT(11)"` | |||
SettleTime int `json:"settle_time" xorm:"default 0 INT(11)"` | |||
CancelTime time.Time `json:"cancel_time" xorm:"DATETIME"` | |||
Info string `json:"info" xorm:"TEXT"` | |||
SendInfo string `json:"send_info" xorm:"TEXT"` | |||
WlOid string `json:"wl_oid" xorm:"VARCHAR(255)"` | |||
EmpName string `json:"emp_name" xorm:"VARCHAR(255)"` | |||
SenderPhone string `json:"sender_phone" xorm:"VARCHAR(255)"` | |||
ReceiverPhone string `json:"receiver_phone" xorm:"VARCHAR(255)"` | |||
CompanyCode string `json:"company_code" xorm:"VARCHAR(255)"` | |||
ExpressFirstAddPrice string `json:"express_first_add_price" xorm:"VARCHAR(255)"` | |||
ExpressSecondAddPrice string `json:"express_second_add_price" xorm:"VARCHAR(255)"` | |||
OfficialExpressFirstAddPrice string `json:"official_express_first_add_price" xorm:"VARCHAR(255)"` | |||
OfficialExpressSecondAddPrice string `json:"official_express_second_add_price" xorm:"VARCHAR(255)"` | |||
AgentPay int `json:"agent_pay" xorm:"default 0 INT(11)"` | |||
StationPay int `json:"station_pay" xorm:"default 0 INT(11)"` | |||
AgentPrice string `json:"agent_price" xorm:"default 0.00 comment('第一次') DECIMAL(20,2)"` | |||
StationPrice string `json:"station_price" xorm:"default 0.00 comment('第一次') DECIMAL(20,2)"` | |||
PlatformPrice string `json:"platform_price" xorm:"default 0.00 comment('第一次') DECIMAL(20,2)"` | |||
CreateMsg string `json:"create_msg" xorm:"TEXT"` | |||
} |
@@ -0,0 +1,8 @@ | |||
package model | |||
type ExpressUserMoney struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Uid int `json:"uid" xorm:"default 0 comment('代理id') INT(11)"` | |||
AgentUid int `json:"agent_uid" xorm:"default 0 comment('代理id') INT(11)"` | |||
Money string `json:"money" xorm:"default 0.00 DECIMAL(20,2)"` | |||
} |
@@ -0,0 +1,16 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type ExpressUserMoneyFlow struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Uid int `json:"uid" xorm:"default 0 INT(11)"` | |||
Type int `json:"type" xorm:"default 0 comment('0收入 1支出') INT(1)"` | |||
Time time.Time `json:"time" xorm:"DATETIME"` | |||
Amount string `json:"amount" xorm:"default 0.00 DECIMAL(20,2)"` | |||
AfterAmount string `json:"after_amount" xorm:"default 0.00 DECIMAL(20,2)"` | |||
Oid string `json:"oid" xorm:"VARCHAR(255)"` | |||
Title string `json:"title" xorm:"VARCHAR(255)"` | |||
} |
@@ -0,0 +1,9 @@ | |||
package model | |||
type MasterListCfg struct { | |||
K string `json:"k" xorm:"not null VARCHAR(255)"` | |||
V string `json:"v" xorm:"TEXT"` | |||
Memo string `json:"memo" xorm:"VARCHAR(255)"` | |||
Uid string `json:"uid" xorm:"comment('0是官方') VARCHAR(255)"` | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
} |
@@ -0,0 +1,33 @@ | |||
package model | |||
type UserAppList struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Uuid int `json:"uuid" xorm:"not null comment('masterId') INT(10)"` | |||
Uid int `json:"uid" xorm:"not null comment('用户ID') INT(10)"` | |||
AppId int `json:"app_id" xorm:"not null comment('应用ID') INT(10)"` | |||
PlanId string `json:"plan_id" xorm:"not null default '' comment('套餐ID') VARCHAR(100)"` | |||
Expire int `json:"expire" xorm:"not null default 0 comment('过期时间') INT(10)"` | |||
Name string `json:"name" xorm:"not null default '' comment('应用主名称') VARCHAR(32)"` | |||
Icon string `json:"icon" xorm:"not null default '' comment('应用主图标') VARCHAR(250)"` | |||
CreateTime int `json:"create_time" xorm:"not null default 0 comment('初次激活时间') INT(10)"` | |||
RenewTime int `json:"renew_time" xorm:"not null default 0 comment('上次续费时间') INT(10)"` | |||
Domain string `json:"domain" xorm:"not null default '' comment('域名') index VARCHAR(110)"` | |||
DomainAlias string `json:"domain_alias" xorm:"not null default '' comment('域名别名') index VARCHAR(110)"` | |||
Platform string `json:"platform" xorm:"not null default '' comment('平台信息 ios,android,applet') VARCHAR(100)"` | |||
Info string `json:"info" xorm:"comment('平台名称如ios.name.#ddd;') TEXT"` | |||
PayMode int `json:"pay_mode" xorm:"not null default 1 comment('付费模式,0授信,1付款') TINYINT(1)"` | |||
Price float32 `json:"price" xorm:"not null default 0.00 comment('应用价格') FLOAT(10,2)"` | |||
PricePay float32 `json:"price_pay" xorm:"not null default 0.00 comment('实际付款价格') FLOAT(10,2)"` | |||
OfficialPrice float32 `json:"official_price" xorm:"not null default 0.00 comment('应用价格') FLOAT(10,2)"` | |||
OfficialPricePay float32 `json:"official_price_pay" xorm:"not null default 0.00 comment('实际付款价格') FLOAT(10,2)"` | |||
State int `json:"state" xorm:"not null default 0 comment('0未创建,1正常,2停用,3过期') TINYINT(1)"` | |||
DeleteAt int `json:"delete_at" xorm:"not null default 0 TINYINT(1)"` | |||
CustomAndroidCount int `json:"custom_android_count" xorm:"default 0 comment('客户端安卓包名重置次数') INT(11)"` | |||
CustomIosCount int `json:"custom_ios_count" xorm:"default 0 comment('客户端ios包名重置次数') INT(11)"` | |||
StoreAndroidCount int `json:"store_android_count" xorm:"default 0 comment('商家端安卓包名重置次数') INT(11)"` | |||
StoreIosCount int `json:"store_ios_count" xorm:"default 0 comment('商家端ios包名重置次数') INT(11)"` | |||
SmsPlatform string `json:"sms_platform" xorm:"default 'mob' comment('mob ljioe联江') VARCHAR(255)"` | |||
IsClose int `json:"is_close" xorm:"default 0 comment('是否关闭') INT(1)"` | |||
Puid int `json:"puid" xorm:"default 0 comment('') INT(11)"` | |||
StoreRateInfo string `json:"store_rate_info" xorm:"comment('付呗商品进件费率') TEXT"` | |||
} |
@@ -0,0 +1,75 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
//公共处理记录 | |||
func DealMoneyWithEg(eg *xorm.Engine, uid int, paidPrice string, orderAction int, ordId int64, id int64, goodsId int, ItemTitle string, ordType string, is_reduce int) { | |||
if utils.StrToFloat64(paidPrice) == 0 { | |||
return | |||
} | |||
//TODO 暂时退到余额 | |||
session := eg.NewSession() | |||
userProfile, err := db.UserProfileFindByIdWithSession(session, uid) | |||
if err != nil || userProfile == nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
// 更新用户余额 | |||
beforeAmount := userProfile.FinValid | |||
var types = 0 | |||
if is_reduce == 1 { | |||
types = 1 | |||
userProfile.FinValid = utils.AnyToString(utils.AnyToFloat64(userProfile.FinValid) - utils.StrToFloat64(paidPrice)) | |||
} else { | |||
userProfile.FinValid = utils.AnyToString(utils.AnyToFloat64(userProfile.FinValid) + utils.StrToFloat64(paidPrice)) | |||
} | |||
userProfile.FinTotal = userProfile.FinTotal + utils.StrToFloat32(paidPrice) | |||
affected, err := db.UserProfileUpdateWithSession(session, uid, userProfile, "fin_valid", "fin_total") | |||
if affected == 0 { | |||
_ = session.Rollback() | |||
return | |||
} | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
// 开始写入流水 | |||
FlowInsert(eg, uid, paidPrice, orderAction, ordId, id, goodsId, ItemTitle, ordType, types, beforeAmount, userProfile.FinValid) | |||
} | |||
// 开始写入流水 | |||
func FlowInsert(eg *xorm.Engine, uid int, paidPrice string, orderAction int, ordId int64, id int64, goodsId int, ItemTitle string, ordType string, types int, beforeAmount string, afterAmount string) { | |||
session := eg.NewSession() | |||
now := time.Now() | |||
if err := db.FinUserFlowInsertOneWithSession( | |||
session, | |||
&model.FinUserFlow{ | |||
Type: types, | |||
Uid: uid, | |||
Amount: paidPrice, | |||
BeforeAmount: beforeAmount, | |||
AfterAmount: afterAmount, | |||
OrdType: ordType, | |||
OrdId: utils.Int64ToStr(ordId), | |||
OrdAction: orderAction, | |||
OrdDetail: utils.IntToStr(goodsId), | |||
State: 2, | |||
OtherId: id, | |||
OrdTitle: ItemTitle, | |||
OrdTime: int(now.Unix()), | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}); err != nil { | |||
_ = session.Rollback() | |||
_ = logx.Warn(err) | |||
return | |||
} | |||
} |
@@ -43,6 +43,7 @@ func initConsumes() { | |||
jobs[consumeMd.ZhiosTikTokAllUpdateFunName] = ZhiosTikTokAllUpdate | |||
jobs[consumeMd.ZhiosCapitalPoolOrderTotalFunName] = ZhiosCapitalPoolOrderTotal | |||
jobs[consumeMd.ZhiosExpressOrderFail] = ZhiosExpressOrderFail | |||
//jobs[consumeMd.ZhiosRechargeOrderFailDevFunName] = ZhiosRechargeOrderFailDev | |||
@@ -192,6 +192,15 @@ var RabbitMqQueueKeyList = []*MqQueue{ | |||
BindKey: "", | |||
ConsumeFunName: "ZhiosRechargeOrderFailDev", | |||
}, | |||
{ | |||
ExchangeName: "zhios.express.order.exchange", | |||
Name: "zhios_express_order_fail", | |||
Type: DirectQueueType, | |||
IsPersistent: false, | |||
RoutKey: "order_fail", | |||
BindKey: "", | |||
ConsumeFunName: "zhiosExpressOrderFail", | |||
}, | |||
} | |||
const ( | |||
@@ -211,6 +220,7 @@ const ( | |||
ZhiosRechargeOrderFailFunName = "ZhiosRechargeOrderFail" | |||
ZhiosRechargeOrderFailDevFunName = "ZhiosRechargeOrderFailDev" | |||
ZhiosCapitalPoolOrderTotalFunName = "ZhiosCapitalPoolOrderTotal" | |||
ZhiosExpressOrderFail = "zhiosExpressOrderFail" | |||
ZhiosTikTokUpdateFunName = "ZhiosTikTokUpdate" | |||
ZhiosTikTokAllUpdateFunName = "ZhiosTikTokAllUpdate" | |||
CloudIssuanceAsyncMLoginFunName = "CloudIssuanceAsyncMLoginConsume" | |||
@@ -8,3 +8,9 @@ type ZhiosCapitalPoolOrderTotal struct { | |||
BonusLevelType int `json:"bonusLevelType"` | |||
Level string `json:"level"` | |||
} | |||
type ZhiosExpressOrderFails struct { | |||
Uid string `json:"uid"` | |||
Mid string `json:"mid"` | |||
Oid string `json:"oid"` | |||
IsFail string `json:"is_fail"` | |||
} |
@@ -0,0 +1,246 @@ | |||
package consume | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/offical" | |||
"applet/app/db/offical/model" | |||
"applet/app/e" | |||
"applet/app/svc" | |||
"applet/app/utils" | |||
"applet/app/utils/cache" | |||
"applet/app/utils/logx" | |||
"applet/consume/md" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/express" | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
"github.com/streadway/amqp" | |||
"github.com/tidwall/gjson" | |||
"time" | |||
) | |||
func ZhiosExpressOrderFail(queue md.MqQueue) { | |||
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>") | |||
ch, err := rabbit.Cfg.Pool.GetChannel() | |||
if err != nil { | |||
logx.Error(err) | |||
return | |||
} | |||
defer ch.Release() | |||
//1、将自己绑定到交换机上 | |||
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey) | |||
//2、取出数据进行消费 | |||
ch.Qos(20) | |||
delivery := ch.Consume(queue.Name, false) | |||
var res amqp.Delivery | |||
var ok bool | |||
for { | |||
res, ok = <-delivery | |||
if ok == true { | |||
//fmt.Println(string(res.Body)) | |||
fmt.Println(">>>>>>>>>>>>>>>>CanalOrderConsume<<<<<<<<<<<<<<<<<<<<<<<<<") | |||
err = handleZhiosExpressOrderFail(res.Body) | |||
//_ = res.Reject(false) | |||
if err == nil { | |||
_ = res.Ack(true) | |||
} | |||
} else { | |||
panic(errors.New("error getting message")) | |||
} | |||
} | |||
fmt.Println("get msg done") | |||
} | |||
func handleZhiosExpressOrderFail(msg []byte) error { | |||
//1、解析canal采集至mq中queue的数据结构体 | |||
var canalMsg *md.ZhiosExpressOrderFails | |||
fmt.Println(string(msg)) | |||
var tmpString string | |||
err := json.Unmarshal(msg, &tmpString) | |||
if err != nil { | |||
fmt.Println(err.Error()) | |||
return err | |||
} | |||
fmt.Println(tmpString) | |||
err = json.Unmarshal([]byte(tmpString), &canalMsg) | |||
if err != nil { | |||
return err | |||
} | |||
mid := canalMsg.Mid | |||
eg := db.DBs[mid] | |||
if eg == nil { | |||
return nil | |||
} | |||
//判断订单是否订单失败 | |||
ord := db.GetExpressWithOid(eg, canalMsg.Oid) | |||
officialOrd := offical.GetExpressWithOid(canalMsg.Oid) | |||
if ord.Status == "已退回" { | |||
return nil | |||
} | |||
base := CommBase(mid) | |||
if canalMsg.IsFail != "1" { //查下订单详情 | |||
param := map[string]interface{}{ | |||
"clientOrderNo": canalMsg.Oid, | |||
} | |||
order, _ := express.ShowOrder(base, param) | |||
if gjson.Get(order, "code").Int() == 500 || gjson.Get(order, "code").String() != "00" || gjson.Get(order, "data.status").String() == "CANCELED" { | |||
ord.Status = "订单失败" | |||
} | |||
} | |||
if ord.Status == "订单失败" || ord.Status == "已取消" { | |||
ord.Status = "已退回" | |||
ord.IsRefund = 1 | |||
ord.RefundTime = time.Now() | |||
officialOrd.Status = "已退回" | |||
officialOrd.IsRefund = 1 | |||
officialOrd.RefundTime = time.Now() | |||
eg.Where("oid=?", ord.Oid).Update(ord) | |||
db.Db.Where("oid=?", officialOrd.Oid).Update(officialOrd) | |||
svc.DealMoneyWithEg(eg, ord.Uid, ord.Money, 56, utils.StrToInt64(ord.Oid), 0, 0, "快递退款", "express", 0) | |||
if ord.AgentPay == 1 { | |||
agentDeduct(ord.Oid, base, ord.AgentPrice) | |||
} | |||
if ord.StationPay == 1 { | |||
stationDeduct(mid, ord.Oid, base, ord.StationPrice) | |||
} | |||
} | |||
return nil | |||
} | |||
//站长预存款扣除 | |||
func stationDeduct(dbName, oid string, base map[string]string, price string) (error, int) { | |||
eg := db.Db | |||
var user model.ExpressUserMoney | |||
get, err := eg.Where("uid=? and agent_uid=?", dbName, base["puid"]).Get(&user) | |||
if get == false || err != nil { | |||
return e.NewErr(400, "站点预存款不足!"), 0 | |||
} | |||
user.Money = utils.Float64ToStr(utils.StrToFloat64(user.Money) + utils.StrToFloat64(price)) | |||
_, err = eg.Where("id=?", user.Id).Update(&user) | |||
if err != nil { | |||
return e.NewErr(400, "站点预存款扣除失败!"), 0 | |||
} | |||
var flow = &model.ExpressUserMoneyFlow{ | |||
Uid: user.Uid, | |||
Type: 0, | |||
Time: time.Now(), | |||
Amount: price, | |||
AfterAmount: user.Money, | |||
Oid: oid, | |||
Title: "快递退款", | |||
} | |||
_, err = eg.Insert(flow) | |||
if err != nil { | |||
return e.NewErr(400, "站点预存款扣除失败!"), 0 | |||
} | |||
return nil, 1 | |||
} | |||
func agentDeduct(oid string, base map[string]string, price string) (error, int) { | |||
eg := db.Db | |||
var user model.ExpressAgentMoney | |||
get, err := eg.Where("uid=?", base["puid"]).Get(&user) | |||
if get == false || err != nil { | |||
return e.NewErr(400, "平台预存款不足!"), 0 | |||
} | |||
user.Money = utils.Float64ToStr(utils.StrToFloat64(user.Money) + utils.StrToFloat64(price)) | |||
_, err = eg.Where("id=?", user.Id).Update(&user) | |||
if err != nil { | |||
return e.NewErr(400, "平台预存款扣除失败!"), 0 | |||
} | |||
var flow = &model.ExpressAgentMoneyFlow{ | |||
Uid: user.Uid, | |||
Type: 0, | |||
Time: time.Now(), | |||
Amount: price, | |||
AfterAmount: user.Money, | |||
Oid: oid, | |||
Title: "快递退款", | |||
} | |||
_, err = eg.Insert(flow) | |||
if err != nil { | |||
return e.NewErr(400, "平台预存款扣除失败!"), 0 | |||
} | |||
return nil, 1 | |||
} | |||
func AppUserListPuid(mid string) string { | |||
appList := offical.GetUserAppList(mid) | |||
uid := "0" | |||
if appList != nil && appList.Puid > 0 { | |||
uid = utils.IntToStr(appList.Puid) | |||
} | |||
return uid | |||
} | |||
func CommBase(mid string) map[string]string { | |||
puid := AppUserListPuid(mid) | |||
key := puid + "_official_express_info" | |||
stringStr, err := cache.GetString(key) | |||
stringMap := make(map[string]string) | |||
json.Unmarshal([]byte(stringStr), &stringMap) | |||
if len(stringMap) == 0 || err != nil { | |||
expressType := offical.MasterListCfgGetOneData(puid, "express_type") | |||
expressUrl := offical.MasterListCfgGetOneData(puid, "express_url") | |||
expressClientId := offical.MasterListCfgGetOneData(puid, "express_client_id") | |||
expressKey := offical.MasterListCfgGetOneData(puid, "express_key") | |||
expressMinSendMoney := offical.MasterListCfgGetOneData(puid, "express_min_send_money") //最低预存款 | |||
expressFeeSendMoney := offical.MasterListCfgGetOneData(puid, "express_fee_send_money") //充值预存款手续费 | |||
expressFirstPayBili := offical.MasterListCfgGetOneData(puid, "express_first_pay_bili") //首重加价 | |||
expressSecondPayBili := offical.MasterListCfgGetOneData(puid, "express_second_pay_bili") //续重加价 | |||
stringMap = map[string]string{ | |||
"puid": puid, | |||
"express_type": expressType, | |||
"express_url": expressUrl, | |||
"express_key": expressKey, | |||
"express_client_id": expressClientId, | |||
"express_min_send_money": "", | |||
"express_fee_send_money": "", | |||
"express_first_pay_bili": "", | |||
"express_second_pay_bili": "", | |||
"official_express_min_send_money": expressMinSendMoney, | |||
"official_express_fee_send_money": expressFeeSendMoney, | |||
"official_express_first_pay_bili": expressFirstPayBili, | |||
"official_express_second_pay_bili": expressSecondPayBili, | |||
} | |||
//如果是官方 不是代理就没有代理的设置 | |||
//如果是代理 就有代理的设置 | |||
if utils.StrToInt(puid) > 0 { | |||
stringMap["express_min_send_money"] = expressMinSendMoney | |||
stringMap["express_fee_send_money"] = expressFeeSendMoney | |||
stringMap["express_first_pay_bili"] = expressFirstPayBili | |||
stringMap["express_second_pay_bili"] = expressSecondPayBili | |||
if stringMap["express_type"] == "1" { //代理自有渠道,智莺的加价不用了 | |||
stringMap["official_express_min_send_money"] = "" | |||
stringMap["official_express_fee_send_money"] = "" | |||
stringMap["official_express_first_pay_bili"] = "" | |||
stringMap["official_express_second_pay_bili"] = "" | |||
} | |||
} | |||
cache.SetEx(key, utils.SerializeStr(stringMap), 300) | |||
} | |||
if utils.StrToInt(puid) > 0 && stringMap["express_type"] != "1" { //跟随官方 | |||
key1 := "0_official_express_info" | |||
stringStr1, err1 := cache.GetString(key1) | |||
stringMap1 := make(map[string]string) | |||
json.Unmarshal([]byte(stringStr1), &stringMap1) | |||
if len(stringMap1) == 0 || err1 != nil { //如果是代理 但只有官方设置 | |||
stringMap1 = make(map[string]string) | |||
stringMap1["express_url"] = offical.MasterListCfgGetOneData("0", "express_url") | |||
stringMap1["express_client_id"] = offical.MasterListCfgGetOneData("0", "express_client_id") | |||
stringMap1["express_key"] = offical.MasterListCfgGetOneData("0", "express_key") | |||
stringMap1["official_express_min_send_money"] = offical.MasterListCfgGetOneData("0", "express_min_send_money") //最低预存款 | |||
stringMap1["official_express_fee_send_money"] = offical.MasterListCfgGetOneData("0", "express_fee_send_money") //充值预存款手续费 | |||
stringMap1["official_express_first_pay_bili"] = offical.MasterListCfgGetOneData("0", "express_first_pay_bili") //首重加价 | |||
stringMap1["official_express_second_pay_bili"] = offical.MasterListCfgGetOneData("0", "express_second_pay_bili") //续重加价 | |||
cache.SetEx(key1, utils.SerializeStr(stringMap1), 300) | |||
} | |||
for k, v := range stringMap1 { | |||
stringMap[k] = v | |||
} | |||
} | |||
return stringMap | |||
} |
@@ -7,7 +7,7 @@ require ( | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.0 | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.4 | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git v1.6.2-0.20230825083620-ef8b12df8cf8 | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20230703061209-fc6ac71cc155 | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20230911014653-22cc8e626d17 | |||
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 | |||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 | |||
github.com/boombuler/barcode v1.0.1 | |||