AgentBehaviorLogs.php 3.2 KB

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