/**
  * 获取促销页
  * @param $site_id
  * return array
  */
 public function get_promotion_page_by_site_id($site_id)
 {
     $promotion_activity_sercice = Mypromotion_activity::instance();
     $request_struct = array('where' => array('site_id' => $site_id, 'disabled' => 0));
     $promotion_activity = $promotion_activity_sercice->lists($request_struct);
     return $promotion_activity;
 }
Exemple #2
0
 public function do_edit()
 {
     // 收集请求数据
     $request_data = $this->input->post();
     $session = Session::instance();
     $session->set_flash('sessionErrorData', $request_data);
     //标签过滤
     tool::filter_strip_tags($request_data);
     $pmts_id = $this->input->post('pmts_id');
     $promotion = Mypromotion::instance($request_data['id'])->get();
     if (!$promotion['id']) {
         remind::set(Kohana::lang('o_global.bad_request'), request::referrer(), 'error');
     }
     //促销规则时间效验
     if (strtotime($request_data['time_end']) + 24 * 3600 < time()) {
         remind::set(Kohana::lang('o_promotion.time_end'), request::referrer(), 'error');
     }
     if (strtotime($request_data['time_begin']) > strtotime($request_data['time_end'])) {
         remind::set(Kohana::lang('o_promotion.begin_time_over_end'), request::referrer(), 'error');
     }
     $dayTimeStamp = 24 * 3600;
     $request_data['time_end'] = date('Y-m-d H:i:s', strtotime($request_data['time_end']) + $dayTimeStamp);
     $time_begin = strtotime($request_data['time_begin']);
     $time_end = strtotime($request_data['time_end']);
     //促销规则时间必须在促销活动时间内
     $promotion_activity = Mypromotion_activity::instance($promotion['pmta_id'])->get();
     if (!$promotion_activity['id']) {
         remind::set(Kohana::lang('o_global.access_denied'), request::referrer(), 'error');
     }
     $pmta_time_begin = strtotime($promotion_activity['pmta_time_begin']);
     $pmta_time_end = strtotime($promotion_activity['pmta_time_end']);
     if ($pmta_time_begin > $time_begin || $pmta_time_end < $time_end) {
         remind::set(Kohana::lang('o_promotion.promotion_out_time_range'), request::referrer(), 'error');
     }
     //验证打折值与订单优惠条件
     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['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_quantitys_error'), request::referrer(), 'error');
     }
     $moneyError = '';
     // extra process needed for IDs
     switch ($pmts_id) {
         case 5:
             // get_gifts_buy_anything
         // get_gifts_buy_anything
         case 6:
             // get_gifts_price_morethan
             $moneyError = '订单金额错误';
             $gift_related_ids = $this->input->post('gift_related_ids');
             if (empty($gift_related_ids)) {
                 remind::set(Kohana::lang('o_promotion.select_gift'), request::referrer(), 'error');
             }
             $request_data['gift_related_ids'] = Mypromotion::enclose_ids($gift_related_ids, ',');
             break;
         case 1:
             // discount_category
             $related_ids = $this->input->post('related_ids');
             if (empty($related_ids)) {
                 remind::set(Kohana::lang('o_promotion.select_cpn_category'), request::referrer(), 'error');
             }
             empty($moneyError) && ($moneyError = '订单金额错误');
         case 2:
             // discount_product_during
             empty($moneyError) && ($moneyError = '订单金额错误');
         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
             if (!isset($related_ids)) {
                 $related_ids = $this->input->post('related_ids');
             }
             if (empty($related_ids)) {
                 remind::set(Kohana::lang('o_promotion.select_product'), request::referrer(), 'error');
             }
             // enclose selected category ids with comma
             $request_data['related_ids'] = Mypromotion::enclose_ids($related_ids, ',');
             break;
         case 7:
             // get_gifts_product_price_morethan
             $related_ids = $this->input->post('related_ids');
             $gift_related_ids = $this->input->post('gift_related_ids');
             empty($moneyError) && ($moneyError = '货品金额错误');
             if (empty($related_ids)) {
                 remind::set(Kohana::lang('o_promotion.select_product'), request::referrer(), 'error');
             }
             if (empty($gift_related_ids)) {
                 remind::set(Kohana::lang('o_promotion.select_gift'), request::referrer(), 'error');
             }
             // enclose selected category ids with comma
             $request_data['related_ids'] = Mypromotion::enclose_ids($related_ids, ',');
             $request_data['gift_related_ids'] = Mypromotion::enclose_ids($gift_related_ids, ',');
             break;
         case 8:
             // get_1_buy_n
             break;
         case 9:
             // get_another_cat_buy_cat
             $related_ids = $this->input->post('related_ids');
             $gift_related_ids = $this->input->post('gift_related_ids');
             if (empty($related_ids)) {
                 remind::set(Kohana::lang('o_promotion.select_cpn_category'), request::referrer(), 'error');
             }
             if (empty($gift_related_ids)) {
                 remind::set(Kohana::lang('o_promotion.select_gift_category'), request::referrer(), 'error');
             }
             // separate selected category ids with comma
             $request_data['related_ids'] = Mypromotion::enclose_ids($related_ids, ',');
             $request_data['gift_related_ids'] = Mypromotion::enclose_ids($gift_related_ids, ',');
             break;
         case 10:
             // get_catgift_price_morethan
             $gift_related_ids = $this->input->post('gift_related_ids');
             empty($moneyError) && ($moneyError = '订单金额错误');
             if (empty($gift_related_ids)) {
                 remind::set(Kohana::lang('o_promotion.select_gift_category'), request::referrer(), 'error');
             }
             // separate selected category ids with comma
             $request_data['gift_related_ids'] = Mypromotion::enclose_ids($gift_related_ids, ',');
             break;
         case 11:
             empty($moneyError) && ($moneyError = '购物车金额错误');
             break;
         case 14:
             empty($moneyError) && ($moneyError = '订单金额错误');
             break;
     }
     //验证
     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($moneyError, request::referrer(), 'error');
     }
     if (Mypromotion::instance()->edit($request_data)) {
         $session->delete('sessionErrorData');
         //promotion::delete_memcache($promotion['site_id']);
         remind::set(Kohana::lang('o_global.update_success'), "promotion/promotion_activity", 'success');
     } else {
         remind::set(Kohana::lang('o_global.update_error'), request::referrer(), 'error');
     }
 }
 public function do_delete_all()
 {
     role::check('promotion_promotion');
     $promotion_activity_id_array = $this->input->post('id');
     if (!(is_array($promotion_activity_id_array) && count($promotion_activity_id_array))) {
         remind::set(Kohana::lang('o_promotion.select_activity'), request::referrer(), 'error');
     }
     $count = 0;
     $false_count = 0;
     foreach ($promotion_activity_id_array as $id) {
         // 验证 - 数据有效性
         $pa = Mypromotion_activity::instance($id);
         $promotion_activity = $pa->get();
         if (!$promotion_activity['id']) {
             $false_count++;
             continue;
         }
         if ($pa->delete()) {
             //promotion::delete_memcache($promotion_activity['site_id']);
             $count++;
         } else {
             $false_count++;
         }
     }
     if ($false_count) {
         remind::set(Kohana::lang('o_promotion.have') . $false_count . Kohana::lang('o_promotion.num_activity_cannot_delete'), request::referrer(), 'error');
     } else {
         remind::set(Kohana::lang('o_promotion.success_delete') . $count . Kohana::lang('o_promotion.num_activity'), request::referrer(), 'success');
     }
 }