Price.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php namespace Place\Lib;
  2. use Dever;
  3. use Place;
  4. class Price
  5. {
  6. public function get($info, $app, $type, $button)
  7. {
  8. $num = Dever::input('num', 'is_numeric', '数量', 1);
  9. $result = array();
  10. $result['status'] = 1;
  11. $result['text'] = '';
  12. $result['original'] = $info['price'];
  13. $result['value'] = $info['price'];
  14. $result['button'] = $button;
  15. $result['num'] = $num;
  16. $result['list'] = array();
  17. $order = Dever::db('order', 'place')->find(array('type' => $type, 'type_id' => $info['id'], 'uid' => Place::$uid, 'status' => 5));
  18. if ($order) {
  19. $result['value'] = $order['cash'];
  20. } else {
  21. $vip = Dever::load('vip', 'place')->getResourcePrice($info['price'], $info['id'], $app, $type);
  22. $agent = Dever::load('agent', 'place')->getResourcePrice($info['price'], $info['id'], $app, $type);
  23. if ($this->getAlone($vip, $agent, $result)) {
  24. return $result;
  25. }
  26. if ($info['price'] > 0) {
  27. $this->getList($vip, $agent, $result);
  28. $info['price'] = $this->getDiscount($info['price'], $vip['list'], $agent['list']);
  29. if ($info['price'] > 0) {
  30. if (isset($info['password'])) {
  31. $result['password'] = 2;
  32. if ($info['password']) {
  33. $result['password'] = 1;
  34. }
  35. }
  36. $result['status'] = 2;
  37. $result['value'] = $info['price'];
  38. }
  39. }
  40. }
  41. $result['value'] = $result['value'] * $result['num'];
  42. $result['text'] = $this->getText($result['value'], $type);
  43. return $result;
  44. }
  45. # 获取价格列表
  46. public function getList($vip, $agent, &$result)
  47. {
  48. if ($vip['list']) {
  49. $result['list'][] = array('name' => $vip['name'], 'list' => array_values($vip['list']));
  50. }
  51. if ($agent['list']) {
  52. $result['list'][] = array('name' => $agent['name'], 'list' => array_values($agent['list']));
  53. }
  54. }
  55. # 获取专享
  56. public function getAlone($vip, $agent, &$result)
  57. {
  58. $state = false;
  59. if ($vip['alone']) {
  60. if (isset($vip['alone'][Place::$user['vip_id']])) {
  61. $state = false;
  62. } else {
  63. $state = true;
  64. $result['list'][] = array('name' => $vip['name'], 'list' => array_values($vip['alone']));
  65. }
  66. }
  67. if ($agent['alone']) {
  68. if (isset($agent['alone'][Place::$user['agent_id']])) {
  69. $state = false;
  70. } else {
  71. $state = true;
  72. $result['list'][] = array('name' => $agent['name'], 'list' => array_values($agent['alone']));
  73. }
  74. }
  75. if ($state) {
  76. $result['status'] = 3;
  77. $result['text'] = '专享';
  78. }
  79. return $state;
  80. }
  81. # 获取折扣价
  82. public function getDiscount($price, $vip, $agent)
  83. {
  84. $result = array();
  85. # 获取会员价
  86. if ($vip && isset($vip[Place::$user['vip_id']])) {
  87. $price = $vip[Place::$user['vip_id']][1];
  88. }
  89. # 获取代理价
  90. if ($agent && isset($agent[Place::$user['agent_id']])) {
  91. $agent_price = $agent[Place::$user['agent_id']][1];
  92. if ($agent_price < $price) {
  93. $price = $agent_price;
  94. }
  95. }
  96. # 获取折扣+代金券的价格,暂时没有
  97. return $price;
  98. }
  99. public function getText($price, $type = 1)
  100. {
  101. if ($price > 0) {
  102. if ($type == 3) {
  103. $price = Place::$info['money_name'] . $price;
  104. } else {
  105. $price = $price . Place::$info['score_name'];
  106. }
  107. } else {
  108. $price = '免费';
  109. }
  110. return $price;
  111. }
  112. public function getValue($value, $price, $type)
  113. {
  114. if ($type == 3) {
  115. return number_format($price * ($value/100), 2);
  116. } elseif ($value || $value === '0') {
  117. return number_format($value, 2);
  118. }
  119. return $price;
  120. }
  121. }