作者 anyv
1 个管道 的构建 通过 耗费 3 秒

5

... ... @@ -20,6 +20,39 @@ class GoodsdetailsController extends WeChatBaseController{
public function Goods_details(){
$goods_id = $this -> request -> param();
$uid = cmf_get_current_user_id();
//判断跳转过来的链接
if(!empty($goods_id['status']) && !empty($goods_id['id'])){
$share_user = Db::name('my_user') -> where('uid',$uid) -> find();
//判断用户是否存在
if(!empty($share_user)){
//判断用户是不是自由人
if($share_user['status'] == 0){
//如果是自由人 那就绑定关系
$share_data['status'] = 4;
$share_data['pid'] = $goods_id['id'];
$share_data['bind_time'] = time();
$share_data['bind_status'] = 1;
Db::name('my_user') -> where("uid",$uid) -> update($share_data);
}
}else{
//用户不存在的话 如果是老师分享过来的
if($goods_id['status'] == 3 || $goods_id['status'] == 4){
//判断这个用户是否存在
if(empty($share_user)){
$share_data['status'] = 4;
$share_data['uid'] = $uid;
$share_data['create_time'] = time();
$share_data['is_pro'] = 0;
$share_data['pid'] = $goods_id['id'];
$share_data['bind_time'] = time();
$share_data['bind_status'] = 1;
Db::name('my_user') -> insert($share_data);
}
}
}
}
$data = Db::name('goods') -> alias('a') -> field("a.*,b.name") -> join('classification b','a.classify_id = b.id','LEFT') -> where('a.id',$goods_id['goods_id']) -> find();
$this -> assign('price',$data['price']);
$price = explode('.',$data['price']);
... ... @@ -67,7 +100,31 @@ class GoodsdetailsController extends WeChatBaseController{
$js = $app->js;
$jssdk=$js->config(array('onMenuShareAppMessage', 'onMenuShareTimeline'), false,false,true);
$this->assign('jssdk',$jssdk);
$url = "http://xkeasy.w.bronet.cn/portal/goodsdetails/goods_details/goods_id/".$goods_id['goods_id'];
//判断用户身份
$my_user = Db::name('my_user') -> where('uid',$uid) -> find();
//如果是业务员身份
if($my_user['status'] == 2 || $my_user['status'] == 0 || $my_user['status'] == 1 || $my_user['status'] == 5 || $my_user['status'] == 6){
$url = "http://xkeasy.w.bronet.cn/portal/goodsdetails/goods_details/goods_id/".$goods_id['goods_id'];
}
//如果是老师身份
if($my_user['status'] == 3){
if(empty($goods_id['id'])){
$url = "http://xkeasy.w.bronet.cn/portal/goodsdetails/goods_details/goods_id/".$goods_id['goods_id']."/status/3/id/".$my_user['id'];
}else{
$url = "http://xkeasy.w.bronet.cn/portal/goodsdetails/goods_details/goods_id/".$goods_id['goods_id']."/status/3/id/".$goods_id['id'];
}
}
//学生身份
if($my_user['status'] == 4){
$teacher_my_user = Db::name('my_user') -> where('id',$my_user['pid']) -> find();
if(empty($goods_id['id'])){
$url = "http://xkeasy.w.bronet.cn/portal/goodsdetails/goods_details/goods_id/".$goods_id['goods_id']."/status/4/id/".$teacher_my_user['id'];
}else{
$url = "http://xkeasy.w.bronet.cn/portal/goodsdetails/goods_details/goods_id/".$goods_id['goods_id']."/status/4/id/".$goods_id['id'];
}
}
$this -> assign('url',$url);
return $this -> fetch();
}
... ... @@ -178,10 +235,32 @@ class GoodsdetailsController extends WeChatBaseController{
return $res;
}
}
/**
* 判断购买的商品是不是自己上一级业务员卖的商品
*/
public function is_salesmang_goods(){
$uid = cmf_get_current_user_id();
$goods_uid = Db::name('goods') -> where("id",$_POST['goods_id']) -> find();
$my_user = Db::name('my_user') -> where('uid',$uid) -> find();
if($my_user['status'] == 3){
$salesman_user = Db::name('my_user') -> where('id',$my_user['pid']) -> find();
}
if($my_user['status'] == 4){
$teacher_user = Db::name('my_user') -> where('id',$my_user['pid']) -> find();
$salesman_user = Db::name('my_user') -> where('id',$teacher_user['pid']) -> find();
}
if(!empty($salesman_user)){
if($goods_uid['uid'] == $salesman_user['uid']){
return true;
}else{
return false;
}
}else{
return true;
}
}
... ... @@ -197,6 +276,4 @@ class GoodsdetailsController extends WeChatBaseController{
}
\ No newline at end of file
... ...
... ... @@ -198,7 +198,15 @@
* 点击跳转购物车页面
*/
function go_to_car(){
window.location.href = "{:url('Shopcart/shop_cart')}";
goods_id = "{$data.id}";
$.post("{:url('Goodsdetails/is_salesmang_goods')}",{goods_id:goods_id},function(data){
if(data){
window.location.href = "{:url('Shopcart/shop_cart')}";
}else{
alert('非上级业务员书籍不能购买');
}
});
}
/**
... ... @@ -206,18 +214,28 @@
*/
function buy_now(id){
price = {$price};
$.post("{:url('Goodsdetails/goodsdetails_go_pay')}",{id:id,myprice:price},function(data){
obj = JSON.parse(data);
if(obj.type == 20){
alert('业务员不能购买');
}if(obj.type == 3){
alert('业务员商品和平台商品不能同时购买!');
}else if(obj.type == 1){
window.location.href = "{:url('Orderpage/order_page')}?indet_id="+obj.indet_id;
}else if(obj.type == 2){
window.location.href = "{:url('Orderpage/order_salesman_ty')}?indet_id="+obj.indet_id;
}
});
goods_id = "{$data.id}";
$.post("{:url('Goodsdetails/is_salesmang_goods')}",{goods_id:goods_id},function(data){
if(data){
$.post("{:url('Goodsdetails/goodsdetails_go_pay')}",{id:id,myprice:price},function(data){
obj = JSON.parse(data);
if(obj.type == 20){
alert('业务员不能购买');
}if(obj.type == 3){
alert('业务员商品和平台商品不能同时购买!');
}else if(obj.type == 1){
window.location.href = "{:url('Orderpage/order_page')}?indet_id="+obj.indet_id;
}else if(obj.type == 2){
window.location.href = "{:url('Orderpage/order_salesman_ty')}?indet_id="+obj.indet_id;
}
});
}else{
alert('非上级业务员书籍不能购买');
}
});
}
... ... @@ -226,35 +244,55 @@
*点击收藏
*/
function goods_collection(id){
$.post("{:url('Goodsdetails/goods_collection')}",{goods_id:id},function(data){
if(data == 3){
alert('已收藏');
goods_id = "{$data.id}";
$.post("{:url('Goodsdetails/is_salesmang_goods')}",{goods_id:goods_id},function(data){
if(data){
$.post("{:url('Goodsdetails/goods_collection')}",{goods_id:id},function(data){
if(data == 3){
alert('已收藏');
}else{
if(data){
$("#imgsss").attr("src","__TMPL__/public/assets/images/xin (1).png");
$('#shoucang').text('已收藏');
alert('收藏成功');
}else{
alert('收藏失败');
}
}
});
}else{
if(data){
$("#imgsss").attr("src","__TMPL__/public/assets/images/xin (1).png");
$('#shoucang').text('已收藏');
alert('收藏成功');
}else{
alert('收藏失败');
}
alert('非上级业务员书籍不能收藏');
}
});
}
/**
*点击加入购物车
*/
function add_cart(id){
$.post("{:url('Shopcart/add_cart')}",{goods_id:id},function(data){
if(data == 2){
alert('已添加购物车');
}else if(data == 3){
alert('添加失败');
}else if(data == 1){
alert('添加成功');
goods_id = "{$data.id}";
$.post("{:url('Goodsdetails/is_salesmang_goods')}",{goods_id:goods_id},function(data){
if(data){
$.post("{:url('Shopcart/add_cart')}",{goods_id:id},function(data){
if(data == 2){
alert('已添加购物车');
}else if(data == 3){
alert('添加失败');
}else if(data == 1){
alert('添加成功');
}
});
}else{
alert('非上级业务员书籍不能加入购物车');
}
});
}
</script>
</body>
... ...