AgentCommissionBasisLog.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace addons\Agent\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_agent_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 AgentCommissionBasisLog extends BaseActiveRecord
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%addons_agent_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. [['source_table','type','from_type'], 'string', 'max' => 255],
  40. [['basic_config', 'relation_ship'], 'string',],
  41. [['level_config', 'goods_config'], 'string',],
  42. ];
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function attributeLabels()
  48. {
  49. return [
  50. 'id' => 'ID',
  51. 'mall_id' => '商城ID',
  52. 'source_table' => '来源表',
  53. 'source_table_id' => '来源表id',
  54. 'type' => '奖励类型',
  55. 'from_type' => '来源类型',
  56. 'basic_config' => '基础配置',
  57. 'level_config' => '等级配置',
  58. 'goods_config' => '商品独立配置',
  59. 'relation_ship' => '关系链等级',
  60. 'status' => '状态[-1:删除;0:禁用;1启用]',
  61. 'created_at' => '创建时间',
  62. 'updated_at' => '修改时间',
  63. ];
  64. }
  65. /**
  66. * @desc:保存数据
  67. * @Author: hua
  68. * @Date: 2021/11/18
  69. * @Time: 10:54
  70. * @Copyright: copyright (c) 2021 广东七件事集团
  71. * @param array $params
  72. * @return AgentCommissionBasisLog|false|null
  73. */
  74. public static function setData(array $params)
  75. {
  76. try {
  77. $model = self::findOne(['mall_id' => $params['mall_id'],
  78. 'source_table_id' => $params['source_table_id'],
  79. 'source_table' => $params['source_table'],
  80. 'type' => $params['type'],
  81. 'from_type' => $params['from_type'],
  82. 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  83. if(!empty($model)) return $model;
  84. $model = new self();
  85. $model->loadDefaultValues();
  86. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  87. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  88. return $model;
  89. } catch (\Exception $e) {
  90. self::$static_error = $e->getMessage();
  91. return false;
  92. }
  93. }
  94. }