RefundLogic.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\logic\finance;
  15. use app\common\enum\RefundEnum;
  16. use app\common\logic\BaseLogic;
  17. use app\common\model\refund\RefundLog;
  18. use app\common\model\refund\RefundRecord;
  19. /**
  20. * 退款
  21. * Class RefundLogic
  22. * @package app\adminapi\logic\finance
  23. */
  24. class RefundLogic extends BaseLogic
  25. {
  26. /**
  27. * @notes 退款统计
  28. * @return array
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. * @author 段誉
  33. * @date 2023/3/3 12:09
  34. */
  35. public static function stat()
  36. {
  37. $records = RefundRecord::select()->toArray();
  38. $total = 0;
  39. $ing = 0;
  40. $success = 0;
  41. $error = 0;
  42. foreach ($records as $record) {
  43. $total += $record['order_amount'];
  44. switch ($record['refund_status']) {
  45. case RefundEnum::REFUND_ING:
  46. $ing += $record['order_amount'];
  47. break;
  48. case RefundEnum::REFUND_SUCCESS:
  49. $success += $record['order_amount'];
  50. break;
  51. case RefundEnum::REFUND_ERROR:
  52. $error += $record['order_amount'];
  53. break;
  54. }
  55. }
  56. return [
  57. 'total' => round($total, 2),
  58. 'ing' => round($ing, 2),
  59. 'success' => round($success, 2),
  60. 'error' => round($error, 2),
  61. ];
  62. }
  63. /**
  64. * @notes 退款日志
  65. * @param $recordId
  66. * @return array
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\DbException
  69. * @throws \think\db\exception\ModelNotFoundException
  70. * @author 段誉
  71. * @date 2023/3/3 14:25
  72. */
  73. public static function refundLog($recordId)
  74. {
  75. return (new RefundLog())
  76. ->order(['id' => 'desc'])
  77. ->where('record_id', $recordId)
  78. ->hidden(['refund_msg'])
  79. ->append(['handler', 'refund_status_text'])
  80. ->select()
  81. ->toArray();
  82. }
  83. }