链街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.

70 lines
1.6 KiB

  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. /**
  9. * 获取可提现金额
  10. * @param $uid
  11. * @param $uType 0/1 普通用户/服务商
  12. */
  13. public static function getBalance($uid, $uType = 0)
  14. {
  15. $row = self::where(['source_id' => $uid, 'user_type' => $uType])->first();
  16. if ($row) {
  17. return $row->balance;
  18. } else {
  19. return '0.00';
  20. }
  21. }
  22. /**
  23. * 扣减可提现金额
  24. */
  25. public static function reduceBalance($sid, $type, $reduceMoney)
  26. {
  27. $row = self::where(['source_id' => $sid, 'user_type' => $type])->first();
  28. if ($row) {
  29. $row->balance = $row->balance - $reduceMoney;
  30. return $row->save();
  31. } else {
  32. return false;
  33. }
  34. }
  35. /**
  36. * 回退审核未通过时的提现金额
  37. */
  38. public static function returnBalance($sid, $uType, $returnMoney)
  39. {
  40. $row = self::where(['source_id' => $sid, 'user_type' => $uType])->first();
  41. if ($row) {
  42. $row->balance = $row->balance + $returnMoney;
  43. return $row->save();
  44. } else {
  45. return false;
  46. }
  47. }
  48. /**
  49. * 生成一条数据
  50. */
  51. public static function create($sid, $type)
  52. {
  53. $self = new self();
  54. $self->source_id = $sid;
  55. $self->user_type = $type;
  56. $self->balance = 0;
  57. $self->save();
  58. }
  59. }