Exemplo n.º 1
0
 /**
  * Get All notifications of a user.
  *
  * @author Kuldeep Dangi <*****@*****.**>
  */
 public function actionAdd($userId, $amount, $curr)
 {
     $nCash = new Ncash();
     $nCash->addAmount($userId, $amount, $curr);
     $this->result['success'] = true;
     $this->sendResponse($this->result);
 }
Exemplo n.º 2
0
 /**
  * Upload a new document.
  *
  * @author Kuldeep Dangi <*****@*****.**>
  */
 public function actionUpload()
 {
     //name,category_id,images,description,price,userid,
     $model = new Extensions();
     if (!empty($_POST['user_id'])) {
         $userModel = Users::model()->findByPk($_POST['user_id']);
         if ($userModel) {
             $model->attributes = $_POST;
             $uploadedFiles = CUploadedFile::getInstancesByName('images');
             if ($uploadedFiles && count($uploadedFiles) > 0) {
                 $allUploadedFiles = array();
                 foreach ($uploadedFiles as $uploadedFile) {
                     $fileName = strtotime($this->getCurrentDateTime()) . '-' . $uploadedFile;
                     $uploadedFile->saveAs(Yii::app()->basePath . '/../../' . Extensions::FILE_UPLOAD_PATH . $fileName);
                     $allUploadedFiles[] = $fileName;
                 }
                 $savedFileNames = $model->getPdfFromImages($allUploadedFiles);
                 $model->pdf = Extensions::FILE_CONVERT_PATH . $savedFileNames['pdf'];
                 $model->imagepdf = $savedFileNames['imagepdf'];
                 $model->image = Extensions::FILE_IMAGE_PATH . $savedFileNames['image'];
                 if ($model->save()) {
                     //Update Reward points
                     //                        $userModel->rewardpoints = $userModel->rewardpoints +
                     //                                self::REWARD_ON_NOTE_UPLOAD;
                     //                        $userModel->save();
                     $nCash = new Ncash();
                     $nCash->addAmount($userObj->user_id, self::REWARD_ON_NOTE_UPLOAD, 2);
                     $notficationModel = new Notifications();
                     $notficationModel->sendPushNotification(array('deviceToken' => $userModel->deviceToken, 'deviceType' => $userModel->deviceType, 'message' => 2));
                     $this->result['success'] = true;
                 } else {
                     $this->result['message'] = 'Record save failed.';
                 }
             } else {
                 $this->result['message'] = 'No images to save';
             }
         } else {
             $this->result['message'] = 'User does not exist.';
         }
     } else {
         $this->result['message'] = 'Invalid user id.';
     }
     $this->sendResponse($this->result);
 }
Exemplo n.º 3
0
 /**
  * Handle webhook request from instamojo
  *
  * @author Kuldeep Dangi <*****@*****.**>
  */
 public function actionCheckoutApp($userId)
 {
     $cartModel = new Cartdetails();
     $userModel = new Users();
     $userByExtentionId = new UsersBuyExtensions();
     $userObj = Users::model()->findByPk($userId);
     $cartData = $cartModel->getUserCartProductIds($userId);
     $settingsModel = Setting::model()->findByPk(1);
     if (!$userObj || count($cartData) < 1) {
         exit;
     }
     $notficationModel = new Notifications();
     $notficationModel->sendPushNotification(array('deviceToken' => $userObj->deviceToken, 'deviceType' => $userObj->deviceType, 'message' => 3));
     foreach ($cartData as $cartRow) {
         $orderModel = new Order();
         $model = Cartdetails::model()->findByPk($cartRow['id']);
         $extentionObj = Extensions::model()->findByPk($model->productid);
         $nCashAmount = $model->price - $model->price * $settingsModel->commission / 100;
         $data = array("user_id" => $userObj->user_id, "coupondata" => '', "uservalrewdata" => '', "userval" => '', "extension_id" => $model->productid, "rewardpoints" => '', "extension_name" => $extentionObj->name, "extension_price" => $model->price, "quantity" => 1, "total_price" => $model->price, "shipping_fee" => '', "transaction_paypal_id" => $_POST['payment_id'], "commission" => $settingsModel->commission, "total_balance" => $nCashAmount, "created_date" => time(), 'added_date' => $this->getCurrentDateTime(), "status" => 1, "payment_type" => 1, "address_id" => 0);
         $orderModel->attributes = $data;
         if ($orderModel->save()) {
             $userModel = Users::model()->findByPk($extentionObj->user_id);
             $nCash = new Ncash();
             // Ncash deducted from buyer account
             $nCash->deductAmount($userObj->user_id, $model->price);
             // Ncash awarded to buyer
             $nCash->addAmount($userObj->user_id, self::REWARD_ON_NOTE_PURCHASE, 2);
             // Ncash for seller
             $nCash->addAmount($userModel->user_id, $nCashAmount, 5);
             if ($userModel) {
                 $notficationModel->sendPushNotification(array('deviceToken' => $userModel->deviceToken, 'deviceType' => $userModel->deviceType, 'message' => 4));
             }
             $model->used = 1;
             $model->save();
             //increment extention download
             // email notification
             $userBuyExtentionObj = $userByExtentionId->findByAttributes(array('user_id' => $userObj->user_id, 'extension_id' => $model->productid));
             if ($userBuyExtentionObj) {
                 $userBuyExtentionObj->download = $userBuyExtentionObj->download + $settingsModel->download_times;
                 if ($userBuyExtentionObj->expire_time > time()) {
                     $userBuyExtentionObj->expire_time = $userBuyExtentionObj->expire_time + $settingsModel->download_expire;
                 } else {
                     $userBuyExtentionObj->expire_time = time() + $settingsModel->download_expire;
                 }
                 $userBuyExtentionObj->save();
             } else {
                 $userByExtentionId->attributes = array('user_id' => $userObj->user_id, 'extension_id' => $model->productid, 'download' => $settingsModel->download_times, 'expire_time' => time() + $settingsModel->download_expire);
                 $userByExtentionId->save();
             }
         }
         $this->result['success'] = true;
     }
     $this->sendResponse($this->result);
 }
Exemplo n.º 4
0
 /**
  * Authenticate user logging in
  *
  * @author Kuldeep Dangi <*****@*****.**>
  */
 public function actionLogin()
 {
     if (isset($_GET['username'])) {
         $model = new LoginForm();
         $userModel = new Users();
         $nCashModel = new Ncash();
         //$userFollowObj = new UserFollow();
         $model->attributes = $_GET;
         if ($model->validate() && $model->login()) {
             $userModel = $this->loadModel(Yii::app()->user->user_id);
             if (!empty($_GET['deviceType']) && !empty($_GET['deviceToken'])) {
                 if (empty($userModel->deviceToken)) {
                     $nCashModel->addAmount(Yii::app()->user->user_id, self::NCASH_AMOUNT_APP_LOGIN, 6);
                 }
                 $userModel->deviceType = $_GET['deviceType'];
                 $userModel->deviceToken = $_GET['deviceToken'];
                 $userModel->save();
             }
             $this->result['success'] = true;
             $this->result['message'] = 'User logged in successfully.';
             $this->result['data'] = $userModel;
             //                  $this->result['data']['profile'] = $userModel;
             //                  $this->result['data']['followers'] =
             //                  $userFollowObj->getUserFollowers($userModel->user_id);
         } else {
             $this->result['message'] = $model->getError('password');
         }
     }
     $this->sendResponse($this->result);
 }