Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PointLog::find();
     $query->orderBy(['created_at' => SORT_DESC]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if ($this->load($params) && !$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'type' => $this->type, 'point' => $this->point, 'balance' => $this->balance, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'remark', $this->remark]);
     return $dataProvider;
 }
Example #2
0
                    <th>积分余额</th>
                </tr>
                <?php 
foreach ($models as $item) {
    ?>
                    <tr>
                        <td><?php 
    echo Yii::$app->formatter->asDate($item->created_at);
    ?>
</td>
                        <td><?php 
    echo $item->point > 0 ? '+' . $item->point : $item->point;
    ?>
</td>
                        <td><?php 
    echo \common\models\PointLog::getTypeLabels($item->type);
    ?>
</td>
                        <td><?php 
    echo $item->remark;
    ?>
</td>
                        <td><?php 
    echo $item->balance;
    ?>
</td>
                    </tr>
                <?php 
}
?>
                </tbody>
 /**
  * Finds the PointLog model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return PointLog the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = PointLog::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #4
0
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="point-log-index">

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

    <p>
        <?php 
echo Html::a(Yii::t('app', 'Create ') . Yii::t('app', 'Point Log'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['attribute' => 'user_id', 'value' => function ($model) {
    return $model->user ? $model->user->username : '******';
}], ['attribute' => 'type', 'format' => 'html', 'value' => function ($model) {
    if ($model->type === PointLog::POINT_TYPE_BOUGHT) {
        $class = 'label-success';
    } elseif ($model->type === PointLog::POINT_TYPE_COMMENT) {
        $class = 'label-warning';
    } else {
        $class = 'label-danger';
    }
    return '<span class="label ' . $class . '">' . PointLog::getTypeLabels($model->type) . '</span>';
}, 'filter' => Html::activeDropDownList($searchModel, 'type', PointLog::getTypeLabels(), ['class' => 'form-control', 'prompt' => Yii::t('app', 'PROMPT_STATUS')])], 'point', 'remark', 'balance', 'created_at:date', ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
Example #5
0
 public function actionPointLog()
 {
     $query = PointLog::find()->where(['user_id' => Yii::$app->user->id]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => Yii::$app->params['defaultPageSizeOrder']], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
     return $this->render('point-log', ['models' => $dataProvider->getModels(), 'pagination' => $dataProvider->pagination]);
 }
Example #6
0
<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model common\models\PointLog */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Point Logs'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="point-log-view">

    <p>
        <?php 
echo Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
?>
        <?php 
echo Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), 'method' => 'post']]);
?>
    </p>

    <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['id', ['attribute' => 'user_id', 'value' => $model->user ? $model->user->username : '******'], ['attribute' => 'type', 'value' => \common\models\PointLog::getTypeLabels($model->type)], 'point', 'remark', 'balance', 'created_at:datetime', 'updated_at:datetime', ['attribute' => 'created_by', 'value' => $model->createdBy->username], ['attribute' => 'updated_by', 'value' => $model->updatedBy->username]]]);
?>

</div>
Example #7
0
/* @var $model common\models\PointLog */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="point-log-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'user_id')->textInput();
?>

    <?php 
echo $form->field($model, 'type')->dropDownList(\common\models\PointLog::getTypeLabels());
?>

    <?php 
echo $form->field($model, 'point')->textInput();
?>

    <?php 
echo $form->field($model, 'remark')->textInput(['maxlength' => 255]);
?>

    <?php 
echo $form->field($model, 'balance')->textInput();
?>

    <div class="form-group">
