PerfMonth.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace common\models;
  3. use common\helpers\Tool;
  4. use Yii;
  5. use common\libs\logging\operate\valueType\Config as ValueTypeConfig;
  6. /**
  7. * This is the model class for table "{{%PERF_MONTH}}".
  8. *
  9. * @property string $ID
  10. * @property string $USER_ID 会员ID
  11. * @property string $FX_AMOUNT_CASH 复消现金金额
  12. * @property string $PV_PCS 个人消费
  13. * @property string $PV_PCS_FX 个人复消业绩
  14. * @property string $PV_1L 一市场业绩
  15. * @property string $PV_2L 二市场业绩
  16. * @property string $PV_3L 三市场业绩
  17. * @property string $PV_4L 四市场业绩
  18. * @property string $PV_5L 五市场业绩
  19. * @property string $PV_1L_TOTAL 一市场历史累计加该月业绩
  20. * @property string $PV_2L_TOTAL 二市场历史累计加该月业绩
  21. * @property string $PV_3L_TOTAL 三市场历史累计加该月业绩
  22. * @property string $PV_4L_TOTAL 四市场历史累计加该月业绩
  23. * @property string $PV_5L_TOTAL 五市场历史累计加该月业绩
  24. * @property int $CALC_MONTH 结算月
  25. * @property int $CREATED_AT 创建时间
  26. */
  27. class PerfMonth extends \common\components\ActiveRecord
  28. {
  29. const NEXT_MONTH_FX_TRUE = 1;
  30. const NEXT_MONTH_FX_FALSE = 0;
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public static function tableName()
  35. {
  36. return '{{%PERF_MONTH}}';
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function rules()
  42. {
  43. return [
  44. [['USER_ID', 'CALC_MONTH', 'CREATED_AT'], 'required'],
  45. [['CALC_MONTH', 'CREATED_AT'], 'integer'],
  46. [['FX_AMOUNT_CASH', 'PV_PCS', 'PV_PCS_FX', 'PV_1L', 'PV_2L', 'PV_3L', 'PV_4L', 'PV_5L','PV_1L_TOTAL', 'PV_2L_TOTAL', 'PV_3L_TOTAL', 'PV_4L_TOTAL', 'PV_5L_TOTAL'], 'number'],
  47. [['ID', 'USER_ID'], 'string', 'max' => 32],
  48. [['ID'], 'unique'],
  49. ];
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function attributeLabels()
  55. {
  56. return [
  57. 'ID' => 'ID',
  58. 'USER_ID' => '会员ID',
  59. 'FX_AMOUNT_CASH' => '复消现金金额',
  60. 'PV_PCS' => '个人消费',
  61. 'PV_PCS_FX' => '个人复消业绩',
  62. 'PV_1L' => '一市场业绩',
  63. 'PV_2L' => '二市场业绩',
  64. 'PV_3L' => '三市场业绩',
  65. 'PV_4L' => '四市场业绩',
  66. 'PV_5L' => '五市场业绩',
  67. 'PV_1L_TOTAL' => '一市场历史累计加该月业绩',
  68. 'PV_2L_TOTAL' => '二市场历史累计加该月业绩',
  69. 'PV_3L_TOTAL' => '三市场历史累计加该月业绩',
  70. 'PV_4L_TOTAL' => '四市场历史累计加该月业绩',
  71. 'PV_5L_TOTAL' => '五市场历史累计加该月业绩',
  72. 'CALC_MONTH' => '结算月',
  73. 'CREATED_AT' => '创建时间',
  74. ];
  75. }
  76. /**
  77. * 获取会员的月业绩总和
  78. * @param $yearMonth
  79. * @param $userId
  80. * @return array|null|\yii\db\ActiveRecord
  81. */
  82. public static function getMonthPerf($yearMonth, $userId){
  83. $result = static::find()->yearMonth($yearMonth)->where('USER_ID=:USER_ID', [':USER_ID'=>$userId])->asArray()->one();
  84. if(!$result){
  85. $result = [
  86. 'USER_ID' => $userId,
  87. 'FX_AMOUNT_CASH' => 0,
  88. 'PV_PCS' => 0,
  89. 'PV_PSS' => 0,
  90. 'PV_1L' => 0,
  91. 'PV_2L' => 0,
  92. 'PV_3L' => 0,
  93. 'PV_4L' => 0,
  94. 'PV_5L' => 0,
  95. 'PV_1L_TOTAL' => 0,
  96. 'PV_2L_TOTAL' => 0,
  97. 'PV_3L_TOTAL' => 0,
  98. 'PV_4L_TOTAL' => 0,
  99. 'PV_5L_TOTAL' => 0,
  100. 'PV_PSS_TOTAL' => 0,
  101. 'DEC_LEVEL' => null,
  102. 'EMP_LEVEL' => null,
  103. 'CF_PERCENT' => 0,
  104. 'LX_PERCENT' => 0,
  105. 'FX_STATUS' => self::NEXT_MONTH_FX_FALSE,
  106. ];
  107. }
  108. $result['PV_TOTAL'] = Tool::formatPrice($result['PV_1L_TOTAL']+$result['PV_2L_TOTAL']+$result['PV_3L_TOTAL']+$result['PV_4L_TOTAL']+$result['PV_5L_TOTAL']);
  109. return $result;
  110. }
  111. /**
  112. * 操作日志记录条件
  113. * @return array
  114. */
  115. public function attrLabelsWithLogType(){
  116. return [
  117. 'USER_ID' => '会员ID',
  118. 'FX_STATUS' => [
  119. 'label' => '复销资格',
  120. 'type' => function($data){
  121. $value = $data['value'];
  122. return $value==1?'是':'否';
  123. },
  124. ],
  125. 'CALC_MONTH' => '结算月',
  126. ];
  127. }
  128. }