UserPower.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class UserPower extends Model
  5. {
  6. // 表名
  7. protected $name = 'user_power';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'private_messages_text',
  17. 'barrage_text',
  18. 'speak_text',
  19. 'speak_time_text',
  20. 'recharge_text',
  21. 'raffle_text',
  22. 'give_gift_text',
  23. 'transfer_text',
  24. 'payorder_text',
  25. 'attire_text',
  26. 'noble_text',
  27. 'withdraw_text'
  28. ];
  29. public function getPrivateMessagesList()
  30. {
  31. return ['0' => __('Private_messages 0'), '1' => __('Private_messages 1')];
  32. }
  33. public function getBarrageList()
  34. {
  35. return ['0' => __('Barrage 0'), '1' => __('Barrage 1')];
  36. }
  37. public function getSpeakList()
  38. {
  39. return ['0' => __('Speak 0')];
  40. }
  41. public function getRechargeList()
  42. {
  43. return ['0' => __('Recharge 0'), '1' => __('Recharge 1')];
  44. }
  45. public function getRaffleList()
  46. {
  47. return ['0' => __('Raffle 0'), '1' => __('Raffle 1')];
  48. }
  49. public function getGiveGiftList()
  50. {
  51. return ['0' => __('Give_gift 0'), '1' => __('Give_gift 1')];
  52. }
  53. public function getTransferList()
  54. {
  55. return ['0' => __('Transfer 0'), '1' => __('Transfer 1')];
  56. }
  57. public function getPayorderList()
  58. {
  59. return ['0' => __('Payorder 0'), '1' => __('Payorder 1')];
  60. }
  61. public function getAttireList()
  62. {
  63. return ['0' => __('Attire 0'), '1' => __('Attire 1')];
  64. }
  65. public function getNobleList()
  66. {
  67. return ['0' => __('Noble 0'), '1' => __('Noble 1')];
  68. }
  69. public function getWithdrawList()
  70. {
  71. return ['0' => __('Withdraw 0'), '1' => __('Withdraw 1')];
  72. }
  73. public function getPrivateMessagesTextAttr($value, $data)
  74. {
  75. $value = $value ? $value : (isset($data['private_messages']) ? $data['private_messages'] : '');
  76. $list = $this->getPrivateMessagesList();
  77. return isset($list[$value]) ? $list[$value] : '';
  78. }
  79. public function getBarrageTextAttr($value, $data)
  80. {
  81. $value = $value ? $value : (isset($data['barrage']) ? $data['barrage'] : '');
  82. $list = $this->getBarrageList();
  83. return isset($list[$value]) ? $list[$value] : '';
  84. }
  85. public function getSpeakTextAttr($value, $data)
  86. {
  87. $value = $value ? $value : (isset($data['speak']) ? $data['speak'] : '');
  88. $list = $this->getSpeakList();
  89. return isset($list[$value]) ? $list[$value] : '';
  90. }
  91. public function getSpeakTimeTextAttr($value, $data)
  92. {
  93. $value = $value ? $value : (isset($data['speak_time']) ? $data['speak_time'] : '');
  94. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  95. }
  96. public function getRechargeTextAttr($value, $data)
  97. {
  98. $value = $value ? $value : (isset($data['recharge']) ? $data['recharge'] : '');
  99. $list = $this->getRechargeList();
  100. return isset($list[$value]) ? $list[$value] : '';
  101. }
  102. public function getRaffleTextAttr($value, $data)
  103. {
  104. $value = $value ? $value : (isset($data['raffle']) ? $data['raffle'] : '');
  105. $list = $this->getRaffleList();
  106. return isset($list[$value]) ? $list[$value] : '';
  107. }
  108. public function getGiveGiftTextAttr($value, $data)
  109. {
  110. $value = $value ? $value : (isset($data['give_gift']) ? $data['give_gift'] : '');
  111. $list = $this->getGiveGiftList();
  112. return isset($list[$value]) ? $list[$value] : '';
  113. }
  114. public function getTransferTextAttr($value, $data)
  115. {
  116. $value = $value ? $value : (isset($data['transfer']) ? $data['transfer'] : '');
  117. $list = $this->getTransferList();
  118. return isset($list[$value]) ? $list[$value] : '';
  119. }
  120. public function getPayorderTextAttr($value, $data)
  121. {
  122. $value = $value ? $value : (isset($data['payorder']) ? $data['payorder'] : '');
  123. $list = $this->getPayorderList();
  124. return isset($list[$value]) ? $list[$value] : '';
  125. }
  126. public function getAttireTextAttr($value, $data)
  127. {
  128. $value = $value ? $value : (isset($data['attire']) ? $data['attire'] : '');
  129. $list = $this->getAttireList();
  130. return isset($list[$value]) ? $list[$value] : '';
  131. }
  132. public function getNobleTextAttr($value, $data)
  133. {
  134. $value = $value ? $value : (isset($data['noble']) ? $data['noble'] : '');
  135. $list = $this->getNobleList();
  136. return isset($list[$value]) ? $list[$value] : '';
  137. }
  138. public function getWithdrawTextAttr($value, $data)
  139. {
  140. $value = $value ? $value : (isset($data['withdraw']) ? $data['withdraw'] : '');
  141. $list = $this->getWithdrawList();
  142. return isset($list[$value]) ? $list[$value] : '';
  143. }
  144. protected function setSpeakTimeAttr($value)
  145. {
  146. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  147. }
  148. public function user()
  149. {
  150. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  151. }
  152. }