request->isAjax && Yii::$app->request->isGet) { $get = Yii::$app->request->get(); $where = [['=', 'mall_id', $this->mall_id], ['<>', 'status' , StatusEnum::DELETE]]; if (isset($get['id']) && $get['id']) { $where[] = ['=', 'id', $get['id']]; } if (isset($get['user_id']) && $get['user_id']) { $where[] = ['=', 'user_id', $get['user_id']]; } if (isset($get['ext_type']) && $get['ext_type']) { $where[] = ['=', 'ext_type', $get['ext_type']]; } if (isset($get['cate_id']) && $get['cate_id']) { $where[] = ['=', 'cate_id', $get['cate_id']]; } if (isset($get['title']) && $get['title']) { $where[] = ['like', 'title', '%' . trim($get['title']) . '%', false]; } // 昵称、手机号 if (isset($get['nickname']) && $get['nickname']) { $user_ids = User::find() ->orWhere(['like', 'nickname', "%" . $get['nickname'] . "%", false]) ->orWhere(['like', 'mobile', "%" . $get['nickname'] . "%", false]) ->select('id') ->asArray() ->column(); $where[] = ['in', 'user_id', $user_ids]; } $params = [ 'limit' => 10, 'where' => $where, 'with' => ['cate', 'user'], 'order' => 'created_at desc' ]; $list = BusinessCardMaterials::listPage($params); $list['material_ext_type'] = CardEnums::getMaterialExtType(); return $this->success('操作成功', $list); } else { return $this->render('index'); } } // 处理 public function actionHandle() { if (Yii::$app->request->isAjax && Yii::$app->request->isPost) { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['id', 'status', 'is_show'], 'integer'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $params = array_filter($params, function ($val) { return $val != null; }); $params['mall_id'] = $this->mall_id; $res = BusinessCardMaterials::setData($params); if ($res == false) return $this->error("操作失败: " . BusinessCardMaterials::getStaticError()); return $this->success("操作成功"); } } // 获取素材分类 public function actionCateList() { $list = BusinessCardMaterialsCate::find() ->select(['id', 'name']) ->andWhere(['<>', 'status', StatusEnum::DELETE]) ->andWhere(['=', 'mall_id', $this->mall_id]) ->asArray() ->all(); return $this->success('操作成功', $list); } // 编辑 public function actionEdit() { if (Yii::$app->request->isAjax && Yii::$app->request->isPost) { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['id', 'user_id', 'is_show', 'cate_id', 'status'], 'integer'], [['title', 'intro', 'ext_type', 'share_title', 'share_desc', 'cover_img', 'material_link'], 'string'], [['material_cont'], 'safe'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $params = array_filter($params, function ($val) { return $val != null; }); $params['mall_id'] = $this->mall_id; $params['status'] = isset($params['status']) ? $params['status'] : StatusEnum::ENABLED; $res = BusinessCardMaterials::setData($params); if ($res == false) return $this->error("操作失败: " . BusinessCardMaterials::getStaticError()); return $this->success('操作成功', []); } else { return $this->render('edit'); } } // 获取视频格式 public function actionExtType() { $list = CardEnums::getMaterialExtType(); return $this->success('操作成功', $list); } public function actionInfo() { if (Yii::$app->request->isAjax && Yii::$app->request->isGet) { $id = Yii::$app->request->get('id'); $info = BusinessCardMaterials::getOne([ ['=', 'id', $id], ['=', 'mall_id', $this->mall_id] ], true); $is_null = $info ? 0 : 1; return $this->success('操作成功', compact('info', 'is_null')); } } }