DistributionCommissionBasisLog.php 3.5 KB

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