Hongbao.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qisse
  5. * Date: 2017/6/27
  6. * Time: 20:02
  7. */
  8. namespace app\core\model;
  9. use think\Model;
  10. use tool\Common;
  11. class Hongbao extends Model
  12. {
  13. protected $pk = 'hongbaoID';
  14. protected $resultSetType = 'collection';
  15. protected $updateTime = 'updateTime';
  16. protected $createTime = 'addTime';
  17. protected $autoWriteTimestamp = true;
  18. const STATUS_ONLINE = 1;
  19. const STATUS_OFFLINE = 2;
  20. const STATUSS = [
  21. self::STATUS_ONLINE=>'已启用',
  22. self::STATUS_OFFLINE=>'未启用',
  23. ];
  24. const TYPE_XIANJIN = 1;
  25. const TYPE_JIAXI = 2;
  26. const TYPESS = [
  27. [
  28. 'typeID'=>self::TYPE_XIANJIN,
  29. 'name'=>'现金券'
  30. ],
  31. [
  32. 'typeID'=>self::TYPE_JIAXI,
  33. 'name'=>'加息券'
  34. ]
  35. ];
  36. public function getTypeList() {
  37. return self::TYPESS;
  38. }
  39. public function setMinMoneyAttr($value) {
  40. return $value * 100;
  41. }
  42. public function getYearAttr($value) {
  43. return sprintf("%.1f",$value);
  44. }
  45. public function getMinMoneyAttr($value) {
  46. return Common::price2($value / 100);
  47. }
  48. public function setMaxMoneyAttr($value) {
  49. return $value * 100;
  50. }
  51. public function getMaxMoneyAttr($value) {
  52. return Common::price2($value / 100);
  53. }
  54. public function setMoneyAttr($value) {
  55. return $value * 100;
  56. }
  57. public function getMoneyAttr($value) {
  58. return Common::price2($value / 100);
  59. }
  60. public function getStatusTextAttr($value, $data) {
  61. return self::STATUSS[$data['status']];
  62. }
  63. public function getTypeNameAttr($value, $data) {
  64. foreach (self::TYPESS as $item) {
  65. if($item['typeID'] == $data['typeID']) {
  66. return $item['name'];
  67. }
  68. }
  69. return '未知';
  70. }
  71. public function getMinDayTextAttr($value, $data) {
  72. if($data['minDay'] == 0) {
  73. return '所有产品通用';
  74. }
  75. return '投资不低于'.$data['minDay'].'天使用';
  76. }
  77. public function getMinMoneyTextAttr($value, $data) {
  78. $minMoney = (int)$this->getMinMoneyAttr($data['minMoney']);
  79. if($minMoney == 0) {
  80. return '满0元使用';
  81. }
  82. return '满'.$minMoney.'元使用';
  83. }
  84. public function getBuyTextAttr($value, $data) {
  85. $text = '';
  86. if($data['typeID'] == self::TYPE_JIAXI) {
  87. $text = '加息'.$data['year'].'%';
  88. }
  89. else {
  90. $text = '现金券'.(int)$this->getMoneyAttr($data['money']).'元';
  91. }
  92. return $text;
  93. }
  94. }