| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace addons\Boss\common\models;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_boss_bonus_pool_performance}}".
- *
- * @property int $id ID
- * @property int $mall_id 商城ID
- * @property int $user_id 用户ID
- * @property float $performance 商品业绩
- * @property string $date 日期
- * @property int $status 状态[-1删除;0禁用;1正常]
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- */
- class BossPoolPrizePerformance extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_boss_pool_prize_performance}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['performance'], 'number'],
- [['date'], 'string', 'max' => 8],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '用户ID',
- 'performance' => '商品业绩',
- 'date' => '日期',
- 'status' => '状态[-1删除;0禁用;1正常]',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * @Description: 保存数据
- * @Author: zsan
- * @DateTime 2023-10-12 09:32:36
- * @param array $data
- * @return bool|self
- */
- public static function setData(array $data)
- {
- try {
- $model = self::findOne(['user_id' => $data['user_id'], 'mall_id' => $data['mall_id'], 'date' => $data['date'], 'status' => StatusEnum::ENABLED]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- }
- $data['performance'] = $model['performance'] + $data['performance'];
- if (!$model->load($data, '') || !$model->save()) {
- throw new \Exception($model->getErrorMessage());
- }
- return $model;
- } catch (\Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|