AccountLogic.php 3.5 KB

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