CangRepay.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 CangRepay extends Model
  12. {
  13. protected $pk = 'cangRepayID';
  14. protected $resultSetType = 'collection';
  15. const STATUS_UNREPAY = 1;
  16. const STATUS_REPAY = 2;
  17. const STATUS_REACH = 3;
  18. const STATUSS = [
  19. self::STATUS_UNREPAY=>'未回款',
  20. self::STATUS_REPAY=>'已回款',
  21. self::STATUS_REACH=>'已到款'
  22. ];
  23. public function cang() {
  24. return $this->belongsTo('Cang', 'cangID');
  25. }
  26. public function subject() {
  27. return $this->belongsTo('Subject', 'subjectID');
  28. }
  29. public function setMoneyAttr($value) {
  30. return $value * 100;
  31. }
  32. public function getMoneyAttr($value) {
  33. return Common::price2($value / 100);
  34. }
  35. public function getReachTimeAttr($value)
  36. {
  37. return Common::timetodate($value, 0);
  38. }
  39. public function getRepayTimeAttr($value)
  40. {
  41. return Common::timetodate($value, 0);
  42. }
  43. public function getResultTimeAttr($value)
  44. {
  45. return Common::timetodate($value, 0);
  46. }
  47. public function getStatusTextAttr($value, $data) {
  48. return self::STATUSS[$data['status']];
  49. }
  50. public function getRepayTypeTextAttr($value)
  51. {
  52. if($value == 1) {
  53. return '本金';
  54. }
  55. else if($value == 2){
  56. return '利息';
  57. }
  58. return '';
  59. }
  60. public function repay() {
  61. //第一步,更新cang
  62. $this->data['status'] = self::STATUS_REPAY;
  63. $this->save();
  64. //第二步,更新用户账户
  65. if($this->data['repayTypeID'] == 1) {
  66. UserAccount::MODE_repayBen_addMoney($this->data['money'], $this->data['cangID'], $this->data['userID']);
  67. }
  68. else {
  69. UserAccount::MODE_repayInterest_addMoney($this->data['money'], $this->data['cangID'], $this->data['userID']);
  70. }
  71. }
  72. }