StorePerfLog.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. public static function addOrUpdate($periodNum, $calcMonth, $userId, $data) {
  54. // 判断是否有此数据,如果有则进行更新
  55. $info = StorePerfLog::findUseDbCalc()
  56. ->select('ID')
  57. ->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM AND CALC_MONTH=:CALC_MONTH',
  58. [':USER_ID'=>$userId,':PERIOD_NUM' => $periodNum, ':CALC_MONTH' => $calcMonth]
  59. )
  60. ->asArray()
  61. ->one();
  62. if ($data['IS_STUDIO'] == 1) {
  63. $data['GRAND_TOTAL_PV'] = $data['PV'] + $info['GRAND_TOTAL_PV'];
  64. }
  65. if (empty($info)) {
  66. $ret = StorePerfLog::insertOne($data);
  67. } else {
  68. $ret = StorePerfLog::updateAll($data, 'ID=:ID', [':ID' => $info['ID']]);
  69. }
  70. return $ret;
  71. }
  72. }