/** *生成树 */ public static function generate_tree($categories, $level_depth, $pid, $category, $category_field, $checkAll) { $tree = ''; //设定标识 static $related = ''; static $mark_tree = 0; if ($related != $category) { $related = $category; $mark_tree = 0; } if ($mark_tree == 0) { $tree .= '<tr style="text-align:left;"> <th style="text-align:left;width:40px;padding-left:4px"><input type="checkbox" name="' . $checkAll . '" id="' . $checkAll . '" /></th>'; if (isset($category_field)) { foreach ($category_field as $field) { $tree .= '<th style="text-align:left">' . $field . '</th>'; } } $tree .= '</tr>'; $mark_tree++; } foreach ($categories[$level_depth] as $value) { $mark_pic = 0; $nbsp = ''; for ($i = 1; $i < $level_depth; $i++) { $nbsp .= ' '; } if ($value['pid'] == $pid) { $tree .= '<tr style="text-align:left;"> <td> <input name="' . $category . '[]" type="checkbox" value="' . $value['id'] . '" title="' . $value['title_manage'] . '"/> <input type="hidden" name="parentId" value="' . $value['pid'] . '"/> </td>'; if (isset($category_field)) { foreach ($category_field as $key => $field) { $tree .= '<td>'; if ($mark_pic == 0) { $tree .= $nbsp . '<img src="/images/icon_dot2.gif" class="icon_dot" />'; $mark_pic++; } $tree .= $value[$key] . '</td>'; } } $tree .= '</tr>'; if (isset($categories[$level_depth + 1])) { $tree .= promotion::generate_tree($categories, $level_depth + 1, $value['id'], $category, $category_field, $checkAll); } } } return $tree; }
public function edit() { role::check('promotion_promotion'); // 收集请求数据 $request_data = $this->input->get(); $promotion = Mypromotion::instance($request_data['id'])->get(); if (!$promotion['id']) { remind::set(Kohana::lang('o_global.bad_request'), request::referrer(), 'error'); } $promotion['money_from'] = sprintf('%.3f', $promotion['money_from']); $promotion['money_to'] = sprintf('%.3f', $promotion['money_to']); $pmts_id = $promotion['pmts_id']; $scheme = Mypromotion_scheme::instance($promotion['pmts_id'])->get(); //实例化session $session = Session::instance(); // 模板输出 $this->template->content = new View("promotion/edit_promotion_" . $pmts_id); //echo $pmts_id; //extra process needed for IDs switch ($pmts_id) { case 1: // discount_category $request_struct = array('where' => array(), 'orderby' => array('title_manage' => 'ASC')); $all_ids = CategoryService::get_instance()->index($request_struct); unset($all_ids['count']); //dialog start $this->template->content->dialog = new View("promotion/partial/dialog_category"); $this->template->content->dialog->related_ids_name = 'related_ids'; if ($session->get('sessionErrorData') === false) { $this->template->content->dialog->related_ids = explode(',', $promotion['related_ids']); } $categoryDiaStruct = array('dialog_form' => 'dialog-form', 'categoryTable' => 'categoryTable'); $this->template->content->dialog->categoryDiaStruct = $categoryDiaStruct; //显示字段设置 $category_field = array("title_manage" => "中文名称", "title" => "分类名"); $all_ids = promotion::convert($all_ids); $tree = promotion::generate_tree($all_ids, 1, 0, 'related_ids', $category_field, 'checkAll'); $this->template->content->dialog->tree = $tree; //dialog end break; case 5: // get_gifts_buy_anything // get_gifts_buy_anything case 6: // get_gifts_price_morethan $request_struct = array('where' => array('type' => ProductService::PRODUCT_TYPE_GOODS, 'on_sale' => 1), 'orderby' => array('title' => 'ASC')); $all_ids = ProductService::get_instance()->index($request_struct); $this->template->content->goods_area = new View("promotion/partial/edit_goods"); if ($session->get('sessionErrorData') === false) { $this->template->content->goods_area->gift_related_ids = explode(',', $promotion['gift_related_ids']); } $this->template->content->goods_area->thing = 'goods'; $this->template->content->thing = 'goods'; $this->template->content->goods_area->all_ids = $all_ids; $this->template->content->all_ids = $all_ids; //dialog start $this->template->content->dialog = new View("promotion/partial/dialog_good"); $goodDiaStruct = array('dialog_form' => 'dialog-form-good', 'goodSearchType' => 'goodSearchType', 'goodKeyword' => 'goodKeyword', 'goodSearchbtn' => 'goodSearchbtn', 'goodTable' => 'goodTable', 'checkAll' => 'checkAll', 'goods' => 'goods'); $this->template->content->dialog->goodDiaStruct = $goodDiaStruct; $this->template->content->dialog->all_ids = $all_ids; //显示字段设置 $js_good_field = 'var good_field = {\'SKU\':"sku","货品名":"title"};'; $good_field = array('sku' => 'SKU', "title" => "货品名"); $this->template->content->js_good_field = $js_good_field; $this->template->content->goods_area->good_field = $good_field; //dialog end break; case 2: // discount_product_during // discount_product_during case 3: // discount_product_quantity_morethan // discount_product_quantity_morethan case 12: // discount_cart_buy_product // discount_cart_buy_product case 16: // free_shipping_buy_product $this->template->content->products_area = new View("promotion/partial/edit_products"); if ($session->get('sessionErrorData') === false) { $related_ids = explode(',', trim($promotion['related_ids'], ',')); // $this->template->content->products_area->related_ids = $related_ids; } else { $related_ids = $session->get('sessionErrorData'); $related_ids = $related_ids['related_ids']; } $all_ids = ProductService::get_instance()->index(array('where' => array('on_sale' => 1, 'id' => $related_ids), 'orderby' => array('name_manage' => 'ASC'))); $this->add_category_name($all_ids); $this->template->content->products_area->all_ids = $all_ids; $this->template->content->all_ids = $all_ids; $this->template->content->products_area->thing = 'products'; $this->template->content->thing = 'products'; //dialog start $this->template->content->dialog = new View("promotion/partial/dialog_product"); $productDiaStruct = array('dialog_form' => 'dialog-form-product', 'productSearchType' => 'productSearchType', 'productKeyword' => 'productKeyword', 'productSearchbtn' => 'productSearchbtn', 'productTable' => 'productTable', 'checkAll' => 'checkAll', 'products' => 'products'); $this->template->content->dialog->productDiaStruct = $productDiaStruct; $this->template->content->dialog->all_ids = $all_ids; //显示字段设置 $js_product_field = 'var product_field = {\'SKU\':"sku","中文名称":"name_manage","商品名称":"title","分类名称":"category_name"};'; $product_field = array('sku' => 'SKU', "name_manage" => "中文名称", "title" => "商品名称", "category_name" => "分类名称"); $this->template->content->js_product_field = $js_product_field; $this->template->content->products_area->product_field = $product_field; //dialog end break; case 7: // get_gifts_product_price_morethan $this->template->content->products_area = new View("promotion/partial/edit_products"); if ($session->get('sessionErrorData') === false) { $related_ids = explode(',', trim($promotion['related_ids'], ',')); $this->template->content->products_area->related_ids = $related_ids; } else { $related_ids = $session->get('sessionErrorData'); $related_ids = $related_ids['related_ids']; } $all_ids = ProductService::get_instance()->index(array('where' => array('on_sale' => 1, 'id' => $related_ids), 'orderby' => array('name_manage' => 'ASC'))); $this->add_category_name($all_ids); $this->template->content->products_area->all_ids = $all_ids; $this->template->content->products_area->thing = 'products'; $this->template->content->thing = 'products'; $this->template->content->product_all_ids = $all_ids; //dialog start $this->template->content->dialog_product = new View("promotion/partial/dialog_product"); $productDiaStruct = array('dialog_form' => 'dialog-form-product', 'productSearchType' => 'productSearchType', 'productKeyword' => 'productKeyword', 'productSearchbtn' => 'productSearchbtn', 'productTable' => 'productTable', 'checkAll' => 'checkAll', 'products' => 'products'); $this->template->content->dialog_product->productDiaStruct = $productDiaStruct; $this->template->content->productDiaStruct = $productDiaStruct; $this->template->content->dialog_product->all_ids = $all_ids; //显示字段设置 $js_product_field = 'var product_field = {\'SKU\':"sku","中文名称":"name_manage","商品名称":"title","分类名称":"category_name"};'; $product_field = array('sku' => 'SKU', "name_manage" => "中文名称", "title" => "商品名称", "category_name" => "分类名称"); $this->template->content->js_product_field = $js_product_field; $this->template->content->products_area->product_field = $product_field; //dialog end $this->template->content->goods_area = new View("promotion/partial/edit_goods"); $this->template->content->goods_area->thing = 'goods'; $this->template->content->thing = 'goods'; $all_ids = ProductService::get_instance()->index(array('where' => array(), 'orderby' => array('title' => 'ASC'))); $this->template->content->goods_area->all_ids = $all_ids; $this->template->content->good_all_ids = $all_ids; if ($session->get('sessionErrorData') === false) { $this->template->content->goods_area->gift_related_ids = explode(',', $promotion['gift_related_ids']); } //dialog start $this->template->content->dialog_good = new View("promotion/partial/dialog_good"); $goodDiaStruct = array('dialog_form' => 'dialog-form-good', 'goodSearchType' => 'goodSearchType', 'goodKeyword' => 'goodKeyword', 'goodSearchbtn' => 'goodSearchbtn', 'goodTable' => 'goodTable', 'checkAll' => 'checkAll', 'goods' => 'goods'); $this->template->content->dialog_good->goodDiaStruct = $goodDiaStruct; $this->template->content->dialog_good->all_ids = $all_ids; //显示字段设置 $js_good_field = 'var good_field = {\'SKU\':"sku","货品名":"title"};'; $good_field = array('sku' => 'SKU', "title" => "货品名"); $this->template->content->js_good_field = $js_good_field; $this->template->content->goods_area->good_field = $good_field; //dialog end break; case 8: // get_1_buy_n break; case 9: // get_another_cat_buy_cat $this->template->content->related_ids = explode(',', $promotion['related_ids']); $request_struct = array('where' => array(), 'orderby' => array('title_manage' => 'ASC')); $all_ids = CategoryService::get_instance()->index($request_struct); //dialog start $this->template->content->dialog = new View("promotion/partial/dialog_category"); $this->template->content->dialog->related_ids_name = 'related_ids'; if ($session->get('sessionErrorData') === false) { $this->template->content->dialog->related_ids = explode(',', $promotion['related_ids']); } $categoryDiaStruct = array('dialog_form' => 'dialog-form', 'categoryTable' => 'categoryTable'); $this->template->content->dialog->categoryDiaStruct = $categoryDiaStruct; $this->template->content->dialog->all_ids = $all_ids; $category_field = array("title_manage" => "中文名称", "title" => "分类名"); $all_ids = promotion::convert($all_ids); $tree = promotion::generate_tree($all_ids, 1, 0, 'related_ids', $category_field, 'checkAll'); $this->template->content->dialog->tree = $tree; //dialog end //dialog start $this->template->content->dialog_gift = new View("promotion/partial/dialog_category"); $this->template->content->dialog_gift->related_ids_name = 'gift_related_ids'; if ($session->get('sessionErrorData') === false) { $this->template->content->dialog_gift->gift_related_ids = explode(',', $promotion['gift_related_ids']); } $categoryDiaStructGift = array('dialog_form' => 'dialog-form-gift', 'categoryTable' => 'categoryTable_gift'); $this->template->content->dialog_gift->categoryDiaStruct = $categoryDiaStructGift; $tree = promotion::generate_tree($all_ids, 1, 0, 'gift_related_ids', $category_field, 'checkAll_gift'); $this->template->content->dialog_gift->tree = $tree; //显示字段设置 //dialog end break; case 10: // get_catgift_price_morethan $request_struct = array('where' => array(), 'orderby' => array('title_manage' => 'ASC')); $all_ids = CategoryService::get_instance()->index($request_struct); unset($all_ids['count']); //dialog start $this->template->content->dialog = new View("promotion/partial/dialog_category"); $this->template->content->dialog->related_ids_name = 'gift_related_ids'; if ($session->get('sessionErrorData') === false) { $this->template->content->dialog->gift_related_ids = explode(',', $promotion['gift_related_ids']); } $categoryDiaStruct = array('dialog_form' => 'dialog-form', 'categoryTable' => 'categoryTable'); $this->template->content->dialog->categoryDiaStruct = $categoryDiaStruct; //显示字段设置 $category_field = array("title_manage" => "中文名称", "title" => "分类名"); $all_ids = promotion::convert($all_ids); $tree = promotion::generate_tree($all_ids, 1, 0, 'gift_related_ids', $category_field, 'checkAll'); $this->template->content->dialog->tree = $tree; //dialog end break; } // 变量绑定 $this->template->content->faction = 'do_edit'; $this->template->content->promotion = $promotion; $this->template->content->pmts_memo = $scheme['pmts_memo']; $this->template->content->promotion_scheme = $scheme; }
public function edit() { role::check('promotion_coupon'); // 收集请求数据 $request_data = $this->input->get(); $promotion = Mycpn_promotion::instance($request_data['id'])->get(); $cpns_id = $promotion['cpns_id']; if (!$cpns_id) { remind::set(Kohana::lang('o_global.access_denied'), request::referrer(), 'error'); } $promotion['money_from'] = sprintf('%.3f', $promotion['money_from']); $promotion['money_to'] = sprintf('%.3f', $promotion['money_to']); $coupon_schemes = Mycoupon_scheme::instance($cpns_id)->get(); //实例化session $session = Session::instance(); $this->template->content = new View("promotion/edit_cpn_promotion_" . $cpns_id); // extra process needed for IDs switch ($cpns_id) { case 3: // discount_cart_user_buy $all_ids = array(); if (isset($promotion['related_ids'])) { $query_struct = array('where' => array('id' => explode(',', $promotion['related_ids']))); $all_ids = Myuser::instance()->lists($query_struct); } $this->template->content->users_area = new View("promotion/partial/edit_users"); if ($session->get('sessionErrorData') === false) { $this->template->content->users_area->related_ids = explode(',', $promotion['related_ids']); } $this->template->content->users_area->thing = 'users'; $this->template->content->thing = 'users'; $this->template->content->users_area->all_ids = $all_ids; $this->template->content->users_area->relatedUsers = "relatedUsers"; $this->template->content->users_area->related_idsu = "related_ids"; $this->template->content->users_area->addUser = "******"; //$this->template->content->all_ids = $all_ids; //dialog start $this->template->content->dialog = new View("promotion/partial/dialog_user"); $userDiaStruct = array('dialog_form' => 'dialog-form-user', 'userSearchType' => 'userSearchType', 'userKeyword' => 'userKeyword', 'userSearchbtn' => 'userSearchbtn', 'userTable' => 'userTable', 'checkAll' => 'checkAll', 'users' => 'users'); $this->template->content->dialog->userDiaStruct = $userDiaStruct; //$this->template->content->dialog->all_ids = $all_ids; //显示字段设置 $js_user_field = 'var user_field = {"用户登录邮箱":"email"};'; $user_field = array('email' => "用户登录邮箱"); $this->template->content->js_user_field = $js_user_field; $this->template->content->users_area->user_field = $user_field; //dialog end break; case 4: // discount_cart_buy_product if ($session->get('sessionErrorData') === false) { // $this->template->content->products_area->related_ids = explode(',', $promotion['related_ids']); $related_ids = explode(',', $promotion['related_ids']); } else { $related_ids = $session->get('sessionErrorData'); $related_ids = $related_ids['related_ids']; } $request_struct = array('where' => array('on_sale' => 1, 'id' => $related_ids), 'orderby' => array('name_manage' => 'ASC')); $all_ids = ProductService::get_instance()->index($request_struct); $this->add_category_name($all_ids); $this->template->content->products_area = new View("promotion/partial/edit_products"); $this->template->content->products_area->all_ids = $all_ids; $this->template->content->products_area->thing = 'products'; $this->template->content->thing = 'products'; //dialog start $this->template->content->dialog = new View("promotion/partial/dialog_product"); $productDiaStruct = array('dialog_form' => 'dialog-form-product', 'productSearchType' => 'productSearchType', 'productKeyword' => 'productKeyword', 'productSearchbtn' => 'productSearchbtn', 'productTable' => 'productTable', 'checkAll' => 'checkAll', 'products' => 'products'); $this->template->content->dialog->productDiaStruct = $productDiaStruct; //显示字段设置 $js_product_field = 'var product_field = {\'SKU\':"sku","中文名称":"name_manage","商品名称":"title","分类名称":"category_name"};'; $product_field = array('sku' => 'SKU', "name_manage" => "中文名称", "title" => "商品名称", "category_name" => "分类名称"); $this->template->content->js_product_field = $js_product_field; $this->template->content->products_area->product_field = $product_field; //dialog end break; case 5: // discount_category $request_struct = array('where' => array(), 'orderby' => array('title_manage' => 'ASC')); $all_ids = CategoryService::get_instance()->index($request_struct); $all_ids = promotion::convert($all_ids); //dialog start $related_ids = 'related_ids'; $this->template->content->dialog = new View("promotion/partial/dialog_category"); $this->template->content->dialog->related_ids_name = $related_ids; if ($session->get('sessionErrorData') === false) { $this->template->content->dialog->related_ids = explode(',', $promotion['related_ids']); } $categoryDiaStruct = array('dialog_form' => 'dialog-form', 'categoryTable' => 'categoryTable'); $this->template->content->dialog->categoryDiaStruct = $categoryDiaStruct; $this->template->content->dialog->all_ids = $all_ids; //显示字段设置 $category_field = array("title_manage" => "中文名称", "title" => "分类名"); $tree = promotion::generate_tree($all_ids, 1, 0, $related_ids, $category_field, 'checkAll'); $this->template->content->dialog->tree = $tree; //dialog end break; } // 变量绑定 $this->template->content->promotion = $promotion; $this->template->content->coupon_schemes = $coupon_schemes; $this->template->content->coupon = Mycoupon::instance($promotion['cpn_id'])->get(); }