request; if ($request->isAjax) { if ($request->isGet) { $get = Yii::$app->request->get(); // 检查提交的参数 $res = Yii::$app->services->validate->validate($get,[ [['id','keyword'], 'safe'], [['limit'],'default','value' => '15'], ]); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); # 搜索条件 $where = []; // if($get['keyword']) $where[] = ['like', 'a.title', $get['keyword']]; // $where[] = ['>=', 'a.status', StatusEnum::DISABLED]; $where[] = ['>=', 'b.status', StatusEnum::DISABLED]; $where[] = ['=', 'mall_id', $this->mall_id]; # 排序 $order = 'b.created_at desc'; # 显示字段 $select = "b.smart_form_template_id,b.id,b.mall_id,b.diy_page_id"; $params = array('where' => $where, 'order'=>$order, 'select'=>$select, 'limit' => $get['limit'],'alias'=>'b' , /*'join'=>[ ['INNER JOIN', AddonsSmartFormTemplate::tableName() . ' a', "b.smart_form_template_id = a.id AND b.mall_id = a.mall_id"], ['INNER JOIN', DiyPage::tableName() . ' c', "c.id = b.diy_page_id"] ]*/ ); # 分页返回 // $list = AddonsSmartFormTemplate::listPage($params, false, true); $list = AddonsSmartFormDecorationForm::listPage($params, false, true); if(!empty($list['list'])){ foreach ($list['list'] as $k => $v) { $formTemplate = AddonsSmartFormTemplate::getOne([['id' => $v['smart_form_template_id'],'mall_id' => $v['mall_id'],'status' => StatusEnum::ENABLED]], true); $list['list'][$k]['title'] = $formTemplate['title']; $list['list'][$k]['header'] = $formTemplate['header']; $list['list'][$k]['expire_time'] = $formTemplate['expire_time']; $list['list'][$k]['status'] = $formTemplate['status']; $list['list'][$k]['created_at'] = $formTemplate['created_at']; $diy_page = DiyPage::getOne([['id'=>$v['diy_page_id']]], true); $list['list'][$k]['diy_page_title'] = $diy_page['title']; } } $this->success('获取成功', $list); } } else { return $this->render($this->action->id,[ ]); } } catch (\Exception $e) { return $this->error($e->getMessage(), []); } } /** * @method actionInfo * 详情 * @author zqh * @datetime 2022-04-27T16:30:05+0800 * @return [type] [description] */ public function actionInfo() { /*$s = AddonsSmartFormTemplateUserForm::exportHandle(['download_id'=>7]); var_dump($s);exit;*/ try { $request = Yii::$app->request; if ($request->isAjax) { if ($request->isGet) { $get = Yii::$app->request->get(); // 检查提交的参数 $res = Yii::$app->services->validate->validate($get,[ [['diy_page_id','template_id','keyword','date_start','date_end'], 'safe'], [['limit'],'default','value' => '15'], ]); if(!$get['template_id']){ return $this->error('模板不存在', []); } if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); # 获取统计数据 $where1['smart_form_template_id'] = $get['template_id']; $where1['diy_page_id'] = $get['diy_page_id']; $where1['month_day'] = date('Y-m-d'); $where1['behavior_type'] = 1; # 今日填写次数-当天填写次数,包含同一个ID用户填写次数 $today_filling_times = AddonsSmartFormTemplateUserBehavior::find()->where($where1)->count('id'); # 今日访问人次-当天访问次数,只访问未填写 $where2['smart_form_template_id'] = $get['template_id']; $where2['diy_page_id'] = $get['diy_page_id']; $where2['month_day'] = date('Y-m-d'); $where2['behavior_type'] = 0; $where2['is_submit'] = 0; $today_view_times = AddonsSmartFormTemplateUserBehavior::find()->where($where2)->count('id'); # 今日填写人数-当天填写人数,一个ID用户统计一次 $where3['smart_form_template_id'] = $get['template_id']; $where3['diy_page_id'] = $get['diy_page_id']; $where3['month_day'] = date('Y-m-d'); $where3['behavior_type'] = 1; $today_filling_people = AddonsSmartFormTemplateUserBehavior::find() ->select('user_id,month_day') ->where($where3) ->groupBy('user_id,month_day') ->count('user_id'); // print_r($today_filling_people);exit; # 总人数/填写人数x100%=填写率 $today_rate = (string)($today_filling_people > 0 ? ($today_view_times/$today_filling_people) : 0) . '%'; # 获取统计数据 $whereAll1['smart_form_template_id'] = $get['template_id']; $whereAll1['diy_page_id'] = $get['diy_page_id']; $whereAll1['behavior_type'] = 1; # 总填写次数- 填写次数,包含同一个ID用户填写次数 $all_filling_times = AddonsSmartFormTemplateUserBehavior::find()->where($whereAll1)->count('id'); # 总访问人次- 访问次数,只访问未填写 $whereAll2['smart_form_template_id'] = $get['template_id']; $whereAll2['diy_page_id'] = $get['diy_page_id']; $whereAll2['behavior_type'] = 0; $whereAll2['is_submit'] = 0; $all_view_times = AddonsSmartFormTemplateUserBehavior::find()->where($whereAll2)->count('id'); # 总填写人数- 填写人数,一个ID用户统计一次 $whereAll3['smart_form_template_id'] = $get['template_id']; $whereAll3['diy_page_id'] = $get['diy_page_id']; $whereAll3['behavior_type'] = 1; $all_filling_people = AddonsSmartFormTemplateUserBehavior::find() ->select('user_id') ->where($whereAll3) ->groupBy('user_id') ->count('user_id'); // print_r($all_filling_people);exit; $all_rate = (string)($all_filling_people > 0 ? ($all_view_times/$all_filling_people) : 0) . '%'; $statistics['filling_times'] = $all_filling_times; $statistics['view_times'] = $all_view_times; $statistics['filling_people'] = $all_filling_people; $statistics['all_rate'] = $all_rate; $statistics['today_filling_times'] = $today_filling_times; $statistics['today_view_times'] = $today_view_times; $statistics['today_filling_people'] = $today_filling_people; $statistics['today_rate'] = $today_rate; $statistics['all_rate'] = $all_rate; # 获取模板字段 $field = " id,concat('a',`id`) type,smart_form_components_code,title label"; $header = AddonsSmartFormTemplateColumn::find()->select($field) ->orderBy('sort asc') ->where(['smart_form_template_id'=>$get['template_id']])->asArray()->all(); # 搜索条件 $where = []; $where[] = ['=', 'a.smart_form_template_id', $get['template_id']]; if($get['date_start'] && $get['date_end']){ $where[] = ['between', 'a.created_at', strtotime($get['date_start']),strtotime($get['date_end'])]; } // if($get['keyword']) $where[] = ['like', 'b.nickname', $get['keyword']]; if($get['keyword']){ $user_ids = User::find() ->where(['and', ['like', 'nickname', $get['keyword']]]) ->select('id') ->asArray() ->all(); $where[] = ['in', 'a.user_id', array_column($user_ids, 'id')]; } $where[] = ['>=', 'a.status', StatusEnum::DISABLED]; $where[] = ['=', 'a.diy_page_id', $get['diy_page_id']]; # 排序 $order = 'a.created_at desc'; # 显示字段 $select = "a.id,a.user_id,a.smart_form_template_column_id,a.col_value,a.source,a.created_at,a.updated_at";//,c.smart_form_components_id,c.smart_form_components_code,c.col_value // $with = [ // 'user' // ,'formInfo' => function($query){ // $query->alias('a')->select('a.*,b.option')->join('inner join',AddonsSmartFormTemplateColumn::tableName() . 'b', "b.id = a.smart_form_components_id"); // } // ]; // $params = array('where' => $where, 'order'=>$order, 'select'=>$select, 'limit' => 10, 'with' => $with,'alias'=>'a','join'=>[ // ['INNER JOIN', User::tableName() . ' b', "b.id = a.user_id"] // ]); $params = array('where' => $where, 'order'=>$order, 'select'=>$select, 'limit' => 10, 'alias'=>'a'); # 分页返回 $list = AddonsSmartFormTemplateUserForm::listPage($params, false); foreach ($list['list'] as $k => $v) { $users = User::findOne($v["user_id"]); $nickname = "普通用户"; if(!empty($users)){ $nickname = $users->nickname; $users = ArrayHelper::toArray($users); $list['list'][$k]["user"] = $users; } $list['list'][$k]["nickname"] = $nickname; $v['formInfo'] = AddonsSmartFormTemplateUserFormInfo::find()->where(["smart_form_template_user_form_id" => $v["id"]])->asArray()->all(); if(!$v['formInfo']){ $v['formInfo'] = []; } $template_columns = AddonsSmartFormTemplateColumn::find() ->where(['and',['in', 'id', array_column($v['formInfo'], 'smart_form_components_id')]]) ->select('id, option') ->asArray() ->all(); $template_columns = array_column($template_columns, 'option', 'id'); foreach ($v['formInfo'] as $k1 => $v1) { $v1['option'] = isset($template_columns[$v1['smart_form_components_id']]) ? $template_columns[$v1['smart_form_components_id']] : []; switch ($v1['smart_form_components_code']) { case 'id-card': case 'single-link-text': // $col_value = json_decode($v1['col_value'],true); $v1['col_value'] = (string)$v1['col_value'] . ' ' ; break; case 'upload-photo': // $col_value = json_decode($v1['col_value'],true); $v1['col_value'] = explode(',',$v1['col_value']); break; case 'city-chose': # 省市区 // $regin = Region::getOne([['id' => [2,3,4]]], true,[],false,'name'); $regin = Region::find()->select('name')->where(['id' => explode(',',$v1['col_value'])])->asArray()->all(); $regin = implode(" ",array_column($regin,'name'));//Region::getTopStr($v1['col_value']); $v1['col_value'] = $regin; break; case 'checked-tool': # 多选 $col_value = explode(',',$v1['col_value']); if(strpos($v1['option'],SmartFormEnum::FIRST_CUTTER) !== false){ $col_option = explode(SmartFormEnum::FIRST_CUTTER,$v1['option']); }else{ $col_option = (array)$v1['option']; } $new_col_option = []; if(is_array($col_value)){ foreach ($col_value as $ok => $ov) { if($col_option[$ov]){ $new_col_option[] = $col_option[$ov]; } } }else{ $new_col_option[0] = $col_option[0]; } $v1['col_value'] = implode(',',$new_col_option); break; case 'radio-tool': # 单选 // $col_value = json_decode($v1['col_value'],true); $col_value = explode(',',$v1['col_value']); if(strpos($v1['option'],SmartFormEnum::FIRST_CUTTER) !== false){ $col_option = explode(SmartFormEnum::FIRST_CUTTER,$v1['option']); }else{ $col_option = (array)$v1['option']; } $new_col_option = []; if(is_array($col_value)){ foreach ($col_value as $ok => $ov) { if($col_option[$ov]){ $new_col_option[] = $col_option[$ov]; } } }else{ $new_col_option[0] = $col_option[0]; } $v1['col_value'] = implode(',',$new_col_option); break; case 'drow-box': # 下拉 // $col_value = json_decode($v1['col_value'],true); $col_value = explode(',',$v1['col_value']); if(strpos($v1['option'],SmartFormEnum::FIRST_CUTTER) !== false){ $col_option = explode(SmartFormEnum::FIRST_CUTTER,$v1['option']); }else{ $col_option = (array)$v1['option']; } $new_col_option = []; if(is_array($col_value)){ foreach ($col_value as $ok => $ov) { if($col_option[$ov]){ $new_col_option[] = $col_option[$ov]; } } }else{ $new_col_option[0] = $col_option[0]; } $v1['col_value'] = implode(',',$new_col_option); break; } $list['list'][$k]['a'.$v1['smart_form_components_id']] = $v1['col_value']; } } $export_list = AddonsSmartFormTemplateUserForm::exportFieldsList($get['template_id']); $this->success('获取成功', compact('statistics','header','list','export_list')); } if ($request->post('flag') == 'EXPORT') { $post = $request->post(); $post['mall_id'] = $this->mall_id; $post['template_id'] = $post['template_id']; $post['fields'] = AddonsSmartFormTemplateUserForm::exportFieldsList($post['template_id']); $info = AddonsSmartFormTemplate::getOne([['id' => $post['template_id']]], true); $filename = $info['title'] .'-' . date('YmdHis').'_'.rand(10000,99999); $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_AGENT,AddonsSmartFormTemplateUserForm::class,'exportHandle',$post); if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError()); return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!'); } } else { return $this->render($this->action->id,[ ]); } } catch (\Exception $e) { return $this->error($e->getMessage(), []); } } /** * @method editIndex * 编辑 * @author zqh * @datetime 2022-04-27T16:30:05+0800 * @return [type] [description] */ public function actionEdit() { return $this->render('edit',[ ]); } /** * @method share * 分享 * @author zqh * @datetime 2022-04-27T16:32:09+0800 * @return [type] [description] */ public function actionShare() { try { $request = Yii::$app->request; if ($request->isAjax) { if ($request->isPost) { $post = Yii::$app->request->post(); if(!$post['id']){ return $this->error('模板不存在', []); } # 获取信息 $info = AddonsSmartFormDecorationForm::findOne(['status' => StatusEnum::ENABLED,'id'=>$post['id']]); $h5_url = Yii::$app->services->setting->get('system.h5_url') ?? ''; $sign = $this->mall['mall_sign']; $diy_page = DiyPage::getOne([['id'=>$info->diy_page_id]], true); $share_url = ''; if ($diy_page['is_home_page'] == 1) { $share_url = $h5_url .'/#'. DiyEnum::HOME_PAGE_PATH . '?sign=' . $sign. '&id=' . $diy_page['id']; } elseif ($diy_page['template'] == DiyEnum::USER_CENTER) { $share_url = $h5_url .'/#'. DiyEnum::USER_CENTER_PATH . '?sign=' . $sign. '&id=' . $diy_page['id']; } else { $share_url = $h5_url .'/#'. DiyEnum::CUSTOM_PAGE_PATH . '?sign=' . $sign . '&id=' . $diy_page['id']; } return $this->success('操作成功',$share_url); } } } catch (\Exception $e) { return $this->error($e->getMessage(), []); } } /** * @method actionDelete * 删除 * @author zqh * @datetime 2022-04-27T16:35:31+0800 * @return [type] [description] */ public function actionDelete() { try { $request = Yii::$app->request; if ($request->isAjax) { if ($request->isPost) { $params = $request->post(); $res = Yii::$app->services->validate->validate($params, [ [['id'], 'required'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $status = AddonsSmartFormDecorationForm::del($params); if(!$status){ Yii::error(AddonsSmartFormDecorationForm::getStaticError()); return $this->error(AddonsSmartFormDecorationForm::getStaticError()); } return $this->success('操作成功'); /* # 获取信息 $info = AddonsSmartFormDecorationForm::findOne(['status' => StatusEnum::ENABLED,'id'=>$params['id']]); if(!$info){ return $this->success('无需删除', []); } // $trans = Yii::$app->db->beginTransaction(); # 删除装修 // $diyInfo = DiyPage::getOne([['id'=>$info['diy_page_id']]], true); $diyInfo = DiyPage::findOne(['id' => $info['diy_page_id']]); if($diyInfo['content']){ $content = json_decode($diyInfo['content'],true); $has = false; foreach ($content as $k => $v) { if($v['funcListItem']['type']=='smart-form'){ unset($content[$k]); $has = true; } } if($has){ $diyInfo['updated_at'] = time(); $diyInfo['content'] = json_encode($content,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); $s1 = $diyInfo->save(); }else{ $s1 = true; } }else{ $s1 = true; } if(!$s1){ return $this->error('移除装修表单失败'); } $info->status = StatusEnum::DELETE; $info->updated_at = time(); $s2 = $info->save(); if(!$s2){ return $this->error('移除表单失败'); } return $this->success('操作成功!'); */ } } } catch (\Exception $e) { return $this->error($e->getMessage(), []); } } }