# 跳蛋禮物功能 ###### tags: `php` --- ## 流程 ### 商業流程 ```sequence 後台->DB: 更新 DB-->後台: 取得開關值 後台->Redis: Publish JAVA-->Redis: Subscribe Note over 後台,JAVA: 跳蛋開關 ``` ```sequence 後台->DB: 設定禮物 DB->Redis: 寫入 Redis->API: 取得禮物列表 DB-->API: 如無快取 API-->Redis: 建立 後台->Redis: Publish JAVA-->Redis: Subscribe API->前台: 取得 Note over 後台,前台: 取得禮物列表 ``` --- ### 程式流程 #### - 跳蛋開關 ```flow st=>start: 開始 end=>end: 結束 jumpEggSwitch=>operation: 跳蛋開關(on/off) updateDB=>operation: 更新DB st->jumpEggSwitch->updateDB->end ``` #### - 取得禮物列表API ```flow st=>start: 開始 end=>end: 結束 st->end ``` --- ## 後台項目 新增跳蛋功能開關 - jump_egg_switch Redis: **key(string)** `sc:jump_egg_switch` **value** `0` or `1` (0:關閉/1:開啟) 通知使用PUB/SUB機制 **Publish Channel:** `jump_egg_info` **Message:** ```json= { "jump_egg_switch":0 } ``` 無取到開關值,預設為關閉 --- ## API項目 取得禮物列表 URL: `/api/goods` Redis: **key(hash)** `hjump_egg_gift_list:gid` gid為200001~200005 ```json= { "price": 10, "name": "昙花震动", "time": 1 } ``` 行為: 手機點一次,call一次 pc只call一次