iwebshop關於收藏店鋪

來源:互聯網
上載者:User

標籤: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關於收藏店鋪

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.