UserRecharge.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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\Config;
  10. use think\Log;
  11. use think\Model;
  12. use tool\Common;
  13. class UserRecharge extends Model
  14. {
  15. protected $resultSetType = 'collection';
  16. protected $updateTime = 'updateTime';
  17. protected $createTime = 'addTime';
  18. protected $autoWriteTimestamp = true;
  19. const TYPE_BANK = 'TYPE_BANK';
  20. const TYPE_WXCHANGE = 'TYPE_WXCHANGE';
  21. const TYPES = [
  22. self::TYPE_BANK=>'银行卡充值',
  23. self::TYPE_WXCHANGE=>'微信零钱充值'
  24. ];
  25. const STATUS_PAY = 1;
  26. const STATUS_UNPAY = 2;
  27. const STATUS_ERROR = 3;
  28. const STATUSS = [
  29. self::STATUS_PAY=>'已充值',
  30. self::STATUS_UNPAY=>'没有支付',
  31. self::STATUS_ERROR=>'充值失败',
  32. ];
  33. public function user() {
  34. return $this->belongsTo('user', 'userID');
  35. }
  36. public function setMoneyAttr($value) {
  37. return $value * 100;
  38. }
  39. public function getMoneyAttr($value) {
  40. return Common::price2($value / 100);
  41. }
  42. public function getResultTimeAttr($value)
  43. {
  44. return Common::timetodate($value, 4);
  45. }
  46. public function getOuterReachTimeAttr($value)
  47. {
  48. return Common::timetodate($value, 4);
  49. }
  50. public function getTypeNameAttr($value, $data) {
  51. return self::TYPES[$data['type']];
  52. }
  53. public function getStatusTextAttr($value, $data) {
  54. return self::STATUSS[$data['status']];
  55. }
  56. public function createAlias($id)
  57. {
  58. return 'RC' . Common::timetodate(THINK_START_TIME, 10) . sprintf("%08d", $id);
  59. }
  60. }