StorePerfLog.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace common\models;
  3. /**
  4. * This is the model class for table "{{%STORE_PERF_LOG}}".
  5. *
  6. * @property string $ID
  7. * @property string $PERF_ORDER_ID PERF_ORDER表的ID字段值
  8. * @property string $USER_ID USER表用户ID
  9. * @property int $IS_STUDIO 是否是工作室 0 不是 1是
  10. * @property string $PV 业绩单PV
  11. * @property string $PERIOD_NUM 业绩期
  12. * @property int $CALC_MONTH 结算月份
  13. * @property int $CREATE_AT 创建时间
  14. */
  15. class StorePerfLog extends \common\components\ActiveRecord
  16. {
  17. /**
  18. * @inheritdoc
  19. */
  20. public static function tableName()
  21. {
  22. return '{{%STORE_PERF_LOG}}';
  23. }
  24. /**
  25. * @inheritdoc
  26. */
  27. public function rules()
  28. {
  29. return [
  30. [['USER_ID', 'IS_STUDIO', 'CREATED_AT'], 'required'],
  31. [['ID'], 'unique'],
  32. ];
  33. }
  34. /**
  35. * @inheritdoc
  36. */
  37. public function attributeLabels()
  38. {
  39. return [
  40. 'ID' => 'ID',
  41. 'PERF_ORDER_ID' => 'PERF_ORDER表的ID字段值',
  42. 'USER_ID' => 'USER表用户ID',
  43. 'IS_STUDIO' => '是否是工作室 0 不是 1是',
  44. 'PV' => '业绩单PV',
  45. 'PERIOD_NUM' => '业绩期',
  46. 'CALC_MONTH' => '结算月份',
  47. 'CREATE_AT' => '创建时间',
  48. ];
  49. }
  50. // 更新或者添加业绩数据
  51. /**
  52. * @param $periodNum 结算业绩期
  53. * @param $calcMonth 结算月
  54. * @param $userId 结算过程中的用户
  55. * @param $data 数据
  56. * @param $appendPv 往上找店铺,需要给店铺的PV值
  57. */
  58. public static function addOrUpdate($periodNum, $calcMonth, $userId, $data, $appendPv = 0) {
  59. $info = StorePerfLog::findUseDbCalc()
  60. ->select('ID')
  61. ->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM AND CALC_MONTH=:CALC_MONTH',
  62. [':USER_ID'=>$userId,':PERIOD_NUM' => $periodNum, ':CALC_MONTH' => $calcMonth]
  63. )
  64. ->asArray()
  65. ->one();
  66. if (empty($info)) {
  67. StorePerfLog::insertOne($data);
  68. } else {
  69. // 如果循环到此用户有业绩单,则将此用户的PV更新为自己业绩单的值
  70. if ($data['MONTH_PV'] > 0) {
  71. StorePerfLog::updateAll(['MONTH_PV' => $data['MONTH_PV']], 'ID=:ID', [':ID' => $info['ID']]);
  72. }
  73. }
  74. return true;
  75. }
  76. // 更新stpefrlog表,用户小组分组工作室ID
  77. public static function stParendStudio($periodNum, $calcMonth, $allUidIn, $studioId) {
  78. if (!is_array($allUidIn) || empty($allUidIn) || empty($studioId)) {
  79. return false;
  80. }
  81. $allUidIn = implode("','", $allUidIn);
  82. StorePerfLog::updateAll(
  83. ['PARENT_UID' => $studioId],
  84. "PERIOD_NUM=:PERIOD_NUM AND CALC_MONTH=:CALC_MONTH AND USER_ID IN ('".$allUidIn."')",
  85. [
  86. ':PERIOD_NUM' => $periodNum,
  87. ':CALC_MONTH' => $calcMonth
  88. ]
  89. );
  90. return true;
  91. }
  92. public static function stGroupPv($periodNum, $calcMonth, $uid, $groupPv) {
  93. StorePerfLog::updateAll(
  94. ['GROUP_PV' => $groupPv],
  95. "PERIOD_NUM=:PERIOD_NUM AND CALC_MONTH=:CALC_MONTH AND USER_ID=:USER_ID",
  96. [
  97. ':PERIOD_NUM' => $periodNum,
  98. ':CALC_MONTH' => $calcMonth,
  99. ':USER_ID' => $uid,
  100. ]
  101. );
  102. return true;
  103. }
  104. }