---
# System prepended metadata

title: 序號交換

---

# 序號交換

## 異動專案
- re-api
- re-admin
    - 合作廠商序號管理
        - 新增RE序號
        - RE序號使用查看
        - 新增合作廠商序號
- open-api-portal
    - 查詢兌換紀錄
    - 帳單查詢
    
- bill
    - 兌換計費
    
- headquarter


## Table 
- re
- 
    - re.finance_rcoin_account_history_type
```sql
INSERT INTO `re`.`finance_rcoin_account_history_type` (`id`, `name`, `code`, `date_created`) 
VALUES (UUID(), '點數兌換轉出', 'point_exchange_rcoin_send_out', now());
```

- headquarter
    - headquarter_point_exchange_provider
        - headquarter_id
        - point_exchange_provider_id
        - date_created
        - date_updated
        

- point_exchange
    - provider
        - id
        - name
        - enabled_exchange_out 
        - enabled_exchange_in 
        - date_created
        - date_updated
    
        
    - exchange_type
        - id
            - 'issue-serial-number' 序號
            - 'api-realtime'
        - name
            - '序號兌換'
            - 'API 即時兌換'
            

    - provider_activity `合作廠商的活動`
        - id
        - name
        - provider_id
        - date_start
        - date_end
        - date_created
        - date_updated

    - provider_product `合作廠商的兌換商品`
        - id
        - name
        - exchange_type_id
            - 'issue-serial-number'
            - 'api-realtime'
        - direction (in / out)
            - in
            - out
        - exchange_rate
        - exchange_platform `兌換平台`
            - re
            - provider
        - is_static_exchange
        - rcoin
        - rcoin_currency_code
        - provider_points
        - date_created
        - date_updated

    - provider_activity_product `合作廠商活動下的商品`
        - id
        - provider_activity_id
        - provider_product_id
        - date_created
        - date_updated
    
    - provider_assigned_serial_number `合作廠商配發的RE序號`
        - id
        - provider_activity_id
        - provider_id
        - publish_record_id
        - date_created
        - date_updated
        
    - provider_issue_serial_number `合作廠商發行的折價券`
        - id
        - provider_activity_product_id
        - provider_activity_id
        - provider_product_id
        - provider_id
        - sno
        - amount
        - date_start
        - date_end
        - date_issued
        - is_issued
        - date_used
        - issued_re_member_id
        - is_used
        - date_created
        - date_updated

## Action
#### 取得sno兌換紀錄
- action `re-sno.getSnoRecipientHistory`
- paramSample: 
```json
{"id": "b43e3ca4-52f1-4e5c-8273-da1e91b6018b"}
```
- response: 
```json
{
    "id": "b43e3ca4-52f1-4e5c-8273-da1e91b6018b",
    "snoId": "test",
    "recipientId": "69bb28a0-4835-11e8-b039-497fe912643e",
    "recipientType": 1, //
    "isRewardDispatched": 1,
    "isLimit": 0,
    "limitationType": 0,
    "dateCreated": "2020-05-07T08:44:02.000Z",
    "reSno": {
        "id": "test",
        "code": "test123",
        "codeType": 3,
        "dateCreated": "2019-08-01T08:27:46.000Z",
        "dateUpdated": "2019-08-01T08:27:56.000Z",
        "profile": {
            "snoId": "test",
            "aliasId": "test-alias",
            "publishAmount": 1000,
            "datePublished": "2019-08-01T02:30:35.000Z",
            "publishRecordId": null,
            "dateCreated": "2019-08-01T02:30:35.000Z",
            "dateUpdated": "2019-10-18T08:10:54.000Z"
        }
    }
}
```

