/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = SinaFreeze::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'uid' => $this->uid, 'freeze_money' => $this->freeze_money, 'status' => $this->status, 'unfreeze_money' => $this->unfreeze_money, 'create_at' => $this->create_at, 'update_at' => $this->update_at]); $query->andFilterWhere(['like', 'identity_id', $this->identity_id])->andFilterWhere(['like', 'account_type', $this->account_type])->andFilterWhere(['like', 'out_freeze_no', $this->out_freeze_no])->andFilterWhere(['like', 'freeze_summary', $this->freeze_summary])->andFilterWhere(['like', 'msg', $this->msg])->andFilterWhere(['like', 'out_unfreeze_no', $this->out_unfreeze_no])->andFilterWhere(['like', 'unfreeze_summary', $this->unfreeze_summary]); return $dataProvider; }
<?php use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel common\models\sinapay\SinaFreezeSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', '新浪冻结解冻记录'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="sina-freeze-index"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'uid', 'identity_id', 'account_type', 'out_freeze_no', 'freeze_money', 'freeze_summary', ['attribute' => 'status', 'format' => 'html', 'headerOptions' => ['width' => '100'], 'value' => function ($model) { if ($model->status === 2) { $class = 'label-success'; } elseif ($model->status === 1) { $class = 'label-success'; } else { $class = 'label-danger'; } return '<span class="label ' . $class . '">' . $model->statusLabel . '</span>'; }, 'filter' => Html::activeDropDownList($searchModel, 'status', \common\models\sinapay\SinaFreeze::labels(), ['class' => 'form-control', 'prompt' => '请筛选'])], 'msg', 'unfreeze_money', 'unfreeze_summary', ['attribute' => 'create_at', 'format' => ['date', 'php:Y-m-d H:i:s'], 'headerOptions' => ['width' => '100']], ['class' => 'yii\\grid\\ActionColumn', 'header' => '操作', 'template' => '{unlock}', 'buttons' => ['unlock' => function ($url, $model, $key) { return $model->status == \common\models\sinapay\SinaFreeze::STATUS_FREEZE ? Html::a('<span class="glyphicon glyphicon-list-alt"></span>', $url, ['title' => '解冻资金']) : ""; }], 'headerOptions' => ['width' => '80']]]]); ?> </div>
/** * 解冻资金 * @param $out_freeze_no 需要解冻的当单号 * @param $money 解冻金额 * @param $summary 解冻原因 * @return array */ public static function balanceUnfreeze($out_freeze_no, $money, $summary) { $flag = SinaFreeze::findOne(['out_freeze_no' => $out_freeze_no, 'status' => SinaFreeze::STATUS_FREEZE]); if (!$flag) { $return = array('errorNum' => '1', 'errorMsg' => '解冻订单信息错误', 'data' => null); return $return; } $identity_id = $flag->identity_id; $freeze_money = $flag->freeze_money; if ($freeze_money < $money) { $return = array('errorNum' => '1', 'errorMsg' => '解冻金额不能大于冻结金额', 'data' => null); return $return; } $sina = new sina(); $out_unfreeze_no = self::build_order_no(); $unfreeze = $sina->balance_unfreeze($out_unfreeze_no, $out_freeze_no, $identity_id, $money, $summary); if ($unfreeze['response_code'] == 'APPLY_SUCCESS') { $unfreeze_money = $flag->unfreeze_money; $flag->unfreeze_money = $unfreeze_money + $money; $flag->status = SinaFreeze::STATUS_UNFREEZE; $flag->msg = '解冻成功'; $flag->save(); $return = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => null); return $return; } else { $unfreeze_money = $flag->unfreeze_money; $flag->unfreeze_money = $unfreeze_money + $money; $flag->status = SinaFreeze::STATUS_ERROR; $flag->msg = '解冻失败'; $flag->save(); $return = array('errorNum' => '1', 'errorMsg' => $unfreeze['response_message'], 'data' => null); return $return; } }
/** * Finds the SinaFreeze model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return SinaFreeze the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = SinaFreeze::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }