示例#1
0
 public function download()
 {
     role::check('promotion_coupon');
     // 收集请求数据
     $request_data = $this->input->get();
     $coupon = Mycoupon::instance($request_data['id'])->get();
     // 权限验证
     if (!$coupon['id']) {
         remind::set(Kohana::lang('o_global.bad_request'), request::referrer(), 'error');
     }
     if (!preg_match('/^\\d+$/', $request_data['amount']) || $request_data['amount'] >= 10000 || $request_data['amount'] <= 0) {
         exit;
     }
     //$used_coupons = Myused_coupon::instance()->get_used_coupon_codes($coupons['site_id']);
     $coupons = Mycoupon::instance()->gen_coupons($coupon['id'], $request_data['amount']);
     $cpn_promotion = Mycpn_promotion::instance()->get_by_couponid($coupon['id']);
     $coupon_scheme = Mycoupon_scheme::instance($cpn_promotion['cpns_id'])->get();
     //CSV输出
     $rand_name = date('Y-m-d') . '_' . mt_rand();
     header("Pragma: public");
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
     header("Content-Type: application/force-download");
     header("Content-Type: application/octet-stream");
     header("Content-Type: application/download");
     header("Content-Transfer-Encoding: binary ");
     header("Content-type:application/vnd.ms-excel");
     header("Content-Disposition:attachment;filename=coupons_{$rand_name}.csv");
     //header("Content-Disposition:attachment;filename={$filename}{$file}.xls");
     header("Pragma: no-cache");
     header("Expires: 0");
     $output = ",,,,,\n";
     switch ($cpn_promotion['cpns_id']) {
         case 1:
         case 2:
             $output .= "订单开始金额,订单结束金额,,,,\n";
             $output .= "\${$cpn_promotion['money_from']},\${$cpn_promotion['money_to']},,,,\n";
             break;
         case 3:
             $related_ids = explode(',', trim($cpn_promotion['related_ids'], ','));
             $request_struct = array('where' => array('id' => $related_ids), 'orderby' => array('email' => 'ASC'));
             $all_users = Myuser::instance()->lists($request_struct);
             $output .= "用户邮箱,姓名,,,,\n";
             foreach ($all_users as $key => $rs) {
                 $output .= "{$rs['email']},{$rs['firstname']} {$rs['lastname']},,,,\n";
             }
             break;
         case 4:
             $related_ids = explode(',', trim($cpn_promotion['related_ids'], ','));
             $request_struct = array('where' => array('id' => $related_ids), 'orderby' => array('name_manage' => 'ASC'));
             $all_products = ProductService::get_instance()->index($request_struct);
             $output .= "商品SKU,名称,,,,\n";
             foreach ($all_products as $key => $rs) {
                 $output .= "{$rs['sku']},{$rs['name_manage']},,,,\n";
             }
             break;
         case 5:
             $related_ids = explode(',', trim($cpn_promotion['related_ids'], ','));
             $request_struct = array('where' => array('id' => $related_ids), 'orderby' => array('title_manage' => 'ASC'));
             $all_categories = CategoryService::get_instance()->index($request_struct);
             $output .= "分类名称,,,,,\n";
             foreach ($all_categories as $key => $rs) {
                 $output .= "{$rs['title_manage']},,,,,\n";
             }
             break;
         case 6:
             $output .= "订单商品开始数量,订单商品结束数量,,,,\n";
             $output .= "{$cpn_promotion['quantity_from']},{$cpn_promotion['quantity_to']},,,,\n";
             break;
     }
     $output .= ",,,,,\n";
     $output .= "打折号,开始时间,结束时间,打折值,折扣类型,\n";
     foreach ($coupons as $key => $rs) {
         $output .= $rs . "," . $cpn_promotion['time_begin'] . "," . $cpn_promotion['time_end'] . ",";
         switch ($cpn_promotion['discount_type']) {
             case 0:
                 $output .= '百分比 ' . $cpn_promotion['price'] * 100 . "%";
                 break;
             case 1:
                 $output .= '减去 $' . $cpn_promotion['price'];
                 break;
             case 2:
                 $output .= '减到 $' . $cpn_promotion['price'];
                 break;
         }
         $output .= ",";
         $output .= "{$coupon_scheme['cpns_memo']},\n";
     }
     echo iconv('UTF-8', 'gb2312', $output);
     exit;
 }
示例#2
0
 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();
 }