AccountLogic.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. $masterWorker = MasterWorker::where('id',$params['worker_id'])->field('user_money,type')->findOrEmpty();
  29. if ($masterWorker->type == 2) {
  30. return ['user_money' =>"-",'account_yesterday' => "-",'case_out_money' => "-"];
  31. }
  32. $data['user_money'] = $masterWorker && $masterWorker->user_money ?? 0;
  33. $where = [];
  34. $where[] = ['worker_id','=',$params['worker_id']] ;
  35. $where[] = ['change_type', '=', WorkerAccountLogEnum::UM_INC_ADMIN];
  36. $where[] = ['action', '=',WorkerAccountLogEnum::INC];
  37. $where[] = ['create_time','between',[$ytime,$yetime]];
  38. $data['account_yesterday']= MasterWorkerAccountLog::where($where)
  39. ->sum('change_amount');
  40. $data['case_out_money']= MasterWorkerCaseOutLog::where([
  41. 'worker_id'=>$params['worker_id'],
  42. 'review_status' => 1,
  43. ])->sum('change_amount');
  44. return $data;
  45. } catch(\Exception $e){
  46. self::setError($e->getMessage());
  47. return false;
  48. }
  49. }
  50. public static function monthAccountWithCaseOutTotal($params)
  51. {
  52. try{
  53. $month = $params['month'];
  54. $firstDay = date("Y-m-d 00:00:00", strtotime("first day of {$month}"));
  55. $lastDay = date("Y-m-d 23:59:59", strtotime("{$month} +1 month -1 day"));
  56. $firstTime = strtotime($firstDay);
  57. $lastTime = strtotime($lastDay);
  58. $where = [];
  59. $where[] = ['worker_id','=',$params['worker_id']] ;
  60. $where[] = ['create_time','between',[$firstTime,$lastTime]];
  61. $data= [];
  62. $incAccountWhere[] = $where+[
  63. ['change_type', '=', WorkerAccountLogEnum::UM_INC_ADMIN],
  64. ['action', '=',WorkerAccountLogEnum::INC],
  65. ];
  66. $data['account_amount_inc_total'] = MasterWorkerAccountLog::where($incAccountWhere)
  67. ->sum('change_amount');
  68. $decAccountWhere[] = $where+[
  69. ['change_type', '=', WorkerAccountLogEnum::UM_DEC_ADMIN],
  70. ['action', '=',WorkerAccountLogEnum::DEC],
  71. ];
  72. $data['account_amount_dec_total'] = MasterWorkerAccountLog::where($decAccountWhere)
  73. ->sum('change_amount');
  74. $data['account_amount_total'] = $data['account_amount_inc_total'] - $data['account_amount_dec_total'];
  75. $caseOutWhere = $where+[
  76. ['review_status','=',1]
  77. ];
  78. $data['case_out_total'] = MasterWorkerCaseOutLog::where($caseOutWhere)->sum('change_amount');
  79. return $data;
  80. }catch(\Exception $e){
  81. self::setError($e->getMessage());
  82. return false;
  83. }
  84. }
  85. }