CreditsLog.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace common\models\member;
  3. use Yii;
  4. use common\enums\StatusEnum;
  5. use common\traits\HasOneMember;
  6. use common\traits\HasOneMerchant;
  7. /**
  8. * This is the model class for table "{{%member_credits_log}}".
  9. *
  10. * @property int $id
  11. * @property string|null $app_id 应用id
  12. * @property int|null $merchant_id 商户id
  13. * @property int|null $member_id 用户id
  14. * @property int|null $member_type 1:会员;2:后台管理员;3:商家管理员
  15. * @property int|null $pay_type 支付类型
  16. * @property string $type 变动类型[integral:积分;money:余额]
  17. * @property string|null $group 变动的组别
  18. * @property float|null $old_num 之前的数据
  19. * @property float|null $new_num 变动后的数据
  20. * @property float|null $num 变动的数据
  21. * @property string|null $remark 备注
  22. * @property string|null $ip ip地址
  23. * @property int|null $map_id 关联id
  24. * @property int|null $is_addon 是否插件
  25. * @property string|null $addon_name 插件名称
  26. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  27. * @property int|null $created_at 创建时间
  28. * @property int|null $updated_at 修改时间
  29. */
  30. class CreditsLog extends \common\models\base\BaseModel
  31. {
  32. use HasOneMember, HasOneMerchant;
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public static function tableName()
  37. {
  38. return '{{%member_credits_log}}';
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function rules()
  44. {
  45. return [
  46. [['merchant_id', 'member_id', 'member_type', 'pay_type', 'map_id', 'is_addon', 'status', 'created_at', 'updated_at'], 'integer'],
  47. [['old_num', 'new_num', 'num'], 'number'],
  48. [['app_id', 'type', 'group', 'ip'], 'string', 'max' => 50],
  49. [['remark', 'addon_name'], 'string', 'max' => 200],
  50. ];
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function attributeLabels()
  56. {
  57. return [
  58. 'id' => 'ID',
  59. 'app_id' => '应用id',
  60. 'merchant_id' => '商户id',
  61. 'member_id' => '用户id',
  62. 'member_type' => '1:会员;2:后台管理员;3:商家管理员',
  63. 'pay_type' => '支付类型',
  64. 'type' => '变动类型[integral:积分;money:余额]',
  65. 'group' => '变动的组别',
  66. 'old_num' => '之前的数据',
  67. 'new_num' => '变动后的数据',
  68. 'num' => '变动的数据',
  69. 'remark' => '备注',
  70. 'ip' => 'ip地址',
  71. 'map_id' => '关联id',
  72. 'is_addon' => '是否插件',
  73. 'addon_name' => '插件名称',
  74. 'status' => '状态',
  75. 'created_at' => '创建时间',
  76. 'updated_at' => '修改时间',
  77. ];
  78. }
  79. /**
  80. * @param bool $insert
  81. * @return bool
  82. */
  83. public function beforeSave($insert)
  84. {
  85. if ($this->isNewRecord) {
  86. $this->app_id = Yii::$app->id;
  87. $this->ip = Yii::$app->services->base->getUserIp();
  88. $this->addon_name = Yii::$app->params['addon']['name'] ?? '';
  89. !empty($this->addon_name) && $this->is_addon = StatusEnum::ENABLED;
  90. }
  91. return parent::beforeSave($insert);
  92. }
  93. }
粤ICP备19079148号