コード例 #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;
     }
 }
コード例 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = StackTransaction::find()->joinWith(['stack' => function ($query) {
         $query->from(['stack' => 'stack']);
     }])->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;
     }
     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']);
         }
     }
     if ($this->updated_at) {
         $date = explode(' - ', $this->updated_at);
         if (count($date) == 2) {
             $query->andFilterWhere(['>=', $this::tableName() . '.updated_at', $date[0] . ' 00:00:00']);
             $query->andFilterWhere(['<=', $this::tableName() . '.updated_at', $date[1] . ' 23:59:59']);
         }
     }
     $query->andFilterWhere(['id' => $this->id, 'stack_id' => $this->stack_id, 'member_id' => $this->member_id, 'volume' => $this->volume, 'type' => $this->type, 'total_price' => $this->total_price, 'stack_transaction.status' => $this->status, 'total' => $this->total])->andFilterWhere(['like', 'stack.code', $this->stackcode])->andFilterWhere(['like', 'stack.name', $this->stackname])->andFilterWhere(['like', 'member.username', $this->membername])->orderBy(['created_at' => SORT_DESC]);
     return $dataProvider;
 }