StoreBossAgentCommissionSettingLog.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace addons\Store\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 "{{%addons_store_boss_agent_commission_setting_log}}".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property int $store_id
  12. * @property string $source_table 来源表
  13. * @property int $source_table_id 来源表id
  14. * @property string|null $basic_config 基础配置
  15. * @property string|null $level_config 等级配置
  16. * @property int $status 状态[-1:删除;0:禁用;1启用]
  17. * @property int $created_at 创建时间
  18. * @property int $updated_at 修改时间
  19. */
  20. class StoreBossAgentCommissionSettingLog extends \common\models\base\BaseActiveRecord
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return '{{%addons_store_boss_agent_commission_setting_log}}';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['mall_id', 'store_id', 'source_table_id', 'status', 'created_at', 'updated_at'], 'integer'],
  36. [['basic_config', 'level_config'], 'string'],
  37. [['source_table'], 'string', 'max' => 255],
  38. ];
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function attributeLabels()
  44. {
  45. return [
  46. 'id' => 'ID',
  47. 'mall_id' => 'Mall ID',
  48. 'store_id' => 'Store ID',
  49. 'source_table' => 'Source Table',
  50. 'source_table_id' => 'Source Table ID',
  51. 'basic_config' => 'Basic Config',
  52. 'level_config' => 'Level Config',
  53. 'status' => 'Status',
  54. 'created_at' => 'Created At',
  55. 'updated_at' => 'Updated At',
  56. ];
  57. }
  58. /**
  59. * @desc:保存数据
  60. * @Author: hua
  61. * @Date: 2021/11/18
  62. * @Time: 10:54
  63. * @Copyright: copyright (c) 2021 广东七件事集团
  64. * @param array $params
  65. * @return AgentCommissionBasisLog|false|null
  66. */
  67. public static function setData(array $params)
  68. {
  69. try {
  70. $model = self::findOne(['mall_id' => $params['mall_id'],
  71. 'source_table_id' => $params['source_table_id'],
  72. 'source_table' => $params['source_table'],
  73. 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  74. if(!empty($model)) return $model;
  75. $model = new self();
  76. $model->loadDefaultValues();
  77. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  78. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  79. return $model;
  80. } catch (\Exception $e) {
  81. self::$static_error = $e->getMessage();
  82. return false;
  83. }
  84. }
  85. }