Form.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\form\shop\controller;
  11. use addon\form\model\Form as FormModel;
  12. use addon\form\model\FormData as FormDataModel;
  13. use app\model\order\Order as OrderModel;
  14. use app\shop\controller\BaseShop;
  15. /**
  16. * 分销订单
  17. */
  18. class Form extends BaseShop
  19. {
  20. protected $replace = [
  21. 'FORM_JS' => __ROOT__ . '/addon/form/shop/view/public/js',
  22. 'FORM_CSS' => __ROOT__ . '/addon/form/shop/view/public/css',
  23. 'FORM_IMG' => __ROOT__ . '/addon/form/shop/view/public/img'
  24. ];
  25. public function __construct()
  26. {
  27. $this->app_module = input('app_module', SHOP_MODULE);
  28. if ($this->app_module == 'store') {
  29. $this->initConstructInfo(); // 加载构造函数重要信息
  30. } else {
  31. parent::__construct();
  32. }
  33. }
  34. /**
  35. * 编辑添加系统表单
  36. * @param $game_data
  37. * @param $award_json
  38. * @return array
  39. */
  40. public function editForm()
  41. {
  42. $from_model = new FormModel();
  43. if (request()->isAjax()) {
  44. $id = input('id', '');
  45. $form_name = input('form_name', '');
  46. $json_data = input('json_data', '');
  47. $data = [
  48. 'form_name' => $form_name,
  49. 'json_data' => $json_data,
  50. 'modify_time' => time()
  51. ];
  52. $res = $from_model->editForm($data, [ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
  53. return $res;
  54. }
  55. $id = input('id', '');
  56. $info = $from_model->getFormInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
  57. if (empty($info[ 'data' ])) $this->error('未获取到表单数据');
  58. $this->assign('component', FormModel::FORM_COMPONENT);
  59. $this->assign('info', $info[ 'data' ]);
  60. $this->assign('form_type', ( new FormModel() )->form_type[ $info[ 'data' ][ 'form_type' ] ]);
  61. return $this->fetch('form/edit', [], $this->replace);
  62. }
  63. /**
  64. * 添加表单
  65. * @return array|mixed
  66. */
  67. public function addForm()
  68. {
  69. if (request()->isAjax()) {
  70. $form_name = input('form_name', '');
  71. $json_data = input('json_data', '');
  72. $form_type = input('form_type', 'order');
  73. $data = [
  74. 'form_name' => $form_name,
  75. 'json_data' => $json_data,
  76. 'form_type' => $form_type,
  77. 'site_id' => $this->site_id,
  78. 'create_time' => time(),
  79. 'is_use' => $form_type != 'order' ? 1 : 0
  80. ];
  81. $from_model = new FormModel();
  82. $res = $from_model->addForm($data);
  83. return $res;
  84. }
  85. $form_type = input('form_type', 'order');
  86. $this->assign('component', FormModel::FORM_COMPONENT);
  87. $this->assign('form_type', ( new FormModel() )->form_type[ $form_type ]);
  88. return $this->fetch('form/edit', [], $this->replace);
  89. }
  90. /**
  91. * 是否开启
  92. * @param $game_data
  93. * @param $award_json
  94. * @return array
  95. */
  96. public function editIsUse()
  97. {
  98. $from_model = new FormModel();
  99. $is_use = input('is_use', '');
  100. $id = input('id', '');
  101. $form_type = input('form_type', '');
  102. if (empty($is_use) && empty($id)) {
  103. $this->error('id和is_use不可为空');
  104. }
  105. //启用之前先把该类型的全都不启用
  106. if ($form_type == 'order') {
  107. $from_model->editForm([ 'is_use' => 0 ], [ [ 'form_type', '=', 'order' ], [ 'site_id', '=', $this->site_id ] ]);
  108. }
  109. $data = [
  110. 'is_use' => $is_use
  111. ];
  112. $res = $from_model->editForm($data, [ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
  113. return $res;
  114. }
  115. /**
  116. * 删除数据
  117. * @param $game_data
  118. * @param $award_json
  119. * @return array
  120. */
  121. public function deleteForm()
  122. {
  123. $id = input('id', '');
  124. if (empty($id)) {
  125. $this->error('id不可为空');
  126. }
  127. $from_model = new FormModel();
  128. $res = $from_model->deleteForm($id, $this->site_id);
  129. return $res;
  130. }
  131. /**
  132. * 表单列表
  133. * @param $game_data
  134. * @param $award_json
  135. * @return array
  136. */
  137. public function lists()
  138. {
  139. if (request()->isAjax()) {
  140. $form_type = input('form_type', '');
  141. $form_name = input('form_name', '');
  142. $page = input('page', 1);
  143. $page_size = input('page_size', PAGE_LIST_ROWS);
  144. $is_use = input('is_use', '');
  145. $condition = [];
  146. $condition[] = [ 'site_id', '=', $this->site_id ];
  147. if (!empty($form_type)) {
  148. $condition[] = [ 'form_type', '=', $form_type ];
  149. }
  150. if (!empty($form_name)) {
  151. $condition[] = [ 'form_name', 'like', '%' . $form_name . '%' ];
  152. }
  153. if (!empty($is_use)) {
  154. $condition[] = [ 'is_use', '=', $is_use ];
  155. }
  156. $from_model = new FormModel();
  157. $res = $from_model->getFormPageList($condition, $page, $page_size);
  158. return $res;
  159. }
  160. $this->assign('form_type', ( new FormModel() )->form_type);
  161. return $this->fetch('form/lists');
  162. }
  163. /**
  164. * 导出表单列表
  165. * @param $game_data
  166. * @param $award_json
  167. * @return array
  168. */
  169. public function exportForm()
  170. {
  171. $id = input('id', '');
  172. if (empty($id)) {
  173. $this->error('id不可为空');
  174. }
  175. $from_model = new FormModel();
  176. $res = $from_model->export([ 'id' => $id, 'site_id' => $this->site_id ]);
  177. if (isset($res[ 'code' ]) && $res[ 'code' ] != 0) $this->error($res[ 'message' ]);
  178. }
  179. /**
  180. * 获取详情
  181. * @param $game_data
  182. * @param $award_json
  183. * @return array
  184. */
  185. public function formInfo()
  186. {
  187. $id = input('id', '');
  188. $condition[] = [ 'site_id', '=', $this->site_id ];
  189. if (empty($id)) {
  190. $this->error('id不可为空');
  191. }
  192. $condition[] = [ 'id', '=', $id ];
  193. $from_model = new FormModel();
  194. $res = $from_model->getFormInfo($condition);
  195. return $res;
  196. }
  197. /**
  198. * 查看表单数据
  199. * @param $game_data
  200. * @param $award_json
  201. * @return array
  202. */
  203. public function formData()
  204. {
  205. $form_id = input('form_id', '');
  206. if (request()->isAjax()) {
  207. if (empty($form_id)) {
  208. $this->error('id不可为空');
  209. }
  210. $page = input('page', 1);
  211. $page_size = input('page_size', PAGE_LIST_ROWS);
  212. $nickname = input('nickname', '');
  213. $start_time = input('start_time', '');
  214. $end_time = input('end_time', '');
  215. $condition[] = [ 'fd.form_id', '=', $form_id ];
  216. $condition[] = [ 'fd.site_id', '=', $this->site_id ];
  217. if ($start_time && !$end_time) {
  218. $condition[] = [ 'fd.create_time', '>=', date_to_time($start_time) ];
  219. } elseif (!$start_time && $end_time) {
  220. $condition[] = [ 'fd.create_time', '<=', date_to_time($end_time) ];
  221. } elseif ($start_time && $end_time) {
  222. $condition[] = [ 'fd.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
  223. }
  224. if (!empty($nickname)) $condition[] = [ 'm.nickname', 'like', "%{$nickname}%" ];
  225. $alias = 'fd';
  226. $join = [
  227. [
  228. 'member m',
  229. 'fd.member_id = m.member_id',
  230. 'inner'
  231. ],
  232. ];
  233. $field = 'fd.*,m.headimg,m.nickname,m.status,m.member_level_type';
  234. $from_model = new FormDataModel();
  235. $res = $from_model->getFormDataPageList($condition, $field, 'fd.id desc', $page, $page_size, $alias, $join);
  236. if (!empty($res[ 'data' ][ 'list' ])) {
  237. $order_model = new OrderModel();
  238. foreach ($res[ 'data' ][ 'list' ] as $k => &$item_v) {
  239. $item_v[ 'form_data' ] = json_decode($item_v[ 'form_data' ], true);
  240. if ($item_v[ 'scene' ] == 'order') {
  241. $item_v[ 'order_info' ] = $order_model->getOrderInfo([ [ 'order_id', '=', $item_v[ 'relation_id' ] ] ], 'order_id,order_no')[ 'data' ];
  242. } elseif ($item_v[ 'scene' ] == 'goods') {
  243. $item_v[ 'order_goods_info' ] = $order_model->getOrderGoodsInfo([ [ 'order_goods_id', '=', $item_v[ 'relation_id' ] ] ], 'order_goods_id,order_id,order_no')[ 'data' ];
  244. }
  245. }
  246. }
  247. return $res;
  248. } else {
  249. $this->assign('form_id', $form_id);
  250. return $this->fetch('form/formdata', [], $this->replace);
  251. }
  252. }
  253. /**
  254. * 查询表单列表
  255. * @return array
  256. */
  257. public function getFormList()
  258. {
  259. if (request()->isAjax()) {
  260. $form_type = input('form_type', 'goods');
  261. $is_use = input('is_use', 1);
  262. $condition = [
  263. [ 'site_id', '=', $this->site_id ],
  264. [ 'form_type', '=', $form_type ],
  265. [ 'is_use', '=', $is_use ]
  266. ];
  267. return ( new FormModel() )->getFormList($condition, 'id desc', 'id,form_name');
  268. }
  269. }
  270. /**
  271. * 推广
  272. * @return array
  273. */
  274. public function promote()
  275. {
  276. if (request()->isAjax()) {
  277. $form_id = input('form_id', '');
  278. $from_model = new FormModel();
  279. $res = $from_model->urlQrcode('/pages_tool/form/form', [ 'id' => $form_id ], $this->site_id);
  280. return $res;
  281. }
  282. }
  283. /**
  284. * 删除表单数据
  285. * @return array|string|string[]
  286. */
  287. public function deleteFormData()
  288. {
  289. if (request()->isAjax()) {
  290. $id = input('id', '');
  291. if (empty($id)) return error(-1, 'id不可为空');
  292. $from_model = new FormDataModel();
  293. $res = $from_model->deleteFormData([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
  294. return $res;
  295. }
  296. }
  297. }