Esempio n. 1
0
 function edit()
 {
     $coupon_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
     if (empty($coupon_id)) {
         echo Lang::get("no_coupon");
     }
     if (!IS_POST) {
         header("Content-Type:text/html;charset=" . CHARSET);
         $coupon = $this->_coupon_mod->get_info($coupon_id);
         $this->assign('coupon', $coupon);
         $this->display('coupon.form.html');
     } else {
         $coupon_value = floatval(trim($_POST['coupon_value']));
         $use_times = intval(trim($_POST['use_times']));
         $min_amount = floatval(trim($_POST['min_amount']));
         if (empty($coupon_value) || $coupon_value < 0) {
             $this->pop_warning('coupon_value_not');
             exit;
         }
         if (empty($use_times)) {
             $this->pop_warning('use_times_not_zero');
             exit;
         }
         if ($min_amount < 0) {
             $this->pop_warning("min_amount_gt_zero");
             exit;
         }
         $start_time = gmstr2time(trim($_POST['start_time']));
         $end_time = gmstr2time_end(trim($_POST['end_time'])) - 1;
         //echo gmstr2time_end(trim($_POST['end_time'])) . '-------' .$end_time;exit;
         if ($end_time < $start_time) {
             $this->pop_warning('end_gt_start');
             exit;
         }
         $coupon = array('coupon_name' => trim($_POST['coupon_name']), 'coupon_value' => $coupon_value, 'store_id' => $this->_store_id, 'use_times' => $use_times, 'start_time' => $start_time, 'end_time' => $end_time, 'min_amount' => $min_amount, 'if_issue' => trim($_POST['if_issue']) == 1 ? 1 : 0);
         $this->_coupon_mod->edit($coupon_id, $coupon);
         if ($this->_coupon_mod->has_error()) {
             $this->pop_warning($this->_coupon_mod->get_error());
             exit;
         }
         $this->pop_warning('ok', 'coupon_edit');
     }
 }
 /**
  * 检查提交的数据
  */
 function _handle_post_data($post, $id = 0)
 {
     if ($post['if_publish'] == 1 || gmstr2time($post['start_time']) <= gmtime()) {
         $post['start_time'] = gmtime();
         //立即发布
         $post['state'] = GROUP_ON;
     } else {
         $post['start_time'] = gmstr2time($post['start_time']);
         $post['state'] = GROUP_PENDING;
     }
     if (intval($post['end_time'])) {
         $post['end_time'] = gmstr2time_end($post['end_time']);
     } else {
         $this->_error('fill_end_time');
         return false;
     }
     if ($post['end_time'] < $post['start_time']) {
         $this->_error('start_not_gt_end');
         return false;
     }
     if (($post['goods_id'] = intval($post['goods_id'])) == 0) {
         $this->_error('fill_goods');
         return false;
     }
     if (empty($post['spec_id']) || !is_array($post['spec_id'])) {
         $this->_error('fill_spec');
         return false;
     }
     foreach ($post['spec_id'] as $key => $val) {
         if (empty($post['group_price'][$key])) {
             $this->_error('invalid_group_price');
             return false;
         }
         $spec_price[$val] = array('price' => number_format($post['group_price'][$key], 2, '.', ''));
     }
     $data = array('group_name' => $post['group_name'], 'group_desc' => $post['group_desc'], 'start_time' => $post['start_time'], 'end_time' => $post['end_time'] - 1, 'goods_id' => $post['goods_id'], 'spec_price' => serialize($spec_price), 'min_quantity' => $post['min_quantity'], 'max_per_user' => $post['max_per_user'], 'state' => $post['state'], 'store_id' => $this->_store_id);
     if ($id > 0) {
         $this->_groupbuy_mod->edit($id, $data);
         if ($this->_groupbuy_mod->has_error()) {
             $this->_error($this->_groupbuy_mod->get_error());
             return false;
         }
     } else {
         if (!($id = $this->_groupbuy_mod->add($data))) {
             $this->_error($this->_groupbuy_mod->get_error());
             return false;
         }
     }
     $this->_last_update_id = $id;
     return true;
 }
