Ejemplo n.º 1
0
 public function actionIndex()
 {
     if (Date::isWorkingDay()) {
         $limit = (int) System::loadConfig('transaction_rule');
         if ($limit) {
             $limit = $limit - 1;
         } else {
             $limit = 0;
         }
         if ($limit == 0) {
             $date = date('Y-m-d');
         } else {
             $dates = Date::find()->where(['<', 'date', new Expression('curdate()')])->andWhere(['=', 'status', 0])->orderBy(['date' => SORT_DESC])->limit(2)->all();
             $date = array_pop($dates);
             $date = $date->date;
         }
         $date .= ' 23:59:59';
         $transactions = StackTransaction::find()->where(['=', 'status', 0])->andWhere(['<', 'created_at', $date])->all();
         foreach ($transactions as $transaction) {
             if ($transaction->type == 0) {
                 $this->dealBuyAction($transaction);
             } else {
                 $this->dealSellAction($transaction);
             }
         }
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
 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();
         }
     }
 }
Ejemplo n.º 3
0
 public function actionSell($id)
 {
     $stack = Stack::findOne($id);
     $model = new StackTransaction();
     $memberStack = Yii::$app->user->identity->getMemberStack($stack->id);
     if ($model->load(Yii::$app->request->post())) {
         if (Date::isWorkingDay()) {
             if (Date::isWorkingTime()) {
                 if ($model->account_type) {
                     $data = Yii::$app->request->post();
                     $validate = true;
                     if (!Yii::$app->user->identity->validatePassword2($data['StackTransaction']['password2'])) {
                         $validate = false;
                         $model->addError('password2', '第二密码不正确, 请确认后重新输入.');
                     }
                     if (!$model->checkSellVolume($memberStack, $model->volume)) {
                         $validate = false;
                     }
                     if ($validate) {
                         $model->price = $stack->price;
                         $model->member_id = Yii::$app->user->identity->id;
                         $model->stack_id = $stack->id;
                         $model->type = 1;
                         $model->total_price = $stack->price * $model->volume;
                         $memberStack->sell_volume -= $model->volume;
                         $memberStack->lock_volume += $model->volume;
                         $connection = Yii::$app->db;
                         try {
                             $transaction = $connection->beginTransaction();
                             if ($model->save() && $memberStack->save()) {
                                 $transaction->commit();
                                 return $this->redirect(['transactions']);
                             } else {
                                 Yii::error('Sell Stack Failed');
                                 Yii::error(json_encode($model->getErrors()));
                                 Yii::error(json_encode($memberStack->getErrors()));
                                 $transaction->rollback();
                             }
                         } catch (Exception $e) {
                         }
                     }
                 } else {
                     $model->total_price = $stack->price * $model->volume;
                 }
             } else {
                 Yii::$app->session->setFlash('danger', '非交易时间. 早上10:00 ~ 12:30. 下午2:00 ~ 4:00');
             }
         } else {
             Yii::$app->session->setFlash('danger', '对不起,非交易日不能进行交易!');
         }
     }
     return $this->render('sell', ['model' => $model, 'stack' => $stack, 'memberStack' => $memberStack]);
 }