Ejemplo n.º 1
0
 public function add()
 {
     global $user_info;
     $ajax = intval($_REQUEST['ajax']);
     if (!$user_info) {
         showErr($GLOBALS['lang']['PLEASE_LOGIN_FIRST'], $ajax);
     }
     if ($_REQUEST['content'] == '') {
         showErr($GLOBALS['lang']['MESSAGE_CONTENT_EMPTY'], $ajax);
     }
     if (!check_ipop_limit(get_client_ip(), "message", intval(app_conf("SUBMIT_DELAY")), 0)) {
         showErr($GLOBALS['lang']['MESSAGE_SUBMIT_FAST'], $ajax);
     }
     $rel_table = addslashes(trim($_REQUEST['rel_table']));
     $message_type = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "message_type where type_name='" . $rel_table . "' and type_name <> 'supplier'");
     if (!$message_type) {
         showErr($GLOBALS['lang']['INVALID_MESSAGE_TYPE'], $ajax);
     }
     $message_group = addslashes(trim($_REQUEST['message_group']));
     //添加留言
     $message['title'] = $_REQUEST['title'] ? htmlspecialchars(addslashes(valid_str($_REQUEST['title']))) : htmlspecialchars(addslashes(valid_str($_REQUEST['content'])));
     $message['content'] = htmlspecialchars(addslashes(valid_str($_REQUEST['content'])));
     $message['title'] = valid_str($message['title']);
     if ($message_group) {
         $message['title'] = "[" . $message_group . "]:" . $message['title'];
         $message['content'] = "[" . $message_group . "]:" . $message['content'];
     }
     $message['create_time'] = get_gmtime();
     $message['rel_table'] = $rel_table;
     $rel_id = $message['rel_id'] = addslashes(trim($_REQUEST['rel_id']));
     $message['user_id'] = intval($GLOBALS['user_info']['id']);
     if (intval($_REQUEST['city_id']) == 0) {
         $message['city_id'] = $GLOBALS['deal_city']['id'];
     } else {
         $message['city_id'] = intval($_REQUEST['city_id']);
     }
     if (app_conf("USER_MESSAGE_AUTO_EFFECT") == 0) {
         $message_effect = 0;
     } else {
         $message_effect = $message_type['is_effect'];
     }
     $message['is_effect'] = $message_effect;
     $message['is_buy'] = intval($_REQUEST['is_buy']);
     $message['contact'] = $_REQUEST['contact'] ? htmlspecialchars(addslashes($_REQUEST['contact'])) : '';
     $message['contact_name'] = $_REQUEST['contact_name'] ? htmlspecialchars(addslashes($_REQUEST['contact_name'])) : '';
     if ($message['is_buy'] == 1) {
         if ($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_order_item as doi left join " . DB_PREFIX . "deal_order as do on doi.order_id = do.id where doi.deal_id = " . intval($message['rel_id']) . " and do.user_id = " . intval($message['user_id']) . " and do.pay_status = 2") == 0) {
             showErr($GLOBALS['lang']['AFTER_BUY_MESSAGE_TIP'], $ajax);
         }
     }
     $message['point'] = intval($_REQUEST['point']);
     $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $message);
     $message_id = intval($GLOBALS['db']->insert_id());
     if ($message['is_buy'] == 1) {
         $message_id = $GLOBALS['db']->insert_id();
         $attach_list = get_topic_attach_list();
         $deal_info = $GLOBALS['db']->getRow("select id,is_shop,name,sub_name from " . DB_PREFIX . "deal where id = " . $rel_id);
         if ($deal_info['is_shop'] == 0) {
             $url_route = array('rel_app_index' => 'tuan', 'rel_route' => 'deal', 'rel_param' => 'id=' . $deal_info['id']);
             $type = "tuancomment";
             $locations = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_location_link where deal_id = " . $deal_info['id']);
             $dp_title = "对" . $deal_info['sub_name'] . "的消费点评";
             foreach ($locations as $location) {
                 insert_dp($dp_title, $message['content'], $location['location_id'], $message['point'], $is_buy = 1, $from = "tuan", $url_route, $message_id);
             }
         }
         if ($deal_info['is_shop'] == 1) {
             $url_route = array('rel_app_index' => 'shop', 'rel_route' => 'goods', 'rel_param' => 'id=' . $deal_info['id']);
             $type = "shopcomment";
         }
         if ($deal_info['is_shop'] == 2) {
             $url_route = array('rel_app_index' => 'youhui', 'rel_route' => 'ydetail', 'rel_param' => 'id=' . $deal_info['id']);
             $type = "youhuicomment";
         }
         increase_user_active(intval($GLOBALS['user_info']['id']), "点评了一个团购");
         $title = "对" . $deal_info['sub_name'] . "发表了点评";
         $tid = insert_topic($message['content'], $title, $type, "share", $relay_id = 0, $fav_id = 0, $group_data = "", $attach_list = array(), $url_route);
         if ($tid) {
             $GLOBALS['db']->query("update " . DB_PREFIX . "topic set source_name = '网站' where id = " . intval($tid));
         }
     }
     showSuccess($GLOBALS['lang']['MESSAGE_POST_SUCCESS'], $ajax);
 }
