Transfer.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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'=>'增值点数',
  35. 'cash'=>'消费点数',
  36. 'point'=>'复销点数'
  37. ];
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public static function tableName()
  42. {
  43. return '{{%TRANSFER}}';
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function rules()
  49. {
  50. return [
  51. [['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'],
  52. [['ORI_AMOUNT', 'FEE', 'AMOUNT'], 'number'],
  53. [['PERIOD_NUM', 'CALC_MONTH', 'CREATED_AT'], 'integer'],
  54. [['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],
  55. [['LAST_OUT_USER_NAME', 'LAST_IN_USER_NAME'], 'string', 'max' => 16],
  56. [['LAST_OUT_REAL_NAME', 'OUT_WALLET', 'LAST_IN_REAL_NAME', 'IN_WALLET'], 'string', 'max' => 128],
  57. [['REMARK'], 'string', 'max' => 4000],
  58. [['ID'], 'unique'],
  59. ];
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function attributeLabels()
  65. {
  66. return [
  67. 'ID' => 'ID',
  68. 'TRANSFER_SN' => '转账记录流水号',
  69. 'OUT_UID' => '转出会员ID',
  70. 'LAST_OUT_USER_NAME' => '转账时转出会员编号',
  71. 'LAST_OUT_REAL_NAME' => '转账时转出会员姓名',
  72. 'LAST_OUT_DEC_LV' => '转账时转出会员级别',
  73. 'LAST_OUT_DEC_ROLE_ID' => '转账时转出会员报单中心级别',
  74. 'OUT_WALLET' => '转出账户',
  75. 'LAST_OUT_SYSTEM_ID' => '转账时转出会员体系',
  76. 'IN_UID' => '转入会员ID',
  77. 'LAST_IN_USER_NAME' => '转账时转入会员编号',
  78. 'LAST_IN_REAL_NAME' => '转账时转入会员姓名',
  79. 'LAST_IN_DEC_LV' => '转账时转入会员级别',
  80. 'IN_WALLET' => '转入账户',
  81. 'LAST_IN_SYSTEM_ID' => '转账时转入会员体系',
  82. 'ORI_AMOUNT' => '转账金额',
  83. 'FEE' => '手续费',
  84. 'AMOUNT' => '实际转入金额',
  85. 'REMARK' => '备注',
  86. 'PERIOD_NUM' => '所在期数',
  87. 'CALC_MONTH' => '所在结算月',
  88. 'CREATED_AT' => '创建时间',
  89. ];
  90. }
  91. /**
  92. * 生成sn
  93. * @return string
  94. */
  95. public static function generateSN() {
  96. $date = date('ymdHis');
  97. $sn = 'BZZ' . $date . Tool::numFix(rand(1, 9999999999), 10, '0');
  98. if (self::find()->where('TRANSFER_SN=:SN', [':SN' => $sn])->exists()) {
  99. return self::generateSN();
  100. }
  101. return $sn;
  102. }
  103. /**
  104. * 本周是否转账
  105. * @param $uid
  106. * @return bool
  107. */
  108. public static function hasThisWeekTransfer($uid) {
  109. $period = Period::instance();
  110. if (static::find()->where('OUT_UID=:OUT_UID AND PERIOD_NUM=:PERIOD_NUM', [':OUT_UID' => $uid, ':PERIOD_NUM' => $period->getNowPeriodNum()])->exists()) {
  111. return true;
  112. }
  113. return false;
  114. }
  115. /**
  116. * 本周提现总额
  117. * @param $uid
  118. * @return mixed
  119. */
  120. public static function weekTransfer($uid){
  121. $period = Period::instance();
  122. return static::find()->where('OUT_UID=:OUT_UID AND PERIOD_NUM=:PERIOD_NUM', [':OUT_UID' => $uid, ':PERIOD_NUM' => $period->getNowPeriodNum()])->sum('ORI_AMOUNT');
  123. }
  124. /**
  125. * 本月提现总额
  126. * @param $uid
  127. * @return mixed
  128. */
  129. public static function monthTransfer($uid){
  130. $period = Period::instance();
  131. return static::find()->where('OUT_UID=:OUT_UID AND CALC_MONTH=:CALC_MONTH', [':OUT_UID' => $uid, ':CALC_MONTH' => $period->getNowYearMonth()])->sum('ORI_AMOUNT');
  132. }
  133. }