示例#1
0
 public function actionCollect($id)
 {
     $model = $this->findModel($id);
     $smember = SinaMember::find()->andWhere(['uid' => $model->member_id, 'status' => SinaMember::STATUS_BINGING])->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->save()) {
                 throw new ErrorException('用户金钱存储失败', 1);
             }
             $pay_uid = array($model->member_id => \App::$app->request->post()['Info']['fabalance']);
             $return = sinapay::collectSite(\App::$app->request->post()['Info']['fabalance'], $pay_uid);
             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('collect', ['model' => $newmodel]);
         }
         return $this->redirect(['index']);
     } else {
         return $this->render('collect', ['model' => $model]);
     }
 }