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;
     }
 }
Beispiel #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Date::find()->orderBy(['date' => SORT_DESC]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     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;
     }
     if ($this->date) {
         $date = explode(' - ', $this->date);
         if (count($date) == 2) {
             $query->andFilterWhere(['>=', $this::tableName() . '.date', $date[0]]);
             $query->andFilterWhere(['<=', $this::tableName() . '.date', $date[1]]);
         }
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at])->orderBy(['date' => SORT_DESC]);
     return $dataProvider;
 }
 /**
  * Creates a new Date model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Date();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->start_date < $model->end_date) {
             $realDate = $model->start_date;
             do {
                 $date = Date::find()->where(['=', 'date', $realDate])->one();
                 if (!$date) {
                     $date = new Date();
                     $date->date = $realDate;
                     $date->save();
                 }
                 $realDate = date('Y-m-d', strtotime($realDate . ' +1 day'));
             } while ($realDate <= $model->end_date);
         } else {
             $model->addError('end_date', 'End Date Must bigger than Start Date');
         }
     }
     return $this->redirect(['index']);
 }
Beispiel #4
0
 public static function isWorkingDay()
 {
     $data = Date::find()->where(['=', 'date', new Expression('curdate()')])->one();
     return $data && $data->status == 0 ? true : false;
 }