| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace common\services;
- use Yii;
- use common\components\dict;
- use common\models\xhLuckyDrawAwardParticipant;
- /**
- * 抽奖活动-用户参与记录
- * Class xhLuckyDrawAwardParticipantService
- * @package common\services
- */
- class xhLuckyDrawAwardParticipantService {
- public static function add($data)
- {
- $data = xhLuckyDrawAwardParticipant::add($data, true);
- //存入缓存
- baseService::setCacheByData($data, 'xhLuckyDrawAwardParticipant', '', Yii::$app->params['oneDayExpireTime']);
- return $data;
- }
- /**
- * 通过ID获取数据
- * @param $id
- * @return bool
- */
- public static function getById($id)
- {
- $preKey = dict::getCacheKey('xhLuckyDrawAwardParticipant');
- $cacheKey = $preKey.$id;
- $cacheData = baseService::getCache($cacheKey);
- if(empty($cacheData)){
- $data = baseService::setCacheById($id, 'xhLuckyDrawAwardParticipant', $cacheKey, Yii::$app->params['oneDayExpireTime']);
- if($data === false){
- return false;
- }
- return $data;
- }
- return $cacheData;
- }
- public static function updateById($id, $data)
- {
- $data['id'] = $id;
- $re = xhLuckyDrawAwardParticipant::updateById($id, $data);
- $reData = $re['data'];
- baseService::setCacheByData($reData, 'xhLuckyDrawAwardParticipant');
- return $re;
- }
- /**
- * @param $id
- * @param $activityDrawCount
- * @param $activityRewardCount
- * @param $activityInviteCount
- * @return mixed
- */
- public static function getDrawCount($id, $activityDrawCount, $activityRewardCount, $activityInviteCount){
- $participant = self::getById($id);
- $rewarDrawCount = 0;
- if($participant['inviteCount'] > 0){
- $rewarDrawCount = floor($participant['inviteCount'] / $activityInviteCount);
- if($rewarDrawCount > $activityRewardCount){
- $rewarDrawCount = $activityRewardCount;
- }
- }
- $drowCount = $activityDrawCount + $rewarDrawCount - $participant['useDrawCount'];
- return $drowCount;
- }
- }
|