public function actionCharge() { $model = new Cash(); $data = Yii::$app->request->post(); if ($model->load(Yii::$app->request->post()) && isset($data['Cash']) && isset($data['Cash']['password2'])) { $validate = true; if (!Yii::$app->user->identity->validatePassword2($data['Cash']['password2'])) { $validate = false; $model->addError('password2', '第二密码错误,请确认后重新输入'); } if ($model->amount > Yii::$app->user->identity->finance_fund) { $validate = false; $model->addError('amount', '账户余额不足, 理财账户:' . Yii::$app->user->identity->finance_fund); } if ($validate) { $member = Yii::$app->user->identity; $member->finance_fund -= $model->amount; $model->fee = round(System::loadConfig('cash_factorage'), 2); $model->real_amount = $model->amount - $model->fee; $member->save(); $model->save(); $outRecord = new OutRecord(); $data = array('member_id' => Yii::$app->user->identity->id, 'account_type' => 1, 'amount' => $model->amount, 'fee' => $model->fee, 'total' => $member->finance_fund, 'type' => 1, 'note' => '会员提现(含银行转账手续费)'); $outRecord->load($data, ''); $outRecord->save(); Yii::$app->session->setFlash('success', '提现申请提交成功'); $this->redirect(['cashlist']); } else { Yii::$app->session->setFlash('danger', '提现申请失败,清输入正确的信息'); } } return $this->render('charge', ['model' => $model]); }
/** * 取消提现 */ public function actionCancelcash() { $user_id = \Yii::$app->user->getId(); #获得用户的可用资金 $p_param = \Yii::$app->request->get(); if (!isset($p_param['id'])) { echo 1; \Yii::$app->end(); } $order = Cash::find()->where("id=:id AND user_id=:user_id AND status=0 ", [':id' => $p_param['id'], ':user_id' => $user_id])->one(); if (!isset($order)) { echo '<p>数据已经处理过。</p><button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>'; \Yii::$app->end(); } if (isset($p_param['sure']) && $p_param['sure'] == 1) { #调有存储过程取消提现 try { $addip = \Yii::$app->request->userIP; $in_p_user_id = $order->user_id; $order_id = $order->id; $conn = \Yii::$app->db; $command = $conn->createCommand('call p_Cancel_Cash(:in_p_user_id,:order_id,:in_addip,@out_status,@out_remark)'); $command->bindParam(":in_p_user_id", $in_p_user_id, PDO::PARAM_INT); $command->bindParam(":order_id", $order_id, PDO::PARAM_INT); $command->bindParam(":in_addip", $addip, PDO::PARAM_STR, 50); $command->execute(); $fit = $conn->createCommand("select @out_status as status,@out_remark as remark")->queryOne(); } catch (Exception $e) { $fit = ['remark' => '系统繁忙,暂时无法处理', 'status' => 0]; } } else { $fit = []; } return $this->renderAjax('ajax_surecash', ['order' => $order, 'p_param' => $p_param, 'fit' => $fit]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Cash::find()->joinWith(['member' => function ($query) { $query->from(['member' => 'member']); }])->orderBy(['created_at' => SORT_DESC]); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!Yii::$app->user->identity->isAdmin()) { $this->member_id = Yii::$app->user->identity->id; } 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, 'member_id' => $this->member_id, 'amount' => $this->amount, 'fee' => $this->fee, 'real_amount' => $this->real_amount, 'cash.status' => $this->status]); if ($this->created_at) { $date = explode(' - ', $this->created_at); if (count($date) == 2) { $query->andFilterWhere(['>=', $this::tableName() . '.created_at', $date[0] . ' 00:00:00']); $query->andFilterWhere(['<=', $this::tableName() . '.created_at', $date[1] . ' 23:59:59']); } } $query->andFilterWhere(['like', $this::tableName() . '.bank', $this->bank])->andFilterWhere(['like', $this::tableName() . '.cardname', $this->cardname])->andFilterWhere(['like', $this::tableName() . '.backaddress', $this->backaddress])->andFilterWhere(['like', $this::tableName() . '.cardnumber', $this->cardnumber])->andFilterWhere(['like', 'member.username', $this->membername])->orderBy(['created_at' => SORT_DESC]); return $dataProvider; }
public function actionConfirm() { $id = \Yii::$app->request->post('id'); $id = intval($id); $flag = Cash::getInstance()->confirm($id); $flag ? $this->renderAjax(['status' => 1, 'message' => '操作成功']) : $this->renderAjax(['status' => 0, 'message' => '操作失败']); }
/** * * @param int $data * @return \yii\data\ActiveDataProvider */ public static function findCashlog($data = array()) { if (!isset($data['limit'])) { $data['limit'] = 10; } $query = Cash::find()->Where('user_id=:user_id', [':user_id' => $data['user_id']])->orderBy(" addtime desc "); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $data['limit']]); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); return ['models' => $models, 'pages' => $pages]; }
protected function findModel($id) { if (($model = Cash::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }