| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?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'
- ];
- }
- // 更新或者添加业绩数据
- /**
- * @param $periodNum 结算业绩期
- * @param $calcMonth 结算月
- * @param $userId 结算过程中的用户
- * @param $data 数据
- * @param $appendPv 往上找店铺,需要给店铺的PV值
- */
- public static function addOrUpdate($periodNum, $calcMonth, $userId, $data, $appendPv = 0) {
- $info = StorePerfLog::findUseDbCalc()
- ->select('ID,GRAND_TOTAL_PV')
- ->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 (empty($info)) {
- if ($data['IS_STUDIO'] == 1) {
- $data['GRAND_TOTAL_PV'] = $data['MONTH_PV'];
- }
- StorePerfLog::insertOne($data);
- } else {
- // 如果循环到此用户有业绩单,则将此用户的PV更新为自己业绩单的值
- if ($data['MONTH_PV'] > 0) {
- StorePerfLog::updateAll(['MONTH_PV' => $data['MONTH_PV']], 'ID=:ID', [':ID' => $info['ID']]);
- }
- if ($data['IS_STUDIO'] == 1) {
- // 累加总PV
- $totalPv = $info['GRAND_TOTAL_PV'] + $appendPv;
- StorePerfLog::updateAll(['GRAND_TOTAL_PV' => $totalPv], 'ID=:ID', [':ID' => $info['ID']]);
- }
- }
- return true;
- }
- }
|