|
|
|
@ -32,7 +32,7 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
|
|
|
|
|
public function __construct(UserAssetsDao $dao, UserAssetsShareDao $shareDao) |
|
|
|
|
{ |
|
|
|
|
$this->dao = $dao; |
|
|
|
|
$this->dao = $dao; |
|
|
|
|
$this->shareDao = $shareDao; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -62,7 +62,7 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
$item = $this->dao->get($uid); |
|
|
|
|
if ($item) { |
|
|
|
|
return $item->toArray(); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
$ret = array( |
|
|
|
|
'uid' => $uid, |
|
|
|
|
'consume' => 0.00, |
|
|
|
@ -200,13 +200,16 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
$this->update($item['uid'], array('welfare' => $assets['welfare'] + $welfare)); |
|
|
|
|
|
|
|
|
|
// 计算分红点获取积分统计 |
|
|
|
|
$shareStatistics = $this->shareDao->findOrCreate(['uid' => $item['uid']]); |
|
|
|
|
$shareStatistics = $this->shareDao->findOrCreate(['uid' => $item['uid']]); |
|
|
|
|
$shareStatistics->current = $shareStatistics->current + $welfare; |
|
|
|
|
$shareStatistics->save(); |
|
|
|
|
if($shareStatistics->current - $shareStatistics->last_point > $config['share_get_welfare_limit'] and $config['share_get_welfare_limit']){ |
|
|
|
|
$share = floor(($shareStatistics->current - $shareStatistics->last_point) / $config['share_get_welfare_limit']); |
|
|
|
|
if ($shareStatistics->current - $shareStatistics->last_point > $config['share_get_welfare_limit'] and $config['share_get_welfare_limit']) { |
|
|
|
|
$share = floor(($shareStatistics->current - $shareStatistics->last_point) / $config['share_get_welfare_limit']); |
|
|
|
|
$shareStatistics->last_point = $shareStatistics->last_point + $config['share_get_welfare_limit'] * $share; |
|
|
|
|
$shareStatistics->save(); |
|
|
|
|
if($share > $assets['share_point']){ |
|
|
|
|
$share = $assets['share_point']; |
|
|
|
|
} |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $item['uid'], |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_SHARE_POINT, |
|
|
|
@ -237,14 +240,15 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
* @author zhangkxiang |
|
|
|
|
* @editor |
|
|
|
|
*/ |
|
|
|
|
public function consumeToShare($uid, $count){ |
|
|
|
|
public function consumeToShare($uid, $count) |
|
|
|
|
{ |
|
|
|
|
$config = $this->getConfig(); |
|
|
|
|
$assets = $this->assets($uid); |
|
|
|
|
if($assets['consume'] < $config['consume_to_share'] * $count){ |
|
|
|
|
if ($assets['consume'] < $config['consume_to_share'] * $count) { |
|
|
|
|
throw new \Exception('消费积分不足'); |
|
|
|
|
} |
|
|
|
|
$logList = array(); |
|
|
|
|
$consume = -1 * $config['consume_to_share'] * $count; |
|
|
|
|
$logList = array(); |
|
|
|
|
$consume = -1 * $config['consume_to_share'] * $count; |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $uid, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_CONSUME, |
|
|
|
@ -277,17 +281,18 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
* @author zhangkxiang |
|
|
|
|
* @editor |
|
|
|
|
*/ |
|
|
|
|
public function sendHuitong($uid, $phone, $count){ |
|
|
|
|
public function sendHuitong($uid, $phone, $count) |
|
|
|
|
{ |
|
|
|
|
$assets = $this->assets($uid); |
|
|
|
|
if($assets['huitong'] < $count){ |
|
|
|
|
if ($assets['huitong'] < $count) { |
|
|
|
|
throw new \Exception('惠通宝不足'); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* @var UserRepository $userRepository |
|
|
|
|
*/ |
|
|
|
|
$userRepository = app()->make(UserRepository::class); |
|
|
|
|
$toUser = $userRepository->getUserByPhone($phone); |
|
|
|
|
if(!$toUser){ |
|
|
|
|
$toUser = $userRepository->getUserByPhone($phone); |
|
|
|
|
if (!$toUser) { |
|
|
|
|
throw new \Exception('用户不存在'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -299,8 +304,8 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG_GET, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_SUCCESS, |
|
|
|
|
'count' => $count, |
|
|
|
|
'ext' => array( |
|
|
|
|
'from_uid' => $uid, |
|
|
|
|
'ext' => array( |
|
|
|
|
'from_uid' => $uid, |
|
|
|
|
'from_phone' => $fromUser['phone'], |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
@ -310,8 +315,8 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG_SEND, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_SUCCESS, |
|
|
|
|
'count' => -1 * $count, |
|
|
|
|
'ext' => array( |
|
|
|
|
'to_uid' => $toUser['uid'], |
|
|
|
|
'ext' => array( |
|
|
|
|
'to_uid' => $toUser['uid'], |
|
|
|
|
'to_phone' => $toUser['phone'], |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
@ -322,7 +327,6 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* notes |
|
|
|
|
* @param $uid |
|
|
|
@ -335,14 +339,15 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
* @author zhangkxiang |
|
|
|
|
* @editor |
|
|
|
|
*/ |
|
|
|
|
public function huitongToConsume($uid, $count){ |
|
|
|
|
public function huitongToConsume($uid, $count) |
|
|
|
|
{ |
|
|
|
|
$current = app(HuitongRepository::class)->getCurrent(); |
|
|
|
|
$assets = $this->assets($uid); |
|
|
|
|
if($assets['huitong'] < $count){ |
|
|
|
|
$assets = $this->assets($uid); |
|
|
|
|
if ($assets['huitong'] < $count) { |
|
|
|
|
throw new \Exception('惠通宝不足'); |
|
|
|
|
} |
|
|
|
|
$logList = array(); |
|
|
|
|
$consume = $current * $count; |
|
|
|
|
$logList = array(); |
|
|
|
|
$consume = $current * $count; |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $uid, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_CONSUME, |
|
|
|
@ -350,7 +355,7 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_SUCCESS, |
|
|
|
|
'count' => $consume, |
|
|
|
|
); |
|
|
|
|
$huitong = -1 * $count; |
|
|
|
|
$huitong = -1 * $count; |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $uid, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG, |
|
|
|
@ -372,8 +377,9 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
* @author zhangkxiang |
|
|
|
|
* @editor |
|
|
|
|
*/ |
|
|
|
|
public function sign($uid, $consume){ |
|
|
|
|
$logList = array(); |
|
|
|
|
public function sign($uid, $consume) |
|
|
|
|
{ |
|
|
|
|
$logList = array(); |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $uid, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_CONSUME, |
|
|
|
@ -387,11 +393,13 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getSum($field){ |
|
|
|
|
public function getSum($field) |
|
|
|
|
{ |
|
|
|
|
return $this->dao->getSum($field); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getWhereCount($where){ |
|
|
|
|
public function getWhereCount($where) |
|
|
|
|
{ |
|
|
|
|
return $this->dao->getWhereCount($where); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|