HomepageModel.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * HomepageModel.php UTF-8
  4. * 玩家主页模型
  5. *
  6. * @date : 2018/8/15 21:43
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HuoMP 1.0
  11. */
  12. namespace huomp\model\homepage;
  13. use huolib\constant\CacheConst;
  14. use huomp\model\common\CommonModel;
  15. use think\Cache;
  16. class HomepageModel extends CommonModel {
  17. protected $table = 'mp_homepage';
  18. // 开启自动写入时间戳字段
  19. protected $autoWriteTimestamp = true;
  20. protected $cache_key_prefix = CacheConst::CACHE_GAME_MP_PREFIX;
  21. /**
  22. * 添加数据
  23. *
  24. * @param $data
  25. *
  26. * @return bool
  27. */
  28. public function addData($data) {
  29. if (empty($data)) {
  30. return false;
  31. }
  32. $_data = $data;
  33. $_obj = self::create($_data, true);
  34. if ($_obj) {
  35. return true;
  36. }
  37. return false;
  38. }
  39. /**
  40. * 更新数据
  41. *
  42. * @param array $data 数据
  43. * @param int $mem_id 玩家ID
  44. *
  45. * @return bool
  46. */
  47. public function updateData($data, $mem_id) {
  48. $_map['mem_id'] = $mem_id;
  49. $_data = $data;
  50. $_rs = self::update($_data, $_map, true);
  51. if (false == $_rs) {
  52. return false;
  53. }
  54. $_cache_key = $this->cache_key_prefix.$_data['mem_id'];
  55. Cache::rm($_cache_key);
  56. return true;
  57. }
  58. /**
  59. * 获取Banner图
  60. *
  61. * @param $mem_id
  62. *
  63. * @return array|bool|false
  64. */
  65. public function getInfoByMemId($mem_id) {
  66. $_cache_key = $this->cache_key_prefix.$mem_id;
  67. $_data = Cache::get($_cache_key);
  68. if (!empty($_data)) {
  69. return $_data;
  70. }
  71. $_map['mem_id'] = $mem_id;
  72. $_info = $this->where($_map)->find();
  73. if (false === $_info) {
  74. return false;
  75. }
  76. if (is_object($_info)) {
  77. $_info = $_info->toArray();
  78. }
  79. Cache::set($_cache_key, $_info);
  80. return $_info;
  81. }
  82. }