ReconsumePoolFlow.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace common\models;
  3. use common\helpers\Tool;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%RECONSUME_POOL_FLOW}}".
  7. *
  8. * @property string $ID
  9. * @property string $USER_ID 会员ID
  10. * @property string $RECONSUME_POOL_SN 流水号
  11. * @property string $LAST_DEC_LV 流水产生时会员级别
  12. * @property string $LAST_EMP_LV 流水产生时会员聘级
  13. * @property int $LAST_STATUS 流水产生时会员状态
  14. * @property int $RECONSUME_POOL_TYPE 流水类型
  15. * @property int $DEAL_TYPE 交易类型
  16. * @property string $DEDUCT_PV 变动PV
  17. * @property int $DEDUCT_MONTH 变动PV
  18. * @property string $UNUSED_PV 当前剩余未扣除PV
  19. * @property int $UNUSED_MONTH 当前剩余未扣除PV
  20. * @property int $IS_FX_DEDUCT 是否复销扣除
  21. * @property string $REMARK 备注
  22. * @property int $REMARK_IS_SHOW 备注前台显示
  23. * @property string $PERIOD_NUM 期数
  24. * @property int $CALC_MONTH 结算月
  25. * @property string $P_CALC_MONTH 分区表标识
  26. * @property int $CREATED_AT 创建时间
  27. * @property string $ADMIN_NAME 操作人
  28. */
  29. class ReconsumePoolFlow extends \common\components\ActiveRecord
  30. {
  31. const POOL_TYPE_PV = 1;
  32. const POOL_TYPE_MONTH = 2;
  33. const POOL_TYPE_NAME = [
  34. self::POOL_TYPE_PV=>'复销池余额流水',
  35. self::POOL_TYPE_MONTH=>'复销池月数流水',
  36. ];
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public static function tableName()
  41. {
  42. return '{{%RECONSUME_POOL_FLOW}}';
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function rules()
  48. {
  49. return [
  50. [['USER_ID', 'RECONSUME_POOL_SN', 'CALC_MONTH', 'P_CALC_MONTH', 'CREATED_AT'], 'required'],
  51. [['LAST_STATUS', 'RECONSUME_POOL_TYPE', 'DEAL_TYPE', 'DEDUCT_MONTH', 'UNUSED_MONTH', 'IS_FX_DEDUCT', 'REMARK_IS_SHOW', 'CALC_MONTH', 'CREATED_AT'], 'integer'],
  52. [['DEDUCT_PV', 'UNUSED_PV', 'PERIOD_NUM'], 'number'],
  53. [['ID', 'USER_ID', 'RECONSUME_POOL_SN', 'LAST_DEC_LV', 'LAST_EMP_LV', 'ADMIN_NAME'], 'string', 'max' => 32],
  54. [['REMARK'], 'string', 'max' => 255],
  55. [['P_CALC_MONTH'], 'string', 'max' => 7],
  56. [['ID'], 'unique'],
  57. ];
  58. }
  59. /**
  60. * {@inheritdoc}
  61. */
  62. public function attributeLabels()
  63. {
  64. return [
  65. 'ID' => 'ID',
  66. 'USER_ID' => '会员ID',
  67. 'RECONSUME_POOL_SN' => '流水号',
  68. 'LAST_DEC_LV' => '流水产生时会员级别',
  69. 'LAST_EMP_LV' => '流水产生时会员聘级',
  70. 'LAST_STATUS' => '流水产生时会员状态',
  71. 'RECONSUME_POOL_TYPE' => '流水类型',
  72. 'DEAL_TYPE' => '交易类型',
  73. 'DEDUCT_PV' => '变动PV',
  74. 'DEDUCT_MONTH' => '变动PV',
  75. 'UNUSED_PV' => '当前剩余未扣除PV',
  76. 'UNUSED_MONTH' => '当前剩余未扣除PV',
  77. 'IS_FX_DEDUCT' => '是否复销扣除',
  78. 'REMARK' => '备注',
  79. 'REMARK_IS_SHOW' => '备注前台显示',
  80. 'PERIOD_NUM' => '期数',
  81. 'CALC_MONTH' => '结算月',
  82. 'P_CALC_MONTH' => '分区表标识',
  83. 'CREATED_AT' => '创建时间',
  84. 'ADMIN_NAME' => '操作人',
  85. ];
  86. }
  87. /**
  88. * 生成sn
  89. * @param array $snArr
  90. * @param int $length
  91. * @return string
  92. */
  93. public static function generateSN() {
  94. $date = date('ymdHis');
  95. $sn = 'FX' . $date . Tool::numFix(rand(1, 9999999999), 10, '0');
  96. if (self::find()->where('RECONSUME_POOL_SN=:SN', [':SN' => $sn])->exists()) {
  97. return self::generateSN();
  98. }
  99. return $sn;
  100. }
  101. }