| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace addons\Store\common\models;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "{{%addons_store_boss_agent_commission_log}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $user_id 用户ID
- * @property int $store_id
- * @property float $commission 永久/额外佣金,单位:元
- * @property string $source_table 来源表
- * @property int $source_table_id 来源表id
- * @property int $is_settle 是否已结算 0 否 1 是
- * @property string $desc 说明
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property string $order_no 订单编号
- * @property int $created_at
- * @property int $updated_at
- */
- class StoreBossAgentCommissionLog extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_store_boss_agent_commission_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'store_id', 'source_table_id', 'is_settle', 'status', 'created_at', 'updated_at','level'], 'integer'],
- [['commission'], 'number'],
- [['source_table', 'desc'], 'string', 'max' => 255],
- [['order_no'], 'string', 'max' => 100],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'store_id' => 'Store ID',
- 'commission' => 'Commission',
- 'source_table' => 'Source Table',
- 'source_table_id' => 'Source Table ID',
- 'is_settle' => 'Is Settle',
- 'desc' => 'Desc',
- 'status' => 'Status',
- 'order_no' => 'Order No',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * @desc:保存数据
- * @Author: hua
- * @Date: 2021/11/18
- * @Time: 10:54
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return AgentCommissionBasisLog|false|null
- */
- public static function setData(array $params)
- {
- try {
- $model = self::findOne([
- 'user_id' => $params['user_id'],
- 'store_id' => $params['store_id'],
- 'mall_id' => $params['mall_id'],
- 'source_table_id' => $params['source_table_id'],
- 'source_table' => $params['source_table'],
- 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if(!empty($model)) return $model;
- $model = new self();
- $model->loadDefaultValues();
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,nickname,mobile,username,avatar_url');
- }
- }
|