site.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 PaycenterModuleSite extends WeModuleSite {
  8. public function __construct() {
  9. global $_W, $_GPC;
  10. load()->model('paycenter');
  11. if($_GPC['do'] != 'pay' && $_GPC['do'] != 'consume') {
  12. $session = json_decode(base64_decode($_GPC['_pc_session']), true);
  13. if(is_array($session)) {
  14. load()->model('user');
  15. $user = user_single(array('uid'=>$session['uid']));
  16. if(is_array($user) && $session['hash'] === $user['hash']) {
  17. $clerk = pdo_get('activity_clerks', array('uniacid' => $_W['uniacid'], 'uid' => $user['uid']));
  18. if(empty($clerk)) {
  19. message('您没有管理该店铺的权限', referer(), 'error');
  20. }
  21. $_W['uid'] = $user['uid'];
  22. $_W['username'] = $user['username'];
  23. $_W['user'] = $user;
  24. } else {
  25. isetcookie('_pc_session', false, -100);
  26. }
  27. unset($user);
  28. }
  29. if(empty($_W['user']) && $_W['openid'] && $_GPC['_wechat_logout'] != '1') {
  30. $clerk = pdo_get('activity_clerks', array('openid' => $_W['openid'], 'uniacid' => $_W['uniacid']));
  31. if(!empty($clerk)) {
  32. $user = pdo_get('users', array('uid' => $clerk['uid']));
  33. if(!empty($user)) {
  34. $cookie = array();
  35. $cookie['uid'] = $user['uid'];
  36. $cookie['username'] = $user['username'];
  37. $cookie['hash'] = md5($user['password'] . $user['salt']);
  38. $session = base64_encode(json_encode($cookie));
  39. isetcookie('_pc_session', $session, !empty($_GPC['rember']) ? 7 * 86400 : 0, true);
  40. $_W['uid'] = $user['uid'];
  41. $_W['username'] = $user['username'];
  42. $_W['user'] = $user;
  43. }
  44. }
  45. }
  46. }
  47. }
  48. public function doMobileLogin() {
  49. global $_W, $_GPC;
  50. if(!empty($_W['user'])) {
  51. header('Location:' . $this->createMobileUrl('home'));
  52. die;
  53. }
  54. if($_W['isajax']) {
  55. load()->model('user');
  56. $user['username'] = trim($_GPC['username']);
  57. $user['password'] = trim($_GPC['password']);
  58. $user = user_single($user);
  59. if(empty($user)) {
  60. message(error(-1, '账号或密码错误'), '', 'ajax');
  61. }
  62. if($user['status'] == 1) {
  63. message(error(-1, '您的账号正在审核或是已经被系统禁止,请联系网站管理员解决'), '', 'ajax');
  64. }
  65. $clerk = pdo_get('activity_clerks', array('uniacid' => $_W['uniacid'], 'uid' => $user['uid']));
  66. if(empty($clerk)) {
  67. message(error(-1, '您没有管理该店铺的权限'), '', 'ajax');
  68. }
  69. $cookie = array();
  70. $cookie['uid'] = $user['uid'];
  71. $cookie['hash'] = $user['hash'];
  72. $session = base64_encode(json_encode($cookie));
  73. isetcookie('_pc_session', $session, !empty($_GPC['rember']) ? 7 * 86400 : 0, true);
  74. message(error(0, ''), '', 'ajax');
  75. }
  76. include $this->template('login');
  77. }
  78. public function doMobileLogout() {
  79. isetcookie('_pc_session', '', -10000);
  80. isetcookie('_wechat_logout', '1', 180);
  81. $forward = $_GPC['forward'];
  82. if(empty($forward)) {
  83. $forward = './?refersh';
  84. }
  85. header('Location:' . $this->createMobileUrl('login'));
  86. die;
  87. }
  88. public function doMobileHome() {
  89. global $_W, $_GPC;
  90. paycenter_check_login();
  91. $user_permission = permission_account_user('system');
  92. $today_revenue = $this->revenue(0);
  93. $yesterday_revenue = $this->revenue(-1);
  94. $seven_revenue = $this->revenue(-7);
  95. include $this->template('home');
  96. }
  97. public function revenue($period) {
  98. global $_W;
  99. if($period == '0') {
  100. $starttime = strtotime(date('Y-m-d'));
  101. $endtime = $starttime + 86400;
  102. } else {
  103. $starttime = strtotime(date('Y-m-d',strtotime($period . 'day')));
  104. $endtime = strtotime(date('Y-m-d'));
  105. }
  106. $condition = "WHERE uniacid = :uniacid AND status = 1 AND paytime >= :starttime AND paytime <= :endtime AND clerk_id = :clerk_id";
  107. $params = array(':starttime' => $starttime, ':endtime' => $endtime, ':uniacid' => $_W['uniacid'], ':clerk_id' => intval($_W['user']['clerk_id']));
  108. $revenue = pdo_fetchcolumn("SELECT SUM(final_fee) FROM" . tablename('paycenter_order') . $condition, $params);
  109. return floatval($revenue);
  110. }
  111. public function doMobilePay() {
  112. global $_W, $_GPC;
  113. $id = intval($_GPC['id']);
  114. $order = pdo_get('paycenter_order', array('uniacid' => $_W['uniacid'], 'id' => $id));
  115. if(empty($order)) {
  116. message('订单不存在或已删除', '', 'error');
  117. }
  118. if($order['status'] == 1) {
  119. message('该订单已付款', '', 'error');
  120. }
  121. if(!empty($_W['member']['uid']) || !empty($_W['fans'])) {
  122. $update = array(
  123. 'uid' => $_W['member']['uid'],
  124. 'openid' => $_W['openid'],
  125. 'nickname' => $_W['fans']['nickname']
  126. );
  127. pdo_update('paycenter_order', $update, array('uniacid' => $_W['uniacid'], 'id' => $id));
  128. $order['uid'] = $_W['member']['uid'];
  129. }
  130. $params['module'] = "paycenter_order";
  131. $params['tid'] = $order['id'];
  132. $params['ordersn'] = $order['id'];
  133. $params['user'] = $order['uid'];
  134. $params['fee'] = $order['final_fee'];
  135. $params['title'] = $_W['account']['name'] . $order['body'] ? $order['body'] : '收银台收款';
  136. $this->pay($params);
  137. }
  138. public function payResult($params) {
  139. global $_W;
  140. if($params['result'] == 'success' && $params['from'] == 'notify') {
  141. $order = pdo_get('paycenter_order', array('id' => $params['tid'], 'uniacid' => $_W['uniacid']));
  142. if(!empty($order)) {
  143. if(!empty($params['tag'])) {
  144. $params['tag'] = iunserializer($params['tag']);
  145. }
  146. $data = array(
  147. 'type' => $params['type'],
  148. 'trade_type' => strtolower($params['trade_type']),
  149. 'status' => 1,
  150. 'paytime' => TIMESTAMP,
  151. 'uniontid' => $params['tag']['uniontid'],
  152. 'transaction_id' => $params['tag']['transaction_id'],
  153. 'follow' => intval($params['follow']),
  154. 'final_fee' => $params['card_fee'],
  155. );
  156. if($params['type'] == 'credit') {
  157. $data['credit2'] = $params['card_fee'];
  158. } else {
  159. $data['cash'] = $params['card_fee'];
  160. }
  161. if($params['is_usecard'] == 1) {
  162. $discount_fee = $order['fee'] - $params['card_fee'];
  163. $data['remark'] = "使用优惠券减免{$discount_fee}元";
  164. }
  165. pdo_update('paycenter_order', $data, array('id' => $params['tid'], 'uniacid' => $_W['uniacid']));
  166. $cash_data = array(
  167. 'uniacid' => $_W['uniacid'],
  168. 'uid' => $order['uid'],
  169. 'fee' => $order['fee'],
  170. 'final_fee' => $order['final_fee'],
  171. 'credit1' => $order['credit1'],
  172. 'credit1_fee' => $order['credit1_fee'],
  173. 'credit2' => $order['credit2'],
  174. 'cash' => $params['card_fee'],
  175. 'final_cash' => $params['card_fee'],
  176. 'return_cash' => 0,
  177. 'remark' => $order['remark'],
  178. 'clerk_id' => $order['clerk_id'],
  179. 'store_id' => $order['store_id'],
  180. 'clerk_type' => $order['clerk_type'],
  181. 'createtime' => TIMESTAMP,
  182. );
  183. pdo_insert('mc_cash_record', $cash_data);
  184. }
  185. }
  186. if($params['result'] == 'success' && $params['from'] == 'return') {
  187. message('支付成功!', $this->createMobileUrl('paydetail', array('id' => $params['tid'])), 'success');
  188. }
  189. }
  190. public function doMobilePayDetail() {
  191. global $_W, $_GPC;
  192. $id = intval($_GPC['id']);
  193. $order = pdo_get('paycenter_order', array('id' => $id, 'uniacid' => $_W['uniacid']));
  194. if(empty($order)) {
  195. message('订单不存在或已删除', '', 'error');
  196. }
  197. if($order['store_id'] > 0) {
  198. $store = pdo_get('activity_stores', array('id' => $order['store_id']), array('business_name'));
  199. }
  200. include $this->template('paydetail');
  201. }
  202. public function doMobileSelfpay() {
  203. global $_W, $_GPC;
  204. if(checksubmit()) {
  205. $fee = trim($_GPC['fee']) ? trim($_GPC['fee']) : message('收款金额有误', '', 'error');
  206. $body = trim($_GPC['body']) ? trim($_GPC['body']) : '收银台收款' . trim($_GPC['fee']);
  207. $openid = trim($_GPC['openid']) ? trim($_GPC['openid']) : message('用户信息错误', '', 'error');
  208. $clerk = pdo_get('activity_clerks', array('uniacid' => $_W['uniacid'], 'id' => intval($_GPC['clerk_id'])));
  209. $data = array(
  210. 'uniacid' => $_W['uniacid'],
  211. 'openid' => $openid,
  212. 'nickname' => trim($_GPC['nickname']),
  213. 'uid' => $_W['member']['uid'],
  214. 'clerk_id' => $clerk['id'],
  215. 'clerk_type' => 3,
  216. 'store_id' => $clerk['storeid'],
  217. 'body' => $body,
  218. 'fee' => $fee,
  219. 'final_fee' => $fee,
  220. 'credit_status' => 1,
  221. 'createtime' => TIMESTAMP,
  222. );
  223. pdo_insert('paycenter_order', $data);
  224. $id = pdo_insertid();
  225. header('location:' . $this->createMobileUrl('pay', array('id' => $id)));
  226. die;
  227. }
  228. $fans = mc_oauth_userinfo();
  229. if(is_error($fans) || empty($fans)) {
  230. message('获取粉丝信息失败', '', 'error');
  231. }
  232. include $this->template('selfpay');
  233. }
  234. public function doMobileConsume() {
  235. global $_GPC, $_W;
  236. $url = murl('entry', array('m' => 'we7_coupon', 'do' => 'consume', 'card_id' => trim($_GPC['card_id']), 'encrypt_code' => trim($_GPC['encrypt_code']), 'openid' => trim($_GPC['openid'])));
  237. header("Location: $url");
  238. exit;
  239. }
  240. }