public function index()
 {
     $merchant_id = intval($GLOBALS['request']['merchant_id']);
     /*商家ID*/
     $page = intval($GLOBALS['request']['page']);
     /*分页*/
     //检查用户,用户密码
     $user = $GLOBALS['user_info'];
     $user_id = intval($user['id']);
     $root = array();
     $root['return'] = 1;
     $page = $page == 0 ? 1 : $page;
     $page_size = PAGE_SIZE;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     $supplier_locationinfo = $GLOBALS['db']->getRow("select name,id,new_dp_count_time from " . DB_PREFIX . "supplier_location where id = " . $merchant_id);
     syn_supplier_locationcount($supplier_locationinfo);
     $condition = " dp.status = 1 and dp.supplier_location_id = " . $merchant_id . " ";
     $sql_count = "select count(*) from " . DB_PREFIX . "supplier_location_dp dp where " . $condition;
     $total = $GLOBALS['db']->getOne($sql_count);
     $page_total = ceil($total / $page_size);
     //$root['sql_count'] = $sql_count;
     $sql = "select dp.*,u.user_name from " . DB_PREFIX . "supplier_location_dp as dp left outer join " . DB_PREFIX . "user as u on u.id = dp.user_id  where " . $condition . " order by dp.is_top desc, dp.create_time desc limit " . $limit;
     $root['sql'] = $sql;
     $list = $GLOBALS['db']->getAll($sql);
     foreach ($list as $k => $v) {
         $list[$k]['merchant_id'] = $v['supplier_location_id'];
         $list[$k]['create_time_format'] = getBeforeTimelag($v['create_time']);
         $list[$k]['width'] = $v['point'] / 5 * 100;
     }
     //星级点评数
     $root['star_1'] = 0;
     $root['star_2'] = 0;
     $root['star_3'] = 0;
     $root['star_4'] = 0;
     $root['star_5'] = 0;
     $root['star_dp_width_1'] = 0;
     $root['star_dp_width_2'] = 0;
     $root['star_dp_width_3'] = 0;
     $root['star_dp_width_4'] = 0;
     $root['star_dp_width_5'] = 0;
     $buy_dp_sum = 0.0;
     $buy_dp_group = $GLOBALS['db']->getAll("select point,count(*) as num from " . DB_PREFIX . "supplier_location_dp where supplier_location_id = " . $merchant_id . " group by point");
     foreach ($buy_dp_group as $dp_k => $dp_v) {
         $star = intval($dp_v['point']);
         if ($star >= 1 && $star <= 5) {
             $root['star_' . $star] = $dp_v['num'];
             $buy_dp_sum += $star * $dp_v['num'];
             $root['star_dp_width_' . $star] = round($dp_v['num'] / $total, 1) * 100;
         }
     }
     //点评平均分
     $root['buy_dp_sum'] = $buy_dp_sum;
     $root['buy_dp_avg'] = round($buy_dp_sum / $total, 1);
     $root['buy_dp_width'] = round($buy_dp_sum / $total, 1) / 5 * 100;
     $root['page'] = array("page" => $page, "page_total" => $page_total, "page_size" => $page_size);
     $root['message_list'] = $list;
     $root['merchant_id'] = $merchant_id;
     $root['page_title'] = "点评列表";
     output($root);
 }
