Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
iwl-live
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Anthony.Suerte
iwl-live
Commits
f2c51c09
Commit
f2c51c09
authored
Nov 15, 2021
by
Antonio.Suerte
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Monthly Charge and Suspension Enhancement
parent
abcdb482
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
653 additions
and
2 deletions
+653
-2
MonthlyCharge.php
system/api/MonthlyCharge.php
+202
-0
SuspendAndDeduct.php
system/api/SuspendAndDeduct.php
+446
-0
db_access.php
system/lib/db_access.php
+5
-2
No files found.
system/api/MonthlyCharge.php
0 → 100644
View file @
f2c51c09
<?php
require_once
"../lib/config.php"
;
class
MonthlyCharge
extends
System
{
/**
*
* @var integer
*/
private
$forTest
;
/**
*
* @var integer
*/
private
$userAccount
;
/**
*
* @var string
*/
private
$ipAddress
;
/**
*
* @var string
*/
private
$contentType
;
/**
*
* @var string
*/
private
$requestMethod
;
/**
*
* コンストラクタ
*
*/
public
function
__construct
(){
parent
::
__construct
();
header
(
"Content-type: text/plain"
);
$this
->
setParameter
();
$this
->
validation
();
}
/**
*
* パラメータの設定
*
*/
private
function
setParameter
(){
$this
->
forTest
=
$this
->
getDataPost
(
"test"
);
$this
->
userAccount
=
$this
->
getDataPost
(
"userAccount"
);
$this
->
ipAddress
=
$this
->
getColumnData
(
$_SERVER
,
"REMOTE_ADDR"
);
$this
->
contentType
=
$this
->
getColumnData
(
$_SERVER
,
"CONTENT_TYPE"
);
$this
->
requestMethod
=
$this
->
getColumnData
(
$_SERVER
,
"REQUEST_METHOD"
);
}
/**
*
* 確認の機能
*
*/
private
function
validation
(){
$validation
=
[];
$chargeAPIConf
=
$this
->
getSettingConfiguration
(
"charge_api_conf"
);
$ipAddresses
=
explode
(
","
,
$chargeAPIConf
->
ip_address
);
if
(
strtoupper
(
$this
->
requestMethod
)
!=
"POST"
)
$validation
[]
=
"Invalid Request Method:
{
$this
->
requestMethod
}
"
;
if
(
!
in_array
(
$this
->
ipAddress
,
$ipAddresses
))
$validation
[]
=
"Invalid IP Address:
{
$this
->
ipAddress
}
"
;
if
(
$this
->
contentType
!=
"application/x-www-form-urlencoded"
)
$validation
[]
=
"Invalid Content-type:
{
$this
->
contentType
}
"
;
if
(
!
$this
->
isLoopData
(
$this
->
getAccountCommon
(
$this
->
userAccount
)))
$validation
[]
=
"Account doesn't exist:
{
$this
->
userAccount
}
"
;
if
(
$this
->
isLoopData
(
$validation
)){
header
(
"HTTP/1.1 403 Forbidden due to validation results"
);
die
(
json_encode
(
$validation
));
}
}
/**
*
* @param integer $account
* @param string $currency
* @param double $amount
*/
private
function
executeWithdraw
(
$account
,
$currency
,
$amount
){
if
(
$this
->
forTest
)
{
$simulatedAmount
=
$this
->
intToCurrency
(
$amount
,
$currency
);
echo
"Simulation: Charged For
{
$currency
}
{
$simulatedAmount
}
\n
"
;
}
else
$this
->
monthlyWithdraw
(
$account
,
$currency
,
$amount
);
}
/**
*
* @param integer $account
* @param string $currency
* @param double $amount
*/
private
function
monthlyWithdraw
(
$account
,
$currency
,
$amount
)
{
$this
->
registFeeCommon
(
$account
,
$currency
,
$this
->
intToCurrency
(
$amount
,
$currency
),
'Monthly Maintenance'
,
VAL_INT_2
);
}
/**
*
* 毎月の保守料の活用
*
*/
private
function
charge
(){
// 維持費を取得する
$fee
=
$this
->
getFeeCommon
(
VAR_MONTHLY
,
NO_COUNT
,
USD
,
$this
->
userAccount
);
// USD手数料
$feeInt
=
$this
->
currencyToInt
(
$this
->
getColumnData
(
$fee
,
USD
.
VAL_INT_1
),
USD
);
// 手数料が無い人は、飛ばす
if
(
$feeInt
==
NO_COUNT
)
return
;
// ユーザの残高を取得する
$balances
=
$this
->
getBalanceListCommon
(
$this
->
userAccount
);
if
(
$this
->
isLoopData
(
$balances
))
{
// まずは、USD優先
if
(
isset
(
$balances
[
USD
]))
{
// USD口座で賄えた場合
if
(
$feeInt
<=
$balances
[
USD
])
{
// 出金処理
$this
->
executeWithdraw
(
$this
->
userAccount
,
USD
,
$feeInt
);
return
;
}
else
{
// 出金処理
$this
->
executeWithdraw
(
$this
->
userAccount
,
USD
,
$balances
[
USD
]);
$feeInt
-=
$balances
[
USD
];
}
unset
(
$balances
[
USD
]);
}
$zeroDecimalCurrencies
=
$this
->
getZeroDecimalCurrenciesCommon
();
// Loop until maintenance costs are gone
foreach
(
$balances
as
$currency
=>
$balance
)
{
// Money exchange
$exchange
=
$this
->
getExchangeCommon
(
$balance
,
$currency
,
USD
,
true
,
false
);
if
(
in_array
(
$currency
,
$zeroDecimalCurrencies
))
$remaining
=
floor
(
$this
->
getColumnData
(
$exchange
,
PARAM_AMOUNT
)
*
100
);
else
$remaining
=
floor
(
$this
->
getColumnData
(
$exchange
,
PARAM_AMOUNT
));
// 相殺できてるか
if
(
$feeInt
<=
$remaining
)
{
$exchange
=
$this
->
getExchangeCommon
(
$feeInt
,
USD
,
$currency
,
true
,
true
);
if
(
in_array
(
$currency
,
$zeroDecimalCurrencies
))
$feeval
=
floor
(
$this
->
getColumnData
(
$exchange
,
PARAM_AMOUNT
)
/
100
);
else
$feeval
=
floor
(
$this
->
getColumnData
(
$exchange
,
PARAM_AMOUNT
));
// 出金処理
$this
->
executeWithdraw
(
$this
->
userAccount
,
$currency
,
$feeval
);
break
;
}
else
{
// 出金処理
$this
->
executeWithdraw
(
$this
->
userAccount
,
$currency
,
$balance
);
$feeInt
-=
$remaining
;
}
// 手数料が無くなったら終了
if
(
$feeInt
<=
NO_COUNT
)
break
;
}
}
}
/**
*
* 主な機能
*
*/
public
function
listen
(){
$this
->
charge
();
}
}
$charge
=
new
MonthlyCharge
();
$charge
->
listen
();
\ No newline at end of file
system/api/SuspendAndDeduct.php
0 → 100644
View file @
f2c51c09
This diff is collapsed.
Click to expand it.
system/lib/db_access.php
View file @
f2c51c09
...
@@ -211,8 +211,11 @@ class DBAccess extends Cnnector {
...
@@ -211,8 +211,11 @@ class DBAccess extends Cnnector {
throw
new
Exception
(
$this
->
getMessage
(
ERROR
,
'E_SQL_EXE_ERROR'
,
array
(
$sqlString
)),
-
1
);
throw
new
Exception
(
$this
->
getMessage
(
ERROR
,
'E_SQL_EXE_ERROR'
,
array
(
$sqlString
)),
-
1
);
}
}
$rtnArr
=
$this
->
setResultForArray
(
$result
);
if
(
!
is_bool
(
$result
)){
$this
->
afterProc
(
$result
);
$rtnArr
=
$this
->
setResultForArray
(
$result
);
$this
->
afterProc
(
$result
);
}
else
$rtnArr
=
[];
return
$rtnArr
;
return
$rtnArr
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment