{"id":199088,"date":"2025-05-03T12:55:27","date_gmt":"2025-05-03T04:55:27","guid":{"rendered":"https:\/\/server.hk\/cnblog\/199088\/"},"modified":"2025-05-03T12:55:27","modified_gmt":"2025-05-03T04:55:27","slug":"ecshop%e9%a6%96%e9%a1%b5%e8%b0%83%e7%94%a8%e6%8c%87%e5%ae%9a%e5%88%86%e7%b1%bb%e7%9a%84%e6%89%80%e6%9c%89%e4%ba%a7%e5%93%81%ef%bc%88%e6%8c%87%e5%ae%9a%e4%b8%80%e7%ba%a7%e8%b0%83","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/199088\/","title":{"rendered":"ecshop\u9996\u9875\u8c03\u7528\u6307\u5b9a\u5206\u7c7b\u7684\u6240\u6709\u4ea7\u54c1\uff08\u6307\u5b9a\u4e00\u7ea7\u8c03"},"content":{"rendered":"<p>ecshop\u9996\u9875\u8c03\u7528\u6307\u5b9a\u5206\u7c7b\u7684\u6240\u6709\u4ea7\u54c1\uff08\u6307\u5b9a\u4e00\u7ea7\u8c03\u4e8c\u7ea7<\/p>\n<p><strong>\u7b2c\u4e00 \u5728\/includes\/lib_goods.php\u4e0b\u589e\u52a0\u5982\u4e0b\u4ee3\u7801\uff0c\u7528\u8fc7\u7f51\u4e0a\u7684\u76f4\u63a5\u6362\u6389\u5c31\u53ef\u4ee5&nbsp;<\/strong><\/p>\n<p>function index_get_cat_id_goods_best_list($cat_id = &#8221;, $num = &#8221;)<br \/> {<br \/> $sql = &#8216;Select g.goods_id, g.cat_id,c.parent_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, &#8216; .<br \/> &#8220;IFNULL(mp.user_price, g.shop_price * &#8216;$_SESSION[discount]&#8217;) AS shop_price, &#8220;.<br \/> &#8220;promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, &#8221; .<br \/> &#8220;g.is_best, g.is_new, g.is_hot, g.is_promote &#8221; .<br \/> &#8216;FROM &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;goods&#8217;) . &#8216; AS g &#8216; .<br \/> &#8216;LEFT JOIN &#8216; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;category&#8217;) . &#8216; AS c ON c.cat_id = g.cat_id &#8216; .<br \/> &#8220;LEFT JOIN &#8221; . $GLOBALS[&#8216;ecs&#8217;]-&gt;table(&#8216;member_price&#8217;) . &#8221; AS mp &#8220;.<br \/> &#8220;ON mp.goods_id = g.goods_id AND mp.user_rank = &#8216;$_SESSION[user_rank]&#8217; &#8220;.<br \/> &#8220;Where g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 &#8220;.<\/p>\n<p>$sql .= &#8221; AND (c.parent_id =&#8221; . $cat_id. &#8221; OR g.cat_id = &#8221; . $cat_id .&#8221; OR g.cat_id &#8220;. db_create_in(array_unique(array_merge(array($cat_id), array_keys(cat_list($cat_id, 0, false))))) .&#8221;)&#8221;;<br \/> $sql .= &#8221; LIMIT $num&#8221;;<br \/> $res = $GLOBALS[&#8216;db&#8217;]-&gt;getAll($sql);<\/p>\n<p>$goods = array();<br \/> foreach ($res AS $idx =&gt; $row)<br \/> {<br \/> $goods[$idx][&#8216;id&#8217;] = $row[&#8216;article_id&#8217;];<br \/> $goods[$idx][&#8216;id&#8217;] = $row[&#8216;goods_id&#8217;];<br \/> $goods[$idx][&#8216;name&#8217;] = $row[&#8216;goods_name&#8217;];<br \/> $goods[$idx][&#8216;brief&#8217;] = $row[&#8216;goods_brief&#8217;];<br \/> $goods[$idx][&#8216;brand_name&#8217;] = $row[&#8216;brand_name&#8217;];<br \/> $goods[$idx][&#8216;goods_style_name&#8217;] = add_style($row[&#8216;goods_name&#8217;],$row[&#8216;goods_name_style&#8217;]);<\/p>\n<p>$goods[$idx][&#8216;short_name&#8217;] = $GLOBALS[&#8216;_CFG&#8217;][&#8216;goods_name_length&#8217;] &gt; 0 ?<br \/> sub_str($row[&#8216;goods_name&#8217;], $GLOBALS[&#8216;_CFG&#8217;][&#8216;goods_name_length&#8217;]) : $row[&#8216;goods_name&#8217;];<br \/> $goods[$idx][&#8216;short_style_name&#8217;] = add_style($goods[$idx][&#8216;short_name&#8217;],$row[&#8216;goods_name_style&#8217;]);<br \/> $goods[$idx][&#8216;market_price&#8217;] = price_format($row[&#8216;market_price&#8217;]);<br \/> $goods[$idx][&#8216;shop_price&#8217;] = price_format($row[&#8216;shop_price&#8217;]);<br \/> $goods[$idx][&#8216;thumb&#8217;] = empty($row[&#8216;goods_thumb&#8217;]) ? $GLOBALS[&#8216;_CFG&#8217;][&#8216;no_picture&#8217;] : $row[&#8216;goods_thumb&#8217;];<br \/> $goods[$idx][&#8216;goods_img&#8217;] = empty($row[&#8216;goods_img&#8217;]) ? $GLOBALS[&#8216;_CFG&#8217;][&#8216;no_picture&#8217;] : $row[&#8216;goods_img&#8217;];<br \/> $goods[$idx][&#8216;url&#8217;] = build_uri(&#8216;goods&#8217;, array(&#8216;gid&#8217; =&gt; $row[&#8216;goods_id&#8217;]), $row[&#8216;goods_name&#8217;]);<br \/> }<\/p>\n<p>return $goods;<br \/> }<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u7b2c\u4e8c\uff1a\u5728index.php\u589e\u52a0<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>$smarty-&gt;assign(&#8216;cat_id16_best_goods&#8217;, index_get_cat_id_goods_best_list(16,3));<\/p>\n<p>&nbsp;<\/p>\n<p>cat_id<font>16<\/font>_best_goods \u7ea2\u8272\u6539\u4e3a\u4f60\u6307\u5b9a\u7684ID<br \/> index_get_cat_id_goods_best_list(<font>16<\/font>,<font>3<\/font>) \u7ea2\u8272\u4f60\u6307\u5b9a\u7684\u4e00\u7ea7\u680f\u76ee<font>ID<\/font> \u84dd\u8272\u4e3a\u8c03\u7528\u7684<font>\u6761\u6570<\/font><\/p>\n<p>&nbsp;<\/p>\n<p><font>&lt;!&#8211;{foreach from=$cat_id16_best_goods item=goods}&#8211;&gt;<br \/> &lt;ul&gt;<br \/> &lt;li class=&#8221;cat_img&#8221;&gt;<br \/> &lt;a href=&#8221;{$goods.url}&#8221; title=&#8221;&#8221; target=&#8221;_blank&#8221;&gt;&lt;img src=&#8221;{$goods.thumb}&#8221; alt=&#8221;{$goods.name|escape:html}&#8221; width=&#8221;100&#8243; height=&#8221;100&#8243; \/&gt;&lt;\/a&gt;<br \/> &lt;\/li&gt;<br \/> &lt;li&gt;&lt;a href=&#8221;{$goods.url}&#8221; target=&#8221;_blank&#8221; title=&#8221;{$goods.name|escape:html}&#8221;&gt;{$goods.short_name|truncate:8:true}&lt;\/a&gt;&lt;\/li&gt;<br \/> &lt;li&gt;&lt;span&gt;{$goods.shop_price}&lt;\/span&gt;&lt;\/li&gt;<br \/> &lt;\/ul&gt;<br \/> &lt;!&#8211; { \/foreach }&#8211;&gt; <\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ecshop\u9996\u9875\u8c03\u7528\u6307\u5b9a\u5206\u7c7b\u7684\u6240&#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-199088","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199088","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=199088"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199088\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=199088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=199088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=199088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}