| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace backend\models\forms;
- use backend\models\RemitApi;
- use common\helpers\Utils;
- use Yii;
- use yii\base\Model;
- use yii\helpers\Url;
- class RemitForm extends Model
- {
- /**
- * @var int 打款单号
- */
- public $remitNo;
-
- private $_outRemitResult;
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['remitNo'], 'required'],
- [['remitNo'], 'integer'],
- ];
- }
- /**
- * @return bool
- */
- public function outRemit()
- {
- if (Yii::$app->getUser()->getIsGuest()) {
- Yii::$app->getUser()->loginRequired();
- return false;
- }
- if ($this->validate()) {
- $data = [];
- $data['remitNo'] = trim($this->remitNo);
- $data['notifyUrl'] = Url::to(["/remit/notify/" . Yii::$app->getSecurity()->maskToken(trim($this->remitNo))], true);
- $data['adminId'] = Yii::$app->getUser()->getId();
- $data['adminName'] = Yii::$app->getUser()->getIdentity(false)->name;
- $data['adminIp'] = Utils::getClientIp();
-
- $api = new RemitApi();
- $result = $api->outRemit($data);
- if ($result['code'] == 1) {
- $this->_outRemitResult = $result['data'];
- } else {
- if (is_array($result['message'])) {
- $this->addErrors($result['message']);
- } else {
- $this->addError('remitNo', $result['message']);
- }
- }
- }
- return !$this->hasErrors();
- }
- /**
- * @return string
- */
- public function getOutRemitResult()
- {
- return $this->_outRemitResult;
- }
- }
|