Example #8
0
 public function actionCheckout()
 {
     Yii::$app->session['step'] = 2;
     $userId = Yii::$app->user->id;
     $addresses = Address::find()->where(['user_id' => $userId])->all();
     $model = new Order();
     if ($model->load(Yii::$app->request->post())) {
         if (!Yii::$app->request->post('address_id')) {
             return $this->goBack();
         }
         // 使用优惠券
         $feeCouponUser = $feeCouponCode = $feePoint = 0.0;
         $couponId = Yii::$app->request->post('coupon');
         if ($couponId && Yii::$app->request->post('checkbox-coupon')) {
             $couponUser = Coupon::findOne($couponId);
             if (!$couponUser || $couponUser->used_at > 0 || $couponUser->ended_at < time() || $couponUser->user_id != Yii::$app->user->id) {
                 return $this->goBack();
             }
             $feeCouponUser = $couponUser->money;
         }
         // 使用优惠码
         $sn = Yii::$app->request->post('sn');
         if ($sn) {
             $couponCode = Coupon::find()->where(['sn' => $sn])->one();
             if (!$couponCode || $couponCode->used_at > 0 || $couponCode->ended_at < time()) {
                 return $this->goBack();
             }
             $feeCouponCode = $couponCode->money;
         }
         // 使用积分
         $point = Yii::$app->request->post('point');
         if ($point && Yii::$app->request->post('checkbox-point')) {
             if ($point > Yii::$app->user->identity->point) {
                 return $this->goBack();
             }
             $feePoint = intval($point) / 100;
         }
         $address = Address::find()->where(['id' => Yii::$app->request->post('address_id'), 'user_id' => $userId])->one();
         $model->user_id = $userId;
         $model->sn = date('YmdHis') . rand(1000, 9999);
         $model->consignee = $address->consignee;
         $model->country = $address->country;
         $model->province = $address->province;
         $model->city = $address->city;
         $model->district = $address->district;
         $model->address = $address->address;
         $model->zipcode = $address->zipcode;
         $model->phone = $address->phone;
         $model->mobile = $address->mobile;
         $model->email = $address->email ? $address->email : Yii::$app->user->identity->email;
         if ($model->payment_method == Order::PAYMENT_METHOD_COD) {
             $model->payment_status = Order::PAYMENT_STATUS_COD;
         } else {
             $model->payment_status = Order::PAYMENT_STATUS_UNPAID;
         }
         $model->status = $model->payment_status;
         $products = Cart::find()->where(['session_id' => Yii::$app->session->id])->all();
         if (count($products)) {
             foreach ($products as $product) {
                 $model->amount += $product->number * $product->price;
             }
         } else {
             $this->redirect('/cart');
         }
         $model->amount += floatval($model->shipment_fee) - $feeCouponUser - $feeCouponCode - $feePoint;
         if ($model->save()) {
             // insert order_product and clear cart
             foreach ($products as $product) {
                 $orderProduct = new OrderProduct();
                 $orderProduct->order_id = $model->id;
                 $orderProduct->product_id = $product->product_id;
                 $orderProduct->sku = $product->sku;
                 $orderProduct->name = $product->name;
                 $orderProduct->number = $product->number;
                 $orderProduct->market_price = $product->market_price;
                 $orderProduct->price = $product->price;
                 $orderProduct->thumb = $product->thumb;
                 $orderProduct->type = $product->type;
                 $orderProduct->save();
                 // 减少商品的库存
                 Product::updateAllCounters(['stock' => -$product->number], ['id' => $product->product_id]);
             }
             // 生成订单后,清空购物车,设置优惠码,更新积分和积分记录
             Cart::deleteAll(['session_id' => Yii::$app->session->id]);
             if (isset($couponUser) && Yii::$app->request->post('checkbox-coupon')) {
                 $couponUser->used_at = time();
                 $couponUser->order_id = $model->id;
                 $couponUser->save();
             }
             if (isset($couponCode) && Yii::$app->request->post('checkbox-coupon')) {
                 $couponCode->user_id = Yii::$app->user->id;
                 $couponCode->used_at = time();
                 $couponCode->order_id = $model->id;
                 $couponCode->save();
             }
             if (isset($point) && Yii::$app->request->post('checkbox-point')) {
                 $balance = Yii::$app->user->identity->point - $point;
                 User::updateAllCounters(['point' => -$point], ['id' => Yii::$app->user->id]);
                 $pointLog = new PointLog(['user_id' => Yii::$app->user->id, 'type' => PointLog::POINT_TYPE_BUYING, 'point' => -$point, 'balance' => $balance]);
                 $pointLog->save();
             }
             // 记录订单日志
             $orderLog = new OrderLog(['order_id' => $model->id, 'status' => $model->status]);
             $orderLog->save();
             // 不同的付款方式到不同的页面
             if ($model->payment_method == Order::PAYMENT_METHOD_COD) {
                 return $this->redirect(['cart/cod', 'id' => $model->id]);
             } else {
                 return $this->redirect(['cart/pay', 'sn' => $model->sn]);
             }
         }
     }
     $products = Cart::find()->where(['session_id' => Yii::$app->session->id])->all();
     if (!count($products)) {
         return $this->redirect('/cart');
     }
     if (count($addresses)) {
         return $this->render('checkout', ['model' => $model, 'addresses' => $addresses, 'products' => $products]);
     } else {
         return $this->redirect(['cart/address']);
     }
 }