|
|
|
@ -84,19 +84,19 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
$assets = $this->assets($uid); |
|
|
|
|
$update = array('integral_buy' => 0, 'integral_withdraw' => 0, 'diamond' => 0, 'stock' => 0); |
|
|
|
|
if (isset($data['integral']) and $data['integral']) { |
|
|
|
|
$tmp = $this->getIntegral($data['integral']); |
|
|
|
|
$update['integral_buy'] = $tmp['integral_buy']; |
|
|
|
|
$tmp = $this->getIntegral($data['integral']); |
|
|
|
|
$update['integral_buy'] = $tmp['integral_buy']; |
|
|
|
|
$update['integral_withdraw'] = $tmp['integral_withdraw']; |
|
|
|
|
} |
|
|
|
|
if(isset($data['diamond']) and $data['diamond']){ |
|
|
|
|
if (isset($data['diamond']) and $data['diamond']) { |
|
|
|
|
$update['diamond'] = $data['diamond']; |
|
|
|
|
} |
|
|
|
|
if(isset($data['stock']) and $data['stock']){ |
|
|
|
|
if (isset($data['stock']) and $data['stock']) { |
|
|
|
|
$update['stock'] = $data['stock']; |
|
|
|
|
} |
|
|
|
|
$updateData = array(); |
|
|
|
|
foreach ($update as $key => $value){ |
|
|
|
|
if($value){ |
|
|
|
|
foreach ($update as $key => $value) { |
|
|
|
|
if ($value) { |
|
|
|
|
$updateData[$key] = $add ? $assets[$key] + $value : $assets[$key] - $value; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -126,29 +126,30 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
*/ |
|
|
|
|
public function integralToDiamond($uid, $count) |
|
|
|
|
{ |
|
|
|
|
$config = $this->getConfig(); |
|
|
|
|
$assets = $this->assets($uid); |
|
|
|
|
if ($assets['consume'] < $config['integralToDiamond'] * $count) { |
|
|
|
|
throw new \Exception('消费积分不足'); |
|
|
|
|
$integralField = "integral_withdraw"; |
|
|
|
|
$config = $this->getConfig(); |
|
|
|
|
$assets = $this->assets($uid); |
|
|
|
|
if ($assets[$integralField] < $config['integralToDiamond'] * $count) { |
|
|
|
|
throw new \Exception('积分不足'); |
|
|
|
|
} |
|
|
|
|
$logList = array(); |
|
|
|
|
$consume = -1 * $config['consume_to_share'] * $count; |
|
|
|
|
$logList[] = array( |
|
|
|
|
$logList = array(); |
|
|
|
|
$integralCount = -1 * $config['integralToDiamond'] * $count; |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $uid, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_CONSUME, |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_SHARE_EXCHANGE, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_SUCCESS, |
|
|
|
|
'count' => $consume, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_INTEGRAL, |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_DIAMOND, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_USE, |
|
|
|
|
'count' => $integralCount, |
|
|
|
|
); |
|
|
|
|
$logList[] = array( |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $uid, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_SHARE_POINT, |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_SHARE_EXCHANGE, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_SUCCESS, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_DIAMOND, |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_DIAMOND, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_GET, |
|
|
|
|
'count' => $count, |
|
|
|
|
); |
|
|
|
|
app()->make(UserAssetsLogRepository::class)->addLog($logList); |
|
|
|
|
$this->dao->update($uid, array('consume' => $assets['consume'] + $consume, 'share_point' => $assets['share_point'] + $count, 'share_point_time' => time())); |
|
|
|
|
$this->dao->update($uid, array($integralField => $assets[$integralField] + $integralCount, 'diamond' => $assets['diamond'] + $count)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -166,7 +167,7 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
public function diamondToStock($uid, $count) |
|
|
|
|
{ |
|
|
|
|
$config = $this->getConfig(); |
|
|
|
|
$assets = $this->assets($uid); |
|
|
|
|
$assets = $this->assets($uid); |
|
|
|
|
if ($assets['diamond'] < $config['diamondToStock'] * $count) { |
|
|
|
|
throw new \Exception('钻石不足'); |
|
|
|
|
} |
|
|
|
@ -179,7 +180,7 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_USE, |
|
|
|
|
'count' => $diamond, |
|
|
|
|
); |
|
|
|
|
$stock = $count; |
|
|
|
|
$stock = $count; |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $uid, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_STOCK, |
|
|
|
@ -205,11 +206,13 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
* @author zhangkxiang |
|
|
|
|
* @editor |
|
|
|
|
*/ |
|
|
|
|
public function sendHuitong($uid, $phone, $count) |
|
|
|
|
public function sendIntegral($uid, $phone, $count) |
|
|
|
|
{ |
|
|
|
|
$assets = $this->assets($uid); |
|
|
|
|
if ($assets['huitong'] < $count) { |
|
|
|
|
throw new \Exception('惠通宝不足'); |
|
|
|
|
$integralField = "integral_withdraw"; |
|
|
|
|
$config = $this->getConfig(); |
|
|
|
|
$assets = $this->assets($uid); |
|
|
|
|
if ($assets[$integralField] < $count) { |
|
|
|
|
throw new \Exception('积分不足'); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* @var UserRepository $userRepository |
|
|
|
@ -220,14 +223,17 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
throw new \Exception('用户不存在'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$rate = round($config['transferRate'] * $count / 100, 2); |
|
|
|
|
|
|
|
|
|
$fromUser = $userRepository->get($uid); |
|
|
|
|
|
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $toUser['uid'], |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG, |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG_GET, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_SUCCESS, |
|
|
|
|
'count' => $count, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_INTEGRAL, |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_INTEGRAL_GET, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_GET, |
|
|
|
|
'count' => $count - $rate, |
|
|
|
|
'fee' => 0, |
|
|
|
|
'ext' => array( |
|
|
|
|
'from_uid' => $uid, |
|
|
|
|
'from_phone' => $fromUser['phone'], |
|
|
|
@ -235,23 +241,85 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
); |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $uid, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG, |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG_SEND, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_SUCCESS, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_INTEGRAL, |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_INTEGRAL_SEND, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_USE, |
|
|
|
|
'count' => -1 * $count, |
|
|
|
|
'fee' => $rate, |
|
|
|
|
'ext' => array( |
|
|
|
|
'to_uid' => $toUser['uid'], |
|
|
|
|
'to_phone' => $toUser['phone'], |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
app()->make(UserAssetsLogRepository::class)->addLog($logList); |
|
|
|
|
$this->dao->update($uid, array('huitong' => $assets['huitong'] - $count)); |
|
|
|
|
$this->dao->update($uid, array($integralField => $assets[$integralField] - $count)); |
|
|
|
|
$toAssets = $this->assets($toUser['uid']); |
|
|
|
|
$this->dao->update($toUser['uid'], array('huitong' => $toAssets['huitong'] + $count)); |
|
|
|
|
$this->dao->update($toUser['uid'], array($integralField => $toAssets[$integralField] + $count - $rate)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* notes 惠通宝转账 |
|
|
|
|
* @param $uid |
|
|
|
|
* @param $phone |
|
|
|
|
* @param $count |
|
|
|
|
* @throws DataNotFoundException |
|
|
|
|
* @throws DbException |
|
|
|
|
* @throws ModelNotFoundException |
|
|
|
|
* @create 2024/3/20 11:01 |
|
|
|
|
* @update 2024/3/20 11:01 |
|
|
|
|
* @author zhangkxiang |
|
|
|
|
* @editor |
|
|
|
|
*/ |
|
|
|
|
public function sendDiamond($uid, $phone, $count) |
|
|
|
|
{ |
|
|
|
|
$config = $this->getConfig(); |
|
|
|
|
$assets = $this->assets($uid); |
|
|
|
|
if ($assets['diamond'] < $count) { |
|
|
|
|
throw new \Exception('积分不足'); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* @var UserRepository $userRepository |
|
|
|
|
*/ |
|
|
|
|
$userRepository = app()->make(UserRepository::class); |
|
|
|
|
$toUser = $userRepository->getUserByPhone($phone); |
|
|
|
|
if (!$toUser) { |
|
|
|
|
throw new \Exception('用户不存在'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$rate = round($config['transferRate'] * $count / 100, 2); |
|
|
|
|
|
|
|
|
|
$fromUser = $userRepository->get($uid); |
|
|
|
|
|
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $toUser['uid'], |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_DIAMOND, |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_DIAMOND_GET, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_GET, |
|
|
|
|
'count' => $count - $rate, |
|
|
|
|
'fee' => 0, |
|
|
|
|
'ext' => array( |
|
|
|
|
'from_uid' => $uid, |
|
|
|
|
'from_phone' => $fromUser['phone'], |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $uid, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_DIAMOND, |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_DIAMOND_SEND, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_USE, |
|
|
|
|
'count' => -1 * $count, |
|
|
|
|
'fee' => $rate, |
|
|
|
|
'ext' => array( |
|
|
|
|
'to_uid' => $toUser['uid'], |
|
|
|
|
'to_phone' => $toUser['phone'], |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
app()->make(UserAssetsLogRepository::class)->addLog($logList); |
|
|
|
|
$this->dao->update($uid, array('diamond' => $assets['diamond'] - $count)); |
|
|
|
|
$toAssets = $this->assets($toUser['uid']); |
|
|
|
|
$this->dao->update($toUser['uid'], array('diamond' => $toAssets['diamond'] + $count - $rate)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getSum($field) |
|
|
|
|