| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace common\models;
- use yii\db\Exception;
- /**
- * 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 创建时间
- */
- 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' => '创建时间',
- ];
- }
- // 更新或者添加业绩数据
- /**
- * @param int|string $periodNum 结算业绩期
- * @param string $calcMonth 结算月
- * @param string $userId 结算过程中的用户
- * @param array $data 数据
- * @param string|int|float $appendPv 往上找店铺,需要给店铺的PV值
- * @throws Exception
- */
- public static function addOrUpdate($periodNum, $calcMonth, $userId, $data, $appendPv = 0) {
- $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]);
- if (!$info) {
- StorePerfLog::insertOne($data);
- } else {
- // 如果循环到此用户有业绩单,则将此用户的PV更新为自己业绩单的值
- if ($data['MONTH_PV'] > 0) {
- StorePerfLog::updateAll(['MONTH_PV' => $data['MONTH_PV']], 'ID=:ID', [':ID' => $info['ID']]);
- }
- }
- return true;
- }
- // 更新stpefrlog表,用户小组分组工作室ID
- public static function stParendStudio($periodNum, $calcMonth, $allUidIn, $studioId) {
- if (!is_array($allUidIn) || empty($allUidIn) || empty($studioId)) {
- return false;
- }
- $allUidIn = implode("','", $allUidIn);
- StorePerfLog::updateAll(
- ['PARENT_UID' => $studioId],
- "PERIOD_NUM=:PERIOD_NUM AND CALC_MONTH=:CALC_MONTH AND USER_ID IN ('".$allUidIn."')",
- [
- ':PERIOD_NUM' => $periodNum,
- ':CALC_MONTH' => $calcMonth
- ]
- );
- return true;
- }
- public static function stGroupPv($periodNum, $calcMonth, $uid, $groupPv) {
- StorePerfLog::updateAll(
- ['GROUP_PV' => $groupPv],
-
- "PERIOD_NUM=:PERIOD_NUM AND CALC_MONTH=:CALC_MONTH AND USER_ID=:USER_ID",
- [
- ':PERIOD_NUM' => $periodNum,
- ':CALC_MONTH' => $calcMonth,
- ':USER_ID' => $uid,
- ]
- );
- return true;
- }
- }
|