Cash.php
4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* 提现相关
* @author tongdesheng
*
*/
class YHMApi_App_V1_Cash extends YHMApi_App_V1_Base
{
/**
* 提现明细
* @param array $params
* @param string $fields
*/
public static function detail(array $params, $fields = '*')
{
$uid = $params['uid'];
$retData = self::getWithdrawData($uid);
return self::result(200, '现金账户明细', $retData);
}
/**
* 绑定支付宝
* @param array $params
* @param string $fields
* @return array
*/
public static function bindAlipay(array $params, $fields = '*')
{
if (empty($params['uid'])) {
return self::result(400, 'uid不能为空');
}
if (empty($params['open_id'])) {
return self::result(400, '绑定账号不能为空');
}
if (empty($params['open_token'])) {
return self::result(400, 'open_token不能为空');
}
$uid = $params['uid'];
$openID = $params['open_id'];
$accountName = empty($params['alipay_name']) ? '' : $params['alipay_name'];
$account = '';
YHMPassport_Models_ShroffAccount_Client::setUserShroffAccount($uid, $openID, $account, $accountName, YHMConfig_Passport::SHROFF_ACCOUNT_ALIPAY);
return self::result(200, "绑定成功");
}
static public function checkBindingAlipay(array $params, $fields = '*')
{
if (empty($params['uid'])) {
return self::result(400, 'uid不能为空');
}
$accountData = YHMPassport_Models_ShroffAccount_Client::getAccountByUid($params['uid'], YHMConfig_Passport::SHROFF_ACCOUNT_ALIPAY);
if (empty($accountData)) {
return self::result(400, '没有绑定');
}
return self::result(200, '绑定信息', $accountData);
}
/**
* 获取提现数据
* @param integer $uid
* @return multitype:Integer String mixed string
*/
private static function getWithdrawData($uid)
{
$accountData = YHMPassport_Models_ShroffAccount_Client::getAccountByUid($uid, YHMConfig_Passport::SHROFF_ACCOUNT_ALIPAY);
//已提现金额
$withdrewAmount = YHMPassport_Models_Withdraw_Client::getWithdrewByUid($uid);
//获取可提现金额(包含已经提现的超过退换货期的)
$canWithdrawAmount = YHMOrders_Models_Orders_Client::getCanWithdrawBySelleruid($uid, 8);
//冻结金额(未达到退换货期的)
$freezeAmount = YHMOrders_Models_Orders_Client::getFreezeBySelleruid($uid);
//获取退款金额
$refundAmount = YHMOrders_Models_Refund_Client::getRefundAmountByRefunduid($uid);
$isBindAlipay = 'Y';
$bind = YHMPassport_Models_ShroffAccount_Client::getAccountByUid($uid, YHMConfig_Passport::SHROFF_ACCOUNT_ALIPAY);
if (empty($bind)) {
$isBindAlipay = 'N';
}
$str="";
if ( $accountData['account'])
{
$arr= explode('@', $accountData['account']);
$len=strlen($arr[0]);
$str= substr($arr[0], 0,1)."***".substr($arr[0], $len-2,1).'@'.$arr[1];
}
$amount=$freezeAmount - $refundAmount-$canWithdrawAmount;
return array(
'is_bind_alipay' => $isBindAlipay, //是否绑定了支付宝
'alipay_account' => $str, //支付宝账户
'can_withdraw_amount' => $amount - $withdrewAmount , //可提现金额
'not_withdraw_amount' => $amount - $withdrewAmount, //未提现金额
'freeze_amount' => ($canWithdrawAmount)?$canWithdrawAmount:0, //冻结金额
'total_amount' => $amount, //累计收入
);
}
/**
*
* @param array $params
* @param string $fields
*/
public static function withdraw(array $params, $fields = '*')
{
$uid = $params['uid'];
$withdraw_amount = $params['withdraw_amount'];
$ret = YHMPassport_Models_Withdraw_Client::setWithdraw($uid, $withdraw_amount);
if (empty($ret)) {
return self::result(412, '添加提现失败');
}
$retData = self::getWithdrawData($uid);
return self::result(200, '提现成功', $retData);
}
}