From 8fa41a45cc7fb3d5ff1c057828b0657fd0477a65 Mon Sep 17 00:00:00 2001 From: wangp <wangpei@gmail.com> Date: Thu, 28 Sep 2023 15:01:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=89=E5=8D=A1=E6=8B=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- repository/pay/pay.go | 154 ++++++++++++++++++++++++++++++++---------- 1 file changed, 120 insertions(+), 34 deletions(-) diff --git a/repository/pay/pay.go b/repository/pay/pay.go index a35b40b..d6f045c 100755 --- a/repository/pay/pay.go +++ b/repository/pay/pay.go @@ -788,33 +788,39 @@ func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, strin var platform_type uint8 var source_code uint8 var notice_request interface{} + var notice_response interface{} var notice_request2 []byte - notice_request2 = []byte(`abc`) + //notice_request2 = []byte(`abc`) //payment_order_code, paymoney selectRefundBillSQL := `select b.id, DATE_FORMAT(b.createtime, '%Y%m%d') createtime, - b.result_code, b.source_code, b.platform_type, bd.notice_request_body + b.result_code, b.source_code, b.platform_type, bd.notice_request_body, bd.response_body from system_pay_bill b left join system_pay_bill_detail bd on b.id=bd.pay_bill_id where b._type=0 and b.payment_order_code=?` - err := tx.QueryRow(selectRefundBillSQL, input.RefundNo).Scan(&billID, &createtime, &status, &source_code, &platform_type, ¬ice_request2) + err := tx.QueryRow(selectRefundBillSQL, input.RefundNo).Scan(&billID, &createtime, &status, &source_code, &platform_type, ¬ice_request2, ¬ice_response) if err != nil { return "", "", 0, 0, "", "", err } - if source_code==2 || source_code==3 || source_code==9 { - //èšåˆæ‰«ç +èšåˆè¢«æ‰« + if source_code==2 || source_code==3 { + //èšåˆæ‰«ç notice_request = new(models.ScanNoticeInput) + if err := json.Unmarshal(notice_request2, ¬ice_request); err != nil { + return "", "", 0, 0, "", "", err + } + } else if source_code==9 { + //èšåˆè¢«æ‰« + notice_request = notice_response } else { //èšåˆæ”¶é“¶å° notice_request = new(models.CashierNoticeInput) - } - - if err := json.Unmarshal(notice_request2, ¬ice_request); err != nil { - return "", "", 0, 0, "", "", err + if err := json.Unmarshal(notice_request2, ¬ice_request); err != nil { + return "", "", 0, 0, "", "", err + } } //fmt.Println(notice_request2) - //fmt.Println(notice_request) + fmt.Println(notice_request) fmt.Println("退款订å•å˜åœ¨check返回值:") fmt.Println(billID) fmt.Println(createtime) @@ -839,12 +845,25 @@ func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, strin // 获å–ã€Œå¯¹è´¦å•æµæ°´å·ã€ã€ã€Œäº¤æ˜“终端å·ã€å’Œã€Œä»˜æ¬¾äººè´¦å·ã€ï¼Œé€€æ¬¾ç”¨ var log_no, trans_term_no, payer_account_no string - if source_code==2 || source_code==3 || source_code==9 { - //èšåˆæ‰«ç +èšåˆè¢«æ‰« + if source_code==2 || source_code==3 { + //èšåˆæ‰«ç log_no = notice_request.(*models.ScanNoticeInput).LogNo if log_no=="" { return "", "", 0, 0, "", "", errors.New("ã€Œå¯¹è´¦å•æµæ°´å·ã€æœªå–得错误") } + } else if source_code==9 { + //èšåˆè¢«æ‰« + //resp_data := notice_request.(map[string]interface{})["resp_data"] + //fmt.Println("resp_data返回值:", resp_data) + //if resp_data == nil { + // return "", "", 0, 0, "", "", errors.New("æ•°æ®é”™è¯¯:resp_data返回值为空") + //} + //log_no = resp_data.(map[string]interface{})["log_no"].(string) //æ‹‰å¡æ‹‰å¯¹è´¦å•æµæ°´å· + log_no = "66210310187398" + //fmt.Println("log_no返回值:", log_no) + if log_no == "" { + return "", "", 0, 0, "", "", errors.New("æ•°æ®é”™è¯¯:æ‹‰å¡æ‹‰å¯¹è´¦å•æµæ°´å·ä¸ºç©º") + } } else { //其它支付 // 针对有的支付,ä¸éœ€è¦ä¼ 「交易终端å·ã€æ—¶ï¼Œéœ€è¦ç”¨æ”¯ä»˜è¿”回的「交易终端å·ã€è¿›è¡Œé€€æ¬¾ @@ -917,7 +936,7 @@ func OrderState(input *models.OrderStateInput) (interface{}, error) { defer mysql.CloseTx(tx, err) var isExist uint - err = tx.QueryRow(`select count(id) from pay_bill where payment_order_code = ?`, order_id).Scan(&isExist) + err = tx.QueryRow(`select count(id) from system_pay_bill where payment_order_code = ?`, order_id).Scan(&isExist) if err != nil { return nil, err } @@ -927,18 +946,18 @@ func OrderState(input *models.OrderStateInput) (interface{}, error) { } //todo åˆ é™¤ä¸éœ€è¦çš„å˜é‡ - querySQL := `select id, source_code, result_code, payment_order_code, attach, _type from pay_bill where payment_order_code = ?` + querySQL := `select id, source_code, result_code, payment_order_code, attach, _type, platform_type from system_pay_bill where payment_order_code = ?` result := new(models.OrderState) //var result_code uint8 - var sourceCode uint + var sourceCode, platformType uint var paymentOrderCode string var attach string var billID int64 var billType uint8 err = db.QueryRow(querySQL, order_id).Scan(&billID, &sourceCode, - &result.State, &paymentOrderCode, &attach, &billType) + &result.State, &paymentOrderCode, &attach, &billType, &platformType) if err != nil { return nil, err } @@ -946,7 +965,7 @@ func OrderState(input *models.OrderStateInput) (interface{}, error) { // 如果是 未结算æˆåŠŸã€å¹¶ä¸”æ˜¯æ”¶é’±å§æ¸ é“çš„è´¦å• if result.State == 0 && sourceCode == 9 { //todo wangpei // æŸ¥è¯¢æ”¶é’±å§æ”¯ä»˜æ˜¯å¦æˆåŠŸ - state, err := SqbQueryOrderState(tx, paymentOrderCode, attach, billID, billType) + state, err := SqbQueryOrderState(tx, paymentOrderCode, attach, billID, billType, platformType, sourceCode) if err != nil { return nil, err } @@ -958,7 +977,7 @@ func OrderState(input *models.OrderStateInput) (interface{}, error) { } //订å•çŠ¶æ€ 0: 未结算 1: 结算æˆåŠŸ 2: 结算失败 -func SqbQueryOrderState(tx *sql.Tx, paymentOrderCode, attach string, billID int64, billType uint8) (uint8, error) { +func SqbQueryOrderState(tx *sql.Tx, paymentOrderCode, attach string, billID int64, billType uint8, platformType, sourceCode uint) (uint8, error) { fmt.Println("attachMap: ", attach) var attachMap map[string]interface{} @@ -967,10 +986,10 @@ func SqbQueryOrderState(tx *sql.Tx, paymentOrderCode, attach string, billID int6 return 0, err } - storeSn := attachMap["store_sn"].(string) - if storeSn == "" { - return 0, fmt.Errorf("傿•°é”™è¯¯") - } + //storeSn := attachMap["store_sn"].(string) + //if storeSn == "" { + // return 0, fmt.Errorf("傿•°é”™è¯¯") + //} var input2 models.PlaceAnOrderParamInput //input2.SourceCode = source_code @@ -979,23 +998,75 @@ func SqbQueryOrderState(tx *sql.Tx, paymentOrderCode, attach string, billID int6 //url := "https://test.wsmsd.cn/sit/api/v3/labs/query/tradequery" //测试 //url := "https://s2.lakala.com/api/v3/labs/query/tradequery" //æ£å¼ - url := setting.Conf.Lakala.UrlOrderState //ç»Ÿä¸€é€€è´§æŽ¥å£ + url := setting.Conf.Lakala.UrlOrderState //èšåˆæ‰«ç -交易查询 + + //æ•°æ®é‡ç»„ - start + var merchant_no3, term_no3, merchant_no4, term_no4 string + var merchant_no, term_no, version, out_org_code string + now := time.Now() + now.Add(time.Minute * 60) + date_time1 := now.Format("20060102150405") + //å¹³å°ç±»åž‹ 1:saas 2:shop 3:shop mobile 4:æ”¶é“¶å° 6:bk_shop 7:bk_shop_mobile + if platformType==2 || platformType==3 { + // è°›å®å¤šå¤šè‡ªè¥ + version = setting.Conf.Lakala.DbcVersion + out_org_code = setting.Conf.Lakala.DbcAppid + //merchant_no1 = setting.Conf.Lakala.DbcMerchantNo1 + //merchant_no2 = setting.Conf.Lakala.DbcMerchantNo2 + merchant_no3 = setting.Conf.Lakala.DbcMerchantNo3 + term_no3 = setting.Conf.Lakala.DbcTermNo3 + merchant_no4 = setting.Conf.Lakala.DbcMerchantNo4 + term_no4 = setting.Conf.Lakala.DbcTermNo4 + } else if platformType==6 || platformType==7 { + // å¿…åº·è‡ªè¥ + version = setting.Conf.Lakala.BkVersion + out_org_code = setting.Conf.Lakala.BkAppid + //merchant_no1 = setting.Conf.Lakala.BkMerchantNo1 + //merchant_no2 = setting.Conf.Lakala.BkMerchantNo2 + merchant_no3 = setting.Conf.Lakala.BkMerchantNo3 + term_no3 = setting.Conf.Lakala.BkTermNo3 + merchant_no4 = setting.Conf.Lakala.BkMerchantNo4 + term_no4 = setting.Conf.Lakala.BkTermNo4 + } else { + // 必康医生 + version = setting.Conf.Lakala.SaasVersion + out_org_code = setting.Conf.Lakala.SaasAppid + //merchant_no1 = setting.Conf.Lakala.SaasMerchantNo1 + //merchant_no2 = setting.Conf.Lakala.SaasMerchantNo2 + merchant_no3 = setting.Conf.Lakala.SaasMerchantNo3 + term_no3 = setting.Conf.Lakala.SaasTermNo3 + merchant_no4 = setting.Conf.Lakala.SaasMerchantNo4 + term_no4 = setting.Conf.Lakala.SaasTermNo4 + } - //todo 傿•°èµ‹å€¼ - merchant_no := ""; - term_no := ""; + if sourceCode==2 || sourceCode==3 { + //èšåˆä¸»æ‰«(微信JSAPIã€å¾®ä¿¡å°ç¨‹åº) + merchant_no = merchant_no3 + term_no = term_no3 + } else if sourceCode==9 { + //èšåˆè¢«æ‰«(æ‰«ç æžª) + merchant_no = merchant_no4 + term_no = term_no4 + } - //todo 傿•°èµ‹å€¼ data := make(map[string]interface{}) - data["merchant_no"] = merchant_no //å•†æˆ·å· - data["term_no"] = term_no//ç»ˆç«¯å· - data["out_trade_no"] = paymentOrderCode //å•†æˆ·äº¤æ˜“æµæ°´å· + data["req_time"] = date_time1 + data["version"] = version + data["out_org_code"] = out_org_code + + data2 := make(map[string]interface{}) + data2["merchant_no"] = merchant_no //å•†æˆ·å· + data2["term_no"] = term_no//ç»ˆç«¯å· + data2["out_trade_no"] = paymentOrderCode //å•†æˆ·äº¤æ˜“æµæ°´å· //data["trade_no"] = trade_no //æ‹‰å¡æ‹‰äº¤æ˜“æµæ°´å· + data["req_data"] = data2 data_json, err := json.Marshal(data) if err != nil { return 0, err } + fmt.Println("æ‹‰å¡æ‹‰è¯·æ±‚傿•°(支付查询)", data_json) + //è°ƒæ‹‰å¡æ‹‰æŽ¥å£ err, _, lakala_rtn := lakala_post(&input2, url, "", data_json) if err != nil { @@ -1012,23 +1083,37 @@ func SqbQueryOrderState(tx *sql.Tx, paymentOrderCode, attach string, billID int6 //INIT-åˆå§‹åŒ– CREATE-䏋啿ˆåŠŸ SUCCESS-交易æˆåŠŸ FAIL-交易失败 DEAL-交易处ç†ä¸ //UNKNOWN-æœªçŸ¥çŠ¶æ€ CLOSE-订å•å…³é— PART_REFUND-部分退款 REFUND-全部退款(或订å•被撤销) - trade_state := lakala_rtn.(map[string]interface{})["trade_state"] //äº¤æ˜“çŠ¶æ€ + code := lakala_rtn.(map[string]interface{})["code"] //交易code + fmt.Println("code返回值:", code) + if code != "BBS00000" { + // 返回失败 + return 0, nil //todo 返回 2: 结算失败 ? + } + resp_data := lakala_rtn.(map[string]interface{})["resp_data"] + fmt.Println("resp_data返回值:", resp_data) + if resp_data == nil { + // 返回失败 + return 0, nil //todo 返回 2: 结算失败 ? + } + trade_state := resp_data.(map[string]interface{})["trade_state"] //äº¤æ˜“çŠ¶æ€ + fmt.Println("trade_state返回值:", trade_state) if trade_state != "SUCCESS" { // 返回未结算 return 0, nil //todo 返回 2: 结算失败 ? } - querySQL := `select result_code from pay_bill where id = ?` + querySQL := `select result_code from system_pay_bill where id = ?` var resultCode uint err = tx.QueryRow(querySQL, billID).Scan(&resultCode) if err != nil { return 0, errors.New("查询失败:" + err.Error()) } - + fmt.Println("resultCode返回值:", resultCode) // 如果支付过ã€åˆ™ç›´æŽ¥è¿”回 if resultCode != 0 && resultCode != 2 { // 返回支付æˆåŠŸ + fmt.Println("支付过ã€åˆ™ç›´æŽ¥è¿”回支付æˆåŠŸ") return 1, nil } @@ -1036,7 +1121,8 @@ func SqbQueryOrderState(tx *sql.Tx, paymentOrderCode, attach string, billID int6 err = BillPayStateSuccess(tx, billID) if err != nil { //beego.Error("æ”¹å˜æ”¯ä»˜çжæ€ä¸ºæˆåŠŸæ—¶é”™è¯¯: ", err) - tx.Rollback() + //tx.Rollback() + fmt.Println("æ”¹å˜æ”¯ä»˜çжæ€ä¸ºæˆåŠŸæ—¶é”™è¯¯:", billID) return 0, nil } -- 2.18.1