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

60 lines
1.4 KiB

5 years ago
5 years ago
  1. <?php
  2. namespace App\Models;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\Model;
  5. class MpBalance extends Model
  6. {
  7. protected $table = 'lanzu_user_balance';
  8. protected $dateFormat = 'U';
  9. protected $guarded = [];
  10. /**
  11. * 获取可提现金额
  12. * @param $uid
  13. * @param $uType 0/1 普通用户/服务商
  14. */
  15. public static function getBalance($uid,$uType=0)
  16. {
  17. $row = self::where(['source_id'=>$uid,'user_type'=>$uType])->firstOrCreate(
  18. ['source_id'=>$uid,'user_type'=>$uType],
  19. ['balance'=>0]
  20. );
  21. if ($row){
  22. return $row->balance;
  23. }else{
  24. return '0.00';
  25. }
  26. }
  27. /**
  28. * 扣减可提现金额
  29. */
  30. public static function reduceBalance($uid,$uType,$reduceMoney)
  31. {
  32. $row = self::where(['source_id'=>$uid,'user_type'=>$uType])->first();
  33. if ($row){
  34. $row->balance = $row->balance-$reduceMoney;
  35. return $row->save();
  36. }else{
  37. return false;
  38. }
  39. }
  40. /**
  41. * 回退审核未通过时的提现金额
  42. */
  43. public static function returnBalance($uid,$uType,$returnMoney)
  44. {
  45. $row = self::where(['source_id'=>$uid,'user_type'=>$uType])->first();
  46. if ($row){
  47. $row->balance = $row->balance+$returnMoney;
  48. return $row->save();
  49. }else{
  50. return false;
  51. }
  52. }
  53. }