BalanceAutomateAuditService.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2019/7/12
  6. * Time: 上午 09:59
  7. */
  8. namespace app\frontend\modules\withdraw\services;
  9. use app\common\models\Withdraw;
  10. use Illuminate\Support\Facades\Log;
  11. use app\common\exceptions\ShopException;
  12. use app\backend\modules\finance\controllers\BalanceWithdrawController;
  13. class BalanceAutomateAuditService
  14. {
  15. /**
  16. * @var Withdraw
  17. */
  18. private $withdrawModel;
  19. public function __construct(Withdraw $withdrawModel)
  20. {
  21. $this->withdrawModel = $withdrawModel;
  22. \Setting::$uniqueAccountId = \YunShop::app()->uniacid = $withdrawModel->uniacid;
  23. }
  24. /**
  25. * 提现免审核
  26. *
  27. * @throws ShopException
  28. */
  29. public function freeAudit()
  30. {
  31. $this->withdrawAudit();
  32. $this->withdrawPay();
  33. Log::debug("余额提现免审核ID:{$this->withdrawModel->id}自动审核打款完成");
  34. }
  35. /**
  36. * 提现审核
  37. *
  38. * @throws ShopException
  39. */
  40. private function withdrawAudit()
  41. {
  42. $this->withdrawModel->status = Withdraw::STATUS_AUDIT;
  43. $this->withdrawModel->audit_at = time();
  44. $this->withdrawUpdate();
  45. }
  46. /**
  47. * 提现打款
  48. *
  49. * @throws \app\common\exceptions\AppException
  50. */
  51. private function withdrawPay()
  52. {
  53. $BalanceWithdraw = new BalanceWithdrawController;
  54. $BalanceWithdraw->withdrawModel = $this->withdrawModel;
  55. $BalanceWithdraw->submitPay();
  56. }
  57. /**
  58. * 提现 model 数据保存
  59. * @return bool
  60. * @throws ShopException
  61. */
  62. private function withdrawUpdate()
  63. {
  64. if (!$this->withdrawModel->save()) {
  65. Log::debug("提现审核失败:{$this->withdrawModel->id}数据修改失败");
  66. throw new ShopException("提现审核失败:{$this->withdrawModel->id}数据修改失败");
  67. }
  68. return true;
  69. }
  70. }