在栏目页调用下属所有产品的销售总量、点击总数和评价积分

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



哈哈,谁要?

  1. /**
  2. * 取得商品销售总量
  3. *
  4. * @paramstring$cat_id 栏目ID
  5. *
  6. * @return销售总量
  7. */
  8. function get_catgoods_buy_sum($cat_id)
  9. {
  10. $sql = "SELECT sum(o.goods_number) as num FROM " . $GLOBALS['ecs']->table('order_goods') . " AS o RIGHT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g on g.goods_id=o.goods_id WHERE g.cat_id =".$cat_id ." or g.cat_id in (SELECT c.cat_id FROM " . $GLOBALS['ecs']->table('category') . " AS c WHERE c.parent_id =".$cat_id .")";
  11. return $GLOBALS['db']->getOne($sql);
  12. }
  13. /**
  14. * 取得本栏目所有商品浏览总量
  15. *
  16. * @paramstring$cat_id 栏目ID
  17. *
  18. * @return浏览总量
  19. */
  20. function get_catgoods_click_sum($cat_id)
  21. {
  22. $sql = "SELECT sum(g.click_count) as num FROM " . $GLOBALS['ecs']->table('goods') . " AS g WHERE g.cat_id =".$cat_id ." or g.cat_id in (SELECT c.cat_id FROM " . $GLOBALS['ecs']->table('category') . " AS c WHERE c.parent_id =".$cat_id .")";
  23. return $GLOBALS['db']->getOne($sql);
  24. }
  25. /**
  26. * 取得本栏目所有商品评价总分
  27. *
  28. * @paramstring$cat_id 栏目ID
  29. *
  30. * @return评价总分
  31. */
  32. function get_catgoods_comment_sum($cat_id)
  33. {
  34. $sql = "SELECT sum(c.comment_rank) as num FROM " . $GLOBALS['ecs']->table('comment') . " AS c RIGHT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g on g.goods_id=c.id_value WHERE g.cat_id =".$cat_id ." or g.cat_id in (SELECT cat.cat_id FROM " . $GLOBALS['ecs']->table('category') . " AS cat WHERE cat.parent_id =".$cat_id .")";
  35. return $GLOBALS['db']->getOne($sql);
  36. }
复制代码

回答:
支持共享

多谢楼主分享啊呵呵

好东西,支持了

如何调用呢?

上楼。接住。是这三个


goods_number
click_count
comment_rank