diff --git a/src/assets/api.js b/src/assets/api.js index 2301734f..4247f568 100644 --- a/src/assets/api.js +++ b/src/assets/api.js @@ -970,8 +970,13 @@ export const resendCardCode = (data) => { } /* 设置开发信息 */ -export const setResellMerchant = (data) => { - return req("post", baseurl + "/reseller/resellMerchant/set", data) +export const setResellMerchant = (id, data) => { + return req("put", baseurl + `/reseller/merchant/${id}`, data) +} + +/* 获取开发信息密钥 */ +export const generateRsaKey = () => { + return req("get", baseurl + "/reseller/merchant/generateRsaKey") } /* 设置分销商通知地址 */ diff --git a/src/pages/distributor/list/list.js b/src/pages/distributor/list/list.js index 7e381264..f8d55130 100644 --- a/src/pages/distributor/list/list.js +++ b/src/pages/distributor/list/list.js @@ -35,13 +35,13 @@ const Column = [ type: "normal", width: "20%" }, - // { - // title: "商户编号", - // name: "merchant", - // prop: "merchant[merchant_id]", - // type: "normal", - // width: "20%" - // }, + { + title: "商户编号", + name: "merchant", + prop: "merchant[merchant_id]", + type: "normal", + width: "20%" + }, { title: "分销商名称", prop: "name", @@ -240,7 +240,7 @@ export default class acclist extends React.Component { }, { path: "distributor-merchant", - name: "开放信息" + name: "更新商户" } ] } @@ -311,11 +311,18 @@ export default class acclist extends React.Component { } onMenuItemClick(e, key, row) { - if (key == 1) { - //重置密码 - this.setState({ pwdVisible: true, resellid: row.id }) - } else if (key == 2) { - this.setState({ logVisible: true }) + switch (Number(key)) { + case 1: + this.setState({ pwdVisible: true, resellid: row.id }) + break + case 2: + this.setState({ logVisible: true }) + break + case 3: + this.openInformation(row) + break + default: + break } } @@ -486,15 +493,6 @@ export default class acclist extends React.Component { > 编辑 - {/* { - this.openInformation(rowData) - }} - > - 开放信息 - */} - { @@ -517,6 +515,7 @@ export default class acclist extends React.Component { }} > 重置密码 + 更新商户 {/* 日志 */} diff --git a/src/pages/distributor/merchant/index.jsx b/src/pages/distributor/merchant/index.jsx index 5cfe5cdd..7a1dfc65 100644 --- a/src/pages/distributor/merchant/index.jsx +++ b/src/pages/distributor/merchant/index.jsx @@ -1,33 +1,39 @@ import FormItem from "@/components/form-item/main" import Form from "@/components/form/main" import Ipt from "@/components/input/main" -import { omit } from "lodash-es" +import { cloneDeep, omit } from "lodash-es" import { useEffect, useRef, useState } from "react" -import { Button, Card, Checkbox, CopyButton, Input, Notify, Radio, RadioGroup } from "zent" -import { setResellMerchant } from "@/assets/api" +import { Button, Card, Checkbox, Input, Notify, Radio, RadioGroup } from "zent" +import { setResellMerchant, generateRsaKey } from "@/assets/api" import "./index" export default function Merchant() { const [state, setState] = useState({ - reseller_id: "", - merchant_id: "", - marketing_notify_url: [""], - custom_rsa_public_key: "", - encrypt_type: 2, - subscribe_event: [], - loading: false + loading: false, + reseller_id: 0 /* 分销商id */, + merchant_id: "", //商户号 * + pos_id: "", //平台id 目前都是单平台 * + app_id: "", //appid。目前都是单应用, * + store_id: "", //api mode 为1时不传 为2时必传* 店铺id + public_key: "", //私钥 * + private_key: "", //公钥 * + merchant_public_key: "", //商户公钥 * + secret_key: "", //api mode 为1时不传 为2时必传* 偏移量 + notify_url: "", //事件通知地址 * + subscribe_event: [], //事件类型 数组 + status: 1, //状态 1正常 2禁用 * + api_mode: 2 //对接类型 1-RSA+标准接口返回 【默认】2-兴业银行模式 * }) const fromRef = useRef() const rules = { - merchant_id: [ - { type: "required", message: "请输入商户编号" }, - { - type: "regExp", - message: "请输入正确的商户号", - reg: /^[A-Za-z0-9]+$/ - } - ], - custom_rsa_public_key: [{ type: "required", message: "请输入商户侧RSA公钥" }], - marketing_notify_url: [ + merchant_id: [{ type: "required", message: "请输入商户编号" }], + public_key: [{ type: "required", message: "请输入公钥" }], + private_key: [{ type: "required", message: "请输入私钥" }], + app_id: [{ type: "required", message: "请输入应用ID" }], + pos_id: [{ type: "required", message: "请输入平台ID" }], + store_id: [{ type: "required", message: "请输入店铺ID" }], + secret_key: [{ type: "required", message: "请输入偏移量" }], + merchant_public_key: [{ type: "required", message: "请输入商户公钥" }], + notify_url: [ { type: "required", message: "请输入商户回调通知网关地址" }, { type: "regExp", @@ -39,36 +45,44 @@ export default function Merchant() { useEffect(() => { const { merchant, id } = JSON.parse(sessionStorage.getItem("merchant")) - setState({ ...state, reseller_id: id, ...merchant }) + const cloneState = cloneDeep(state) + for (let key in cloneState) { + cloneState[key] = merchant[key] + } + setState({ ...state, reseller_id: id, ...cloneState }) }, []) + /* 获取密钥 */ + function getKey() { + generateRsaKey().then(({ data }) => { + setState({ ...state, ...data }) + }) + } + /* 提交 */ function submit() { const valid = fromRef.current.validator() if (valid) { setState({ loading: true }) - const data = omit(state, [ - "create_time", - "id", - "status", - "update_time", - "rsa_private_key", - "rsa_public_key", - "loading" - ]) - setResellMerchant(data).then(({ code, message }) => { - if (code === 200) { + const data = omit(state, ["reseller_id", "loading"]) + setResellMerchant(state.reseller_id, data) + .then(({ code, message }) => { + if (code === 200) { + Notify.success("保存成功") + let clr = setTimeout(() => { + window.history.go(-1) + setState({ loading: false }) + clearTimeout(clr) + }, 1000) + } else { + setState({ loading: false }) + Notify.success(message) + } + }) + .catch(({ message }) => { + setState({ loading: false }) Notify.success(message) - let clr = null - clr = setTimeout(() => { - window.history.go(-1) - clearTimeout(clr) - }, 1000) - } else { - Notify.success(message) - } - setState({ loading: false }) - }) + }) } } @@ -77,7 +91,7 @@ export default function Merchant() {
- + setState({ ...state, merchant_id: value })} onClearItem={() => setState({ ...state, merchant_id: "" })} @@ -91,12 +105,112 @@ export default function Merchant() { alignment={"left"} /> - + setState({ ...state, marketing_notify_url: value })} - onClearItem={() => setState({ ...state, marketing_notify_url: "" })} + onChange={(value) => setState({ ...state, pos_id: value })} + onClearItem={() => setState({ ...state, pos_id: "" })} countShow={false} - value={state.marketing_notify_url} + value={state.pos_id} + placeholder={"请输入平台ID"} + labelWidth={"0px"} + maxLength={20} + height={"36px"} + width={"520px"} + alignment={"left"} + /> + + + setState({ ...state, app_id: value })} + onClearItem={() => setState({ ...state, app_id: "" })} + countShow={false} + value={state.app_id} + placeholder={"请输入APPID"} + labelWidth={"0px"} + maxLength={20} + height={"36px"} + width={"520px"} + alignment={"left"} + /> + + + {state.api_mode === 2 ? ( + + setState({ ...state, store_id: value })} + onClearItem={() => setState({ ...state, store_id: "" })} + countShow={false} + value={state.store_id} + placeholder={"请输入店铺ID"} + labelWidth={"0px"} + maxLength={20} + height={"36px"} + width={"520px"} + alignment={"left"} + /> + + ) : null} + {state.api_mode === 2 ? ( + + setState({ ...state, secret_key: value })} + onClearItem={() => setState({ ...state, secret_key: "" })} + countShow={false} + value={state.secret_key} + placeholder={"请输入偏移量"} + labelWidth={"0px"} + maxLength={20} + height={"36px"} + width={"520px"} + alignment={"left"} + /> + + ) : null} + + + setState({ ...state, private_key: target.value })} + value={state.private_key} + placeholder={"请输入私钥"} + labelWidth={"0px"} + width={"520px"} + alignment={"left"} + /> + + + setState({ ...state, public_key: target.value })} + value={state.public_key} + placeholder={"请输入公钥"} + labelWidth={"0px"} + width={"520px"} + alignment={"left"} + /> + + + + + + setState({ ...state, merchant_public_key: target.value })} + value={state.merchant_public_key} + placeholder={"请输入商户公钥"} + labelWidth={"0px"} + width={"520px"} + alignment={"left"} + /> + + + setState({ ...state, notify_url: value })} + onClearItem={() => setState({ ...state, notify_url: "" })} + countShow={false} + value={state.notify_url} placeholder={"请输入网关地址"} labelWidth={"0px"} height={"36px"} @@ -104,77 +218,22 @@ export default function Merchant() { alignment={"left"} /> - {state.rsa_public_key ? ( - -
- - { - Notify.clear() - Notify.success("复制成功!") - }} - > - - -
-
- ) : null} - {state.rsa_private_key ? ( - -
- - {state.rsa_private_key ? ( - { - Notify.clear() - Notify.success("复制成功!") - }} - > - - - ) : null} -
-
- ) : null} - - - setState({ ...state, custom_rsa_public_key: target.value }) - } - value={state.custom_rsa_public_key} - placeholder={"请输入商户侧RSA公钥"} - labelWidth={"0px"} - width={"520px"} - alignment={"left"} - /> - - + setState({ ...state, encrypt_type: target.value })} - value={state.encrypt_type} + onChange={({ target }) => setState({ ...state, status: target.value })} + value={state.status} > - RSA - 定制算法 + 正常 + 禁用 + + + + setState({ ...state, api_mode: target.value })} + value={state.api_mode} + > + 兴业银行模式 + RSA模式