| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- namespace addons\BusinessCard\backend\controllers;
- use addons\BusinessCard\common\enums\CardEnums;
- use addons\BusinessCard\common\models\BusinessCardMaterials;
- use addons\BusinessCard\common\models\BusinessCardMaterialsCate;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- class MaterialController extends BaseController
- {
- public $enableCsrfValidation = false;
- public function actionIndex()
- {
- if (Yii::$app->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'));
- }
- }
- }
|