推荐管理-分成管理的数据是怎么查询出来的,affiliate_ck.php里没看懂

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



点击分成管理,然后会列出订单分成数据,这个是admin/affiliate_ck.php里面的方法get_affiliate_ck()查询出来的,里面那个left join没看懂,明明'affiliate_log'中没得数据,但是还是查询出来了,而其推荐注册分成和推荐订单分成sql代码都是一样的,无语了

affiliate_log里面是已经分成的记录了,但是,还没分成的不可能也在存在里面了吧,但是查询的时候怎么要left join affiliate_log表呢,ON o.order_id = a.order_id这个根本不肯能哦,咋又查出数据了,谁帮帮我说一下是怎查出来的呢,非常感谢!


推荐注册分成和推荐订单分成sql代码都是一样的
  1. if(!empty($affiliate['on']))
  2. {
  3. if(empty($separate_by))
  4. {
  5. //推荐注册分成
  6. $sql = "SELECT o.*, a.log_id, a.user_id as suid,a.user_name as auser, a.money, a.point, a.separate_type,u.parent_id as up FROM " . $GLOBALS['ecs']->table('order_info') . " o".
  7. " LEFT JOIN".$GLOBALS['ecs']->table('users')." u ON o.user_id = u.user_id".
  8. " LEFT JOIN " . $GLOBALS['ecs']->table('affiliate_log') . " a ON o.order_id = a.order_id" .
  9. " WHERE o.user_id > 0 AND (u.parent_id > 0 AND o.is_separate = 0 OR o.is_separate > 0) $sqladd".
  10. " ORDER BY order_id DESC" .
  11. " LIMIT " . $filter['start'] . ",$filter[page_size]";

  12. /*
  13. SQL解释:

  14. 列出同时满足以下条件的订单分成情况:
  15. 1、有效订单o.user_id > 0
  16. 2、满足以下情况之一:
  17. a.有用户注册上线的未分成订单 u.parent_id > 0 AND o.is_separate = 0
  18. b.已分成订单 o.is_separate > 0

  19. */
  20. }
  21. else
  22. {
  23. //推荐订单分成
  24. $sql = "SELECT o.*, a.log_id,a.user_id as suid, a.user_name as auser, a.money, a.point, a.separate_type,u.parent_id as up FROM " . $GLOBALS['ecs']->table('order_info') . " o".
  25. " LEFT JOIN".$GLOBALS['ecs']->table('users')." u ON o.user_id = u.user_id".
  26. " LEFT JOIN " . $GLOBALS['ecs']->table('affiliate_log') . " a ON o.order_id = a.order_id" .
  27. " WHERE o.user_id > 0 AND (o.parent_id > 0 AND o.is_separate = 0 OR o.is_separate > 0) $sqladd" .
  28. " ORDER BY order_id DESC" .
  29. " LIMIT " . $filter['start'] . ",$filter[page_size]";

  30. /*
  31. SQL解释:

  32. 列出同时满足以下条件的订单分成情况:
  33. 1、有效订单o.user_id > 0
  34. 2、满足以下情况之一:
  35. a.有订单推荐上线的未分成订单 o.parent_id > 0 AND o.is_separate = 0
  36. b.已分成订单 o.is_separate > 0

  37. */
  38. }
  39. }
复制代码

回答:
你看下sql了连接查询你就知道了.呵呵.