示例#1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Goods();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Goods'])) {
         $model->attributes = $_POST['Goods'];
         $model->color = $_POST['Goods']['color'];
         $model->count = $_POST['Goods']['count'];
         $model->size = $_POST['Goods']['size'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
示例#2
0
 *
 *      @version $Revision: 2075 $
 */
require "../libraries/common.inc.php";
require LIB_PATH . 'page.class.php';
require "session_cp.inc.php";
uses("good");
$goods = new Goods();
$tpl_file = "goods";
$page = new Pages();
if (isset($_POST['save'])) {
    $vals = $_POST['goods'];
    $id = $_POST['id'];
    if (!empty($id)) {
        $vals['modified'] = $time_stamp;
        $result = $goods->save($vals, "update", $id);
    } else {
        $vals['created'] = $vals['modified'] = $time_stamp;
        $result = $goods->save($vals);
    }
    if (!$result) {
        flash();
    }
}
if (isset($_POST['del']) && !empty($_POST['id'])) {
    $result = $goods->del($_POST['id']);
}
if (isset($_GET['do'])) {
    $do = trim($_GET['do']);
    if (!empty($_GET['id'])) {
        $id = intval($_GET['id']);
示例#3
0
 /**
  * 增加商品
  *
  * @return Response
  */
 public function postAdd()
 {
     // return Input::all();
     //提交表单数据
     $data = Input::all();
     //建立验证规则
     $rules = array('shop_id' => 'required', 'goods_name' => 'max:32', 'goods_price' => 'digits_between:1,16|numeric|min:0', 'goods_stock' => 'digits_between:1,16|numeric|min:0', 'goods_brief' => 'max:255');
     //进行验证
     $validator = Validator::make($data, $rules);
     if ($validator->fails()) {
         return Redirect::back()->withInput()->withErrors($validator);
     }
     $goodsName = Input::get('goods_name');
     $goodsIconName = Input::get('goods_icon_name');
     $goodsType = Input::get('goods_type');
     $goodsPrice = Input::get('goods_price');
     $goodsPrice = round($goodsPrice, PRECISION_3);
     $goodsStock = Input::get('goods_stock');
     $goodsStock = round($goodsStock, PRECISION_3);
     $goodsBrief = Input::get('goods_brief');
     $shopIDs = Input::get('shop_id');
     $shopIDArray = json_decode($shopIDs, true);
     if (is_array($shopIDArray) && !empty($shopIDArray)) {
         foreach ($shopIDArray as $index => $value) {
             $shopID = base64_decode($value);
             $goods = new Goods();
             $goods->wy_goods_name = $goodsName;
             $goods->wy_goods_icon = $goodsIconName;
             $goods->wy_goods_type = $goodsType;
             $goods->wy_goods_sale_price = $goodsPrice;
             $goods->wy_stock = $goodsStock;
             $goods->wy_brief = $goodsBrief;
             $goods->wy_sale_count = DEFAULT_0;
             $goods->wy_recommend_times = DEFAULT_0;
             $goods->wy_goods_state = GOODS_STATUS_1;
             $goods->wy_onsale_time = Carbon::now();
             $goods->wy_shop_id = $shopID;
             $result = $goods->save();
             if ($result) {
                 //增加图片管理表
                 $img = new Img();
                 $img->wy_user_id = Auth::id();
                 $img->wy_shop_id = $shopID;
                 $img->wy_goods_id = $goods->getGoodsID();
                 $img->wy_img_name = $goodsIconName;
                 $img->wy_img_type = IMG_TYPE_3;
                 $img->wy_create_at = Carbon::now();
                 $img->save();
             } else {
                 $context = array("errorCode" => -15015, "userID" => Auth::id(), "data" => $data);
                 Log::error(Lang::get('errormessages.-15015'), $context);
                 return Redirect::back()->withInput()->with('error', Lang::get('errormessages.-15015'));
             }
         }
     }
     return Redirect::back()->with('success', Lang::get('messages.10007'));
 }
示例#4
0
 function actionJia()
 {
     //1创建模型对象
     $goods_model = new Goods();
     //2为对象丰富属性 goods_name,goods_id, goods_price
     $goods_model->goods_name = "Apple 5s";
     $goods_model->goods_price = 5999;
     $goods_model->goods_weight = 102;
     //3.调用save()方法实现数据添加
     if ($goods_model->save()) {
         echo "success";
     } else {
         echo "fail";
     }
 }
 /**
  * 商品添加
  */
 public function actionCreate()
 {
     if ($_POST) {
         $Goods = new Goods();
         $ImageImage = new ImageImage();
         $goods_attributes = $this->post('Goods');
         //判断货号是否存在
         $bn_goods = Goods::model()->find('bn = :bn', array(':bn' => $goods_attributes['bn']));
         if ($bn_goods) {
             $this->message('error', '货号冲突', $this->createUrl('index'));
         }
         $goods_attributes['update_time'] = time();
         $Goods->attributes = $goods_attributes;
         if (!$Goods->save()) {
             $this->message('error', CHtml::errorSummary($Goods), $this->createUrl('index'));
         }
         $goods_id = Yii::app()->db->getLastInsertID();
         //商品图片
         $image_attributes = $this->post('Image');
         $image_attach_attributes = $this->post('ImageAttach');
         $image_ids = $this->post('ImageId');
         $result = $ImageImage->imageList($image_attributes, $image_attach_attributes, $image_ids, $goods_id);
         if (!$result) {
             $this->message('error', CHtml::errorSummary($ImageImage), $this->createUrl('index'));
         }
         //创建货品
         $product_attributes = array('goods_id' => $goods_id, 'bn' => $goods_attributes['bn'], 'price' => $goods_attributes['price'], 'cost' => $goods_attributes['cost'], 'mktprice' => $goods_attributes['mktprice'], 'name' => $goods_attributes['name'], 'weight' => $goods_attributes['weight'], 'unit' => $goods_attributes['unit'], 'store' => $goods_attributes['store'], 'freez' => 0, 'goods_type' => 'normal', 'is_default' => 'true', 'uptime' => time(), 'marketable' => 'true');
         $Product = new Products();
         $Product->attributes = $product_attributes;
         if (!$Product->save()) {
             $this->message('error', CHtml::errorSummary($Product), $this->createUrl('index'));
         }
         $this->referrer();
     }
     //商品类型
     $type_list = GoodsType::model()->findAll();
     $type_arr = array();
     if ($type_list) {
         foreach ($type_list as $v) {
             $type_arr[$v->type_id] = $v->name;
         }
     }
     //品牌
     $TypeBrand = new TypeBrand();
     $model['brand'] = $TypeBrand->type_brand();
     $model['type'] = $type_arr;
     $this->render('create', array('model' => $model));
 }
示例#6
0
 function actionJia()
 {
     //1 创建模型对象出来
     $goods_model = new Goods();
     //我们需要添加数据,创建对象方式有别与查询
     //2. 为对象丰富属性 goods_name,goods_price,goods_weight,等等
     //$goods_model -> goods_name = "Apple 5s";
     //$goods_model -> goods_price = 5199;
     //$goods_model -> goods_weight = 102;
     if (isset($_POST['Goods'])) {
         $goods_model->attributes = $_POST['Goods'];
         //foreach($_POST['Goods'] as $_k => $_v){
         //    $goods_model -> $_k = $_v;
         //}
         //$goods_model -> goods_create_time = time();
         //3. 调用save()方法实现数据添加
         if ($goods_model->save()) {
             echo $goods_model->getPrimaryKey();
             echo "success";
         } else {
             echo "fail";
         }
     }
     $this->renderPartial('add', array('goods_model' => $goods_model));
 }
 /**
  * 新增数据
  *
  */
 public function actionCreate()
 {
     $model = new Goods();
     if (isset($_POST['Goods'])) {
         $model->attributes = $_POST['Goods'];
         if ($_FILES['attach']['error'] == UPLOAD_ERR_OK) {
             //封面图片
             $upload = new Uploader();
             $upload->_thumb_width = 300;
             $upload->_thumb_height = 300;
             $upload->uploadFile($_FILES['attach'], true);
             if ($upload->_error) {
                 $upload->deleteFile($upload->_file_name);
                 $upload->deleteFile($upload->_thumb_name);
                 $this->message('error', Yii::t('admin', $upload->_error));
                 return;
             }
             $model->default_image = $upload->_file_name;
             $model->default_thumb = $upload->_thumb_name;
         }
         //组图
         $imageList = $this->_request->getPost('imageList');
         $imageListSerialize = $this->imageListSerialize($imageList);
         $model->image_list = $imageListSerialize['dataSerialize'];
         //添加时间
         $model->create_time = time();
         $model->update_time = $model->create_time;
         if ($model->save()) {
             $this->message('success', Yii::t('admin', 'Add Success'), $this->createUrl('index'));
         }
     }
     //判断有无商品栏目
     $goods_cat = Catalog::model()->find('type=:type', array(':type' => $this->_type));
     if (!$goods_cat) {
         $this->message('error', Yii::t('admin', 'No Catalog'), $this->createUrl('index'));
     }
     $this->render('update', array('model' => $model));
 }
示例#8
0
 public function actionGoods2()
 {
     $todo = array();
     $todo[0] = null;
     $filename = './public/goods.txt';
     $goods = file($filename);
     $goods = array_map('check', $goods);
     $specialChar = '-';
     $pid = 0;
     //当前
     $prePid = 0;
     //前一个分类的的
     for ($i = 1; $i < count($goods); $i++) {
         $id = $i;
         $name = $goods[$i - 1];
         $next = $goods[$i];
         $todo[$i]['id'] = $i;
         $todo[$i]['name'] = trim(str_replace($specialChar, '', $name));
         //			$todo[$i]['current'] = $name;
         //			$todo[$i]['next'] = $next;
         $currentPos = strstr($goods[$i - 1], $specialChar);
         $nextPos = strstr($goods[$i], $specialChar);
         //当前没有,下一个也没有
         if (!$currentPos && !$nextPos) {
             $todo[$i]['pid'] = 0;
             $pid = $i;
             $prePid = $i;
         }
         //当前没有,下一个有
         if (!$currentPos && $nextPos) {
             $todo[$i]['pid'] = $prePid;
             $pid = $i;
         }
         //当前有,下一个没有
         if ($currentPos && !$nextPos) {
             $todo[$i]['pid'] = $pid;
         }
         //当前有,下一个也有
         if ($currentPos && $nextPos) {
             $todo[$i]['pid'] = $pid;
         }
     }
     foreach ($todo as $item) {
         $goods = new Goods();
         $goods->id = $item['id'];
         $goods->pid = $item['pid'];
         $goods->name = $item['name'];
         if ($goods->save()) {
             echo 'ok' . $goods->id . "<br />";
         } else {
             echo CHtml::errorSummary($goods);
         }
     }
     UtilHelper::dump($todo);
 }