DistributionCommissionBasisLog.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace addons\Distribution\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_addons_distribution_reward_config_log".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property string $source_table 来源表
  12. * @property int $source_table_id 来源表id
  13. * @property string $type 积分:score;佣金:commission
  14. * @property string $from_type 来源类型
  15. * @property string|null $basic_config 基础配置
  16. * @property string|null $level_config 等级配置
  17. * @property string|null $goods_config 商品独立配置
  18. * @property string|null $relation_ship 关系链等级
  19. * @property int $status 状态[-1:删除;0:禁用;1启用]
  20. * @property int $created_at 创建时间
  21. * @property int $updated_at 修改时间
  22. */
  23. class DistributionCommissionBasisLog extends BaseActiveRecord
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%addons_distribution_commission_basis_log}}';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['mall_id', 'source_table_id', 'status', 'created_at', 'updated_at'], 'integer'],
  39. [['type'], 'required'],
  40. [['basic_config', 'level_config', 'goods_config'], 'string'],
  41. [['source_table', 'type', 'from_type'], 'string', 'max' => 255],
  42. [['relation_ship'], 'string', 'max' => 2000],
  43. ];
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function attributeLabels()
  49. {
  50. return [
  51. 'id' => 'ID',
  52. 'mall_id' => '商城ID',
  53. 'source_table' => '来源表',
  54. 'source_table_id' => '来源表id',
  55. 'type' => '积分:score;佣金:commission',
  56. 'from_type' => '来源类型',
  57. 'basic_config' => '基础配置',
  58. 'level_config' => '等级配置',
  59. 'goods_config' => '商品独立配置',
  60. 'relation_ship' => '关系链等级',
  61. 'status' => '状态[-1:删除;0:禁用;1启用]',
  62. 'created_at' => '创建时间',
  63. 'updated_at' => '修改时间',
  64. ];
  65. }
  66. /**
  67. * @desc:保存数据
  68. * @Author: hua
  69. * @Date: 2021/11/18
  70. * @Time: 14:11
  71. * @Copyright: copyright (c) 2021 广东七件事集团
  72. * @param array $params
  73. * @return DistributionRewardConfigLog|false
  74. */
  75. public static function setData(array $params)
  76. {
  77. try {
  78. $model = self::findOne(['mall_id' => $params['mall_id'],
  79. 'source_table_id' => $params['source_table_id'],
  80. 'source_table' => $params['source_table'],
  81. 'type' => $params['type'],
  82. 'from_type' => $params['from_type'],
  83. 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  84. if (!empty($model)) return $model;
  85. $model = new self();
  86. $model->loadDefaultValues();
  87. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  88. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  89. return $model;
  90. } catch (\Exception $e) {
  91. self::$static_error = $e->getMessage();
  92. return false;
  93. }
  94. }
  95. }