仿京东商品套装可定义套装主体(申请加精)

2016-07-07 15:01 来源:www.chinab4c.com 作者:ecshop专家



修改:后台文件 admin/package.phpadmin/ templates/package_info.htm
前台文件 goods.php goods.dwt

admin/package.php



  1. /* 39行开始, 红色部分为增加 */
  2. $package = array('package_price'=>'', 'start_time' => $start_time,'goods_id' => $go_id, 'end_time' => $end_time);
  3. /* 78行开始, 红色部分为增加 */
  4. /* 插入数据 */
  5. $record = array('act_name'=>$_POST['package_name'], 'act_desc'=>$_POST['desc'],'goods_id'=>$_POST['go_id'],
  6. 'act_type'=>GAT_PACKAGE, 'start_time'=>$_POST['start_time'],
  7. 'end_time'=>$_POST['end_time'], 'is_finished'=>0, 'ext_info'=>serialize($info));

  8. /* 146行开始, 红色部分为增加 */
  9. /* 更新数据 */
  10. $record = array('act_name' => $_POST['package_name'], 'start_time' => $_POST['start_time'], 'goods_id'=>$_POST['go_id'], 'end_time' => $_POST['end_time'],
  11. 'act_desc' => $_POST['desc'], 'ext_info'=>serialize($info));
复制代码


admin/ templates/package_info.htm

  1. /* 13行开始, 全部为增加 */
  2. <tr>
  3. <td class="label">主体商品</td>
  4. <td><input type="text" name="go_id" maxlength="60" size="40" value="{$package.goods_id}" />{$lang.require_field}</td>
  5. </tr>
复制代码


合同效果图如下:




