|
@@ -768,14 +768,42 @@ class User extends BaseModel
|
|
|
{
|
|
{
|
|
|
if ($uid == $to_uid) return self::setErrorInfo('不可以转账给自己');
|
|
if ($uid == $to_uid) return self::setErrorInfo('不可以转账给自己');
|
|
|
$user = self::get($uid);
|
|
$user = self::get($uid);
|
|
|
|
|
+ if (!User::where('spread_uid', $uid)->where('self_achievement', '>', 0)->find()) {
|
|
|
|
|
+ return self::setErrorInfo('您需要至少推荐一名会员购买礼包商品才可进行积分转账');
|
|
|
|
|
+ }
|
|
|
$to_user = self::get($to_uid);
|
|
$to_user = self::get($to_uid);
|
|
|
if ($user['integral'] < $num) return self::setErrorInfo('积分不足');
|
|
if ($user['integral'] < $num) return self::setErrorInfo('积分不足');
|
|
|
BaseModel::beginTrans();
|
|
BaseModel::beginTrans();
|
|
|
try {
|
|
try {
|
|
|
$res1 = self::bcDec($uid, 'integral', $num, 'uid')
|
|
$res1 = self::bcDec($uid, 'integral', $num, 'uid')
|
|
|
&& UserBill::expend('积分转出', $uid, 'integral', 'trade_out', $num, 0, $user['integral'] - $num, '积分转出' . $num);
|
|
&& UserBill::expend('积分转出', $uid, 'integral', 'trade_out', $num, 0, $user['integral'] - $num, '积分转出' . $num);
|
|
|
- $res2 = self::bcInc($to_uid, 'integral', $num, 'uid')
|
|
|
|
|
- && UserBill::income('积分转入', $to_uid, 'integral', 'trade_in', $num, 0, $to_user['integral'] + $num, '积分转入' . $num);
|
|
|
|
|
|
|
+ $res2 = self::bcInc($to_uid, 'integral', bcmul($num, 0.9, 2), 'uid')
|
|
|
|
|
+ && UserBill::income('积分转入', $to_uid, 'integral', 'trade_in', bcmul($num, 0.9, 2), 0, $to_user['integral'] + (float)bcmul($num, 0.9, 2), '积分转入' . $num . ',扣除手续费后实际到账' . bcmul($num, 0.9, 2));
|
|
|
|
|
+ if ($res1 && $res2) {
|
|
|
|
|
+ BaseModel::commitTrans();
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ BaseModel::rollbackTrans();
|
|
|
|
|
+ return self::setErrorInfo('转账失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ BaseModel::rollbackTrans();
|
|
|
|
|
+ return self::setErrorInfo($e->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function tradeYue($uid, $to_uid, $num)
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($uid == $to_uid) return self::setErrorInfo('不可以转账给自己');
|
|
|
|
|
+ $user = self::get($uid);
|
|
|
|
|
+ $to_user = self::get($to_uid);
|
|
|
|
|
+ if ($user['now_money'] < $num) return self::setErrorInfo('积分不足');
|
|
|
|
|
+ BaseModel::beginTrans();
|
|
|
|
|
+ try {
|
|
|
|
|
+ $res1 = self::bcDec($uid, 'now_money', $num, 'uid')
|
|
|
|
|
+ && UserBill::expend('余额转出', $uid, 'now_money', 'trade_out_yue', $num, 0, $user['now_money'] - $num, '余额转出' . $num);
|
|
|
|
|
+ $res2 = self::bcInc($to_uid, 'now_money', $num, 'uid')
|
|
|
|
|
+ && UserBill::income('余额转入', $to_uid, 'now_money', 'trade_in_yue', $num, 0, $to_user['now_money'] + $num, '余额转入' . $num);
|
|
|
if ($res1 && $res2) {
|
|
if ($res1 && $res2) {
|
|
|
BaseModel::commitTrans();
|
|
BaseModel::commitTrans();
|
|
|
return true;
|
|
return true;
|