Created
May 1, 2019 15:09
-
-
Save jpn0424/4b9f9dd754d7ce6a0a3c96d994ecbef9 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.18; | |
contract Fbethorder { | |
event ActivityInfor(string location, string Abstract); | |
uint256 constant public ticketFee = 5 ether; // 票價 + 押金 | |
uint256 constant public deposit = 2 ether; // 壓金 | |
mapping (address => uint256) public ticketNumberMap; | |
mapping (uint256 => address) public id2AddrMap; | |
mapping (address => bool) public userJoinMap; // User Join ? true : False | |
uint256 public userAmount; | |
uint256 public ticketNumber; | |
address public FbWallet; | |
uint256 public activityEndTime; | |
bool public activityStatus; // activity start ? True : False | |
address public fborder; | |
uint256 public nowtime; | |
uint256 public maxAttendees; | |
uint256 public startTime; | |
function Fbethorder(uint256 _maxAttendees, uint256 _startTime, string _location, string _Abstract) public { | |
FbWallet = msg.sender; | |
maxAttendees = _maxAttendees; | |
userAmount = 0; | |
startTime = _startTime; | |
activityStatus = false; | |
fborder = msg.sender; | |
emit ActivityInfor( _location, _Abstract ); | |
} | |
function GetNow() public { | |
nowtime = now; | |
} | |
function () payable external { | |
GetTicket(msg.sender); | |
} | |
function GetTicket (address participant) payable public { | |
require(msg.value >= ticketFee && ticketNumberMap[participant] == 0); | |
userAmount ++; | |
ticketNumber ++; | |
require(userAmount <= maxAttendees); | |
ticketNumberMap[participant] = ticketNumber; | |
id2AddrMap[userAmount] = participant; | |
} | |
/* 發起人設定結束時間,時間使用 UTC + 8 */ | |
/* 活動開始時設定結束時間 */ | |
function ActivityEndTime(uint256 endTime) public { | |
require(FbWallet == msg.sender); | |
activityEndTime = endTime; | |
activityStatus = true; | |
} | |
/* 確任使用者, 紀錄出席者 */ | |
function UserAtt( ) public { | |
require(activityStatus == true && ticketNumberMap[msg.sender] != 0 && userJoinMap[msg.sender] == false); | |
userJoinMap[msg.sender] = true; | |
} | |
/* 課程結束,準時退回押金,延遲罰款 */ | |
function Withdraw () public { | |
require(FbWallet == msg.sender); | |
for(uint i = 1; i <= userAmount; i++){ | |
if(userJoinMap[id2AddrMap[i]] == false) continue; | |
/* 這邊時間要減去 UTC+8 */ | |
if(now <= activityEndTime + 1 minutes){ | |
id2AddrMap[i].transfer(deposit); | |
}else { | |
id2AddrMap[i].transfer(deposit + 1 ether); | |
} | |
} | |
FbWallet.transfer(this.balance); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment