public function syn_data() { set_time_limit(0); es_session::close(); //同步,supplier_location表, deal表, youhui表, event表 , supplier 表 //总数 $page = intval($_REQUEST['p']) == 0 ? 1 : intval($_REQUEST['p']); if ($page == 1) { syn_dealing(); } $page_size = 5; $location_total = M("SupplierLocation")->count(); $deal_total = M("Deal")->count(); $youhui_total = M("Youhui")->count(); $event_total = M("Event")->count(); $supplier_total = M("Supplier")->count(); $count = max(array($location_total, $deal_total, $youhui_total, $event_total, $supplier_total)); $limit = ($page - 1) * $page_size . "," . $page_size; $location_list = M("SupplierLocation")->limit($limit)->findAll(); foreach ($location_list as $v) { recount_supplier_data_count($v['id'], "tuan"); recount_supplier_data_count($v['id'], "youhui"); recount_supplier_data_count($v['id'], "daijin"); recount_supplier_data_count($v['id'], "event"); recount_supplier_data_count($v['id'], "shop"); syn_supplier_location_match($v['id']); } $supplier_list = M("Supplier")->limit($limit)->findAll(); foreach ($supplier_list as $v) { syn_supplier_match($v['id']); } $deal_list = M("Deal")->limit($limit)->findAll(); foreach ($deal_list as $v) { syn_deal_match($v['id']); } $youhui_list = M("Youhui")->limit($limit)->findAll(); foreach ($youhui_list as $v) { syn_youhui_match($v['id']); } $event_list = M("Event")->limit($limit)->findAll(); foreach ($youhui_list as $v) { syn_event_match($v['id']); } if ($page * $page_size >= $count) { $this->assign("jumpUrl", U("Cache/index")); $ajax = intval($_REQUEST['ajax']); $data['status'] = 1; $data['info'] = "<div style='line-height:50px; text-align:center; color:#f30;'>同步成功</div><div style='text-align:center;'><input type='button' onclick='\$.weeboxs.close();' class='button' value='关闭' /></div>"; header("Content-Type:text/html; charset=utf-8"); exit(json_encode($data)); } else { $total_page = ceil($count / $page_size); $data['status'] = 0; $data['info'] = "共" . $total_page . "页,当前第" . $page . "页,等待更新下一页记录"; $data['url'] = U("Cache/syn_data", array("p" => $page + 1)); header("Content-Type:text/html; charset=utf-8"); exit(json_encode($data)); } }
public function load($param) { $param = array("id" => $param['id']); $store_key = intval($param['id']); static $store; if (!$store[$store_key]) { if ($GLOBALS['distribution_cfg']['CACHE_TYPE'] != "File") { $key = $this->build_key(__CLASS__, $param); $GLOBALS['cache']->set_dir(APP_ROOT_PATH . "public/runtime/data/" . __CLASS__ . "/"); $store_info = $GLOBALS['cache']->get($key); } else { $store_info = false; } if ($store_info === false) { $param['id'] = intval($GLOBALS['db']->getOne("select id from " . DB_PREFIX . "supplier_location where id = " . $store_key)); $key = $this->build_key(__CLASS__, $param); $GLOBALS['cache']->set_dir(APP_ROOT_PATH . "public/runtime/data/" . __CLASS__ . "/"); $store_info = $GLOBALS['cache']->get($key); if ($store_info !== false) { return $store_info; } $store_key = $param['id']; $store_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "supplier_location where id = '" . $store_key . "'"); if ($store_info) { $id = $store_info['id']; $store_info = recount_supplier_data_count($id, "tuan", $store_info); $store_info = recount_supplier_data_count($id, "youhui", $store_info); $store_info = recount_supplier_data_count($id, "event", $store_info); $store_info = recount_supplier_data_count($id, "shop", $store_info); $durl = url("index", "store#" . $store_info['id']); $store_info['url'] = $durl; if ($GLOBALS['distribution_cfg']['CACHE_TYPE'] != "File") { $GLOBALS['cache']->set_dir(APP_ROOT_PATH . "public/runtime/data/" . __CLASS__ . "/"); $GLOBALS['cache']->set($key, $store_info, 300); } } } $store[$store_key] = $store_info; } return $store[$store_key]; }
public function set_effect() { $id = intval($_REQUEST['id']); $ajax = intval($_REQUEST['ajax']); $info = M(MODULE_NAME)->where("id=" . $id)->getField("name"); $c_is_effect = M(MODULE_NAME)->where("id=" . $id)->getField("is_effect"); //当前状态 $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态 M(MODULE_NAME)->where("id=" . $id)->setField("is_effect", $n_is_effect); M(MODULE_NAME)->where("id=" . $id)->setField("update_time", NOW_TIME); save_log($info . l("SET_EFFECT_" . $n_is_effect), 1); $locations = M("DealLocationLink")->where(array('deal_id' => $id))->findAll(); foreach ($locations as $location) { recount_supplier_data_count($location['location_id'], "daijin"); recount_supplier_data_count($location['location_id'], "tuan"); } $this->ajaxReturn($n_is_effect, l("SET_EFFECT_" . $n_is_effect), 1); }
public function youhui_update() { B('FilterString'); $data = M(MODULE_NAME)->create(); $log_info = M(MODULE_NAME)->where("id=" . intval($data['id']))->getField("name"); //开始验证有效性 $this->assign("jumpUrl", u(MODULE_NAME . "/youhui_edit", array("id" => $data['id']))); if (!check_empty($data['name'])) { $this->error(L("DEAL_YOUHUI_NAME_EMPTY_TIP")); } if (!check_empty($data['sub_name'])) { $this->error(L("DEAL_YOUHUI_SUB_NAME_EMPTY_TIP")); } if ($data['cate_id'] == 0) { $this->error(L("DEAL_YOUHUI_CATE_EMPTY_TIP")); } if ($data['city_id'] == 0) { $this->error(L("DEAL_YOUHUI_CITY_EMPTY_TIP")); } if ($data['max_bought'] < 0) { $this->error(L("DEAL_YOUHUI_MAX_BOUGHT_ERROR_TIP")); } if ($data['user_min_bought'] < 0) { $this->error(L("DEAL_USER_MIN_BOUGHT_ERROR_TIP")); } if ($data['user_max_bought'] < 0) { $this->error(L("DEAL_USER_MAX_BOUGHT_ERROR_TIP")); } if ($data['user_max_bought'] < $data['user_min_bought'] && $data['user_max_bought'] > 0) { $this->error(L("DEAL_USER_MAX_MIN_BOUGHT_ERROR_TIP")); } $data['is_shop'] = 2; $data['is_coupon'] = 1; if (intval($data['is_coupon']) == 1 && intval($data['is_refund']) == 1) { $data['expire_refund'] = intval($_REQUEST['expire_refund']); $data['any_refund'] = intval($_REQUEST['any_refund']); } else { $data['expire_refund'] = 0; $data['any_refund'] = 0; } $data['notice'] = intval($_REQUEST['notice']); $data['begin_time'] = trim($data['begin_time']) == '' ? 0 : to_timespan($data['begin_time']); $data['end_time'] = trim($data['end_time']) == '' ? 0 : to_timespan($data['end_time']); $data['coupon_begin_time'] = trim($data['coupon_begin_time']) == '' ? 0 : to_timespan($data['coupon_begin_time']); $data['coupon_end_time'] = trim($data['coupon_end_time']) == '' ? 0 : to_timespan($data['coupon_end_time']); //将第一张图片设为团购图片 $imgs = $_REQUEST['img']; foreach ($imgs as $k => $v) { if ($v != '') { $data['img'] = $v; break; } } $data['update_time'] = get_gmtime(); $data['publish_wait'] = 0; // 更新数据 $list = M(MODULE_NAME)->save($data); if (false !== $list) { $GLOBALS['db']->query("update " . DB_PREFIX . "deal_coupon set expire_refund = " . $data['expire_refund'] . ",any_refund = " . $data['any_refund'] . ",supplier_id=" . $data['supplier_id'] . ",end_time=" . $data['coupon_end_time'] . ",begin_time=" . $data['coupon_begin_time'] . " where deal_id = " . $data['id']); //开始处理图片 M("DealGallery")->where("deal_id=" . $data['id'])->delete(); $imgs = $_REQUEST['img']; foreach ($imgs as $k => $v) { if ($v != '') { $img_data['deal_id'] = $data['id']; $img_data['img'] = $v; $img_data['sort'] = $k; M("DealGallery")->add($img_data); } } //end 处理图片 M("DealPayment")->where("deal_id=" . $data['id'])->delete(); if (intval($_REQUEST['define_payment']) == 1) { $payment_ids = $_REQUEST['payment_id']; foreach ($payment_ids as $k => $v) { $payment_conf = array(); $payment_conf['payment_id'] = $payment_ids[$k]; $payment_conf['deal_id'] = $data['id']; M("DealPayment")->add($payment_conf); } } //成功提示 M("DealCateTypeDealLink")->where("deal_id=" . $data['id'])->delete(); foreach ($_REQUEST['deal_cate_type_id'] as $type_id) { $link_data = array(); $link_data['deal_cate_type_id'] = $type_id; $link_data['deal_id'] = $data['id']; M("DealCateTypeDealLink")->add($link_data); } M("DealLocationLink")->where("deal_id=" . $data['id'])->delete(); foreach ($_REQUEST['location_id'] as $location_id) { $link_data = array(); $link_data['location_id'] = $location_id; $link_data['deal_id'] = $data['id']; M("DealLocationLink")->add($link_data); } syn_deal_status($data['id']); foreach ($_REQUEST['location_id'] as $location_id) { recount_supplier_data_count($location_id, "daijin"); } syn_deal_match($data['id']); rm_auto_cache("cache_deal_cart", array("id" => $data['id'])); rm_auto_cache("static_goods_info", array("id" => $data['id'])); //成功提示 save_log($log_info . L("UPDATE_SUCCESS"), 1); $this->success(L("UPDATE_SUCCESS")); } else { //错误提示 $dbErr = M()->getDbError(); save_log($log_info . L("UPDATE_FAILED") . $dbErr, 0); $this->error(L("UPDATE_FAILED") . $dbErr, 0); } }
public function view() { $id = intval($_REQUEST['id']); if (check_ipop_limit(get_client_ip(), "recount_supplier_location", 1200, $id)) { recount_supplier_data_count($id, "tuan"); recount_supplier_data_count($id, "youhui"); recount_supplier_data_count($id, "daijin"); recount_supplier_data_count($id, "event"); recount_supplier_data_count($id, "shop"); } $GLOBALS['tmpl']->caching = true; $cache_id = md5(MODULE_NAME . ACTION_NAME . $id); if (!$GLOBALS['tmpl']->is_cached('store_view.html', $cache_id)) { $store_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "supplier_location where id = " . $id . " and is_effect = 1"); if (!$store_info) { showErr($GLOBALS['lang']['NO_STORE_INFO']); } $store_info['group_point'] = $GLOBALS['db']->getAll("select id,name from " . DB_PREFIX . "point_group as pg left join " . DB_PREFIX . "point_group_link as pgl on pg.id = pgl.point_group_id where pgl.category_id = " . $store_info['deal_cate_id'] . " order by sort asc"); foreach ($store_info['group_point'] as $kk => $vv) { $store_info['group_point'][$kk]['avg_point'] = round(floatval($GLOBALS['db']->getOne("select avg_point from " . DB_PREFIX . "supplier_location_point_result where supplier_location_id = " . $store_info['id'] . " and group_id = " . $vv['id'])), 1); } $tags = array(); if ($store_info['tags']) { $ttags = explode(" ", $store_info['tags']); foreach ($ttags as $tv) { $tags[$tv]['name'] = $tv; $tags[$tv]['code'] = $tv; } } $store_info['tags_list'] = $tags; //标签分组 $tag_group = $GLOBALS['db']->getAll("select g.id,g.name,g.allow_vote from " . DB_PREFIX . "tag_group as g left join " . DB_PREFIX . "tag_group_link as gl on g.id = gl.tag_group_id where gl.category_id = " . $store_info['deal_cate_id'] . " order by g.sort"); foreach ($tag_group as $k => $v) { $tags = $GLOBALS['db']->getAll("select tag_name,total_count from " . DB_PREFIX . "supplier_tag where group_id = " . $v['id'] . " and supplier_location_id =" . $store_info['id'] . " order by total_count desc limit 30"); $tags_arr = array(); foreach ($tags as $kk => $vv) { $vv['tag_name'] = trim($vv['tag_name']); if ($vv['tag_name'] != '') { $tags_arr[$kk]['url'] = url("youhui", "store#index", array("tag" => $vv['tag_name'])); $tags_arr[$kk]['name'] = $vv['tag_name']; $tags_arr[$kk]['total_count'] = $vv['total_count']; } } $tag_group[$k]['tags'] = $tags_arr; } $store_info['tag_group'] = $tag_group; $cate_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_cate where id = " . $store_info['deal_cate_id']); $site_nav[] = array('name' => $GLOBALS['lang']['HOME_PAGE'], 'url' => url("youhui", "index")); $site_nav[] = array('name' => $GLOBALS['lang']['STORE_LIST'], 'url' => url("youhui", "store#index")); $site_nav[] = array('name' => $cate_item['name'], 'url' => url("youhui", "store#index", array("cid" => $cate_item['id']))); $site_nav[] = array('name' => $store_info['name'], 'url' => url("youhui", "store#view", array("id" => $store_info['id']))); $GLOBALS['tmpl']->assign("site_nav", $site_nav); $seo_title = $store_info['seo_title'] ? $store_info['seo_title'] : $store_info['name']; $GLOBALS['tmpl']->assign("page_title", $seo_title); $seo_keyword = $store_info['seo_keyword'] ? $store_info['seo_keyword'] : $store_info['name']; $GLOBALS['tmpl']->assign("page_keyword", $seo_keyword . ","); $seo_description = $store_info['seo_description'] ? $store_info['seo_description'] : $store_info['name']; $GLOBALS['tmpl']->assign("page_description", $seo_description . ","); $GLOBALS['tmpl']->assign("store_info", $store_info); //输出最新加入的商家 $new_stores = $GLOBALS['db']->getAll("select id,name,address from " . DB_PREFIX . "supplier_location where city_id = " . $GLOBALS['deal_city']['id'] . " and is_effect = 1 order by id desc limit 5"); $GLOBALS['tmpl']->assign("new_stores", $new_stores); $rec_stores = $GLOBALS['db']->getAll("select id,name,address,avg_point,dp_count from " . DB_PREFIX . "supplier_location where city_id = " . $GLOBALS['deal_city']['id'] . " and is_recommend = 1 and is_effect = 1 order by is_recommend desc limit 5"); $GLOBALS['tmpl']->assign("rec_stores", $rec_stores); } $GLOBALS['tmpl']->display("store_view.html", $cache_id); }
/** * 获取商家店面列表 */ 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; }
public function toogle_status() { $id = intval($_REQUEST['id']); $ajax = intval($_REQUEST['ajax']); $field = $_REQUEST['field']; $info = $id . "_" . $field; $c_is_effect = M(MODULE_NAME)->where("id=" . $id)->getField($field); //当前状态 $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态 M(MODULE_NAME)->where("id=" . $id)->setField($field, $n_is_effect); save_log($info . l("SET_EFFECT_" . $n_is_effect), 1); $locations = M("EventLocationLink")->where(array('event_id' => $id))->findAll(); foreach ($locations as $location) { recount_supplier_data_count($location['location_id'], "event"); } $this->ajaxReturn($n_is_effect, l("SET_EFFECT_" . $n_is_effect), 1); }
public function foreverdelete() { //删除指定记录 $ajax = intval($_REQUEST['ajax']); $id = $_REQUEST['id']; if (isset($id)) { $condition = array('id' => array('in', explode(',', $id))); $rel_data = M(MODULE_NAME)->where($condition)->findAll(); foreach ($rel_data as $data) { $info[] = $data['name']; } if ($info) { $info = implode(",", $info); } $list = M(MODULE_NAME)->where($condition)->delete(); if ($list !== false) { clear_auto_cache("fyouhui_filter_nav_cache"); $locations = M("YouhuiLocationLink")->where(array('youhui_id' => array('in', explode(',', $id))))->findAll(); M("DealCateTypeYouhuiLink")->where(array('youhui_id' => array('in', explode(',', $id))))->delete(); M("YouhuiLocationLink")->where(array('youhui_id' => array('in', explode(',', $id))))->delete(); foreach ($locations as $location) { recount_supplier_data_count($location['location_id'], "youhui"); } save_log($info . l("DELETE_SUCCESS"), 1); $this->success(l("DELETE_SUCCESS"), $ajax); } else { save_log($info . l("DELETE_FAILED"), 0); $this->error(l("DELETE_FAILED"), $ajax); } } else { $this->error(l("INVALID_OPERATION"), $ajax); } }