Beispiel #1
0
 public function __construct($ebayID = null)
 {
     if ($ebayID !== null && ($ebayAcc = EbayAccount::findOne(['id' => $ebayID, 'user_id' => Yii::$app->user->id]))) {
         $this->token = $ebayAcc->token;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
         $this->token = null;
     }
     //$this->tokens = [];
     // $this->ebayID = $ebayID;
     // if($this->ebayID == null){//所有ebay
     // 	$ebayAccArray = EbayAccount::find()->allOfCurrentUser($db = null);
     //
     // 	foreach ($ebayAccArray as $ebayAccModel) {
     // 		$this->tokens[$ebayAccModel->seller_id] = $ebayAccModel->token;
     // 	}
     // }else{//一个ebay
     // 	$ebayAcc = EbayAccount::findOne(['id'=>$this->ebayID,'user_id'=>Yii::$app->user->id]);
     // 	$this->tokens=$ebayAcc->token;
     // }
     //$this->tokens='1';
 }
Beispiel #2
0
 protected function findModel($id)
 {
     $ebayAccount = EbayAccount::findOne($id);
     if (Yii::$app->user->can('ebaycontrol', ['userID' => $ebayAccount->user_id])) {
         if (($model = OrderLog::findOne($id)) !== null) {
             return $model;
         } else {
             return null;
         }
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #3
0
 public function actionPreviewDesc($id, $ebayID)
 {
     $product = $this->findModel($id);
     $ebayAcc = EbayAccount::findOne($ebayID);
     $lstImages = ListingImages::findOne(['product_id' => $id, 'ebay_account_id' => $ebayID]);
     $listingImages = ['http://i.imgur.com/roXpiR8.png'];
     if ($lstImages) {
         $listingImages = json_decode($lstImages->image_url);
     }
     return $this->renderFile(Yii::$app->params['listingTemplatePath'] . $ebayAcc->listingTemplate->name . '.php', ['ebayAcc' => $ebayAcc, 'product' => $product, 'lstImages' => $listingImages]);
 }
Beispiel #4
0
 public function actionReviseOneItem()
 {
     if (Yii::$app->request->isAjax) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $post = Yii::$app->request->post();
         $ebayListing = new EbayListing($post['ebayID']);
         $listing = Listing::find()->where(['item_id' => $post['itemID']])->one();
         if ($listing == null) {
             return false;
         }
         $listingItem = new ApiListingItem();
         $listingItem->item_id = $listing->item_id;
         $listingItem->title = $post['title'];
         $listingItem->qty = $post['qty'];
         $listingItem->price = $post['price'];
         $listingItem->shippingCost = $post['shipping'];
         $listingItem->shippingExpressCost = $post['expressShipping'];
         $product = Product::findOne(['sku' => $listing->sku]);
         $ebayAccount = EbayAccount::findOne($post['ebayID']);
         $lstImages = ListingImages::findOne(['product_id' => $product->id, 'ebay_account_id' => $post['ebayID']]);
         $listingImages = ['http://i.imgur.com/roXpiR8.png'];
         if ($lstImages) {
             $listingImages = json_decode($lstImages->image_url);
         }
         $listingItem->description = $this->renderFile(Yii::$app->params['listingTemplatePath'] . $ebayAccount->listingTemplate->name . '.php', ['ebayAcc' => $ebayAccount, 'product' => $product, 'lstImages' => $listingImages]);
         $result = $ebayListing->reviseItem($listingItem);
         if (isset($result['itemID']) && !isset($result['error'])) {
             $result['status'] = 'success';
             $result['message'] = "Item: " . $result['itemID'] . " revised";
         } else {
             $result['status'] = 'failed';
             $result['message'] = "Item: " . $result['itemID'] . " NOT revised";
         }
         return $result;
     } else {
         return false;
     }
 }
Beispiel #5
0
 /**
  * 拿到ebay token,存到数据库
  * @return [type] [description]
  */
 public function actionGetToken($id)
 {
     $session = Yii::$app->session;
     if (!$session->isActive) {
         $session->open();
     }
     $theID = $session->get('ebSession');
     $ebayAcc = EbayAccount::findOne($id);
     $ebayApi = new EbayApi();
     if ($theID === null) {
         $sesId = $ebayApi->getSessionID();
         if ($sesId != false) {
             $session->set('ebSession', $sesId['sesId']);
             return $this->redirect($sesId['loginURL'] . urlencode($sesId['sesId']));
         } else {
             throw new NotFoundHttpException('fail to get ebay session ID');
         }
     } else {
         $token = $ebayApi->getToken($theID);
         if ($token == false) {
             throw new NotFoundHttpException('fail to get ebay token');
         } else {
             $ebayAcc->token = $token['0'];
             $ebayAcc->token_expiration = strtotime($token['1']);
             $ebayAcc->save();
             return $this->render('view', ['model' => $ebayAcc]);
         }
     }
 }