Buy.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Collection\Lib;
  3. use Dever;
  4. class Buy
  5. {
  6. private function getOne($info)
  7. {
  8. if (!is_array($info)) {
  9. $info = Dever::db('collection/buy')->one($info);
  10. }
  11. return $info;
  12. }
  13. public function getInfo($info)
  14. {
  15. $info['name'] = $this->getName($info);
  16. $info['price'] = $this->getPrice($info);
  17. return $info;
  18. }
  19. public function getName($info)
  20. {
  21. $info = $this->getOne($info);
  22. if ($info && $info['name']) {
  23. return $info['name'];
  24. } else {
  25. $collection = Dever::db('collection/info')->one($info['info_id']);
  26. return '购买' . $info['num'] . $collection['unit'];
  27. }
  28. }
  29. public function getPrice($info)
  30. {
  31. $info = $this->getOne($info);
  32. $collection = Dever::db('collection/info')->one($info['info_id']);
  33. if ($info['price'] > 0) {
  34. return $info['price'];
  35. } else {
  36. return $info['num'] * $collection['buy_price'];
  37. }
  38. }
  39. public function getPriceName($info)
  40. {
  41. $price = $this->getPrice($info);
  42. return $price . '元';
  43. }
  44. }