xhLuckyDrawAwardCustomerService.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace common\services;
  3. use Yii;
  4. use common\components\dict;
  5. use common\models\xhLuckyDrawAwardCustomer;
  6. /**
  7. * 抽奖活动-中奖用户
  8. * Class xhLuckyDrawAwardCustomerService
  9. * @package common\services
  10. */
  11. class xhLuckyDrawAwardCustomerService {
  12. public static function add($data)
  13. {
  14. $data = xhLuckyDrawAwardCustomer::add($data, true);
  15. //存入缓存
  16. baseService::setCacheByData($data, 'xhLuckyDrawAwardCustomer', '', 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('xhLuckyDrawAward');
  27. $cacheKey = $preKey.$id;
  28. $cacheData = baseService::getCache($cacheKey);
  29. if(empty($cacheData)){
  30. $data = baseService::setCacheById($id, 'xhLuckyDrawAwardCustomer', $cacheKey, Yii::$app->params['oneDayExpireTime']);
  31. if($data === false){
  32. return false;
  33. }
  34. return $data;
  35. }
  36. }
  37. public static function updateById($id, $data)
  38. {
  39. $data['id'] = $id;
  40. $re = xhLuckyDrawAwardCustomer::updateById($id, $data);
  41. $reData = $re['data'];
  42. baseService::setCacheByData($reData, 'xhLuckyDrawAwardCustomer');
  43. return $re;
  44. }
  45. }