xhLuckyDrawAwardParticipantService.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace common\services;
  3. use Yii;
  4. use common\components\dict;
  5. use common\models\xhLuckyDrawAwardParticipant;
  6. /**
  7. * 抽奖活动-用户参与记录
  8. * Class xhLuckyDrawAwardParticipantService
  9. * @package common\services
  10. */
  11. class xhLuckyDrawAwardParticipantService {
  12. public static function add($data)
  13. {
  14. $data = xhLuckyDrawAwardParticipant::add($data, true);
  15. //存入缓存
  16. baseService::setCacheByData($data, 'xhLuckyDrawAwardParticipant', '', Yii::$app->params['oneDayExpireTime']);
  17. return $data;
  18. }
  19. /**
  20. * 通过ID获取数据
  21. * @param $id
  22. * @return bool
  23. */
  24. public static function getById($id)
  25. {
  26. $preKey = dict::getCacheKey('xhLuckyDrawAwardParticipant');
  27. $cacheKey = $preKey.$id;
  28. $cacheData = baseService::getCache($cacheKey);
  29. if(empty($cacheData)){
  30. $data = baseService::setCacheById($id, 'xhLuckyDrawAwardParticipant', $cacheKey, Yii::$app->params['oneDayExpireTime']);
  31. if($data === false){
  32. return false;
  33. }
  34. return $data;
  35. }
  36. return $cacheData;
  37. }
  38. public static function updateById($id, $data)
  39. {
  40. $data['id'] = $id;
  41. $re = xhLuckyDrawAwardParticipant::updateById($id, $data);
  42. $reData = $re['data'];
  43. baseService::setCacheByData($reData, 'xhLuckyDrawAwardParticipant');
  44. return $re;
  45. }
  46. /**
  47. * @param $id
  48. * @param $activityDrawCount
  49. * @param $activityRewardCount
  50. * @param $activityInviteCount
  51. * @return mixed
  52. */
  53. public static function getDrawCount($id, $activityDrawCount, $activityRewardCount, $activityInviteCount){
  54. $participant = self::getById($id);
  55. $rewarDrawCount = 0;
  56. if($participant['inviteCount'] > 0){
  57. $rewarDrawCount = floor($participant['inviteCount'] / $activityInviteCount);
  58. if($rewarDrawCount > $activityRewardCount){
  59. $rewarDrawCount = $activityRewardCount;
  60. }
  61. }
  62. $drowCount = $activityDrawCount + $rewarDrawCount - $participant['useDrawCount'];
  63. return $drowCount;
  64. }
  65. }