Ejemplo n.º 1
0
 /**
  * 用于提交emailafriend时给自己发送邮件
  * @param $email   自己的邮件地址
  * @param $title_param   标题变量
  * @param $content_param 内容变量
  */
 public static function email_to_me($email, $title_param, $content_param)
 {
     $site_id = Mysite::instance()->id();
     //判断是否生成打折号并取得打折号的折扣信息
     $config = Mycoupon::instance()->is_generate_discount_num('email_to_me');
     if (!empty($config)) {
         $discount_info = Mycoupon::instance()->get_discount_number($config);
     }
     //设置打折信息
     $param_data = array();
     if (!empty($discount_info)) {
         $param_data = array('{discount_num}' => $discount_info['discount_num'], '{expiration_date}' => $discount_info['expiration_date'], '{discount_value}' => $discount_info['discount_value']);
     }
     //判断取得的模板类型
     $mail_type = 'email_to_me';
     if (empty($param_data)) {
         $mail_type = 'email_to_meNoDiscountNumber';
     }
     $content_param = array_merge($content_param, $param_data);
     //发送邮件
     $from_mail = '';
     $to_mail = $email;
     self::send_mail(1, $mail_type, $to_mail, $from_mail, $title_param, $content_param);
 }
Ejemplo n.º 2
0
 /**
  * Generate multiple coupon codes
  * 
  * @param Integer $coupon_id
  * @param Integer $quantity
  * @return Array|Boolean
  */
 public function gen_coupons($coupon_id, $quantity)
 {
     $coupon = Mycoupon::instance($coupon_id)->get();
     if (!$coupon['id']) {
         return $false;
     }
     $coupons = array();
     if ($coupon['cpn_type'] == 'A') {
         $end = $coupon['cpn_gen_quantity'] + $quantity;
         for ($i = $coupon['cpn_gen_quantity'] + 1; $i <= $end; $i++) {
             $coupons[] = $this->generate_coupon($coupon['cpn_type'], $coupon['cpn_prefix'], $coupon['cpn_key'], $i);
         }
     } else {
         $end = 1;
         $coupons[] = $this->generate_coupon($coupon['cpn_type'], $coupon['cpn_prefix'], $coupon['cpn_key'], $end);
     }
     $coupon_orm = ORM::factory('coupon', $coupon_id);
     $coupon_orm->cpn_gen_quantity = $end;
     $coupon_orm->save();
     return $coupons;
 }
Ejemplo n.º 3
0
 public function do_delete_all()
 {
     role::check('promotion_coupon');
     $coupon_id_array = $this->input->post('id');
     if (!(is_array($coupon_id_array) && count($coupon_id_array))) {
         remind::set(Kohana::lang('o_promotion.select_cpn'), request::referrer(), 'error');
     }
     $count = 0;
     $false_count = 0;
     foreach ($coupon_id_array as $key => $coupon_id) {
         // 验证 - 数据有效性
         $coupon = Mycoupon::instance($coupon_id)->get();
         if (!$coupon['id']) {
             $false_count++;
             continue;
         }
         if (Mycoupon::instance()->delete($coupon_id)) {
             $count++;
         } else {
             $false_count++;
         }
     }
     if ($false_count) {
         remind::set(Kohana::lang('o_promotion.have') . $false_count . Kohana::lang('o_promotion.num_cpn_cannot_delete'), request::referrer(), 'error');
     } else {
         remind::set(Kohana::lang('o_promotion.success_delete') . $count . Kohana::lang('o_promotion.num_cpn'), request::referrer(), 'success');
     }
 }
