| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace addons\BusinessCard\backend\controllers;
- use addons\BusinessCard\common\models\BusinessCardMaterials;
- use addons\BusinessCard\common\models\BusinessCardMaterialsBrowse;
- use addons\BusinessCard\common\models\BusinessCardMaterialsBrowseLog;
- use addons\BusinessCard\common\models\BusinessCardUser;
- use common\enums\StatusEnum;
- use Yii;
- use common\models\user\User;
- class MaterialBrowseController extends BaseController
- {
- public $enableCsrfValidation = false;
- public function actionIndex()
- {
- if (Yii::$app->request->isAjax && Yii::$app->request->isPost) {
- $post = Yii::$app->request->post();
- $where = [['=', 'mall_id', $this->mall_id], ['<>', 'status' , StatusEnum::DELETE]];
- if (isset($post['user_id']) && $post['user_id']) {
- $where[] = ['=', 'user_id', $post['user_id']];
- }
- if (isset($post['nickname']) && $post['nickname']) {
- $user_ids = User::find()
- ->orWhere(['like', 'nickname', "%" . $post['nickname'] . "%", false])
- ->orWhere(['like', 'mobile', "%" . $post['nickname'] . "%", false])
- ->select('id')
- ->asArray()
- ->column();
- $where[] = ['in', 'user_id', $user_ids];
- }
- if (isset($post['recent_time']) && $post['recent_time']) {
- list ($start, $end) = $post['recent_time'];
- $where[] = ['>=', 'recent_time', strtotime($start)];
- $where[] = ['<=', 'recent_time', strtotime($end)];
- }
- $params = [
- 'limit' => 10,
- 'with' => 'user',
- 'where' => $where,
- 'order' => 'id desc'
- ];
- $list = BusinessCardMaterialsBrowse::listPage($params);
- return $this->success('操作成功', $list);
- } else {
- return $this->render('index');
- }
- }
- /**
- * 观看记录
- */
- public function actionLog() {
- if (Yii::$app->request->isAjax && Yii::$app->request->isPost) {
- $post = Yii::$app->request->post();
- $where = [['=', 'mall_id', $this->mall_id], ['<>', 'status' , StatusEnum::DELETE]];
- if (isset($post['user_id']) && $post['user_id']) {
- $where[] = ['=', 'user_id', $post['user_id']];
- }
- if (isset($post['material_id']) && $post['material_id']) {
- $where[] = ['=', 'material_id', $post['material_id']];
- }
- if (isset($post['title']) && $post['title']) {
- $material_ids = BusinessCardMaterials::find()
- ->orWhere(['like', 'title', "%" . $post['title'] . "%", false])
- ->select('id')
- ->asArray()
- ->column();
- $where[] = ['in', 'material_id', $material_ids];
- }
- if (isset($post['parent']) && $post['parent']) {
- $parent_ids = User::find()
- ->orWhere(['like', 'nickname', "%" . $post['parent'] . "%", false])
- ->orWhere(['like', 'mobile', "%" . $post['parent'] . "%", false])
- ->select('id')
- ->asArray()
- ->column();
- $user_ids = BusinessCardUser::find()
- ->where(['in', 'parent_id', $parent_ids])
- ->select('user_id')
- ->asArray()
- ->column();
- $where[] = ['in', 'user_id', $user_ids];
- }
- if (isset($post['nickname']) && $post['nickname']) {
- $user_ids = User::find()
- ->orWhere(['like', 'nickname', "%" . $post['nickname'] . "%", false])
- ->orWhere(['like', 'mobile', "%" . $post['nickname'] . "%", false])
- ->select('id')
- ->asArray()
- ->column();
- $where[] = ['in', 'user_id', $user_ids];
- }
- if (isset($post['created_at']) && $post['created_at']) {
- list ($start, $end) = $post['created_at'];
- $where[] = ['>=', 'created_at', strtotime($start)];
- $where[] = ['<=', 'created_at', strtotime($end)];
- }
- $params = [
- 'limit' => 10,
- 'with' => ['user', 'material', 'shareuser'],
- 'where' => $where,
- 'order' => 'id desc'
- ];
- $list = BusinessCardMaterialsBrowseLog::listPage($params);
- $list['list'] = is_array($list['list']) ? $list['list'] : [];
- // foreach ($list['list'] as $index => $item) {
- //
- // $list['list'][$index] = $item;
- // }
- return $this->success('操作成功', $list);
- } else {
- return $this->render('log');
- }
- }
- }
|