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); } }