{"id":60497,"date":"2025-04-24T11:57:38","date_gmt":"2025-04-24T03:57:38","guid":{"rendered":"https:\/\/fwq.ai\/blog\/60497\/"},"modified":"2025-04-24T11:57:38","modified_gmt":"2025-04-24T03:57:38","slug":"%e5%ae%9e%e7%8e%b0%e5%b0%86ecshop%e5%95%86%e5%93%81%e6%89%b9%e9%87%8f%e5%8a%a0%e5%85%a5%e6%94%b6%e8%97%8f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/60497\/","title":{"rendered":"\u5b9e\u73b0\u5c06ecshop\u5546\u54c1\u6279\u91cf\u52a0\u5165\u6536\u85cf"},"content":{"rendered":"<p>ecshop \u662f\u81ea\u5e26\u6536\u85cf\u5546\u54c1\u529f\u80fd\u7684\uff0c\u53ea\u53ef\u60dc\u53ea\u80fd\u4e00\u6b21\u6536\u85cf\u4e00\u4e2a\uff0c\u76f8\u5bf9\u4e8e\u8f83\u5927\u4e00\u70b9\u7684\u8d2d\u7269\u7ad9\u70b9\uff0c\u6709\u53ef\u80fd\u4e00\u6b21\u5c31\u9700\u8981\u6536\u85cf\u591a\u4e2a\u5546\u54c1\uff0c\u5b9e\u73b0\u8fd9\u6837\u7684\u64cd\u4f5c\u4e5f\u5e76\u4e0d\u662f\u5f88\u96be\u7684\uff0c\u53ea\u9700\u8981\u5728 ecshop \u81ea\u5e26\u6536\u85cf\u529f\u80fd\u7684\u57fa\u7840\u4e0a\u5c0f\u5c0f\u7684\u66f4\u6539\u4e00\u4e0b\u5373\u53ef\uff0c\u4e0b\u9762\u590f\u65e5\u535a\u5ba2\u5c31\u6765\u6559\u5927\u5bb6\u5982\u4f55\u4fee\u6539\u4e00\u4e0b\u5427\u3002   \u9996\u5148\u5faa\u73af\u51fa\u8981\u6536\u85cf\u5546\u54c1\u7684ID\uff0c\u7528\u4e00\u4e2a\u7b26\u53f7\u8fdb\u884c\u5206\u9694\u5f00\uff0c\u6bd4\u5982\u201812|5|8|\u2019\uff0c\u5230\u65f6\u5019\u4f20\u5165 PHP \u5904\u7406\u7684\u65f6\u5019\u5c31\u53ef\u4ee5\u4f7f\u7528 explode() \u51fd\u6570\u6309\u201c|\u201d\u7b26\u53f7\u6765\u8fdb\u884c\u5206\u5272\u5206\u5f00\uff0c\u7136\u540e\u518d\u8fdb\u884c\u5faa\u73af\u8fd9\u4e9bID\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u4e86\uff0c\u4ee3\u7801\u5982\u4e0b:   &lt;a class=&#8221;joinSave png&#8221; href=&#8221;javascript:collect_all(&#8216;{foreach from=$goods item=g}{$g.goods_id}|{\/foreach}&#8217;)&#8221;&gt;\u52a0\u5165\u6536\u85cf\u5939 &nbsp;   &nbsp;&nbsp;   &lt;\/a&gt; \u7ecf\u8fc7\u5faa\u73af\u540e\u5c31\u53ef\u4ee5\u5f97\u5230\u7c7b\u4f3c &lt;a class=&#8221;joinSave png&#8221; href=&#8221;javascript:collect_all(&#8217;12|5|8|&#8217;)&#8221;&gt;\u52a0\u5165\u6536\u85cf\u5939&lt;\/a&gt; \u7684\u4ee3\u7801\u4e86\u3002 &nbsp;   \u63a5\u7740\u6253\u5f00 common.js\uff0c\u627e\u5230 collect(goodsId) \u51fd\u6570\uff0c\u8fd9\u4e2a\u5c31\u662f\u6536\u85cf\u7684\u51fd\u6570\u4e86\uff0c\u6211\u4eec\u53ef\u4ee5\u4eff\u7167\u8fd9\u4e2a\u51fd\u6570\u518d\u91cd\u65b0\u6dfb\u52a0\u4e00\u4e2a\u51fd\u6570\uff0c\u5b9e\u4f8b\u4ee3\u7801\u5982\u4e0b:   \/* *&nbsp;   &nbsp;* &nbsp; \u6279\u91cf\u6dfb\u52a0\u5546\u54c1\u5230\u6536\u85cf\u5939&nbsp;   &nbsp;*\/ &nbsp;   function collect_all(AllId){ &nbsp;   Ajax.call(&#8216;user.php?act=collect_all&#8217;, &#8216;id=&#8217; + AllId, collectResponse, &#8216;GET&#8217;, &#8216;JSON&#8217;); &nbsp;   } &nbsp;   \u6700\u540e\u6253\u5f00 user.php \u6587\u4ef6\uff0c\u5728\u8fd9\u4e2a\u6587\u4ef6\u91cc\u9762\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801:   \/* \u6279\u91cf\u6dfb\u52a0\u6536\u85cf\u5546\u54c1(ajax) *\/ &nbsp;   elseif ($action == &#8216;collect_all&#8217;){ &nbsp;   include_once(ROOT_PATH .&#8217;includes\/cls_json.php&#8217;); &nbsp;   $json = new JSON(); &nbsp;   $result = array(&#8216;error&#8217; =&gt; 0, &#8216;message&#8217; =&gt; &#8221;); &nbsp;   $goods_id = $_GET[&#8216;id&#8217;]; &nbsp;   $goods_id = explode(&#8220;|&#8221;,$goods_id); &nbsp;   $goods_id = array_filter($goods_id); &nbsp; &nbsp;\/\/\u8fc7\u6ee4\u6389\u6570\u7ec4\u4e2d\u7a7a\u7684\u503c &nbsp;   &nbsp;&nbsp;   if (!isset($_SESSION[&#8216;user_id&#8217;]) || $_SESSION[&#8216;user_id&#8217;] == 0){ &nbsp;   $result[&#8216;error&#8217;] = 1; &nbsp;   $result[&#8216;message&#8217;] = $_LANG[&#8216;login_please&#8217;]; &nbsp;   die($json-&gt;encode($result)); &nbsp;   } &nbsp;   else{ &nbsp;   foreach($goods_id as $goods_id){ &nbsp;   \/* \u68c0\u67e5\u662f\u5426\u5df2\u7ecf\u5b58\u5728\u4e8e\u7528\u6237\u7684\u6536\u85cf\u5939 *\/ &nbsp;   $sql = &#8220;SELECT COUNT(*) FROM &#8221; .$GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;collect_goods&#8217;) . &nbsp;   &#8221; WHERE user_id=&#8217;$_SESSION[user_id]&#8217; AND goods_id = &#8216;$goods_id'&#8221;; &nbsp;   if ($GLOBALS[&#8216;db&#8217;]-&gt;GetOne($sql) &gt; 0){} &nbsp;   else{ &nbsp;   $time = gmtime(); &nbsp;   $sql = &#8220;INSERT INTO &#8221; .$GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;collect_goods&#8217;). &#8221; (user_id, goods_id, add_time) &#8221; . &nbsp;   &#8221; VALUES (&#8216;$_SESSION[user_id]&#8217;, &#8216;$goods_id&#8217;, &#8216;$time&#8217;)&#8221;; &nbsp;   &nbsp;&nbsp;   if ($GLOBALS[&#8216;db&#8217;]-&gt;query($sql) === false){ &nbsp;   $result[&#8216;error&#8217;] = 1; &nbsp;   $result[&#8216;message&#8217;] = $GLOBALS[&#8216;db&#8217;]-&gt;errorMsg(); &nbsp;   die($json-&gt;encode($result)); &nbsp;   } &nbsp;   } &nbsp;   } &nbsp;   $result[&#8216;error&#8217;] = 0; &nbsp;   $result[&#8216;message&#8217;] = $GLOBALS[&#8216;_LANG&#8217;][&#8216;collect_success&#8217;]; &nbsp;   die($json-&gt;encode($result)); &nbsp;   } &nbsp;   } &nbsp;   OK,\u505a\u5b8c\u8fd9\u4e9b\u5c31\u5df2\u7ecf\u53ef\u4ee5\u5b9e\u73b0\u5546\u54c1\u6279\u91cf\u52a0\u5165\u6536\u85cf\u7684\u529f\u80fd\u4e86\u3002  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>ecshop \u662f\u81ea\u5e26\u6536\u85cf\u5546\u54c1\u529f\u80fd\u7684\uff0c\u53ea\u53ef\u60dc\u53ea\u80fd\u4e00\u6b21\u6536\u85cf\u4e00\u4e2a\uff0c\u76f8\u5bf9\u4e8e\u8f83\u5927\u4e00\u70b9\u7684\u8d2d\u7269\u7ad9\u70b9\uff0c\u6709\u53ef\u80fd\u4e00\u6b21\u5c31\u9700\u8981\u6536\u85cf\u591a\u4e2a\u5546\u54c1\uff0c\u5b9e\u73b0\u8fd9\u6837\u7684\u64cd\u4f5c\u4e5f\u5e76\u4e0d\u662f\u5f88\u96be\u7684\uff0c\u53ea\u9700\u8981\u5728 ecshop \u81ea\u5e26\u6536\u85cf\u529f\u80fd\u7684\u57fa\u7840\u4e0a\u5c0f\u5c0f\u7684\u66f4\u6539\u4e00\u4e0b\u5373\u53ef\uff0c\u4e0b\u9762\u590f\u65e5\u535a\u5ba2\u5c31\u6765\u6559\u5927\u5bb6\u5982\u4f55\u4fee\u6539\u4e00\u4e0b\u5427\u3002 \u9996\u5148\u5faa\u73af\u51fa\u8981\u6536\u85cf\u5546\u54c1\u7684ID\uff0c\u7528\u4e00\u4e2a\u7b26\u53f7\u8fdb\u884c\u5206\u9694\u5f00\uff0c\u6bd4\u5982\u201812|5|8|\u2019\uff0c\u5230\u65f6\u5019\u4f20\u5165 PHP \u5904\u7406\u7684\u65f6\u5019\u5c31\u53ef\u4ee5\u4f7f\u7528 explode() \u51fd\u6570\u6309\u201c|\u201d\u7b26\u53f7\u6765\u8fdb\u884c\u5206\u5272\u5206\u5f00\uff0c\u7136\u540e\u518d\u8fdb\u884c\u5faa\u73af\u8fd9\u4e9bID\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u4e86\uff0c\u4ee3\u7801\u5982\u4e0b: &lt;a class=&#8221;joinSave png&#8221; href=&#8221;javascript:collect_all(&#8216;{foreach from=$goods item=g}{$g.goods_id}|{\/foreach}&#8217;)&#8221;&gt;\u52a0\u5165\u6536\u85cf\u5939 &nbsp; &nbsp;&nbsp; &lt;\/a&gt; \u7ecf\u8fc7\u5faa\u73af\u540e\u5c31\u53ef\u4ee5\u5f97\u5230\u7c7b\u4f3c &lt;a class=&#8221;joinSave png&#8221; href=&#8221;javascript:collect_all(&#8217;12|5|8|&#8217;)&#8221;&gt;\u52a0\u5165\u6536\u85cf\u5939&lt;\/a&gt; \u7684\u4ee3\u7801\u4e86\u3002 &nbsp; \u63a5\u7740\u6253\u5f00 common.js\uff0c\u627e\u5230 collect(goodsId) \u51fd\u6570\uff0c\u8fd9\u4e2a\u5c31\u662f\u6536\u85cf\u7684\u51fd\u6570\u4e86\uff0c\u6211\u4eec\u53ef\u4ee5\u4eff\u7167\u8fd9\u4e2a\u51fd\u6570\u518d\u91cd\u65b0\u6dfb\u52a0\u4e00\u4e2a\u51fd\u6570\uff0c\u5b9e\u4f8b\u4ee3\u7801\u5982\u4e0b: \/* *&nbsp; &nbsp;* &nbsp; \u6279\u91cf\u6dfb\u52a0\u5546\u54c1\u5230\u6536\u85cf\u5939&nbsp; &nbsp;*\/ &nbsp; function collect_all(AllId){ &nbsp; Ajax.call(&#8216;user.php?act=collect_all&#8217;, &#8216;id=&#8217; + AllId, collectResponse, &#8216;GET&#8217;, &#8216;JSON&#8217;); &nbsp; } &nbsp; \u6700\u540e\u6253\u5f00 user.php \u6587\u4ef6\uff0c\u5728\u8fd9\u4e2a\u6587\u4ef6\u91cc\u9762\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801: \/* \u6279\u91cf\u6dfb\u52a0\u6536\u85cf\u5546\u54c1(ajax) *\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-60497","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/60497","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=60497"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/60497\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=60497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=60497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=60497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}