Ejemplo n.º 4
0
 public function do_edit()
 {
     role::check('promotion_coupon');
     // 收集请求数据
     $request_data = $this->input->post();
     $session = Session::instance();
     $session->set_flash('sessionErrorData', $request_data);
     //标签过滤
     tool::filter_strip_tags($request_data);
     $cpn_promotion = Mycpn_promotion::instance($request_data['id'])->get();
     $cpns_id = $cpn_promotion['cpns_id'];
     if (!$cpn_promotion['id']) {
         remind::set(Kohana::lang('o_global.update_error'), request::referrer(), 'error');
     }
     //时间处理
     if (strtotime($request_data['time_end']) < strtotime($request_data['time_begin'])) {
         remind::set(Kohana::lang('o_promotion.begin_time_over_end'), request::referrer(), 'error');
     }
     $request_data['time_end'] = date("Y-m-d H:i:s", strtotime($request_data['time_end']) + 24 * 3600);
     //促销规则时间必须在促销活动时间内
     $coupon = Mycoupon::instance($request_data['cpn_id'])->get();
     //var_dump($coupon);exit;
     if (!$coupon['id']) {
         remind::set(Kohana::lang('o_global.access_denied'), request::referrer(), 'error');
     }
     $cpn_time_begin = strtotime($coupon['cpn_time_begin']);
     $cpn_time_end = strtotime($coupon['cpn_time_end']);
     if ($cpn_time_begin > strtotime($request_data['time_begin']) || $cpn_time_end < strtotime($request_data['time_end'])) {
         remind::set(Kohana::lang('o_promotion.cpn_out_time_range'), request::referrer(), 'error');
     }
     // extra process needed for IDs
     //验证打折值与订单优惠条件
     if (isset($request_data['discount_type'])) {
         if (isset($request_data['price']) && (!preg_match('/^\\d{1,12}(\\.\\d{0,3})?$/', $request_data['price']) || $request_data['price'] < 0)) {
             remind::set(Kohana::lang('o_promotion.cpn_price_error'), request::referrer(), 'error');
         }
         if ($request_data['discount_type'] == 0 && $request_data['price'] > 1) {
             remind::set(Kohana::lang('o_promotion.cpn_price_error'), request::referrer(), 'error');
         }
     }
     if (isset($request_data['money_from']) && (!preg_match('/^\\d{1,12}(\\.\\d{0,3})?$/', $request_data['money_from']) || $request_data['money_from'] < 0) || isset($request_data['money_to']) && (!preg_match('/^\\d{1,12}(\\.\\d{0,3})?$/', $request_data['money_to']) || $request_data['money_to'] < 0) || isset($request_data['money_from']) && $request_data['money_from'] >= $request_data['money_to']) {
         remind::set(Kohana::lang('o_promotion.cpn_money_error'), request::referrer(), 'error');
     }
     if (isset($request_data['quantity_from']) && (!preg_match('/^\\d+$/', $request_data['quantity_from']) || $request_data['quantity_from'] < 0) || isset($request_data['quantity_to']) && (!preg_match('/^\\d+$/', $request_data['quantity_to']) || $request_data['quantity_to'] < 0) || isset($request_data['quantity_from']) && $request_data['quantity_from'] >= $request_data['quantity_to']) {
         remind::set(Kohana::lang('o_promotion.buy_quantity_error'), request::referrer(), 'error');
     }
     switch ($cpns_id) {
         case 3:
             // discount_cart_user_buy
             isset($info) || ($info = "请选择用户");
         case 4:
             // discount_cart_buy_product
             isset($info) || ($info = "请选择货品");
         case 5:
             // discount_category
             isset($info) || ($info = "请选择分类");
             $related_ids = $this->input->post('related_ids');
             if (empty($related_ids)) {
                 remind::set($info, request::referrer(), 'error');
             }
             // enclose selected category ids with comma
             $request_data['related_ids'] = Mycpn_promotion::enclose_ids($related_ids, ',');
             break;
     }
     //print_r($request_data);exit;
     if ($promotion_id = Mycpn_promotion::instance()->edit($request_data)) {
         $session->delete('sessionErrorData');
         remind::set(Kohana::lang('o_global.update_success'), "promotion/coupon", 'success');
     } else {
         remind::set(Kohana::lang('o_global.update_error'), request::referrer(), 'error');
     }
 }