RetentionMoneyLogic.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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\master_worker\MasterWorker;
  6. use app\common\model\master_worker\MasterWorkerRetentionMoneyLog;
  7. /**
  8. * @author 林海涛
  9. * @date 2024/7/28 上午10:32
  10. */
  11. class RetentionMoneyLogic extends BaseLogic
  12. {
  13. public static function totalAmount($params)
  14. {
  15. try{
  16. $model = MasterWorker::findOrEmpty($params['worker_id']);
  17. if($model->isEmpty()){
  18. throw new \Exception('用户不存在');
  19. }
  20. $where = [];
  21. $where[] = ['worker_id','=',$params['worker_id']] ;
  22. $incWhere =$where;
  23. $incWhere[] = ['action', '=',WorkerAccountLogEnum::INC];
  24. $data['amount_inc_total'] = MasterWorkerRetentionMoneyLog::where($incWhere)
  25. ->sum('amount');
  26. $outWhere = $where;
  27. $outWhere[] =['action', '=',WorkerAccountLogEnum::DEC];
  28. $data['amount_dec_total'] = MasterWorkerRetentionMoneyLog::where($outWhere)
  29. ->sum('amount');
  30. $data['amount_available_total'] = $data['amount_inc_total'] - $data['amount_dec_total'];
  31. $data['retention_money_status'] = $model->retention_money_status;
  32. $data['retention_money_status_text'] = $model->retention_money_status_text;
  33. $data['retention_pay_status'] = $model->retention_pay_status;
  34. $data['retention_pay_status_text'] = $model->retention_pay_status_text;
  35. return $data;
  36. } catch(\Exception $e){
  37. self::setError($e->getMessage());
  38. return false;
  39. }
  40. }
  41. }