```javascript=
export enum ReSnoAmountLimitationType {
  EveryDay = 1,
  TimeLimitation = 2,
  NoLimitation = 3,
}

export enum ReSnoRecipientType {
  ReMember = 1,
  StoreId = 2,
  AffiliateId = 3,
}

/** 命名規則 */
export enum ReSnoCodeType {
  /** 含有日期 */
  DateTime = 1,
  /** 隨機 */
  Random = 2,
  /** 流水號碼 */
  SerialNumber = 3,
}

export enum ReSnoFrequencyLimitationType {
  EveryDay = 1,
  TimeLimitation = 2,
  NoLimitation = 3,
}

```
#### 以code取得sno
- action: getReSnoByCodeAndAlias
- paramSample
```json
{
   "code":"rPiMOJHYEs"
}
```
- responseSample
```jsonld=
{
    "id": "163ddfa8-0443-4972-9178-e098538e3c0f",
    "code": "rPiMOJHYEs",
    "codeType": 3,
    "dateCreated": "2020-03-10T06:29:53.000Z",
    "dateUpdated": "2020-03-10T06:29:53.000Z",
    "profile": {
        "snoId": "163ddfa8-0443-4972-9178-e098538e3c0f",
        "aliasId": "281e86f4-c557-4d8c-836a-65fd603c607a",
        "publishAmount": 1,
        "datePublished": "2020-03-10T06:29:53.000Z",
        "publishRecordId": null,
        "dateCreated": "2020-03-10T06:29:53.000Z",
        "dateUpdated": "2020-03-10T06:29:53.000Z",
        "alias": {
            "id": "281e86f4-c557-4d8c-836a-65fd603c607a",
            "name": "RND20200310",
            "dateCreated": "2020-03-10T06:29:53.000Z",
            "dateUpdated": "2020-03-10T06:29:53.000Z"
        }
    },
    "status": {
        "snoId": "163ddfa8-0443-4972-9178-e098538e3c0f",
        "snoLimitationId": "0cf4ce20-c3a6-48f0-8dd0-66f37654041c",
        "amount": 1,
        "enabled": true,
        "isOut": 0,
        "dateCreated": "2020-03-10T06:29:53.000Z",
        "dateUpdated": "2020-03-10T06:29:53.000Z",
        "limitation": {
            "id": "0cf4ce20-c3a6-48f0-8dd0-66f37654041c",
            "dateCreated": "2020-03-10T06:29:53.000Z",
            "dateUpdated": "2020-03-10T06:29:53.000Z",
            "frequencyLimitation": {
                "snoLimitationId": "0cf4ce20-c3a6-48f0-8dd0-66f37654041c",
                "type": 2,
                "frequency": 1,
                "dateCreated": "2020-03-10T06:29:53.000Z",
                "dateUpdated": "2020-03-10T06:29:53.000Z"
            },
            "timeLimitation": {
                "snoLimitationId": "0cf4ce20-c3a6-48f0-8dd0-66f37654041c",
                "dateStart": "2020-03-10T06:29:53.000Z",
                "dateEnd": null,
                "isAlways": true,
                "dateCreated": "2020-03-10T06:29:53.000Z",
                "dateUpdated": "2020-03-10T06:29:53.000Z"
            },
            "amountLimitation": {
                "snoLimitationId": "0cf4ce20-c3a6-48f0-8dd0-66f37654041c",
                "type": 3,
                "amount": 1,
                "dateCreated": "2020-03-10T06:29:53.000Z",
                "dateUpdated": "2020-03-10T06:29:53.000Z"
            }
        }
    },
    "rewards": [
        {
            "id": "d603318b-241d-4f42-8b00-8e036e08aadf",
            "type": 1,
            "rcoin": 5,
            "currency": "TWD",
            "dateCreated": "2020-03-10T06:29:52.000Z",
            "dateUpdated": "2020-03-10T06:29:52.000Z"
        }
    ]
}

```


#### 以code取得sno
- action: checkCodeAvailable
- paramSample
```
{
   "code":"rPiMOJHYEs"
}
```
- response
```json
{
    "isExist": true, // code 是否存在
    "isAmountEnough": true, // 數量是否足夠
    "isDateAvailable": true, // 時間是否通過驗證
    "reSno": {{同getReSno Response}}
}
```

