/** * 提交保存点评 * @param unknown_type $user_id 提交点评的会员 * @param unknown_type $param 参数 详细规则见 check_dp_status函数说明 * @param unknown_type $content 点评文字内容 * @param unknown_type $dp_point 总评分 * @param unknown_type $dp_image 点评的图片数组 array("./public/...","./public/....."); * @param unknown_type $tag_group 点评标签(二维数组),格式如下 * array( * "group_id" = array("tag","tag") * ); 其中group_id为分组的ID,第二维为每个分组中的tag * @param unknown_type $point_group 点评评分分组数据,格式如下 * array( * "group_id" => "point" * ); 其中group_id为分组的ID,point为对应分组的评分 * * 返回 array("status"=>bool, "info"=>"消息","location_id"=>"门店的ID","deal_id"=>"","youhui_id"=>"","event_id"=>""); */ function save_review($user_id, $param = array("deal_id" => 0, "youhui_id" => 0, "event_id" => 0, "location_id" => 0, "order_item_id" => 0, "youhui_log_id" => 0, "event_submit_id" => 0), $content, $dp_point, $dp_image = array(), $tag_group = array(), $point_group = array()) { //获取参数 $order_item_id = intval($param['order_item_id']); //订单商品ID $youhui_log_id = intval($param['youhui_log_id']); //优惠券领取日志ID $event_submit_id = intval($param['event_submit_id']); //活动报名日志ID if ($order_item_id > 0) { $deal_id = intval($GLOBALS['db']->getOne("select deal_id from " . DB_PREFIX . "deal_order_item where id = " . $order_item_id)); } else { $deal_id = intval($param['deal_id']); } if ($youhui_log_id > 0) { $youhui_id = intval($GLOBALS['db']->getOne("select youhui_id from " . DB_PREFIX . "youhui_log where id = " . $youhui_log_id)); } else { $youhui_id = intval($param['youhui_id']); } if ($event_submit_id > 0) { $event_id = intval($GLOBALS['db']->getOne("select event_id from " . DB_PREFIX . "event_submit where id = " . $event_submit_id)); } else { $event_id = intval($param['event_id']); } $location_id = intval($param['location_id']); //部份初始化的变量 $is_buy = 0; //默认的点评为非购物点评 $avg_price = 0; //均价为0 if ($deal_id > 0) { require_once APP_ROOT_PATH . "system/model/deal.php"; $deal_info = get_deal($deal_id); if ($deal_info) { //验证是否可以点评 $checker = check_dp_status($GLOBALS['user_info']['id'], array("deal_id" => $deal_id, "order_item_id" => $order_item_id)); if (!$checker['status']) { return array("status" => false, "info" => $checker['info']); } else { $supplier_location_id = $checker['supplier_location_id']; } $is_buy = 1; $avg_price = $checker['avg_price']; } else { return array("status" => false, "info" => "你要点评的商品不存在"); } } elseif ($youhui_id > 0) { require_once APP_ROOT_PATH . "system/model/youhui.php"; $youhui_info = get_youhui($youhui_id); if ($youhui_info) { //验证是否可以点评 $checker = check_dp_status($GLOBALS['user_info']['id'], array("youhui_id" => $youhui_id, "youhui_log_id" => $youhui_log_id)); if (!$checker['status']) { return array("status" => false, "info" => $checker['info']); } else { $supplier_location_id = $checker['supplier_location_id']; } } else { return array("status" => false, "info" => "你要点评的优惠券不存在"); } } elseif ($event_id > 0) { require_once APP_ROOT_PATH . "system/model/event.php"; $event_info = get_event($event_id); if ($event_info) { //验证是否可以点评 $checker = check_dp_status($GLOBALS['user_info']['id'], array("event_id" => $event_id, "event_submit_id" => $event_submit_id)); if (!$checker['status']) { return array("status" => false, "info" => $checker['info']); } else { $supplier_location_id = $checker['supplier_location_id']; } } else { return array("status" => false, "info" => "你要点评的活动不存在"); } } elseif ($location_id > 0) { require_once APP_ROOT_PATH . "system/model/supplier.php"; $location_info = get_location($location_id); if ($location_info) { //验证是否可以点评 $checker = check_dp_status($GLOBALS['user_info']['id'], array("location_id" => $location_id)); if (!$checker['status']) { return array("status" => false, "info" => $checker['info']); } else { $supplier_location_id = $checker['supplier_location_id']; } } else { return array("status" => false, "info" => "你要点评的商家不存在"); } } if ($deal_id == 0 && $youhui_id == 0 && $event_id == 0 && $location_id == 0) { return array("status" => false, "info" => "非法的数据"); } //点评入库 $supplier_info = $GLOBALS['db']->getRow("select name,id,new_dp_count_time,supplier_id from " . DB_PREFIX . "supplier_location where id = " . intval($supplier_location_id)); $supplier_id = $supplier_info['supplier_id']; $dp_data = array(); if ($content != "") { $dp_data['is_content'] = 1; $dp_data['content'] = $content; } $dp_data['create_time'] = NOW_TIME; $dp_data['point'] = $dp_point; $dp_data['user_id'] = $user_id; $dp_data['supplier_location_id'] = $supplier_location_id; $dp_data['youhui_id'] = $youhui_id; $dp_data['event_id'] = $event_id; $dp_data['deal_id'] = $deal_id; $dp_data['images_cache'] = serialize($dp_image); $dp_data['supplier_id'] = $supplier_id; $dp_data['status'] = 1; if (count($dp_image) > 0) { $dp_data['is_img'] = 1; } $dp_data['avg_price'] = floatval($avg_price); $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp", $dp_data, "INSERT"); $dp_id = $GLOBALS['db']->insert_id(); if ($dp_id > 0) { if ($checker['order_item_id']) { $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set dp_id = " . $dp_id . " where id = '" . $checker['order_item_id'] . "'"); $order_id = intval($GLOBALS['db']->getOne("select order_id from " . DB_PREFIX . "deal_order_item where id = " . $checker['order_item_id'])); update_order_cache($order_id); require_once APP_ROOT_PATH . "system/model/deal_order.php"; distribute_order($order_id); } if ($checker['youhui_log_id']) { $GLOBALS['db']->query("update " . DB_PREFIX . "youhui_log set dp_id = " . $dp_id . " where id = '" . $checker['youhui_log_id'] . "'"); } if ($checker['event_submit_id']) { $GLOBALS['db']->query("update " . DB_PREFIX . "event_submit set dp_id = " . $dp_id . " where id = '" . $checker['event_submit_id'] . "'"); } increase_user_active($user_id, "发表了一则点评"); $GLOBALS['db']->query("update " . DB_PREFIX . "user set dp_count = dp_count + 1 where id = " . $user_id); //创建点评图库 if (count($dp_image) > 0) { foreach ($dp_image as $pkey => $photo) { //点评图片不入商户图片库 // $c_data = array(); // $c_data['image'] = $photo; // $c_data['sort'] = 10; // $c_data['create_time'] = NOW_TIME; // $c_data['user_id'] = $user_id; // $c_data['supplier_location_id'] = $supplier_location_id; // $c_data['dp_id'] = $dp_id; // $c_data['status'] = 0; // $GLOBALS['db']->autoExecute(DB_PREFIX."supplier_location_images", $c_data,"INSERT"); $c_data = array(); $c_data['image'] = $photo; $c_data['dp_id'] = $dp_id; $c_data['create_time'] = NOW_TIME; $c_data['location_id'] = $supplier_location_id; $c_data['supplier_id'] = $supplier_id; $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp_images", $c_data, "INSERT"); } } //创建点评评分 foreach ($point_group as $group_id => $point) { $point_data = array(); $point_data['group_id'] = $group_id; $point_data['dp_id'] = $dp_id; $point_data['supplier_location_id'] = $supplier_location_id; $point_data['point'] = $point; $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp_point_result", $point_data, "INSERT"); //创建商品点评数据 if ($dp_data['deal_id'] > 0) { $point_data = array(); $point_data['group_id'] = $group_id; $point_data['dp_id'] = $dp_id; $point_data['deal_id'] = $dp_data['deal_id']; $point_data['point'] = $point; $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_dp_point_result", $point_data, "INSERT"); } //创建优惠券点评数据 if ($dp_data['youhui_id'] > 0) { $point_data = array(); $point_data['group_id'] = $group_id; $point_data['dp_id'] = $dp_id; $point_data['youhui_id'] = $dp_data['youhui_id']; $point_data['point'] = $point; $GLOBALS['db']->autoExecute(DB_PREFIX . "youhui_dp_point_result", $point_data, "INSERT"); } //创建活动点评数据 if ($dp_data['event_id'] > 0) { $point_data = array(); $point_data['group_id'] = $group_id; $point_data['dp_id'] = $dp_id; $point_data['event_id'] = $dp_data['event_id']; $point_data['point'] = $point; $GLOBALS['db']->autoExecute(DB_PREFIX . "event_dp_point_result", $point_data, "INSERT"); } } //创建点评分组的标签 foreach ($tag_group as $group_id => $tag_row_arr) { foreach ($tag_row_arr as $tag_row) { $tag_row_data = array(); $tag_row_data['tags'] = $tag_row; $tag_row_data['dp_id'] = $dp_id; $tag_row_data['supplier_location_id'] = $supplier_location_id; $tag_row_data['group_id'] = $group_id; $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp_tag_result", $tag_row_data, "INSERT"); insert_match_item($tag_row, "supplier_location_dp", $dp_id, "tags_match"); //更新点评的索引 review_supplier_location_match($supplier_location_id, $tag_row, $group_id); //创建商品点评数据 if ($dp_data['deal_id'] > 0) { $tag_row_data = array(); $tag_row_data['tags'] = $tag_row; $tag_row_data['dp_id'] = $dp_id; $tag_row_data['deal_id'] = $dp_data['deal_id']; $tag_row_data['group_id'] = $group_id; $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_dp_tag_result", $tag_row_data, "INSERT"); } //创建优惠券点评数据 if ($dp_data['youhui_id'] > 0) { $tag_row_data = array(); $tag_row_data['tags'] = $tag_row; $tag_row_data['dp_id'] = $dp_id; $tag_row_data['youhui_id'] = $dp_data['youhui_id']; $tag_row_data['group_id'] = $group_id; $GLOBALS['db']->autoExecute(DB_PREFIX . "youhui_dp_tag_result", $tag_row_data, "INSERT"); } //创建活动点评数据 if ($dp_data['event_id'] > 0) { $tag_row_data = array(); $tag_row_data['tags'] = $tag_row; $tag_row_data['dp_id'] = $dp_id; $tag_row_data['event_id'] = $dp_data['event_id']; $tag_row_data['group_id'] = $group_id; $GLOBALS['db']->autoExecute(DB_PREFIX . "event_dp_tag_result", $tag_row_data, "INSERT"); } } } //更新统计 syn_supplier_locationcount($supplier_info); cache_store_point($supplier_info['id']); //统计商品点评数据 if ($dp_data['deal_id'] > 0) { //计算总点评1-5星人数 $item_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . $dp_data['deal_id']); $sql = "select count(*) as total,point from " . DB_PREFIX . "supplier_location_dp where deal_id = " . $item_data['id'] . " group by point "; $data_result = $GLOBALS['db']->getAll($sql); foreach ($data_result as $k => $v) { $item_data['dp_count_' . $v['point']] = $v['total']; } $GLOBALS['db']->autoExecute(DB_PREFIX . "deal", $item_data, "UPDATE", " id = " . $item_data['id'] . " "); syn_deal_review_count($item_data['id']); } //创建优惠券点评数据 if ($dp_data['youhui_id'] > 0) { //计算总点评1-5星人数 $item_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "youhui where id = " . $dp_data['youhui_id']); $sql = "select count(*) as total,point from " . DB_PREFIX . "supplier_location_dp where youhui_id = " . $item_data['id'] . " group by point "; $data_result = $GLOBALS['db']->getAll($sql); foreach ($data_result as $k => $v) { $item_data['dp_count_' . $v['point']] = $v['total']; } $GLOBALS['db']->autoExecute(DB_PREFIX . "youhui", $item_data, "UPDATE", " id = " . $item_data['id'] . " "); syn_youhui_review_count($item_data['id']); } //创建活动点评数据 if ($dp_data['event_id'] > 0) { //计算总点评1-5星人数 $item_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "event where id = " . $dp_data['event_id']); $sql = "select count(*) as total,point from " . DB_PREFIX . "supplier_location_dp where event_id = " . $item_data['id'] . " group by point "; $data_result = $GLOBALS['db']->getAll($sql); foreach ($data_result as $k => $v) { $item_data['dp_count_' . $v['point']] = $v['total']; } $GLOBALS['db']->autoExecute(DB_PREFIX . "event", $item_data, "UPDATE", " id = " . $item_data['id'] . " "); syn_event_review_count($item_data['id']); } $return['location_id'] = $supplier_location_id; $return['deal_id'] = $dp_data['deal_id']; $return['youhui_id'] = $dp_data['youhui_id']; $return['event_id'] = $dp_data['event_id']; $return['status'] = 1; $return['info'] = "发表成功"; return $return; } else { $return['status'] = 0; $return['info'] = "数据库异常,提交失败"; return $return; } }
public function savereview() { $return["status"] = 0; if (!$GLOBALS['user_info']) { $return["status"] = 2; $return["message"] = $GLOBALS['LANG']["PLEASE_LOGIN_FIRST"]; ajax_return($return); exit; } //验证码 if (app_conf("VERIFY_IMAGE") == 1) { $verify = md5(trim($_REQUEST['verify'])); $session_verify = es_session::get('verify'); if ($verify != $session_verify) { $return["message"] = $GLOBALS['lang']['VERIFY_CODE_ERROR']; ajax_return($return); exit; } } es_session::delete("verify"); //创建基础点评数据 $dp_data = array(); $dp_data['title'] = addslashes(htmlspecialchars($_REQUEST['dp_title'])); $dp_data['content'] = addslashes(htmlspecialchars($_REQUEST['content'])); $dp_data['create_time'] = get_gmtime(); $dp_data['point'] = intval($_REQUEST['dp_point']); $dp_data['user_id'] = intval($GLOBALS['user_info']['id']); $dp_data['supplier_location_id'] = intval($_REQUEST['supplier_location_id']); $dp_data['status'] = 1; if (count($_REQUEST['pics']) > 0) { $dp_data['is_img'] = 1; } $dp_data['avg_price'] = floatval($_REQUEST['avg_price']); $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp", $dp_data, "INSERT"); $dp_id = $GLOBALS['db']->insert_id(); if ($dp_id > 0) { increase_user_active(intval($GLOBALS['user_info']['id']), "发表了一则商户点评"); $GLOBALS['db']->query("update " . DB_PREFIX . "user set dp_count = dp_count + 1 where id = " . intval($GLOBALS['user_info']['id'])); //创建点评图库 if (isset($_REQUEST['pics']) && is_array($_REQUEST['pics']) && count($_REQUEST['pics']) > 0) { $photos = $_REQUEST['pics']; foreach ($photos as $pkey => $photo) { $c_data = array(); $c_data['image'] = $photo; $c_data['sort'] = 10; $c_data['create_time'] = get_gmtime(); $c_data['user_id'] = intval($GLOBALS['user_info']['id']); $c_data['supplier_location_id'] = intval($_REQUEST['supplier_location_id']); $c_data['dp_id'] = $dp_id; $c_data['brief'] = addslashes(htmlspecialchars($_REQUEST['brief'][$pkey])); $c_data['status'] = 0; $c_data['image_type'] = intval($_REQUEST['type'][$pkey]); $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_images", $c_data, "INSERT"); } } //创建点评评分 $point_Group = $_REQUEST['dp_point_group']; foreach ($point_Group as $group_id => $point) { $point_data = array(); $point_data['group_id'] = $group_id; $point_data['dp_id'] = $dp_id; $point_data['supplier_location_id'] = intval($_REQUEST['supplier_location_id']); $point_data['point'] = intval($point); $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp_point_result", $point_data, "INSERT"); } //创建点评分组的标签 $tag_group = $_REQUEST['dp_tags']; foreach ($tag_group as $group_id => $tag_row) { if (trim($tag_row) != '') { $arr_rer = array(",", ","); $arr_rep = array(" ", " "); $tag_row = str_replace($arr_rer, $arr_rep, $tag_row); $tag_row_data = array(); $tag_row_data['tags'] = $tag_row; $tag_row_data['dp_id'] = $dp_id; $tag_row_data['supplier_location_id'] = intval($_REQUEST['supplier_location_id']); $tag_row_data['group_id'] = $group_id; $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp_tag_result", $tag_row_data, "INSERT"); review_supplier_location_match(intval($_REQUEST['supplier_location_id']), $tag_row, $group_id); } } //分享 $supplier_info = $GLOBALS['db']->getRow("select name,id,new_dp_count_time from " . DB_PREFIX . "supplier_location where id = " . $dp_data['supplier_location_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($dp_data['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)); } //更新统计 syn_supplier_locationcount($supplier_info); cache_store_point($supplier_info['id']); $cache_id = md5("store" . "view" . $supplier_info['id']); $GLOBALS['tmpl']->clear_cache('store_view.html', $cache_id); $return['status'] = 1; } else { $return['message'] = "数据库异常,提交失败"; } ajax_return($return); exit; }
public function foreverdelete() { //删除指定记录 $ajax = intval($_REQUEST['ajax']); $id = $_REQUEST['id']; if (!empty($id)) { $name = $this->getActionName(); $model = D($name); $pk = $model->getPk(); $ids = explode(',', $id); $condition = array($pk => array('in', $ids)); $condition_link = array("dp_id" => array('in', $ids)); $dp_list = $model->where($condition)->findAll(); if (M("SupplierLocationDpReply")->where($condition_link)->count() > 0) { $this->error("请先清空点评回应", $ajax); } if (false !== $model->where($condition)->delete()) { M("SupplierLocationDpImages")->where($condition_link)->delete(); M("SupplierLocationDpPointResult")->where($condition_link)->delete(); M("SupplierLocationDpTagResult")->where($condition_link)->delete(); M("DealDpPointResult")->where($condition_link)->delete(); M("DealDpTagResult")->where($condition_link)->delete(); M("YouhuiDpPointResult")->where($condition_link)->delete(); M("YouhuiDpTagResult")->where($condition_link)->delete(); M("EventDpPointResult")->where($condition_link)->delete(); M("EventDpTagResult")->where($condition_link)->delete(); foreach ($dp_list as $k => $v) { if ($v['status'] == 1) { $merchant_info = M("SupplierLocation")->getById($v['supplier_location_id']); syn_supplier_locationcount($merchant_info); syn_deal_review_count($v['deal_id']); syn_youhui_review_count($v['youhui_id']); syn_event_review_count($v['event_id']); cache_store_point($merchant_info['id']); } $GLOBALS['db']->query("update " . DB_PREFIX . "user set dp_count = dp_count - 1 where id = " . intval($v['user_id'])); } save_log($ids . l("FOREVER_DELETE_SUCCESS"), 1); $this->success(l("FOREVER_DELETE_SUCCESS"), $ajax); } else { save_log($ids . l("FOREVER_DELETE_FAILED"), 0); $this->error(l("FOREVER_DELETE_FAILED"), $ajax); } } else { $this->error(l("INVALID_OPERATION"), $ajax); } }
/** * 获取商家店面列表 */ function get_store_list($limit, $cate_id = 0, $where = '', $orderby = '', $cached = true, $count = true) { $key = md5("STORE_LIST_" . $limit . $cate_id . $where . $orderby); if ($cached) { $res = $GLOBALS['cache']->get($key); } else { $res = false; } if ($res === false) { $time = get_gmtime(); if (strpos($orderby, "is_recommend") && strpos($orderby, "is_verify") && strpos($orderby, "dp_count")) { $key_sort = "search_idx5,sort_default"; } else { $key_sort = explode(" ", trim($orderby)); $key_sort = trim($key_sort[0]); if ($key_sort != '') { $key_sort = "{$key_sort}"; } } static $supplier_total; if (empty($supplier_total)) { $supplier_total = $GLOBALS['db']->getOne("select count(id) from " . DB_PREFIX . "supplier_location"); } if ($supplier_total > 50000) { $count_sql = "select count(*) from " . DB_PREFIX . "supplier_location use index(search_idx5) where is_effect = 1 "; $sql = "select * from " . DB_PREFIX . "supplier_location use index({$key_sort}) where is_effect = 1 "; } else { $count_sql = "select count(*) from " . DB_PREFIX . "supplier_location where is_effect = 1 "; $sql = "select * from " . DB_PREFIX . "supplier_location where is_effect = 1 "; } if ($cate_id > 0) { $ids = load_auto_cache("deal_sub_cate_ids", array("cate_id" => $cate_id)); $sql .= " and deal_cate_id in (" . implode(",", $ids) . ")"; $count_sql .= " and deal_cate_id in (" . implode(",", $ids) . ")"; } //$city = get_current_deal_city(); $city_id = $GLOBALS['deal_city']['id']; if ($city_id > 0) { $ids = load_auto_cache("deal_city_belone_ids", array("city_id" => $city_id)); if ($ids) { $sql .= " and city_id in (" . implode(",", $ids) . ")"; $count_sql .= " and city_id in (" . implode(",", $ids) . ")"; } } if ($where != '') { $sql .= " and " . $where; $count_sql .= " and " . $where; } if ($orderby == '') { $sql .= " limit " . $limit; } else { $sql .= " order by " . $orderby . " limit " . $limit; } $stores = $GLOBALS['db']->getAll($sql); if ($count) { $stores_count = $GLOBALS['db']->getOne($count_sql); } if ($stores) { foreach ($stores as $k => $store) { if ($store['dp_group_point'] == "") { $store = cache_store_point($store['id']); } if ($store['tuan_youhui_cache'] == "") { $store = recount_supplier_data_count($store['id'], "tuan"); $store = recount_supplier_data_count($store['id'], "youhui"); } $tuan_youhui_cache = unserialize($store['tuan_youhui_cache']); if ($store['tuan_count'] > 0) { $store['tuan'] = $tuan_youhui_cache['tuan']; } if ($store['youhui_count'] > 0) { $store['youhui'] = $tuan_youhui_cache['youhui']; } $durl = url("youhui", "store#view", array("id" => $store['id'])); $store['url'] = $durl; $tags = array(); if ($store['tags']) { $ttags = explode(" ", $store['tags']); foreach ($ttags as $tv) { $tags[$tv]['name'] = $tv; $tags[$tv]['code'] = $tv; } } $store['tags_list'] = $tags; $stores[$k] = $store; $group_point = unserialize($store['dp_group_point']); $stores[$k]['group_point'] = $group_point; } } $res = array('list' => $stores, 'count' => $stores_count); if ($cached) { $GLOBALS['cache']->set($key, $res); } } return $res; }