PerfMonth.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 $LAST_DEC_LV 结算时会员级别
  12. * @property string $LAST_EMP_LV 结算时会员聘级
  13. * @property int $LAST_STATUS 结算时会有状态
  14. * @property string $FX_AMOUNT_CASH 复消现金金额
  15. * @property string $PV_PCS 个人消费
  16. * @property string $PV_PCS_FX 个人复消业绩
  17. * @property string $PV_1L 一市场业绩
  18. * @property string $PV_2L 二市场业绩
  19. * @property string $PV_3L 三市场业绩
  20. * @property string $PV_4L 四市场业绩
  21. * @property string $PV_5L 五市场业绩
  22. * @property string $VIP_PV_1L_ZC VIP一市场报单业绩
  23. * @property string $VIP_PV_2L_ZC VIP二市场报单业绩
  24. * @property string $VIP_PV_3L_ZC VIP三市场报单业绩
  25. * @property string $VIP_PV_4L_ZC VIP四市场报单业绩
  26. * @property string $VIP_PV_5L_ZC VIP五市场报单业绩
  27. * @property string $VIP_SURPLUS_1L_ZC VIP一市场剩余报单业绩
  28. * @property string $VIP_SURPLUS_2L_ZC VIP二市场剩余报单业绩
  29. * @property string $VIP_SURPLUS_3L_ZC VIP三市场剩余报单业绩
  30. * @property string $VIP_SURPLUS_4L_ZC VIP四市场剩余报单业绩
  31. * @property string $VIP_SURPLUS_5L_ZC VIP五市场剩余报单业绩
  32. * @property string $PV_1L_TOTAL 一市场历史累计加该月业绩
  33. * @property string $PV_2L_TOTAL 二市场历史累计加该月业绩
  34. * @property string $PV_3L_TOTAL 三市场历史累计加该月业绩
  35. * @property string $PV_4L_TOTAL 四市场历史累计加该月业绩
  36. * @property string $PV_5L_TOTAL 五市场历史累计加该月业绩
  37. * @property int $CF_PERCENT 车房养老奖分工系数
  38. * @property int $LX_PERCENT 领袖分红分工系数
  39. * @property int $FX_STATUS 本月复销状态作为下月发奖资格
  40. * @property int $CALC_MONTH 结算月
  41. * @property string $P_CALC_MONTH 表分区日期索引
  42. * @property int $CREATED_AT 创建时间
  43. */
  44. class PerfMonth extends \common\components\ActiveRecord
  45. {
  46. const NEXT_MONTH_FX_TRUE = 1;
  47. const NEXT_MONTH_FX_FALSE = 0;
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public static function tableName()
  52. {
  53. return '{{%PERF_MONTH}}';
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function rules()
  59. {
  60. return [
  61. [['USER_ID', 'CALC_MONTH', 'P_CALC_MONTH', 'CREATED_AT'], 'required'],
  62. [['LAST_STATUS', 'CF_PERCENT', 'LX_PERCENT', 'FX_STATUS', 'CALC_MONTH', 'CREATED_AT'], 'integer'],
  63. [['FX_AMOUNT_CASH', 'PV_PCS', 'PV_PCS_FX', 'PV_1L', 'PV_2L', 'PV_3L', 'PV_4L', 'PV_5L', 'VIP_PV_1L_ZC', 'VIP_PV_2L_ZC', 'VIP_PV_3L_ZC', 'VIP_PV_4L_ZC', 'VIP_PV_5L_ZC', 'VIP_SURPLUS_1L_ZC', 'VIP_SURPLUS_2L_ZC', 'VIP_SURPLUS_3L_ZC', 'VIP_SURPLUS_4L_ZC', 'VIP_SURPLUS_5L_ZC', 'PV_1L_TOTAL', 'PV_2L_TOTAL', 'PV_3L_TOTAL', 'PV_4L_TOTAL', 'PV_5L_TOTAL'], 'number'],
  64. [['ID', 'USER_ID', 'LAST_DEC_LV', 'LAST_EMP_LV'], 'string', 'max' => 32],
  65. [['P_CALC_MONTH'], 'safe'],
  66. [['ID'], 'unique'],
  67. ];
  68. }
  69. /**
  70. * {@inheritdoc}
  71. */
  72. public function attributeLabels()
  73. {
  74. return [
  75. 'ID' => 'ID',
  76. 'USER_ID' => '会员ID',
  77. 'LAST_DEC_LV' => '结算时会员级别',
  78. 'LAST_EMP_LV' => '结算时会员聘级',
  79. 'LAST_STATUS' => '结算时会有状态',
  80. 'FX_AMOUNT_CASH' => '复消现金金额',
  81. 'PV_PCS' => '个人消费',
  82. 'PV_PCS_FX' => '个人复消业绩',
  83. 'PV_1L' => '一市场业绩',
  84. 'PV_2L' => '二市场业绩',
  85. 'PV_3L' => '三市场业绩',
  86. 'PV_4L' => '四市场业绩',
  87. 'PV_5L' => '五市场业绩',
  88. 'VIP_PV_1L_ZC' => 'VIP一市场报单业绩',
  89. 'VIP_PV_2L_ZC' => 'VIP二市场报单业绩',
  90. 'VIP_PV_3L_ZC' => 'VIP三市场报单业绩',
  91. 'VIP_PV_4L_ZC' => 'VIP四市场报单业绩',
  92. 'VIP_PV_5L_ZC' => 'VIP五市场报单业绩',
  93. 'VIP_SURPLUS_1L_ZC' => 'VIP一市场剩余报单业绩',
  94. 'VIP_SURPLUS_2L_ZC' => 'VIP二市场剩余报单业绩',
  95. 'VIP_SURPLUS_3L_ZC' => 'VIP三市场剩余报单业绩',
  96. 'VIP_SURPLUS_4L_ZC' => 'VIP四市场剩余报单业绩',
  97. 'VIP_SURPLUS_5L_ZC' => 'VIP五市场剩余报单业绩',
  98. 'PV_1L_TOTAL' => '一市场历史累计加该月业绩',
  99. 'PV_2L_TOTAL' => '二市场历史累计加该月业绩',
  100. 'PV_3L_TOTAL' => '三市场历史累计加该月业绩',
  101. 'PV_4L_TOTAL' => '四市场历史累计加该月业绩',
  102. 'PV_5L_TOTAL' => '五市场历史累计加该月业绩',
  103. 'CF_PERCENT' => '车房养老奖分工系数',
  104. 'LX_PERCENT' => '领袖分红分工系数',
  105. 'FX_STATUS' => '本月复销状态作为下月发奖资格',
  106. 'CALC_MONTH' => '结算月',
  107. 'P_CALC_MONTH' => '表分区日期索引',
  108. 'CREATED_AT' => '创建时间',
  109. ];
  110. }
  111. /**
  112. * 获取会员的月业绩总和
  113. * @param $yearMonth
  114. * @param $userId
  115. * @return array|null|\yii\db\ActiveRecord
  116. */
  117. public static function getMonthPerf($yearMonth, $userId){
  118. $result = static::find()->yearMonth($yearMonth)->where('USER_ID=:USER_ID', [':USER_ID'=>$userId])->asArray()->one();
  119. if(!$result){
  120. $result = [
  121. 'USER_ID' => $userId,
  122. 'FX_AMOUNT_CASH' => 0,
  123. 'PV_PCS' => 0,
  124. 'PV_PSS' => 0,
  125. 'PV_1L' => 0,
  126. 'PV_2L' => 0,
  127. 'PV_3L' => 0,
  128. 'PV_4L' => 0,
  129. 'PV_5L' => 0,
  130. 'PV_1L_TOTAL' => 0,
  131. 'PV_2L_TOTAL' => 0,
  132. 'PV_3L_TOTAL' => 0,
  133. 'PV_4L_TOTAL' => 0,
  134. 'PV_5L_TOTAL' => 0,
  135. 'PV_PSS_TOTAL' => 0,
  136. 'DEC_LEVEL' => null,
  137. 'EMP_LEVEL' => null,
  138. 'CF_PERCENT' => 0,
  139. 'LX_PERCENT' => 0,
  140. 'FX_STATUS' => self::NEXT_MONTH_FX_FALSE,
  141. ];
  142. }
  143. $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']);
  144. return $result;
  145. }
  146. public static function fetchMonthPerf($yearMonth, $userId){
  147. $result = static::find()->select('*')->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', [':USER_ID'=>$userId, ':CALC_MONTH'=>$yearMonth])->asArray()->one();
  148. return $result;
  149. }
  150. // 校验业绩状态
  151. public static function checkStatus($pv) {
  152. if ($pv >= 1500) {
  153. return true;
  154. }
  155. return false;
  156. }
  157. /**
  158. * 操作日志记录条件
  159. * @return array
  160. */
  161. public function attrLabelsWithLogType(){
  162. return [
  163. 'USER_ID' => '会员ID',
  164. 'FX_STATUS' => [
  165. 'label' => '复销资格',
  166. 'type' => function($data){
  167. $value = $data['value'];
  168. return $value==1?'是':'否';
  169. },
  170. ],
  171. 'CALC_MONTH' => '结算月',
  172. ];
  173. }
  174. }