UserModel.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\common\model;
  3. use think\db\exception\DataNotFoundException;
  4. use think\db\exception\ModelNotFoundException;
  5. use think\Exception;
  6. use think\exception\DbException;
  7. use think\Model;
  8. /**
  9. * 会员模型
  10. */
  11. class UserModel extends Model
  12. {
  13. // // 开启自动写入时间戳字段
  14. // protected $autoWriteTimestamp = 'int';
  15. // // 定义时间戳字段名
  16. // protected $createTime = 'createtime';
  17. // protected $updateTime = 'updatetime';
  18. // // 追加属性
  19. // protected $append = [
  20. // 'url',
  21. // ];.
  22. protected $name = 'user';
  23. public function getById($userID)
  24. {
  25. return $this->where('id', $userID)->find();
  26. }
  27. public function getByAddress($address)
  28. {
  29. return $this->where("address", $address)->find();
  30. }
  31. public function getAllAddress()
  32. {
  33. $all_list = $this->field('id,address')->select();
  34. $arr = [];
  35. foreach ($all_list as $item){
  36. $arr[$item['address']] = $item['id'];
  37. }
  38. return $arr;
  39. }
  40. //获取用户余额 冻结金额 和 折合金额
  41. public static function getUserAmount(int $uid): float
  42. {
  43. return self::where('id', $uid)->sum("balance-frozen_amount");
  44. }
  45. //获取用户RWA
  46. public static function getUserRwaNum(int $uid): int
  47. {
  48. return self::where('id', $uid)->value("rwa_num");
  49. }
  50. /**
  51. * RWA更新数据
  52. * @param int $uid
  53. * @param string $power
  54. * @return void
  55. */
  56. public static function updateForRwaNum(int $uid, string $score, string $action)
  57. {
  58. if($action == '+'){
  59. return self::where('id', $uid)->setInc('rwa_num', $score);
  60. }else{
  61. return self::where('id', $uid)->setDec('rwa_num', $score);
  62. }
  63. }
  64. /**
  65. * 余额更新数据
  66. * @param int $uid
  67. * @param string $power
  68. * @return void
  69. */
  70. public static function updateForRBalance(int $uid, string $score, string $action)
  71. {
  72. if($action == '+'){
  73. return self::where('id', $uid)->setInc('balance', $score);
  74. }else{
  75. return self::where('id', $uid)->setDec('balance', $score);
  76. }
  77. }
  78. }