AllformController.class.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author cy 2021-05-21
  12. * @desc 万能表单管理
  13. *
  14. */
  15. namespace Seller\Controller;
  16. class AllformController extends CommonController{
  17. protected $menu;
  18. protected function _initialize(){
  19. parent::_initialize();
  20. $menu = array(
  21. 'title' => '万能表单',
  22. 'subtitle' => '万能表单',
  23. 'route' => 'allform/index',
  24. 'items' => array(
  25. array('title' => '表单列表', 'route' => 'allform/index'),
  26. array('title' => '表单设置', 'route' => 'allform/config'),
  27. )
  28. );
  29. $perm_url = strtolower(CONTROLLER_NAME) .'/'. strtolower(ACTION_NAME);
  30. $this->assign('perm_url', $perm_url );
  31. //组件权限方法===begin
  32. if(SELLERUID != 1)
  33. {
  34. $seller_info = M('seller')->field('s_role_id')->where( array('s_id' => SELLERUID ) )->find();
  35. $perm_role = M('lionfish_comshop_perm_role')->where( array('id' => $seller_info['s_role_id']) )->find();
  36. $perms_str = $perm_role['perms2'];
  37. $items = [];
  38. $can_use_routearr = [];
  39. foreach( $menu['items'] as $val )
  40. {
  41. $val_route = str_replace('/','.', $val['route']);
  42. if( strpos($perms_str, '.'.$val_route) !== false )
  43. {
  44. $items[] = $val;
  45. $can_use_routearr[] = strtolower($val['route']);
  46. }
  47. }
  48. $menu['items'] = $items;
  49. if( empty($can_use_routearr) )
  50. {
  51. $this->redirect( 'application/index', [], 1,'您没有当前应用权限' );
  52. }else if( !in_array($perm_url , $can_use_routearr ) )
  53. {
  54. $this->redirect( $can_use_routearr[0] );
  55. }
  56. }
  57. //组件方法end
  58. $this->menu = $menu;
  59. $this->assign('menu', $menu );
  60. }
  61. /**
  62. * @author cy 2021-05-21
  63. * @desc 万能表单列表
  64. */
  65. public function index(){
  66. $_GPC = I('request.');
  67. $pindex = max(1, intval($_GPC['page']));
  68. $psize = 20;
  69. $condition = " 1 ";
  70. if (!empty($_GPC['keyword'])) {
  71. $_GPC['keyword'] = trim($_GPC['keyword']);
  72. $condition .= ' and form_name like "%'.$_GPC['keyword'].'%"';
  73. }
  74. $list = M('lionfish_comshop_forms')->where($condition)->order('id desc')->limit( (($pindex - 1) * $psize) , $psize )->select();
  75. foreach($list as $k=>$v){
  76. $list[$k]['form_type_text'] = D('Seller/allform')->getFormTypeName($v['form_type']);
  77. $list[$k]['collection_count'] = D('Seller/allform')->getFormInfoCountByFormId($v['id']);
  78. $list[$k]['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
  79. }
  80. $total = M('lionfish_comshop_forms')->where( $condition )->count();
  81. $pager = pagination2($total, $pindex, $psize);
  82. $this->list = $list;
  83. $this->pager = $pager;
  84. $this->_GPC = $_GPC;
  85. $this->display();
  86. }
  87. /**
  88. * @desc 添加万能表单
  89. * @author cy
  90. */
  91. public function add( )
  92. {
  93. $_GPC = I('request.');
  94. $id = $_GPC['id'];
  95. if( $id > 0 )
  96. {
  97. $item = D('Seller/allform')->getFormsById( $id );
  98. $item_content = D('Seller/allform')->setFormsContent($item);
  99. $item['item_li'] = $item_content['item_li'];
  100. $item['phone_item'] = $item_content['phone_item'];
  101. $this->item = $item;
  102. }
  103. if( IS_POST )
  104. {
  105. $res = D('Seller/allform')->addOrUpdateForm();
  106. if( $res['code'] == 0 )
  107. {
  108. show_json(0, array('message' => $res['message'] ,'url' => $_SERVER['HTTP_REFERER']) );
  109. die();
  110. }else if( $res['code'] == 1 ){
  111. show_json(1, array('url' => U('allform/index')));
  112. die();
  113. }
  114. }
  115. $this->display('Allform/addform');
  116. }
  117. /**
  118. * @author cy 2021-05-24
  119. * @desc 万能表单添加项目
  120. */
  121. public function add_item(){
  122. $type = I('request.type');
  123. $need_data = D('Seller/allform')->getFormItem($type);
  124. show_json(1, array('data' => $need_data));
  125. }
  126. /**
  127. * @author cy 2021-05-25
  128. * @desc 删除万能表单
  129. * @return mixed
  130. */
  131. public function delete(){
  132. $id = I('request.id');
  133. $res = D('Seller/allform')->deleteForm($id);
  134. if($res['code'] == 0){
  135. show_json(0, array('message' => $res['message'] ,'url' => $_SERVER['HTTP_REFERER']) );
  136. die();
  137. }else{
  138. show_json(1, array('url' => U('allform/index')));
  139. die();
  140. }
  141. }
  142. /**
  143. * @author cy 2021-05-25
  144. * @desc 表单设置
  145. */
  146. public function config()
  147. {
  148. $_GPC = I('request.');
  149. if (IS_POST) {
  150. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  151. $data['is_open_allform'] = isset($data['is_open_allform']) ? $data['is_open_allform'] : 0;
  152. $data['is_open_orderform'] = isset($data['is_open_orderform']) ? $data['is_open_orderform'] : 0;
  153. $data['order_allform_id'] = isset($data['order_allform_id']) ? $data['order_allform_id'] : 0;
  154. D('Seller/Config')->update($data);
  155. show_json(1, array('url' => $_SERVER['HTTP_REFERER']) );
  156. die();
  157. }
  158. $data = D('Seller/Config')->get_all_config();
  159. if(!empty($data['order_allform_id'])){
  160. $form_data = D('Seller/allform')->getFormsById( $data['order_allform_id'] );
  161. if(!empty($form_data)){
  162. $data['order_allform_name'] = $form_data['form_name'];
  163. }
  164. }else{
  165. $data['order_allform_name'] = "";
  166. }
  167. $this->data = $data;
  168. $this->display();
  169. }
  170. /**
  171. * @author cy 2021-05-25
  172. * @desc 公共查询表单数据列表
  173. */
  174. public function query_form(){
  175. $_GPC = I('request.');
  176. $is_ajax = isset($_GPC['is_ajax']) ? intval($_GPC['is_ajax']) : 0;
  177. $need_data = D('Seller/allform')->queryList($_GPC);
  178. if( $is_ajax == 1 ) {
  179. echo json_encode( array('code' => 0, 'html' => $need_data['html'],'pager' => $need_data['pager']) );
  180. die();
  181. }else{
  182. $data = [];
  183. $data['gpc'] = ['keyword' => $_GPC['keyword'],'type' => $_GPC['type'],'template' => $_GPC['template']];
  184. $data['list'] = $need_data['list'];
  185. $data['pager'] = $need_data['pager'];
  186. $this->data = $data;
  187. $this->display('Allform/query_form');
  188. }
  189. }
  190. /**
  191. * @author cy 2021-05-26
  192. * @desc 表单数据列表
  193. */
  194. public function datalist(){
  195. $_GPC = I('request.');
  196. $need_data = D('Seller/allform')->getDataList($_GPC);
  197. $data = [];
  198. $data['gpc'] = ['keyword' => $_GPC['keyword'],'id' => $_GPC['id']];
  199. $data['list'] = $need_data['list'];
  200. $data['pager'] = $need_data['pager'];
  201. $data['form_info'] = $need_data['form_info'];
  202. $this->data = $data;
  203. $this->display('Allform/datalist');
  204. }
  205. /**
  206. * @author cy 2021-05-26
  207. * @desc 导出表单数据列表信息
  208. */
  209. public function exportdata(){
  210. $_GPC = I('request.');
  211. $form_id = $_GPC['id'];
  212. //获取表单信息
  213. $form_data = D('Seller/allform')->getExportFormDataList($form_id);
  214. $title_list = $form_data['title_list'];
  215. $form_list = $form_data['form_list'];
  216. $form_data = $form_data['form_data'];
  217. $columns = array(
  218. array('title' => '表单数据ID', 'field' => 'id', 'width' => 12),
  219. array('title' => '表单名称', 'field' => 'form_name', 'width' => 12),
  220. array('title' => '表单类型', 'field' => 'form_type_name', 'width' => 12),
  221. array('title' => '关联订单', 'field' => 'order_number', 'width' => 24),
  222. array('title' => '提交会员', 'field' => 'username', 'width' => 24),
  223. array('title' => '提交时间', 'field' => 'addtime', 'width' => 24)
  224. );
  225. if(!empty($title_list)){
  226. foreach($title_list as $k=>$v){
  227. $columns[] = array('title' => $v, 'field' => $v, 'width' => 24 );
  228. }
  229. }
  230. $need_list = [];
  231. if( !empty($form_list) )
  232. {
  233. foreach($form_list as $val )
  234. {
  235. $tmp_arr = [];
  236. if($form_data['form_type'] == 'order'){
  237. $tmp_arr['id'] = $val['id'];
  238. $tmp_arr['form_name'] = $val['form_name'];
  239. $tmp_arr['form_type_name'] = D('Seller/allform')->getFormTypeName($val['form_type']);
  240. $tmp_arr['order_number'] = $val['order_number']."\t";
  241. $tmp_arr['username'] = $val['username'];
  242. $tmp_arr['addtime'] = $val['addtime'];
  243. }
  244. if(!empty($title_list)){
  245. foreach($title_list as $k=>$v){
  246. if(!empty($val[$v])){
  247. $tmp_arr[$v] = $val[$v]."\t";;
  248. }else{
  249. $tmp_arr[$v] = "";
  250. }
  251. }
  252. }
  253. $need_list[] = $tmp_arr;
  254. }
  255. }
  256. D('Seller/Excel')->export($need_list, array('title' => $form_data['form_name'].'表单数据列表-' . date('Y-m-d-H-i', time()), 'columns' => $columns));
  257. }
  258. }
  259. ?>