#### 批次建立sno
- action `re-sno.publishMultipleReSno`
- paramSample
```json
{
    "codeList": [],
    "codeAmount": 2,
    "totalPublishAmount": 10,
    "publishAmount": 1,
    "datePublish": "2020-05-07 17:12:00",
    "isAutoGenerate": true, //是否自動產生
    "codeType": 1,
    "alias": {
        "name": "0507測試多組",
        "languages": []
    },
    "timeLimit": {
        "dateStart": "2020-05-27 10:42:00",
        "dateEnd": null,
        "isAlways": true
    },
    "frequencyLimit": {
        "type": 2,
        "frequency": 1
    },
    "amountLimit": {
        "type": 2,
        "amount": 1
    },
    "reward": {
        "type": 1,
        "currency": "TWD",
        "rcoin": 100
    }
}
```
- response
```json
{
    "codes": [
        "NEgoxL03fH",
        "r5rB9tMdHA"
    ],
    "publishRecordId": "242453f6-c77f-426d-8585-cd3d7dc28cf0"
}
```



#### 批次建立sno
- action `re-sno.getSnoListByParameter`
- paramSample
```json
{
    "publishRecordId": "test-alias",
    "page":{
        "index":1,
        "size":100
    }
}
```
- response
```json
{
    "items": [
        {
            "id": "test",
            "code": "test123",
            "codeType": 3,
            "dateCreated": "2019-08-01T08:27:46.000Z",
            "dateUpdated": "2019-08-01T08:27:56.000Z",
            "profile": {
                "snoId": "test",
                "aliasId": "test-alias",
                "publishAmount": 1000,
                "datePublished": "2019-08-01T02:30:35.000Z",
                "publishRecordId": "test-alias",
                "dateCreated": "2019-08-01T02:30:35.000Z",
                "dateUpdated": "2020-05-11T08:55:17.000Z"
            },
            "status": {
                "snoId": "test",
                "snoLimitationId": "test-limit",
                "amount": 913,
                "enabled": true,
                "isOut": 0,
                "dateCreated": "2019-08-01T02:30:56.000Z",
                "dateUpdated": "2020-05-07T08:44:02.000Z"
            },
            "snoRecipientHistory": { // 若未領取則為 null
                "id": "0103b0af-bc2e-4dc4-881b-d45d341f3e1e",
                "snoId": "test",
                "recipientId": "6dcf8d40-4fd0-11e7-8b7e-f1929b90c782",
                "recipientType": 1,
                "isRewardDispatched": true,
                "isLimit": false,
                "limitationType": 0,
                "dateCreated": "2019-10-21T04:56:52.000Z"
            }
        }
    ],
    "page": {
        "pagesAmount": 1,
        "dataAmount": 1
    }
}
```


        
## Event
#### 已經建立sno兌換紀錄
- eventString `reSno.snoRecipientHistoryCreated`
- payload
```json
   {"snoRecipientHistoryId":""}
```



## Vars

```sql
INSERT INTO `re`.`vars` (`id`, `name`, `description`, `key`, `meta_str_1`, `meta_str_2`, `meta_str_long`, `meta_int_1`, `meta_int_2`, `meta_float_1`, `meta_float_2`, `meta_boolean_1`, `meta_boolean_2`, `meta_date_1`, `meta_date_2`, `type`) VALUES (NULL, 'TW 是否要出現點數兌換功能', 'meta_boolean_1 = 是否出現在 RE APP 中', 're-cms-display-point-exchange-tw', '', '', ' ', '0', '0', '0', '0', '1', '0', '2020-06-01 15:40:00', '2020-06-01 15:40:00', 're');

INSERT INTO `re`.`vars` (`name`, `description`, `key`, `meta_str_1`, `meta_str_2`, `meta_str_long`, `meta_int_1`, `meta_int_2`, `meta_float_1`, `meta_float_2`, `meta_boolean_1`, `meta_boolean_2`, `meta_date_1`, `meta_date_2`, `type`) VALUES ('MY 是否要出現點數兌換功能', 'meta_boolean_1 = 是否出現在 RE APP 中', 're-cms-display-point-exchange-my', '', '', ' ', '0', '0', '0', '0', '0', '0', '2020-06-01 15:40:00', '2020-06-01 15:40:00', 're');


```

# 新增 provider 的順序

```sql

ALTER TABLE `point_exchange`.`provider` 
ADD COLUMN `sort` INT NOT NULL DEFAULT 0 AFTER `enabled_exchange_in`;

```