UserPower.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. 'speak_text',
  18. 'speak_time_text',
  19. 'recharge_text',
  20. 'raffle_text',
  21. 'give_gift_text',
  22. 'transfer_text',
  23. 'payorder_text',
  24. 'attire_text',
  25. 'noble_text',
  26. 'withdraw_text'
  27. ];
  28. public function getPrivateMessagesList()
  29. {
  30. return ['0' => __('Private_messages 0'), '1' => __('Private_messages 1'), '2' => __('Private_messages 2')];
  31. }
  32. public function getSpeakList()
  33. {
  34. return ['0' => __('Speak 0'),'1' => __('Speak 1'),'2' => __('Speak 2')];
  35. }
  36. public function getRechargeList()
  37. {
  38. return ['0' => __('Recharge 0'), '1' => __('Recharge 1')];
  39. }
  40. public function getRaffleList()
  41. {
  42. return ['0' => __('Raffle 0'), '1' => __('Raffle 1')];
  43. }
  44. public function getGiveGiftList()
  45. {
  46. return ['0' => __('Give_gift 0'), '1' => __('Give_gift 1')];
  47. }
  48. public function getTransferList()
  49. {
  50. return ['0' => __('Transfer 0'), '1' => __('Transfer 1')];
  51. }
  52. public function getPayorderList()
  53. {
  54. return ['0' => __('Payorder 0'), '1' => __('Payorder 1')];
  55. }
  56. public function getAttireList()
  57. {
  58. return ['0' => __('Attire 0'), '1' => __('Attire 1')];
  59. }
  60. public function getNobleList()
  61. {
  62. return ['0' => __('Noble 0'), '1' => __('Noble 1')];
  63. }
  64. public function getWithdrawList()
  65. {
  66. return ['0' => __('Withdraw 0'), '1' => __('Withdraw 1')];
  67. }
  68. public function getPrivateMessagesTextAttr($value, $data)
  69. {
  70. $value = $value ? $value : (isset($data['private_messages']) ? $data['private_messages'] : '');
  71. $list = $this->getPrivateMessagesList();
  72. return isset($list[$value]) ? $list[$value] : '';
  73. }
  74. public function getSpeakTextAttr($value, $data)
  75. {
  76. $value = $value ? $value : (isset($data['speak']) ? $data['speak'] : '');
  77. $list = $this->getSpeakList();
  78. return isset($list[$value]) ? $list[$value] : '';
  79. }
  80. public function getSpeakTimeTextAttr($value, $data)
  81. {
  82. $value = $value ? $value : (isset($data['speak_time']) ? $data['speak_time'] : '');
  83. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  84. }
  85. public function getRechargeTextAttr($value, $data)
  86. {
  87. $value = $value ? $value : (isset($data['recharge']) ? $data['recharge'] : '');
  88. $list = $this->getRechargeList();
  89. return isset($list[$value]) ? $list[$value] : '';
  90. }
  91. public function getRaffleTextAttr($value, $data)
  92. {
  93. $value = $value ? $value : (isset($data['raffle']) ? $data['raffle'] : '');
  94. $list = $this->getRaffleList();
  95. return isset($list[$value]) ? $list[$value] : '';
  96. }
  97. public function getGiveGiftTextAttr($value, $data)
  98. {
  99. $value = $value ? $value : (isset($data['give_gift']) ? $data['give_gift'] : '');
  100. $list = $this->getGiveGiftList();
  101. return isset($list[$value]) ? $list[$value] : '';
  102. }
  103. public function getTransferTextAttr($value, $data)
  104. {
  105. $value = $value ? $value : (isset($data['transfer']) ? $data['transfer'] : '');
  106. $list = $this->getTransferList();
  107. return isset($list[$value]) ? $list[$value] : '';
  108. }
  109. public function getPayorderTextAttr($value, $data)
  110. {
  111. $value = $value ? $value : (isset($data['payorder']) ? $data['payorder'] : '');
  112. $list = $this->getPayorderList();
  113. return isset($list[$value]) ? $list[$value] : '';
  114. }
  115. public function getAttireTextAttr($value, $data)
  116. {
  117. $value = $value ? $value : (isset($data['attire']) ? $data['attire'] : '');
  118. $list = $this->getAttireList();
  119. return isset($list[$value]) ? $list[$value] : '';
  120. }
  121. public function getNobleTextAttr($value, $data)
  122. {
  123. $value = $value ? $value : (isset($data['noble']) ? $data['noble'] : '');
  124. $list = $this->getNobleList();
  125. return isset($list[$value]) ? $list[$value] : '';
  126. }
  127. public function getWithdrawTextAttr($value, $data)
  128. {
  129. $value = $value ? $value : (isset($data['withdraw']) ? $data['withdraw'] : '');
  130. $list = $this->getWithdrawList();
  131. return isset($list[$value]) ? $list[$value] : '';
  132. }
  133. protected function setSpeakTimeAttr($value)
  134. {
  135. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  136. }
  137. public function user()
  138. {
  139. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  140. }
  141. }