You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

142 lines
4.2 KiB

  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. use yii\db\Expression;
  5. /**
  6. * This is the model class for table "log_user_operation".
  7. *
  8. * @property integer $id
  9. * @property string $title
  10. * @property string $memo
  11. * @property integer $uid
  12. * @property integer $user_type
  13. * @property string $user_name
  14. * @property integer $resources_id
  15. * @property integer $resources_type
  16. * @property string $resources_name
  17. * @property string $phpsessid
  18. * @property string $user_agent
  19. * @property string $create_time
  20. */
  21. class LogUserOperation extends \yii\db\ActiveRecord
  22. {
  23. /**
  24. * @inheritdoc
  25. */
  26. public static function tableName()
  27. {
  28. return 'log_user_operation';
  29. }
  30. /**
  31. * @inheritdoc
  32. */
  33. public function rules()
  34. {
  35. return [
  36. [['title', 'memo', 'user_name'], 'required'],
  37. [['memo'], 'string'],
  38. [['uid', 'user_type', 'resources_id', 'resources_type'], 'integer'],
  39. [['create_time'], 'safe'],
  40. [['title'], 'string', 'max' => 120],
  41. [['user_name', 'resources_name', 'phpsessid', 'user_agent','last_login'], 'string', 'max' => 255],
  42. ];
  43. }
  44. /**
  45. * @inheritdoc
  46. */
  47. public function attributeLabels()
  48. {
  49. return [
  50. 'id' => 'ID',
  51. 'title' => 'Title',
  52. 'memo' => 'Memo',
  53. 'uid' => 'Uid',
  54. 'user_type' => 'User Type',
  55. 'user_name' => 'User Name',
  56. 'resources_id' => 'Resources ID',
  57. 'resources_type' => 'Resources Type',
  58. 'resources_name' => 'Resources Name',
  59. 'phpsessid' => 'Phpsessid',
  60. 'user_agent' => 'User Agent',
  61. 'create_time' => 'Crate Time',
  62. 'last_login' => 'last_login'
  63. ];
  64. }
  65. public function getList($param, $type)
  66. {
  67. //where条件
  68. $where = ['and'];
  69. if ($param['user_name'] != '') {
  70. $where[] = ['=', 'user_name', $param['user_name']];
  71. }
  72. if ($param['title'] != '') {
  73. $where[] = ['like', 'title', $param['title']];
  74. }
  75. if ($param['resource_id'] != '') {
  76. $where[] = ['=', 'resources_id', $param['resource_id']];
  77. }
  78. if ($param['create_time_start'] != '') {
  79. $where[] = ['>=', 'create_time', $param['create_time_start']];
  80. }
  81. if ($param['create_time_end'] != '') {
  82. $where[] = ['<', 'create_time', date('Y-m-d', strtotime("{$param['create_time_end']} +1 day"))];
  83. }
  84. if ($type == 1) {//获取count
  85. $select = ["count(1) cnt"];
  86. $result = self::find()->select($select)
  87. ->where($where)
  88. ->asArray()
  89. ->one();
  90. return $result['cnt'];
  91. } else {//获取列表
  92. //查询字段
  93. $select = [
  94. 'id',
  95. 'title',
  96. 'memo' ,
  97. 'uid' ,
  98. 'user_type',
  99. 'user_name',
  100. 'resources_id'=>new Expression("if(resources_id=0,' - ',resources_id)"),
  101. 'resources_type',
  102. 'resources_name',
  103. 'phpsessid',
  104. 'user_agent',
  105. 'create_time',
  106. 'last_login',
  107. new Expression("CASE user_type
  108. WHEN 1 THEN '管理员'
  109. WHEN 2 THEN '分销商'
  110. WHEN 3 THEN '客户'
  111. WHEN 4 THEN 'CS管理员'
  112. ELSE '-'
  113. END
  114. as user_type_name
  115. "),
  116. new Expression("CASE resources_type
  117. WHEN 1 THEN '产品'
  118. WHEN 2 THEN '订单'
  119. ELSE '-'
  120. END
  121. as resources_type_name
  122. ")
  123. ];
  124. $offset = ($param['current_page'] - 1) * $param['page_size'];
  125. $result = self::find()->select($select)
  126. ->where($where)
  127. ->orderBy('create_time DESC')
  128. ->offset($offset)
  129. ->limit($param['page_size'])
  130. ->asArray()
  131. ->all();
  132. return $result;
  133. }
  134. }
  135. }