site.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 ('pay' != $_GPC['do'] && 'consume' != $_GPC['do']) {
  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 = table('activity_clerks')->getByUid($user['uid'], $_W['uniacid']);
  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'] && '1' != $_GPC['_wechat_logout']) {
  30. $clerk = table('activity_clerks')->getByOpenid($_W['openid'], $_W['uniacid']);
  31. if (!empty($clerk)) {
  32. $user = table('users')->where(array('uid' => $clerk['uid']))->get();
  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'] = safe_gpc_string($_GPC['username']);
  57. $user['password'] = safe_gpc_string($_GPC['password']);
  58. $user = user_single($user);
  59. if (empty($user)) {
  60. message(error(-1, '账号或密码错误'), '', 'ajax');
  61. }
  62. if (1 == $user['status']) {
  63. message(error(-1, '您的账号正在审核或是已经被系统禁止,请联系网站管理员解决'), '', 'ajax');
  64. }
  65. $clerk = table('activity_clerks')->getByUid($user['uid'], $_W['uniacid']);
  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 = safe_gpc_string($_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 ('0' == $period) {
  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. $revenue = table('paycenter_order')
  107. ->where(array(
  108. 'uniacid' => $_W['uniacid'],
  109. 'status' => 1,
  110. 'paytime >=' => $starttime,
  111. 'paytime <=' => $endtime,
  112. 'clerk_id' => intval($_W['user']['clerk_id'])
  113. ))
  114. ->getcolumn('SUM(final_fee)');
  115. return floatval($revenue);
  116. }
  117. public function doMobilePay() {
  118. global $_W, $_GPC;
  119. $id = intval($_GPC['id']);
  120. $order = table('paycenter_order')->getById($id, $_W['uniacid']);
  121. if (empty($order)) {
  122. message('订单不存在或已删除', '', 'error');
  123. }
  124. if (1 == $order['status']) {
  125. message('该订单已付款', '', 'error');
  126. }
  127. if (!empty($_W['member']['uid']) || !empty($_W['fans'])) {
  128. $update = array(
  129. 'uid' => $_W['member']['uid'],
  130. 'openid' => $_W['openid'],
  131. 'nickname' => $_W['fans']['nickname'],
  132. );
  133. table('paycenter_order')
  134. ->where(array(
  135. 'uniacid' => $_W['uniacid'],
  136. 'id' => $id
  137. ))
  138. ->fill($update)
  139. ->save();
  140. $order['uid'] = $_W['member']['uid'];
  141. }
  142. $params['module'] = 'paycenter_order';
  143. $params['tid'] = $order['id'];
  144. $params['ordersn'] = $order['id'];
  145. $params['user'] = $order['uid'];
  146. $params['fee'] = $order['final_fee'];
  147. $params['title'] = $_W['account']['name'] . $order['body'] ? $order['body'] : '收银台收款';
  148. $this->pay($params);
  149. }
  150. public function payResult($params) {
  151. global $_W;
  152. if ('success' == $params['result'] && 'notify' == $params['from']) {
  153. $order = table('paycenter_order')->getById($params['tid'], $_W['uniacid']);
  154. if (!empty($order)) {
  155. if (!empty($params['tag'])) {
  156. $params['tag'] = iunserializer($params['tag']);
  157. }
  158. $data = array(
  159. 'type' => $params['type'],
  160. 'trade_type' => strtolower($params['trade_type']),
  161. 'status' => 1,
  162. 'paytime' => TIMESTAMP,
  163. 'uniontid' => $params['tag']['uniontid'],
  164. 'transaction_id' => $params['tag']['transaction_id'],
  165. 'follow' => intval($params['follow']),
  166. 'final_fee' => $params['card_fee'],
  167. );
  168. if ('credit' == $params['type']) {
  169. $data['credit2'] = $params['card_fee'];
  170. } else {
  171. $data['cash'] = $params['card_fee'];
  172. }
  173. if (1 == $params['is_usecard']) {
  174. $discount_fee = $order['fee'] - $params['card_fee'];
  175. $data['remark'] = "使用优惠券减免{$discount_fee}元";
  176. }
  177. table('paycenter_order')
  178. ->where(array(
  179. 'id' => $params['tid'],
  180. 'uniacid' => $_W['uniacid']
  181. ))
  182. ->fill($data)
  183. ->save();
  184. $cash_data = array(
  185. 'uniacid' => $_W['uniacid'],
  186. 'uid' => $order['uid'],
  187. 'fee' => $order['fee'],
  188. 'final_fee' => $order['final_fee'],
  189. 'credit1' => $order['credit1'],
  190. 'credit1_fee' => $order['credit1_fee'],
  191. 'credit2' => $order['credit2'],
  192. 'cash' => $params['card_fee'],
  193. 'final_cash' => $params['card_fee'],
  194. 'return_cash' => 0,
  195. 'remark' => $order['remark'],
  196. 'clerk_id' => $order['clerk_id'],
  197. 'store_id' => $order['store_id'],
  198. 'clerk_type' => $order['clerk_type'],
  199. 'createtime' => TIMESTAMP,
  200. );
  201. table('mc_cash_record')->fill($cash_data)->save();
  202. }
  203. }
  204. if ('success' == $params['result'] && 'return' == $params['from']) {
  205. message('支付成功!', $this->createMobileUrl('paydetail', array('id' => $params['tid'])), 'success');
  206. }
  207. }
  208. public function doMobilePayDetail() {
  209. global $_W, $_GPC;
  210. $id = intval($_GPC['id']);
  211. $order = table('paycenter_order')->getById($id, $_W['uniacid']);
  212. if (empty($order)) {
  213. message('订单不存在或已删除', '', 'error');
  214. }
  215. if ($order['store_id'] > 0) {
  216. $store = pdo_get('activity_stores', array('id' => $order['store_id']), array('business_name'));
  217. }
  218. include $this->template('paydetail');
  219. }
  220. public function doMobileSelfpay() {
  221. global $_W, $_GPC;
  222. if (checksubmit()) {
  223. $fee = !empty($_GPC['fee']) ? safe_gpc_string($_GPC['fee']) : message('收款金额有误', '', 'error');
  224. $body = !empty($_GPC['body']) ? safe_gpc_string($_GPC['body']) : '收银台收款' . safe_gpc_string($_GPC['fee']);
  225. $openid = !empty($_GPC['openid']) ? safe_gpc_string($_GPC['openid']) : message('用户信息错误', '', 'error');
  226. $clerk = table('activity_clerks')->getById(intval($_GPC['clerk_id']), $_W['uniacid']);
  227. $data = array(
  228. 'uniacid' => $_W['uniacid'],
  229. 'openid' => $openid,
  230. 'nickname' => safe_gpc_string($_GPC['nickname']),
  231. 'uid' => $_W['member']['uid'],
  232. 'clerk_id' => $clerk['id'],
  233. 'clerk_type' => 3,
  234. 'store_id' => $clerk['storeid'],
  235. 'body' => $body,
  236. 'fee' => $fee,
  237. 'final_fee' => $fee,
  238. 'credit_status' => 1,
  239. 'createtime' => TIMESTAMP,
  240. );
  241. table('paycenter_order')->fill($data)->save();
  242. $id = pdo_insertid();
  243. header('location:' . $this->createMobileUrl('pay', array('id' => $id)));
  244. die;
  245. }
  246. $fans = mc_oauth_userinfo();
  247. if (is_error($fans) || empty($fans)) {
  248. message('获取粉丝信息失败', '', 'error');
  249. }
  250. include $this->template('selfpay');
  251. }
  252. public function doMobileConsume() {
  253. global $_GPC, $_W;
  254. $url = murl('entry', array('m' => 'we7_coupon', 'do' => 'consume', 'card_id' => intval($_GPC['card_id']), 'encrypt_code' => safe_gpc_string($_GPC['encrypt_code']), 'openid' => safe_gpc_string($_GPC['openid'])));
  255. header("Location: $url");
  256. exit;
  257. }
  258. }