国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.1KB

  1. <?php
  2. /**
  3. *
  4. * 发送到购物车
  5. *
  6. * @version $Id: posttocar.php$
  7. * @package DedeCMS.Site
  8. * @copyright Copyright (c) 2020, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. require_once (dirname(__FILE__) . "/../include/common.inc.php");
  13. require_once DEDEINC.'/shopcar.class.php';
  14. $cart = new MemberShops();
  15. $do = isset($do) ? trim($do) : 'add';
  16. if($do == 'add')
  17. {
  18. /*
  19. function addItem(); add a product to car
  20. */
  21. $buynum = isset($buynum) && is_numeric($buynum) ? $buynum : 1;
  22. $id =empty($id)? "" : intval($id);
  23. $buynum = ($buynum < 1) ? 1 : $buynum;
  24. $rs = $dsql->GetOne("SELECT id,channel,title FROM #@__archives WHERE id='$id'");
  25. if(!is_array($rs))
  26. {
  27. ShowMsg("该商品已不存在!","-1");
  28. exit();
  29. }
  30. $cts = GetChannelTable($rs['channel']);
  31. $rows = $dsql->GetOne("SELECT aid as id,trueprice as price,units FROM `$cts[addtable]` WHERE aid='$id'");
  32. if(!is_array($rows))
  33. {
  34. ShowMsg("该商品已不存在!","-1");
  35. exit();
  36. }
  37. $rows['buynum'] = $buynum;
  38. $rows['title'] = $rs['title'];
  39. $cart->addItem($id, $rows);
  40. ShowMsg("已添加加到购物车,<a href='car.php'>查看购物车</a>","car.php");
  41. exit();
  42. }
  43. elseif($do == 'del')
  44. {
  45. /*
  46. function delItem(); del products from car
  47. */
  48. if(!isset($ids))
  49. {
  50. ShowMsg("请选择要删除的商品!","-1");
  51. exit;
  52. }
  53. if(is_array($ids))
  54. {
  55. foreach($ids as $id)
  56. {
  57. $id = intval($id);
  58. $cart->delItem($id);
  59. }
  60. }
  61. else
  62. {
  63. $ids = intval($ids);
  64. $cart->delItem($ids);
  65. }
  66. ShowMsg("已成功删除购物车中的商品,<a href='car.php'>查看购物车</a>","car.php");
  67. exit;
  68. }
  69. elseif($do == 'clear')
  70. {
  71. /*
  72. function clearItem(); clear car products all!
  73. */
  74. $cart->clearItem();
  75. ShowMsg("购物车中商品已全部清空!","car.php");
  76. exit;
  77. }
  78. elseif($do == 'update')
  79. {
  80. /*
  81. function updateItem(); update car products number!
  82. */
  83. if(isset($ids) && is_array($ids))
  84. {
  85. foreach($ids as $id){
  86. $id = intval($id);
  87. $rs = $dsql->GetOne("SELECT id,channel,title FROM #@__archives WHERE id='$id'");
  88. if(!is_array($rs)) continue;
  89. $cts = GetChannelTable($rs['channel']);
  90. $rows = $dsql->GetOne("SELECT aid as id,trueprice as price,units FROM `$cts[addtable]` WHERE aid='$id'");
  91. if(!is_array($rows)) continue;
  92. $rows['buynum'] = intval(${'buynum'.$id});
  93. if($rows['buynum'] < 1)
  94. {
  95. //如果设单位数量小于1个时更新,则移出购物车
  96. $cart->delItem($id);
  97. continue;
  98. }
  99. $rows['title'] = $rs['title'];
  100. $cart->addItem($id, $rows);
  101. }
  102. }
  103. ShowMsg("购物车中商品已全部更新!","car.php");
  104. exit;
  105. }