diff --git a/app/db/model/fb_pay_set.go b/app/db/model/fb_pay_set.go new file mode 100644 index 0000000..1feb463 --- /dev/null +++ b/app/db/model/fb_pay_set.go @@ -0,0 +1,21 @@ +package model + +import ( + "time" +) + +type FbPaySet struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + IsUse int `json:"is_use" xorm:"not null default 0 comment('1开启') TINYINT(1)"` + VendorSn string `json:"vendor_sn" xorm:"not null comment('服务商开放平台id(服务商后台生成') VARCHAR(255)"` + StoreId string `json:"store_id" xorm:"not null comment('商户门店号') VARCHAR(255)"` + AppSecret string `json:"app_secret" xorm:"not null default '' comment('appSecret') VARCHAR(255)"` + MerchantId string `json:"merchant_id" xorm:"not null comment('呗商户号,以服务商级接入时必传,以商户级接入时不传') VARCHAR(255)"` + PayImg string `json:"pay_img" xorm:"not null comment('支付图标') VARCHAR(255)"` + UpdateTime time.Time `json:"update_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"` + AliPayUse int `json:"ali_pay_use" xorm:"not null default 1 comment('1开启') TINYINT(1)"` + WechatPayUse int `json:"wechat_pay_use" xorm:"not null default 1 comment('1开启') TINYINT(1)"` + FastPayUse int `json:"fast_pay_use" xorm:"default 0 comment('1开启') TINYINT(1)"` + AppId string `json:"app_id" xorm:"not null comment('付呗应用id') VARCHAR(255)"` + OriginalId string `json:"original_id" xorm:"comment('original_id') VARCHAR(255)"` +} diff --git a/app/db/model/fb_pay_set_func.go b/app/db/model/fb_pay_set_func.go new file mode 100644 index 0000000..4748011 --- /dev/null +++ b/app/db/model/fb_pay_set_func.go @@ -0,0 +1,83 @@ +package model + +import ( + "applet/app/utils/cache" + "fmt" + jsoniter "github.com/json-iterator/go" + "xorm.io/xorm" +) + +var Json = jsoniter.ConfigCompatibleWithStandardLibrary + +func (set *FbPaySet) init(engine *xorm.Engine) error { + _, err := engine.Insert(set) + return err +} + +func (set *FbPaySet) Get(engine *xorm.Engine) error { + exist, err := engine.IsTableExist(set) + if err != nil { + return err + } + if !exist { + if err := engine.CreateTables(set); err != nil { + return err + } + } + if err != nil { + return err + } + get, err := engine.Get(set) + if err != nil { + return err + } + if !get { + err := set.init(engine) + if err != nil { + return err + } + } + return nil +} + +func (set *FbPaySet) Update(engine *xorm.Engine, cols []string) error { + if len(cols) == 0 { + _, err := engine.ID(set.Id).AllCols().Update(set) + if err != nil { + return err + } + return nil + } else { + _, err := engine.ID(set.Id).Cols(cols...).Update(set) + if err != nil { + return err + } + return nil + } +} + +func (set *FbPaySet) ToRedis(mid string) error { + marshalToString, err := Json.MarshalToString(set) + if err != nil { + return err + } + key := fmt.Sprintf("%s:fb_pay_setting", mid) + _, err = cache.SetEx(key, marshalToString, 39528000) // 半年 + if err != nil { + return err + } + return nil +} + +func (set *FbPaySet) GetByRedis(mid string) bool { + key := fmt.Sprintf("%s:fb_pay_setting", mid) + marshalString, _ := cache.GetString(key) + if marshalString == "" || len(marshalString) < 10 { + return false + } + err := Json.UnmarshalFromString(marshalString, set) + if err != nil { + return false + } + return true +} diff --git a/app/db/model/merchant_income_info.go b/app/db/model/merchant_income_info.go new file mode 100644 index 0000000..bb1cb0e --- /dev/null +++ b/app/db/model/merchant_income_info.go @@ -0,0 +1,42 @@ +package model + +import ( + "time" +) + +type MerchantIncomeInfo struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + ZyosMerchantId int `json:"zyos_merchant_id" xorm:"not null comment('智莺商家id') INT(11)"` + FbMerchantCode string `json:"fb_merchant_code" xorm:"not null comment('付呗商户账号') VARCHAR(255)"` + SalesMan int `json:"sales_man" xorm:"comment('授理商编号') INT(11)"` + BaseInfo string `json:"base_info" xorm:"not null comment('付呗商户基本信息') TEXT"` + LegalPerson string `json:"legal_person" xorm:"not null comment('付呗法人信息,个人类型填联系人信息') TEXT"` + AddressInfo string `json:"address_info" xorm:"not null comment('付呗店铺地址信息') TEXT"` + LicenseInfo string `json:"license_info" xorm:"comment('付呗(营业资质信息)注:小微进件不要传此对象') TEXT"` + AccountInfo string `json:"account_info" xorm:"comment('付呗结算信息') TEXT"` + ShopInfo string `json:"shop_info" xorm:"comment('付呗门店信息') TEXT"` + RateInfo string `json:"rate_info" xorm:"comment('付呗费率') TEXT"` + OtherInfo string `json:"other_info" xorm:"comment('付呗其它信息') TEXT"` + CreateTime time.Time `json:"create_time" xorm:"created not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"` + UpdateTime time.Time `json:"update_time" xorm:"updated not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"` + DeletedTime time.Time `json:"deleted_time" xorm:"deleted comment('删除时间') DATETIME"` + FbMerchantId int `json:"fb_merchant_id" xorm:"comment('付呗商户号') INT(11)"` + FbStoreId int `json:"fb_store_id" xorm:"comment('付呗门店ID') INT(11)"` + IncomeSuccessInfo string `json:"income_success_info" xorm:"comment('付呗入驻成功后返回的信息') TEXT"` + LegalIdCardFrontPhoto string `json:"legal_id_card_front_photo" xorm:"comment('法人身份证正面二进制数据源') TEXT"` + LegalIdCardBackPhoto string `json:"legal_id_card_back_photo" xorm:"comment('法人身份证反面二进制数据源') TEXT"` + HandHoldIdCardPhoto string `json:"hand_hold_id_card_photo" xorm:"comment('手持身份证照二进制数据源') TEXT"` + LicensePhoto string `json:"license_photo" xorm:"comment('营业执照照片二进制数据源') TEXT"` + StoreEnvPhoto string `json:"store_env_photo" xorm:"comment('经营场所内设照片二进制数据源') TEXT"` + StoreFrontPhoto string `json:"store_front_photo" xorm:"comment('门头照二进制数据源') TEXT"` + StoreCashPhoto string `json:"store_cash_photo" xorm:"comment('收银台照片二进制数据源') TEXT"` + OperatingLicensePhoto string `json:"operating_license_photo" xorm:"comment('经营许可证图片二进制数据源') TEXT"` + BankCardPhoto string `json:"bank_card_photo" xorm:"comment('银行卡正面二进制数据源') TEXT"` + IdCardFrontPhoto string `json:"id_card_front_photo" xorm:"comment('结算人身份证正面二进制数据源') TEXT"` + IdCardBackPhoto string `json:"id_card_back_photo" xorm:"comment('结算人身份证反面二进制数据源') TEXT"` + GroupCreateState int `json:"group_create_state" xorm:"comment('创建分账组是否成功') INT(11)"` + GroupCreateResp string `json:"group_create_resp" xorm:"comment('创建分账组返回结果') TEXT"` + GroupId string `json:"group_id" xorm:"not null comment('分账组id') VARCHAR(255)"` + AgreementImg string `json:"agreement_img" xorm:"not null comment('') VARCHAR(600)"` + AppSupplementInfo string `json:"app_supplement_info" xorm:"comment('app补充信息') TEXT"` +} diff --git a/app/db/model/station_ledger_info.go b/app/db/model/station_ledger_info.go new file mode 100644 index 0000000..107ecd5 --- /dev/null +++ b/app/db/model/station_ledger_info.go @@ -0,0 +1,23 @@ +package model + +type StationLedgerInfo struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + MerchantOrderSn string `json:"merchant_order_sn" xorm:"comment('系统订单号') VARCHAR(255)"` + Info string `json:"info" xorm:"comment('申请信息') TEXT"` + AccountId string `json:"account_id" xorm:"comment('分账id') VARCHAR(100)"` + Type string `json:"type" xorm:"comment('第三方类型 付呗--fubei') VARCHAR(50)"` + State int `json:"state" xorm:"default 0 comment('1审核中 2审核成功 3审核失败') INT(1)"` + ReturnData string `json:"return_data" xorm:"comment('第三方返回信息') TEXT"` + FailMessage string `json:"fail_message" xorm:"comment('失败原因') VARCHAR(255)"` + MerchantId string `json:"merchant_id" xorm:"comment('商户id') VARCHAR(100)"` + LegalPersonIdCardFrontPhoto string `json:"legal_person_id_card_front_photo" xorm:"comment('法人证件正面照片') TEXT"` + LegalPersonIdCardBackPhoto string `json:"legal_person_id_card_back_photo" xorm:"comment('法人证件反面照片') TEXT"` + SettlementPersonIdCardFrontPhoto string `json:"settlement_person_id_card_front_photo" xorm:"comment('结算人证件正面照片') TEXT"` + SettlementPersonIdCardBackPhoto string `json:"settlement_person_id_card_back_photo" xorm:"comment('结算人证件反面照片') TEXT"` + BankCardPhoto string `json:"bank_card_photo" xorm:"comment('结算银行卡照片') TEXT"` + LicensePhoto string `json:"license_photo" xorm:"comment('营业执照照片地址') TEXT"` + AuthorizationPic string `json:"authorization_pic" xorm:"comment('非法人结算授权函 ') TEXT"` + StoreEnvPhoto string `json:"store_env_photo" xorm:"comment('店内环境照') TEXT"` + StoreFrontImgUrl string `json:"store_front_img_url" xorm:"comment('门头照') TEXT"` + StoreCashPhoto string `json:"store_cash_photo" xorm:"comment('收银台照片') TEXT"` +} diff --git a/app/db/model/yibao_share_money.go b/app/db/model/yibao_share_money.go index 7bc2b1f..3214890 100644 --- a/app/db/model/yibao_share_money.go +++ b/app/db/model/yibao_share_money.go @@ -16,4 +16,5 @@ type YibaoShareMoney struct { EndStatus string `json:"end_status" xorm:"VARCHAR(255)"` Param string `json:"param" xorm:"TEXT"` EndParam string `json:"end_param" xorm:"TEXT"` + Type string `json:"type" xorm:"VARCHAR(255)"` } diff --git a/consume/yibao_order_share_money_mall.go b/consume/yibao_order_share_money_mall.go index 0e9e546..1707c94 100644 --- a/consume/yibao_order_share_money_mall.go +++ b/consume/yibao_order_share_money_mall.go @@ -1,18 +1,22 @@ package consume import ( + "applet/app/cfg" "applet/app/db" "applet/app/db/model" "applet/app/utils" "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_pay.git/lib/fb_pay" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db/offical" "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/yibao_pay" "encoding/json" "errors" "fmt" "github.com/streadway/amqp" "github.com/tidwall/gjson" + "time" "xorm.io/xorm" ) @@ -91,10 +95,124 @@ func handleZhiosYibao0rderShareMoneyMallExchange(msg []byte) error { total += utils.StrToFloat64(v.CostPrice) } total += fee - commShare(eg, payMethod, total, payOid, uniqueOrderNo, MerchantNo, uid) + if utils.InArr(utils.IntToStr(payMethod), []string{"21", "22"}) { + yibaoShare(eg, payMethod, total, payOid, uniqueOrderNo, MerchantNo, uid) + } else if utils.InArr(utils.IntToStr(payMethod), []string{"19"}) { + fbShare(eg, canalMsg.Mid, payMethod, total, payOid, uniqueOrderNo, MerchantNo, uid) + } return nil } -func commShare(eg *xorm.Engine, payMethod int, total float64, payOid, uniqueOrderNo, MerchantNo string, uid int) { +func fbShare(eg *xorm.Engine, dbName string, payMethod int, total float64, payOid, uniqueOrderNo, MerchantNo string, uid int) { + key := yibao_pay.CommKey(db.Db, true) + zhiyingOnlineBili := utils.StrToFloat64(key["zhiyingOnlineBili"]) - 0.63 + zhiyingUnlineBili := utils.StrToFloat64(key["zhiyingUnlineBili"]) - 0.63 + allBili := utils.StrToFloat64(key["zhiyingUnlineBili"]) / 100 + bili := zhiyingUnlineBili / 100 + if payMethod == 19 { + allBili = utils.StrToFloat64(key["zhiyingOnlineBili"]) / 100 + bili = zhiyingOnlineBili / 100 + } + fee := total * bili + if fee < 0.01 { + fee = 0 + } + req3 := map[string]string{} + req3["key"] = utils.SerializeStr(key) + req3["bili"] = utils.Float64ToStr(bili) + var tmp = model.YibaoShareMoney{ + Oid: utils.OrderUUID(uid), + PayOid: payOid, + StoreMoney: utils.Float64ToStr(total - total*allBili), + ZhiyingMoney: utils.Float64ToStr(total * bili), + Platform: "mall", + PayMethod: utils.IntToStr(payMethod), + Param: utils.SerializeStr(req3), + Type: "fb", + } + eg.Insert(&tmp) + //4、调用分账接口 + fbPaySet, err := GetFbMdSetting(eg, dbName) + if err != nil { + utils.FilePutContents("GetFbMdSettingErr", "err:"+err.Error()) + logx.Warn(err) + return + } + if fbPaySet.VendorSn == "" { + err = errors.New("没有设置相关付呗支付信息") + utils.FilePutContents("GetFbMdSettingErr", "err:"+err.Error()) + logx.Warn(err) + return + } + var ( + merchantIncomeInfo model.MerchantIncomeInfo + ) + if merchantIncomeInfo.FbStoreId == 0 || merchantIncomeInfo.FbMerchantId == 0 { + err = errors.New("付呗支付暂未开通") + utils.FilePutContents("GetMerchantIncomeInfoErr", "err:"+err.Error()) + logx.Warn(err) + return + } + parameters := fb_pay.GetRequestParametersByVendorSn(fbPaySet.VendorSn) + parameters.Method = "openapi.agent.account.order.share" + param := make(map[string]interface{}) + param["merchant_id"] = merchantIncomeInfo.FbMerchantId + param["pay_order_sn"] = payOid + param["merchant_order_sn"] = tmp.Oid + param["notify_level"] = "agent" + host := "http://csapi.fnuo123.com.cn" + if cfg.Prd { + host = "http://yadht.zehaochi.com.cn" + } + param["notify_url"] = fmt.Sprintf("%s/api/v1/o2oc/customer/pay/fb/order/share/callback", host) + shareDetail := []map[string]interface{}{ + { + "account_id": "", + "account_type": "2", + "share_amount": total - fee, + "remark": "商户分账", + }, + } + if fee > 0 { //TODO + var tmp1 = map[string]interface{}{ + "account_id": offical.SysCfgByKey(db.Db, "zhiying_fb_account"), + "account_type": "1", + "share_amount": fee, + "remark": "服务费", + } + shareDetail = append(shareDetail, tmp1) + } + param["share_detail"] = shareDetail + utils.FilePutContents("split_account_param:::", utils.SerializeStr(param)) + fmt.Println(param) + parameters.Nonce = utils.AnyToString(time.Now().Unix()) + parameters.SetBizContent(param) + parameters.SetSign(fbPaySet.AppSecret) + send, err := parameters.Send(cfg.Prd) + if err != nil { + utils.FilePutContents("openapiagentaccountordershare", "err:"+err.Error()) + logx.Warn(err) + return + } + resp := struct { + MerchantId int64 `json:"merchant_id"` + PayOrderSn interface{} `json:"pay_order_sn"` + MerchantPayOrderSn interface{} `json:"merchant_pay_order_sn"` + MerchantOrderSn string `json:"merchant_order_sn"` + OrderNo interface{} `json:"order_no"` + ShareDetail interface{} `json:"share_detail"` + }{} + utils.Unserialize([]byte(send), &resp) + tmp.Msg = send + if orderNoStr, ok := resp.OrderNo.(string); ok { + tmp.Oid = orderNoStr + } else if orderNoStrArry, ok := resp.OrderNo.([]string); ok && len(orderNoStrArry) > 0 { + tmp.Oid = orderNoStrArry[0] + } + tmp.Status = "SUCCESS" + eg.Where("id=?", tmp.Id).Cols("msg,status").Update(&tmp) + return +} +func yibaoShare(eg *xorm.Engine, payMethod int, total float64, payOid, uniqueOrderNo, MerchantNo string, uid int) { key := yibao_pay.CommKey(db.Db, true) zhiyingOnlineBili := utils.StrToFloat64(key["zhiyingOnlineBili"]) - utils.StrToFloat64(key["yibaoOnlineBili"]) zhiyingUnlineBili := utils.StrToFloat64(key["zhiyingUnlineBili"]) - utils.StrToFloat64(key["yibaoUnlineBili"]) @@ -131,6 +249,7 @@ func commShare(eg *xorm.Engine, payMethod int, total float64, payOid, uniqueOrde Platform: "mall", PayMethod: utils.IntToStr(payMethod), Param: utils.SerializeStr(req3), + Type: "yibao", } eg.Insert(&tmp) if fee > 0 { @@ -195,3 +314,18 @@ func commShare(eg *xorm.Engine, payMethod int, total float64, payOid, uniqueOrde eg.Where("id=?", tmp.Id).Cols("end_msg,end_status").Update(&tmp) return } +func GetFbMdSetting(engine *xorm.Engine, mid string) (*model.FbPaySet, error) { + var ( + setting model.FbPaySet + ) + get := setting.GetByRedis(mid) + if get { + return &setting, nil + } else { + err := setting.Get(engine) + if err != nil { + return nil, err + } + return &setting, nil + } +}