示例#1
0
 public function actionProduct_edit()
 {
     $this->setauth();
     //检查有无权限
     $p_db = Yii::app()->p_db;
     $id = $_GET['id'];
     $product = VcosProduct::model()->findByPk($id);
     if ($_POST) {
         $state = isset($_POST['state']) ? $_POST['state'] : '0';
         $code = isset($_POST['code']) ? $_POST['code'] : '';
         $name = isset($_POST['name']) ? $_POST['name'] : '';
         $origin = isset($_POST['origin']) ? $_POST['origin'] : '';
         $desc = isset($_POST['desc']) ? $_POST['desc'] : '';
         $num = isset($_POST['num']) ? $_POST['num'] : 0;
         $price = isset($_POST['price']) ? $_POST['price'] * 100 : 0;
         $mprice = isset($_POST['mprice']) ? $_POST['mprice'] * 100 : 0;
         $category = isset($_POST['category_3']) ? $_POST['category_3'] : 0;
         $shop = isset($_POST['shop']) ? $_POST['shop'] : 0;
         $brand = isset($_POST['brand']) ? $_POST['brand'] : 0;
         $time = explode(" - ", $_POST['time']);
         $s_time = $time[0] . ' ' . $_POST['stime'];
         $e_time = $time[1] . ' ' . $_POST['etime'];
         $stime = date('Y/m/d H:i:s', strtotime($s_time));
         $etime = date('Y/m/d H:i:s', strtotime($e_time));
         $photo = '';
         if ($_FILES['photo']['error'] != 4) {
             $result = Helper::upload_file('photo', Yii::app()->params['img_save_url'] . 'product_images/' . Yii::app()->params['month'], 'image', 3);
             $photo = $result['filename'];
         }
         $photo_url = 'product_images/' . Yii::app()->params['month'] . '/' . $photo;
         //$create_times = date("Y/m/d H:i:s",time());
         $cruise_id = Yii::app()->params['cruise_id'];
         $this_user_id = Yii::app()->user->id;
         $this_user_name = Yii::app()->user->name;
         //事务处理
         $transaction = $p_db->beginTransaction();
         try {
             $product->product_code = $code;
             $product->product_name = $name;
             $product->origin = $origin;
             $product->product_desc = $desc;
             //$product->product_img = $photo_url;
             $product->inventory_num = $num;
             $product->sale_price = $price;
             $product->standard_price = $mprice;
             $product->category_code = $category;
             $product->cruise_id = $cruise_id;
             $product->shop_id = $shop;
             $product->brand_id = $brand;
             $product->sale_start_time = $stime;
             $product->sale_end_time = $etime;
             //$product->created = $create_times;
             $product->creator = $this_user_name;
             $product->creator_id = $this_user_id;
             if ($photo) {
                 $product->product_img = $photo_url;
             }
             $product->status = $state;
             $product->save();
             $transaction->commit();
             Helper::show_message(yii::t('vcos', '修改成功。'), Yii::app()->createUrl("Product/product_list"));
         } catch (Exception $e) {
             $transaction->rollBack();
             Helper::show_message(yii::t('vcos', '修改失败。'));
         }
     }
     $category_code = $product['category_code'];
     $sql = "SELECT parent_cid FROM `vcos_category` WHERE category_code =" . $category_code;
     $layer_cat_2 = $p_db->createCommand($sql)->queryRow();
     $sql = "SELECT parent_cid FROM `vcos_category` WHERE category_code =" . $layer_cat_2['parent_cid'];
     $layer_cat_1 = $p_db->createCommand($sql)->queryRow();
     $sql = "SELECT brand_id,brand_cn_name from `vcos_brand`";
     $brand = $p_db->createCommand($sql)->queryAll();
     $sql = "SELECT category_code,name,parent_cid FROM `vcos_category` WHERE parent_cid=0";
     $layer_1 = $p_db->createCommand($sql)->queryAll();
     $sql = "SELECT category_code,name,parent_cid FROM `vcos_category` WHERE parent_cid=" . $layer_cat_1['parent_cid'];
     $layer_2 = $p_db->createCommand($sql)->queryAll();
     $sql = "SELECT category_code,name,parent_cid FROM `vcos_category` WHERE parent_cid=" . $layer_cat_2['parent_cid'];
     $layer_3 = $p_db->createCommand($sql)->queryAll();
     $sql = "SELECT shop_id,shop_title FROM `vcos_shop`";
     $shop = $p_db->createCommand($sql)->queryAll();
     $this->render('product_edit', array('shop' => $shop, 'product' => $product, 'layer_cat' => $layer_cat_1['parent_cid'], 'layer_cat2' => $layer_cat_2['parent_cid'], 'brand' => $brand, 'layer_1' => $layer_1, 'layer_2' => $layer_2, 'layer_3' => $layer_3));
 }
