public function beforeSave()
 {
     $in = intval($this->getAttribute('in'));
     $out = intval($this->getAttribute('out'));
     $goods_id = $this->getAttribute('goods_id');
     $stock = intval(Goods::model()->findByPk($goods_id)->stock);
     //echo $stock;
     if ($stock >= 0) {
         //echo '1';
         if ($this->isNewRecord) {
             $balance_history = $stock + $in - $out;
         } else {
             $model = $this->findByPk($this->id);
             $ms = intval($model->in);
             $mk = intval($model->out);
             //echo "$stok - $ms + $mk + $in - $out =";
             //echo
             $balance_history = $stock - $ms + $mk + $in - $out;
         }
         if ($balance_history < 0) {
             $this->addError('out', "Proses gagal, sisa stok tidak boleh kurang dari 0");
             $return = false;
         } else {
             $this->setAttribute('balance_history', $balance_history);
             $return = true;
         }
     } else {
         echo '1';
         $return = false;
     }
     return $return;
 }
 public function actionView($id)
 {
     $goods = Goods::model()->findByPk(intval($id));
     if (false == $goods || $goods->status == 'N') {
         throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.'));
     }
     // seo信息
     $this->_seoTitle = empty($goods->seo_title) ? $goods->goods_name : $goods->seo_title;
     //更新浏览次数
     $goods->updateCounters(array('views' => 1), 'id=:id', array('id' => $id));
     $this->render('view', array('goods' => $goods));
 }
 public function actionSearch()
 {
     $keyword = $_POST['keyword'];
     //最新商品
     $criteria = new CDbCriteria();
     if ($keyword) {
         $criteria->compare('goods_name', $keyword, true);
     }
     $criteria->order = 't.id DESC';
     $data = Goods::model()->findAll($criteria);
     Yii::app()->session['keyword'] = $keyword;
     $this->render('search', array('goods' => $data, 'keyword' => $keyword));
 }
 public function actionAddtrans()
 {
     if (isset($_POST['goods_id'])) {
         //print_r($_POST['id']);
         /*
         			$criteria = new CDbCriteria();			
         			$criteria->join = "JOIN angkutan on(angkutan.id_angkutan = t.id_angkutan)";
         			$criteria->condition = "id_detail = ".$_POST['id'][0];			*/
         $goods = Goods::model()->findByPk($_POST['goods_id']);
         //{"id_detail":"1","nama":"Boeng 757 Jakarta - Surabaya","harga":"350","id_angkutan":"1"}
         $data["goods_id"] = $goods->id;
         echo CJSON::encode($data);
     }
 }
示例#5
0
 function actionCategory()
 {
     //渲染视图
     //render() 带布局渲染
     //renderPartial()  部分渲染
     error_reporting(E_ALL || ~E_NOTICE);
     $goods_model = Goods::model();
     $total = $goods_model->count();
     $per = 8;
     $page = new Pagination($total, $per);
     $sql = "select * from {{goods}} {$page->limit}";
     $goods_infos = $goods_model->findAllBySql($sql);
     $page_list = $page->fpage();
     $this->render('category', array('goods_infos' => $goods_infos, 'page_list' => $page_list));
 }
 public function actionCekgoods()
 {
     if (strpos($_GET['term'], "(") === false) {
         $condition = $_GET['term'];
         $criteria = new CDbCriteria();
         $criteria->condition = " goods_name like '%{$condition}%'";
         $criteria->limit = 7;
         $info = Goods::model()->findAll($criteria);
         $arModels = array();
         foreach ($info as $model) {
             $arModels[] = array('id' => $model->id, 'label' => $model->goods_name, 'value' => $model->goods_name);
         }
         echo CJSON::encode($arModels);
     }
 }
 /**
  * 新增数据
  *
  */
 public function actionCreate()
 {
     $model = new GoodsPlan();
     if (isset($_POST['GoodsPlan'])) {
         $model->attributes = $_POST['GoodsPlan'];
         //添加时间
         $model->create_time = time();
         if ($model->save()) {
             $this->message('success', Yii::t('admin', 'Add Success'), $this->createUrl('index'));
         }
     }
     //判断有无商品栏目
     $goods = Goods::model()->find();
     if (!$goods) {
         $this->message('error', '请先添加商品信息', $this->createUrl('index'));
     }
     $this->render('update', array('model' => $model));
 }
 public function actionBuy($id)
 {
     $goods = Goods::model()->findByPk(intval($id));
     if (false == $goods) {
         throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.'));
     }
     // seo信息
     $this->_seoTitle = $goods->goods_name;
     $goodsplan = GoodsPlan::model()->findAll('goods_id=:goods_id', array('goods_id' => $id));
     $criteria = new CDbCriteria();
     $criteria->select = '*';
     // only select the 'title' column
     $criteria->condition = 'goods_id=:goods_id';
     $criteria->params = array(':goods_id' => $id);
     $criteria->order = 'plan_price asc';
     $goodsplan = GoodsPlan::model()->findAll($criteria);
     // $params is not needed
     //print_r($goodsplan);
     $this->render('buy', array('goods' => $goods, 'goodsplan' => $goodsplan, 'uid' => $uid, 'username' => $username));
 }
