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