RemitForm.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace backend\models\forms;
  3. use backend\models\RemitApi;
  4. use common\helpers\Utils;
  5. use Yii;
  6. use yii\base\Model;
  7. use yii\helpers\Url;
  8. class RemitForm extends Model
  9. {
  10. /**
  11. * @var int 打款单号
  12. */
  13. public $remitNo;
  14. /**
  15. * @var string 打款密码
  16. */
  17. public $password;
  18. private $_outRemitResult;
  19. /**
  20. * @inheritdoc
  21. */
  22. public function rules()
  23. {
  24. return [
  25. [['remitNo', 'password'], 'required'],
  26. [['remitNo'], 'integer'],
  27. [['password'], 'string'],
  28. ];
  29. }
  30. /**
  31. * @return bool
  32. */
  33. public function outRemit()
  34. {
  35. if (Yii::$app->getUser()->getIsGuest()) {
  36. Yii::$app->getUser()->loginRequired();
  37. return false;
  38. }
  39. if ($this->validate()) {
  40. $data = [];
  41. $data['remitNo'] = trim($this->remitNo);
  42. $data['password'] = $this->password;
  43. $data['notifyUrl'] = Url::to(["/remit/notify/" . Yii::$app->getSecurity()->maskToken(trim($this->remitNo))], true);
  44. $data['adminId'] = Yii::$app->getUser()->getId();
  45. $data['adminName'] = Yii::$app->getUser()->getIdentity(false)->name;
  46. $data['adminIp'] = Utils::getClientIp();
  47. $api = new RemitApi();
  48. $result = $api->outRemit($data);
  49. if ($result['code'] == 1) {
  50. $this->_outRemitResult = $result['data'];
  51. } else {
  52. if (is_array($result['message'])) {
  53. $this->addErrors($result['message']);
  54. } else {
  55. $this->addError('remitNo', $result['message']);
  56. }
  57. }
  58. }
  59. return !$this->hasErrors();
  60. }
  61. /**
  62. * @return string
  63. */
  64. public function getOutRemitResult()
  65. {
  66. return $this->_outRemitResult;
  67. }
  68. }