示例#1
0
 public function actionDelete($id)
 {
     $params = $this->getParams();
     $accountId = $this->getAccountId();
     $where = ['status' => Goods::STATUS_OFF, 'accountId' => $accountId];
     if (isset($params['all']) && $params['all']) {
         if (Goods::deleteAll($where) === false) {
             throw new ServerErrorHttpException('Failed to delete the object for unknown reason.');
         }
     } else {
         $idstrList = explode(',', $id);
         $ids = [];
         foreach ($idstrList as $perId) {
             $ids[] = new \MongoId($perId);
         }
         //check the goods are not  on shelves
         $where['status'] = Goods::STATUS_ON;
         $where = array_merge($where, ['_id' => ['$in' => $ids]]);
         if (!empty($goods = Goods::findAll($where))) {
             throw new ServerErrorHttpException(Yii::t('product', 'delete_on_shelves'));
         }
         unset($where['status']);
         if (Goods::deleteAll($where) == false) {
             throw new ServerErrorHttpException('Failed to delete the object for unknown reason.');
         }
     }
     Yii::$app->getResponse()->setStatusCode(204);
 }
示例#2
0
 public static function getGoodsName($params, $accountId)
 {
     $where = ['accountId' => $accountId, 'productId' => ['$in' => $params['id']]];
     return Goods::findAll($where);
 }
示例#3
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]);
 }
示例#4
0
 /**
  * 获取商品对象
  * @return $object array
  */
 public static function getGoods()
 {
     return Goods::findAll(['is_show' => 0]);
 }