Transfer.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace common\models;
  3. use common\helpers\Tool;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%TRANSFER}}".
  7. *
  8. * @property string $ID
  9. * @property string $TRANSFER_SN 转账记录流水号
  10. * @property string $OUT_UID 转出会员ID
  11. * @property string $LAST_OUT_USER_NAME 转账时转出会员编号
  12. * @property string $LAST_OUT_REAL_NAME 转账时转出会员姓名
  13. * @property string $LAST_OUT_DEC_LV 转账时转出会员级别
  14. * @property string $LAST_OUT_DEC_ROLE_ID 转账时转出会员报单中心级别
  15. * @property string $OUT_WALLET 转出账户
  16. * @property string $LAST_OUT_SYSTEM_ID 转账时转出会员体系
  17. * @property string $IN_UID 转入会员ID
  18. * @property string $LAST_IN_USER_NAME 转账时转入会员编号
  19. * @property string $LAST_IN_REAL_NAME 转账时转入会员姓名
  20. * @property string $LAST_IN_DEC_LV 转账时转入会员级别
  21. * @property string $IN_WALLET 转入账户
  22. * @property string $LAST_IN_SYSTEM_ID 转账时转入会员体系
  23. * @property string $ORI_AMOUNT 转账金额
  24. * @property string $FEE 手续费
  25. * @property string $AMOUNT 实际转入金额
  26. * @property string $REMARK 备注
  27. * @property int $PERIOD_NUM 所在期数
  28. * @property int $CALC_MONTH 所在结算月
  29. * @property int $CREATED_AT 创建时间
  30. */
  31. class Transfer extends \common\components\ActiveRecord
  32. {
  33. const WALLET_NAME = [
  34. 'bonus'=>'Bonus',
  35. 'cash'=>'Ecoin',
  36. ];
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public static function tableName()
  41. {
  42. return '{{%TRANSFER}}';
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function rules()
  48. {
  49. return [
  50. [['TRANSFER_SN', 'OUT_UID', 'LAST_OUT_USER_NAME', 'LAST_OUT_REAL_NAME', 'IN_UID', 'LAST_IN_USER_NAME', 'LAST_IN_REAL_NAME', 'PERIOD_NUM', 'CALC_MONTH', 'CREATED_AT'], 'required'],
  51. [['ORI_AMOUNT', 'FEE', 'AMOUNT'], 'number'],
  52. [['PERIOD_NUM', 'CALC_MONTH', 'CREATED_AT'], 'integer'],
  53. [['ID', 'TRANSFER_SN', 'OUT_UID', 'LAST_OUT_DEC_LV', 'LAST_OUT_DEC_ROLE_ID', 'LAST_OUT_SYSTEM_ID', 'IN_UID', 'LAST_IN_DEC_LV', 'LAST_IN_SYSTEM_ID'], 'string', 'max' => 32],
  54. [['LAST_OUT_USER_NAME', 'LAST_IN_USER_NAME'], 'string', 'max' => 16],
  55. [['LAST_OUT_REAL_NAME', 'OUT_WALLET', 'LAST_IN_REAL_NAME', 'IN_WALLET'], 'string', 'max' => 128],
  56. [['REMARK'], 'string', 'max' => 4000],
  57. [['ID'], 'unique'],
  58. ];
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. public function attributeLabels()
  64. {
  65. return [
  66. 'ID' => 'ID',
  67. 'TRANSFER_SN' => '转账记录流水号',
  68. 'OUT_UID' => '转出会员ID',
  69. 'LAST_OUT_USER_NAME' => '转账时转出会员编号',
  70. 'LAST_OUT_REAL_NAME' => '转账时转出会员姓名',
  71. 'LAST_OUT_DEC_LV' => '转账时转出会员级别',
  72. 'LAST_OUT_DEC_ROLE_ID' => '转账时转出会员报单中心级别',
  73. 'OUT_WALLET' => '转出账户',
  74. 'LAST_OUT_SYSTEM_ID' => '转账时转出会员体系',
  75. 'IN_UID' => '转入会员ID',
  76. 'LAST_IN_USER_NAME' => '转账时转入会员编号',
  77. 'LAST_IN_REAL_NAME' => '转账时转入会员姓名',
  78. 'LAST_IN_DEC_LV' => '转账时转入会员级别',
  79. 'IN_WALLET' => '转入账户',
  80. 'LAST_IN_SYSTEM_ID' => '转账时转入会员体系',
  81. 'ORI_AMOUNT' => '转账金额',
  82. 'FEE' => '手续费',
  83. 'AMOUNT' => '实际转入金额',
  84. 'REMARK' => '备注',
  85. 'PERIOD_NUM' => '所在期数',
  86. 'CALC_MONTH' => '所在结算月',
  87. 'CREATED_AT' => '创建时间',
  88. ];
  89. }
  90. /**
  91. * 生成sn
  92. * @return string
  93. */
  94. public static function generateSN() {
  95. $date = date('ymdHis');
  96. $sn = 'BZZ' . $date . Tool::numFix(rand(1, 9999999999), 10, '0');
  97. if (self::find()->where('TRANSFER_SN=:SN', [':SN' => $sn])->exists()) {
  98. return self::generateSN();
  99. }
  100. return $sn;
  101. }
  102. /**
  103. * 本周是否转账
  104. * @param $uid
  105. * @return bool
  106. */
  107. public static function hasThisWeekTransfer($uid) {
  108. $period = Period::instance();
  109. if (static::find()->where('OUT_UID=:OUT_UID AND PERIOD_NUM=:PERIOD_NUM', [':OUT_UID' => $uid, ':PERIOD_NUM' => $period->getNowPeriodNum()])->exists()) {
  110. return true;
  111. }
  112. return false;
  113. }
  114. /**
  115. * 本周提现总额
  116. * @param $uid
  117. * @return mixed
  118. */
  119. public static function weekTransfer($uid){
  120. $period = Period::instance();
  121. return static::find()->where('OUT_UID=:OUT_UID AND PERIOD_NUM=:PERIOD_NUM', [':OUT_UID' => $uid, ':PERIOD_NUM' => $period->getNowPeriodNum()])->sum('ORI_AMOUNT');
  122. }
  123. /**
  124. * 本月提现总额
  125. * @param $uid
  126. * @return mixed
  127. */
  128. public static function monthTransfer($uid){
  129. $period = Period::instance();
  130. return static::find()->where('OUT_UID=:OUT_UID AND CALC_MONTH=:CALC_MONTH', [':OUT_UID' => $uid, ':CALC_MONTH' => $period->getNowYearMonth()])->sum('ORI_AMOUNT');
  131. }
  132. }