示例#9
0
 /**
  * 商品详情
  * @param unknown $id
  * @throws CHttpException
  */
 public function actionView($id)
 {
     $good = Goods::model()->findByPk(intval($id));
     if (false == $good || $good->status == 'N') {
         throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.'));
     }
     // seo信息
     $this->_seoTitle = empty($good->seo_title) ? $good->goods_name . ' - ' . $this->_setting['site_name'] : $good->seo_title;
     $this->_seoKeywords = empty($good->seo_keywords) ? $this->_seoKeywords : $good->seo_keywords;
     $this->_seoDescription = empty($good->seo_description) ? $this->_seoDescription : $good->seo_description;
     $catalogArr = Catalog::model()->findByPk($good->catalog_id);
     //更新浏览次数
     $good->updateCounters(array('views' => 1), 'id=:id', array('id' => $id));
     // 加载css,js
     Yii::app()->clientScript->registerCssFile($this->_stylePath . "/css/view.css");
     Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.js");
     // 最近的商品
     $last_goods = Goods::model()->findAll(array('condition' => 'catalog_id = ' . $good->catalog_id, 'order' => 'id DESC', 'limit' => 10));
     // nav
     $navs = array();
     $navs[] = array('url' => $this->createUrl('goods/view', array('id' => $id)), 'name' => $good->goods_name);
     $tplVar = array('good' => $good, 'navs' => $navs, 'last_goods' => $last_goods);
     $this->render('view', $tplVar);
 }
 /**
  * 批量操作
  *
  */
 public function actionBatch()
 {
     if ($this->method() == 'GET') {
         $command = trim($_GET['command']);
         $ids = intval($_GET['id']);
     } elseif ($this->method() == 'POST') {
         $command = trim($_POST['command']);
         $ids = $_POST['id'];
     } else {
         $this->message('errorBack', Yii::t('admin', 'Only POST Or GET'));
     }
     empty($ids) && $this->message('error', Yii::t('admin', 'No Select'));
     switch ($command) {
         case 'delete':
             //删除商品
             foreach ((array) $ids as $id) {
                 $goodsModel = Goods::model()->findByPk($id);
                 if ($goodsModel) {
                     $image_list = $goodsModel->image_list;
                     $image_list && ($image_list = unserialize($image_list));
                     if ($image_list) {
                         foreach ($image_list as $image) {
                             Uploader::deleteFile($image['file']);
                             $file = Upload::model()->findByPk($image['fileId']);
                             if ($file) {
                                 $file->delete();
                             }
                         }
                     }
                     Uploader::deleteFile($goodsModel->default_image);
                     Uploader::deleteFile($goodsModel->default_thumb);
                     $goodsModel->delete();
                 }
             }
             break;
         case 'show':
             //商品显示
             foreach ((array) $ids as $id) {
                 $goodsModel = Goods::model()->findByPk($id);
                 if ($goodsModel) {
                     $goodsModel->status = 'Y';
                     $goodsModel->save();
                 }
             }
             break;
         case 'hidden':
             //商品隐藏
             foreach ((array) $ids as $id) {
                 $goodsModel = Goods::model()->findByPk($id);
                 if ($goodsModel) {
                     $goodsModel->status = 'N';
                     $goodsModel->save();
                 }
             }
             break;
         case 'commend':
             //商品推荐
             foreach ((array) $ids as $id) {
                 $recom_id = intval($_POST['recom_id']);
                 if ($recom_id) {
                     $goodsModel = Goods::model()->findByPk($id);
                     if ($goodsModel) {
                         $goodsModel->recommend = 'Y';
                         $goodsModel->save();
                     }
                 } else {
                     $this->message('error', Yii::t('admin', 'RecommendPosition is Required'));
                 }
             }
             break;
         case 'unCommend':
             //商品取消推荐
             foreach ((array) $ids as $id) {
                 $goodsModel = Goods::model()->findByPk($id);
                 if ($goodsModel) {
                     $goodsModel->commend = 'N';
                     $goodsModel->save();
                 }
             }
             break;
         default:
             throw new CHttpException(404, Yii::t('admin', 'Error Operation'));
             break;
     }
     $this->message('success', Yii::t('admin', 'Batch Operate Success'));
 }
