{"id":199167,"date":"2025-05-03T10:19:49","date_gmt":"2025-05-03T02:19:49","guid":{"rendered":"https:\/\/server.hk\/cnblog\/199167\/"},"modified":"2025-05-03T10:19:49","modified_gmt":"2025-05-03T02:19:49","slug":"ecshop%e6%96%87%e7%ab%a0%e9%a1%b5%e5%85%b3%e8%81%94%e5%95%86%e5%93%81%e6%98%be%e7%a4%ba%e5%95%86%e5%93%81%e7%ae%80%e5%8d%95%e6%8f%8f%e8%bf%b0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/199167\/","title":{"rendered":"ecshop\u6587\u7ae0\u9875\u5173\u8054\u5546\u54c1\u663e\u793a\u5546\u54c1\u7b80\u5355\u63cf\u8ff0"},"content":{"rendered":"<p>\u597d\u6a21\u677f\u5728\u7ed9\u5ba2\u6237\u5236\u4f5cecshop\u65f6\u5019\uff0c\u53d1\u73b0\u6587\u7ae0\u5185\u5173\u8054\u5546\u54c1\u90fd\u6bd4\u8f83\u7b80\u6d01\uff0c\u82e5\u662f\u80fd\u5728\u5173\u8054\u5546\u54c1\u7684\u6807\u9898\u4e0b\u9762\u663e\u793a\u7b80\u5355\u7684\u4ea7\u54c1\u63cf\u8ff0\uff0c\u90a3\u6837\u4f1a\u6bd4\u8f83\u597d\u770b\u3002<\/p>\n<p>\u5982\u4e0b\u56fe\uff1a<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" style=\"cursor:pointer\" src=\"https:\/\/www.ldhost.cn\/helphmb\/uploads\/allimg\/110719\/1_110719211955_1.jpg\" class=\"aligncenter\">  <\/p>\n<p>\u597d\u6a21\u677f\u7814\u7a76\u51fa\u5982\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p>\u627e\u5230 ecshop\u6839\u76ee\u5f55\u6587\u4ef6article.php<\/p>\n<p>\u83b7\u5f97\u6587\u7ae0\u5173\u8054\u7684\u5546\u54c1 \u8fd9\u4e2a\u5b9a\u4e49\u51fd\u6570\uff1a<\/p>\n<p>\u539f\u662f\uff1a<\/p>\n<p>&nbsp;<\/p>\n<p>\/**<\/p>\n<p>&nbsp;* \u83b7\u5f97\u6587\u7ae0\u5173\u8054\u7684\u5546\u54c1<\/p>\n<p>&nbsp;*<\/p>\n<p>&nbsp;* @access &nbsp;public<\/p>\n<p>&nbsp;* @param &nbsp; integer $id<\/p>\n<p>&nbsp;* @return &nbsp;array<\/p>\n<p>&nbsp;*\/<\/p>\n<p>function article_related_goods($id)<\/p>\n<p>{<\/p>\n<p>&nbsp; &nbsp; $sql = &#8216;SELECT g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price AS org_price, &#8216; .<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;IFNULL(mp.user_price, g.shop_price * &#8216;$_SESSION[discount]&#8217;) AS shop_price, &#8220;.<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;g.market_price, g.promote_price, g.promote_start_date, g.promote_end_date &#8216; .<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;FROM &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;goods_article&#8217;) . &#8216; ga &#8216; .<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;LEFT JOIN &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;goods&#8217;) . &#8216; AS g ON g.goods_id = ga.goods_id &#8216; .<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;LEFT JOIN &#8221; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;member_price&#8217;) . &#8221; AS mp &#8220;.<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;ON mp.goods_id = g.goods_id AND mp.user_rank = &#8216;$_SESSION[user_rank]&#8217; &#8220;.<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;WHERE ga.article_id = &#8216;$id&#8217; AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0&#8221;;<\/p>\n<p>&nbsp; &nbsp; $res = $GLOBALS[&#8216;db&#8217;]-&gt;query($sql);<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp; &nbsp; $arr = array();<\/p>\n<p>&nbsp; &nbsp; while ($row = $GLOBALS[&#8216;db&#8217;]-&gt;fetchRow($res))<\/p>\n<p>&nbsp; &nbsp; {<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;goods_id&#8217;] &nbsp; &nbsp; &nbsp;= $row[&#8216;goods_id&#8217;];<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;goods_name&#8217;] &nbsp; &nbsp;= $row[&#8216;goods_name&#8217;];<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;short_name&#8217;] &nbsp; = $GLOBALS[&#8216;_CFG&#8217;][&#8216;goods_name_length&#8217;] &gt; 0 ?<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sub_str($row[&#8216;goods_name&#8217;], $GLOBALS[&#8216;_CFG&#8217;][&#8216;goods_name_length&#8217;]) : $row[&#8216;goods_name&#8217;];<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;goods_thumb&#8217;] &nbsp; = get_image_path($row[&#8216;goods_id&#8217;], $row[&#8216;goods_thumb&#8217;], true);<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;goods_img&#8217;] &nbsp; &nbsp; = get_image_path($row[&#8216;goods_id&#8217;], $row[&#8216;goods_img&#8217;]);<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;market_price&#8217;] &nbsp;= price_format($row[&#8216;market_price&#8217;]);<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;shop_price&#8217;] &nbsp; &nbsp;= price_format($row[&#8216;shop_price&#8217;]);<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;url&#8217;] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = build_uri(&#8216;goods&#8217;, array(&#8216;gid&#8217; =&gt; $row[&#8216;goods_id&#8217;]), $row[&#8216;goods_name&#8217;]);<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if ($row[&#8216;promote_price&#8217;] &gt; 0)<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; {<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;promote_price&#8217;] = bargain_price($row[&#8216;promote_price&#8217;], $row[&#8216;promote_start_date&#8217;], $row[&#8216;promote_end_date&#8217;]);<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;formated_promote_price&#8217;] = price_format($arr[$row[&#8216;goods_id&#8217;]][&#8216;promote_price&#8217;]);<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; else<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; {<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;promote_price&#8217;] = 0;<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n<p>&nbsp; &nbsp; }<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp; &nbsp; return $arr;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p><span>\u4fee\u6539\u6210\uff1a<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>\/**<\/p>\n<p>&nbsp;* \u83b7\u5f97\u6587\u7ae0\u5173\u8054\u7684\u5546\u54c1<\/p>\n<p>&nbsp;*<\/p>\n<p>&nbsp;* @access &nbsp;public<\/p>\n<p>&nbsp;* @param &nbsp; integer $id<\/p>\n<p>&nbsp;* @return &nbsp;array<\/p>\n<p>&nbsp;*\/<\/p>\n<p>function article_related_goods($id)<\/p>\n<p>{<\/p>\n<p>&nbsp; &nbsp; $sql = &#8216;SELECT g.goods_id, g.goods_name, g.goods_thumb, g.goods_img<span>, g.goods_brief<\/span>, g.shop_price AS org_price, &#8216; .<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;IFNULL(mp.user_price, g.shop_price * &#8216;$_SESSION[discount]&#8217;) AS shop_price, &#8220;.<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;g.market_price, g.promote_price, g.promote_start_date, g.promote_end_date &#8216; .<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;FROM &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;goods_article&#8217;) . &#8216; ga &#8216; .<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;LEFT JOIN &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;goods&#8217;) . &#8216; AS g ON g.goods_id = ga.goods_id &#8216; .<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;LEFT JOIN &#8221; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;member_price&#8217;) . &#8221; AS mp &#8220;.<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;ON mp.goods_id = g.goods_id AND mp.user_rank = &#8216;$_SESSION[user_rank]&#8217; &#8220;.<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;WHERE ga.article_id = &#8216;$id&#8217; AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0&#8221;;<\/p>\n<p>&nbsp; &nbsp; $res = $GLOBALS[&#8216;db&#8217;]-&gt;query($sql);<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp; &nbsp; $arr = array();<\/p>\n<p>&nbsp; &nbsp; while ($row = $GLOBALS[&#8216;db&#8217;]-&gt;fetchRow($res))<\/p>\n<p>&nbsp; &nbsp; {<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;goods_id&#8217;] &nbsp; &nbsp; &nbsp;= $row[&#8216;goods_id&#8217;];<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;goods_name&#8217;] &nbsp; &nbsp;= $row[&#8216;goods_name&#8217;];<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;short_name&#8217;] &nbsp; = $GLOBALS[&#8216;_CFG&#8217;][&#8216;goods_name_length&#8217;] &gt; 0 ?<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sub_str($row[&#8216;goods_name&#8217;], $GLOBALS[&#8216;_CFG&#8217;][&#8216;goods_name_length&#8217;]) : $row[&#8216;goods_name&#8217;];<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;goods_thumb&#8217;] &nbsp; = get_image_path($row[&#8216;goods_id&#8217;], $row[&#8216;goods_thumb&#8217;], true);<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;goods_img&#8217;] &nbsp; &nbsp; = get_image_path($row[&#8216;goods_id&#8217;], $row[&#8216;goods_img&#8217;]);<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;market_price&#8217;] &nbsp;= price_format($row[&#8216;market_price&#8217;]);<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;shop_price&#8217;] &nbsp; &nbsp;= price_format($row[&#8216;shop_price&#8217;]);<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;url&#8217;] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = build_uri(&#8216;goods&#8217;, array(&#8216;gid&#8217; =&gt; $row[&#8216;goods_id&#8217;]), $row[&#8216;goods_name&#8217;]);<\/p>\n<p>&nbsp;<span> &nbsp; <\/span><span>&nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;goods_brief&#8217;] &nbsp; &nbsp;= $row[&#8216;goods_brief&#8217;];<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if ($row[&#8216;promote_price&#8217;] &gt; 0)<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; {<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;promote_price&#8217;] = bargain_price($row[&#8216;promote_price&#8217;], $row[&#8216;promote_start_date&#8217;], $row[&#8216;promote_end_date&#8217;]);<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;formated_promote_price&#8217;] = price_format($arr[$row[&#8216;goods_id&#8217;]][&#8216;promote_price&#8217;]);<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; else<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; {<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $arr[$row[&#8216;goods_id&#8217;]][&#8216;promote_price&#8217;] = 0;<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n<p>&nbsp; &nbsp; }<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp; &nbsp; return $arr;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p><span>\u7ea2\u8272\u4e3a\u589e\u52a0\u90e8\u5206\uff01<\/span><\/p>\n<p>\u5728\u6a21\u677f\u5e93\uff1agoods_related.lbi \u76f8\u5e94\u4f4d\u7f6e\u51fa\u5165\uff1a&nbsp;{$releated_goods_data.goods_brief}\u3002\u641e\u5b9a\uff01<\/p>\n<p>\u597d\u6a21\u677f\u539f\u521b\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u7f51\u5740\uff01<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u597d\u6a21\u677f\u5728\u7ed9\u5ba2\u6237\u5236\u4f5cecshop\u65f6&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-199167","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=199167"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199167\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=199167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=199167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=199167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}