| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- <?php
- namespace addons\Material\backend\controllers;
- use addons\Material\common\enums\MaterialEnum;
- use common\components\sensitivewords\SensitiveWords;
- use addons\Material\common\models\Material;
- use addons\Material\common\models\MaterialCate;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- use common\controllers\AddonsController;
- use yii\db\Exception;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Material\backend\controllers
- */
- class DefaultController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isGet) {
- $post = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($post,[
- [['id','level','cate_id', 'second_cate_id'], 'integer'],
- [['id','keyword','check_status','date_end','date_start','mobile','user_id','user_name','describe'], 'safe'],
- [['limit'],'default','value' => '15'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where = [];
- // 根据搜索手机号查询用户id
- if (!empty($post['mobile'])) {
- $user_ids = User::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'mobile', $post['mobile'] . '%', false])->asArray()->column();
- if (empty($user_ids)) $this->success('查无此用户');
- $where[] = ['in', 'user_id', $user_ids];
- }
- // 根据搜索会员昵称查询用户id
- if (!empty($post['user_name'])) {
- $user_ids = User::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'nickname', $post['user_name'] . '%', false])->asArray()->column();
- $where[] = ['or',['in', 'user_id', $user_ids],['like','user_name',$post['user_name']]];
- }
- if($post['keyword']) $where[] = ['=', 'user_name', $post['keyword']];
- if(!empty($post['describe'])) $where[] = ['like', 'describe', trim($post['describe'])];
- if($post['user_id']) $where[] = ['=', 'user_id', $post['user_id']];
- if($post['cate_id']) $where[] = ['=', 'cate_id', $post['cate_id']];
- if($post['second_cate_id']) $where[] = ['=', 'second_cate_id', $post['second_cate_id']];
- if($post['date_start']&&$post['date_end']) $where[] = ['between', 'created_at', strtotime($post['date_start']),strtotime($post['date_end'])];
- $where[] = ['=', 'mall_id', $this->mall_id];
- if(isset($post['check_status']) && in_array($post['check_status'],[StatusEnum::ENABLED,StatusEnum::DISABLED,'2'])) {
- $where[] = ['=', 'check_status', $post['check_status']];
- } else {
- $where[] = ['=', 'check_status', StatusEnum::ENABLED];
- }
- $where[] = ['>=','status',StatusEnum::DISABLED];
- $order = 'sort,created_at desc';
- $params = array('where' => $where, 'order'=>$order, 'limit' => $post['limit'],'with' => ['cate','goods','user','secondCate']);
- $list = Material::listPage($params, false, true);
- // 获取分类
- $list['cates'] = MaterialCate::getList($this->mall_id);
- $this->success('获取成功', $list);
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- public function actionList()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isGet) {
- $post = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($post,[
- [['id','level'], 'integer'],
- [['id','keyword','check_status','date_end','date_start','mobile','user_id','user_name'], 'safe'],
- [['limit'],'default','value' => '15'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where = [];
- // 根据搜索手机号查询用户id
- if (!empty($post['mobile'])) {
- $user_ids = User::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'mobile', $post['mobile'] . '%', false])->asArray()->column();
- if (empty($user_ids)) $this->success('查无此用户');
- $where[] = ['in', 'user_id', $user_ids];
- }
- // 根据搜索会员昵称查询用户id
- if (!empty($post['user_name'])) {
- $user_ids = User::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'nickname', $post['user_name'] . '%', false])->asArray()->column();
- $where[] = ['or',['in', 'user_id', $user_ids],['like','user_name',$post['user_name']]];
- }
- if($post['keyword']) $where[] = ['=', 'user_name', $post['keyword']];
- if($post['user_id']) $where[] = ['=', 'user_id', $post['user_id']];
- if($post['date_start']&&$post['date_end']) $where[] = ['between', 'created_at', strtotime($post['date_start']),strtotime($post['date_end'])];
- $where[] = ['=', 'mall_id', $this->mall_id];
- if(isset($post['check_status']) && in_array($post['check_status'],[StatusEnum::ENABLED,StatusEnum::DISABLED,'2'])) {
- $where[] = ['=', 'check_status', $post['check_status']];
- } else {
- $where[] = ['=', 'check_status', StatusEnum::ENABLED];
- }
- $where[] = ['>=','status',StatusEnum::DISABLED];
- $order = 'sort,created_at desc';
- $params = array('where' => $where, 'order'=>$order, 'limit' => $post['limit'],'with' => ['cate','goods','user','secondCate']);
- $list = Material::listPage($params, false, true);
- $this->success('获取成功', $list);
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- /**
- * 编辑
- * @Author: ltm
- * @DateTime: 2021/12/13 0021 18:29
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionEdit()
- {
- try {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- // 提交等级内容
- if ($request->isGet) {
- $params = Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($params, [
- [['id'], 'safe'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $detail = Material::getOne([['id' => $params['id']]], 1, ['goods']);
- if(!empty($detail['goods_id'])) $detail['goods_id'] = json_decode($detail['goods_id']);
- $detail && $detail['pic_url'] = !empty($detail['pic_url']) ? json_decode($detail['pic_url']) : [];
- return $this->success('操作成功', compact('detail'));
- }
- //提交等级内容
- if ($request->isPost) {
- $params = Yii::$app->request->post();
- $is_type = $params['type'] == 1;
- if($params['type'] == 1){ //禁用操作和删除操作和审核操作
- $res = Yii::$app->services->validate->validate($params, [
- [['id','status','check_status','remark'],'safe']
- ]);
- }else{
- $res = Yii::$app->services->validate->validate($params, [
- [['cate_id','describe','download_type'], 'required'],
- [['second_cate_id','pic_url','id','virtual_download_num','goods_id','thumb_url','status','video_url'],'safe']
- ]);
- }
- $params = Material::exceptNullVal($params);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['mall_id'] = $this->mall_id;
- if($params['id']) $params['updated_at'] = time();else $params['create_at'] = time();//更新时间
- //删除操作
- if(isset($params['status']) && in_array($params['status'],[StatusEnum::DISABLED,StatusEnum::ENABLED,StatusEnum::DELETE])) {
- $params['status'] = $params['status'];
- }
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['>', 'status', StatusEnum::DISABLED];
- //审核操作
- if($params['check_status']) {
- $params['check_status'] = $params['check_status'];
- $params['status'] = StatusEnum::ENABLED;
- }
- if($params['check_status']) $params['check_at'] = time();
- if(!empty($params['pic_url'])) $params['pic_url'] = json_encode($params['pic_url']);
- //验证标题内容是否有敏感词汇
- $config = \Yii::$app->services->setting->addons->get($this->mall_id, MaterialEnum::ADDONS_NAME, 'basic');
- if ($config['is_filter'] == '1') {
- $common = new SensitiveWords();
- $textStatus = $common->getTextStatus($params['describe'],$this->mall_id);
- if ($textStatus['status'] != 0) {
- return $this->error('敏感词过滤报错:'.$textStatus['msg']);
- }
- };
- if (!$is_type) {
- $params['user_name'] = $this->mall['name'] ?? ''; // 默认获取商家名称
- if (!empty($config['user_name'])) {
- // 独立配置了获取配置名称
- $params['user_name'] = $config['user_name'];
- }
- $mallLogo = Yii::$app->services->setting->mall->get($this->mall_id, 'basic.logo');
- if(empty($mallLogo)) $mallLogo = \Yii::$app->request->hostInfo.'/resources/img/admin/mall-logo.png';
- $params['user_avatar_url'] = $mallLogo ?? '';
- if (!empty($config['user_avatar_url'])) {
- $params['user_avatar_url'] = $config['user_avatar_url'];
- }
- }
- $res = Material::setData($params);
- if ($res === false) throw new Exception(MaterialCate::getStaticCodeError()['error']);
- return $this->success('操作成功');
- }
- }
- } catch (\Exception $e) {
- return $this->error($e->getMessage(), []);
- }
- return $this->render($this->action->id);
- }
- /**
- * 审核
- * @Author: ltm
- * @DateTime: 2021/12/13 0021 18:29
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionCheck(){
- return $this->render($this->action->id);
- }
- /**
- * 获取分类
- *
- * @return mixed
- */
- public function actionGetCateList()
- {
- $params['where'][] = ['=', 'mall_id', $this->mall_id];
- $params['where'][] = ['>=', 'status', StatusEnum::DISABLED];
- $params['where'][] = ['=', 'parent_id', 0];
- $params['with'] = ['children' => function ($query) {
- $query->select('id, id as value, name as label,parent_id');
- }];
- $params['select'] = 'id, id as value, name as label';
- $materil_cate_list = MaterialCate::lists($params, 1);
- return $this->success('ok', $materil_cate_list);
- }
- }
|