StorePerfLog.php 3.5 KB

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