国内流行的内容管理系统(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.

92 lines
3.0KB

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