Ejemplo n.º 1
0
 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 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 . "/edit", array("id" => $data['id'])));
     if (!check_empty($data['name'])) {
         $this->error(L("SUPPLIER_NAME_EMPTY_TIP"));
     }
     // 更新数据
     $list = M(MODULE_NAME)->save($data);
     if (false !== $list) {
         syn_supplier_match($data['id']);
         clear_auto_cache("static_goods_info");
         //成功提示
         save_log($log_info . L("UPDATE_SUCCESS"), 1);
         $this->success(L("UPDATE_SUCCESS"));
     } else {
         //错误提示
         save_log($log_info . L("UPDATE_FAILED"), 0);
         $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
     }
 }
 public function insert()
 {
     B('FilterString');
     $ajax = intval($_REQUEST['ajax']);
     $data = M(MODULE_NAME)->create();
     //开始验证有效性
     $this->assign("jumpUrl", u(MODULE_NAME . "/add"));
     if (!check_empty($data['name'])) {
         $this->error(L("LOCATION_NAME_EMPTY_TIP"));
     }
     // 更新数据
     //自动创建品牌
     if ($data['supplier_id'] == 0) {
         $supplier_data['name'] = $data['name'];
         $supplier_data['is_effect'] = 1;
         $supplier_id = M("Supplier")->add($supplier_data);
         syn_supplier_match($supplier_id);
         $data['supplier_id'] = $supplier_id;
     }
     $data['is_effect'] = 1;
     $log_info = $data['name'];
     $list = M(MODULE_NAME)->add($data);
     if (false !== $list) {
         //成功提示
         if ($data['is_main'] == 1) {
             M(MODULE_NAME)->where("supplier_id=" . $data['supplier_id'] . " and id <> " . $list)->setField("is_main", 0);
         }
         if (M(MODULE_NAME)->where("supplier_id=" . $data['supplier_id'] . " and is_main = 1")->count() == 0) {
             M(MODULE_NAME)->where("id=" . $list)->setField("is_main", 1);
         }
         $area_ids = $_REQUEST['area_id'];
         foreach ($area_ids as $area_id) {
             $area_data['area_id'] = $area_id;
             $area_data['location_id'] = $list;
             M("SupplierLocationAreaLink")->add($area_data);
         }
         $brand_ids = $_REQUEST['brand_id'];
         foreach ($brand_ids as $brand_id) {
             $brand_data['brand_id'] = $brand_id;
             $brand_data['location_id'] = $list;
             M("SupplierLocationBrandLink")->add($brand_data);
         }
         foreach ($_REQUEST['deal_cate_type_id'] as $type_id) {
             $link_data = array();
             $link_data['deal_cate_type_id'] = $type_id;
             $link_data['location_id'] = $list;
             M("DealCateTypeLocationLink")->add($link_data);
         }
         $group_ids = $_REQUEST['group_id'];
         foreach ($group_ids as $gid => $preset) {
             if (trim($preset) != '') {
                 $link['group_id'] = $gid;
                 $link['supplier_location_id'] = $list;
                 $link['preset'] = trim($preset);
                 M("SupplierTagGroupPreset")->add($link);
             }
         }
         $show_group_ids = $_REQUEST['show_group_id'];
         $exist_tags_array = array();
         foreach ($show_group_ids as $gid => $row) {
             if (trim($row) != '') {
                 $show_tags_array = preg_split("[ |,]", $row);
                 foreach ($show_tags_array as $kk => $rr) {
                     $rs = explode("|", $rr);
                     $tag = trim($rs[0]);
                     $count = intval($rs[1]);
                     $exist_tags_array[] = "'" . $tag . "'";
                     if (trim($tag) != '') {
                         $tag_rs = array();
                         $tag_rs['tag_name'] = $tag;
                         $tag_rs['supplier_location_id'] = $list;
                         $tag_rs['group_id'] = $gid;
                         $tag_rs['total_count'] = $count;
                         M("SupplierTag")->add($tag_rs);
                     }
                 }
             }
         }
         clear_auto_cache("store_filter_nav_cache");
         syn_supplier_location_match($list);
         save_log($log_info . L("INSERT_SUCCESS"), 1);
         $this->success(L("INSERT_SUCCESS"));
     } else {
         //错误提示
         save_log($log_info . L("INSERT_FAILED"), 0);
         $this->error(L("INSERT_FAILED"));
     }
 }
Ejemplo n.º 4
0
 public function 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 . "/edit", array("id" => $data['id'])));
     if (!check_empty($data['name'])) {
         $this->error(L("SUPPLIER_NAME_EMPTY_TIP"));
     }
     //处理商户帐号信息部分
     $account_id = intval($_REQUEST['account_id']);
     //更新商户账户信息
     $account_ins['supplier_id'] = $data['id'];
     $account_ins['id'] = $account_id;
     $account_ins['account_name'] = strim($_REQUEST['account_name']);
     $account_ins['mobile'] = strim($_REQUEST['mobile']);
     $account_ins['is_effect'] = 1;
     if (!$account_ins['id']) {
         if (!$account_ins['account_name']) {
             $this->error("请输入管理员账户");
         }
         if (!$account_ins['mobile']) {
             $this->error("请输入商户手机");
         }
     }
     if (strim($_REQUEST['account_password'])) {
         $account_ins['account_password'] = md5(strim($_REQUEST['account_password']));
     } else {
         if (!$account_ins['id']) {
             $this->error("请输入密码");
         }
     }
     //商户帐号验证
     if (M("SupplierAccount")->where("account_name='" . $account_ins['account_name'] . "' and id<>" . $account_id)->count()) {
         $this->error("账户名已被使用!");
     }
     if (M("SupplierAccount")->where("mobile='" . $account_ins['mobile'] . "' and id<>" . $account_id)->count()) {
         $this->error("手机号已被使用!");
     }
     // 更新数据
     $list = M(MODULE_NAME)->save($data);
     if (false !== $list) {
         syn_supplier_match($data['id']);
         $account_ins['is_main'] = 1;
         if ($account_ins['id']) {
             M("SupplierAccount")->save($account_ins);
         } else {
             M("SupplierAccount")->add($account_ins);
         }
         //成功提示
         save_log($log_info . L("UPDATE_SUCCESS"), 1);
         $this->success(L("UPDATE_SUCCESS"));
     } else {
         //错误提示
         save_log($log_info . L("UPDATE_FAILED"), 0);
         $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
     }
 }
