AuditController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. *
  5. * User: king/QQ:995265288
  6. * Date: 2018/6/12 下午4:23
  7. * Email: livsyitian@163.com
  8. */
  9. namespace app\backend\modules\withdraw\controllers;
  10. use app\backend\models\Withdraw;
  11. use app\common\exceptions\ShopException;
  12. use app\common\services\withdraw\AuditService;
  13. use Yunshop\WithdrawalLimit\Common\services\WithdrawHandleService;
  14. class AuditController extends PreController
  15. {
  16. /**
  17. * 提现记录审核接口
  18. */
  19. public function index()
  20. {
  21. list($audit_ids, $invalid_ids, $rebut_ids) = $this->auditResult();
  22. $this->withdrawModel->audit_ids = $audit_ids;
  23. $this->withdrawModel->rebut_ids = $rebut_ids;
  24. $this->withdrawModel->invalid_ids = $invalid_ids;
  25. $this->withdrawModel->reject_reason = request()->reject_reason ? : '';
  26. $result = (new AuditService($this->withdrawModel))->withdrawAudit();
  27. if ($result == true) {
  28. if(app('plugins')->isEnabled('withdrawal-limit'))
  29. {
  30. WithdrawHandleService::handle('rebut',$rebut_ids,$this->withdrawModel,true);
  31. WithdrawHandleService::handle('invalid',$invalid_ids,$this->withdrawModel,true);
  32. }
  33. return $this->successJson('审核成功');
  34. }
  35. return $this->errorJson('审核失败,请刷新重试');
  36. }
  37. /**
  38. * @return array
  39. * @throws ShopException
  40. */
  41. private function auditResult()
  42. {
  43. $audit_data = $this->getPostAuditData();
  44. $audit_ids = [];
  45. $rebut_ids = [];
  46. $invalid_ids = [];
  47. foreach ($audit_data as $income_id => $status) {
  48. switch ($status) {
  49. case Withdraw::STATUS_AUDIT:
  50. $audit_ids[] = $income_id;
  51. break;
  52. case Withdraw::STATUS_INVALID:
  53. $invalid_ids[] = $income_id;
  54. break;
  55. case Withdraw::STATUS_REBUT:
  56. $rebut_ids[] = $income_id;
  57. break;
  58. }
  59. }
  60. return [$audit_ids, $invalid_ids, $rebut_ids];
  61. }
  62. /**
  63. * @return array
  64. * @throws ShopException
  65. */
  66. private function getPostAuditData()
  67. {
  68. $audit_data = \YunShop::request()->audit;
  69. if (!$audit_data) {
  70. throw new ShopException('数据参数错误');
  71. }
  72. return $audit_data;
  73. }
  74. public function validatorWithdrawModel($withdrawModel)
  75. {
  76. if ($withdrawModel->status != Withdraw::STATUS_INITIAL && $withdrawModel->status != Withdraw::STATUS_INVALID) {
  77. throw new ShopException('状态错误,不符合审核规则!');
  78. }
  79. }
  80. }