wmerchant.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php
  2. define('IN_IA', true);
  3. define('STARTTIME', microtime());
  4. define('IA_ROOT', str_replace('\\', '/', dirname(dirname(__FILE__))));
  5. define('MAGIC_QUOTES_GPC', (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) || @ini_get('magic_quotes_sybase'));
  6. define('TIMESTAMP', time());
  7. $_W = $_GPC = array();
  8. $configfile = IA_ROOT . '/data/config.php';
  9. if (!(file_exists($configfile)))
  10. {
  11. exit('配置文件不存在或是不可读,请检查“data/config”文件或是重新安装!');
  12. }
  13. require $configfile;
  14. require IA_ROOT . '/framework/version.inc.php';
  15. require IA_ROOT . '/framework/const.inc.php';
  16. require IA_ROOT . '/framework/class/loader.class.php';
  17. load()->func('global');
  18. load()->func('compat');
  19. load()->func('pdo');
  20. load()->classs('account');
  21. load()->classs('agent');
  22. load()->model('cache');
  23. load()->model('account');
  24. load()->model('setting');
  25. load()->model('user');
  26. load()->func('tpl');
  27. define('CLIENT_IP', getip());
  28. $_W['config'] = $config;
  29. $_W['config']['db']['tablepre'] = ((!(empty($_W['config']['db']['master']['tablepre'])) ? $_W['config']['db']['master']['tablepre'] : $_W['config']['db']['tablepre']));
  30. $_W['timestamp'] = TIMESTAMP;
  31. $_W['charset'] = $_W['config']['setting']['charset'];
  32. $_W['clientip'] = CLIENT_IP;
  33. $_W['token'] = token();
  34. unset($configfile, $config);
  35. define('ATTACHMENT_ROOT', IA_ROOT . '/attachment/');
  36. define('DEVELOPMENT', $_W['config']['setting']['development'] == 1);
  37. if (DEVELOPMENT)
  38. {
  39. ini_set('display_errors', '1');
  40. error_reporting(30719 ^ 8);
  41. }
  42. else
  43. {
  44. error_reporting(0);
  45. }
  46. if (!(in_array($_W['config']['setting']['cache'], array('mysql', 'file', 'memcache'))))
  47. {
  48. $_W['config']['setting']['cache'] = 'mysql';
  49. }
  50. load()->func('cache');
  51. if (function_exists('date_default_timezone_set'))
  52. {
  53. date_default_timezone_set($_W['config']['setting']['timezone']);
  54. }
  55. if (!(empty($_W['config']['setting']['memory_limit'])) && function_exists('ini_get') && function_exists('ini_set'))
  56. {
  57. if (@ini_get('memory_limit') != $_W['config']['setting']['memory_limit'])
  58. {
  59. @ini_set('memory_limit', $_W['config']['setting']['memory_limit']);
  60. }
  61. }
  62. $_W['ishttps'] = ((!(empty($_W['config']['setting']['https'])) ? true : strtolower((($_SERVER['SERVER_PORT'] == 443) || (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) ? true : false))));
  63. $_W['isajax'] = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
  64. $_W['ispost'] = $_SERVER['REQUEST_METHOD'] == 'POST';
  65. $_W['sitescheme'] = (($_W['ishttps'] ? 'https://' : 'http://'));
  66. $_W['script_name'] = htmlspecialchars(scriptname());
  67. $sitepath = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
  68. $_W['siteroot'] = htmlspecialchars($_W['sitescheme'] . $_SERVER['HTTP_HOST'] . $sitepath);
  69. if (substr($_W['siteroot'], -1) != '/')
  70. {
  71. $_W['siteroot'] .= '/';
  72. }
  73. $urls = parse_url($_W['siteroot']);
  74. $urls['path'] = str_replace(array('/web', '/app', '/payment/wechat', '/payment/alipay', '/api'), '', $urls['path']);
  75. $_W['siteroot'] = $urls['scheme'] . '://' . $urls['host'] . ((!(empty($urls['port'])) && ($urls['port'] != '80') ? ':' . $urls['port'] : '')) . $urls['path'];
  76. $_W['siteurl'] = $urls['scheme'] . '://' . $urls['host'] . ((!(empty($urls['port'])) && ($urls['port'] != '80') ? ':' . $urls['port'] : '')) . $_W['script_name'] . ((empty($_SERVER['QUERY_STRING']) ? '' : '?')) . $_SERVER['QUERY_STRING'];
  77. if (MAGIC_QUOTES_GPC)
  78. {
  79. $_GET = istripslashes($_GET);
  80. $_POST = istripslashes($_POST);
  81. $_COOKIE = istripslashes($_COOKIE);
  82. }
  83. $cplen = strlen($_W['config']['cookie']['pre']);
  84. foreach ($_COOKIE as $key => $value )
  85. {
  86. if (substr($key, 0, $cplen) == $_W['config']['cookie']['pre'])
  87. {
  88. $_GPC[substr($key, $cplen)] = $value;
  89. }
  90. }
  91. unset($cplen, $key, $value);
  92. $_GPC = array_merge($_GET, $_POST, $_GPC);
  93. $_GPC = ihtmlspecialchars($_GPC);
  94. if (!($_W['isajax']))
  95. {
  96. $input = file_get_contents('php://input');
  97. if (!(empty($input)))
  98. {
  99. $__input = @json_decode($input, true);
  100. if (!(empty($__input)))
  101. {
  102. $_GPC['__input'] = $__input;
  103. $_W['isajax'] = true;
  104. }
  105. }
  106. unset($input, $__input);
  107. }
  108. setting_load();
  109. if (empty($_W['setting']['upload']))
  110. {
  111. $_W['setting']['upload'] = array_merge($_W['config']['upload']);
  112. }
  113. $_W['attachurl'] = $_W['attachurl_local'] = $_W['siteroot'] . $_W['config']['upload']['attachdir'] . '/';
  114. if (!(empty($_W['setting']['remote'][$_GPC['i']]['type'])))
  115. {
  116. $_W['setting']['remote'] = $_W['setting']['remote'][$_GPC['i']];
  117. }
  118. if (!(empty($_W['setting']['remote']['type'])))
  119. {
  120. if ($_W['setting']['remote']['type'] == 1)
  121. {
  122. $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['ftp']['url'] . '/';
  123. }
  124. else if ($_W['setting']['remote']['type'] == 2)
  125. {
  126. $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['alioss']['url'] . '/';
  127. }
  128. else if ($_W['setting']['remote']['type'] == 3)
  129. {
  130. $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['qiniu']['url'] . '/';
  131. }
  132. else if ($_W['setting']['remote']['type'] == 4)
  133. {
  134. $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['cos']['url'] . '/';
  135. }
  136. }
  137. header('Content-Type: text/html; charset=' . $_W['charset']);
  138. $session = json_decode(authcode($_GPC['__session']), true);
  139. if (empty($session))
  140. {
  141. $session = json_decode(base64_decode($_GPC['__session']), true);
  142. }
  143. if (is_array($session))
  144. {
  145. $user = user_single(array('uid' => $session['uid']));
  146. if (is_array($user) && ($session['hash'] == md5($user['password'] . $user['salt'])))
  147. {
  148. $_W['uid'] = $user['uid'];
  149. $_W['username'] = $user['username'];
  150. $user['currentvisit'] = $user['lastvisit'];
  151. $user['currentip'] = $user['lastip'];
  152. $user['lastvisit'] = $session['lastvisit'];
  153. $user['lastip'] = $session['lastip'];
  154. $_W['user'] = $user;
  155. $founders = explode(',', $_W['config']['setting']['founder']);
  156. $_W['isfounder'] = in_array($_W['uid'], $founders);
  157. if (0 < $_GPC['sid'])
  158. {
  159. isetcookie('__sid', $_GPC['sid'], 7 * 86400);
  160. }
  161. unset($founders);
  162. }
  163. else
  164. {
  165. isetcookie('__session', false, -100);
  166. isetcookie('__sid', 0, -1000);
  167. }
  168. unset($user);
  169. }
  170. unset($session);
  171. if (!(function_exists('uni_permission')))
  172. {
  173. function uni_permission($uid = 0, $uniacid = 0)
  174. {
  175. global $_W;
  176. $uid = ((empty($uid) ? $_W['uid'] : intval($uid)));
  177. $uniacid = ((empty($uniacid) ? $_W['uniacid'] : intval($uniacid)));
  178. $founders = explode(',', $_W['config']['setting']['founder']);
  179. if (in_array($uid, $founders))
  180. {
  181. return 'founder';
  182. }
  183. $sql = 'SELECT `role` FROM ' . tablename('uni_account_users') . ' WHERE `uid`=:uid AND `uniacid`=:uniacid';
  184. $pars = array();
  185. $pars[':uid'] = $uid;
  186. $pars[':uniacid'] = $uniacid;
  187. $role = pdo_fetchcolumn($sql, $pars);
  188. return (in_array($role, array('manager', 'owner')) ? 'manager' : 'operator');
  189. }
  190. }
  191. if (!(empty($_GPC['i'])))
  192. {
  193. $_W['uniacid'] = intval($_GPC['i']);
  194. $_W['uniaccount'] = $_W['account'] = uni_fetch($_W['uniacid']);
  195. $_W['acid'] = $_W['account']['acid'];
  196. if (!(empty($_W['uid'])))
  197. {
  198. $_W['role'] = uni_permission($_W['uid'], $_W['uniacid']);
  199. if ($_W['role'] == 'owner')
  200. {
  201. $_W['role'] = 'manager';
  202. }
  203. }
  204. }
  205. if (empty($_W['uniacid']))
  206. {
  207. exit('公众号信息错误');
  208. }
  209. if (empty($_W['isfounder']) && empty($_W['role']))
  210. {
  211. $session = json_decode(base64_decode($_GPC['__we7_wmall_agent']), true);
  212. if (is_array($session))
  213. {
  214. $agent = pdo_get('tiny_wmall_agent', array('id' => $session['id']));
  215. if (is_array($session) && ($session['hash'] == $agent['password']))
  216. {
  217. $_W['role'] = 'agenter';
  218. $_W['we7_wmall']['agent'] = $agent;
  219. $_W['agentid'] = $agent['id'];
  220. isetcookie('__agent_id', $agent['id'], 7 * 86400);
  221. if ($_W['uniacid'] != $_GPC['uniacid'])
  222. {
  223. isetcookie('__uniacid', $_W['uniacid'], 7 * 86400);
  224. }
  225. }
  226. else
  227. {
  228. isetcookie('__we7_wmall_agent', false, -100);
  229. isetcookie('__agent_id', 0, -1000);
  230. }
  231. unset($user);
  232. }
  233. unset($session);
  234. }
  235. if (empty($_W['isfounder']) && ($_W['role'] != 'manager') && ($_W['role'] != 'operator') && ($_W['role'] != 'agenter'))
  236. {
  237. $session = json_decode(base64_decode($_GPC['__we7_wmall_store']), true);
  238. if (is_array($session))
  239. {
  240. $user = pdo_get('tiny_wmall_clerk', array('id' => $session['clerk_id']));
  241. if (is_array($user) && ($session['hash'] == $user['password']))
  242. {
  243. $perms = pdo_getall('tiny_wmall_store_clerk', array('uniacid' => $_W['uniacid'], 'clerk_id' => $user['id'], 'role' => 'manager'), array(), 'sid');
  244. if (empty($perms))
  245. {
  246. exit('您的申请是店员身份,没有权限管理店铺!');
  247. }
  248. $sids = array_keys($perms);
  249. $_W['role'] = 'merchanter';
  250. $_W['clerk'] = $user;
  251. $_W['we7_wmall']['store'] = pdo_get('tiny_wmall_store', array('id' => $sids[0]), array('title', 'id'));
  252. isetcookie('__sid', $user['sid'], 7 * 86400);
  253. if ($_W['uniacid'] != $_GPC['uniacid'])
  254. {
  255. isetcookie('__uniacid', $_W['uniacid'], 7 * 86400);
  256. }
  257. }
  258. else
  259. {
  260. isetcookie('__we7_wmall_store', false, -100);
  261. isetcookie('__sid', 0, -1000);
  262. }
  263. unset($user);
  264. }
  265. unset($session);
  266. }
  267. $entry = array('module' => 'we7_wmall', 'do' => 'web');
  268. define('IN_SYS', true);
  269. define('IN_MODULE', $entry['module']);
  270. load()->web('common');
  271. load()->web('template');
  272. $site = WeUtility::createModuleSite($entry['module']);
  273. if (!(is_error($site)))
  274. {
  275. $method = 'doWeb' . ucfirst($entry['do']);
  276. exit($site->$method());
  277. }
  278. exit();
  279. ?>