HunterRankModel.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * HunterRankModel.php UTF-8
  4. * 猎人平台虚拟排行
  5. *
  6. * @date : 2018/9/20 19:36
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HuoMP 1.0
  11. */
  12. namespace huomp\model\hunter;
  13. use huomp\model\common\CommonModel;
  14. class HunterRankModel extends CommonModel {
  15. protected $table = 'mp_hunter_rank';
  16. // 开启自动写入时间戳字段
  17. protected $autoWriteTimestamp = true;
  18. public function mem() {
  19. return $this->hasone('\huo\model\member\MemberModel', 'id', 'mem_id')->field('id,nickname,avatar');
  20. }
  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 $id ID
  44. *
  45. * @return bool
  46. */
  47. public function updateData($data, $id) {
  48. $_map['id'] = $id;
  49. $_data = $data;
  50. $_rs = self::update($_data, $_map, true);
  51. if (false == $_rs) {
  52. return false;
  53. }
  54. return true;
  55. }
  56. /**
  57. * 获取数据
  58. *
  59. * @param $id
  60. */
  61. public function getInfoById($id) {
  62. $_map = ['id' => $id];
  63. $_data = $this->with('mem')->where($_map)->find();
  64. if (is_object($_data)) {
  65. $_data = $_data->toArray();
  66. }
  67. $_rdata = [
  68. 'id' => get_val($_data, 'id', 0),
  69. 'mem_id' => get_val($_data, 'mem_id', 0),
  70. 'nickname' => empty($_data['mem']) ? '' : $_data['mem']['nickname'],
  71. 'day_money' => get_val($_data, 'day_money', 0),
  72. 'month_money' => get_val($_data, 'month_money', 0),
  73. 'total_money' => get_val($_data, 'total_money', 0),
  74. ];
  75. return $_rdata;
  76. }
  77. /**
  78. * 删除数据
  79. *
  80. * @param $id
  81. *
  82. * @return int
  83. */
  84. public function deleteData($id) {
  85. $_map = ['id' => $id];
  86. return $this->where($_map)->delete();
  87. }
  88. /**
  89. * 获取列表中的所有mem_id
  90. *
  91. * @return array
  92. */
  93. public function getMemIds() {
  94. return $this->column('mem_id');
  95. }
  96. }