Exemple #1
0
 public static function prepareModelForSellStack($member_id, $amount, $total, $fee)
 {
     $data = array('member_id' => $member_id, 'type' => 2, 'fee' => $fee, 'amount' => $amount, 'total' => $total, 'account_type' => 1, 'note' => '出售股票');
     $model = new InRecord();
     $model->load($data, '');
     return $model;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = InRecord::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, 'account_type' => $this->account_type, 'type' => $this->type, 'amount' => $this->amount, 'fee' => $this->fee, 'total' => $this->total]);
     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', 'note', $this->note])->andFilterWhere(['like', 'member.username', $this->membername])->orderBy(['created_at' => SORT_DESC]);
     return $dataProvider;
 }
 public function actionIndex()
 {
     if (Date::isWorkingDay()) {
         $transactions = FundTransaction::find()->where(['=', 'locked', 1])->andWhere(['=', 'cleared', 0])->all();
         foreach ($transactions as $transaction) {
             $amount = $transaction->investment * $transaction->fund->daily;
             $transaction->revenue += $amount;
             $member = $transaction->member;
             $member->finance_fund += $amount;
             $inRecord = new InRecord();
             $data = array('member_id' => $transaction->member_id, 'type' => 5, 'fee' => 0, 'amount' => $amount, 'total' => $member->finance_fund, 'account_type' => 1, 'note' => '基金分红: (' . date('Y-m-d', time()) . ')');
             $inRecord->load($data, '');
             $inRecord->save();
             $member->save();
             $transaction->save();
         }
     }
 }
 protected function dealSellAction($transaction)
 {
     $transaction->status = 1;
     $memberStack = $transaction->getMemberStack()->one();
     $memberStack->lock_volume -= $transaction->volume;
     $member = $transaction->getMember()->one();
     $fee = round($transaction->total_price * System::loadConfig('sell_fee_rate'), 2);
     $member->finance_fund += $transaction->total_price - $fee;
     $stackOutRecord = InRecord::prepareModelForSellStack($transaction->member_id, $transaction->total_price - $fee, $member->finance_fund, $fee);
     $stackOutRecord->note = '系统解锁[' . $transaction->created_at . ']出售[' . $transaction->stack->code . ']' . $transaction->volume . '股';
     $stackOutRecord->save();
     $member->save();
     $memberStack->save();
     $transaction->save();
 }
 public function actionReject($id)
 {
     $model = $this->findModel($id);
     $connection = Yii::$app->db;
     try {
         $transaction = $connection->beginTransaction();
         $model->status = 3;
         $user = Member::findOne($model->member_id);
         $user->finance_fund += $model->amount;
         $data = array('member_id' => $model->member_id, 'account_type' => 1, 'amount' => $model->amount, 'fee' => 0, 'total' => $user->finance_fund, 'type' => 4, 'note' => '拒绝提现,货币返还.');
         $model->note .= '拒绝提现,货币返还.';
         Yii::$app->session->setFlash('success', '提现申请拒绝成功');
         $revenue = new InRecord();
         $revenue->load($data, '');
         $revenue->save();
         $user->save();
         $model->save();
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollback();
         //回滚函数
         return $this->render('create', ['model' => $model]);
     }
     return $this->redirect(['cashlist', 'id' => $model->id]);
 }
 public function actionClear($id)
 {
     $model = $this->findTransaction($id);
     $model->cleared = 1;
     $model->cleared_at = date('Y-m-d H:i:s');
     $connection = Yii::$app->db;
     try {
         $member = $model->member;
         $member->finance_fund += $model->investment;
         $inRecord = InRecord::prepareModelForSellStack($model->member_id, $model->investment, $member->finance_fund, 0);
         $inRecord->note = '基金[' . $model->fund->name . ']清仓';
         $inRecord->type = 5;
         $transaction = $connection->beginTransaction();
         if ($model->save() && $inRecord->save() && $member->save()) {
             $transaction->commit();
             return $this->redirect(['history']);
         } else {
             Yii::error('Fund Clear Failed');
             Yii::error(json_encode($model->getErrors()));
             Yii::error(json_encode($inRecord->getErrors()));
             Yii::error(json_encode($member->getErrors()));
             $transaction->rollback();
         }
     } catch (Exception $e) {
     }
     return $this->redirect(['history']);
 }
 public function actionUnlock()
 {
     $id = Yii::$app->request->get('id');
     $stackTransaction = StackTransaction::findOne($id);
     $connection = Yii::$app->db;
     try {
         $transaction = $connection->beginTransaction();
         if ($stackTransaction->type == 0) {
             $stackTransaction->status = 1;
             $memberStack = $stackTransaction->getMemberStack()->one();
             $memberStack->sell_volume += $stackTransaction->volume;
             $memberStack->lock_volume -= $stackTransaction->volume;
             if ($memberStack->save() && $stackTransaction->save()) {
                 $transaction->commit();
                 Yii::$app->session->setFlash('success', '交易自主解锁成功');
             } else {
                 $transaction->rollBack();
                 Yii::$app->session->setFlash('danger', '交易自主解锁失败, 请稍后再试或联系管理员');
             }
         } else {
             $stackTransaction->status = 1;
             $memberStack = $stackTransaction->getMemberStack()->one();
             $memberStack->lock_volume -= $stackTransaction->volume;
             $member = $stackTransaction->getMember()->one();
             $fee = round($stackTransaction->total_price * System::loadConfig('sell_fee_rate'), 2);
             $member->stack_fund += $stackTransaction->total_price - $fee;
             $stackOutRecord = InRecord::prepareModelForSellStack($stackTransaction->member_id, $stackTransaction->total_price - $fee, $member->stack_fund, $fee);
             $stackOutRecord->account_type = 2;
             $stackOutRecord->note = '自主解锁[' . $stackTransaction->created_at . ']出售股票[' . $stackTransaction->stack->code . ']' . $stackTransaction->volume . '股';
             if ($memberStack->save() && $stackTransaction->save() && $member->save() && $stackOutRecord->save()) {
                 $transaction->commit();
                 Yii::$app->session->setFlash('success', '交易自主解锁成功');
             } else {
                 $transaction->rollBack();
                 Yii::$app->session->setFlash('danger', '交易自主解锁失败, 请稍后再试或联系管理员');
             }
         }
     } catch (Exception $e) {
         $transaction->rollBack();
     }
     $this->redirect(Yii::$app->request->referrer);
     return;
 }