public function actionProduct_add() { $this->setauth(); //检查有无权限 $p_db = Yii::app()->p_db; $product = new VcosProduct(); 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; $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', '添加失败。'), '#'); } } $sql = "SELECT brand_id,brand_cn_name from `vcos_brand`"; $brand = $p_db->createCommand($sql)->queryAll(); $sql = "SELECT shop_id,shop_title FROM `vcos_shop`"; $shop = $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_1[0]['category_code']; $layer_2 = $p_db->createCommand($sql)->queryAll(); $sql = "SELECT category_code,name,parent_cid FROM `vcos_category` WHERE parent_cid=" . $layer_2[0]['category_code']; $layer_3 = $p_db->createCommand($sql)->queryAll(); $this->render('product_add', array('shop' => $shop, 'product' => $product, 'brand' => $brand, 'layer_1' => $layer_1, 'layer_2' => $layer_2, 'layer_3' => $layer_3)); }
public function actionProduct_add() { $this->setauth(); //检查有无权限 $p_db = Yii::app()->p_db; $product = new VcosProduct(); 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; $category = isset($_POST['category']) ? $_POST['category'] : 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()); 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 = ''; } } 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 = ''; } } $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; $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; $product->status = $state; $product->save(); $inser_id = $product->attributes['product_id']; $transaction->commit(); //Helper::show_message(yii::t('vcos', '添加成功。'), Yii::app()->createUrl("Product/product_now_wait_list")); Helper::show_message_querys(yii::t('vcos', '添加成功,是否继续添加商品图片?'), yii::t('vcos', '是否继续添加商品图文?'), Yii::app()->createUrl("Product/product_now_wait_list"), Yii::app()->createUrl("Product/product_edit", array('id' => $inser_id, 'action' => 'img')), Yii::app()->createUrl("Product/product_edit", array('id' => $inser_id, 'action' => 'graphic'))); } catch (Exception $e) { $transaction->rollBack(); Helper::show_message(yii::t('vcos', '添加失败。'), '#'); } } $category = isset($_GET['category']) ? empty($_GET['category']) ? 0 : 1 : 0; $shop = isset($_GET['shop']) ? empty($_GET['shop']) ? 0 : 1 : 0; if ($category == 1 && $shop == 1) { $sql = "SELECT brand_id,brand_cn_name from `vcos_brand`"; $brand = $p_db->createCommand($sql)->queryAll(); $sql = "SELECT shop_id,shop_title FROM `vcos_shop`"; $shop_sel = $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_1[0]['category_code']; $layer_2 = $p_db->createCommand($sql)->queryAll(); $sql = "SELECT category_code,name,parent_cid FROM `vcos_category` WHERE parent_cid=" . $layer_2[0]['category_code']; $layer_3 = $p_db->createCommand($sql)->queryAll(); //店铺分类 $sql = "SELECT * FROM `vcos_shop_category` WHERE shop_id=" . $_GET['shop'] . " ORDER BY sort_order"; $shop_cat = $p_db->createCommand($sql)->queryAll(); $shop_cat = self::sortOut($shop_cat); $this->render('product_add', array('shop_cat' => $shop_cat, 'shop' => $_GET['shop'], 'category' => $_GET['category'], 'shop_sel' => $shop_sel, 'product' => $product, 'brand' => $brand, 'layer_1' => $layer_1, 'layer_2' => $layer_2, 'layer_3' => $layer_3)); } else { $sql = "SELECT shop_id,shop_title FROM `vcos_shop` WHERE shop_status=1 AND is_delete=0"; $shop_sel = $p_db->createCommand($sql)->queryAll(); $sql = "SELECT a.category_code,a.parent_catogory_code,b.name FROM `vcos_shop_operation_category` a LEFT JOIN `vcos_category` b ON a.category_code=b.category_code WHERE b.status=1 AND a.status=1 AND tree_type=1 AND a.shop_id=" . $shop_sel[0]['shop_id'] . " ORDER BY a.category_code"; $cat1_sel = $p_db->createCommand($sql)->queryAll(); if ($cat1_sel) { $sql = "SELECT a.category_code,a.parent_catogory_code,b.name FROM `vcos_shop_operation_category` a LEFT JOIN `vcos_category` b ON a.category_code=b.category_code WHERE b.status=1 AND a.status=1 AND tree_type=2 AND a.shop_id=" . $shop_sel[0]['shop_id'] . " ORDER BY a.category_code"; $cat2_sel = $p_db->createCommand($sql)->queryAll(); $sql = "SELECT a.category_code,a.parent_catogory_code,b.name FROM `vcos_shop_operation_category` a LEFT JOIN `vcos_category` b ON a.category_code=b.category_code WHERE b.status=1 AND a.status=1 AND tree_type=3 AND a.shop_id=" . $shop_sel[0]['shop_id'] . " ORDER BY a.category_code"; $cat3_sel = $p_db->createCommand($sql)->queryAll(); $cat1_but = $cat1_sel[0]['category_code']; $cat2_but = $cat2_sel[0]['category_code']; $cat3_but = $cat3_sel[0]['category_code']; } else { $cat1_but = ''; $cat2_but = ''; $cat3_but = ''; $cat2_sel = ''; $cat3_sel = ''; } $this->render('product_add_category', array('shop_sel' => $shop_sel, 'cat1_but' => $cat1_but, 'cat2_but' => $cat2_but, 'cat3_but' => $cat3_but, 'cat1_sel' => $cat1_sel, 'cat2_sel' => $cat2_sel, 'cat3_sel' => $cat3_sel)); } }