Beispiel #1
0
 /**
  * Displays profile homepage.
  *
  * @return mixed
  */
 public function actionIndex($code = null)
 {
     $codes = Yii::$app->user->identity->availableCodes;
     $allCodes = array_merge($codes, Yii::$app->user->identity->availableGroupCodes);
     $campaigns = CodeBankCampaign::find()->where(['codeBank_code' => $allCodes])->all();
     $model = CodeBank::find()->where(['code' => $codes])->all();
     return $this->render('index', ['model' => $model, 'roleOptions' => $this->roleOptions, 'allCodes' => $allCodes, 'selectedCode' => $code, 'campaigns' => $campaigns]);
 }
 /**
  * @param $duration
  * @param $orderProductId
  *
  * This function required order_product to be succefully created
  */
 private function createCodeBank($duration, $orderProductId, $maxCallOut, $minBalance)
 {
     $cb = new CodeBank();
     $cb->code = self::GenerateCode();
     $cb->expiredBy = self::GenerateExpiredBy($duration);
     $cb->maxCallOut = $maxCallOut;
     $cb->minBalance = $minBalance;
     $cb->order_product_id = $orderProductId;
     $cb->save();
     // Create record for code_member
     $codeMember = new CodeMember();
     $codeMember->loadDefaultValues();
     $codeMember->auth_item_name = 'admin';
     $codeMember->user_id = Yii::$app->user->identity->id;
     $codeMember->link('codeBank', $cb);
     if (Yii::$app->authManager->getAssignment('admin', Yii::$app->user->identity->id) == null) {
         $adminRole = Yii::$app->authManager->getRole('admin');
         Yii::$app->authManager->assign($adminRole, Yii::$app->user->identity->id);
     }
     return true;
 }
Beispiel #3
0
 public function actionUpdateTopup()
 {
     $result = \Yii::$app->request->post();
     foreach ($result as $key => $value) {
         Yii::$app->db->createCommand('Update toppupBank set code=:code , used=1 where order_product_id=:key')->bindValue(':code', $value)->bindValue(':key', $key)->execute();
         $codeBank = CodeBank::find()->where(['code' => $value])->one();
         // Get Topup id
         $orderProduct = OrderProduct::findOne($key);
         // Get topup maxCallOut
         $tp = Topup::findOne($orderProduct->objectId);
         $codeBank->updateCounters(['maxCallout' => $tp->maxCallOut]);
     }
     return 1;
 }
Beispiel #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCodeBank()
 {
     return $this->hasOne(CodeBank::className(), ['code' => 'codeBank_code']);
 }
Beispiel #5
0
 public function getCodes()
 {
     return $this->hasOne(CodeBank::className(), ['order_product_id' => 'id']);
     //        return $this->hasOne(CodeBank::className(),['order_product_id'=>'id']);
 }