Beispiel #1
0
 public function actionUncollect($id)
 {
     $model = $this->findModel($id);
     $smember = SinaMember::find()->andWhere(['uid' => $model->member_id])->one();
     if ($smember && $smember->status == 1) {
         //$sina = new sina();
         // $model->sinamoney = $sina->query_balance('1440052548HQW131102199007042019');
     } else {
         \Yii::$app->getSession()->setFlash('warning', '该用户没用绑定新浪账户');
         return $this->redirect(['index']);
     }
     if (\App::$app->request->post()) {
         //事物回滚
         $transaction = \App::$app->db->beginTransaction();
         try {
             $model->balance -= \App::$app->request->post()['Info']['fabalance'];
             if ($model->balance < 1) {
                 throw new ErrorException('提取金额大于用户余额', 1);
             }
             if (!$model->save()) {
                 throw new ErrorException('用户金钱存储数据失败', 1);
             }
             $return = sinapay::collectUser($model->member_id, \App::$app->request->post()['Info']['fabalance']);
             if ($return['errorNum'] == 1) {
                 throw new ErrorException($return['errorMsg'], 1);
             }
             $transaction->commit();
         } catch (ErrorException $e) {
             $transaction->rollBack();
             \Yii::$app->getSession()->setFlash('warning', $e->getMessage());
             $newmodel = $this->findModel($id);
             return $this->render('uncollect', ['model' => $newmodel]);
         }
         return $this->redirect(['index']);
     } else {
         return $this->render('uncollect', ['model' => $model]);
     }
 }