iwebshop关于收藏店铺

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iwebshop关于收藏店铺相关的知识,希望对你有一定的参考价值。

今天做了一个店铺收藏功能!把喜欢的店铺可以收藏起来!

前端主要是在js上做了文章

这是页面a标签部分:

<a href="javascript:;" onclick="add_shop_collect({echo:$item[‘id‘]});" class="stores_shou">收藏店铺</a>

这是页面js部分:

<script>
//传递后台参数
    function add_shop_collect(shop_id){
 $.ajax(
   {
   url:‘后台方法路径‘,
          type:‘POST‘,
   dataType:‘text‘,
   data:{"shop_id":shop_id},
   success:function(message){
             if(message == 0){

      }else if(message == 1){
         alert("收藏成功");
      }else if (message == 2){
         alert("收藏失败");
      }else if (message ==3){
         alert("您已经收藏了");
      }
      }
    }
 )
}
</script>

后台控制器部分:

function add_collect(){
   //获取当前用户id
    $user_id  = $this->user[‘user_id‘];
  //获取前端参数  
    $shop_id = IFilter::act(IReq::get(‘shop_id‘), ‘int‘);
    $shop_id_str = ‘‘;
    if($user_id){
    //执行查询 结合框架逻辑来书写次部分
      $memberDB = new IModel(‘‘);
     $memberData = $memberDB->getObj(‘user_id=‘.$user_id,‘collection_shop_id‘);
    //结合框架逻辑来书写次部分    
     $shop_id_str = empty($memberData[‘collection_shop_id‘])?"":$memberData[‘collection_shop_id‘];
        if(!in_array($shop_id,explode(",",$shop_id_str))){
            $shop_id_str = trim(($shop_id_str.‘,‘.$shop_id),",");
            $memberDB->setData(array(
                ‘collection_shop_id‘ => "$shop_id_str",
            ));
        }else{
            echo 3;
            exit();
        }
        if($memberDB->update(‘user_id = ‘.$user_id)){
            echo 1;
        }else{
            echo 2;
        }
    }else{
        echo 0;
    }
    exit();
}


本文出自 “kangjunfei” 博客,谢绝转载!

以上是关于iwebshop关于收藏店铺的主要内容,如果未能解决你的问题,请参考以下文章

iwebshop关于按钮点击提示的系列代码操作流程

关于iwebshop里excel表格导出开发整理

淘宝权重指的是什么

几个关于js数组方法reduce的经典片段

[PHP代码审计]iWebShop开源商城系统V5.9.21010存在命令执行漏洞

[PHP代码审计]iWebShop开源商城系统V5.9.21010存在命令执行漏洞