MaterialBrowseController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace addons\BusinessCard\backend\controllers;
  3. use addons\BusinessCard\common\models\BusinessCardMaterials;
  4. use addons\BusinessCard\common\models\BusinessCardMaterialsBrowse;
  5. use addons\BusinessCard\common\models\BusinessCardMaterialsBrowseLog;
  6. use addons\BusinessCard\common\models\BusinessCardUser;
  7. use common\enums\StatusEnum;
  8. use Yii;
  9. use common\models\user\User;
  10. class MaterialBrowseController extends BaseController
  11. {
  12. public $enableCsrfValidation = false;
  13. public function actionIndex()
  14. {
  15. if (Yii::$app->request->isAjax && Yii::$app->request->isPost) {
  16. $post = Yii::$app->request->post();
  17. $where = [['=', 'mall_id', $this->mall_id], ['<>', 'status' , StatusEnum::DELETE]];
  18. if (isset($post['user_id']) && $post['user_id']) {
  19. $where[] = ['=', 'user_id', $post['user_id']];
  20. }
  21. if (isset($post['nickname']) && $post['nickname']) {
  22. $user_ids = User::find()
  23. ->orWhere(['like', 'nickname', "%" . $post['nickname'] . "%", false])
  24. ->orWhere(['like', 'mobile', "%" . $post['nickname'] . "%", false])
  25. ->select('id')
  26. ->asArray()
  27. ->column();
  28. $where[] = ['in', 'user_id', $user_ids];
  29. }
  30. if (isset($post['recent_time']) && $post['recent_time']) {
  31. list ($start, $end) = $post['recent_time'];
  32. $where[] = ['>=', 'recent_time', strtotime($start)];
  33. $where[] = ['<=', 'recent_time', strtotime($end)];
  34. }
  35. $params = [
  36. 'limit' => 10,
  37. 'with' => 'user',
  38. 'where' => $where,
  39. 'order' => 'id desc'
  40. ];
  41. $list = BusinessCardMaterialsBrowse::listPage($params);
  42. return $this->success('操作成功', $list);
  43. } else {
  44. return $this->render('index');
  45. }
  46. }
  47. /**
  48. * 观看记录
  49. */
  50. public function actionLog() {
  51. if (Yii::$app->request->isAjax && Yii::$app->request->isPost) {
  52. $post = Yii::$app->request->post();
  53. $where = [['=', 'mall_id', $this->mall_id], ['<>', 'status' , StatusEnum::DELETE]];
  54. if (isset($post['user_id']) && $post['user_id']) {
  55. $where[] = ['=', 'user_id', $post['user_id']];
  56. }
  57. if (isset($post['material_id']) && $post['material_id']) {
  58. $where[] = ['=', 'material_id', $post['material_id']];
  59. }
  60. if (isset($post['title']) && $post['title']) {
  61. $material_ids = BusinessCardMaterials::find()
  62. ->orWhere(['like', 'title', "%" . $post['title'] . "%", false])
  63. ->select('id')
  64. ->asArray()
  65. ->column();
  66. $where[] = ['in', 'material_id', $material_ids];
  67. }
  68. if (isset($post['parent']) && $post['parent']) {
  69. $parent_ids = User::find()
  70. ->orWhere(['like', 'nickname', "%" . $post['parent'] . "%", false])
  71. ->orWhere(['like', 'mobile', "%" . $post['parent'] . "%", false])
  72. ->select('id')
  73. ->asArray()
  74. ->column();
  75. $user_ids = BusinessCardUser::find()
  76. ->where(['in', 'parent_id', $parent_ids])
  77. ->select('user_id')
  78. ->asArray()
  79. ->column();
  80. $where[] = ['in', 'user_id', $user_ids];
  81. }
  82. if (isset($post['nickname']) && $post['nickname']) {
  83. $user_ids = User::find()
  84. ->orWhere(['like', 'nickname', "%" . $post['nickname'] . "%", false])
  85. ->orWhere(['like', 'mobile', "%" . $post['nickname'] . "%", false])
  86. ->select('id')
  87. ->asArray()
  88. ->column();
  89. $where[] = ['in', 'user_id', $user_ids];
  90. }
  91. if (isset($post['created_at']) && $post['created_at']) {
  92. list ($start, $end) = $post['created_at'];
  93. $where[] = ['>=', 'created_at', strtotime($start)];
  94. $where[] = ['<=', 'created_at', strtotime($end)];
  95. }
  96. $params = [
  97. 'limit' => 10,
  98. 'with' => ['user', 'material', 'shareuser'],
  99. 'where' => $where,
  100. 'order' => 'id desc'
  101. ];
  102. $list = BusinessCardMaterialsBrowseLog::listPage($params);
  103. $list['list'] = is_array($list['list']) ? $list['list'] : [];
  104. // foreach ($list['list'] as $index => $item) {
  105. //
  106. // $list['list'][$index] = $item;
  107. // }
  108. return $this->success('操作成功', $list);
  109. } else {
  110. return $this->render('log');
  111. }
  112. }
  113. }