card.mod.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. function card_setting($uniacid = 0) {
  8. global $_W;
  9. $uniacid = intval($uniacid);
  10. if($uniacid <= 0) {
  11. $uniacid = $_W['uniacid'];
  12. }
  13. $data = pdo_get('mc_card', array('uniacid' =>$uniacid));
  14. if(empty($data)) {
  15. return error(-1, '会员卡不存在或已经被删除');
  16. }
  17. if(!empty($data['color'])) {
  18. $data['color'] = iunserializer($data['color']);
  19. }
  20. $data['color'] = iunserializer($data['color']);
  21. $data['background'] = iunserializer($data['background']);
  22. $data['fields'] = iunserializer($data['fields']);
  23. $data['discount'] = iunserializer($data['discount']);
  24. if(!empty($data['discount']) && $data['discount_type'] != 0) {
  25. $discount = array();
  26. foreach($data['discount'] as $key=>$val) {
  27. $key_condition = 'condition_'.$data['discount_type'];
  28. $key_discount = 'discount_'.$data['discount_type'];
  29. $discount[$key] = array(
  30. 'condition' => $val[$key_condition],
  31. 'discount' => ($data['discount_type'] == 1 ? $val[$key_discount] : ($val[$key_discount]/10)),
  32. );
  33. }
  34. $data['discount'] = $discount;
  35. }
  36. $data['grant'] = iunserializer($data['grant']);
  37. return $data;
  38. }
  39. function card_member($uid = 0) {
  40. global $_W;
  41. $uid = intval($uid);
  42. if($uid <= 0) {
  43. $uid = $_W['member']['uid'];
  44. }
  45. $data = pdo_get('mc_card_members', array('uniacid' => $_W['uniacid'], 'uid' => $uid));
  46. if(empty($data)) {
  47. return error(-1, '会员还没有领取会员卡');
  48. }
  49. return $data;
  50. }
  51. function card_credit_setting() {
  52. global $_W;
  53. $set = array();
  54. $set = pdo_get('mc_card_credit_set', array('uniacid' => $_W['uniacid']));
  55. if(!empty($set)) {
  56. $set['sign'] = iunserializer($set['sign']);
  57. $set['share'] = iunserializer($set['share']);
  58. }
  59. return $set;
  60. }
  61. function card_notice_stat() {
  62. global $_W;
  63. $new_id = pdo_fetchcolumn('SELECT notice_id FROM ' . tablename('mc_card_notices_unread') . ' WHERE uniacid = :uniacid AND uid = :uid AND type = 1 ORDER BY notice_id DESC LIMIT 1', array(':uid' => $_W['member']['uid'], ':uniacid' => $_W['uniacid']));
  64. $new_id = intval($new_id);
  65. $notices = pdo_fetchall('SELECT id FROM ' . tablename('mc_card_notices') . ' WHERE uniacid = :uniacid AND type = 1 AND (groupid = 0 OR groupid = :groupid) AND id > :id', array(':uniacid' => $_W['uniacid'], ':groupid' => $_W['member']['groupid'], ':id' => $new_id));
  66. if(!empty($notices)) {
  67. foreach($notices as &$notice) {
  68. $insert = array(
  69. 'uniacid' => $_W['uniacid'],
  70. 'uid' => $_W['member']['uid'],
  71. 'notice_id' => $notice['id'],
  72. 'is_new' => 1,
  73. 'type' => 1,
  74. );
  75. pdo_insert('mc_card_notices_unread', $insert);
  76. }
  77. }
  78. $total = 0;
  79. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_card_notices_unread') . ' WHERE uniacid = :uniacid AND uid = :uid AND is_new = 1', array(':uniacid' => $_W['uniacid'], ':uid' => $_W['member']['uid']));
  80. return $total;
  81. }
  82. function card_params_setting($setting_name = '') {
  83. global $_W;
  84. $setting = pdo_get('mc_card', array('uniacid' => $_W['uniacid'], 'status' => '1'));
  85. $params = json_decode($setting['params'], true);
  86. if (!empty($params)) {
  87. foreach ($params as $value) {
  88. $params_new[$value['id']] = $value;
  89. }
  90. }
  91. if (!empty($setting_name)) {
  92. return $params_new[$setting_name];
  93. } else {
  94. return $params_new;
  95. }
  96. }
  97. function card_discount_fee($fee) {
  98. global $_W;
  99. $fee = floatval($fee);
  100. $card_settings = card_setting();
  101. $discount_params = $card_settings['discount'];
  102. if (!empty($card_settings['discount_type'])) {
  103. $group = mc_fetch($_W['member']['uid'], array('groupid'));
  104. if ($card_settings['discount_type'] == 1) {
  105. if ($discount_params[$group['groupid']]['condition'] <= $fee) {
  106. $final_fee = $fee - $discount_params[$group['groupid']]['discount'];
  107. } else {
  108. $final_fee = $fee;
  109. }
  110. } elseif ($card_settings['discount_type'] == 2) {
  111. if ($discount_params[$group['groupid']]['condition'] <= $fee) {
  112. $final_fee = $fee * $discount_params[$group['groupid']]['discount'];
  113. } else {
  114. $final_fee = $fee;
  115. }
  116. }
  117. return $final_fee;
  118. } else {
  119. return $fee;
  120. }
  121. }