PerfPeriodPrepare.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. namespace common\models;
  3. use common\helpers\user\Info;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%PERF_PERIOD_PREPARE}}".
  7. * 预计算用户团队月业绩
  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_ZC 个人消费注册单
  17. * @property string $PV_PCS_YH 个人消费优惠单
  18. * @property string $PV_PCS_ZG 个人消费增购单
  19. * @property string $PV_PCS_LS 个人消费零售单
  20. * @property string $PV_PCS_FX 个人消费复销单
  21. * @property string $PV_PCS_FX_CASH 现金复消
  22. * @property string $PV_PCS_FX_POINT 积分复消
  23. * @property string $PV_1L 一市场业绩
  24. * @property string $PV_1L_TOUCH 一市场对碰业绩
  25. * @property string $PV_1L_ZC
  26. * @property string $PV_1L_YH
  27. * @property string $PV_1L_ZG
  28. * @property string $PV_1L_LS
  29. * @property string $PV_1L_FX
  30. * @property string $PV_2L 二市场业绩
  31. * @property string $PV_2L_TOUCH 二市场对碰业绩
  32. * @property string $PV_2L_ZC
  33. * @property string $PV_2L_YH
  34. * @property string $PV_2L_ZG
  35. * @property string $PV_2L_LS
  36. * @property string $PV_2L_FX
  37. * @property string $PV_3L 三市场业绩
  38. * @property string $PV_3L_TOUCH 三市场对碰业绩
  39. * @property string $PV_3L_ZC
  40. * @property string $PV_3L_YH
  41. * @property string $PV_3L_ZG
  42. * @property string $PV_3L_LS
  43. * @property string $PV_3L_FX
  44. * @property string $PV_4L 四市场业绩
  45. * @property string $PV_4L_TOUCH 四市场对碰业绩
  46. * @property string $PV_4L_ZC
  47. * @property string $PV_4L_YH
  48. * @property string $PV_4L_ZG
  49. * @property string $PV_4L_LS
  50. * @property string $PV_4L_FX
  51. * @property string $PV_5L 五市场业绩
  52. * @property string $PV_5L_TOUCH 五市场对碰业绩
  53. * @property string $PV_5L_ZC
  54. * @property string $PV_5L_YH
  55. * @property string $PV_5L_ZG
  56. * @property string $PV_5L_LS
  57. * @property string $PV_5L_FX
  58. * @property string $PV_LS_TOUCH 隐藏零售区业绩30%后的
  59. * @property string $SURPLUS_1L 一市场结余业绩
  60. * @property string $SURPLUS_1L_ZC 一市场首购结余业绩
  61. * @property string $SURPLUS_1L_FX 一市场复消结余业绩
  62. * @property string $SURPLUS_2L 二市场结余业绩
  63. * @property string $SURPLUS_2L_ZC 二市场首购结余业绩
  64. * @property string $SURPLUS_2L_FX 二市场复消结余业绩
  65. * @property string $SURPLUS_3L 三市场结余业绩
  66. * @property string $SURPLUS_3L_ZC 三市场首购结余业绩
  67. * @property string $SURPLUS_3L_FX 三市场复消结余业绩
  68. * @property string $SURPLUS_4L 四市场结余业绩
  69. * @property string $SURPLUS_4L_ZC 四市场首购结余业绩
  70. * @property string $SURPLUS_4L_FX 四市场复消结余业绩
  71. * @property string $SURPLUS_5L 五市场结余业绩
  72. * @property string $SURPLUS_5L_ZC 五市场首购结余业绩
  73. * @property string $SURPLUS_5L_FX 五市场复消结余业绩
  74. * @property string $SURPLUS_LS 零售隐藏区结余业绩
  75. * @property int $PERIOD_NUM 期数
  76. * @property int $CALC_MONTH 结算月YYYYMM
  77. * @property string $P_CALC_MONTH 表分区日期索引
  78. * @property int $CREATED_AT 创建时间
  79. */
  80. class PerfPeriodPrepare extends \common\components\ActiveRecord
  81. {
  82. /**
  83. * {@inheritdoc}
  84. */
  85. public static function tableName()
  86. {
  87. return '{{%PERF_PERIOD_PREPARE}}';
  88. }
  89. /**
  90. * {@inheritdoc}
  91. */
  92. public function rules()
  93. {
  94. return [
  95. [['USER_ID', 'PERIOD_NUM', 'CALC_MONTH', 'P_CALC_MONTH', 'CREATED_AT'], 'required'],
  96. [['LAST_STATUS', 'PERIOD_NUM', 'CALC_MONTH', 'CREATED_AT'], 'integer'],
  97. [['FX_AMOUNT_CASH', 'PV_PCS', 'PV_PCS_ZC', 'PV_PCS_YH', 'PV_PCS_ZG', 'PV_PCS_LS', 'PV_PCS_FX', 'PV_PCS_FX_CASH', 'PV_PCS_FX_POINT', 'PV_1L', 'PV_1L_TOUCH', 'PV_1L_ZC', 'PV_1L_YH', 'PV_1L_ZG', 'PV_1L_LS', 'PV_1L_FX', 'PV_2L', 'PV_2L_TOUCH', 'PV_2L_ZC', 'PV_2L_YH', 'PV_2L_ZG', 'PV_2L_LS', 'PV_2L_FX', 'PV_3L', 'PV_3L_TOUCH', 'PV_3L_ZC', 'PV_3L_YH', 'PV_3L_ZG', 'PV_3L_LS', 'PV_3L_FX', 'PV_4L', 'PV_4L_TOUCH', 'PV_4L_ZC', 'PV_4L_YH', 'PV_4L_ZG', 'PV_4L_LS', 'PV_4L_FX', 'PV_5L', 'PV_5L_TOUCH', 'PV_5L_ZC', 'PV_5L_YH', 'PV_5L_ZG', 'PV_5L_LS', 'PV_5L_FX', 'PV_LS_TOUCH', 'SURPLUS_1L', 'SURPLUS_1L_ZC', 'SURPLUS_1L_FX', 'SURPLUS_2L', 'SURPLUS_2L_ZC', 'SURPLUS_2L_FX', 'SURPLUS_3L', 'SURPLUS_3L_ZC', 'SURPLUS_3L_FX', 'SURPLUS_4L', 'SURPLUS_4L_ZC', 'SURPLUS_4L_FX', 'SURPLUS_5L', 'SURPLUS_5L_ZC', 'SURPLUS_5L_FX', 'SURPLUS_LS'], 'number'],
  98. [['ID', 'USER_ID', 'LAST_DEC_LV', 'LAST_EMP_LV'], 'string', 'max' => 32],
  99. [['P_CALC_MONTH'], 'safe'],
  100. [['ID'], 'unique'],
  101. ];
  102. }
  103. /**
  104. * {@inheritdoc}
  105. */
  106. public function attributeLabels()
  107. {
  108. return [
  109. 'ID' => 'ID',
  110. 'USER_ID' => '会员ID',
  111. 'LAST_DEC_LV' => '结算时会员级别',
  112. 'LAST_EMP_LV' => '结算时会员聘级',
  113. 'LAST_STATUS' => '结算时会有状态',
  114. 'FX_AMOUNT_CASH' => '复消现金金额',
  115. 'PV_PCS' => '个人消费',
  116. 'PV_PCS_ZC' => '个人消费注册单',
  117. 'PV_PCS_YH' => '个人消费优惠单',
  118. 'PV_PCS_ZG' => '个人消费增购单',
  119. 'PV_PCS_LS' => '个人消费零售单',
  120. 'PV_PCS_FX' => '个人消费复销单',
  121. 'PV_PCS_FX_CASH' => '现金复消',
  122. 'PV_PCS_FX_POINT' => '积分复消',
  123. 'PV_1L' => '一市场业绩',
  124. 'PV_1L_TOUCH' => '一市场对碰业绩',
  125. 'PV_1L_ZC' => 'Pv 1 L Zc',
  126. 'PV_1L_YH' => 'Pv 1 L Yh',
  127. 'PV_1L_ZG' => 'Pv 1 L Zg',
  128. 'PV_1L_LS' => 'Pv 1 L Ls',
  129. 'PV_1L_FX' => 'Pv 1 L Fx',
  130. 'PV_2L' => '二市场业绩',
  131. 'PV_2L_TOUCH' => '二市场对碰业绩',
  132. 'PV_2L_ZC' => 'Pv 2 L Zc',
  133. 'PV_2L_YH' => 'Pv 2 L Yh',
  134. 'PV_2L_ZG' => 'Pv 2 L Zg',
  135. 'PV_2L_LS' => 'Pv 2 L Ls',
  136. 'PV_2L_FX' => 'Pv 2 L Fx',
  137. 'PV_3L' => '三市场业绩',
  138. 'PV_3L_TOUCH' => '三市场对碰业绩',
  139. 'PV_3L_ZC' => 'Pv 3 L Zc',
  140. 'PV_3L_YH' => 'Pv 3 L Yh',
  141. 'PV_3L_ZG' => 'Pv 3 L Zg',
  142. 'PV_3L_LS' => 'Pv 3 L Ls',
  143. 'PV_3L_FX' => 'Pv 3 L Fx',
  144. 'PV_4L' => '四市场业绩',
  145. 'PV_4L_TOUCH' => '四市场对碰业绩',
  146. 'PV_4L_ZC' => 'Pv 4 L Zc',
  147. 'PV_4L_YH' => 'Pv 4 L Yh',
  148. 'PV_4L_ZG' => 'Pv 4 L Zg',
  149. 'PV_4L_LS' => 'Pv 4 L Ls',
  150. 'PV_4L_FX' => 'Pv 4 L Fx',
  151. 'PV_5L' => '五市场业绩',
  152. 'PV_5L_TOUCH' => '五市场对碰业绩',
  153. 'PV_5L_ZC' => 'Pv 5 L Zc',
  154. 'PV_5L_YH' => 'Pv 5 L Yh',
  155. 'PV_5L_ZG' => 'Pv 5 L Zg',
  156. 'PV_5L_LS' => 'Pv 5 L Ls',
  157. 'PV_5L_FX' => 'Pv 5 L Fx',
  158. 'PV_LS_TOUCH' => '隐藏零售区业绩30%后的',
  159. 'SURPLUS_1L' => '一市场结余业绩',
  160. 'SURPLUS_1L_ZC' => '一市场首购结余业绩',
  161. 'SURPLUS_1L_FX' => '一市场复消结余业绩',
  162. 'SURPLUS_2L' => '二市场结余业绩',
  163. 'SURPLUS_2L_ZC' => '二市场首购结余业绩',
  164. 'SURPLUS_2L_FX' => '二市场复消结余业绩',
  165. 'SURPLUS_3L' => '三市场结余业绩',
  166. 'SURPLUS_3L_ZC' => '三市场首购结余业绩',
  167. 'SURPLUS_3L_FX' => '三市场复消结余业绩',
  168. 'SURPLUS_4L' => '四市场结余业绩',
  169. 'SURPLUS_4L_ZC' => '四市场首购结余业绩',
  170. 'SURPLUS_4L_FX' => '四市场复消结余业绩',
  171. 'SURPLUS_5L' => '五市场结余业绩',
  172. 'SURPLUS_5L_ZC' => '五市场首购结余业绩',
  173. 'SURPLUS_5L_FX' => '五市场复消结余业绩',
  174. 'SURPLUS_LS' => '零售隐藏区结余业绩',
  175. 'PERIOD_NUM' => '期数',
  176. 'CALC_MONTH' => '结算月YYYYMM',
  177. 'P_CALC_MONTH' => '表分区日期索引',
  178. 'CREATED_AT' => '创建时间',
  179. ];
  180. }
  181. /**
  182. * 操作日志记录条件
  183. * @return array
  184. */
  185. public function attrLabelsWithLogType(){
  186. return [
  187. 'USER_ID' => '会员ID',
  188. 'SURPLUS_1L' => '一市场结余业绩',
  189. 'SURPLUS_2L' => '二市场结余业绩',
  190. 'SURPLUS_3L' => '三市场结余业绩',
  191. 'SURPLUS_4L' => '四市场结余业绩',
  192. 'SURPLUS_5L' => '五市场结余业绩',
  193. 'SURPLUS_LS' => '虚拟零售区结余业绩',
  194. ];
  195. }
  196. /**
  197. * 获取期结余业绩
  198. * @param $periodNum
  199. * @param $userId
  200. * @return array|\yii\db\ActiveRecord|null
  201. * @throws \yii\db\Exception
  202. */
  203. public static function getPeriodSurplusPerf($periodNum, $userId){
  204. $period = Period::instance();
  205. $yearMonth = $period->getYearMonth($periodNum);
  206. $result = static::findUseDbCalc()->yearMonth($yearMonth)->select('SURPLUS_1L,SURPLUS_2L,SURPLUS_3L,SURPLUS_4L,SURPLUS_5L,SURPLUS_LS')->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', [':USER_ID'=>$userId, ':PERIOD_NUM'=>$periodNum])->asArray()->one();
  207. if(!$result){
  208. $result = [
  209. 'USER_ID' => $userId,
  210. 'SURPLUS_1L' => 0,
  211. 'SURPLUS_2L' => 0,
  212. 'SURPLUS_3L' => 0,
  213. 'SURPLUS_4L' => 0,
  214. 'SURPLUS_5L' => 0,
  215. 'SURPLUS_LS' => 0,
  216. ];
  217. }
  218. return $result;
  219. }
  220. }