CompanyUserMoneyService.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace Modules\Jiesuan\Services;
  3. use Illuminate\Support\Facades\DB;
  4. class CompanyUserMoneyService
  5. {
  6. /**
  7. * 公司管理员用户金额详情
  8. * @param $companyUid
  9. * @return null | object
  10. * <pre>
  11. * {
  12. * 'company_uid' : 1, // 公司管理员uid
  13. * 'total_income' : 1, // 总收入,
  14. * 'total_dakuan' :1, //已打款金额
  15. * 'total_tuikuan' : 1, // 总退款金额
  16. * 'tixian_money' : 1, // 审核中提现金额
  17. * 'yue_money' : 1, // 当前余额
  18. * }
  19. * </pre>
  20. */
  21. public static function userMoneyInfo($companyUid)
  22. {
  23. $moneyInfo = DB::table('company_user_money')
  24. ->where('company_uid', $companyUid)
  25. ->select('total_income', 'total_dakuan', 'total_tuikuan', 'company_uid')
  26. ->first();
  27. if(!$moneyInfo) {
  28. return (object)[
  29. 'company_uid' => $companyUid,
  30. 'total_income' => 0,
  31. 'total_dakuan' => 0,
  32. 'total_tuikuan' => 0,
  33. 'tixian_money' => 0,
  34. 'yue_money' => 0,
  35. ];
  36. }
  37. $tixian_money = DB::table('tixian_records')
  38. ->where('company_uid', $companyUid)
  39. ->whereIn('status', [1, 3])
  40. ->sum('tixian_money');
  41. $moneyInfo->tixian_money = $tixian_money;
  42. $moneyInfo->yue_money = $moneyInfo->total_income - $moneyInfo->total_tuikuan - $moneyInfo->total_dakuan - $tixian_money;
  43. return $moneyInfo;
  44. }
  45. /**
  46. * 用户金额变动日志记录
  47. * @param $companyUid
  48. * @param $type
  49. * @param $before
  50. * @param $after
  51. */
  52. public static function log($companyUid, $type, $before, $after) {
  53. $now = date('Y-m-d H:i:s');
  54. $field = [
  55. 'total_income' => '总充值',
  56. 'total_dakuan' => '总打款',
  57. 'total_tuikuan' => '总退款',
  58. 'tixian_money' => '提现金额',
  59. 'yue_money' => '余额'
  60. ];
  61. foreach ($field as $key=>$val) {
  62. $des[] = sprintf('%s变动:[%s元-->%s元]', $val, $before->{$key}, $after->{$key});
  63. }
  64. DB::table('company_user_money_change_logs')
  65. ->insert([
  66. 'type' => $type,
  67. 'company_uid' => $companyUid,
  68. 'created_at' => $now,
  69. 'log' => \json_encode([
  70. 'desc' => join(', ', $des),
  71. 'before' => [
  72. 'total_income' => $before->total_income,
  73. 'total_dakuan' => $before->total_dakuan,
  74. 'total_tuikuan' => $before->total_tuikuan,
  75. 'tixian_money' => $before->tixian_money,
  76. 'yue_money' => $before->yue_money,
  77. ],
  78. 'after' => [
  79. 'total_income' => $after->total_income,
  80. 'total_dakuan' => $after->total_dakuan,
  81. 'total_tuikuan' => $after->total_tuikuan,
  82. 'tixian_money' => $after->tixian_money,
  83. 'yue_money' => $after->yue_money,
  84. ],
  85. 'created_at' => $now,
  86. ], JSON_UNESCAPED_UNICODE)
  87. ]);
  88. }
  89. }