AccountLogic.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\workerapi\logic;
  3. use app\common\enum\worker\WorkerAccountLogEnum;
  4. use app\common\logic\BaseLogic;
  5. use app\common\model\finance\MasterWorkerCaseOutLog;
  6. use app\common\model\master_worker\MasterWorker;
  7. use app\common\model\master_worker\MasterWorkerAccountLog;
  8. /**
  9. * @author 林海涛
  10. * @date 2024/7/22 下午4:31
  11. */
  12. class AccountLogic extends BaseLogic
  13. {
  14. /**
  15. * 我的账户总资产
  16. * @param $params
  17. * @return false|int[]
  18. * @author 林海涛
  19. * @date 2024/7/22 下午5:39
  20. */
  21. public static function totalAssets($params)
  22. {
  23. try{
  24. $yDay = date("Y-m-d",strtotime("-1 day"));
  25. $ytime = strtotime("$yDay 00:00:00");//昨天开始时间戳
  26. $yetime = strtotime("$yDay 23:59:59");//昨天开始时间戳
  27. $data= ['user_money' =>0,'account_yesterday' => 0,'case_out_money' => 0];
  28. $data['user_money'] = MasterWorker::where('id',$params['worker_id'])->value('user_money') ?? 0;
  29. $where = [];
  30. $where[] = ['worker_id','=',$params['worker_id']] ;
  31. $where[] = ['change_type', '=', WorkerAccountLogEnum::UM_INC_ADMIN];
  32. $where[] = ['action', '=',WorkerAccountLogEnum::INC];
  33. $where[] = ['create_time','between',[$ytime,$yetime]];
  34. $data['account_yesterday']= MasterWorkerAccountLog::where($where)
  35. ->sum('change_amount');
  36. $data['case_out_money']= MasterWorkerCaseOutLog::where([
  37. 'worker_id'=>$params['worker_id'],
  38. 'review_status' => 1,
  39. ])->sum('change_amount');
  40. return $data;
  41. } catch(\Exception $e){
  42. self::setError($e->getMessage());
  43. return false;
  44. }
  45. }
  46. public static function monthAccountWithCaseOutTotal($params)
  47. {
  48. try{
  49. $month = $params['month'];
  50. $firstDay = date("Y-m-d 00:00:00", strtotime("first day of {$month}"));
  51. $lastDay = date("Y-m-d 23:59:59", strtotime("{$month} +1 month -1 day"));
  52. $firstTime = strtotime($firstDay);
  53. $lastTime = strtotime($lastDay);
  54. $where = [];
  55. $where[] = ['worker_id','=',$params['worker_id']] ;
  56. $where[] = ['create_time','between',[$firstTime,$lastTime]];
  57. $data= [];
  58. $incAccountWhere[] = $where+[
  59. ['change_type', '=', WorkerAccountLogEnum::UM_INC_ADMIN],
  60. ['action', '=',WorkerAccountLogEnum::INC],
  61. ];
  62. $data['account_amount_inc_total'] = MasterWorkerAccountLog::where($incAccountWhere)
  63. ->sum('change_amount');
  64. $decAccountWhere[] = $where+[
  65. ['change_type', '=', WorkerAccountLogEnum::UM_DEC_ADMIN],
  66. ['action', '=',WorkerAccountLogEnum::DEC],
  67. ];
  68. $data['account_amount_dec_total'] = MasterWorkerAccountLog::where($decAccountWhere)
  69. ->sum('change_amount');
  70. $data['account_amount_total'] = $data['account_amount_inc_total'] - $data['account_amount_dec_total'];
  71. $caseOutWhere = $where+[
  72. ['review_status','=',1]
  73. ];
  74. $data['case_out_total'] = MasterWorkerCaseOutLog::where($caseOutWhere)->sum('change_amount');
  75. return $data;
  76. }catch(\Exception $e){
  77. self::setError($e->getMessage());
  78. return false;
  79. }
  80. }
  81. }