链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.8 KiB

5 years ago
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class LanzuUserBalance extends Model
  5. {
  6. protected $table = 'lanzu_user_balance';
  7. protected $dateFormat = 'U';
  8. protected $guarded = [];
  9. /**
  10. * 获取可提现金额
  11. * @param $uid
  12. * @param $uType 0/1 普通用户/服务商
  13. */
  14. public static function getBalance($uid, $uType=null)
  15. {
  16. $row = self::where(['source_id' => $uid, 'user_type' => $uType])->first();
  17. if ($row) {
  18. return $row->balance;
  19. } else {
  20. return '0.00';
  21. }
  22. }
  23. /**
  24. * 扣减可提现金额
  25. */
  26. public static function reduceBalance($sid, $type, $reduceMoney)
  27. {
  28. $row = self::where(['source_id' => $sid, 'user_type' => $type])->first();
  29. if ($row) {
  30. $row->balance = $row->balance - $reduceMoney;
  31. return $row->save();
  32. } else {
  33. return false;
  34. }
  35. }
  36. /**
  37. * 回退审核未通过时的提现金额
  38. */
  39. public static function returnBalance($sid, $uType, $returnMoney)
  40. {
  41. $row = self::where(['source_id' => $sid, 'user_type' => $uType])->first();
  42. if ($row) {
  43. $row->balance = $row->balance + $returnMoney;
  44. return $row->save();
  45. } else {
  46. return false;
  47. }
  48. }
  49. /**
  50. * 生成一条数据
  51. */
  52. public static function create($aduid, $type)
  53. {
  54. $self = new self();
  55. $self->source_id = $aduid;
  56. $self->user_type = $type;
  57. $self->balance = 0;
  58. $self->save();
  59. }
  60. /**
  61. * 校验是否在足够的可提现金额
  62. */
  63. public static function checkBalance($aduid,$money)
  64. {
  65. return self::where('source_id',$aduid)->where('balance','>=',$money)->count();
  66. }
  67. }