function index($id = 0) { $this->css("top.css"); $this->js('time.js'); if (!($id > 0)) { $id = 6; } if (!($id > 0)) { $this->action('common', 'show404tpl'); } $json = Import::json(); $rt = $this->Cache->read(3600); if (is_null($rt)) { $time = mktime(); $sql = "SELECT * FROM `{$this->App->prefix()}topic` WHERE topic_id='{$id}' AND end_time > '{$time}' LIMIT 1"; $rt['info'] = $this->App->findrow($sql); if (empty($rt['info'])) { $this->jump(SITE_URL, '', "该专题已经超过有效期!"); } $rt['info']['goods_ids'] = addcslashes($rt['info']['goods_ids'], "'"); $tmp = @unserialize($rt['info']["goods_ids"]); $arr = (array) $tmp; $goods_id = array(); foreach ($arr as $key => $value) { foreach ($value as $k => $val) { $opt = explode('|', $val); $arr[$key][$k] = $opt[1]; $goods_id[] = $opt[1]; } } $sql = "SELECT goods_id,goods_name,goods_thumb,goods_img,shop_price,pifa_price FROM `{$this->App->prefix()}goods` WHERE goods_id IN(" . implode(',', $goods_id) . ")"; $rts = $this->App->find($sql); foreach ($rts as $rows) { foreach ($arr as $key => $value) { foreach ($value as $val) { if ($val == $rows['goods_id']) { $key = $key == 'default' ? 'default' : $key; $sort_goods_arr[$key][] = $rows; } } } } $rt['goodslist'] = $sort_goods_arr; unset($sort_goods_arr, $tts); //预告 $t1 = date('Y-m-d', mktime() + 24 * 3600); //$t2 = date('Y-m-d',mktime()-24*3600); $rt['yugao'] = array(); $sql = "SELECT tb1.article_title,tb1.article_img,tb2.cat_name,tb2.cat_title AS date1 FROM `{$this->App->prefix()}article` AS tb1 LEFT JOIN `{$this->App->prefix()}article_cate` AS tb2 ON tb1.cat_id = tb2.cat_id WHERE tb2.type='case' AND tb2.cat_name ='{$t1}' ORDER BY tb2.cat_title DESC"; $rt['yugao'] = $this->App->find($sql); $this->Cache->write($rt); } $title = $rt['info']['topic_name']; $this->title($title . ' - ' . $GLOBALS['LANG']['site_name']); $this->meta("title", $title); $this->meta("keywords", htmlspecialchars($rt['info']['meta_keys'])); $this->meta("description", htmlspecialchars($rt['info']['meta_desc'])); $this->set('rt', $rt); $this->template('topgoods'); }
function ajax_searchGoods($data = "") { $err = 0; $result = array('error' => $err, 'message' => ''); $json = Import::json(); if (empty($data)) { $result['error'] = 2; $result['message'] = '传送的数据为空!'; die($json->encode($result)); } $art = $json->decode($data); //反json $cat_id = $art->cat_id; $brand_id = $art->brand_id; $keyword = $art->keyword; $comd = array(); if (intval($cat_id) > 0) { $cids = $this->action('common', 'get_goods_sub_cat_ids', $cat_id); $comd[] = 'cat_id IN(' . implode(",", $cids) . ')'; } if (intval($brand_id) > 0) { $comd[] = "brand='{$brand_id}'"; } if (!empty($keyword)) { $comd[] = "goods_name LIKE '%{$keyword}%'"; } if (empty($comd)) { $result['error'] = 2; $result['message'] = ''; die($json->encode($result)); } $sql = "SELECT goods_id,goods_name FROM `{$this->App->prefix()}goods` WHERE " . implode(' AND ', $comd) . " ORDER BY goods_id DESC LIMIT 20"; $rt = $this->App->find($sql); $result['error'] = 1; $result['message'] = $rt; die($json->encode($result)); }
function ajax_getcategoodslist($w = array()) { $err = 0; $json = Import::json(); $result = array('error' => $err, 'message' => ''); if (empty($w)) { $result['error'] = 2; $result['message'] = '传送的数据为空!'; die($json->encode($result)); } $wobj = $json->decode($w); //反json ,返回值为对象 $page = $wobj->page; if (!$page) { $page = 1; } $cid = $wobj->cid; if (!$cid) { $cid = 0; } $bid = $wobj->bid; if (!$bid) { $bid = 0; } $price = $wobj->price; if (!$price) { $price = ""; } $order_type = $wobj->order; if (!$order_type) { $order_type = "goods_id"; } $keyword = $wobj->keyword; if (!$keyword) { $keyword = ""; } $sort_type = $wobj->sorts; if (empty($sort_type)) { $sort_type = "DESC"; } $list = $wobj->limit; if (!$list) { $list = 40; } if (!empty($keyword) && !(preg_match('/^.*$/u', $keyword) > 0)) { $keyword = Import::gz_iconv()->ec_iconv('GB2312', 'UTF8', $keyword); //编码转换 } $rt['thiscid'] = $cid; $rt['thisbid'] = $bid; $rt['price'] = $price; $rt['page'] = $page; $rt['sort'] = $sort_type; $rt['order'] = $order_type; $rt['limit'] = $list; //当前分类的基本信息 if ($cid > 0) { $sql = "SELECT * FROM `{$this->App->prefix()}goods_cate` WHERE cat_id='{$cid}' LIMIT 1"; $rt['cateinfo'] = $this->App->findrow($sql); } else { $rt['cateinfo'] = array(); //查找时没有cid } //品牌信息 if ($bid > 0) { $sql = "SELECT brand_name FROM `{$this->App->prefix()}brand` WHERE brand_id='{$bid}' LIMIT 1"; $rt['brandinfo']['brand_name'] = $this->App->findvar($sql); } else { $rt['brandinfo']['brand_name'] = ""; } //显示方式 if (!isset($_COOKIE['DISPLAY_TYPE']) || empty($_COOKIE['DISPLAY_TYPE']) || !in_array($_COOKIE['DISPLAY_TYPE'], array('list', 'text'))) { $rt['display'] = 'text'; } else { $rt['display'] = $_COOKIE['DISPLAY_TYPE']; } //start 当前位置 $rt['hear'] = array(); $perend_id = 0; $hear[] = '<a href="' . SITE_URL . '">首页</a>'; $hear[] = '<a href="' . get_url('商品中心', 0, SITE_URL . "costume.php", 'goodscate', array('catalog', 'index')) . '">商品中心</a>'; if ($cid > 0) { $rts_ = $this->get_goods_parent_cats($cid); //父类ID $rts = Import::basic()->array_sort($rts_, 'cat_id'); //根据cat_id排序 if (!empty($rts)) { $perend_id = $rts[count($rts) - 1]['cat_id']; foreach ($rts as $rows) { $hear[] = '<a href="' . get_url($rows['cat_name'], $rows['cat_id'], "costume.php?cid=" . $rows["cat_id"], 'goodscate', array('catalog', 'index', $row['cat_id'])) . '">' . $rows['cat_name'] . '</a>'; } } unset($rts, $rts_); } elseif ($bid > 0) { //品牌 $hear[] = '<a href="' . SITEURL . 'brand/">品牌中心</a>'; $hear[] = '<a href="' . get_url($rt['brandinfo']['brand_name'], $rt['brandinfo']['brand_id'], "costume.php?bid=" . $rt['brandinfo']['brand_id'], 'brand') . '">' . $rt['brandinfo']['brand_name'] . '</a>'; } elseif (!empty($keyword)) { $perend_id = -1; switch ($keyword) { case 'is_hot': $hear[] = '<a href="' . SITE_URL . 'hotproduct/">热销商品</a>'; break; case 'is_new': $hear[] = '<a href="' . SITE_URL . 'newproduct/">新商推荐</a>'; break; case 'is_best': $hear[] = '<a href="' . SITE_URL . 'bestproduct/">精品推荐</a>'; break; case 'is_promote': $hear[] = '<a href="' . SITE_URL . 'promote/">促销商品</a>'; break; default: $hear[] = '<a href="javascript:;">商品查找</a>'; $hear[] = '<a href="' . SITE_URL . 'costume.php?keyword=' . $keyword . '">' . $keyword . '</a>'; break; } } elseif (!empty($price)) { $perend_id = -1; $hear[] = '<a href="javascript:;">价格商品</a>'; } else { $perend_id = -1; $hear[] = '<a href="' . get_url('商品中心', 0, SITE_URL . "costume.php", 'goodscate', array('catalog', 'index')) . '">商品分类</a>'; } if (!empty($hear)) { $rt['hear'] = implode(' > ', $hear); } else { $rt['hear'] = ""; } unset($hear); //end 当前位置 //分类信息 if (!empty($rt['cateinfo']['cat_name'])) { $rt['infoname'] = $pcat_name . $rt['cateinfo']['cat_name']; } elseif (!empty($rt['brandinfo']['brand_name'])) { $rt['infoname'] = $rt['brandinfo']['brand_name']; } elseif (!empty($keyword)) { switch ($keyword) { case 'is_hot': $rt['infoname'] = "热销商品专区"; break; case 'is_new': $rt['infoname'] = "新品推荐"; break; case 'is_best': $rt['infoname'] = "精品推荐"; $rt['cateinfo']['cat_title'] = "精选商品-%100满意"; break; case 'is_promote': $rt['infoname'] = "促销商品专区"; break; default: $rt['infoname'] = "商品搜索中心:" . $keyword; break; } } elseif (!empty($price)) { $rt['infoname'] = $price . '价格商品'; } else { $rt['infoname'] = '商品中心'; } //条件 $comd = array('cid' => $cid, 'bid' => $bid, 'price' => $price, 'keyword' => $keyword); $orderby = " ORDER BY g.{$order_type} {$sort_type}"; $start = ($page - 1) * $list; $tt = $this->App->__get_goods_count_category($comd); //获取商品的数量 $rt['categoodspage'] = Import::basic()->ajax_page($tt, $list, $page, 'get_categoods_page_list', array($cid, $bid, $price, $order_type, $sort_type, $list)); $rt['categoodslist'] = $this->App->__get_categoods_list_category($comd, $orderby, $start, $list); //商品列表 $this->set('rt', $rt); $con = $this->fetch('ajax_goods_connent', true); $result = array('error' => $err, 'message' => $con); die($json->encode($result)); }
function ajax_save_and_caijigoods() { $data = $_GET['message']; $err = 0; $result = array('error' => $err, 'message' => ''); $json = Import::json(); if (empty($data)) { $result['error'] = 2; $result['message'] = '传送的数据为空!'; die($json->encode($result)); } $mesobj = $json->decode($data); //反json ,返回值为对象 //以下字段对应评论的表单页面 一定要一致 $goods_name = $mesobj->goods_name; !empty($goods_name) ? $datas['goods_name'] = $goods_name : ""; $cat_id = $mesobj->cat_id; !empty($cat_id) ? $datas['cat_id'] = $cat_id : ""; $brand_id = $mesobj->brand_id; !empty($brand_id) ? $datas['brand_id'] = $brand_id : ""; $goods_bianhao = $mesobj->goods_bianhao; !empty($goods_bianhao) ? $datas['goods_bianhao'] = $goods_bianhao : ""; $goods_sn = $mesobj->goods_sn; !empty($goods_sn) ? $datas['goods_sn'] = $goods_sn : ""; $goods_unit = $mesobj->goods_unit; !empty($goods_unit) ? $datas['goods_unit'] = $goods_unit : ""; $goods_brief = $mesobj->goods_brief; !empty($goods_brief) ? $datas['goods_brief'] = $goods_brief : ""; $shop_price = $mesobj->shop_price; $shop_price > 0 ? $datas['shop_price'] = $shop_price : ""; $pifa_price = $mesobj->pifa_price; if (intval($pifa_price) > 0) { $datas['pifa_price'] = intval($pifa_price); $datas['market_price'] = $datas['pifa_price']; } else { $datas['pifa_price'] = $shop_price; $datas['market_price'] = $shop_price; } $goods_number = $mesobj->goods_number; intval($goods_number) > 0 ? $datas['goods_number'] = intval($goods_number) : ""; $warn_number = $mesobj->warn_number; intval($warn_number) > 0 ? $datas['warn_number'] = intval($warn_number) : ""; $meta_keys = $mesobj->meta_keys; !empty($meta_keys) ? $datas['meta_keys'] = $meta_keys : ""; $meta_desc = $mesobj->meta_desc; !empty($meta_desc) ? $datas['meta_desc'] = $meta_desc : ""; $original_img = $mesobj->original_img; if (!empty($original_img)) { $datas['original_img'] = $original_img; $pa = dirname($original_img); $thumb = basename($original_img); $datas['goods_img'] = $pa . '/thumb_b/' . $thumb; $datas['goods_thumb'] = $pa . '/thumb_s/' . $thumb; } $gid = $mesobj->goods_id; if (empty($datas['goods_bianhao'])) { $gids = $this->App->findvar("SELECT MAX(goods_id) + 1 FROM `{$this->App->prefix()}goods`"); $gids = empty($gids) ? 1 : $gids; $datas['goods_bianhao'] = '2EJ' . str_repeat('0', 6 - strlen($gids)) . $gids . '-' . $gid; } //检查是否已经存在 if (empty($datas['goods_sn'])) { $datas['goods_sn'] = $datas['goods_bianhao']; } $uid = 50; $this->App->update('goods_cache_list', $datas, 'goods_id', $gid); //更新 //转移 $dd = array(); $dd['goods_number'] = $datas['goods_number'] > 0 ? $datas['goods_number'] : 1000; $dd['warn_number'] = $datas['warn_number'] > 0 ? $datas['warn_number'] : 10; if ($datas['market_price'] > 0) { $dd['market_price'] = $datas['market_price']; } if ($datas['pifa_price'] > 0) { $dd['pifa_price'] = $datas['pifa_price']; } if ($datas['shop_price'] > 0) { $dd['shop_price'] = $datas['shop_price']; } $sql = "SELECT add_time FROM `{$this->App->prefix()}goods_cache_list` WHERE goods_id='{$gid}'"; $ad = $this->App->findvar($sql); if (empty($ad)) { $datas['add_time'] = mktime(); $this->App->insert('goods', $datas); $lastid = $this->App->iid(); $this->App->update('goods_cache_list', array('add_time' => $datas['add_time'], 'is_zhuanyi' => '1'), 'goods_id', $gid); //添加到供应商商品表 $sql = "SELECT sgid FROM `{$this->App->prefix()}suppliers_goods` WHERE goods_id='{$lastid}' AND suppliers_id='{$uid}'"; $sgid = $this->App->findvar($sql); $dd['is_check'] = 1; $dd['is_on_sale'] = 1; $dd['goods_id'] = $lastid; $dd['suppliers_id'] = $uid; $dd['addtime'] = mktime(); $this->App->insert('suppliers_goods', $dd); $result['message'] = '保存并转移成功'; } else { $sql = "SELECT goods_id FROM `{$this->App->prefix()}goods` WHERE add_time='{$ad}'"; $goodid = $this->App->findvar($sql); if ($goodid > 0) { //更新 $datas['last_update'] = mktime(); $this->App->update('goods', $datas, 'goods_id', $goodid); //更新供应商商品表 $sql = "SELECT sgid FROM `{$this->App->prefix()}suppliers_goods` WHERE goods_id='{$goodid}' AND suppliers_id='{$uid}'"; $sgid = $this->App->findvar($sql); $dd['is_check'] = 1; if (empty($sgid) || !($sgid > 0)) { $dd['is_on_sale'] = 1; $dd['goods_id'] = $goodid; $dd['suppliers_id'] = $uid; $dd['addtime'] = mktime(); $this->App->insert('suppliers_goods', $dd); } else { $this->App->update('suppliers_goods', $dd, array("suppliers_id='{$uid}'", "goods_id='{$goodid}'")); } $result['message'] = '保存并转移修改成功'; } else { $datas['add_time'] = mktime(); $this->App->insert('goods', $datas); $lastid = $this->App->iid(); $this->App->update('goods_cache_list', array('add_time' => $datas['add_time'], 'is_zhuanyi' => '1'), 'goods_id', $gid); //添加到供应商商品表 $sql = "SELECT sgid FROM `{$this->App->prefix()}suppliers_goods` WHERE goods_id='{$lastid}' AND suppliers_id='{$uid}'"; $sgid = $this->App->findvar($sql); $dd['is_check'] = 1; $dd['is_on_sale'] = 1; $dd['goods_id'] = $lastid; $dd['suppliers_id'] = $uid; $dd['addtime'] = mktime(); $this->App->insert('suppliers_goods', $dd); $result['message'] = '保存并转移成功'; } } $result['error'] = 0; unset($data, $datas, $dd); die($json->encode($result)); }
function ajax_ressinfoop($data = array()) { $uid = $this->Session->read('User.uid'); if (isset($data['attrbul']) && !empty($data['attrbul'])) { $err = 0; $result = array('error' => $err, 'message' => ''); $json = Import::json(); $attrbul = $json->decode($data['attrbul']); //反json if (empty($attrbul)) { $result['error'] = 1; $result['message'] = "传送的数据为空!"; die($json->encode($result)); } $id = $attrbul->id; $dd = array(); $type = $attrbul->type; $dd['user_id'] = $uid; $dd['consignee'] = $attrbul->consignee; if (empty($dd['consignee'])) { $result['error'] = 1; $result['message'] = "收货人姓名不能为空!"; die($json->encode($result)); } $dd['country'] = 1; $dd['province'] = $attrbul->province; $dd['city'] = $attrbul->city; $dd['district'] = $attrbul->district; $dd['address'] = $attrbul->address; /*$dd['shoppingname'] = $attrbul->shoppingname; $dd['shoppingtime'] = $attrbul->shoppingtime;*/ if (empty($dd['province']) || empty($dd['city']) || empty($dd['district']) || empty($dd['address'])) { $result['error'] = 1; $result['message'] = "收货地址不能为空!"; die($json->encode($result)); } $dd['sex'] = $attrbul->sex; $dd['email'] = $attrbul->email; $dd['zipcode'] = $attrbul->zipcode; $dd['mobile'] = $attrbul->mobile; $dd['tel'] = $attrbul->tel; if (empty($dd['mobile']) && empty($dd['tel'])) { $result['error'] = 1; $result['message'] = "电话或者手机必须填写一个!"; die($json->encode($result)); } $dd['is_default'] = '1'; if (!($id > 0) && $type == 'add') { //添加 $this->App->update('user_address', array('is_default' => '0'), 'user_id', $uid); $this->App->insert('user_address', $dd); } elseif ($type == 'update') { //编辑 $this->App->update('user_address', $dd, 'address_id', $id); } unset($dd); if (empty($dd['mobile']) && empty($dd['tel'])) { $result['error'] = 0; $result['message'] = "操作成功!"; die($json->encode($result)); } exit; } $id = $data['id']; $type = $data['type']; if (!empty($id) && !empty($type)) { switch ($type) { case 'delete': //删除收货地址 $this->App->delete('user_address', 'address_id', $id); break; case 'setdefaut': //设为默认收货地址 if (!empty($uid)) { $this->App->update('user_address', array('is_default' => '0'), 'user_id', $uid); $this->App->update('user_address', array('is_default' => '1'), 'address_id', $id); } break; case 'quxiao': //取消收货地址 $this->App->update('user_address', array('is_default' => '0'), 'address_id', $id); break; case 'showupdate': //当前用户的收货地址 $sql = "SELECT * FROM `{$this->App->prefix()}user_address` WHERE user_id='{$uid}' AND address_id='{$id}'"; $rt['userress'] = $this->App->findrow($sql); $rt['province'] = $this->get_regions(1); //获取省列表 $rt['city'] = $this->get_regions(2, $rt['userress']['province']); //城市 $rt['district'] = $this->get_regions(3, $rt['userress']['city']); //区 $this->set('rt', $rt); $con = $this->fetch('ajax_show_updateressbox', true); die($con); break; } } }
function ajax_comment($data = array(), $page = 0) { $err = 0; $result = array('error' => $err, 'message' => ''); $json = Import::json(); if (!($page > 0)) { $page = 1; if (empty($data['comments'])) { $result['error'] = 1; $result['message'] = '意外错误,传送的数据为空!'; die($json->encode($result)); } $comments = $json->decode($data['comments']); //反json ,返回值为对象 $goods_id = $comments->goods_id; if (!(intval($goods_id) > 0)) { $result['error'] = 1; $result['message'] = '意外错误,传送的数据为空!'; die($json->encode($result)); } //以下字段对应评论的表单页面 一定要一致 $datas['id_value'] = $goods_id; //$datas['email'] = $comments->email; $username = $this->Session->read('User.username'); $uid = $this->Session->read('User.uid'); $error2 = false; $datas['user_name'] = !empty($username) ? $username : ""; if (empty($datas['user_name']) || !($uid > 0)) { //需要登录 $result['error'] = 4; $result['message'] = '你还没有登录!请你先登录!'; die($json->encode($result)); } //检查是否已经存在购买商品 $sql = "SELECT tb1.rec_id FROM `{$this->App->prefix()}goods_order` AS tb1"; $sql .= " LEFT JOIN `{$this->App->prefix()}goods_order_info` AS tb2 ON tb1.order_id=tb2.order_id"; $sql .= " WHERE tb1.goods_id='{$goods_id}' AND tb2.user_id='{$uid}' AND tb2.order_status='2' AND tb2.pay_status='1'"; $re_id = $this->App->findvar($sql); if (!($re_id > 0)) { //不存在该记录! $result['error'] = 1; $result['message'] = '抱歉,你还没有购买当前商品,不能评论哦!'; die($json->encode($result)); } //检查该商品是否已经评论过 $sql = "SELECT comment_id FROM `{$this->App->prefix()}comment` WHERE id_value='{$goods_id}' AND user_id='{$uid}' LIMIT 1"; $comment_id = $this->App->findvar($sql); if ($comment_id > 0) { //存在该记录! $result['error'] = 1; $result['message'] = '抱歉,你已经评论过该商品,不能再评论哦!'; die($json->encode($result)); } $datas['content'] = $comments->comment; if (empty($datas['content'])) { $result['error'] = 1; $result['message'] = '请填写评论内容!'; die($json->encode($result)); } if (strlen($datas['content']) < 12) { $result['error'] = 1; $result['message'] = '评论内容不能太少!'; die($json->encode($result)); } //限制用户不能重复提交评论,需要等待三分钟后才能评论 $read_time = $this->Session->read("Comment.{$goods_id}"); if (!empty($read_time)) { if (mktime() - $read_time < 200) { $result['error'] = 3; $result['message'] = '你刚才已经发表了评论,请你稍等下再发表!'; die($json->encode($result)); } } $this->Session->write("Comment.{$goods_id}", mktime()); $datas['comment_rank'] = $comments->comment_rank; $datas['goods_rand'] = $comments->goods_rand; $datas['goods_rand'] = empty($datas['goods_rand']) ? 5 : $datas['goods_rand']; $datas['shopping_rand'] = $comments->shopping_rand; $datas['shopping_rand'] = empty($datas['shopping_rand']) ? 5 : $datas['shopping_rand']; $datas['saleafter_rand'] = $comments->saleafter_rand; $datas['saleafter_rand'] = empty($datas['saleafter_rand']) ? 5 : $datas['saleafter_rand']; $datas['status'] = '1'; $datas['add_time'] = mktime(); $ip = Import::basic()->getip(); $datas['ip_address'] = $ip ? $ip : '0.0.0.0'; $datas['ip_form'] = Import::ip()->ipCity($ip); $datas['user_id'] = intval($uid) > 0 ? intval($uid) : 0; $this->App->insert('comment', $datas); unset($datas, $data); } //查询评论 $list = 2; $start = ($page - 1) * $list; $tt = $this->get_comment_count($goods_id); $rt['comment_count'] = $tt; $rt['commentlist'] = $this->get_comment_list($goods_id, $start, $list); $rt['commentpage'] = Import::basic()->ajax_page($tt, $list, $page, 'get_comment_page', array($goods_id)); $this->set('rt', $rt); $result['message'] = $this->fetch('ajax_comment', true); die($json->encode($result)); }
function zhuanyi_goods() { if (isset($_GET['kk']) && isset($_GET['maxpage'])) { $imgobj = Import::img(); $kk = $_GET['kk']; $list = 20; if ($kk == 0) { $tt = $this->App->findvar("SELECT COUNT(goods_id) FROM `{$this->App->prefix()}goods`"); $maxpage = ceil($tt / $list); } else { $maxpage = $_GET['maxpage']; } $start = $kk * $list; $sql = "SELECT g.*,u.user_name FROM `{$this->App->prefix()}goods` AS g LEFT JOIN `{$this->App->prefix()}user` AS u ON u.user_id = g.uid LIMIT {$start},{$list}"; $rt = $this->App->find($sql); $str = ""; if (!empty($rt)) { foreach ($rt as $row) { //检查是否已经存在该记录 if ($row['uid'] > 0) { $sgid = $this->App->findvar("SELECT sgid FROM `{$this->App->prefix()}suppliers_goods` WHERE suppliers_id='{$row['uid']}' AND goods_id='{$row['goods_id']}'"); if (empty($sgid)) { $this->App->insert('suppliers_goods', array('suppliers_id' => $row['uid'], 'goods_id' => $row['goods_id'], 'market_price' => $row['market_price'], 'shop_price' => $row['shop_price'], 'pifa_price' => $row['pifa_price'], 'is_on_sale' => $row['is_on_sale'], 'is_delete' => $row['is_delete'], 'is_check' => $row['is_check'], 'addtime' => mktime())); $str .= '转移=>供应商[' . $row['user_name'] . '] goods_id[' . $row['goods_id'] . '] 供应价[' . $row['market_price'] . '] 零售价[' . $row['shop_price'] . '] 批发价[' . $row['pifa_price'] . ']' . "<br/>"; } else { //$this->App->update('suppliers_goods',array('suppliers_id'=>$row['uid'],'goods_id'=>$row['goods_id'],'market_price'=>$row['market_price'],'shop_price'=>$row['shop_price'],'pifa_price'=>$row['pifa_price'],'is_on_sale'=>$row['is_on_sale'],'is_delete'=>$row['is_delete'],'addtime'=>mktime()),array("goods_id='$row[goods_id]'","suppliers_id='$row[uid]'")); $str .= "该商品已经存在=goods_id:" . $row['goods_id'] . ",正在更新!<br/>"; } } else { $str .= "没有指定供应商!<br/>"; } } } $kk = $kk + 1; $str .= "<font color=red>==============Load.....page(" . $kk . ")================</font><br />"; if ($kk > $maxpage) { $kk = ""; } sleep(2); $rts = array('kk' => $kk, 'url' => $str, 'maxpage' => $maxpage); die(Import::json()->encode($rts)); } $this->template('zhuanyi_goods'); }
function ajax_feedback($data = array()) { $err = 0; $result = array('error' => $err, 'message' => ''); $json = Import::json(); if (empty($data)) { $result['error'] = 2; $result['message'] = '传送的数据为空!'; die($json->encode($result)); } $mesobj = $json->decode($data); //反json ,返回值为对象 //以下字段对应评论的表单页面 一定要一致 $datas['comment_title'] = $mesobj->comment_title; $datas['goods_id'] = $mesobj->goods_id; $goods_id = $datas['goods_id']; $uid = $this->Session->read('User.uid'); $datas['user_id'] = !empty($uid) ? $uid : 0; $datas['status'] = 2; if (strlen($datas['comment_title']) < 12) { $result['error'] = 2; $result['message'] = '评论内容不能太少!'; die($json->encode($result)); } //检查需要超过24小时候才能再次提问 //if(!empty($goods_id)){ $t = mktime() + 24 * 3600; $sql = "SELECT addtime FROM `{$this->App->prefix()}message` WHERE user_id='{$uid}' AND goods_id='{$goods_id}' ORDER BY addtime DESC LIMIT 1"; $dt = $this->App->findvar($sql); if (!empty($dt)) { if ($dt + 3600 * 24 > mktime()) { $result['error'] = 1; $result['message'] = '今天你已经发表过提问了,请你<font color=red>' . intval(($dt + 3600 * 24 - mktime()) / 3600) . '</font>小时之后再次提问吧!'; die($json->encode($result)); } } //} /*$datas['content'] = $mesobj->content;goods_id $datas['user_name'] = $mesobj->user_name; $datas['sex'] = $mesobj->sex; $datas['mobile'] = $mesobj->mobile; $datas['telephone'] = $mesobj->telephone; $datas['email'] = $mesobj->email; $datas['companyname'] = $mesobj->companyname; $datas['address'] = $mesobj->address; $datas['companyurl'] = $mesobj->companyurl; */ $datas['addtime'] = mktime(); $ip = Import::basic()->getip(); $datas['ip_address'] = $ip ? $ip : '0.0.0.0'; $datas['ip_from'] = Import::ip()->ipCity($ip); if ($this->App->insert('message', $datas)) { $rl = $this->action('user', 'add_user_jifen', 'comment'); $result['error'] = 0; $result['message'] = '提问成功,我们会很快回答你的问题!<br />恭喜你,本次提问所得积分:' . $rl['points'] . '分!'; } else { $result['error'] = 1; $result['message'] = '提问失败,请通过在线联系客服吧!'; } unset($datas, $data); //查询评论 if (!$page) { $page = 1; } $list = 2; $start = ($page - 1) * $list; $tt = $this->__get_message_count($goods_id); $rt['message_count'] = $tt; $rt['messagelist'] = $this->__get_message($goods_id, $start, $list); $rt['messagepage'] = Import::basic()->ajax_page($tt, $list, $page, 'get_message_page', array($goods_id)); $rt['goodsinfo']['goods_id'] = $goods_id; $this->set('rt', $rt); $result['message'] = $this->fetch('ajax_message', true); die($json->encode($result)); }
function ajax_get_freecatalog($data = array()) { $err = 0; $result = array('error' => $err, 'message' => ''); $json = Import::json(); if (empty($data)) { $result['error'] = 2; echo $result['message'] = '传送的数据为空!'; exit; //die($json->encode($result)); } $mesobj = $json->decode($data); //反json ,返回值为对象 $is_freecatalog_time = $this->Session->read("User.is_freecatalog_time"); if (!empty($is_freecatalog_time) && mktime() - $is_freecatalog_time < 1000) { $result['error'] = 2; echo $result['message'] = '你已经提交过了,请歇歇吧 !'; exit; //die($json->encode($result)); } //以下字段对应评论的表单页面 一定要一致 $dir_ids = $mesobj->dir_ids; //$s = str_replace('++',"",$dir_ids); if (empty($dir_ids)) { $result['error'] = 2; echo $result['message'] = '请选择您想索取的目录 !'; exit; //die($json->encode($result)); } $fn = SYS_PATH . 'data/freecatalogdata.php'; file_exists($fn) ? require_once $fn : ($freecatalog = array()); if (empty($freecatalog)) { $result['error'] = 2; echo $result['message'] = '管理需要现在后台设置好提取目录在执行!'; exit; //die($json->encode($result)); } $dir_ids_rt = explode("--", $dir_ids); $dbids = array(); foreach ($dir_ids_rt as $k => $hh) { $hh = intval($hh) - 1; $dbids[] = $freecatalog[$hh]; } $datas['dir_ids'] = !empty($dbids) ? implode('、 ', $dbids) : ""; unset($dir_ids_rt, $dbids); $datas['user_name'] = $mesobj->username; if (empty($datas['user_name'])) { $result['error'] = 2; echo $result['message'] = '姓名不能为空 !'; exit; //die($json->encode($result)); } $datas['birthday'] = $mesobj->birthday; $datas['user_id'] = $mesobj->user_no; //顾客号 $datas['sex'] = $mesobj->sex; $datas['province'] = $mesobj->province; $datas['city'] = $mesobj->city; $datas['district'] = $mesobj->district; $datas['address'] = $mesobj->address; if (empty($datas['province']) || empty($datas['city']) || empty($datas['district']) || empty($datas['address'])) { $result['error'] = 2; echo $result['message'] = '请填写好完整的地址 !'; exit; //die($json->encode($result)); } $datas['postcode'] = $mesobj->postcode; $datas['dayphone'] = $mesobj->dayphone; $datas['nightphone'] = $mesobj->nightphone; $datas['mobile'] = $mesobj->mobile; if (empty($datas['mobile'])) { $result['error'] = 2; echo $result['message'] = '手机不能为空 !'; exit; //die($json->encode($result)); } $datas['email'] = $mesobj->email; $datas['addtime'] = mktime(); $ip = Import::basic()->getip(); $datas['ip_address'] = $ip ? $ip : '0.0.0.0'; $datas['ip_from'] = Import::ip()->ipCity($ip); if ($this->App->insert('freecatalog', $datas)) { $result['error'] = 0; $result['message'] = '你已经提交,我们很快会联系你!'; $this->Session->write("User.is_freecatalog_time", mktime()); } else { $result['error'] = 1; $result['message'] = '提交失败,请通过在线联系客服吧!'; } unset($datas, $data); echo $result['message']; exit; die($json->encode($result)); }
function ajax_getcategoodslist($data = array()) { $w = $data['goodswhere']; unset($data); $err = 0; $json = Import::json(); $result = array('error' => $err, 'message' => ''); if (empty($w)) { $result['error'] = 2; $result['message'] = 'IS DATA EMPTY!'; die($json->encode($result)); } $wobj = $json->decode($w); //反json ,返回值为对象 $page = $wobj->page; if (!$page) { $page = 1; } $cid = $wobj->cid; if (!$cid) { $cid = 0; } $bid = $wobj->bid; if (!$bid) { $bid = 0; } $price = $wobj->price; if (!$price) { $price = ""; } $order_type = $wobj->order; if (!$order_type) { $order_type = "goods_id"; } $keyword = $wobj->keyword; if (!$keyword) { $keyword = ""; } $sort_type = $wobj->sorts; if (empty($sort_type)) { $sort_type = "DESC"; } $list = $wobj->limit; if (!$list) { $list = 40; } if (!empty($keyword) && !(preg_match('/^.*$/u', $keyword) > 0)) { $keyword = Import::gz_iconv()->ec_iconv('GB2312', 'UTF8', $keyword); //编码转换 } $attr = $wobj->attr; //属性 $rt['thiskeyword'] = $keyword; $rt['thisattr'] = $attr; $rt['thiscid'] = $cid; $rt['thisbid'] = $bid; $rt['price'] = $price; $rt['page'] = $page; $rt['sort'] = $sort_type; $rt['order'] = $order_type; $rt['limit'] = $list; //当前分类的基本信息 if ($bid > 0) { $sql = "SELECT brand_name FROM `{$this->App->prefix()}brand` WHERE brand_id='{$bid}' LIMIT 1"; $rt['infoname'] = $this->App->findvar($sql); } elseif ($cid > 0) { $sql = "SELECT cat_name FROM `{$this->App->prefix()}goods_cate` WHERE cat_id='{$cid}' LIMIT 1"; $rt['infoname'] = $this->App->findvar($sql); } else { $rt['infoname'] = 'Category'; } //display type if (!isset($_COOKIE['DISPLAY_TYPE']) || empty($_COOKIE['DISPLAY_TYPE']) || !in_array($_COOKIE['DISPLAY_TYPE'], array('list', 'gallery'))) { $rt['display'] = 'gallery'; } else { $rt['display'] = $_COOKIE['DISPLAY_TYPE']; } if (isset($_COOKIE['THISORDER']) && !empty($_COOKIE['THISORDER'])) { $rt['thisorder'] = $_COOKIE['THISORDER']; } //条件 $comd = array('cid' => $cid, 'bid' => $bid, 'price' => $price, 'keyword' => $keyword, 'attr' => !empty($attr) ? explode('|', $attr) : array()); $orderby = " ORDER BY g.{$order_type} {$sort_type}"; $start = ($page - 1) * $list; $tt = $this->App->__get_goods_count_category($comd); //获取商品的数量 $rt['goods_count'] = $tt; $rt['categoodspage'] = Import::basic()->ajax_page($tt, $list, $page, 'get_categoods_page_list', array($cid, $bid, $price, $order_type, $sort_type, $list, $attr)); $rt['categoodslist'] = $this->App->__get_categoods_list_category($comd, $orderby, $start, $list); //商品列表 $this->set('rt', $rt); $con = $this->fetch('ajax_goods_connent', true); $result = array('error' => $err, 'message' => $con); die($json->encode($result)); }
function ajax_change_price($data = array()) { $id = $data['id']; $number = $data['number']; $maxnumber = $this->Session->read("cart.{$id}.goods_number"); if ($number > $maxnumber) { die("购买数量已经超过了库存,你最大只能购买:" . $maxnumber); } //是否是赠品,如果是赠品,那么只能添加一件,不能重复添加 $is_alone_sale = $this->Session->read("cart.{$id}.is_alone_sale"); if (!empty($is_alone_sale)) { $this->Session->write("cart.{$id}.number", $number); } //end 赠品 $uid = $this->Session->read('User.uid'); $active = $this->Session->read('User.active'); //用户等级折扣 $discount = 100; $rank = $this->Session->read('User.rank'); if ($rank > 0) { $sql = "SELECT discount FROM `{$this->App->prefix()}user_level` WHERE lid='{$rank}' LIMIT 1"; $discount = $this->App->findvar($sql); } $json = Import::json(); $cartlist = $this->Session->read('cart'); $total = 0; if (!empty($cartlist)) { foreach ($cartlist as $row) { $comd = array(); if (!empty($uid) && $active == '1') { if ($discount > 0) { $comd[] = $discount / 100 * $row['shop_price']; } if ($row['shop_price'] > 0 && $rank == 1) { //个人会员价格 $comd[] = $row['shop_price']; //个人会员价格 } if ($row['pifa_price'] > 0 && $rank != '1') { //高级会员价格 $comd[] = $row['pifa_price']; //高级会员价格 } } else { $comd[] = $row['shop_price']; } if ($row['is_promote'] == '1' && $row['promote_start_date'] < mktime() && $row['promote_end_date'] > mktime() && $row['promote_price'] > 0) { //促销价格 $comd[] = $row['promote_price']; } if ($row['is_qianggou'] == '1' && $row['qianggou_start_date'] < mktime() && $row['qianggou_end_date'] > mktime() && $row['qianggou_price'] > 0) { //抢购价格 $comd[] = $row['qianggou_price']; } $onetotal = min($comd); $total += $row['number'] * $onetotal; //是否赠品,如:买10送1 $gifts = array(); $gift2 = array(); if (!empty($row['buy_more_best']) && $row['goods_id'] == $id) { if (preg_match_all('/1\\d{1,2}|2[01][0-9]|22[0-7]|[1-9][0-9]|[1-9]/', $row['buy_more_best'], $buyrt)) { $num1 = isset($buyrt[0][0]) ? $buyrt[0][0] : 0; $num2 = isset($buyrt[0][1]) ? $buyrt[0][1] : 0; $gift2 = $this->Session->read("cart.{$id}.gifts"); if ($number >= $num1 && $num2 > 0) { //允许赠品 $mb = mb_substr(trim($row['buy_more_best']), -1, 1, 'utf-8'); if (!empty($mb)) { if ($mb > 0) { $gifts['goods_unit'] = $row['goods_unit']; } else { $gifts['goods_unit'] = $mb; } } else { $gifts['goods_unit'] = $row['goods_unit']; } $gifts['number'] = $num2; $gifts['goods_id'] = $row['goods_id']; $gifts['goods_sn'] = $row['goods_sn']; $gifts['goods_bianhao'] = $row['goods_bianhao']; $gifts['goods_key'] = $row['goods_id'] . '__' . mktime(); $gifts['goods_name'] = $row['goods_name']; $gifts['shop_price'] = 0.0; $gifts['pifa_price'] = 0.0; $gifts['goods_brief'] = $row['goods_brief']; } //end if } //end if $gift = $this->Session->read("cart.{$id}.gifts"); $this->Session->write("cart.{$id}.gifts", $gifts); if (!empty($gift2) && $number <= $num1 || empty($gift) && $number >= $num1) { $cartlist = $this->Session->read('cart'); $rt['goodslist'] = array(); if (!empty($cartlist)) { foreach ($cartlist as $k => $row) { $rt['goodslist'][$k] = $row; $rt['goodslist'][$k]['url'] = get_url($row['goods_name'], $row['goods_id'], 'product.php?id=' . $row['goods_id'], 'goods', array('product', 'index', $row['goods_id'])); $rt['goodslist'][$k]['goods_thumb'] = is_file(SYS_PATH . $row['goods_thumb']) ? SITE_URL . $row['goods_thumb'] : SITE_URL . 'theme/images/no_picture.gif'; $rt['goodslist'][$k]['goods_img'] = is_file(SYS_PATH . $row['goods_img']) ? SITE_URL . $row['goods_img'] : SITE_URL . 'theme/images/no_picture.gif'; $rt['goodslist'][$k]['original_img'] = is_file(SYS_PATH . $row['original_img']) ? SITE_URL . $row['original_img'] : SITE_URL . 'theme/images/no_picture.gif'; } //end foreach unset($goodslist); } //end if cart $this->set('rt', $rt); $con = $this->fetch('ajax_mycart', true); unset($cartlist, $gift, $gift2); $result = array('error' => 1, 'message' => $con); die($json->encode($result)); } } //end if } //end foreach } //end if unset($cartlist); $moneyinfo = $this->get_give_off_monery($total); $result = array('error' => 0, 'message' => $total, 'offprice' => $moneyinfo['offmoney'], 'shippingprice' => $moneyinfo['shippingprice']); die($json->encode($result)); }
function ajax_markall($kk = 0, $type = 'nav') { //必须已开启静态方式才可以生成静态页面 if (empty($GLOBALS['LANG']['is_static'])) { $rts = array('kk' => '', 'url' => '请你先开启静态方式再生成静态页面', 'type' => 'cache'); die(Import::json()->encode($rts)); } $nav = array(); $cate = array(); $art = array(); $rts = array('kk' => '', 'url' => '', 'type' => 'end'); if ($type == 'nav') { $nav = $this->get_nav_var($kk); if (empty($nav)) { $rts = array('kk' => '', 'url' => '', 'type' => 'cate'); } else { Import::fileop()->markhtml($nav['url'], $nav['path']); $kk = $kk + 1; $rts = array('kk' => $kk, 'url' => '<a href="' . $nav['returnurl'] . '" target="_blank">' . $nav['returnurl'] . '</a><br />', 'type' => 'nav'); } die(Import::json()->encode($rts)); } if (empty($nav) && $type == 'cate') { $cate = $this->get_category_var($kk); if (empty($cate)) { $rts = array('kk' => '', 'url' => '', 'type' => 'art'); } else { Import::fileop()->markhtml($cate['url'], $cate['path']); $kk = $kk + 1; $rts = array('kk' => $kk, 'url' => '<a href="' . $cate['returnurl'] . '" target="_blank">' . $cate['returnurl'] . '</a><br />', 'type' => 'cate'); } die(Import::json()->encode($rts)); } if (empty($cate) && $type == 'art') { $art = $this->get_article_var($kk); if (empty($art)) { $rts = array('kk' => '', 'url' => '', 'type' => 'index'); } else { Import::fileop()->markhtml($art['url'], $art['path']); $kk = $kk + 1; $rts = array('kk' => $kk, 'url' => '<a href="' . $art['returnurl'] . '" target="_blank">' . $art['returnurl'] . '</a><br />', 'type' => 'art'); } die(Import::json()->encode($rts)); } if (empty($art) && $type == 'index') { Import::fileop()->markhtml(SITE_URL, SYS_PATH . 'index.html'); $rts = array('kk' => '', 'url' => '<a href="' . SITE_URL . '/" target="_blank">' . SITE_URL . '/</a><br />', 'type' => 'end'); die(Import::json()->encode($rts)); } die(Import::json()->encode($rts)); }
function ajax_daili_login($data = array()) { $uid = $this->Session->read('Agent.uid'); $json = Import::json(); $result = array('error' => 2, 'message' => '传送的数据为空!'); if (empty($data['fromAttr'])) { die($json->encode($result)); } $fromAttr = $json->decode($data['fromAttr']); //反json ,返回值为对象 unset($data); $mobile_phone = $fromAttr->mobile_phone; $password = $fromAttr->password; if (empty($mobile_phone) || empty($password)) { $result = array('error' => 2, 'message' => '请输入完整信息!'); die($json->encode($result)); } $sql = "SELECT mobile_phone,password,user_id,active,last_login,last_ip FROM `{$this->App->prefix()}user` WHERE mobile_phone='{$mobile_phone}' AND user_rank!='1' LIMIT 1"; $rt = $this->App->findrow($sql); $pass = isset($rt['password']) ? $rt['password'] : ''; $uid = isset($rt['user_id']) ? $rt['user_id'] : ''; if (empty($pass)) { $result = array('error' => 2, 'message' => '该账户不存在!'); die($json->encode($result)); } if ($pass == md5(trim($password))) { $this->Session->write('Agent.uid', $uid); $this->Session->write('Agent.username', $rt['mobile_phone']); $this->Session->write('Agent.active', $rt['active']); $this->Session->write('Agent.lasttime', $rt['last_login']); $this->Session->write('Agent.lastip', $rt['last_ip']); $datas = array(); $ip = Import::basic()->getip(); $datas['last_ip'] = empty($ip) ? '0.0.0.0' : $ip; $datas['last_login'] = mktime(); $datas['visit_count'] = '`visit_count`+1'; $this->App->update('user', $datas, 'user_id', $uid); //更新 $result = array('error' => 0, 'message' => '登录成功!'); die($json->encode($result)); } else { $result = array('error' => 2, 'message' => '密码错误!'); die($json->encode($result)); } }
function ajax_getuser($data = array()) { $err = 0; $json = Import::json(); $result = array('error' => $err, 'message' => ''); if (empty($data)) { $result['error'] = 2; $result['message'] = '传送的数据为空!'; die($json->encode($result)); } $wobj = $json->decode($data); //反json ,返回值为对象 $page = $wobj->page; $returnw = $wobj->returnw; if (!empty($returnw)) { unset($wobj, $data); $wobj = $json->decode(base64_decode($returnw)); //反json ,返回值为对象 $data = base64_decode($returnw); } $keyword = $wobj->keys; $province = $wobj->province; $city = $wobj->city; $district = $wobj->district; $user_rank = $wobj->user_rank; $sex = $wobj->sex; $start_birthday = $wobj->start_birthday; $end_birthday = $wobj->end_birthday; $start_reg_date = $wobj->start_reg_date; $end_reg_date = $wobj->end_reg_date; $reg_date = $wobj->reg_date; $type = $wobj->type; $types = array('salerank', 'poitsrank', 'logincount'); $type = in_array($type, $types) ? $type : ""; $comd = array(); if (intval($province) > 0) { $comd[] = "ua.province='{$province}'"; } if (intval($city) > 0) { $comd[] = "ua.city='{$city}'"; } if (intval($district) > 0) { $comd[] = "ua.district='{$district}'"; } if (intval($user_rank) > 0) { $comd[] = "u.user_rank='{$user_rank}'"; } if (intval($sex) > 0) { $sex = $sex - 1; $comd[] = "(u.sex='{$sex}' OR ua.sex='{$sex}')"; } if ($end_birthday > $start_birthday) { $comd[] = "u.birthday BETWEEN '{$start_birthday}' AND '{$end_birthday}'"; } if ($end_reg_date > $start_reg_date) { $end_reg_date = strtotime($end_reg_date); $start_reg_date = strtotime($start_reg_date); $comd[] = "u.reg_time BETWEEN '{$start_reg_date}' AND '{$end_reg_date}'"; } $orderby = " ORDER BY u.user_id DESC"; switch ($type) { case 'salerank': $orderby = " ORDER BY salerank DESC, u.user_id ASC"; break; case 'poitsrank': $orderby = " ORDER BY pointrank DESC, u.user_id ASC"; break; case 'logincount': $orderby = " ORDER BY visit_count DESC, u.user_id ASC"; break; } if (!empty($keyword)) { $comd[] = "(u.user_name LIKE '%{$keyword}%' OR u.email LIKE '%{$keyword}%' OR u.nickname LIKE '%{$keyword}%' OR ua.consignee LIKE '%{$keyword}%' OR ua.email LIKE '%{$keyword}%')"; } if (!($page > 0)) { $page = 1; } $list = 10; $start = ($page - 1) * $list; $sql = "SELECT distinct u.user_id FROM `{$this->App->prefix()}user` AS u"; $sql .= " LEFT JOIN `{$this->App->prefix()}user_address` AS ua ON u.user_id=ua.user_id AND ua.is_own='1'"; $sql .= " LEFT JOIN `{$this->App->prefix()}goods_order_info` AS goi ON u.user_id=goi.user_id AND goi.pay_status='2'"; $sql .= " LEFT JOIN `{$this->App->prefix()}user_point_change` AS upc ON u.user_id=upc.uid"; $sql .= !empty($comd) ? " WHERE " . implode(' AND ', $comd) . " GROUP BY u.user_id" : " GROUP BY u.user_id"; $tts = $this->App->findcol($sql); $tt = count($tts); $getuserpage = Import::basic()->ajax_page($tt, $list, $page, 'ajax_getuser', array(base64_encode($data))); $this->set('getuserpage', $getuserpage); $sql = "SELECT distinct u.user_id,u.user_name,u.birthday,u.reg_time,u.visit_count,ua.sex,ua.email,SUM(goi.goods_amount+goi.shipping_fee) AS salerank,SUM(upc.points) AS pointrank FROM `{$this->App->prefix()}user` AS u"; $sql .= " LEFT JOIN `{$this->App->prefix()}user_address` AS ua ON u.user_id=ua.user_id AND ua.is_own='1'"; $sql .= " LEFT JOIN `{$this->App->prefix()}goods_order_info` AS goi ON u.user_id=goi.user_id AND goi.pay_status='2'"; $sql .= " LEFT JOIN `{$this->App->prefix()}user_point_change` AS upc ON u.user_id=upc.uid"; $sql .= !empty($comd) ? " WHERE " . implode(' AND ', $comd) . " GROUP BY u.user_id" : " GROUP BY u.user_id"; $sql .= "{$orderby} LIMIT {$start},{$list}"; $rt = $this->App->find($sql); $this->set('rt_user', $rt); echo $result = $this->fetch('ajax_need_send_user', true); unset($rt); exit; }
function ajax_add_cart($data = array()) { /* *error:可以的值 *0:无任何错误提示 *1:购买数量操作库存 *2:错误提示,提示内容为message值 */ $err = 0; $result = array('error' => $err, 'message' => ''); $json = Import::json(); if (empty($data['goods'])) { $result['error'] = 2; $result['message'] = '传送的数据为空!'; die($json->encode($result)); } $goods = $json->decode($data['goods']); //反json $optype = $goods->optype; $spec = $goods->spec; $number = $goods->number; if (!($number > 0)) { $number = 1; } $goods_id = $goods->goods_id; //处理搭配购买的商品 传送的goods_id例子:12:11|22|44 $dapei_ids = array(); if (strpos($goods_id, ':')) { // $dapei_ar = explode(":", $goods_id); $goods_id = $dapei_ar[0]; $dapei_ids = !empty($dapei_ar[1]) ? explode("|", $dapei_ar[1]) : array(); unset($dapei_ar); } $sql = "SELECT * FROM `{$this->App->prefix()}goods` WHERE goods_id='{$goods_id}' LIMIT 1"; $cart = array(); $cart = $this->App->findrow($sql); $is_alone_sale = $cart['is_alone_sale']; if (empty($cart)) { //空信息处理 $result['error'] = 2; $result['message'] = '该商品的记录信息为空!'; die($json->encode($result)); } ############################### //验证是否是兑换积分===>相应减少积分 $is_pay_jifen = false; $cart['is_jifen_session'] = 0; //默认积分兑换 if ($cart['is_jifen'] == '1') { //检查用户的目前的积分 $uid = $this->Session->read('User.uid'); if (!($uid > 0)) { //需要先登录 $result['error'] = 3; $result['message'] = '请你先登录后再操作!'; die($json->encode($result)); } $need_jifen = $cart['need_jifen']; if ($need_jifen > 0) { $sql = "SELECT SUM(points) FROM `{$this->App->prefix()}user_point_change` WHERE uid='{$uid}'"; $points = $this->App->findvar($sql); $points = empty($points) ? 0 : $points; $sql = "SELECT points_ucount FROM `{$this->App->prefix()}user` WHERE user_id='{$uid}'"; $points2 = $this->App->findvar($sql); if ($points > 0 && $points >= $need_jifen && $points2 > 0 && $points2 >= $need_jifen) { //满足兑换积分的条件 $is_pay_jifen = true; $cart['is_jifen_session'] = 1; } else { $result['error'] = 2; $result['message'] = '当前积分为:<font color=red>' . $points . '</font>积分!<br />很抱歉,无法满足兑换该商品的条件!'; die($json->encode($result)); } } else { $result['error'] = 2; $result['message'] = '意外错误,你暂时不能兑换商品!'; die($json->encode($result)); } $pri = $cart['pifa_price']; if ($pri > 0) { $sql = "SELECT SUM(money) FROM `{$this->App->prefix()}user_money_change` WHERE uid='{$uid}'"; $moneys = $this->App->findvar($sql); $moneys = empty($moneys) ? 0 : $moneys; if ($moneys > 0 && $moneys >= $pri) { //满足兑换积分的条件 $is_pay_jifen = true; $cart['is_jifen_session'] = 1; } else { //$result['error'] = 2; //$result['message'] = '当前资金为:<font color=red>'.$moneys.'</font>元!<br />很抱歉,你的资金不足,请才充值!'; //die($json->encode($result)); } } } ############################# if ($cart['goods_number'] < $number) { //不能购买大于库存数量 $result['error'] = 1; $result['message'] = '购买数量不能大于库存数量!'; die($json->encode($result)); } //是否是赠品,如果是赠品,那么只能添加一件,不能重复添加 if ($is_alone_sale == '0') { $is_gift = $this->Session->read("excart.{$goods_id}"); if (isset($is_gift) && !empty($is_gift)) { $result['error'] = 4; $result['message'] = '赠品不能重复添加!'; die($json->encode($result)); } } //end 赠品 //start 检查是否有商品属性 if (empty($spec)) { $sql = "SELECT tb1.*,tb2.* FROM `{$this->App->prefix()}goods_attr` AS tb1"; $sql .= " LEFT JOIN `{$this->App->prefix()}attribute` AS tb2 ON tb1.attr_id = tb2.attr_id"; $sql .= " WHERE tb1.goods_id='{$goods_id}' AND tb2.is_show_cart='1'"; $spec = $this->App->find($sql); $rt['spec'] = array(); if (!empty($spec)) { foreach ($spec as $k => $row) { $rt['spec'][$row['attr_id']][] = $row; } unset($row, $spec); } if (!empty($rt['spec'])) { //存在商品属性,弹出对话框 $rt['goodsinfo']['goods_id'] = $goods_id; $this->set('rt', $rt); $con = $this->fetch('ajax_show_goods_spec', true); $result = array('error' => 5, 'message' => $con); unset($con); die($json->encode($result)); } } //end 检查是否有商品属性 $key_ar = array(); $str = array(); if (!empty($spec)) { //取出来商品属性 if (!empty($spec)) { foreach ($spec as $var) { $ar = explode('---', $var); $k = isset($ar[0]) ? $ar[0] : ""; if (empty($k)) { continue; } $v = isset($ar[1]) ? $ar[1] : ""; if (!in_array($k, $key_ar)) { $str[$k] = $this->get_goods_spec_name($k) . ':' . $v; } else { $str[$k] .= '+' . $v; } $key_ar[] = $k; } unset($spec); } } $cart['spec'] = $str; //商品属性 $cart['number'] = $number; //商品数量 //搭配商品 $cart['dapei'] = array(); if (!empty($dapei_ids)) { $sql = "SELECT uid AS supplier_id,goods_id,goods_name,brand_id,goods_number,goods_weight,market_price,shop_price,promote_price,promote_start_date,promote_end_date,is_qianggou,qianggou_price,qianggou_start_date,qianggou_end_date,goods_thumb,goods_img,is_on_sale,is_shipping,is_promote,is_jifen,need_jifen FROM `{$this->App->prefix()}goods` WHERE " . db_create_in($dapei_ids); $cart['dapei'] = $this->App->find($sql); } //处理重复添加 $ty = md5(@implode('+', $str) . '+' . $cart['goods_id']); //当前的唯一商品标记 $thiscart = $this->Session->read('excart'); //读取当前购物车商品 if (!empty($thiscart)) { //购物车中已经有内容 $gids = array_keys($thiscart); //所有商品id $md5_arr = array(); foreach ($thiscart as $kk => $row) { if (@ereg('[#,_]', $kk)) { list($k) = split('[#,_]', $kk); } else { $k = $kk; } $md5 = md5(implode('+', $row['spec']) . '+' . $k); //if(!in_array($md5,$md5_arr)){ $md5_arr[] = $md5; //} } if (is_array($md5_arr) && !empty($md5_arr) && !empty($ty)) { if (!in_array($ty, $md5_arr)) { //没存在重复的项 if (in_array($goods_id, $gids)) { $goods_id = $goods_id . '_' . mktime(); //新的id } unset($md5_arr); $this->Session->write("excart.{$goods_id}", $cart); } else { //已经存在重复项 $index = array_search($ty, $md5_arr); list($p) = array_keys(array_slice($thiscart, $index, 1, true)); if (!empty($p)) { //数量+1 //$this->Session->write("excart.{$p}.number", ($thiscart[$p]['number'])+$number); } } } else { $this->Session->write("excart.{$goods_id}", $cart); } } else { //购物车没内容 $this->Session->write("excart.{$goods_id}", $cart); //写入购物车 } $result = array('error' => $err, 'message' => '恭喜您,已成功将产品添加到购物车,继续购买请点继续选购,结帐请点前往购物车!'); die($json->encode($result)); }
function ajax_change_price($data = array()) { $json = Import::json(); $id = $data['id']; $number = $data['number']; $shipping_id = $data['shipping_id']; $userress_id = $data['userress_id']; $maxnumber = $this->Session->read("cart.{$id}.goods_number"); if ($number > $maxnumber) { $result = array('error' => 2, 'message' => "购买数量已经超过了库存,你最大只能购买:" . $maxnumber); die($json->encode($result)); } //是否是赠品,如果是赠品,那么只能添加一件,不能重复添加 $is_alone_sale = $this->Session->read("cart.{$id}.is_alone_sale"); if (!empty($is_alone_sale)) { $this->Session->write("cart.{$id}.number", $number); } //end 赠品 $uid = $this->Session->read('User.uid'); $cartlist = $this->Session->read('cart'); //返回总价 $sql = "SELECT * FROM `{$this->App->prefix()}userconfig` LIMIT 1"; //配置信息 $rts = $this->App->findrow($sql); $sql = "SELECT is_subscribe FROM `{$this->App->prefix()}user` WHERE user_id='{$uid}' LIMIT 1"; $issubscribe = $this->App->findvar($sql); $guanzhuoff = $rts['guanzhuoff']; $address3off = $rts['address3off']; $address2off = $rts['address2off']; $prices = 0; $thisprice = 0; foreach ($cartlist as $k => $row) { $counts = $row['number']; $off = 1; if ($issubscribe == '1' && $guanzhuoff < 101 && $guanzhuoff > 0) { $off = $guanzhuoff / 100; } if ($issubscribe == '1' && $counts >= 2 && $address2off < 101 && $address2off > 0) { $off = $address2off / 100; } if ($issubscribe == '1' && $counts >= 3 && $address3off < 101 && $address3off > 0) { $off = $address3off / 100 * $off; } $price = format_price($row['pifa_price'] * $off); if ($id == $k) { $thisprice = $price; } $prices += $price * $row['number']; } $prices = format_price($prices); unset($cartlist); //邮费 $f = $this->ajax_jisuan_shopping(array('shopping_id' => $shipping_id, 'userress_id' => $userress_id), 'cart'); $f = empty($f) ? '0' : $f; unset($cartlist); $result = array('error' => 0, 'message' => '1', 'prices' => $prices, 'thisprice' => $thisprice, 'freemoney' => $f); die($json->encode($result)); }
function return_order_text($orderid) { $uid = $this->Session->read('User.uid'); $rt = $this->App->findrow("SELECT oid,order_status,shipping_status,pay_status,is_print FROM `{$this->App->prefix()}goods_order_status` WHERE suppliers_id='{$uid}' AND order_id='{$orderid}'"); $order_status = $rt['order_status']; $shipping_status = $rt['shipping_status']; $pay_status = $rt['pay_status']; $result['error'] = 0; $result['orderid'] = $orderid; $result['status'] = $this->get_status($order_status, $pay_status, $shipping_status); $result['message'] = $this->get_suppliers_order_option($order_status, $pay_status, $shipping_status, 1); $json = Import::json(); die($json->encode($result)); }