Ejemplo n.º 5
0
 public function insert()
 {
     B('FilterString');
     $ajax = intval($_REQUEST['ajax']);
     $data = M(MODULE_NAME)->create();
     //对于商户请求操作
     $id = intval($_REQUEST['id']);
     $edit_type = intval($_REQUEST['edit_type']);
     if ($id > 0 && $edit_type == 2) {
         //商户申请新增团购
         unset($data['id']);
     }
     //开始验证有效性
     $this->assign("jumpUrl", u(MODULE_NAME . "/add"));
     if (!check_empty($data['name'])) {
         $this->error(L("LOCATION_NAME_EMPTY_TIP"));
     }
     if ($data['city_id'] == 0) {
         $this->error(L("DEAL_CITY_EMPTY_TIP"));
     }
     $city_info = M("DealCity")->where("id=" . intval($data['city_id']))->find();
     if ($city_info['pid'] == 0) {
         $this->error("只能选择城市,不能选择省份");
     }
     // 更新数据
     //自动创建品牌
     if ($data['supplier_id'] == 0) {
         $supplier_data['name'] = $data['name'];
         $supplier_data['is_effect'] = 1;
         $supplier_id = M("Supplier")->add($supplier_data);
         syn_supplier_match($supplier_id);
         $data['supplier_id'] = $supplier_id;
     }
     $data['is_effect'] = 1;
     $log_info = $data['name'];
     if (M(MODULE_NAME)->where("name='" . $data['name'] . "'")->find()) {
         $this->error("门店名重复");
     } else {
         $list = M(MODULE_NAME)->add($data);
     }
     if (false !== $list) {
         //成功提示
         if ($data['is_main'] == 1) {
             M(MODULE_NAME)->where("supplier_id=" . $data['supplier_id'] . " and id <> " . $list)->setField("is_main", 0);
         }
         if (M(MODULE_NAME)->where("supplier_id=" . $data['supplier_id'] . " and is_main = 1")->count() == 0) {
             M(MODULE_NAME)->where("id=" . $list)->setField("is_main", 1);
         }
         $area_ids = $_REQUEST['area_id'];
         foreach ($area_ids as $area_id) {
             $area_data['area_id'] = $area_id;
             $area_data['location_id'] = $list;
             M("SupplierLocationAreaLink")->add($area_data);
         }
         $brand_ids = $_REQUEST['brand_id'];
         foreach ($brand_ids as $brand_id) {
             $brand_data['brand_id'] = $brand_id;
             $brand_data['location_id'] = $list;
             M("SupplierLocationBrandLink")->add($brand_data);
         }
         foreach ($_REQUEST['deal_cate_type_id'] as $type_id) {
             $link_data = array();
             $link_data['deal_cate_type_id'] = $type_id;
             $link_data['location_id'] = $list;
             M("DealCateTypeLocationLink")->add($link_data);
         }
         $group_ids = $_REQUEST['group_id'];
         foreach ($group_ids as $gid => $preset) {
             if (strim($preset) != '') {
                 $link['group_id'] = $gid;
                 $link['supplier_location_id'] = $list;
                 $link['preset'] = strim($preset);
                 M("SupplierTagGroupPreset")->add($link);
             }
         }
         $show_group_ids = $_REQUEST['show_group_id'];
         $exist_tags_array = array();
         foreach ($show_group_ids as $gid => $row) {
             if (strim($row) != '') {
                 $show_tags_array = preg_split("[ |,]", $row);
                 foreach ($show_tags_array as $kk => $rr) {
                     $rs = explode("|", $rr);
                     $tag = strim($rs[0]);
                     $count = intval($rs[1]);
                     $exist_tags_array[] = "'" . $tag . "'";
                     if (strim($tag) != '') {
                         $tag_rs = array();
                         $tag_rs['tag_name'] = $tag;
                         $tag_rs['supplier_location_id'] = $list;
                         $tag_rs['group_id'] = $gid;
                         $tag_rs['total_count'] = $count;
                         M("SupplierTag")->add($tag_rs);
                     }
                 }
             }
         }
         syn_supplier_location_match($list);
         save_log($log_info . L("INSERT_SUCCESS"), 1);
         if ($id > 0 && $edit_type == 2) {
             //商户提交审核
             //同步商户数据表
             $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_biz_submit", array("location_id" => $list, "admin_check_status" => 1), "UPDATE", "id=" . $id);
             //同步商户发布的图集
             $this->syn_location_images($list);
         }
         $this->success(L("INSERT_SUCCESS"));
     } else {
         //错误提示
         save_log($log_info . L("INSERT_FAILED"), 0);
         $this->error(L("INSERT_FAILED"));
     }
 }