Agent.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php namespace Place\Lib;
  2. use Dever;
  3. class Agent
  4. {
  5. # 获取列表
  6. public function getList($state = true)
  7. {
  8. $data = array();
  9. if ($state) {
  10. $data = array
  11. (
  12. 0 => array
  13. (
  14. 'id' => -1,
  15. 'name' => '无代理',
  16. ),
  17. );
  18. }
  19. $where['status'] = 1;
  20. $data = array_merge($data, Dever::db('agent', 'place')->select($where));
  21. return $data;
  22. }
  23. # 获取代理购买资源的价格
  24. public function getPrice($price, $agent_id, $info_id, $key = 'price', $app = 'content', $type = 1)
  25. {
  26. if ($agent_id > 0) {
  27. $result = '';
  28. $info = Dever::db('agent_price', $app)->select(array('info_id' => $info_id));
  29. if ($info) {
  30. foreach ($info as &$v) {
  31. if ($v['agent_id'] == $agent_id) {
  32. $result = $v[$key];
  33. break;
  34. } elseif (!$v['agent_id']) {
  35. $result = $v[$key];
  36. }
  37. }
  38. if ($key == 'per') {
  39. if ($result > 0) {
  40. return number_format($price * $result, 2);
  41. }
  42. } elseif ($result || $result === '0') {
  43. return number_format($result, 2);
  44. }
  45. }
  46. $info = Dever::db('agent_price', 'place')->find(array('agent_id' => $agent_id, 'type' => $type));
  47. if ($info && $info['per']) {
  48. $result = number_format($price * $info['per'], 2);
  49. return $result;
  50. }
  51. }
  52. return null;
  53. }
  54. # 获取佣金
  55. public function getFee($price, $agent_id, $info_id, $app = 'content', $type = 1)
  56. {
  57. if ($agent_id > 0) {
  58. $result = '';
  59. $info = Dever::db('agent_price', $app)->select(array('info_id' => $info_id));
  60. if ($info) {
  61. foreach ($info as &$v) {
  62. if ($v['agent_id'] == $agent_id) {
  63. $result = $v['fee'];
  64. break;
  65. } elseif (!$v['agent_id']) {
  66. $result = $v['fee'];
  67. }
  68. }
  69. if ($result > 0) {
  70. return number_format($price * $result/100, 2);
  71. }
  72. }
  73. $info = Dever::db('agent_price', 'place')->find(array('agent_id' => $agent_id, 'type' => $type));
  74. if ($info && $info['fee'] > 0) {
  75. $result = number_format($price * $info['fee']/100, 2);
  76. return $result;
  77. }
  78. }
  79. return null;
  80. }
  81. }