StorePerfLog.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. * @property string $GRAND_TOTAL_PV 工作室用户累计获得的小组PV
  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. 'GRAND_TOTAL_PV' => '工作室用户累计获得的小组PV'
  50. ];
  51. }
  52. // 更新或者添加业绩数据
  53. /**
  54. * @param $periodNum 结算业绩期
  55. * @param $calcMonth 结算月
  56. * @param $userId 结算过程中的用户
  57. * @param $data 数据
  58. * @param $appendPv 往上找店铺,需要给店铺的PV值
  59. */
  60. public static function addOrUpdate($periodNum, $calcMonth, $userId, $data, $appendPv = 0) {
  61. $info = StorePerfLog::findUseDbCalc()
  62. ->select('ID,GRAND_TOTAL_PV')
  63. ->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM AND CALC_MONTH=:CALC_MONTH',
  64. [':USER_ID'=>$userId,':PERIOD_NUM' => $periodNum, ':CALC_MONTH' => $calcMonth]
  65. )
  66. ->asArray()
  67. ->one();
  68. if (empty($info)) {
  69. if ($data['IS_STUDIO'] == 1) {
  70. $data['GRAND_TOTAL_PV'] = $data['MONTH_PV'];
  71. }
  72. StorePerfLog::insertOne($data);
  73. } else {
  74. // 如果循环到此用户有业绩单,则将此用户的PV更新为自己业绩单的值
  75. if ($data['MONTH_PV'] > 0) {
  76. StorePerfLog::updateAll(['MONTH_PV' => $data['MONTH_PV']], 'ID=:ID', [':ID' => $info['ID']]);
  77. }
  78. if ($data['IS_STUDIO'] == 1) {
  79. // 累加总PV
  80. $totalPv = $info['GRAND_TOTAL_PV'] + $appendPv;
  81. StorePerfLog::updateAll(['GRAND_TOTAL_PV' => $totalPv], 'ID=:ID', [':ID' => $info['ID']]);
  82. }
  83. }
  84. return true;
  85. }
  86. }