goods.php

  1. /*礼包函数, 红色部分为增加 */
  2. function get_package_goods_list($goods_id)
  3. {
  4. $now = gmtime();
  5. $sql = "SELECT ga.act_id, ga.act_name, ga.act_desc, ga.goods_id, ga.goods_name, ga.start_time, ".
  6. " ga.end_time, ga.is_finished, ga.ext_info ".
  7. " FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS ga".
  8. ", " . $GLOBALS['ecs']->table('package_goods') . " AS pg".
  9. "LEFT JOIN ". $GLOBALS['ecs']->table('goods') . " AS g ".
  10. "ON g.goods_id = pg.goods_id ".
  11. /**此部分可以只在主体商品下显示套装(不能和绿色的同时使用)
  12. " WHERE pg.package_id = ga.act_id AND ga.start_time <= '" . $now . "' AND ga.end_time >= '" . $now . "'AND ga.goods_id = '" . $goods_id . "' AND ga.goods_id = pg.goods_id".
  13. */
  14. " WHERE pg.package_id = ga.act_id AND ga.start_time <= '" . $now . "' AND ga.end_time >= '" . $now . "'AND pg.goods_id = " . $goods_id .
  15. " ORDER BY ga.act_id";
  16. $res = $GLOBALS['db']->getAll($sql);
  17. foreach ($res as $tempkey => $value)
  18. {
  19. $subtotal = 0;
  20. $row = unserialize($value['ext_info']);
  21. unset($value['ext_info']);
  22. if ($row)
  23. {
  24. foreach ($row as $key=>$val)
  25. {
  26. $res[$tempkey][$key] = $val;
  27. }
  28. }
  29. $sql = "SELECT pg.package_id, pg.goods_id, pg.goods_number, pg.admin_id, ".
  30. " g.goods_sn, g.goods_name, g.market_price, g.goods_thumb, ".
  31. " IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS rank_price " .
  32. " FROM " . $GLOBALS['ecs']->table('package_goods') . " AS pg ".
  33. "LEFT JOIN ". $GLOBALS['ecs']->table('goods') . " AS g ".
  34. "ON g.goods_id = pg.goods_id ".
  35. " LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
  36. "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
  37. " WHERE pg.package_id = " . $value['act_id']. " ".
  38. " ORDER BY pg.package_id";
  39. $goods_res = $GLOBALS['db']->getAll($sql);
  40. foreach($goods_res as $key => $val)
  41. {
  42. $goods_res[$key]['goods_thumb']= get_image_path($val['goods_id'], $val['goods_thumb'], true);
  43. $goods_res[$key]['market_price'] = price_format($val['market_price']);
  44. $goods_res[$key]['rank_price']= price_format($val['rank_price']);
  45. $subtotal += $val['rank_price'] * $val['goods_number'];
  46. $goods_res[$key]['short_name']= $GLOBALS['_CFG']['goods_name_length'] > 0 ?
  47. sub_str($goods_res[$key]['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $goods_res[$key]['goods_name'];
  48. }
  49. $res[$tempkey]['goods_list'] = $goods_res;
  50. $res[$tempkey]['subtotal']= price_format($subtotal);
  51. $res[$tempkey]['saving']= price_format(($subtotal - $res[$tempkey]['package_price']));
  52. $res[$tempkey]['package_price'] = price_format($res[$tempkey]['package_price']);
  53. }
  54. return $res;
  55. }
复制代码


goods.dwt 增加


  1. <style type="text/css" media="screen">@import url( http://www.919it.com/css/style.css );</style>
  2. <!-- {foreach from=$package_goods_list item=package_goods} -->
  3. <DIV class="padd_c">
  4. <TABLE class="view_tl1" cellSpacing=1 cellPadding=7
  5. width="100%" border=0 >
  6. <TBODY>
  7. <tr> <td colspan="3"><b style="color:red">{$package_goods.act_name}</b></td></tr>
  8. <tr>
  9. <td width="90">
  10. <ul><!-- {foreach name=package_goods from=$package_goods.goods_list item=goods_list} --> {if $goods_list.goods_id eq $package_goods.goods_id}<li style="float:left;width:90px;"><a href="goods.php?id={$goods_list.goods_id}" target="_blank"><img src="{$goods_list.goods_thumb}" width=80alt="" /></a><div> <a href="goods.php?id={$goods_list.goods_id}" target="_blank"><font color="red">{$goods_list.short_name}</font></a>&nbsp;<font size="+1">×</font>&nbsp;{$goods_list.goods_number}</div> </li>{/if}<!-- {/foreach} --></ul></td>
  11. <td width="30" align="left"><img src="http://www.919it.com/css/images/pick.gif"/></td>
  12. <td align="left">
  13. <ul> <!-- {foreach name=package_good from=$package_goods.goods_list item=goods_lists} --> {if $goods_lists.goods_id neq $package_goods.goods_id}<li class="li_b"><a href="goods.php?id={$goods_lists.goods_id}" target="_blank"><img src="{$goods_lists.goods_thumb}" width=80alt="" /></a><div> <a href="goods.php?id={$goods_lists.goods_id}" target="_blank">{$goods_lists.short_name}</a>&nbsp;<font size="+1">×</font>&nbsp;{$goods_lists.goods_number}</div></li>{/if}<!-- {/foreach} --></ul></td>
  14. </tr>
  15. </TBODY></TABLE>
  16. <div class="view_tl1">&nbsp;&nbsp;原 价:{$package_goods.subtotal}&nbsp;&nbsp;<font size="+2">-</font>&nbsp;&nbsp;打包折扣:{$package_goods.saving}&nbsp;&nbsp;<font size="+1">=</font>&nbsp;&nbsp;<b style="color:red">套装价:</b><font color="red" size="+2">{$package_goods.package_price}</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:addPackageToCart({$package_goods.act_id})" style="background:transparent"><img src="http://www.919it.com/css/images/but_buy.jpg" alt="{$lang.add_to_cart}" /></a></div>
  17. </DIV><!-- {/foreach} -->
复制代码
前台页面效果图




o(∩_∩)o...第一次写这么详细的功能教程!希望版主加精!!!

回答:
不错哦,顶你了

晕,在代码里面还不能标示各种颜色!

送分了 哈哈

好东西,收藏了。

好帖子不少啊,光顾着顶了,谢谢啊

不错,功能很实用

谢谢共享



顶,很实用啊,照着楼主做的果然可以,我自己又改了样式.

LS 的技术不赖嘛什么时候也共享一下下撒~

谢谢各位的支持,好东西就得共享!

LS 的技术不赖嘛什么时候也共享一下下撒~
齐迹 发表于 2009-12-5 09:48

呵呵,好的,其实很简单的,马上要去朋友那吃饭,晚上回来就发出来.

如果礼包的价格不用手动输入,也可以自定义就好了,例如 9折,8折.



至于样式你想怎么调就怎么调啥?每个人的想法是不一样的所以我强调不是样式调用