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 shop_update() { B('FilterString'); $data = M(MODULE_NAME)->create(); //对于商户请求操作 if (intval($_REQUEST['edit_type']) == 2 && intval($_REQUEST['deal_id']) > 0) { //商户提交修改审核 $deal_submit_id = intval($_REQUEST['id']); $data['id'] = intval($_REQUEST['deal_id']); } $log_info = M(MODULE_NAME)->where("id=" . intval($data['id']))->getField("name"); //开始验证有效性 $this->assign("jumpUrl", u(MODULE_NAME . "/shop_edit", array("id" => $data['id']))); if ($data['buy_type'] == 0) { if (intval($data['return_score']) < 0) { $this->error("积分返还不能为负数"); } if (floatval($data['return_money']) < 0) { $this->error("现金返还不能为负数"); } } else { $data['return_score'] = "-" . abs($_REQUEST['deal_score']); if (intval($_REQUEST['deal_score']) == 0) { $this->error("请输入所需的积分"); } } if (!check_empty($data['name'])) { $this->error(L("DEAL_NAME_EMPTY_TIP")); } if (!check_empty($data['sub_name'])) { $this->error(L("DEAL_SUB_NAME_EMPTY_TIP")); } if ($data['shop_cate_id'] == 0) { $this->error(L("SHOP_CATE_EMPTY_TIP")); } if ($data['max_bought'] < 0) { $this->error(L("DEAL_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")); } if ($data['brand_promote'] == 1) { //品牌促销 $brand_info = M("Brand")->getById($data['brand_id']); if ($brand_info['brand_promote'] == 1) { $data['begin_time'] = $brand_info['begin_time']; $data['end_time'] = $brand_info['end_time']; } } else { $data['begin_time'] = strim($data['begin_time']) == '' ? 0 : to_timespan($data['begin_time']); $data['end_time'] = strim($data['end_time']) == '' ? 0 : to_timespan($data['end_time']); } $data['coupon_begin_time'] = strim($data['coupon_begin_time']) == '' ? 0 : to_timespan($data['coupon_begin_time']); $data['coupon_end_time'] = strim($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'] = NOW_TIME; $data['publish_wait'] = 0; 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; } if ($_REQUEST['deal_attr'] && count($_REQUEST['deal_attr']) > 0) { $data['multi_attr'] = 1; } else { $data['multi_attr'] = 0; } if ($data['buy_type'] != 1) { $deal_tags = $_REQUEST['deal_tag']; $deal_tag = 0; foreach ($deal_tags as $t) { $t2 = pow(2, $t); $deal_tag = $deal_tag | $t2; } $data['deal_tag'] = $deal_tag; } else { $data['deal_tag'] = 0; } $data['is_lottery'] = 0; foreach ($deal_tags as $t) { if ($t == 0) { $data['is_lottery'] = 1; } } if ($data['buy_type'] == 1) { $data['cart_type'] = 3; $data['is_refund'] = 0; $data['deal_tag'] = 0; $data['is_lottery'] = 0; } $inc_prices = $_REQUEST['inc_price']; if (isset($_REQUEST['level_ids'])) { //无数据 $level_ids = $_REQUEST['level_ids']; foreach ($level_ids as $key => $value) { $deal_tech_level = array('level_id' => $value, 'deal_id' => $data['id'], 'price' => $inc_prices[$key], 'createtime' => time()); M('dealTechLevel')->add($deal_tech_level); } } elseif ($_REQUEST['deal_tech_level_ids']) { //有数据 $deal_tech_level_ids = $_REQUEST['deal_tech_level_ids']; foreach ($deal_tech_level_ids as $key => $value) { $deal_tech_level = array('id' => $value, 'price' => $inc_prices[$key], 'createtime' => time()); M('dealTechLevel')->save($deal_tech_level); } } // 更新数据 $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("DealAttr")->where("deal_id=" . $data['id'])->delete(); $deal_attr = $_REQUEST['deal_attr']; $deal_attr_price = $_REQUEST['deal_attr_price']; $deal_add_balance_price = $_REQUEST['deal_add_balance_price']; $deal_attr_stock_hd = $_REQUEST['deal_attr_stock_hd']; foreach ($deal_attr as $goods_type_attr_id => $arr) { foreach ($arr as $k => $v) { if ($v != '') { $deal_attr_item['deal_id'] = $data['id']; $deal_attr_item['goods_type_attr_id'] = $goods_type_attr_id; $deal_attr_item['name'] = $v; $deal_attr_item['add_balance_price'] = $deal_add_balance_price[$goods_type_attr_id][$k]; $deal_attr_item['price'] = $deal_attr_price[$goods_type_attr_id][$k]; $deal_attr_item['is_checked'] = intval($deal_attr_stock_hd[$goods_type_attr_id][$k]); M("DealAttr")->add($deal_attr_item); } } } //开始创建属性库存 M("AttrStock")->where("deal_id=" . $data['id'])->delete(); $stock_cfg = $_REQUEST['stock_cfg_num']; $attr_cfg = $_REQUEST['stock_attr']; $attr_str = $_REQUEST['stock_cfg']; foreach ($stock_cfg as $row => $v) { $stock_data = array(); $stock_data['deal_id'] = $data['id']; $stock_data['stock_cfg'] = $v; $stock_data['attr_str'] = $attr_str[$row]; $attr_cfg_data = array(); foreach ($attr_cfg as $attr_id => $cfg) { $attr_cfg_data[$attr_id] = $cfg[$row]; } $stock_data['attr_cfg'] = serialize($attr_cfg_data); $sql = "select sum(oi.number) from " . DB_PREFIX . "deal_order_item as oi left join " . DB_PREFIX . "deal as d on d.id = oi.deal_id left join " . DB_PREFIX . "deal_order as do on oi.order_id = do.id where" . " do.pay_status = 2 and do.is_delete = 0 and d.id = " . $data['id'] . " and oi.attr_str like '%" . $attr_str[$row] . "%'"; $stock_data['buy_count'] = intval($GLOBALS['db']->getOne($sql)); M("AttrStock")->add($stock_data); } M("FreeDelivery")->where("deal_id=" . $data['id'])->delete(); if (intval($_REQUEST['free_delivery']) == 1) { $delivery_ids = $_REQUEST['delivery_id']; $free_counts = $_REQUEST['free_count']; foreach ($delivery_ids as $k => $v) { $free_conf = array(); $free_conf['delivery_id'] = $delivery_ids[$k]; $free_conf['free_count'] = $free_counts[$k]; $free_conf['deal_id'] = $data['id']; M("FreeDelivery")->add($free_conf); } } 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("DealDelivery")->where("deal_id=" . $data['id'])->delete(); $delivery_ids = $_REQUEST['forbid_delivery_id']; foreach ($delivery_ids as $k => $v) { $delivery_conf = array(); $delivery_conf['delivery_id'] = $delivery_ids[$k]; $delivery_conf['deal_id'] = $data['id']; M("DealDelivery")->add($delivery_conf); } //开始创建筛选项 M("DealFilter")->where("deal_id=" . $data['id'])->delete(); $filter = $_REQUEST['filter']; foreach ($filter as $filter_group_id => $filter_value) { $filter_data = array(); $filter_data['filter'] = $filter_value; $filter_data['filter_group_id'] = $filter_group_id; $filter_data['deal_id'] = $data['id']; M("DealFilter")->add($filter_data); // $filter_array = preg_split("/[ ,]/i",$filter_value); // foreach($filter_array as $filter_item) // { // $filter_row = M("Filter")->where("filter_group_id = ".$filter_group_id." and name = '".$filter_item."'")->find(); // if(!$filter_row) // { // if(strim($filter_item)!='') // { // $filter_row = array(); // $filter_row['name'] = $filter_item; // $filter_row['filter_group_id'] = $filter_group_id; // M("Filter")->add($filter_row); // } // // } // } } 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']); syn_deal_match($data['id']); syn_attr_stock_key($data['id']); //对于商户请求操作 if (intval($_REQUEST['edit_type']) == 2 && $deal_submit_id > 0) { //商户提交修改审核 /*同步商户发布表状态*/ $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_submit", array("admin_check_status" => 1), "UPDATE", "id=" . $deal_submit_id); // 1 通过 2 拒绝', } //成功提示 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 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 update() { B('FilterString'); $data = M("Deal")->create(); $log_info = M("Deal")->where("id=" . intval($data['id']))->getField("name"); //开始验证有效性 $this->assign("jumpUrl", "javascript:history.back(-1);"); if (!check_empty($data['name'])) { $this->error(L("DEAL_NAME_EMPTY_TIP")); } if (!check_empty($data['sub_name'])) { $this->error(L("DEAL_SUB_NAME_EMPTY_TIP")); } if ($data['cate_id'] == 0) { $this->error(L("DEAL_CATE_EMPTY_TIP")); } if (D("Deal")->where("deal_sn='" . $data['deal_sn'] . "' and id<>" . $data['id'])->count() > 0) { $this->error("借款编号已存在"); } $loantype_list = load_auto_cache("loantype_list"); if (!in_array($data['repay_time_type'], $loantype_list[$data['loantype']]['repay_time_type'])) { $this->error("还款方式不支持当前借款期限类型"); } $data['update_time'] = TIME_UTC; $data['publish_wait'] = 0; $data['start_time'] = trim($data['start_time']) == '' ? 0 : to_timespan($data['start_time']); $user_info = M("User")->getById($data['user_id']); $old_imgdata_str = unserialize($user_info['view_info']); $data['view_info'] = array(); foreach ($_REQUEST['key'] as $k => $v) { if (isset($old_imgdata_str[$v])) { $data['view_info'][$v] = $old_imgdata_str[$v]; } } $data['view_info'] = serialize($data['view_info']); if ($data['deal_status'] == 4) { if ($GLOBALS['db']->getOne("SELECT sum(money) FROM " . DB_PREFIX . "deal_load where deal_id=" . $data['id']) < floatval($data['borrow_amount'])) { $this->error("未满标无法设置为还款状态!"); exit; } } if ($data['agency_id'] != M("Deal")->where("id=" . $data['id'])->getField("agency_id")) { $data['agency_status'] = 0; } // 更新数据 $list = M("Deal")->save($data); if (false !== $list) { M("DealCityLink")->where("deal_id=" . $data['id'])->delete(); foreach ($_REQUEST['city_id'] as $k => $v) { if (intval($v) > 0) { $deal_city_link['deal_id'] = $data['id']; $deal_city_link['city_id'] = intval($v); M("DealCityLink")->add($deal_city_link); } } require_once APP_ROOT_PATH . "app/Lib/common.php"; if ($data['is_delete'] == 3) { //发送失败短信通知 if (app_conf("SMS_ON") == 1) { $user_info = D("User")->where("id=" . $data['user_id'])->find(); $deal_info = D("Deal")->where("id=" . $data['id'])->find(); $tmpl = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_SMS_DEAL_DELETE'"); $tmpl_content = $tmpl['content']; $notice['user_name'] = $user_info["user_name"]; $notice['deal_name'] = $data['name']; $notice['site_name'] = app_conf("SHOP_TITLE"); $notice['delete_msg'] = $data['delete_msg']; $notice['deal_publish_time'] = to_date($deal_info['create_time'], "Y年m月d日"); $GLOBALS['tmpl']->assign("notice", $notice); $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content); $msg_data['dest'] = $user_info['mobile']; $msg_data['send_type'] = 0; $msg_data['title'] = "审核失败通知"; $msg_data['content'] = addslashes($msg); $msg_data['send_time'] = 0; $msg_data['is_send'] = 0; $msg_data['create_time'] = TIME_UTC; $msg_data['user_id'] = $user_info['id']; $msg_data['is_html'] = $tmpl['is_html']; $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data); //插入 } } else { //成功提示 syn_deal_status($data['id']); syn_deal_match($data['id']); //发送电子协议邮件 require_once APP_ROOT_PATH . "app/Lib/deal.php"; send_deal_contract_email($data['id'], array(), $data['user_id']); } //成功提示 save_log("编号:" . $data['id'] . "," . $log_info . L("UPDATE_SUCCESS"), 1); $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $data['id']))); $this->success(L("UPDATE_SUCCESS")); } else { //错误提示 $dbErr = M()->getDbError(); save_log("编号:" . $data['id'] . "," . $log_info . L("UPDATE_FAILED") . $dbErr, 0); $this->error(L("UPDATE_FAILED") . $dbErr, 0); } }