AllformController.class.php 9.4 KB

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