人人商城

site.php 43KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  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. class StoreModuleSite extends WeModuleSite {
  8. public $modulename = 'store';
  9. private $left_menus;
  10. public function __construct() {
  11. global $_W, $_GPC;
  12. if ($_GPC['c'] == 'site') {
  13. checklogin();
  14. }
  15. load()->model('store');
  16. $this->store_setting = (array)$_W['setting']['store'];
  17. $this->left_menus = $this->leftMenu();
  18. }
  19. public function storeIsOpen() {
  20. global $_W;
  21. if ((!$_W['isfounder'] || user_is_vice_founder()) && $this->store_setting['status'] == 1) {
  22. itoast('商城已被创始人关闭!', referer(), 'error');
  23. }
  24. if (!empty($_W['username']) && !empty($this->store_setting['permission_status']) && empty($this->store_setting['permission_status']['close']) && !($_W['isfounder'] && !user_is_vice_founder())) {
  25. if (!in_array($_W['username'], (array)$this->store_setting['whitelist']) && !empty($this->store_setting['permission_status']['whitelist']) ||
  26. in_array($_W['username'], (array)$this->store_setting['blacklist']) && !empty($this->store_setting['permission_status']['blacklist']) && empty($this->store_setting['permission_status']['whitelist'])) {
  27. itoast('您无权限进入商城,请联系管理员!', referer(), 'error');
  28. }
  29. }
  30. return true;
  31. }
  32. public function getTypeName($type) {
  33. $sign = array(
  34. STORE_TYPE_MODULE => '公众号应用',
  35. STORE_TYPE_ACCOUNT => '公众号个数',
  36. STORE_TYPE_WXAPP => '小程序个数',
  37. STORE_TYPE_WXAPP_MODULE => '小程序应用',
  38. STORE_TYPE_PACKAGE => '应用权限组',
  39. STORE_TYPE_API => '应用访问流量(API)',
  40. STORE_TYPE_ACCOUNT_RENEW => '公众号续费',
  41. STORE_TYPE_WXAPP_RENEW => '小程序续费'
  42. );
  43. return $sign[$type];
  44. }
  45. public function payResult($params) {
  46. global $_W;
  47. if($params['result'] == 'success' && $params['from'] == 'notify') {
  48. $order = pdo_get('site_store_order', array('id' => $params['tid'], 'type' => 1));
  49. if(!empty($order)) {
  50. $goods = pdo_get('site_store_goods', array('id' => $order['goodsid']));
  51. $history_order_endtime = pdo_getcolumn('site_store_order', array('goodsid' => $goods['id'], 'buyerid' => $order['buyerid'], 'uniacid' => $order['uniacid'], 'type' => STORE_ORDER_FINISH), 'max(endtime)');
  52. $endtime = strtotime('+' . $order['duration'] . $goods['unit'], max($history_order_endtime, time()));
  53. pdo_update('site_store_order', array('type' => 3, 'endtime' => $endtime), array('id' => $params['tid']));
  54. if (in_array($goods['type'], array(STORE_TYPE_ACCOUNT_RENEW, STORE_TYPE_WXAPP_RENEW))) {
  55. $account_type = $goods['type'] == STORE_TYPE_ACCOUNT_RENEW ? 'uniacid' : 'wxapp';
  56. $account_num = $goods['type'] == STORE_TYPE_ACCOUNT_RENEW ? $goods['account_num'] : $goods['wxapp_num'];
  57. $account_info = uni_fetch($order[$account_type]);
  58. $account_endtime = strtotime('+' . $order['duration'] * $account_num . $goods['unit'], max(TIMESTAMP, $account_info['endtime']));
  59. pdo_update('account', array('endtime' => $account_endtime), array('uniacid' => $order[$account_type]));
  60. $store_create_account_info = table('store')->StoreCreateAccountInfo($order[$account_type]);
  61. if (!empty($store_create_account_info)) {
  62. $endtime = strtotime('+' . $order['duration'] * $account_num . $goods['unit'], max(TIMESTAMP, $store_create_account_info['endtime']));
  63. pdo_update('site_store_create_account', array('endtime' => $endtime), array('uniacid' => $order[$account_type]));
  64. }
  65. pdo_update('account', array('endtime' => $account_endtime), array('uniacid' => $order[$account_type]));
  66. cache_delete(cache_system_key('uniaccount_type', array('account_type' => $order[$account_type])));
  67. }
  68. cache_delete(cache_system_key('site_store_buy', array('type' => $goods['type'], 'uniacid' => $order['uniacid'])));
  69. if ($goods['type'] == STORE_TYPE_USER_PACKAGE) {
  70. cache_delete(cache_system_key('system_frame', array('uniacid' => $_W['uniacid'])));
  71. }
  72. cache_build_account_modules($order['uniacid']);
  73. }
  74. }
  75. if($params['result'] == 'success' && $params['from'] == 'return') {
  76. header('Location: ' . $_W['siteroot'] . $this->createWebUrl('orders', array('direct' => 1)));
  77. }
  78. }
  79. public function doWebPaySetting() {
  80. $this->storeIsOpen();
  81. global $_W, $_GPC;
  82. if (!$_W['isfounder'] || user_is_vice_founder()) {
  83. itoast('', referer(), 'info');
  84. }
  85. $operate = $_GPC['operate'];
  86. $operates = array('alipay', 'wechat');
  87. $operate = in_array($operate, $operates) ? $operate : 'alipay';
  88. $_W['page']['title'] = '支付设置 - 商城';
  89. $settings = $_W['setting']['store_pay'];
  90. if (checksubmit('submit')) {
  91. if ($operate == 'alipay') {
  92. $settings['alipay'] = array(
  93. 'switch' => intval($_GPC['switch']),
  94. 'account' => trim($_GPC['account']),
  95. 'partner' => trim($_GPC['partner']),
  96. 'secret' => trim($_GPC['secret']),
  97. );
  98. } elseif ($operate == 'wechat') {
  99. if ($_GPC['switch'] == 1 && (empty($_GPC['appid']) || empty($_GPC['mchid']) || empty($_GPC['signkey']))) {
  100. itoast('请完善支付设置。', referer(), 'info');
  101. }
  102. $settings['wechat'] = array(
  103. 'switch' => intval($_GPC['switch']),
  104. 'appid' => $_GPC['appid'],
  105. 'mchid' => $_GPC['mchid'],
  106. 'signkey' => $_GPC['signkey'],
  107. );
  108. }
  109. setting_save($settings, 'store_pay');
  110. itoast('设置成功!', referer(), 'success');
  111. }
  112. if ($operate == 'alipay') {
  113. $alipay = $settings['alipay'];
  114. } elseif ($operate == 'wechat') {
  115. $wechat = $settings['wechat'];
  116. }
  117. include $this->template('paysetting');
  118. }
  119. public function doWebOrders() {
  120. $this->storeIsOpen();
  121. global $_GPC, $_W;
  122. load()->model('module');
  123. load()->model('message');
  124. $operates = array('display', 'change_price', 'delete');
  125. $operate = $_GPC['operate'];
  126. $operate = in_array($operate, $operates) ? $operate : 'display';
  127. $_W['page']['title'] = '订单管理 - 商城';
  128. if (user_is_vice_founder()) {
  129. $role = 'buyer';
  130. } elseif (!empty($_W['isfounder'])) {
  131. $role = 'seller';
  132. } else {
  133. $role = 'buyer';
  134. }
  135. if ($operate == 'display') {
  136. if (user_is_founder($_W['uid']) && !user_is_vice_founder($_W['uid'])) {
  137. $message_id = $_GPC['message_id'];
  138. message_notice_read($message_id);
  139. }
  140. $pindex = max(1, intval($_GPC['page']));
  141. $psize = 15;
  142. $store_table = table('store');
  143. if (isset($_GPC['type']) && intval($_GPC['type']) > 0) {
  144. $order_type = intval($_GPC['type']);
  145. $store_table->searchOrderType($order_type);
  146. }
  147. $store_table->searchWithOrderid($_GPC['orderid']);
  148. if (empty($_W['isfounder']) || user_is_vice_founder()) {
  149. $store_table->searchOrderWithUid($_W['uid']);
  150. }
  151. $order_list = $store_table->searchOrderList($pindex, $psize);
  152. if (is_array($order_list) && !empty($order_list)) {
  153. foreach ($order_list as &$order) {
  154. $order['account'] = uni_fetch($order['uniacid']);
  155. }
  156. }
  157. unset($order);
  158. $total = $store_table->getLastQueryTotal();
  159. $pager = pagination($total, $pindex, $psize);
  160. if (!empty($order_list)) {
  161. foreach ($order_list as $key => &$order) {
  162. if (empty($_W['isfounder']) && $order['type'] == 2) {
  163. unset($order_list[$key]);
  164. }
  165. $order['createtime'] = date('Y-m-d H:i:s', $order['createtime']);
  166. $order['goods_info'] = store_goods_info($order['goodsid']);
  167. $order['abstract_amount'] = $order['duration'] * $order['goods_info']['price'];
  168. if (!empty($order['goods_info']) && ($order['goods_info']['type'] == STORE_TYPE_MODULE || $order['goods_info']['type'] == STORE_TYPE_WXAPP_MODULE)) {
  169. $order['goods_info']['module_info'] = module_fetch($order['goods_info']['module']);
  170. }
  171. if (!empty($order['goods_info']) && ($order['goods_info']['type'] == STORE_TYPE_USER_PACKAGE)) {
  172. $user_group_id = $order['goods_info']['user_group'];
  173. $user_group_info = pdo_fetch("SELECT * FROM ".tablename('users_group') . " WHERE id = :id", array(':id' => $user_group_id));
  174. $order['goods_info']['user_group_name'] = $user_group_info['name'];
  175. }
  176. }
  177. unset($order);
  178. }
  179. }
  180. if ($operate == 'change_price') {
  181. if (user_is_vice_founder() || empty($_W['isfounder'])) {
  182. iajax(-1, '无权限更改!');
  183. }
  184. $id = intval($_GPC['id']);
  185. $price = floatval($_GPC['price']);
  186. $if_exists = store_order_info($id);
  187. if (empty($if_exists)) {
  188. iajax(-1, '订单不存在!');
  189. }
  190. $result = store_order_change_price($id, $price);
  191. if (!empty($result)) {
  192. iajax(0, '修改成功!');
  193. } else {
  194. iajax(-1, '修改失败!');
  195. }
  196. }
  197. if ($operate == 'delete') {
  198. $id = intval($_GPC['id']);
  199. if (empty($id)) {
  200. itoast('订单错误,请刷新后重试!');
  201. }
  202. $order_info = store_order_info($id);
  203. if (empty($order_info)) {
  204. itoast('订单不存在!');
  205. }
  206. if ($order_info['type'] != STORE_ORDER_PLACE) {
  207. itoast('只可删除未完成交易的订单!');
  208. }
  209. $result = store_order_delete($id);
  210. if (!empty($result)) {
  211. itoast('删除成功!', referer(), 'success');
  212. } else {
  213. itoast('删除失败,请稍候重试!', referer(), 'error');
  214. }
  215. }
  216. include $this->template('orders');
  217. }
  218. public function doWebSetting() {
  219. $this->storeIsOpen();
  220. global $_GPC, $_W;
  221. if (!$_W['isfounder'] || user_is_vice_founder()) {
  222. itoast('', referer(), 'info');
  223. }
  224. $operate = $_GPC['operate'];
  225. $operates = array('store_status', 'menu');
  226. $operate = in_array($operate, $operates) ? $operate : 'store_status';
  227. $_W['page']['title'] = '商城设置 - 商城';
  228. $settings = $this->store_setting;
  229. if ($operate == 'store_status') {
  230. if (checksubmit('submit')) {
  231. $status = intval($_GPC['status']) > 0 ? 1 : 0;
  232. $settings['status'] = $status;
  233. setting_save($settings, 'store');
  234. itoast('更新设置成功!', referer(), 'success');
  235. }
  236. }
  237. if ($operate == 'menu') {
  238. $left_menu = $this->leftMenu();
  239. $goods_menu = !empty($left_menu['store_goods']) ? $left_menu['store_goods']['menu'] : array();
  240. if (checksubmit('submit')) {
  241. foreach ($goods_menu as $key => $menu) {
  242. $settings[$key] = intval($_GPC['hide'][$key]) > 0 ? 1 : 0;
  243. }
  244. setting_save($settings, 'store');
  245. itoast('更新设置成功!', referer(), 'success');
  246. }
  247. }
  248. include $this->template('storesetting');
  249. }
  250. public function doWebGoodsSeller() {
  251. $this->storeIsOpen();
  252. global $_GPC, $_W;
  253. load()->model('module');
  254. if (!$_W['isfounder'] || user_is_vice_founder()) {
  255. itoast('', referer(), 'info');
  256. }
  257. $operate = $_GPC['operate'];
  258. $operates = array('display', 'delete', 'changestatus');
  259. $operate = in_array($operate, $operates) ? $operate : 'display';
  260. $type = intval($_GPC['type']) > 0 ? intval($_GPC['type']) : STORE_TYPE_MODULE;
  261. $_W['page']['title'] = '商品列表 - 商城管理 - 商城';
  262. if ($operate == 'display') {
  263. $pindex = max(1, intval($_GPC['page']));
  264. $psize = 15;
  265. $store_table = table('store');
  266. $keyword = trim($_GPC['keyword']);
  267. if (!empty($keyword)) {
  268. $store_table->searchWithKeyword($keyword);
  269. }
  270. $status = isset($_GPC['online']) && $_GPC['online'] == 0 ? 0 : 1;
  271. $store_table->searchWithStatus($status);
  272. if(isset($_GPC['letter']) && strlen($_GPC['letter']) == 1) {
  273. $store_table->searchWithLetter($_GPC['letter']);
  274. }
  275. $goods_list = $store_table->searchGoodsList($type, $pindex, $psize);
  276. $total = $goods_list['total'];
  277. $goods_list = $goods_list['goods_list'];
  278. $pager = pagination($total, $pindex, $psize);
  279. if (!empty($goods_list)) {
  280. foreach ($goods_list as &$good) {
  281. $good['module_info'] = module_fetch($good['module']);
  282. }
  283. unset($good);
  284. }
  285. $module_list = array();
  286. if (in_array($type, array(STORE_TYPE_MODULE, STORE_TYPE_WXAPP_MODULE))) {
  287. $modules = user_modules($_W['uid']);
  288. $modules = array_filter($modules, function($module) {
  289. return empty($module['issystem']);
  290. });
  291. $have_module_goods = $store_table->searchHaveModule($type);
  292. $have_module_goods = array_keys($have_module_goods);
  293. $have_module_goods = array_unique($have_module_goods);
  294. if (!empty($modules)) {
  295. foreach ($modules as $module) {
  296. if (in_array ($module['name'], $have_module_goods) || $type == STORE_TYPE_MODULE && $module[MODULE_SUPPORT_ACCOUNT_NAME] != 2 || $type == STORE_TYPE_WXAPP_MODULE && $module['wxapp_support'] != 2) {
  297. continue;
  298. }
  299. $module_list[] = $module;
  300. }
  301. }
  302. }
  303. if ($type == STORE_TYPE_PACKAGE) {
  304. $groups = uni_groups();
  305. }
  306. if ($type == STORE_TYPE_USER_PACKAGE) {
  307. $user_groups = pdo_fetchall("SELECT * FROM " . tablename('users_group'), array(), 'id');
  308. $user_groups = user_group_format($user_groups);
  309. }
  310. }
  311. if ($operate == 'changestatus' || $operate == 'delete') {
  312. $id = intval($_GPC['id']);
  313. $if_exist = store_goods_info($id);
  314. if (empty($if_exist)) {
  315. itoast('商品不存在,请刷新后重试!', referer(), 'error');
  316. }
  317. }
  318. if ($operate == 'changestatus') {
  319. $result = store_goods_changestatus($id);
  320. if (!empty($result)) {
  321. itoast('更新成功!', referer(), 'success');
  322. } else {
  323. itoast('更新失败!', referer(), 'error');
  324. }
  325. }
  326. if ($operate == 'delete') {
  327. $result = store_goods_delete($id);
  328. if (!empty($result)) {
  329. itoast('删除成功!', referer(), 'success');
  330. } else {
  331. itoast('删除失败!', referer(), 'error');
  332. }
  333. }
  334. include $this->template('goodsseller');
  335. }
  336. public function doWebGoodsPost() {
  337. $this->storeIsOpen();
  338. global $_GPC, $_W;
  339. if (!$_W['isfounder'] || user_is_vice_founder()) {
  340. itoast('', referer(), 'info');
  341. }
  342. $operate = $_GPC['operate'];
  343. $operates = array('post', 'add');
  344. $operate = in_array($operate, $operates) ? $operate : 'post';
  345. $type = intval($_GPC['type']) > 0 ? intval($_GPC['type']) : STORE_TYPE_MODULE;
  346. $_W['page']['title'] = '编辑商品 - 商城管理 - 商城';
  347. $user_groups = pdo_getall('users_group');
  348. if ($operate == 'post') {
  349. $id = intval($_GPC['id']);
  350. if (checksubmit('submit')) {
  351. if (!empty($_GPC['price']) && !is_numeric($_GPC['price'])) {
  352. itoast('价格有误,请填写有效数字!', referer(), 'error');
  353. }
  354. $user_group_price = array();
  355. if (!empty($_GPC['user_group_price']) && !empty($_GPC['user_group_id']) && count($_GPC['user_group_price']) == count($_GPC['user_group_id'])) {
  356. foreach ($_GPC['user_group_price'] as $k => $value) {
  357. if (empty($value) || empty($_GPC['user_group_id'][$k])) {
  358. continue;
  359. }
  360. $value = trim($value);
  361. if (!is_numeric($value)) {
  362. itoast('价格有误,请填写有效数字!', referer(), 'error');
  363. }
  364. $user_group_price[intval($_GPC['user_group_id'][$k])] = array(
  365. 'group_id' => $_GPC['user_group_id'][$k],
  366. 'group_name' => $_GPC['user_group_name'][$k],
  367. 'price' => $value,
  368. );
  369. }
  370. }
  371. $data = array(
  372. 'unit' => $_GPC['unit'],
  373. 'account_num' => $_GPC['account_num'],
  374. 'wxapp_num' => $_GPC['wxapp_num'],
  375. 'module_group' => $_GPC['module_group'],
  376. 'user_group' => $_GPC['user_group'],
  377. 'type' => $_GPC['type'],
  378. 'title' => !empty($_GPC['title']) ? trim($_GPC['title']) : '',
  379. 'price' => is_numeric($_GPC['price']) ? floatval($_GPC['price']) : 0,
  380. 'user_group_price' => iserializer($user_group_price),
  381. 'slide' => !empty($_GPC['slide']) ? iserializer($_GPC['slide']) : '',
  382. 'api_num' => is_numeric($_GPC['api_num']) ? intval($_GPC['api_num']) : 0,
  383. 'description' => safe_gpc_html(htmlspecialchars_decode($_GPC['description'])),
  384. );
  385. if ($_GPC['type'] == STORE_TYPE_API) {
  386. $data['title'] = '应用访问流量(API)';
  387. }
  388. if ($_GPC['type'] == STORE_TYPE_PACKAGE) {
  389. $data['title'] = '应用权限组';
  390. }
  391. if ($_GPC['type'] == STORE_TYPE_USER_PACKAGE) {
  392. $data['title'] = '用户权限组';
  393. }
  394. if ($_GPC['submit'] == '保存并上架') {
  395. $data['status'] = 1;
  396. }
  397. if (!empty($id)) {
  398. $data['id'] = $id;
  399. }
  400. $result = store_goods_post($data);
  401. if (!empty($result)) {
  402. if (!empty($id)) {
  403. itoast('编辑成功!', $this->createWebUrl('goodsseller', array('direct' =>1, 'type' => $type, 'online' => $data['status'])), 'success');
  404. } else {
  405. itoast('添加成功!', $this->createWebUrl('goodsSeller', array('direct' =>1, 'type' => $type)), 'success');
  406. }
  407. } else {
  408. itoast('未作任何更改或编辑/添加失败!', referer(), 'error');
  409. }
  410. }
  411. if (!empty($id)) {
  412. $goods_info = store_goods_info($id);
  413. $goods_info['slide'] = !empty($goods_info['slide']) ? (array)iunserializer($goods_info['slide']) : array();
  414. $goods_info['price'] = floatval($goods_info['price']);
  415. $goods_info['user_group_price'] = empty($goods_info['user_group_price']) ? array() : iunserializer($goods_info['user_group_price']);
  416. }
  417. if ($_GPC['type'] == STORE_TYPE_PACKAGE) {
  418. $module_groups = uni_groups();
  419. }
  420. if ($_GPC['type'] == STORE_TYPE_USER_PACKAGE) {
  421. $user_groups = user_group_format($user_groups);
  422. }
  423. }
  424. if ($operate == 'add') {
  425. if (empty($_GPC['module']) && $type == STORE_TYPE_MODULE) {
  426. iajax(-1, '请选择一个模块!');
  427. }
  428. $data = array(
  429. 'type' => $type,
  430. 'title' => !empty($_GPC['module']['title']) ? trim($_GPC['module']['title']) : trim($_GPC['title']),
  431. 'module' => !empty($_GPC['module']['name']) ? trim($_GPC['module']['name']) : '',
  432. 'synopsis' => !empty($_GPC['module']['ability']) ? trim($_GPC['module']['ability']) : '',
  433. 'description' => !empty($_GPC['module']['description']) ? trim($_GPC['module']['description']) : '',
  434. 'api_num' => is_numeric($_GPC['visit_times']) ? intval($_GPC['visit_times']) : 0,
  435. 'price' => is_numeric($_GPC['price']) ? floatval($_GPC['price']) : 0,
  436. 'status' => !empty($_GPC['online']) ? STATUS_ON : STATUS_OFF,
  437. );
  438. $result = store_goods_post($data);
  439. if (!empty($result)) {
  440. if (isset($_GPC['toedit']) && !empty($_GPC['toedit'])) {
  441. $id = pdo_insertid();
  442. iajax(0, $id);
  443. } else {
  444. iajax(0, '添加成功!');
  445. }
  446. } else {
  447. iajax(-1, '添加失败!');
  448. }
  449. }
  450. include $this->template('goodspost');
  451. }
  452. public function doWebGoodsBuyer() {
  453. $this->storeIsOpen();
  454. global $_GPC, $_W;
  455. load()->model('module');
  456. load()->model('payment');
  457. load()->model('message');
  458. load()->func('communication');
  459. load()->library('qrcode');
  460. $operate = $_GPC['operate'];
  461. $operates = array ('display', 'goods_info', 'get_expiretime', 'submit_order', 'pay_order');
  462. $operate = in_array($operate, $operates) ? $operate : 'display';
  463. $_W['page']['title'] = '商品列表 - 商城';
  464. if ($operate == 'display') {
  465. $pageindex = max(intval($_GPC['page']), 1);
  466. $pagesize = 24;
  467. $type = 0;
  468. if (!empty($_GPC['type']) && in_array($_GPC['type'], array(STORE_TYPE_MODULE, STORE_TYPE_ACCOUNT, STORE_TYPE_WXAPP, STORE_TYPE_WXAPP_MODULE, STORE_TYPE_PACKAGE, STORE_TYPE_API, STORE_TYPE_ACCOUNT_RENEW, STORE_TYPE_WXAPP_RENEW, STORE_TYPE_USER_PACKAGE))) {
  469. $type = $_GPC['type'];
  470. }
  471. $store_table = table('store');
  472. $store_table->searchWithStatus(1);
  473. $store_table = $store_table->searchGoodsList($type, $pageindex, $pagesize);
  474. $store_goods = $store_table['goods_list'];
  475. if (!user_is_founder($_W['uid']) && !empty($_W['user']['groupid'])) {
  476. foreach ($store_goods as $key => &$goods) {
  477. $goods['user_group_price'] = iunserializer($goods['user_group_price']);
  478. if (!empty($goods['user_group_price'][$_W['user']['groupid']]['price'])) {
  479. $goods['price'] = $goods['user_group_price'][$_W['user']['groupid']]['price'];
  480. }
  481. }
  482. unset($goods);
  483. }
  484. if ((empty($type) || in_array($type, array(STORE_TYPE_MODULE, STORE_TYPE_WXAPP_MODULE))) && is_array($store_goods)) {
  485. foreach ($store_goods as $key => &$goods) {
  486. if (empty($goods) || !in_array($goods['type'], array(STORE_TYPE_MODULE, STORE_TYPE_WXAPP_MODULE))) {
  487. continue;
  488. }
  489. $goods['module'] = module_fetch($goods['module']);
  490. }
  491. unset($goods);
  492. }
  493. if ($_GPC['type'] == STORE_TYPE_PACKAGE || empty($_GPC['type'])) {
  494. $module_groups = uni_groups();
  495. }
  496. if ($_GPC['type'] == STORE_TYPE_USER_PACKAGE || empty($_GPC['type'])) {
  497. $user_groups = pdo_fetchall("SELECT * FROM " . tablename('users_group'), array(), 'id');
  498. $user_groups = user_group_format($user_groups);
  499. }
  500. $pager = pagination ($store_table['total'], $pageindex, $pagesize);
  501. }
  502. if ($operate == 'goods_info') {
  503. $goods = intval ($_GPC['goods']);
  504. if (empty($goods)) {
  505. itoast ('商品不存在', '', 'info');
  506. }
  507. $goods = pdo_get('site_store_goods', array ('id' => $goods));
  508. if (!user_is_founder($_W['uid']) && !empty($_W['user']['groupid'])) {
  509. $goods['user_group_price'] = iunserializer($goods['user_group_price']);
  510. if (!empty($goods['user_group_price'][$_W['user']['groupid']]['price'])) {
  511. $goods['price'] = $goods['user_group_price'][$_W['user']['groupid']]['price'];
  512. }
  513. }
  514. if (in_array($goods['type'], array(STORE_TYPE_MODULE, STORE_TYPE_WXAPP_MODULE, STORE_TYPE_API))) {
  515. $goods['module'] = module_fetch ($goods['module']);
  516. $goods['slide'] = iunserializer ($goods['slide']);
  517. } elseif (in_array($goods['type'], array(STORE_TYPE_ACCOUNT, STORE_TYPE_WXAPP))) {
  518. $goods['title'] = $goods['type'] == STORE_TYPE_ACCOUNT ? '公众号' : '小程序';
  519. $goods['num'] = $goods['type'] == STORE_TYPE_ACCOUNT ? $goods['account_num'] : $goods['wxapp_num'];
  520. } elseif ($goods['type'] == STORE_TYPE_PACKAGE) {
  521. $module_groups = uni_groups();
  522. } elseif ($goods['type'] == STORE_TYPE_USER_PACKAGE) {
  523. $user_group_info = pdo_fetch("SELECT * FROM ".tablename('users_group') . " WHERE id = :id", array(':id' => $goods['user_group']));
  524. $user_group_info['package'] = iunserializer($user_group_info['package']);
  525. if (!empty($user_group_info['package']) && in_array(-1, $user_group_info['package'])) {
  526. $user_group_info['package_all'] = true;
  527. }
  528. $module_groups = uni_groups();
  529. if (!empty($module_groups)) {
  530. foreach ($module_groups as $key => &$module) {
  531. if (!empty($user_group_info['package']) && in_array($key, $user_group_info['package'])) {
  532. $user_group_info['package_info'][] = $module;
  533. }
  534. }
  535. }
  536. }
  537. $account_table = table ('account');
  538. $user_account = $account_table->userOwnedAccount();
  539. $wxapp_account_list = array();
  540. if (!empty($user_account) && is_array($user_account)) {
  541. foreach ($user_account as $key => $account) {
  542. $default_account = uni_fetch($account['uniacid']);
  543. if (in_array($goods['type'], array(STORE_TYPE_MODULE, STORE_TYPE_ACCOUNT_RENEW)) && !in_array($default_account['type'], array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH)) || in_array($goods['type'], array(STORE_TYPE_WXAPP_MODULE, STORE_TYPE_WXAPP_RENEW)) && !in_array($default_account['type'], array(ACCOUNT_TYPE_APP_NORMAL, ACCOUNT_TYPE_APP_AUTH))) {
  544. unset($user_account[$key]);
  545. }
  546. if (in_array($goods['type'], array(STORE_TYPE_ACCOUNT_RENEW, STORE_TYPE_WXAPP_RENEW)) && $default_account['endtime'] <= 0) {
  547. unset($user_account[$key]);
  548. }
  549. if ($goods['type'] == STORE_TYPE_PACKAGE && !empty($module_groups[$goods['module_group']]['wxapp']) && $default_account['type'] == 4) {
  550. $wxapp_account_list[] = array('uniacid' => $default_account['uniacid'], 'name' => $default_account['name']);
  551. unset($user_account[$key]);
  552. }
  553. }
  554. }
  555. reset($user_account);
  556. reset($wxapp_account_list);
  557. $default_account = current($user_account);
  558. $default_account = !empty($_GPC['uniacid']) ? $_GPC['uniacid'] : $default_account['uniacid'];
  559. $default_wxapp = current($wxapp_account_list);
  560. $default_wxapp = !empty($_GPC['wxapp']) ? $_GPC['wxapp'] : $default_wxapp['uniacid'];
  561. if (in_array($goods['type'], array(STORE_TYPE_MODULE, STORE_TYPE_WXAPP_MODULE)) && empty($user_account)) {
  562. $type_name = $goods['type'] == STORE_TYPE_MODULE ? '公众号' : '小程序';
  563. itoast("您没有可操作的{$type_name},请先创建{$type_name}后购买模块.", referer(), 'info');
  564. }
  565. $pay_way = array();
  566. if (!empty($_W['setting']['store_pay']) && is_array($_W['setting']['store_pay']) && ($_W['setting']['store_pay']['alipay']['switch'] == 1 || $_W['setting']['store_pay']['wechat']['switch'] == 1)) {
  567. foreach ($_W['setting']['store_pay'] as $way => $setting) {
  568. if ($setting['switch'] == 1) {
  569. $pay_way[$way] = $setting;
  570. if ($way == 'alipay') {
  571. $pay_way[$way]['title'] = '支付宝';
  572. } elseif ($way == 'wechat') {
  573. $pay_way[$way]['title'] = '微信';
  574. }
  575. }
  576. }
  577. } else {
  578. itoast('没有有效的支付方式.', referer(), 'info');
  579. }
  580. }
  581. if ($operate == 'get_expiretime') {
  582. $duration = intval ($_GPC['duration']);
  583. $date = date ('Y-m-d', strtotime ('+' . $duration . $_GPC['unit'], time ()));
  584. iajax (0, $date);
  585. }
  586. if ($operate == 'submit_order') {
  587. $uniacid = intval ($_GPC['uniacid']);
  588. $wxapp = intval ($_GPC['wxapp']);
  589. $goodsid = intval($_GPC['goodsid']);
  590. if (intval($_GPC['duration']) <= 0) {
  591. iajax(-1, '购买时长不合法,请重新填写!');
  592. }
  593. if (empty($_GPC['type'])) {
  594. iajax(-1, '请选择支付方式。');
  595. }
  596. if (empty($goodsid)) {
  597. iajax(-1, '参数错误!');
  598. }
  599. $user_account = table('account')->userOwnedAccount();
  600. $goods_info = store_goods_info($goodsid);
  601. if (!user_is_founder($_W['uid']) && !empty($_W['user']['groupid'])) {
  602. $goods_info['user_group_price'] = iunserializer($goods_info['user_group_price']);
  603. if (!empty($goods_info['user_group_price'][$_W['user']['groupid']]['price'])) {
  604. $goods_info['price'] = $goods_info['user_group_price'][$_W['user']['groupid']]['price'];
  605. }
  606. }
  607. if (in_array($goods_info['type'], array(STORE_TYPE_MODULE, STORE_TYPE_WXAPP_MODULE, STORE_TYPE_API, STORE_TYPE_ACCOUNT_RENEW, STORE_TYPE_WXAPP_RENEW))) {
  608. if (empty($uniacid)) {
  609. iajax(-1, '请选择公众号!');
  610. }
  611. if (empty($user_account[$uniacid])) {
  612. iajax(-1, '非法公众号!');
  613. }
  614. }
  615. if ($goods_info['type'] == STORE_TYPE_PACKAGE) {
  616. if (empty($uniacid) && empty($wxapp)) {
  617. iajax(-1, '请选择公众号!');
  618. }
  619. if (!empty($uniacid) && (empty($user_account[$uniacid]) || in_array($user_account[$uniacid]['type'], array(ACCOUNT_TYPE_APP_NORMAL, ACCOUNT_TYPE_APP_AUTH, ACCOUNT_TYPE_WXAPP_WORK)))) {
  620. iajax(-1, '非法公众号!');
  621. }
  622. if (!empty($wxapp) && (empty($user_account[$wxapp]) || !in_array($user_account[$wxapp]['type'], array(ACCOUNT_TYPE_APP_NORMAL, ACCOUNT_TYPE_APP_AUTH, ACCOUNT_TYPE_WXAPP_WORK)))) {
  623. iajax(-1, '非法小程序!');
  624. }
  625. }
  626. if (empty($goods_info)) {
  627. iajax(-1, '商品不存在!');
  628. }
  629. $uid = empty($_W['uid']) ? '000000' : sprintf ("%06d", $_W['uid']);
  630. $orderid = date ('YmdHis') . $uid . random (8, 1);
  631. $duration = intval ($_GPC['duration']);
  632. $order = array (
  633. 'orderid' => $orderid,
  634. 'duration' => $duration,
  635. 'amount' => $goods_info['price'] * $duration,
  636. 'goodsid' => $goodsid,
  637. 'buyer' => $_W['user']['username'],
  638. 'buyerid' => $_W['uid'],
  639. 'type' => STORE_ORDER_PLACE,
  640. 'createtime' => time(),
  641. 'uniacid' => $uniacid,
  642. 'wxapp' => $wxapp
  643. );
  644. if (in_array($goods_info['type'], array(STORE_TYPE_ACCOUNT, STORE_TYPE_WXAPP, STORE_TYPE_MODULE, STORE_TYPE_WXAPP_MODULE, STORE_TYPE_PACKAGE, STORE_TYPE_USER_PACKAGE))) {
  645. $history_order_endtime = pdo_getcolumn('site_store_order', array('goodsid' => $goodsid, 'buyerid' => $_W['uid'], 'uniacid' => $uniacid, 'type' => STORE_ORDER_FINISH), 'max(endtime)');
  646. $order['endtime'] = strtotime('+' . $duration . $goods_info['unit'], max($history_order_endtime, time()));
  647. }
  648. if (in_array($goods_info['type'], array(STORE_TYPE_WXAPP, STORE_TYPE_WXAPP_RENEW))) {
  649. $order['wxapp'] = $order['uniacid'];
  650. $order['uniacid'] = 0;
  651. }
  652. pdo_insert ('site_store_order', $order);
  653. $store_orderid = pdo_insertid();
  654. $type_name = $this->getTypeName($goods_info['type']);
  655. $content = $_W['user']['username'] . date("Y-m-d H:i:s") . '在商城订购了' . $type_name . ', 商品金额 ' . $order['amount'];
  656. message_notice_record($content, $_W['uid'], $orderid, MESSAGE_ORDER_TYPE);
  657. $pay_log = array(
  658. 'type' => $_GPC['type'],
  659. 'uniontid' => $orderid,
  660. 'tid' => $store_orderid,
  661. 'fee' => $order['amount'],
  662. 'card_fee' => $order['amount'],
  663. 'module' => 'store'
  664. );
  665. pdo_insert('core_paylog', $pay_log);
  666. iajax (0, $store_orderid);
  667. }
  668. if ($operate == 'pay_order') {
  669. $orderid = intval ($_GPC['orderid']);
  670. $order = pdo_get ('site_store_order', array ('id' => $orderid));
  671. $goods = pdo_get ('site_store_goods', array ('id' => $order['goodsid']));
  672. if (empty($order)) {
  673. itoast ('订单不存在', referer (), 'info');
  674. }
  675. if ($order['type'] != 1) {
  676. $message = $order['type'] == 2 ? '订单已删除.' : '订单已付款成功';
  677. itoast ($message, referer (), 'info');
  678. } else {
  679. if ($order['amount'] == 0) {
  680. $history_order_endtime = pdo_getcolumn('site_store_order', array('goodsid' => $goods['id'], 'buyerid' => $_W['uid'], 'uniacid' => $order['uniacid'], 'type' => STORE_ORDER_FINISH), 'max(endtime)');
  681. $endtime = strtotime('+' . $order['duration'] . $goods['unit'], max($history_order_endtime, time()));
  682. pdo_update('site_store_order', array('type' => 3, 'endtime' => $endtime), array('id' => $order['id']));
  683. pdo_update('core_paylog', array('status' => 1), array('uniontid' => $order['orderid']));
  684. if (in_array($goods['type'], array(STORE_TYPE_ACCOUNT_RENEW, STORE_TYPE_WXAPP_RENEW))) {
  685. $account_type = $goods['type'] == STORE_TYPE_ACCOUNT_RENEW ? 'uniacid' : 'wxapp';
  686. $account_num = $goods['type'] == STORE_TYPE_ACCOUNT_RENEW ? $goods['account_num'] : $goods['wxapp_num'];
  687. $account_info = uni_fetch($order[$account_type]);
  688. $account_endtime = strtotime('+' . $order['duration'] * $account_num . $goods['unit'], max(TIMESTAMP, $account_info['endtime']));
  689. pdo_update('account', array('endtime' => $account_endtime), array('uniacid' => $order[$account_type]));
  690. cache_delete(cache_system_key('uniaccount_type', array('account_type' => $order[$account_type])));
  691. }
  692. if ($goods['type'] == STORE_TYPE_USER_PACKAGE) {
  693. $data['uid'] = $_W['uid'];
  694. $user = user_single($data['uid']);
  695. if ($user['status'] == USER_STATUS_CHECK || $user['status'] == USER_STATUS_BAN) {
  696. iajax(-1, '访问错误,该用户未审核或者已被禁用,请先修改用户状态!', '');
  697. }
  698. $data['groupid'] = $goods['user_group'];
  699. $data['endtime'] = $order['endtime'];
  700. cache_delete(cache_system_key('system_frame', array('uniacid' => $_W['uniacid'])));
  701. if (!user_update($data)) {
  702. iajax(1, '修改权限失败', '');
  703. }
  704. }
  705. cache_build_account_modules($order['uniacid']);
  706. $content = $_W['user']['username'] . date("Y-m-d H:i:s") . '在商城成功支付' . $order['amount'] . '¥';
  707. message_notice_record($content, $_W['uid'], $orderid, MESSAGE_ORDER_PAY_TYPE);
  708. itoast('支付成功!', $this->createWebUrl('orders', array('direct' => 1)), 'success');
  709. }
  710. }
  711. $setting = setting_load ('store_pay');
  712. $core_paylog = pdo_get('core_paylog', array('module' => 'store', 'status' => 0, 'module' => 'store', 'uniontid' => $order['orderid'], 'tid' => $order['id']));
  713. if ($core_paylog['type'] == 'wechat') {
  714. $wechat_setting = $setting['store_pay']['wechat'];
  715. $params = array(
  716. 'pay_way' => 'web',
  717. 'title' => $goods['title'],
  718. 'uniontid' => $order['orderid'],
  719. 'fee' => $order['amount'],
  720. 'goodsid' => $goods['id'],
  721. );
  722. $wechat_setting['version'] = 2;
  723. $wechat_result = wechat_build($params, $wechat_setting);
  724. if (is_error($wechat_result)) {
  725. itoast($wechat_result['message'], $this->createWebUrl('goodsBuyer', array('direct' => 1)), 'info');
  726. }
  727. file_delete('store_wechat_pay_' . $_W['uid'] . '.png');
  728. $picture_attach = 'store_wechat_pay_' . $_W['uid'] . '.png';
  729. $picture = $_W['siteroot'] . 'attachment/' . $picture_attach;
  730. QRcode::png($wechat_result['code_url'], ATTACHMENT_ROOT . $picture_attach);
  731. include $this->template('wechat_pay_qrcode');
  732. } elseif ($core_paylog['type'] == 'alipay') {
  733. $alipay_setting = $setting['store_pay']['alipay'];
  734. $alipay_params = array (
  735. 'service' => 'create_direct_pay_by_user',
  736. 'title' => $goods['title'],
  737. 'fee' => $order['amount'],
  738. 'uniontid' => $order['orderid'],
  739. );
  740. $alipay_result = alipay_build($alipay_params, $alipay_setting);
  741. header ('Location: ' . $alipay_result['url']);
  742. }
  743. exit();
  744. }
  745. include $this->template ('goodsbuyer');
  746. }
  747. public function doWebPermission() {
  748. global $_W, $_GPC;
  749. $this->storeIsOpen();
  750. $operation = trim($_GPC['operation']);
  751. $operations = array('display', 'post', 'delete', 'change_status');
  752. $operation = in_array($operation, $operations) ? $operation : 'display';
  753. $blacklist = (array)$this->store_setting['blacklist'];
  754. $whitelist = (array)$this->store_setting['whitelist'];
  755. $permission_status = (array)$this->store_setting['permission_status'];
  756. if ($operation == 'display') {
  757. include $this->template('permission');
  758. }
  759. if ($operation == 'post') {
  760. $username = safe_gpc_string($_GPC['username']);
  761. $type = in_array($_GPC['type'], array('black', 'white')) ? $_GPC['type'] : '';
  762. if (empty($type)) {
  763. message(error(-1, '参数错误!'), referer(), 'ajax');
  764. }
  765. $user_exist = pdo_get('users', array('username' => $username));
  766. if (empty($user_exist)) {
  767. message(error(-1, '用户不存在!'), $this->createWebUrl('permission', array('type' => $type, 'direct' =>1)), 'ajax');
  768. }
  769. if (in_array($username, $blacklist)) {
  770. message(error(-1, '用户已在黑名单中!'), $this->createWebUrl('permission', array('type' => $type, 'direct' =>1)), 'ajax');
  771. }
  772. if (in_array($username, $whitelist)) {
  773. message(error(-1, '用户已在白名单中!'), $this->createWebUrl('permission', array('type' => $type, 'direct' =>1)), 'ajax');
  774. }
  775. if ($type == 'black') {
  776. array_push($blacklist, $username);
  777. $this->store_setting['blacklist'] = $blacklist;
  778. }
  779. if ($type == 'white') {
  780. array_push($whitelist, $username);
  781. $this->store_setting['whitelist'] = $whitelist;
  782. }
  783. setting_save($this->store_setting, 'store');
  784. cache_build_frame_menu();
  785. message(error(0, '更新成功!'), $this->createWebUrl('permission', array('type' => $type, 'direct' =>1)), 'ajax');
  786. }
  787. if ($operation == 'change_status') {
  788. $type = in_array($_GPC['type'], array('black', 'white', 'close')) ? $_GPC['type'] : '';
  789. if (empty($type)) {
  790. message(error(-1, '参数错误!'), referer(), 'ajax');
  791. }
  792. if ($type == 'black') {
  793. $permission_status['blacklist'] = !$permission_status['blacklist'];
  794. if (!empty($permission_status['blacklist'])) {
  795. if (!empty($permission_status['whitelist'])) {
  796. message(error(-1, '请先关闭白名单!'), referer(), 'ajax');
  797. }
  798. if (!empty($permission_status['close'])) {
  799. $permission_status['close'] = false;
  800. }
  801. }
  802. }
  803. if ($type == 'white') {
  804. $permission_status['whitelist'] = !$permission_status['whitelist'];
  805. $permission_status['blacklist'] = !empty($permission_status['whitelist']) ? false : $permission_status['blacklist'];
  806. if (!empty($permission_status['whitelist']) && !empty($permission_status['close'])) {
  807. $permission_status['close'] = false;
  808. }
  809. }
  810. if ($type == 'close') {
  811. $permission_status['close'] = !$permission_status['close'];
  812. if (!empty($permission_status['close'])) {
  813. $permission_status['whitelist'] = $permission_status['blacklist'] = false;
  814. }
  815. }
  816. $this->store_setting['permission_status'] = $permission_status;
  817. setting_save($this->store_setting, 'store');
  818. cache_build_frame_menu();
  819. message(error(0, '更新成功!'), $this->createWebUrl('permission', array('type' => $type, 'direct' => 1), 'ajax'));
  820. }
  821. if ($operation == 'delete') {
  822. $username = safe_gpc_string($_GPC['username']);
  823. $type = in_array($_GPC['type'], array('black', 'white')) ? $_GPC['type'] : '';
  824. if (empty($username) || empty($type)) {
  825. message(error(-1, '参数错误!'), referer(),'ajax');
  826. }
  827. if ($type == 'white') {
  828. if (!in_array($username, $whitelist)) {
  829. message(error(-1, '用户不在白名单中!'), $this->createWebUrl('permission', array('type' => $type, 'direct' =>1)), 'ajax');
  830. }
  831. foreach ($whitelist as $key => $val) {
  832. if ($val == $username) {
  833. unset($whitelist[$key]);
  834. }
  835. }
  836. $this->store_setting['whitelist'] = $whitelist;
  837. }
  838. if ($type == 'black') {
  839. if (!in_array($username, $blacklist)) {
  840. message(error(-1, '用户不在黑名单中!'), $this->createWebUrl('permission', array('type' => $type, 'direct' =>1)), 'ajax');
  841. }
  842. foreach ($blacklist as $key => $val) {
  843. if ($val == $username) {
  844. unset($blacklist[$key]);
  845. }
  846. }
  847. $this->store_setting['blacklist'] = $blacklist;
  848. }
  849. setting_save($this->store_setting, 'store');
  850. cache_build_frame_menu();
  851. message(error(0, '删除成功!'), $this->createWebUrl('permission', array('type' => $type, 'direct' =>1)), 'ajax');
  852. }
  853. }
  854. public function leftMenu() {
  855. $this->storeIsOpen();
  856. $menu = array(
  857. 'store_goods' => array(
  858. 'title' => '商品分类',
  859. 'menu' => array(
  860. 'store_goods_module' =>array(
  861. 'title' => '公众号应用',
  862. 'url' => $this->createWebUrl('goodsbuyer', array('direct' => 1, 'type' => STORE_TYPE_MODULE)),
  863. 'icon' => 'wi wi-apply',
  864. 'type' => STORE_TYPE_MODULE,
  865. ),
  866. 'store_goods_wxapp_module' => array(
  867. 'title' => '小程序应用',
  868. 'url' => $this->createWebUrl('goodsbuyer', array('direct' => 1, 'type' => STORE_TYPE_WXAPP_MODULE)),
  869. 'icon' => 'wi wi-small-routine',
  870. 'type' => STORE_TYPE_WXAPP_MODULE,
  871. ),
  872. 'store_goods_account' => array(
  873. 'title' => '公众号个数',
  874. 'url' => $this->createWebUrl('goodsbuyer', array('direct' => 1, 'type' => STORE_TYPE_ACCOUNT)),
  875. 'icon' => 'wi wi-wechat',
  876. 'type' => STORE_TYPE_ACCOUNT,
  877. ),
  878. 'store_goods_wxapp' => array(
  879. 'title' => '小程序个数',
  880. 'url' => $this->createWebUrl('goodsbuyer', array('direct' => 1, 'type' => STORE_TYPE_WXAPP)),
  881. 'icon' => 'wi wi-wxapp',
  882. 'type' => STORE_TYPE_WXAPP,
  883. ),
  884. 'store_goods_api' => array(
  885. 'title' => '应用访问流量(API)',
  886. 'url' => $this->createWebUrl('goodsbuyer', array('direct' => 1, 'type' => STORE_TYPE_API)),
  887. 'icon' => 'wi wi-api',
  888. 'type' => STORE_TYPE_API,
  889. ),
  890. 'store_goods_package' => array(
  891. 'title' => '应用权限组',
  892. 'url' => $this->createWebUrl('goodsbuyer', array('direct' => 1, 'type' => STORE_TYPE_PACKAGE)),
  893. 'icon' => 'wi wi-appjurisdiction',
  894. 'type' => STORE_TYPE_PACKAGE,
  895. ),
  896. 'store_goods_users_package' => array(
  897. 'title' => '用户权限组',
  898. 'url' => $this->createWebUrl('goodsbuyer', array('direct' => 1, 'type' => STORE_TYPE_USER_PACKAGE)),
  899. 'icon' => 'wi wi-userjurisdiction',
  900. 'type' => STORE_TYPE_USER_PACKAGE,
  901. ),
  902. 'store_goods_account_renew' => array(
  903. 'title' => '公众号续费',
  904. 'url' => $this->createWebUrl('goodsbuyer', array('direct' => 1, 'type' => STORE_TYPE_ACCOUNT_RENEW)),
  905. 'icon' => 'wi wi-appjurisdiction',
  906. 'type' => STORE_TYPE_ACCOUNT_RENEW,
  907. ),
  908. 'store_goods_wxapp_renew' => array(
  909. 'title' => '小程序续费',
  910. 'url' => $this->createWebUrl('goodsbuyer', array('direct' => 1, 'type' => STORE_TYPE_WXAPP_RENEW)),
  911. 'icon' => 'wi wi-appjurisdiction',
  912. 'type' => STORE_TYPE_WXAPP_RENEW,
  913. ),
  914. ),
  915. ),
  916. 'store_manage' => array(
  917. 'title' => '商城管理',
  918. 'founder' => true,
  919. 'menu' => array(
  920. 'store_manage_goods' => array(
  921. 'title' => '添加商品',
  922. 'url' => $this->createWebUrl('goodsSeller', array('direct' => 1)),
  923. 'icon' => 'wi wi-goods-add',
  924. 'type' => 'goodsSeller',
  925. ),
  926. 'store_manage_setting' => array(
  927. 'title' => '商城设置',
  928. 'url' => $this->createWebUrl('setting', array('direct' => 1)),
  929. 'icon' => 'wi wi-store',
  930. 'type' => 'setting',
  931. ),
  932. 'store_manage_payset' => array(
  933. 'title' => '支付设置',
  934. 'url' => $this->createWebUrl('paySetting', array('direct' => 1)),
  935. 'icon' => 'wi wi-account',
  936. 'type' => 'paySetting',
  937. ),
  938. 'store_manage_permission' => array(
  939. 'title' => '商城访问权限',
  940. 'url' => $this->createWebUrl('permission', array('direct' => 1)),
  941. 'icon' => 'wi wi-blacklist',
  942. 'type' => 'blacklist',
  943. ),
  944. )
  945. ),
  946. 'store_orders' => array(
  947. 'title' => '订单管理',
  948. 'menu' => array(
  949. 'store_orders_my' => array(
  950. 'title' => '我的订单',
  951. 'url' => $this->createWebUrl('orders', array('direct' => 1)),
  952. 'icon' => 'wi wi-sale-record',
  953. 'type' => 'orders',
  954. ),
  955. ),
  956. ),
  957. 'store_payments' => array(
  958. 'title' => '收入明细',
  959. 'menu' => array(
  960. 'payments' => array (
  961. 'title' => '收入明细',
  962. 'url' => $this->createWebUrl('payments', array('direct' => 1)),
  963. 'icon' => 'wi wi-sale-record',
  964. 'type' => 'payments',
  965. )
  966. )
  967. ),
  968. );
  969. return $menu;
  970. }
  971. public function doWebPay() {
  972. $this->storeIsOpen();
  973. global $_GPC, $_W;
  974. $operate = $_GPC['operate'];
  975. $operates = array ('check_pay_result');
  976. $operate = in_array ($operate, $operates) ? $operate : 'check_pay_result';
  977. if ($operate == 'check_pay_result') {
  978. $orderid = intval($_GPC['orderid']);
  979. $pay_type = pdo_getcolumn('site_store_order', array('id' => $orderid), 'type');
  980. if ($pay_type == STORE_ORDER_FINISH) {
  981. iajax(1);
  982. } else {
  983. iajax(2);
  984. }
  985. }
  986. }
  987. public function doWebPayments() {
  988. global $_W, $_GPC;
  989. $pindex = max(1, $_GPC['page']);
  990. $pagesize = 20;
  991. $store_table = table('store');
  992. $payments_list = $store_table->searchPaymentsOrder();
  993. $pager = pagination(count($payments_list), $pindex, $pagesize);
  994. $payments_list = array_slice($payments_list, ($pindex - 1) * $pagesize, $pagesize);
  995. include $this->template ('goodspayments');
  996. }
  997. public function doWebChangeOrderExpire() {
  998. global $_GPC, $_W;
  999. $uniacid = intval($_GPC['uniacid']);
  1000. $goodsid = intval($_GPC['goodsid']);
  1001. $duration = intval($_GPC['duration']);
  1002. $unit = safe_gpc_string($_GPC['unit']);
  1003. if (empty($uniacid) || empty($goodsid) && empty($duration) && empty($unit)) {
  1004. iajax(-1, '提交数据不完整!');
  1005. }
  1006. $endtime_old = pdo_getcolumn('site_store_order', array('goodsid' => $goodsid, 'buyerid' => $_W['uid'], 'uniacid' => $uniacid, 'type' => STORE_ORDER_FINISH), 'max(endtime)');
  1007. $endtime_new = strtotime('+' . $duration . $unit, max($endtime_old, time()));
  1008. iajax(0, date('Y-m-d H:i:s', $endtime_new));
  1009. }
  1010. public function doWebDeactivateOrder() {
  1011. global $_GPC;
  1012. $order_id = intval($_GPC['order_id']);
  1013. $goods_id = intval($_GPC['goods_id']);
  1014. $uniacid = intval($_GPC['uniacid']);
  1015. $type = intval($_GPC['type']);
  1016. $condition = array('id' => $order_id, 'goodsid' => $goods_id, 'uniacid' => $uniacid);
  1017. $order_info = pdo_get('site_store_order', $condition, '');
  1018. if (empty($order_info)) {
  1019. itoast('订单信息错误!', '', 'error');
  1020. }
  1021. $res = pdo_update('site_store_order', array('type' => STORE_ORDER_DEACTIVATE), $condition);
  1022. if (!$res) {
  1023. itoast('修改失败!', '', 'error');
  1024. } else{
  1025. $cachekey = cache_system_key('site_store_buy', array('type' => $type, 'uniacid' => $uniacid));
  1026. cache_delete($cachekey);
  1027. itoast('修改成功!', '', 'success');
  1028. }
  1029. }
  1030. }