123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- <?php
- /**
- * [WeEngine System] Copyright (c) 2014 WE7.CC
- * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
- */
- defined('IN_IA') or exit('Access Denied');
- class PaycenterModuleSite extends WeModuleSite {
- public function __construct() {
- global $_W, $_GPC;
- load()->model('paycenter');
- if ('pay' != $_GPC['do'] && 'consume' != $_GPC['do']) {
- $session = json_decode(base64_decode($_GPC['_pc_session']), true);
- if (is_array($session)) {
- load()->model('user');
- $user = user_single(array('uid' => $session['uid']));
- if (is_array($user) && $session['hash'] === $user['hash']) {
- $clerk = table('activity_clerks')->getByUid($user['uid'], $_W['uniacid']);
- if (empty($clerk)) {
- message('您没有管理该店铺的权限', referer(), 'error');
- }
- $_W['uid'] = $user['uid'];
- $_W['username'] = $user['username'];
- $_W['user'] = $user;
- } else {
- isetcookie('_pc_session', false, -100);
- }
- unset($user);
- }
- if (empty($_W['user']) && $_W['openid'] && '1' != $_GPC['_wechat_logout']) {
- $clerk = table('activity_clerks')->getByOpenid($_W['openid'], $_W['uniacid']);
- if (!empty($clerk)) {
- $user = table('users')->where(array('uid' => $clerk['uid']))->get();
- if (!empty($user)) {
- $cookie = array();
- $cookie['uid'] = $user['uid'];
- $cookie['username'] = $user['username'];
- $cookie['hash'] = md5($user['password'] . $user['salt']);
- $session = base64_encode(json_encode($cookie));
- isetcookie('_pc_session', $session, !empty($_GPC['rember']) ? 7 * 86400 : 0, true);
- $_W['uid'] = $user['uid'];
- $_W['username'] = $user['username'];
- $_W['user'] = $user;
- }
- }
- }
- }
- }
- public function doMobileLogin() {
- global $_W, $_GPC;
- if (!empty($_W['user'])) {
- header('Location:' . $this->createMobileUrl('home'));
- die;
- }
- if ($_W['isajax']) {
- load()->model('user');
- $user['username'] = safe_gpc_string($_GPC['username']);
- $user['password'] = safe_gpc_string($_GPC['password']);
- $user = user_single($user);
- if (empty($user)) {
- message(error(-1, '账号或密码错误'), '', 'ajax');
- }
- if (1 == $user['status']) {
- message(error(-1, '您的账号正在审核或是已经被系统禁止,请联系网站管理员解决'), '', 'ajax');
- }
- $clerk = table('activity_clerks')->getByUid($user['uid'], $_W['uniacid']);
- if (empty($clerk)) {
- message(error(-1, '您没有管理该店铺的权限'), '', 'ajax');
- }
- $cookie = array();
- $cookie['uid'] = $user['uid'];
- $cookie['hash'] = $user['hash'];
- $session = base64_encode(json_encode($cookie));
- isetcookie('_pc_session', $session, !empty($_GPC['rember']) ? 7 * 86400 : 0, true);
- message(error(0, ''), '', 'ajax');
- }
- include $this->template('login');
- }
- public function doMobileLogout() {
- isetcookie('_pc_session', '', -10000);
- isetcookie('_wechat_logout', '1', 180);
- $forward = safe_gpc_string($_GPC['forward']);
- if (empty($forward)) {
- $forward = './?refersh';
- }
- header('Location:' . $this->createMobileUrl('login'));
- die;
- }
- public function doMobileHome() {
- global $_W, $_GPC;
- paycenter_check_login();
- $user_permission = permission_account_user('system');
- $today_revenue = $this->revenue(0);
- $yesterday_revenue = $this->revenue(-1);
- $seven_revenue = $this->revenue(-7);
- include $this->template('home');
- }
-
- public function revenue($period) {
- global $_W;
- if ('0' == $period) {
- $starttime = strtotime(date('Y-m-d'));
- $endtime = $starttime + 86400;
- } else {
- $starttime = strtotime(date('Y-m-d', strtotime($period . 'day')));
- $endtime = strtotime(date('Y-m-d'));
- }
- $revenue = table('paycenter_order')
- ->where(array(
- 'uniacid' => $_W['uniacid'],
- 'status' => 1,
- 'paytime >=' => $starttime,
- 'paytime <=' => $endtime,
- 'clerk_id' => intval($_W['user']['clerk_id'])
- ))
- ->getcolumn('SUM(final_fee)');
- return floatval($revenue);
- }
- public function doMobilePay() {
- global $_W, $_GPC;
- $id = intval($_GPC['id']);
- $order = table('paycenter_order')->getById($id, $_W['uniacid']);
- if (empty($order)) {
- message('订单不存在或已删除', '', 'error');
- }
- if (1 == $order['status']) {
- message('该订单已付款', '', 'error');
- }
- if (!empty($_W['member']['uid']) || !empty($_W['fans'])) {
- $update = array(
- 'uid' => $_W['member']['uid'],
- 'openid' => $_W['openid'],
- 'nickname' => $_W['fans']['nickname'],
- );
- table('paycenter_order')
- ->where(array(
- 'uniacid' => $_W['uniacid'],
- 'id' => $id
- ))
- ->fill($update)
- ->save();
- $order['uid'] = $_W['member']['uid'];
- }
- $params['module'] = 'paycenter_order';
- $params['tid'] = $order['id'];
- $params['ordersn'] = $order['id'];
- $params['user'] = $order['uid'];
- $params['fee'] = $order['final_fee'];
- $params['title'] = $_W['account']['name'] . $order['body'] ? $order['body'] : '收银台收款';
- $this->pay($params);
- }
- public function payResult($params) {
- global $_W;
- if ('success' == $params['result'] && 'notify' == $params['from']) {
- $order = table('paycenter_order')->getById($params['tid'], $_W['uniacid']);
- if (!empty($order)) {
- if (!empty($params['tag'])) {
- $params['tag'] = iunserializer($params['tag']);
- }
- $data = array(
- 'type' => $params['type'],
- 'trade_type' => strtolower($params['trade_type']),
- 'status' => 1,
- 'paytime' => TIMESTAMP,
- 'uniontid' => $params['tag']['uniontid'],
- 'transaction_id' => $params['tag']['transaction_id'],
- 'follow' => intval($params['follow']),
- 'final_fee' => $params['card_fee'],
- );
- if ('credit' == $params['type']) {
- $data['credit2'] = $params['card_fee'];
- } else {
- $data['cash'] = $params['card_fee'];
- }
- if (1 == $params['is_usecard']) {
- $discount_fee = $order['fee'] - $params['card_fee'];
- $data['remark'] = "使用优惠券减免{$discount_fee}元";
- }
- table('paycenter_order')
- ->where(array(
- 'id' => $params['tid'],
- 'uniacid' => $_W['uniacid']
- ))
- ->fill($data)
- ->save();
- $cash_data = array(
- 'uniacid' => $_W['uniacid'],
- 'uid' => $order['uid'],
- 'fee' => $order['fee'],
- 'final_fee' => $order['final_fee'],
- 'credit1' => $order['credit1'],
- 'credit1_fee' => $order['credit1_fee'],
- 'credit2' => $order['credit2'],
- 'cash' => $params['card_fee'],
- 'final_cash' => $params['card_fee'],
- 'return_cash' => 0,
- 'remark' => $order['remark'],
- 'clerk_id' => $order['clerk_id'],
- 'store_id' => $order['store_id'],
- 'clerk_type' => $order['clerk_type'],
- 'createtime' => TIMESTAMP,
- );
- table('mc_cash_record')->fill($cash_data)->save();
- }
- }
- if ('success' == $params['result'] && 'return' == $params['from']) {
- message('支付成功!', $this->createMobileUrl('paydetail', array('id' => $params['tid'])), 'success');
- }
- }
- public function doMobilePayDetail() {
- global $_W, $_GPC;
- $id = intval($_GPC['id']);
- $order = table('paycenter_order')->getById($id, $_W['uniacid']);
- if (empty($order)) {
- message('订单不存在或已删除', '', 'error');
- }
- if ($order['store_id'] > 0) {
- $store = pdo_get('activity_stores', array('id' => $order['store_id']), array('business_name'));
- }
- include $this->template('paydetail');
- }
- public function doMobileSelfpay() {
- global $_W, $_GPC;
- if (checksubmit()) {
- $fee = !empty($_GPC['fee']) ? safe_gpc_string($_GPC['fee']) : message('收款金额有误', '', 'error');
- $body = !empty($_GPC['body']) ? safe_gpc_string($_GPC['body']) : '收银台收款' . safe_gpc_string($_GPC['fee']);
- $openid = !empty($_GPC['openid']) ? safe_gpc_string($_GPC['openid']) : message('用户信息错误', '', 'error');
- $clerk = table('activity_clerks')->getById(intval($_GPC['clerk_id']), $_W['uniacid']);
- $data = array(
- 'uniacid' => $_W['uniacid'],
- 'openid' => $openid,
- 'nickname' => safe_gpc_string($_GPC['nickname']),
- 'uid' => $_W['member']['uid'],
- 'clerk_id' => $clerk['id'],
- 'clerk_type' => 3,
- 'store_id' => $clerk['storeid'],
- 'body' => $body,
- 'fee' => $fee,
- 'final_fee' => $fee,
- 'credit_status' => 1,
- 'createtime' => TIMESTAMP,
- );
- table('paycenter_order')->fill($data)->save();
- $id = pdo_insertid();
- header('location:' . $this->createMobileUrl('pay', array('id' => $id)));
- die;
- }
- $fans = mc_oauth_userinfo();
- if (is_error($fans) || empty($fans)) {
- message('获取粉丝信息失败', '', 'error');
- }
- include $this->template('selfpay');
- }
- public function doMobileConsume() {
- global $_GPC, $_W;
- $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'])));
- header("Location: $url");
- exit;
- }
- }
|