Example #2
0
 function op_dp_del($id, $change, $reason, $check = false)
 {
     $dp = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "supplier_location_dp where id = " . $id);
     if ($check) {
         $result['status'] = 1;
         return $result;
     }
     if (check_user_auth("dp", "del")) {
         $sql = "delete from " . DB_PREFIX . "supplier_location_dp where id = " . $id;
         $GLOBALS['db']->query($sql);
         $GLOBALS['db']->query("delete from " . DB_PREFIX . "supplier_location_dp_reply where dp_id = " . $id);
         if ($dp['status'] == 1) {
             $merchant_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "supplier_location where id = " . $dp['supplier_location_id']);
             syn_supplier_locationcount($merchant_info);
         }
         $GLOBALS['db']->query("update " . DB_PREFIX . "user set dp_count = dp_count - 1 where id = " . intval($dp['user_id']));
         $GLOBALS['db']->query("delete from " . DB_PREFIX . "supplier_location_dp_point_result where dp_id = " . $id);
         $GLOBALS['db']->query("delete from " . DB_PREFIX . "supplier_location_dp_tag_result where dp_id = " . $id);
         $o_reason = $reason;
         $reason .= "商户点评(" . $dp['title'] . ")被删除";
         if ($change == 1) {
             modify_account(get_op_change("dp", "del"), $dp['user_id'], $reason);
             $reason .= get_op_change_show("dp", "del");
         }
         if ($change == 1 || $o_reason != "") {
             send_msg($dp['user_id'], $reason, "notify", 0);
         }
         $cache_id = md5("store" . "view" . $dp['supplier_location_id']);
         $GLOBALS['tmpl']->clear_cache('store_view.html', $cache_id);
         $result['status'] = 1;
     } else {
         $result['status'] = 0;
         $result['info'] = "没有权限";
     }
     return $result;
 }
 public function index()
 {
     $root = array();
     $root['return'] = 1;
     $yh_id = intval($GLOBALS['request']['yh_id']);
     $merchant_id = intval($GLOBALS['request']['merchant_id']);
     $city_name = strim($GLOBALS['request']['city_name']);
     //城市分类ID
     //添加点评数据
     $content = addslashes(trim($GLOBALS['request']['content']));
     if ($GLOBALS['request']['from'] == "wap") {
         if ($content != null && $content != "") {
             //检查用户,用户密码
             $user = $GLOBALS['user_info'];
             $user_id = intval($user['id']);
             if ($merchant_id > 0) {
                 $supplier_location_id = $merchant_id;
                 $merchant_youhui_comment = array('user_id' => $user_id, 'supplier_location_id' => $supplier_location_id, 'title' => $content, 'content' => $content, 'status' => 1, 'create_time' => get_gmtime());
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp", $merchant_youhui_comment, 'INSERT');
             } else {
                 $rel_table = 'youhui';
                 $rel_id = $yh_id;
                 if ($yh_id == 0) {
                     //$rel_id = $merchant_id;
                     //rel_table = 'supplier_location';
                 } else {
                     //$supplier_location_id = intval($GLOBALS['db']->getOne("select supplier_location_id from ".DB_PREFIX."youhui where id='".$yh_id."'"));
                 }
                 $merchant_youhui_comment = array('user_id' => $user_id, 'rel_id' => $rel_id, 'rel_table' => $rel_table, 'title' => $content, 'content' => $content, 'is_effect' => 1, 'create_time' => get_gmtime());
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $merchant_youhui_comment, 'INSERT');
             }
         }
     } else {
         if ($content) {
             //检查用户,用户密码
             $user = $GLOBALS['user_info'];
             $user_id = intval($user['id']);
             if ($merchant_id > 0) {
                 $supplier_location_id = $merchant_id;
                 $merchant_youhui_comment = array('user_id' => $user_id, 'supplier_location_id' => $supplier_location_id, 'title' => $content, 'content' => $content, 'status' => 1, 'create_time' => get_gmtime());
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp", $merchant_youhui_comment, 'INSERT');
             } else {
                 $rel_table = 'youhui';
                 $rel_id = $yh_id;
                 if ($yh_id == 0) {
                     //$rel_id = $merchant_id;
                     //rel_table = 'supplier_location';
                 } else {
                     //$supplier_location_id = intval($GLOBALS['db']->getOne("select supplier_location_id from ".DB_PREFIX."youhui where id='".$yh_id."'"));
                 }
                 $merchant_youhui_comment = array('user_id' => $user_id, 'rel_id' => $rel_id, 'rel_table' => $rel_table, 'title' => $content, 'content' => $content, 'is_effect' => 1, 'create_time' => get_gmtime());
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $merchant_youhui_comment, 'INSERT');
             }
         }
         $id = $GLOBALS['db']->insert_id();
         $root['id'] = $id;
         if ($id > 0) {
             $root['status'] = 1;
             $root['info'] = "添加成功";
         } else {
             $root['status'] = 0;
             $root['info'] = "添加失败";
         }
     }
     // Fwb add 2014-08-27
     $page = intval($GLOBALS['request']['page']);
     //分页
     $page = $page == 0 ? 1 : $page;
     $page_size = PAGE_SIZE;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     $youhui_comment_list = array();
     if ($merchant_id > 0) {
         $supplier_locationinfo = $GLOBALS['db']->getRow("select name,id,new_dp_count_time from " . DB_PREFIX . "supplier_location where id = " . $merchant_id);
         syn_supplier_locationcount($supplier_locationinfo);
         $condition = " dp.status = 1 and dp.supplier_location_id = " . $merchant_id . " ";
         $sql_count = "select count(*) from " . DB_PREFIX . "supplier_location_dp dp where " . $condition;
         $total = $GLOBALS['db']->getOne($sql_count);
         $page_total = ceil($total / $page_size);
         //$root['sql_count'] = $sql_count;
         $sql = "select dp.*,u.user_name from " . DB_PREFIX . "supplier_location_dp as dp left outer join " . DB_PREFIX . "user as u on u.id = dp.user_id  where " . $condition . " order by dp.is_top desc, dp.create_time desc limit " . $limit;
         $root['sql'] = $sql;
         $list = $GLOBALS['db']->getAll($sql);
         foreach ($list as $item) {
             $youhui_comment_list[] = array("id" => $item['id'], "merchant_id" => $item['supplier_location_id'], "content" => trim($item['content']), "point" => intval($item['point']), "user_name" => trim($item['user_name']), "create_time" => $item['create_time'], "create_time_format" => getBeforeTimelag($item['create_time']));
         }
     } else {
         $sql_count = "select count(*) from " . DB_PREFIX . "message as a " . " left outer join " . DB_PREFIX . "youhui as b on b.id = a.rel_id " . " left outer join " . DB_PREFIX . "user as c on c.id = a.user_id ";
         $sql = "select a.id, a.rel_id as yh_id, a.content,a.create_time, c.user_name from " . DB_PREFIX . "message as a " . " left outer join " . DB_PREFIX . "user as c on c.id = a.user_id ";
         $where = " a.is_effect = 1 and a.rel_table = 'youhui' and a.rel_id = {$yh_id}";
         $sql_count .= " where " . $where;
         $sql .= " where " . $where . " order by a.create_time desc";
         $sql .= " limit " . $limit;
         $total = $GLOBALS['db']->getOne($sql_count);
         $page_total = ceil($total / $page_size);
         $list = $GLOBALS['db']->getAll($sql);
         foreach ($list as $item) {
             /*
             			$title = trim($item['youhui_title']);
             			if ($title == "" || empty($title)){
             				$title = trim($item['m_name']);
             			}
             */
             $youhui_comment_list[] = array("id" => $item['id'], "yh_id" => $item['yh_id'], "content" => trim($item['content']), "user_name" => trim($item['user_name']), "create_time" => $item['create_time'], "create_time_format" => getBeforeTimelag($item['create_time']));
         }
     }
     //echo $sql; exit;
     $root['item'] = $youhui_comment_list;
     $root['page'] = array("page" => $page, "page_total" => $page_total, "page_size" => $page_size);
     $root['merchant_id'] = $merchant_id;
     //fwb add 2014-08-27
     $root['yh_id'] = $yh_id;
     $root['page_title'] = "评论详情";
     $root['city_name'] = $city_name;
     output($root);
 }
