| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace common\models;
- /**
- * This is the model class for table "{{%STORE_PERF_LOG}}".
- *
- * @property string $ID
- * @property string $PERF_ORDER_ID PERF_ORDER表的ID字段值
- * @property string $USER_ID USER表用户ID
- * @property int $IS_STUDIO 是否是工作室 0 不是 1是
- * @property string $PV 业绩单PV
- * @property string $PERIOD_NUM 业绩期
- * @property int $CALC_MONTH 结算月份
- * @property int $CREATE_AT 创建时间
- * @property string $GRAND_TOTAL_PV 工作室用户累计获得的小组PV
- */
- class StorePerfLog extends \common\components\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%STORE_PERF_LOG}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['USER_ID', 'IS_STUDIO', 'CREATED_AT'], 'required'],
- [['ID'], 'unique'],
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'ID' => 'ID',
- 'PERF_ORDER_ID' => 'PERF_ORDER表的ID字段值',
- 'USER_ID' => 'USER表用户ID',
- 'IS_STUDIO' => '是否是工作室 0 不是 1是',
- 'PV' => '业绩单PV',
- 'PERIOD_NUM' => '业绩期',
- 'CALC_MONTH' => '结算月份',
- 'CREATE_AT' => '创建时间',
- 'GRAND_TOTAL_PV' => '工作室用户累计获得的小组PV'
- ];
- }
- // 更新或者添加业绩数据
- public static function addOrUpdate($periodNum, $calcMonth, $userId, $data) {
- // 判断是否有此数据,如果有则进行更新
- $info = StorePerfLog::findUseDbCalc()
- ->select('ID')
- ->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM AND CALC_MONTH=:CALC_MONTH',
- [':USER_ID'=>$userId,':PERIOD_NUM' => $periodNum, ':CALC_MONTH' => $calcMonth]
- )
- ->asArray()
- ->one();
- if ($data['IS_STUDIO'] == 1) {
- $data['GRAND_TOTAL_PV'] = $data['PV'] + $info['GRAND_TOTAL_PV'];
- }
- if (empty($info)) {
- $ret = StorePerfLog::insertOne($data);
- } else {
- $ret = StorePerfLog::updateAll($data, 'ID=:ID', [':ID' => $info['ID']]);
- }
- return $ret;
- }
- }
|