Ejemplo n.º 2
0
 public function add()
 {
     $ajax = intval($_REQUEST['ajax']);
     if (!$GLOBALS['user_info']) {
         showErr($GLOBALS['lang']['PLEASE_LOGIN_FIRST'], $ajax);
     }
     if ($_REQUEST['content'] == '') {
         showErr($GLOBALS['lang']['MESSAGE_CONTENT_EMPTY'], $ajax);
     }
     //验证码
     if (app_conf("VERIFY_IMAGE") == 1) {
         $verify = md5(trim($_REQUEST['verify']));
         $session_verify = es_session::get('verify');
         if ($verify != $session_verify) {
             showErr($GLOBALS['lang']['VERIFY_CODE_ERROR'], $ajax);
         }
     }
     es_session::delete("verify");
     if (!check_ipop_limit(get_client_ip(), "message", intval(app_conf("SUBMIT_DELAY")), 0)) {
         showErr($GLOBALS['lang']['MESSAGE_SUBMIT_FAST'], $ajax);
     }
     $rel_table = $_REQUEST['rel_table'];
     //		$message_type = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."message_type where type_name='".$rel_table."' and type_name <> 'supplier'");
     //		if(!$message_type)
     //		{
     //			showErr($GLOBALS['lang']['INVALID_MESSAGE_TYPE'],$ajax);
     //		}
     $message_group = $_REQUEST['message_group'];
     //添加留言
     $message['title'] = $_REQUEST['title'] ? htmlspecialchars(addslashes(valid_str($_REQUEST['title']))) : htmlspecialchars(addslashes(valid_str($_REQUEST['content'])));
     $message['content'] = htmlspecialchars(addslashes(valid_str($_REQUEST['content'])));
     $message['title'] = valid_str($message['title']);
     if ($message_group) {
         $message['title'] = "[" . $message_group . "]:" . $message['title'];
         $message['content'] = "[" . $message_group . "]:" . $message['content'];
     }
     $message['create_time'] = get_gmtime();
     $message['rel_table'] = $rel_table;
     $rel_id = $message['rel_id'] = intval($_REQUEST['rel_id']);
     $message['user_id'] = intval($GLOBALS['user_info']['id']);
     if (isset($_REQUEST['is_effect'])) {
         $message_effect = intval($_REQUEST['is_effect']);
     } else {
         if (app_conf("USER_MESSAGE_AUTO_EFFECT") == 0) {
             $message_effect = 0;
         } else {
             $message_effect = $message_type['is_effect'];
         }
     }
     $message['is_effect'] = $message_effect;
     $message['is_buy'] = intval($_REQUEST['is_buy']);
     $message['contact'] = $_REQUEST['contact'] ? htmlspecialchars(addslashes($_REQUEST['contact'])) : '';
     $message['contact_name'] = $_REQUEST['contact_name'] ? htmlspecialchars(addslashes($_REQUEST['contact_name'])) : '';
     if ($message['is_buy'] == 1) {
         if ($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_order_item as doi left join " . DB_PREFIX . "deal_order as do on doi.order_id = do.id where doi.deal_id = " . intval($message['rel_id']) . " and do.user_id = " . intval($message['user_id']) . " and do.pay_status = 2") == 0) {
             showErr($GLOBALS['lang']['AFTER_BUY_MESSAGE_TIP'], $ajax);
         }
     }
     $message['point'] = intval($_REQUEST['point']);
     $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $message);
     $message_id = $GLOBALS['db']->insert_id();
     if ($message['is_buy'] == 1) {
         $deal_info = $GLOBALS['db']->getRow("select id,is_shop,name,sub_name from " . DB_PREFIX . "deal where id = " . $rel_id);
         if ($deal_info) {
             $attach_list = get_topic_attach_list();
             if ($deal_info['is_shop'] == 0) {
                 $url_route = array('rel_app_index' => 'tuan', 'rel_route' => 'deal', 'rel_param' => 'id=' . $deal_info['id']);
                 $type = "tuancomment";
                 $locations = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_location_link where deal_id = " . intval($deal_info['id']));
                 $dp_title = "对" . $deal_info['sub_name'] . "的消费点评";
                 foreach ($locations as $location) {
                     insert_dp($dp_title, $message['content'], $location['location_id'], $message['point'], $is_buy = 1, $from = "tuan", $url_route, $message_id);
                 }
             }
             if ($deal_info['is_shop'] == 1) {
                 $url_route = array('rel_app_index' => 'shop', 'rel_route' => 'goods', 'rel_param' => 'id=' . $deal_info['id']);
                 $type = "shopcomment";
                 $locations = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_location_link where deal_id = " . intval($deal_info['id']));
                 $dp_title = "对" . $deal_info['sub_name'] . "的消费点评";
                 foreach ($locations as $location) {
                     insert_dp($dp_title, $message['content'], $location['location_id'], $message['point'], $is_buy = 1, $from = "shop", $url_route, $message_id);
                 }
             }
             if ($deal_info['is_shop'] == 2) {
                 $url_route = array('rel_app_index' => 'youhui', 'rel_route' => 'ydetail', 'rel_param' => 'id=' . $deal_info['id']);
                 $type = "youhuicomment";
                 $locations = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_location_link where deal_id = " . intval($deal_info['id']));
                 $dp_title = "对" . $deal_info['sub_name'] . "的消费点评";
                 foreach ($locations as $location) {
                     insert_dp($dp_title, $message['content'], $location['location_id'], $message['point'], $is_buy = 1, $from = "daijin", $url_route, $message_id);
                 }
             }
             increase_user_active(intval($GLOBALS['user_info']['id']), "点评了一个商品");
             $title = "对" . $deal_info['sub_name'] . "发表了点评";
             $tid = insert_topic($message['content'], $title, $type, $group = "", $relay_id = 0, $fav_id = 0, $group_data = "", $attach_list = array(), $url_route);
             if ($tid) {
                 $GLOBALS['db']->query("update " . DB_PREFIX . "topic set source_name = '网站' where id = " . intval($tid));
             }
         }
     }
     if ($message['rel_table'] == 'youhui') {
         $youhui_info = $GLOBALS['db']->getRow("select name,id from " . DB_PREFIX . "youhui where id = " . $rel_id);
         if ($youhui_info) {
             increase_user_active(intval($GLOBALS['user_info']['id']), "点评了一个优惠券");
             $title = "对" . $youhui_info['name'] . "发表了点评";
             $url_route = array('rel_app_index' => 'youhui', 'rel_route' => 'fdetail', 'rel_param' => 'id=' . $youhui_info['id']);
             $tid = insert_topic($message['content'], $title, "fyouhuicomment", $group = "", $relay_id = 0, $fav_id = 0, $group_data = "", $attach_list = array(), $url_route);
             if ($tid) {
                 $GLOBALS['db']->query("update " . DB_PREFIX . "topic set source_name = '网站' where id = " . intval($tid));
             }
             $locations = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "youhui_location_link where youhui_id = " . intval($youhui_info['id']));
             $dp_title = "对" . $youhui_info['name'] . "的点评";
             foreach ($locations as $location) {
                 insert_dp($dp_title, $message['content'], $location['location_id'], 3, $is_buy = 0, $from = "youhui", $url_route, $message_id);
             }
         }
     }
     if ($message['rel_table'] == 'event') {
         $event_info = $GLOBALS['db']->getRow("select name,id from " . DB_PREFIX . "event where id = " . $rel_id);
         if ($event_info) {
             increase_user_active(intval($GLOBALS['user_info']['id']), "点评了一个活动");
             $title = "对" . $event_info['name'] . "发表了点评";
             $url_route = array('rel_app_index' => 'youhui', 'rel_route' => 'edetail', 'rel_param' => 'id=' . $event_info['id']);
             $tid = insert_topic($message['content'], $title, "eventcomment", $group = "", $relay_id = 0, $fav_id = 0, $group_data = "", $attach_list = array(), $url_route);
             if ($tid) {
                 $GLOBALS['db']->query("update " . DB_PREFIX . "topic set source_name = '网站' where id = " . intval($tid));
             }
             $GLOBALS['db']->query("update " . DB_PREFIX . "event set reply_count = reply_count+1 where id =" . $rel_id);
             $locations = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "event_location_link where event_id = " . intval($event_info['id']));
             $dp_title = "对" . $event_info['name'] . "的点评";
             foreach ($locations as $location) {
                 insert_dp($dp_title, $message['content'], $location['location_id'], 3, $is_buy = 0, $from = "event", $url_route, $message_id);
             }
         }
     }
     if ($message['rel_table'] == 'supplier_location') {
         $supplier_info = $GLOBALS['db']->getRow("select name,id from " . DB_PREFIX . "supplier_location where id = " . $rel_id);
         if ($supplier_info) {
             increase_user_active(intval($GLOBALS['user_info']['id']), "点评了一家商户");
             $title = "对" . $supplier_info['name'] . "发表了点评";
             $url_route = array('rel_app_index' => 'youhui', 'rel_route' => 'store#view', 'rel_param' => 'id=' . $supplier_info['id']);
             $tid = insert_topic($message['content'], $title, "slocationcomment", $group = "", $relay_id = 0, $fav_id = 0, $group_data = "", $attach_list = array(), $url_route);
             if ($tid) {
                 $GLOBALS['db']->query("update " . DB_PREFIX . "topic set source_name = '网站' where id = " . intval($tid));
             }
         }
     }
     //开始处理为deal时的计分
     if ($rel_table == 'deal') {
         $total_point = $GLOBALS['db']->getOne("select sum(point) from " . DB_PREFIX . "message where rel_table = 'deal' and rel_id = " . intval($_REQUEST['rel_id']));
         $total_comment = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "message where rel_table = 'deal' and rel_id = " . intval($_REQUEST['rel_id']));
         $avg_point = round($total_point / $total_comment);
         $GLOBALS['db']->query("update " . DB_PREFIX . "deal set total_point = " . $total_point . ",avg_point = " . $avg_point . " where id =" . intval($_REQUEST['rel_id']));
     }
     showSuccess($GLOBALS['lang']['MESSAGE_POST_SUCCESS'], $ajax);
 }