UserBehaviorLogs.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace common\models\user;
  3. use Exception;
  4. use InvalidArgumentException;
  5. use RuntimeException;
  6. use Yii;
  7. /**
  8. * This is the model class for table "qimall_user_behavior_logs".
  9. *
  10. * @property int $id
  11. * @property int $mall_id
  12. * @property int $operator_user_id
  13. * @property int $operator_user_type 操作用户类型 1后台 2用户
  14. * @property int $operator_target_user_id 操作目标用户id
  15. * @property int $behavior 1修改手机号 2修改关系 3注销 4修改密码 5修改支付密码 6手动升级 7手动降级 8系统升级 9系统降级
  16. * @property string $desc
  17. * @property string|null $extra_info
  18. * @property int $ip
  19. * @property int $status
  20. * @property int $created_at
  21. * @property int $updated_at
  22. */
  23. class UserBehaviorLogs extends \common\models\base\BaseActiveRecord
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return 'qimall_user_behavior_logs';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['mall_id', 'operator_user_id', 'operator_user_type', 'behavior', 'ip', 'status', 'operation_time', 'created_at', 'updated_at', 'operator_target_user_id'], 'integer'],
  39. [['extra_info'], 'safe'],
  40. [['desc'], 'string', 'max' => 500],
  41. ];
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function attributeLabels()
  47. {
  48. return [
  49. 'id' => 'ID',
  50. 'mall_id' => 'Mall ID',
  51. 'operator_user_id' => 'Operator User ID',
  52. 'operator_user_type' => 'Operator User Type',
  53. 'operator_target_user_id' => 'Operator Target User Id',
  54. 'behavior' => 'Behavior',
  55. 'desc' => 'Desc',
  56. 'extra_info' => 'Extra Info',
  57. 'ip' => 'Ip',
  58. 'status' => 'Status',
  59. 'operation_time' => 'Operation Time',
  60. 'created_at' => 'Created At',
  61. 'updated_at' => 'Updated At',
  62. ];
  63. }
  64. public function getUser()
  65. {
  66. return $this->hasOne(User::class, ['id' => 'operator_target_user_id']);
  67. }
  68. /**
  69. * @param $params
  70. *
  71. * @return false|self
  72. */
  73. public static function setData($params)
  74. {
  75. try {
  76. $model = new self();
  77. $model->loadDefaultValues();
  78. if (!empty($params['ip'])) {
  79. $params['ip'] = ip2long($params['ip']);
  80. }
  81. if (empty($params['operator_target_user_id'])) {
  82. $params['operator_target_user_id'] = $params['operator_user_id'];
  83. }
  84. if (empty($params['operation_time'])) {
  85. $params['operation_time'] = time();
  86. }
  87. if (!$model->load($params, '')) {
  88. throw new RuntimeException($model->getErrorMessage());
  89. }
  90. if (!$model->save()) {
  91. throw new RuntimeException($model->getErrorMessage());
  92. }
  93. return $model;
  94. } catch (Exception $e) {
  95. self::$static_error = $e->getMessage();
  96. return false;
  97. }
  98. }
  99. }