コード例 #1
0
ファイル: EbayAccountSearch.php プロジェクト: sea129/kbay
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = EbayAccount::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     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;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'listing_template_id' => $this->listing_template_id, 'token_expiration' => $this->token_expiration]);
     $query->andFilterWhere(['like', 'seller_id', $this->seller_id])->andFilterWhere(['like', 'store_id', $this->store_id])->andFilterWhere(['like', 'shipping_info', $this->shipping_info])->andFilterWhere(['like', 'warranty_info', $this->warranty_info])->andFilterWhere(['like', 'payment_info', $this->payment_info])->andFilterWhere(['like', 'contact_info', $this->contact_info])->andFilterWhere(['like', 'token', $this->token])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'listing_assets_url', $this->listing_assets_url]);
     return $dataProvider;
 }
コード例 #2
0
ファイル: EbayApi.php プロジェクト: sea129/kbay
 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';
 }
コード例 #3
0
ファイル: index.php プロジェクト: sea129/kbay
/* @var $dataProvider yii\data\ActiveDataProvider */
use frontend\models\ebayaccounts\EbayAccount;
$this->title = Yii::t('app/listing', 'Listings');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="listing-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
//= Html::a(Yii::t('app/listing', 'Create Listing'), ['create'], ['class' => 'btn btn-success'])
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['item_id', ['attribute' => 'sku', 'value' => function ($model, $key, $index, $widget) {
    return Html::a($model->sku, Url::to(['product/view', 'id' => $model->product->id]), ['target' => '_blank']);
}, 'format' => 'raw'], ['attribute' => 'ebay_id', 'value' => function ($model, $key, $index, $widget) {
    return $model->ebay->seller_id;
}, 'vAlign' => 'middle', 'width' => '180px', 'label' => Yii::t('app/order', 'eBay Account', []), 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(EbayAccount::find()->where(['user_id' => Yii::$app->user->id])->orderBy('seller_id')->asArray()->all(), 'id', 'seller_id'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'filterInputOptions' => ['placeholder' => 'eBay Account'], 'format' => 'raw'], 'price', 'title', 'qty', 'sold_qty', 'sync_at']]);
?>

</div>
コード例 #4
0
ファイル: OrderController.php プロジェクト: sea129/kbay
 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.');
     }
 }
コード例 #5
0
ファイル: ProductController.php プロジェクト: sea129/kbay
 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]);
 }
コード例 #6
0
ファイル: EOrder.php プロジェクト: sea129/kbay
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEbay()
 {
     return $this->hasOne(EbayAccount::className(), ['id' => 'ebay_id']);
 }
コード例 #7
0
ファイル: ListingController.php プロジェクト: sea129/kbay
 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;
     }
 }
コード例 #8
0
ファイル: index.php プロジェクト: sea129/kbay
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>


    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'hover' => true, 'columns' => [['class' => 'kartik\\grid\\ExpandRowColumn', 'width' => '50px', 'value' => function ($model, $key, $index, $column) {
    return GridView::ROW_COLLAPSED;
}, 'detail' => function ($model, $key, $index, $column) {
    return Yii::$app->controller->renderPartial('_expand-transaction', ['model' => $model]);
}, 'headerOptions' => ['class' => 'kartik-sheet-style'], 'expandOneOnly' => true], ['class' => '\\kartik\\grid\\BooleanColumn', 'attribute' => 'status', 'trueLabel' => 'YES', 'falseLabel' => 'NO', 'label' => Yii::t('app/order', 'Shipped', [])], ['attribute' => 'ebay_id', 'value' => function ($model, $key, $index, $widget) {
    return $model->ebay->seller_id;
}, 'vAlign' => 'middle', 'width' => '180px', 'label' => Yii::t('app/order', 'eBay Account', []), 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(EbayAccount::find()->where(['user_id' => Yii::$app->user->id])->orderBy('seller_id')->asArray()->all(), 'id', 'seller_id'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'filterInputOptions' => ['placeholder' => 'eBay Account'], 'format' => 'raw'], 'sale_record_number', 'buyer_id', ['label' => 'Buyer Email', 'value' => function ($model, $key, $index, $column) {
    if (isset($model->ebayTransactions[0])) {
        return $model->ebayTransactions[0]->buyer_email;
    } else {
        return null;
    }
}], 'ebay_order_id', 'total', ['attribute' => 'created_time', 'label' => 'Sale Date', 'filterType' => GridView::FILTER_DATE_RANGE, 'value' => function ($model, $key, $index, $column) {
    if ($model['created_time']) {
        $date = new DateTime($model['created_time'], new DateTimeZone('GMT'));
        $date->setTimezone(new DateTimeZone('Australia/Sydney'));
        return $date->format('Y-m-d H:i:s');
    } else {
        return null;
    }
}], ['attribute' => 'paid_time', 'label' => Yii::t('app/order', 'Paid Time', []), 'filterType' => GridView::FILTER_DATE_RANGE, 'value' => function ($model, $key, $index, $column) {
    if ($model['paid_time']) {
コード例 #9
0
ファイル: Product.php プロジェクト: sea129/kbay
 public function getEbayAccoutsObj()
 {
     $ebayAcc = EbayAccount::find()->allOfUserObj(Yii::$app->user->id, $db = null);
     return $ebayAcc;
 }
コード例 #10
0
ファイル: EbayAccountController.php プロジェクト: sea129/kbay
 /**
  * 拿到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]);
         }
     }
 }