clerk.ctrl.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. $dos = array('check', 'card', 'token');
  8. $do = in_array($do, $dos) ? $do : 'check';
  9. load()->model('clerk');
  10. $clerk = clerk_check();
  11. if(is_error($clerk)) {
  12. message('您不是操作店员,没有使用该功能的权限', '', 'error');
  13. }
  14. if($do != 'check') {
  15. } else {
  16. template('mc/clerk');
  17. }
  18. if($do == 'card') {
  19. load()->model('card');
  20. $card_setting = card_setting();
  21. $card_params = json_decode($card_setting['params'], true);
  22. if (!empty($card_params)) {
  23. foreach ($card_params as $key => $value) {
  24. if ($value['id'] == 'cardActivity') {
  25. $grant_rate = $value['params']['grant_rate'];
  26. }
  27. }
  28. }
  29. $card_setting['grant_rate'] = $grant_rate;
  30. if(is_error($card_setting)) {
  31. message($card_setting['message'], referer(), 'error');
  32. }
  33. $card_member = card_member($uid);
  34. if(is_error($card_member)) {
  35. message($card_member['message'], referer(), 'error');
  36. }
  37. $stores = pdo_fetchall('SELECT id,business_name FROM ' . tablename('activity_stores') . ' WHERE uniacid = :uniacid', array(':uniacid' => $_W['uniacid']), 'id');
  38. if(checksubmit()) {
  39. $credit = max(0, floatval($_GPC['credit']));
  40. $discount_credit = $credit;
  41. $store_id = intval($_GPC['store_id']);
  42. $store_str = (!$store_id || empty($stores[$store_id])) ? '未知' : $stores[$store_id]['business_name'];
  43. if(!$credit || $credit <= 0) {
  44. message('请输入消费金额', referer(), 'error');
  45. }
  46. if($card_setting['discount_type'] > 0) {
  47. $discount = $card_setting['discount'][$_W['member']['groupid']];
  48. if(!empty($discount['condition']) && !empty($discount['discount']) && $credit >= $discount['condition']) {
  49. if($card_setting['discount_type'] == 1) {
  50. $discount_credit = $credit - $discount['discount'];
  51. $discount_str = ",该会员属于【{$_W['member']['groupname']}】,可享受【满{$discount['condition']}元减{$discount['discount']}元】,最终支付【{$discount_credit}】元";
  52. } else {
  53. $rate = $discount['discount']/10;
  54. $discount_credit = $credit * $rate;
  55. $discount_str = ",该会员属于【{$_W['member']['groupname']}】,可享受【满{$discount['condition']}元打{$rate}折】,最终支付【{$discount_credit}】元";
  56. }
  57. if($discount_credit < 0) {
  58. $discount_credit = 0;
  59. }
  60. }
  61. }
  62. if($member['credit2'] < $discount_credit) {
  63. message('余额不足', referer(), 'error');
  64. }
  65. if($card_setting['grant_rate'] > 0) {
  66. $credit1 = $discount_credit * $card_setting['grant_rate'];
  67. $log_credit1 = array(
  68. $_W['member']['uid'],
  69. "使用会员卡消费【{$discount_credit}】元,消费返积分比率:【1:{$card_setting['grant_rate']}】,共赠送积分{$credit1}",
  70. 'card',
  71. $clerk['id']
  72. );
  73. mc_credit_update($_W['member']['uid'], 'credit1', $credit1, $log_credit1);
  74. $discount_str .= ",消费返积分比率:【1:{$card_setting['grant_rate']}】,共赠送积分{$credit1}";
  75. }
  76. $log_credit2 = array(
  77. $_W['member']['uid'],
  78. "使用会员卡消费【{$credit}】元 {$discount_str},消费门店:{$store_str}",
  79. 'card',
  80. $clerk['id']
  81. );
  82. mc_credit_update($_W['member']['uid'], 'credit2', -$discount_credit, $log_credit2);
  83. message("消费成功,共扣除余额{$discount_credit}元,赠送{$credit1}积分", url('mc/clerk'), 'success');
  84. }
  85. if($card_setting['discount_type'] != 0) {
  86. $discount = $card_setting['discount'];
  87. $tips = "该会员所在的会员组: {$_W['account']['groups'][$member['groupid']]['title']} ,可享受满 {$discount[$member['groupid']]['condition']} ";
  88. if($card_setting['discount_type'] == 2) {
  89. $tips .= "打 {$discount[$member['groupid']]['discount']} 折";
  90. } else {
  91. $tips .= "减 {$discount[$member['groupid']]['discount']} 元";
  92. }
  93. $mine_discount = $discount[$member['groupid']];
  94. }
  95. template('mc/clerk-card');
  96. exit();
  97. }
  98. if($do == 'token') {
  99. $id = intval($_GPC['id']);
  100. load()->model('activity');
  101. $token = pdo_get('activity_coupon', array('uniacid' => $_W['uniacid'], 'id' => $id));
  102. if(empty($token)) {
  103. message('优惠券不存在或已删除', referer(), 'error');
  104. }
  105. $own_func = 'activity_token_owned';
  106. $use_func = 'activity_token_use';
  107. if($token['type'] == 1) {
  108. $own_func = 'activity_coupon_owned';
  109. $use_func = 'activity_coupon_use';
  110. }
  111. $data = $own_func($_W['member']['uid'], array('couponid' => $id, 'used' => 1));
  112. $data = $data['data'][$id];
  113. if(empty($data)) {
  114. message('该会员没有领取该优惠券或领取的优惠券已核销', referer(), 'error');
  115. }
  116. if(checksubmit('submit')) {
  117. load()->model('user');
  118. $password = $_GPC['password'];
  119. $sql = 'SELECT * FROM ' . tablename('activity_clerks') . " WHERE `uniacid` = :uniacid AND `password` = :password";
  120. $clerk = pdo_fetch($sql, array(':uniacid' => $_W['uniacid'], ':password' => $password));
  121. if(!empty($clerk)) {
  122. $status = $use_func($_W['member']['uid'], $id, $clerk['name']);
  123. if (!is_error($status)) {
  124. message('代金券使用成功!', url('activity/token/mine', array('type' => $_GPC['type'])), 'success');
  125. } else {
  126. message($status['message'], url('activity/token/mine', array('type' => $_GPC['type'])), 'error');
  127. }
  128. }
  129. message('密码错误!', referer(), 'error');
  130. }
  131. template('mc/clerk-card');
  132. exit();
  133. }