Cang.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 Cang extends Model
  12. {
  13. protected $pk = 'cangID';
  14. protected $resultSetType = 'collection';
  15. protected $updateTime = 'updateTime';
  16. protected $createTime = 'addTime';
  17. protected $autoWriteTimestamp = true;
  18. const STATUS_PAY = 1;
  19. const STATUS_UNPAY = 2;
  20. const STATUS_INTEREST = 3;
  21. const STATUS_REPAY = 4;
  22. const STATUS_FINISH = 10;
  23. const STATUSS = [
  24. self::STATUS_PAY=>'持有中',
  25. self::STATUS_UNPAY=>'未支付',
  26. self::STATUS_INTEREST=>'计息中',
  27. self::STATUS_REPAY=>'回款中',
  28. self::STATUS_FINISH=>'已回款'
  29. ];
  30. public function subject() {
  31. return $this->belongsTo('Subject', 'subjectID');
  32. }
  33. public function cangRepay() {
  34. return $this->hasMany('CangRepay', 'cangID');
  35. }
  36. public function user() {
  37. return $this->belongsTo('User', 'userID');
  38. }
  39. public function setMoneySubjectAttr($value) {
  40. return $value * 100;
  41. }
  42. public function getMoneySubjectAttr($value) {
  43. return Common::price2($value / 100);
  44. }
  45. public function setBenAttr($value) {
  46. return $value * 100;
  47. }
  48. public function getBenAttr($value) {
  49. return Common::price2($value / 100);
  50. }
  51. public function setMoneyAttr($value) {
  52. return $value * 100;
  53. }
  54. public function getMoneyAttr($value) {
  55. return Common::price2($value / 100);
  56. }
  57. public function setInterestAttr($value) {
  58. return $value * 100;
  59. }
  60. public function getInterestAttr($value) {
  61. return Common::price2($value / 100);
  62. }
  63. public function getInterestBeginTimeAttr($value)
  64. {
  65. return Common::timetodate($value, 0);
  66. }
  67. public function getPayTimeAttr($value)
  68. {
  69. return Common::timetodate($value);
  70. }
  71. public function getInterestEndTimeAttr($value)
  72. {
  73. return Common::timetodate($value + 86400, 0);
  74. }
  75. public function getRepayTimeTextAttr($value)
  76. {
  77. return '到期日15点前还款';
  78. }
  79. /*public function getStatusAttr($value) {
  80. if($value == self::STATUS_PAY) {
  81. if(THINK_START_TIME < $this->getData['interestBeginTime']) {
  82. return self::STATUS_PAY;
  83. }
  84. else if(THINK_START_TIME >= $this->getData['interestBeginTime'] && THINK_START_TIME < $this->getData['interestEndTime']){
  85. return self::STATUS_INTEREST;
  86. }
  87. else {
  88. return self::STATUS_REPAY;
  89. }
  90. }
  91. return $value;
  92. }*/
  93. public function getStatusTextAttr($value, $data) {
  94. return self::STATUSS[$data['status']];
  95. }
  96. public function getIsForgedTextAttr($value, $data) {
  97. if($data['isForged'] === 1) {
  98. return '虚拟账号';
  99. }
  100. return '自然人';
  101. }
  102. //设置计息状态
  103. public function setStatusInterest() {
  104. if($this->status != self::STATUS_PAY) {
  105. return true;
  106. }
  107. $this->status = self::STATUS_INTEREST;
  108. $this->save();
  109. return true;
  110. }
  111. public static function createAlias($id)
  112. {
  113. return 'CP' . Common::timetodate(THINK_START_TIME, 10) . sprintf("%08d", $id);
  114. }
  115. }