Example #1
0
 public function actionIntegral()
 {
     $dataProvider = new ActiveDataProvider(['query' => Kiwi::getDealLog()->find()->innerJoinWith('customerSales')->where(['customer_sales.user_id' => \Yii::$app->user->id])]);
     /** @var \yincart\customer\models\Customer $customer */
     $customer = \Yii::$app->user->identity;
     $customerSellers = Kiwi::getCustomerSeller()->find()->where(['referrer' => $customer->username])->all();
     $sellerIds = ArrayHelper::getColumn($customerSellers, 'customer_id');
     $referrerProvider = new ActiveDataProvider(['query' => Kiwi::getDealLog()->find()->innerJoinWith('customerSales')->where(['customer_sales.user_id' => $sellerIds])]);
     return $this->render('integral', ['dataProvider' => $dataProvider, 'referrerProvider' => $referrerProvider]);
 }
Example #2
0
 /**
  * @param \yii\base\ModelEvent $event
  * @throws \yii\db\Exception
  */
 public function addDealLog($event)
 {
     /** @var \yincart\order\models\Order $order */
     $order = $event->sender;
     foreach ($order->orderItems as $orderItem) {
         $deal_log = Kiwi::getDealLog();
         $deal_log->user_id = $order->user_id;
         $deal_log->order_id = $order->order_id;
         $deal_log->item_id = $orderItem->item_id;
         $deal_log->sale_price = $orderItem->price;
         $deal_log->memo = $orderItem->name;
         $deal_log->key = $orderItem->data['key'];
         $deal_log->deal_time = $order->create_at;
         $deal_log->percent = 0.35 + 0.05 * ($deal_log->customerSales->customer->customerSeller->level - 1);
         $deal_log->created_at = time();
         if (!$deal_log->save()) {
             throw new Exception(\Yii::t('app', 'add deal log fail'), $deal_log->getErrors());
         }
     }
 }
Example #3
0
 public function getMonthSelesCount()
 {
     $sales = Kiwi::getCustomerSales()->find()->where(['user_id' => $this->customer_id])->all();
     $saleKeys = ArrayHelper::getColumn($sales, 'key');
     return Kiwi::getDealLog()->find()->innerJoinWith(['orderItem', 'order'])->where(['key' => $saleKeys])->andWhere('order.create_at > ' . strtotime('- 1 month'))->count('order_item.qty');
 }
Example #4
0
            <li class=""><a href="#category" style="padding: 8px" data-toggle="tab">分类排行</a></li>
        </ul>
        <div id="myTabContent" class="tab-content">
            <div class="tab-pane fade active in" id="profile">
                <ul class="list-unstyled contact-details">
                    <?php 
$month = date('m');
$year = date('Y');
$last_month = date('m') - 1;
if ($month == 1) {
    $last_month = 12;
    $year = $year - 1;
}
$start = mktime(0, 0, 0, $last_month, 0, $year);
$end = mktime(0, 0, 0, $month, 0, $year);
$dealLogModels = Kiwi::getDealLog()->find()->select('key,count(*) as order_id')->where(['between', 'created_at', $start, $end])->groupBy('user_id')->orderBy('order_id desc')->limit(7)->all();
foreach ($dealLogModels as $dealLogModel) {
    $seller = Kiwi::getCustomerSales()->find()->where(['key' => $dealLogModel->key])->one();
    if ($seller) {
        $user = $seller->user;
        ?>
                            <li><span><?php 
        echo $user->username;
        ?>
</span> 卖出 <?php 
        echo $dealLogModel->order_id;
        ?>
 单</li>
                    <?php 
    }
}