示例#11
0
 public function actionOnsale()
 {
     $id = $_POST['crowid'];
     $result = Goods::model()->updateAll(array('IsSale' => 'Y'), "id in ({$id})");
     if ($result) {
         Yii::app()->user->setFlash('success', '商品上架成功');
     } else {
         Yii::app()->user->setFlash('failed', '商品上架失败');
     }
     echo json_encode($result);
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Goods::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
示例#13
0
 /**
  * 商品扩展属性
  */
 public function actionProps()
 {
     $goods_id = $this->get('goods_id');
     $goods_row = Goods::model()->find('goods_id = :goods_id', array(':goods_id' => $goods_id));
     //商品扩展属性
     $GoodsTypeProps = new GoodsTypeProps();
     if ($_POST) {
         $props_attributes = $this->post('Props');
         $GoodsTypeProps = new GoodsTypeProps();
         $result = $GoodsTypeProps->TypeGoodsValue($goods_id, $goods_row['type_id'], $props_attributes['props_id'], $props_attributes['props_value_id']);
         if ($result) {
             $this->message('success', '编辑成功', $this->createUrl('index'));
         } else {
             $this->message('error', '编辑失败', $this->createUrl('index'));
         }
     }
     $type_props = $GoodsTypeProps->TypeProps($goods_row['type_id']);
     $model['type_props'] = $type_props;
     $model['type_goods_value'] = $GoodsTypeProps->TypeGoodsValueList($goods_id, $goods_row['type_id']);
     $model['goods_row'] = $goods_row;
     $this->render('props', array('model' => $model));
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = new GoodsBuild();
     $goods = new Goods();
     $goods = Goods::model()->findByPk($id);
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['GoodsBuild'])) {
         $model->attributes = $_POST['GoodsBuild'];
         //var_dump($model->attributes);
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model, 'goods' => $goods));
 }
示例#15
0
 function actionHui()
 {
     //测试事务
     $goods_model = Goods::model();
     $transaction = $goods_model->dbConnection->beginTransaction();
     $goods_info = $goods_model->findByPk(25);
     $goods_info->goods_price += 952;
     $goods_info->save();
     if ($goods_info->goods_price < 1000) {
         echo $goods_info->goods_price;
         echo "回滚";
         $transaction->rollback();
     } else {
         echo "执行";
         $transaction->commit();
     }
     $this->renderPartial('add', array('goods_model' => $goods_model));
 }
示例#16
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Goods the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Goods::model()->findByPk($id);
     $count = Count::model()->find('goods_id=:goods_id', array(':goods_id' => $id));
     $model->count = $count->count;
     $model->size = $count->size;
     $model->color = $count->color;
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
示例#17
0
 /**
  * 删除方法
  */
 function actionDel($id)
 {
     //根据$id将被删除商品的数据模型获得到,通过该被删除的对象调用delete方法
     $goods_model = Goods::model();
     $goods_info = $goods_model->findByPk($id);
     if ($goods_info->delete()) {
         $this->redirect('index.php?r=backend/goods/show');
     }
 }
示例#18
0
echo Yii::t('admin', 'add');
?>
</span></a></li>
    </ul>
    <div class="search right">
      <?php 
$form = $this->beginWidget('CActiveForm', array('id' => 'searchForm', 'method' => 'get', 'action' => array('index'), 'htmlOptions' => array('name' => 'xform', 'class' => 'right ')));
?>
  选择商品
      <select name="goods_id" id="goods_id">
        <option value="">=<?php 
echo Yii::t('admin', 'All Content');
?>
=</option>
        <?php 
foreach ((array) Goods::model()->findAll(array('order' => 'id desc')) as $goods) {
    ?>
        <option value="<?php 
    echo $goods['id'];
    ?>
"><?php 
    echo $goods['goods_name'];
    ?>
</option>
        <?php 
}
?>
      </select>
  套餐名称关键字
      <input id="plan_name" type="text" name="plan_name" value="" class="txt" size="15"/>