Example #4
0
/**
 * 
 * @param $dp_title  点评的标题
 * @param $dp_content  内容
 * @param $location_id  点评的门店
 * @param $point   评分 1-5
 * @param $is_buy  是否购买点评
 * @param $from    来源 (event/tuan/youhui/daijin)
 * @param $url_route  网址参数
 * @param $message_id  其他部份留言的ID,用于同步
 */
function insert_dp($dp_title, $dp_content, $location_id, $point = 0, $is_buy = 0, $from = "", $url_route = array(), $message_id = 0)
{
    $dp_data = array();
    $dp_data['title'] = valid_str($dp_title);
    $dp_data['content'] = valid_str($dp_content);
    $dp_data['create_time'] = get_gmtime();
    $dp_data['point'] = $point;
    $dp_data['user_id'] = intval($GLOBALS['user_info']['id']);
    $dp_data['supplier_location_id'] = $location_id;
    $dp_data['status'] = 1;
    $dp_data['from_data'] = $from;
    $dp_data['is_buy'] = $is_buy;
    $dp_data['message_id'] = $message_id;
    foreach ($url_route as $k => $v) {
        $dp_data[$k] = $v;
    }
    $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp", $dp_data, "INSERT");
    $dp_id = $GLOBALS['db']->insert_id();
    if ($dp_id > 0) {
        $GLOBALS['db']->query("update " . DB_PREFIX . "user set dp_count = dp_count + 1 where id = " . intval($GLOBALS['user_info']['id']));
        $supplier_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "supplier_location where id = " . $dp_data['supplier_location_id']);
        //更新统计
        syn_supplier_locationcount($supplier_info);
        $cache_id = md5("store" . "view" . $supplier_info['id']);
        $GLOBALS['tmpl']->clear_cache('store_view.html', $cache_id);
    }
    return $dp_id;
}
Example #5
0
/**
 * 提交保存点评
 * @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 delete()
 {
     if ($_REQUEST['pid'] > 0 && intval($_REQUEST['id']) > 0) {
         $s_account_info = es_session::get("account_info");
         if (!in_array(intval($_POST['pid']), $s_account_info['location_ids'])) {
             showErr("门店不存在或者没有编辑该门店的权限");
         }
         $image = $GLOBALS['db']->getOne(" SELECT `image` FROM " . DB_PREFIX . "supplier_location_images WHERE id = " . intval($_REQUEST['pid']));
         @unlink(APP_ROOT_PATH . $image);
         $GLOBALS['db']->query("DELETE FROM " . DB_PREFIX . "supplier_location_images WHERE id = " . intval($_REQUEST['pid']));
         //更新统计
         $supplier_info['id'] = $_REQUEST['id'];
         syn_supplier_locationcount($supplier_info);
         $cache_id = md5("store" . "view" . $_REQUEST['id']);
         $GLOBALS['tmpl']->clear_cache('store_view.html', $cache_id);
         showSuccess($GLOBALS['lang']['DELETE_SUCCESS'], 0, url("biz", "publish#images", array("id" => intval($_REQUEST['id']))));
     } else {
         app_redirect(url("biz"));
     }
 }
 function update()
 {
     //B('FilterString');
     $name = $this->getActionName();
     $model = D($name);
     if (false === ($data = $model->create())) {
         $this->error($model->getError());
     }
     $id = $data[$model->getPk()];
     if ($data['reply_content'] != "" && $data['reply_time'] == "") {
         $data['reply_time'] = NOW_TIME;
     }
     // 更新数据
     $list = $model->save($data);
     $dp = $model->getById($id);
     if (false !== $list) {
         //成功提示
         $group_points = $_REQUEST['group_point'];
         foreach ($group_points as $group_id => $point) {
             $model->query("update " . DB_PREFIX . "supplier_location_dp_point_result set point = " . $point . " where group_id = " . $group_id . " and dp_id = " . $id . " and supplier_location_id = " . $dp['supplier_location_id']);
             M()->query("update " . DB_PREFIX . "deal_dp_point_result set point = " . $point . " where group_id = " . $group_id . " and dp_id = " . $id . " and deal_id = " . $dp['deal_id']);
             M()->query("update " . DB_PREFIX . "youhui_dp_point_result set point = " . $point . " where group_id = " . $group_id . " and dp_id = " . $id . " and youhui_id = " . $dp['youhui_id']);
             M()->query("update " . DB_PREFIX . "event_dp_point_result set point = " . $point . " where group_id = " . $group_id . " and dp_id = " . $id . " and event_id = " . $dp['event_id']);
         }
         $group_tags = $_REQUEST['group_tag'];
         M()->query("update " . DB_PREFIX . "supplier_location_dp set tags_match = '',tags_match_row='' where id = " . $id);
         foreach ($group_tags as $group_id => $tags) {
             $model->query("update " . DB_PREFIX . "supplier_location_dp_tag_result set tags = '" . $tags . "' where group_id = " . $group_id . " and dp_id = " . $id . " and supplier_location_id = " . $dp['supplier_location_id']);
             M()->query("update " . DB_PREFIX . "deal_dp_tag_result set tags = '" . $tags . "' where group_id = " . $group_id . " and dp_id = " . $id . " and deal_id = " . $dp['deal_id']);
             M()->query("update " . DB_PREFIX . "youhui_dp_tag_result set tags = '" . $tags . "' where group_id = " . $group_id . " and dp_id = " . $id . " and youhui_id = " . $dp['youhui_id']);
             M()->query("update " . DB_PREFIX . "event_dp_tag_result set tags = '" . $tags . "' where group_id = " . $group_id . " and dp_id = " . $id . " and event_id = " . $dp['event_id']);
             insert_match_item($tags, "supplier_location_dp", $id, "tags_match");
             //更新点评的索引
         }
         $count = M("SupplierLocationDpReply")->where("dp_id=" . $id)->count();
         $model->where("id=" . $id)->setField("reply_count", $count);
         $supplier_info['id'] = $dp['supplier_location_id'];
         syn_supplier_locationcount($supplier_info);
         save_log($dp . L("UPDATE_SUCCESS"), 1);
         $this->assign('jumpUrl', Cookie::get('_currentUrl_'));
         $this->success(L('UPDATE_SUCCESS'));
     } else {
         //错误提示
         $dbErr = M()->getDbError();
         save_log($dp . L("UPDATE_FAILED") . $dbErr, 0);
         $this->error(L('EDIT_ERROR'));
     }
 }
 public function do_sign()
 {
     if ($GLOBALS['user_info']) {
         $point = intval($_REQUEST['point']);
         $id = intval($_REQUEST['id']);
         $user_id = intval($GLOBALS['user_info']['id']);
         if ($point <= 0 || $point > 5) {
             ajax_return(array("status" => false, "message" => "请点击星星为商家打分,最高5颗星"));
         }
         $store_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "supplier_location where id = " . $id . " and is_effect = 1");
         if ($store_info) {
             $begin_time = get_gmtime() - 3 * 24 * 3600;
             $end_time = get_gmtime() + 3 * 24 * 3600;
             $sign_data_count = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "supplier_location_sign_log where user_id = " . $user_id . " and location_id  = " . $id . " and (sign_time between {$begin_time} and {$end_time})");
             if ($sign_data_count) {
                 ajax_return(array("status" => false, "message" => "最近一周您已经签到过了"));
             } else {
                 $sign_data['user_id'] = $user_id;
                 $sign_data['location_id'] = $id;
                 $sign_data['point'] = $point;
                 $sign_data['sign_time'] = get_gmtime();
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_sign_log", $sign_data);
                 syn_supplier_locationcount($store_info);
                 $cache_id = md5("store" . "view" . $store_info['id']);
                 $GLOBALS['tmpl']->clear_cache('store_view.html', $cache_id);
                 ajax_return(array("status" => true, "message" => "签到成功"));
             }
         } else {
             ajax_return(array("status" => false, "message" => "商户不存在"));
         }
     } else {
         ajax_return(array("status" => false, "message" => "请先登录"));
     }
 }
 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));
         $list = $model->where($condition)->findAll();
         if (false !== $model->where($condition)->delete()) {
             //循环删除数据
             foreach ($list as $k => $v) {
                 @unlink(APP_ROOT . $v['image']);
                 $supplier_info['id'] = $v['supplier_location_id'];
                 syn_supplier_locationcount($supplier_info);
                 update_supplier_location_img($supplier_info['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 update()
 {
     //B('FilterString');
     $name = $this->getActionName();
     $model = D($name);
     if (false === ($data = $model->create())) {
         $this->error($model->getError());
     }
     $id = $data[$model->getPk()];
     // 更新数据
     $list = $model->save();
     $dp = $model->getById($id);
     if (false !== $list) {
         //成功提示
         $group_points = $_REQUEST['group_point'];
         foreach ($group_points as $group_id => $point) {
             $model->query("update " . DB_PREFIX . "supplier_location_dp_point_result set point = " . $point . " where group_id = " . $group_id . " and dp_id = " . $id . " and supplier_location_id = " . $dp['supplier_location_id']);
         }
         $group_tags = $_REQUEST['group_tag'];
         foreach ($group_tags as $group_id => $tags) {
             $model->query("update " . DB_PREFIX . "supplier_location_dp_tag_result set tags = '" . $tags . "' where group_id = " . $group_id . " and dp_id = " . $id . " and supplier_location_id = " . $dp['supplier_location_id']);
         }
         $count = M("SupplierLocationDpReply")->where("dp_id=" . $id)->count();
         $model->where("id=" . $id)->setField("reply_count", $count);
         $supplier_info['id'] = $dp['supplier_location_id'];
         syn_supplier_locationcount($supplier_info);
         save_log($dp . L("UPDATE_SUCCESS"), 1);
         $this->assign('jumpUrl', Cookie::get('_currentUrl_'));
         $this->success(L('UPDATE_SUCCESS'));
     } else {
         //错误提示
         $dbErr = M()->getDbError();
         save_log($dp . L("UPDATE_FAILED") . $dbErr, 0);
         $this->error(L('EDIT_ERROR'));
     }
 }
 public function update()
 {
     if (intval($_POST['id']) == 0) {
         showErr($GLOBALS['lang']['ERROR_TITLE'], 0, url("biz", "profile"));
         exit;
     }
     $id = intval($_POST['id']);
     $s_account_info = es_session::get("account_info");
     $location_ids = $s_account_info['location_ids'];
     $info = $GLOBALS['db']->getRow(" SELECT * FROM " . DB_PREFIX . "supplier_location WHERE id = " . intval($id) . " and id in (" . implode(",", $s_account_info['location_ids']) . ")");
     if (!$info) {
         showErr("门店不存在或者没有编辑该门店的权限");
     }
     $data['preview'] = str_replace(get_domain() . APP_ROOT, ".", addslashes(htmlspecialchars(trim($_POST['preview']))));
     $data['tags'] = addslashes(htmlspecialchars(trim($_POST['tags'])));
     $data['address'] = addslashes(htmlspecialchars(trim($_POST['address'])));
     $data['route'] = addslashes(htmlspecialchars(trim($_POST['route'])));
     $data['tel'] = addslashes(htmlspecialchars(trim($_POST['tel'])));
     $data['contact'] = addslashes(htmlspecialchars(trim($_POST['contact'])));
     $data['open_time'] = addslashes(htmlspecialchars(trim($_POST['open_time'])));
     $data['api_address'] = addslashes(htmlspecialchars(trim($_POST['api_address'])));
     $data['xpoint'] = $_POST['xpoint'];
     $data['ypoint'] = $_POST['ypoint'];
     $data['sms_content'] = addslashes(htmlspecialchars(trim($_POST['sms_content'])));
     $data['brief'] = addslashes(trim(replace_public($_POST['brief'])));
     $data['brief'] = valid_tag($data['brief']);
     $data['id'] = intval($_POST['id']);
     $data['seo_title'] = addslashes(htmlspecialchars(trim($_POST['seo_title'])));
     $data['seo_keyword'] = addslashes(htmlspecialchars(trim($_POST['seo_keyword'])));
     $data['seo_description'] = addslashes(htmlspecialchars(trim($_POST['seo_description'])));
     $rs = $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location", $data, "UPDATE", " id = " . intval($_POST['id']));
     if ($rs) {
         //更新统计
         syn_supplier_locationcount($data);
         syn_supplier_location_match($data['id']);
         $cache_id = md5("store" . "view" . $data['id']);
         $GLOBALS['tmpl']->clear_cache('store_view.html', $cache_id);
         showSuccess($GLOBALS['lang']['SUPPLIER_MODIFY_SUCCESS'], 0, url("biz", "profile#modify", array("id" => intval($_POST['id']))));
     }
 }