|
|
|
@ -198,4 +198,79 @@ class UserAssetsRepository extends BaseRepository |
|
|
|
|
$logRepository->addLog($logList); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* notes |
|
|
|
|
* @param $uid |
|
|
|
|
* @param $count |
|
|
|
|
* @throws DataNotFoundException |
|
|
|
|
* @throws DbException |
|
|
|
|
* @throws ModelNotFoundException |
|
|
|
|
* @create 2024/3/19 22:33 |
|
|
|
|
* @update 2024/3/19 22:33 |
|
|
|
|
* @author zhangkxiang |
|
|
|
|
* @editor |
|
|
|
|
*/ |
|
|
|
|
public function consumeToShare($uid, $count){ |
|
|
|
|
$config = $this->getConfig(); |
|
|
|
|
$assets = $this->assets($uid); |
|
|
|
|
if($assets['consume'] < $config['consume_to_share'] * $count){ |
|
|
|
|
throw new \Exception('消费积分不足'); |
|
|
|
|
} |
|
|
|
|
$logList = array(); |
|
|
|
|
$consume = -1 * $config['consume_to_share'] * $count; |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $uid, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_CONSUME, |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_SHARE_EXCHANGE, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_SUCCESS, |
|
|
|
|
'count' => $consume, |
|
|
|
|
); |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $uid, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_SHARE_POINT, |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_SHARE_EXCHANGE, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_SUCCESS, |
|
|
|
|
'count' => $count, |
|
|
|
|
); |
|
|
|
|
app()->make(UserAssetsLogRepository::class)->addLog($logList); |
|
|
|
|
$this->changeEvent($uid, UserAssetsLogRepository::STATUS_SUCCESS, array('consume' => $consume)); |
|
|
|
|
$this->dao->update($uid, array('share_point' => $assets['share_point'] + $count, 'share_point_time' => time())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function sendHuitong($uid, $phone, $count){ |
|
|
|
|
$assets = $this->assets($uid); |
|
|
|
|
if($assets['huitong'] < $count){ |
|
|
|
|
throw new \Exception('惠通宝不足'); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* @var UserRepository $userRepository |
|
|
|
|
*/ |
|
|
|
|
$userRepository = app()->make(UserRepository::class); |
|
|
|
|
$toUser = $userRepository->getUserByPhone($phone); |
|
|
|
|
if(!$toUser){ |
|
|
|
|
throw new \Exception('用户不存在'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $toUser['uid'], |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG, |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG_GET, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_SUCCESS, |
|
|
|
|
'count' => $count, |
|
|
|
|
); |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $uid, |
|
|
|
|
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG, |
|
|
|
|
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG_SEND, |
|
|
|
|
'status' => UserAssetsLogRepository::STATUS_SUCCESS, |
|
|
|
|
'count' => -1 * $count, |
|
|
|
|
); |
|
|
|
|
app()->make(UserAssetsLogRepository::class)->addLog($logList); |
|
|
|
|
$this->changeEvent($uid, UserAssetsLogRepository::STATUS_SUCCESS, array('huitong' => -1 * $count)); |
|
|
|
|
$toAssets = $this->assets($toUser['uid']); |
|
|
|
|
$this->dao->update($toUser['uid'], array('huitong' => $toAssets['huitong'] + $count)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|