人人商城

site.php 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 CoreModuleSite extends WeModuleSite {
  8. public function doMobilePaymethod() {
  9. global $_W, $_GPC;
  10. $params = array(
  11. 'fee' => floatval($_GPC['fee']),
  12. 'tid' => $_GPC['tid'],
  13. 'module' => $_GPC['module'],
  14. );
  15. if (empty($params['tid']) || empty($params['fee']) || empty($params['module'])) {
  16. message(error(1, '支付参数不完整'));
  17. }
  18. if($params['fee'] <= 0) {
  19. $notify_params = array(
  20. 'form' => 'return',
  21. 'result' => 'success',
  22. 'type' => '',
  23. 'tid' => $params['tid'],
  24. );
  25. $site = WeUtility::createModuleSite($params['module']);
  26. $method = 'payResult';
  27. if (method_exists($site, $method)) {
  28. $site->$method($notify_params);
  29. message(error(-1, '支付成功'));
  30. }
  31. }
  32. $log = pdo_get('core_paylog', array('uniacid' => $_W['uniacid'], 'module' => $params['module'], 'tid' => $params['tid']));
  33. if (empty($log)) {
  34. $log = array(
  35. 'uniacid' => $_W['uniacid'],
  36. 'acid' => $_W['acid'],
  37. 'openid' => $_W['member']['uid'],
  38. 'module' => $params['module'],
  39. 'tid' => $params['tid'],
  40. 'fee' => $params['fee'],
  41. 'card_fee' => $params['fee'],
  42. 'status' => '0',
  43. 'is_usecard' => '0',
  44. );
  45. pdo_insert('core_paylog', $log);
  46. }
  47. if($log['status'] == '1') {
  48. message(error(1, '订单已经支付'));
  49. }
  50. $setting = uni_setting($_W['uniacid'], array('payment', 'creditbehaviors'));
  51. if(!is_array($setting['payment'])) {
  52. message(error(1, '暂无有效支付方式'));
  53. }
  54. $pay = $setting['payment'];
  55. if (empty($_W['member']['uid'])) {
  56. $pay['credit']['switch'] = false;
  57. }
  58. if (!empty($pay['credit']['switch'])) {
  59. $credtis = mc_credit_fetch($_W['member']['uid']);
  60. }
  61. include $this->template('pay');
  62. }
  63. public function doMobilePay() {
  64. global $_W, $_GPC;
  65. $moduels = uni_modules();
  66. $params = $_POST;
  67. if(empty($params) || !array_key_exists($params['module'], $moduels)) {
  68. message(error(1, '模块不存在'), '', 'ajax', true);
  69. }
  70. $setting = uni_setting($_W['uniacid'], 'payment');
  71. $dos = array();
  72. if(!empty($setting['payment']['credit']['switch'])) {
  73. $dos[] = 'credit';
  74. }
  75. if(!empty($setting['payment']['alipay']['switch'])) {
  76. $dos[] = 'alipay';
  77. }
  78. if(!empty($setting['payment']['wechat']['switch'])) {
  79. $dos[] = 'wechat';
  80. }
  81. if(!empty($setting['payment']['delivery']['switch'])) {
  82. $dos[] = 'delivery';
  83. }
  84. if(!empty($setting['payment']['unionpay']['switch'])) {
  85. $dos[] = 'unionpay';
  86. }
  87. if(!empty($setting['payment']['baifubao']['switch'])) {
  88. $dos[] = 'baifubao';
  89. }
  90. $type = in_array($params['method'], $dos) ? $params['method'] : '';
  91. if(empty($type)) {
  92. message(error(1, '暂无有效支付方式,请联系商家'), '', 'ajax', true);
  93. }
  94. $moduleid = pdo_getcolumn('modules', array('name' => $params['module']), 'mid');
  95. $moduleid = empty($moduleid) ? '000000' : sprintf("%06d", $moduleid);
  96. $uniontid = date('YmdHis').$moduleid.random(8,1);
  97. $paylog = pdo_get('core_paylog', array('uniacid' => $_W['uniacid'], 'module' => $params['module'], 'tid' => $params['tid']));
  98. if (empty($paylog)) {
  99. $paylog = array(
  100. 'uniacid' => $_W['uniacid'],
  101. 'acid' => $_W['acid'],
  102. 'openid' => $_W['member']['uid'],
  103. 'module' => $params['module'],
  104. 'tid' => $params['tid'],
  105. 'uniontid' => $uniontid,
  106. 'fee' => $params['fee'],
  107. 'card_fee' => $params['fee'],
  108. 'status' => '0',
  109. 'is_usecard' => '0',
  110. );
  111. pdo_insert('core_paylog', $paylog);
  112. $paylog['plid'] = pdo_insertid();
  113. }
  114. if(!empty($paylog) && $paylog['status'] != '0') {
  115. message(error(1, '这个订单已经支付成功, 不需要重复支付.'), '', 'ajax', true);
  116. }
  117. if (!empty($paylog) && empty($paylog['uniontid'])) {
  118. pdo_update('core_paylog', array(
  119. 'uniontid' => $uniontid,
  120. ), array('plid' => $paylog['plid']));
  121. }
  122. $paylog['title'] = $params['title'];
  123. if (intval($_GPC['iswxapp'])) {
  124. message(error(2, $_W['siteroot']."app/index.php?i={$_W['uniacid']}&c=wxapp&a=home&do=go_paycenter&title={$params['title']}&plid={$paylog['plid']}"), '', 'ajax', true);
  125. }
  126. if ($params['method'] == 'wechat') {
  127. return $this->doMobilePayWechat($paylog);
  128. } elseif ($params['method'] == 'alipay') {
  129. return $this->doMobilePayAlipay($paylog);
  130. } else {
  131. $params['tid'] = $paylog['plid'];
  132. $sl = base64_encode(json_encode($params));
  133. $auth = sha1($sl . $_W['uniacid'] . $_W['config']['setting']['authkey']);
  134. message(error(0, $_W['siteroot'] . "/payment/{$type}/pay.php?i={$_W['uniacid']}&auth={$auth}&ps={$sl}"), '', 'ajax', true);
  135. exit();
  136. }
  137. }
  138. private function doMobilePayWechat($paylog = array()) {
  139. global $_W;
  140. load()->model('payment');
  141. pdo_update('core_paylog', array(
  142. 'openid' => $_W['openid'],
  143. 'tag' => iserializer(array('acid' => $_W['acid'], 'uid' => $_W['member']['uid']))
  144. ), array('plid' => $paylog['plid']));
  145. $_W['uniacid'] = $paylog['uniacid'];
  146. $setting = uni_setting($_W['uniacid'], array('payment'));
  147. $wechat_payment = $setting['payment']['wechat'];
  148. $account = pdo_get('account_wechats', array('acid' => $wechat_payment['account']), array('key', 'secret'));
  149. $wechat_payment['appid'] = $account['key'];
  150. $wechat_payment['secret'] = $account['secret'];
  151. $params = array(
  152. 'tid' => $paylog['tid'],
  153. 'fee' => $paylog['card_fee'],
  154. 'user' => $paylog['openid'],
  155. 'title' => urldecode($paylog['title']),
  156. 'uniontid' => $paylog['uniontid'],
  157. );
  158. if (intval($wechat_payment['switch']) == PAYMENT_WECHAT_TYPE_SERVICE || intval($wechat_payment['switch']) == PAYMENT_WECHAT_TYPE_BORROW) {
  159. if (!empty($_W['openid'])) {
  160. $params['sub_user'] = $_W['openid'];
  161. $wechat_payment_params = wechat_proxy_build($params, $wechat_payment);
  162. } else {
  163. $params['tid'] = $paylog['plid'];
  164. $params['title'] = urlencode($params['title']);
  165. $sl = base64_encode(json_encode($params));
  166. $auth = sha1($sl . $paylog['uniacid'] . $_W['config']['setting']['authkey']);
  167. $callback = urlencode($_W['siteroot'] . "payment/wechat/pay.php?i={$_W['uniacid']}&auth={$auth}&ps={$sl}");
  168. $proxy_pay_account = payment_proxy_pay_account();
  169. if (!is_error($proxy_pay_account)) {
  170. $forward = $proxy_pay_account->getOauthCodeUrl($callback, 'we7sid-'.$_W['session_id']);
  171. message(error(2, $forward), $forward, 'ajax');
  172. exit;
  173. }
  174. }
  175. } else {
  176. unset($wechat_payment['sub_mch_id']);
  177. $wechat_payment_params = wechat_build($params, $wechat_payment);
  178. }
  179. if (is_error($wechat_payment_params)) {
  180. message($wechat_payment_params, '', 'ajax', true);
  181. } else {
  182. message(error(0, $wechat_payment_params), '', 'ajax', true);
  183. }
  184. }
  185. private function doMobilePayAlipay($paylog = array()) {
  186. global $_W;
  187. load()->model('payment');
  188. load()->func('communication');
  189. $_W['uniacid'] = $paylog['uniacid'];
  190. $setting = uni_setting($_W['uniacid'], array('payment'));
  191. $params = array(
  192. 'tid' => $paylog['tid'],
  193. 'fee' => $paylog['card_fee'],
  194. 'user' => $paylog['openid'],
  195. 'title' => urldecode($paylog['title']),
  196. 'uniontid' => $paylog['uniontid'],
  197. );
  198. $alipay_payment_params = alipay_build($params, $setting['payment']['alipay']);
  199. if($alipay_payment_params['url']) {
  200. message(error(0, $alipay_payment_params['url']), '', 'ajax', true);
  201. exit();
  202. }
  203. }
  204. public function doMobileDetail() {
  205. global $_W, $_GPC;
  206. $id = intval($_GPC['id']);
  207. $sql = "SELECT * FROM " . tablename('news_reply') . " WHERE `id`=:id";
  208. $row = pdo_fetch($sql, array(':id'=>$id));
  209. $createtime = $row['createtime'];
  210. if (!empty($row['url'])) {
  211. header("Location: ".$row['url']);
  212. exit;
  213. }
  214. if (!empty($row['media_id']) && intval($row['media_id']) != 0) {
  215. $row = pdo_get('wechat_news', array('attach_id' => $row['media_id'], 'displayorder' => $row['displayorder']));
  216. $row['createtime'] = $createtime;
  217. if (!empty($row['content_source_url'])) {
  218. header("Location: ".$row['content_source_url']);
  219. exit;
  220. }
  221. }
  222. $row = istripslashes($row);
  223. $title = $row['title'];
  224. if($_W['os'] == 'android' && $_W['container'] == 'wechat' && $_W['account']['account']) {
  225. $subscribeurl = "weixin://profile/{$_W['account']['account']}";
  226. } else {
  227. $sql = 'SELECT `subscribeurl` FROM ' . tablename('account_wechats') . " WHERE `acid` = :acid";
  228. $subscribeurl = pdo_fetchcolumn($sql, array(':acid' => intval($_W['acid'])));
  229. }
  230. include $this->template('detail');
  231. }
  232. }