Esempio n. 3
0
 function edit()
 {
     $coupon_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
     $current_coupon = $this->_coupon_mod->get_info($coupon_id);
     if (empty($coupon_id)) {
         echo Lang::get("no_coupon");
     }
     if (!IS_POST) {
         $this->import_resource(array('script' => array(array('path' => 'jquery.ui/jquery.ui.js', 'attr' => ''), array('path' => 'jquery.ui/i18n/' . i18n_code() . '.js', 'attr' => ''), array('path' => 'jquery.plugins/jquery.validate.js', 'attr' => '')), 'style' => 'jquery.ui/themes/ui-lightness/jquery.ui.css'));
         header("Content-Type:text/html;charset=" . CHARSET);
         $gcategory_mod =& bm('gcategory', array('store_id' => 0));
         $this->assign('scategories', $this->_get_scategories());
         $this->assign('sgrades', $this->_get_sgrade());
         $this->assign('gcategories', $gcategory_mod->get_options(0));
         $current_coupon['selected'] = array();
         $current_coupon['selected'][$current_coupon['type']] = $current_coupon['type_content'];
         if ($current_coupon['coupon_image']) {
             $current_coupon['coupon_image'] = dirname(site_url()) . "/" . $current_coupon['coupon_image'];
         }
         $store_mod =& m('store');
         $store = $store_mod->find(array('conditions' => 'state=1', 'fields' => 'store_name,store_id'));
         if ($current_coupon['type'] == 4) {
             $type_content = unserialize($current_coupon['type_content']);
             if (!empty($type_content)) {
                 foreach ($type_content as $key => $val) {
                     $store[$val]['selected'] = 1;
                 }
             }
         }
         $this->assign('build_editor', $this->_build_editor(array('name' => 'tip', 'content_css' => SITE_URL . "/themes/mall/{$template_name}/styles/{$style_name}/css/ecmall.css")));
         $this->assign('build_upload', $this->_build_upload(array('belong' => BELONG_ARTICLE, 'item_id' => 0)));
         // 构建swfupload上传组件
         $this->assign('store', $store);
         $this->assign('coupon', $current_coupon);
         $this->display('coupon.form.html');
     } else {
         if (!$current_coupon['if_issue']) {
             $coupon_value = floatval(trim($_POST['coupon_value']));
             $use_times = intval(trim($_POST['use_times']));
             $min_amount = floatval(trim($_POST['min_amount']));
             if (empty($coupon_value) || $coupon_value < 0) {
                 $this->show_warning('coupon_value_not');
                 exit;
             }
             if (empty($use_times)) {
                 $this->show_warning('use_times_not_zero');
                 exit;
             }
             if ($min_amount < 0) {
                 $this->show_warning("min_amount_gt_zero");
                 exit;
             }
             $start_time = gmstr2time(trim($_POST['start_time']));
             $end_time = gmstr2time_end(trim($_POST['end_time'])) - 1;
             //echo gmstr2time_end(trim($_POST['end_time'])) . '-------' .$end_time;exit;
             if ($end_time < $start_time) {
                 $this->show_warning('end_gt_start');
                 exit;
             }
             $coupon = array('coupon_name' => trim($_POST['coupon_name']), 'coupon_value' => $coupon_value, 'store_id' => 0, 'use_times' => $use_times, 'start_time' => $start_time, 'end_time' => $end_time, 'min_amount' => $min_amount, 'if_issue' => trim($_POST['if_issue']) == 1 ? 1 : 0, 'tip' => $_POST['tip'], 'open_agree_item' => $_POST['open_agree_item'], 'show_in_list' => $_POST['show_in_list']);
             if ($_POST['open_agree_item']) {
                 $coupon['type_content'] = $_POST['type'] == 4 ? serialize($_POST['type_content'][$_POST['type']]) : $_POST['type_content'][$_POST['type']];
                 $coupon['type'] = $_POST['type'];
             } else {
                 $coupon['type_content'] = '';
                 $coupon['type'] = '';
             }
             /* 处理上传的图片 */
             $coupon_image = $this->_upload_image($coupon_id);
             if ($coupon_image) {
                 $coupon['coupon_image'] = $coupon_image;
             }
             if ($_POST['open_agree_item']) {
                 $store_ids = $this->_save_store_coupon($_POST['type'], $_POST['type_content'][$_POST['type']], $coupon_id);
                 if (trim($_POST['if_issue']) == 1) {
                     if ($store_ids) {
                         foreach ($store_ids as $key => $val) {
                             $ms =& ms();
                             $content = get_msg(Lang::get('to_store_owner_who_can_use_coupon'), array('coupon_name' => $_POST['coupon_name']));
                             $ms->pm->send(MSG_SYSTEM, $val, '', $content);
                         }
                     }
                 }
             } else {
                 $store_coupon_mod =& m('store_coupon');
                 $store_coupon_mod->drop('coupon_id=' . $coupon_id);
             }
         } else {
             $coupon['if_issue'] = trim($_POST['if_issue']) == 1 ? 1 : 0;
             $coupon['tip'] = $_POST['tip'];
         }
         $this->_coupon_mod->edit($coupon_id, $coupon);
         if ($this->_coupon_mod->has_error()) {
             $this->show_warning($this->_coupon_mod->get_error());
             exit;
         }
         $this->show_message('edit_coupon_success', 'back_list', 'index.php?app=coupon');
     }
 }
 /**
  * 检查提交的数据
  */
 function _handle_post_data($post, $id = 0)
 {
     if (gmstr2time($post['start_time']) <= gmtime()) {
         $post['start_time'] = gmtime();
     } else {
         $post['start_time'] = gmstr2time($post['start_time']);
     }
     if (intval($post['end_time'])) {
         $post['end_time'] = gmstr2time_end($post['end_time']);
     } else {
         $this->_error('fill_end_time');
         return false;
     }
     if ($post['end_time'] < $post['start_time']) {
         $this->_error('start_not_gt_end');
         return false;
     }
     if (($post['goods_id'] = intval($post['goods_id'])) == 0) {
         $this->_error('fill_goods');
         return false;
     }
     if ($id == 0 && $this->_promotion_mod->get(array('conditions' => 'goods_id=' . $post['goods_id']))) {
         $this->_error('goods_has_set_promotion');
         return false;
     }
     if (empty($post['spec_id']) || !is_array($post['spec_id'])) {
         $this->_error('fill_spec');
         return false;
     }
     $spec_id_yx = array();
     //print_r($post['spec_id']);exit;
     foreach ($post['spec_id'] as $key => $val) {
         if (empty($post['pro_price' . $val])) {
             $this->_error('invalid_pro_price');
             return false;
         }
         $spec_id_yx[] = $val;
         $spec_price[$val] = array('price' => $post['pro_price' . $val], 'pro_type' => $post['pro_type' . $val], 'is_pro' => 1);
     }
     // 取得所有 spec_id,对未设置的进行处理
     $goods_info = $this->_query_goods_info($post['goods_id']);
     foreach ($goods_info['_specs'] as $spec) {
         if (!in_array($spec['spec_id'], $spec_id_yx)) {
             $spec_price[$spec['spec_id']] = array('is_pro' => 0);
             // 设置未选中的 spec_id
         }
     }
     //print_r($spec_price);exit;
     $data = array('pro_name' => $post['pro_name'], 'pro_desc' => $post['pro_desc'], 'start_time' => $post['start_time'], 'end_time' => $post['end_time'] - 1, 'goods_id' => $post['goods_id'], 'spec_price' => serialize($spec_price), 'store_id' => $this->_store_id);
     if ($id > 0) {
         $this->_promotion_mod->edit($id, $data);
         if ($this->_promotion_mod->has_error()) {
             $this->_error($this->_promotion_mod->get_error());
             return false;
         }
     } else {
         if (!($id = $this->_promotion_mod->add($data))) {
             $this->_error($this->_promotion_mod->get_error());
             return false;
         }
     }
     $this->_last_update_id = $id;
     return true;
 }