示例#2
0
 public function actionProduct_edit()
 {
     $this->setauth();
     //检查有无权限
     $p_db = Yii::app()->p_db;
     $id = $_GET['id'];
     $product = VcosProduct::model()->findByPk($id);
     if ($_POST) {
         $shop_cat = isset($_POST['shop_cat']) ? $_POST['shop_cat'] : '';
         $state = isset($_POST['state']) ? $_POST['state'] : '0';
         $code = isset($_POST['code']) ? $_POST['code'] : '';
         $name = isset($_POST['name']) ? $_POST['name'] : '';
         $origin = isset($_POST['origin']) ? $_POST['origin'] : '';
         $desc = isset($_POST['desc']) ? $_POST['desc'] : '';
         $num = isset($_POST['num']) ? $_POST['num'] : 0;
         $price = isset($_POST['price']) ? $_POST['price'] * 100 : 0;
         $mprice = isset($_POST['mprice']) ? $_POST['mprice'] * 100 : 0;
         $category = isset($_POST['category_3']) ? $_POST['category_3'] : 0;
         $shop = isset($_POST['shop']) ? $_POST['shop'] : 0;
         $brand = isset($_POST['brand']) ? $_POST['brand'] : 0;
         $create_times = date("Y-m-d H:i:s", time());
         //$overdue == 0 :未过期  $overdue==1:已过期
         if ($_POST['sub_type'] == 1) {
             //保存且下架
             $s_time = $_POST['time_up'] . ':00';
             $stime = date('Y-m-d H:i:s', strtotime($s_time));
             if ($_POST['time_down'] != '' && isset($_POST['down'])) {
                 $e_time = $_POST['time_down'] . ':00';
                 $etime = date('Y-m-d H:i:s', strtotime($e_time));
             } else {
                 $etime = '9999-12-31 23:59:59';
             }
         } else {
             //开始销售
             if ($_POST['time_up'] != '' && isset($_POST['up'])) {
                 $s_time = $_POST['time_up'] . ':00';
                 $stime = date('Y-m-d H:i:s', strtotime($s_time));
             } else {
                 $stime = $create_times;
             }
             if ($_POST['time_down'] != '' && isset($_POST['down'])) {
                 $e_time = $_POST['time_down'] . ':00';
                 $etime = date('Y-m-d H:i:s', strtotime($e_time));
             } else {
                 $etime = '9999-12-31 23:59:59';
             }
         }
         $photo = '';
         if ($_FILES['photo']['error'] != 4) {
             $result = Helper::upload_file('photo', Yii::app()->params['img_save_url'] . 'product_images/' . Yii::app()->params['month'], 'image', 3);
             $photo = $result['filename'];
         }
         $photo_url = 'product_images/' . Yii::app()->params['month'] . '/' . $photo;
         $create_times = date("Y-m-d H:i:s", time());
         $cruise_id = Yii::app()->params['cruise_id'];
         $this_user_id = Yii::app()->user->id;
         $this_user_name = Yii::app()->user->name;
         //事务处理
         $transaction = $p_db->beginTransaction();
         try {
             $product->product_code = $code;
             $product->product_name = $name;
             $product->origin = $origin;
             $product->product_desc = $desc;
             //$product->product_img = $photo_url;
             $product->inventory_num = $num;
             $product->sale_price = $price;
             $product->standard_price = $mprice;
             $product->category_code = $category;
             $product->cruise_id = $cruise_id;
             $product->shop_id = $shop;
             $product->brand_id = $brand;
             if ($stime != '') {
                 $product->sale_start_time = $stime;
             }
             if ($etime != '') {
                 $product->sale_end_time = $etime;
             }
             //$product->created = $create_times;
             $product->creator = $this_user_name;
             $product->creator_id = $this_user_id;
             if ($photo) {
                 $product->product_img = $photo_url;
             }
             $product->status = $state;
             $product->save();
             /*if($stime<=$create_times && $etime>=$create_times){
             			//将活动商品过期更改为未过期
             			$sql = "UPDATE `vcos_activity_product` SET is_overdue=0 WHERE product_type=6 AND product_id='{$id}'";
             		}else{
             			$sql = "UPDATE `vcos_activity_product` SET is_overdue=1 WHERE product_type=6 AND product_id='{$id}'";
             		}
             		Yii::app()->p_db->createCommand($sql)->execute();*/
             //将店铺分类产品删除后新增
             //删除全部店铺分类产品
             $sql = "DELETE FROM `vcos_shop_category_product` WHERE product_id='{$id}'";
             Yii::app()->p_db->createCommand($sql)->execute();
             if ($shop_cat != '') {
                 foreach ($shop_cat as $row) {
                     $sql = "INSERT INTO `vcos_shop_category_product` (shop_category_id,product_id) VALUES ('{$row}','{$id}')";
                     Yii::app()->p_db->createCommand($sql)->execute();
                 }
             }
             //启用禁用判断栏目页面记录是否有效,时间日期判断,分别判断了栏目页面配置及页面详情配置
             if ($state == 0) {
                 $sql = "UPDATE `vcos_activity_product` SET is_overdue=1 WHERE product_id='{$id}' AND product_type=6";
                 Yii::app()->p_db->createCommand($sql)->execute();
             } else {
                 if ($state == 1) {
                     $sql = "SELECT activity_id FROM `vcos_navigation`";
                     $activity_ids = Yii::app()->p_db->createCommand($sql)->queryAll();
                     $activity_ids_str = array();
                     foreach ($activity_ids as $k => $row) {
                         $activity_ids_str[$k] = $row['activity_id'];
                     }
                     $sql = "SELECT * FROM `vcos_activity_product` WHERE product_id='{$id}' AND product_type=6";
                     $activity_product_obj = Yii::app()->p_db->createCommand($sql)->queryAll();
                     $sql = "SELECT sale_start_time,sale_end_time FROM `vcos_product` WHERE product_id='{$id}'";
                     $this_product = Yii::app()->p_db->createCommand($sql)->queryRow();
                     foreach ($activity_product_obj as $val) {
                         if (in_array($val['activity_id'], $activity_ids_str)) {
                             //只判断商品本身时间
                             if ($this_product['sale_start_time'] <= $create_times && $this_product['sale_end_time'] >= $create_times) {
                                 $sql = "UPDATE `vcos_activity_product` SET is_overdue=0 WHERE activity_id='{$val['activity_id']}' AND product_id='{$id}' AND product_type=6";
                             } else {
                                 $sql = "UPDATE `vcos_activity_product` SET is_overdue=1 WHERE activity_id='{$val['activity_id']}' AND product_id='{$id}' AND product_type=6";
                             }
                         } else {
                             //判断页面详情时间再判断商品本身时间是否符合且页面详情时间是否在商品时间范围内
                             if ($val['start_show_time'] <= $create_times && $val['end_show_time'] >= $create_times) {
                                 if ($this_product['sale_start_time'] <= $create_times && $this_product['sale_end_time'] >= $create_times) {
                                     if ($val['start_show_time'] >= $this_product['sale_start_time'] && $val['end_show_time'] <= $this_product['sale_end_time']) {
                                         $sql = "UPDATE `vcos_activity_product` SET is_overdue=0 WHERE activity_id='{$val['activity_id']}' AND product_id='{$id}' AND product_type=6";
                                     } else {
                                         $sql = "UPDATE `vcos_activity_product` SET is_overdue=1 WHERE activity_id='{$val['activity_id']}' AND product_id='{$id}' AND product_type=6";
                                     }
                                 } else {
                                     $sql = "UPDATE `vcos_activity_product` SET is_overdue=1 WHERE activity_id='{$val['activity_id']}' AND product_id='{$id}' AND product_type=6";
                                 }
                             } else {
                                 $sql = "UPDATE `vcos_activity_product` SET is_overdue=1 WHERE activity_id='{$val['activity_id']}' AND product_id='{$id}' AND product_type=6";
                             }
                         }
                         Yii::app()->p_db->createCommand($sql)->execute();
                     }
                 }
             }
             $transaction->commit();
             Helper::show_message(yii::t('vcos', '修改成功。'), Yii::app()->createUrl("Product/product_now_wait_list"));
         } catch (Exception $e) {
             $transaction->rollBack();
             Helper::show_message(yii::t('vcos', '修改失败。'));
         }
     }
     $category_code = $product['category_code'];
     $sql = "SELECT parent_cid FROM `vcos_category` WHERE status=1 AND category_code =" . $category_code;
     $layer_cat_2 = $p_db->createCommand($sql)->queryRow();
     $sql = "SELECT parent_cid FROM `vcos_category` WHERE  status=1 AND category_code =" . $layer_cat_2['parent_cid'];
     $layer_cat_1 = $p_db->createCommand($sql)->queryRow();
     $sql = "SELECT brand_id,brand_cn_name from `vcos_brand`";
     $brand = $p_db->createCommand($sql)->queryAll();
     $sql = "SELECT category_code,name,parent_cid FROM `vcos_category`  WHERE  status=1 AND parent_cid=0";
     $layer_1 = $p_db->createCommand($sql)->queryAll();
     $sql = "SELECT category_code,name,parent_cid FROM `vcos_category` WHERE  status=1 AND parent_cid=" . $layer_cat_1['parent_cid'];
     $layer_2 = $p_db->createCommand($sql)->queryAll();
     $sql = "SELECT category_code,name,parent_cid FROM `vcos_category` WHERE  status=1 AND parent_cid=" . $layer_cat_2['parent_cid'];
     $layer_3 = $p_db->createCommand($sql)->queryAll();
     $sql = "SELECT shop_id,shop_title FROM `vcos_shop`";
     $shop = $p_db->createCommand($sql)->queryAll();
     $sql = "SELECT a.*,b.product_name FROM `vcos_product_img` a\r\n\t\tLEFT JOIN `vcos_product` b ON a.product_id=b.product_id\r\n\t\tWHERE b.product_id = " . $id . " ORDER BY sort_order";
     $product_img = Yii::app()->p_db->createCommand($sql)->queryAll();
     $sql = "SELECT a.*,b.product_name FROM `vcos_product_graphic` a\r\n\t\tLEFT JOIN `vcos_product` b ON a.product_id=b.product_id\r\n\t\tWHERE b.product_id = " . $id . " ORDER BY sort_order";
     $product_graphic = Yii::app()->p_db->createCommand($sql)->queryAll();
     //店铺分类
     $sql = "SELECT * FROM `vcos_shop_category` WHERE shop_id=" . $product['shop_id'] . " ORDER BY sort_order";
     $shop_cat = $p_db->createCommand($sql)->queryAll();
     $shop_cat = self::sortOut($shop_cat);
     //获取已经选中的店铺分类产品
     $sql = "SELECT shop_category_id FROM `vcos_shop_category_product` WHERE product_id='{$id}'";
     $already_shop_category = $p_db->createCommand($sql)->queryAll();
     $this->render('product_edit', array('already_shop_category' => $already_shop_category, 'shop_cat' => $shop_cat, 'product_graphic' => $product_graphic, 'product_img' => $product_img, 'shop' => $shop, 'product' => $product, 'layer_cat' => $layer_cat_1['parent_cid'], 'layer_cat2' => $layer_cat_2['parent_cid'], 'brand' => $brand, 'layer_1' => $layer_1, 'layer_2' => $layer_2, 'layer_3' => $layer_3));
 }