人人商城

post.ctrl.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->model('module');
  8. load()->model('miniapp');
  9. $dos = array('post', 'get_wxapp_modules', 'module_binding');
  10. $do = in_array($do, $dos) ? $do : 'post';
  11. $_W['page']['title'] = '小程序 - 新建版本';
  12. $account_info = permission_user_account_num($_W['uid']);
  13. $type = intval($_GPC['type']);
  14. if ($do == 'post') {
  15. $uniacid = intval($_GPC['uniacid']);
  16. if (checksubmit('submit')) {
  17. if ($account_info['aliapp_limit'] <= 0 && empty($uniacid) && !$_W['isfounder']) {
  18. iajax(-1, '创建的支付宝小程序已达上限!');
  19. }
  20. if (!preg_match('/^[0-9]{1,2}\.[0-9]{1,2}(\.[0-9]{1,2})?$/', trim($_GPC['version']))) {
  21. iajax(-1, '版本号错误,只能是数字、点,数字最多2位,例如 1.1.1 或1.2');
  22. }
  23. if (empty($uniacid)) {
  24. if (empty($_GPC['name'])) {
  25. iajax(-1, '请填写支付宝小程序名称');
  26. }
  27. $data = array(
  28. 'name' => trim($_GPC['name']),
  29. 'description' => safe_gpc_string($_GPC['description']),
  30. 'headimg' => safe_gpc_path($_GPC['headimg']),
  31. 'qrcode' => safe_gpc_path($_GPC['qrcode']),
  32. 'level' => 1,
  33. 'appid' => trim($_GPC['appid']),
  34. 'type' => $type,
  35. );
  36. $uniacid = miniapp_create($data, ACCOUNT_TYPE_ALIAPP_NORMAL);
  37. if (is_error($uniacid)) {
  38. iajax(-1, '添加失败');
  39. }
  40. }
  41. $version = array(
  42. 'uniacid' => $uniacid,
  43. 'multiid' => '0',
  44. 'description' => safe_gpc_string($_GPC['description']),
  45. 'version' => safe_gpc_string($_GPC['version']),
  46. 'modules' => '',
  47. 'createtime' => TIMESTAMP,
  48. );
  49. if (!empty($_GPC['choose_module'])) {
  50. $module = module_fetch($_GPC['choose_module']['name']);
  51. if (!empty($module)) {
  52. $select_modules[$module['name']] = array(
  53. 'name' => $module['name'],
  54. 'version' => $module['version']
  55. );
  56. $version['modules'] = serialize($select_modules);
  57. }
  58. }
  59. $result = pdo_insert('wxapp_versions', $version);
  60. $msg = $result ? '创建成功' : '创建失败';
  61. iajax(0, $msg, url('account/display/switch', array('uniacid' => $uniacid, 'type' => $type)));
  62. }
  63. if (!empty($uniacid)) {
  64. $miniapp_info = miniapp_fetch($uniacid);
  65. }
  66. template('miniapp/post');
  67. }