Ejemplo n.º 1
0
 public function actionDelGood()
 {
     if (Yii::$app->request->isAjax) {
         $data = Yii::$app->request->post();
         $goods_id = $data['goods_id'];
         \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         $session = new Sitesession();
         $user_id = $session->getUserId();
         if (!$user_id) {
             return ['goods_id' => 0, 'count' => 0];
         }
         $goods = $session->getGoods($user_id);
         $shopping_car = $goods ? $goods : array();
         if (in_array($goods_id, $shopping_car)) {
             foreach ($shopping_car as $key => $gid) {
                 if ($gid == $goods_id) {
                     unset($shopping_car[$key]);
                 }
             }
         }
         $session->storeGoods($user_id, $shopping_car);
         $count = count($shopping_car);
         return ['goods_id' => $goods_id, 'shopping_car' => $shopping_car, 'count' => $count];
     }
 }
Ejemplo n.º 2
0
 public function actionDetails()
 {
     $session = new Sitesession();
     $user_id = $session->getUserId();
     $goods = $session->getGoods($user_id);
     $order_id = $session->getOrderId();
     $order = null;
     if (!empty($order_id)) {
         $order = Orders::findOne($order_id);
     }
     $user = null;
     if ($user_id) {
         //获取user_id用户信息
         /*$connection = \Yii::$app->db;
           $command = $connection->createCommand('SELECT * FROM customer WHERE id='.$user_id);
           $user = $command->queryOne();*/
         $user = Customer::findOne($user_id);
     }
     $count = 0;
     if (is_array($goods) && !empty($goods)) {
         /*$str = '';
           foreach ($goods as $key => $value) {
               if(empty($str)) {
                   $str = $str." ".$value;
               } else {
                   $str = $str.", ".$value;
               }
           }  */
         $count = count($goods);
         //获取goods
         $connection = \Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
             // 所有的查询都在主服务器上执行
             //$goods = $connection->createCommand('SELECT * FROM goods WHERE goods_id in ('.$str.')')->queryAll();
             $goods = Goods::findAll($goods);
             $transaction->commit();
         } catch (\Exception $e) {
             $transaction->rollBack();
             throw $e;
         }
     } else {
         $goods = false;
     }
     return $this->render('details', ['user' => $user, 'goods' => $goods, 'count' => $count, 'order' => $order]);
 }
Ejemplo n.º 3
0
	    <?php 
    echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'username', 'title', 'address', ['label' => '选择', 'format' => 'raw', 'value' => function ($data) {
        $url = "index.php?r=order/fix-user&user_id=" . $data->id;
        return Html::a('选择用户', $url, ['title' => '选择']);
    }]]]);
    ?>

	<?php 
} else {
    ?>
		
		<?php 
    echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'goods_id', 'goods_sn', 'goods_name', 'shop_price', 'promote_price', ['label' => '添加到购物列表', 'format' => 'raw', 'value' => function ($data) {
        $session = new Sitesession();
        $user_id = $session->getUserId();
        $goods = $session->getGoods($user_id);
        if (!empty($goods) && in_array($data->goods_id, $goods)) {
            $text = "已添加";
            $actionadd = 0;
        } else {
            $text = "添加";
            $actionadd = 1;
        }
        return Html::a($text, null, ['title' => '添加', 'goods_id' => $data->goods_id, 'actionad' => $actionadd, 'class' => 'jsAddGoods']);
    }]]]);
    ?>
	<?php 
}
?>
</div>
<script>