/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = FundTransaction::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;
     }
     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->cleared_at) {
         $date = explode(' - ', $this->cleared_at);
         if (count($date) == 2) {
             $query->andFilterWhere(['>=', $this::tableName() . '.cleared_at', $date[0] . ' 00:00:00']);
             $query->andFilterWhere(['<=', $this::tableName() . '.cleared_at', $date[1] . ' 23:59:59']);
         }
     }
     $query->andFilterWhere(['id' => $this->id, 'fund_id' => $this->fund_id, 'member_id' => $this->member_id, 'investment' => $this->investment, 'revenue' => $this->revenue, 'fund_transaction.locked' => $this->locked, 'cleared' => $this->cleared])->andFilterWhere(['like', 'member.username', $this->membername])->orderBy(['created_at' => SORT_DESC]);
     return $dataProvider;
 }
示例#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();
         }
     }
 }
示例#3
0
 protected function findTransaction($id)
 {
     if (($model = FundTransaction::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFundTransactions()
 {
     return $this->hasMany(FundTransaction::className(), ['fund_id' => 'id']);
 }