人人商城

coupon.mod.php 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 coupon_colors($name, $value = 'Color082', $options = array()) {
  8. empty($name) && ($name = 'coupon_color');
  9. if (!defined('TPL_INIT_COUPON_COLOR')) {
  10. $html .= '
  11. <script type="text/javascript">
  12. function showCouponColor(eml) {
  13. var dropdown = $(eml).parent().parent().next();
  14. dropdown.show();
  15. $(document).click(function(){
  16. dropdown.hide();
  17. });
  18. $(".coupon-color").click(function(e){
  19. e.stopPropagation();
  20. });
  21. $(".dropdown-menu li").click(function(){
  22. $(eml).parent().prev().css("background", $(this).attr("data-color"));
  23. $(eml).parent().prev().css("border-color", $(this).attr("data-color"));
  24. $(eml).parent().prev().prev().prev().val($(this).attr("data-name"));
  25. $(eml).parent().prev().prev().val($(this).attr("data-color"));
  26. dropdown.hide();
  27. $(document).unbind("click");
  28. $(".dropdown-menu li, .coupon-color").unbind("click");
  29. });
  30. }
  31. </script>';
  32. define('TPL_INIT_COUPON_COLOR', true);
  33. }
  34. $html .= '
  35. <div class="col-sm-9 col-xs-12 coupon-color" style="position: relative;width:200px;">
  36. <div class="input-group" style="width:200px;">
  37. <input type="text" class="form-control" name="'.$name.'" value="'.$value.'"/>
  38. <input type="hidden" name="'.$name.'-value" class="form-control" value="'.$value.'"/>
  39. <span class="input-group-addon" style="width:35px;background:'.$options[$value]['value'].'"></span>
  40. <span class="input-group-btn">
  41. <button class="btn btn-default" type="button" onclick="showCouponColor(this);">选择颜色</button>
  42. </span>
  43. </div>
  44. <div class="dropdown-menu" style="display:none;padding:6px 0 0 6px;width:185px;position: absolute;top:35px;left:15px">
  45. <ul style="padding:0">
  46. ';
  47. if(!empty($options)) {
  48. foreach($options as $option) {
  49. $html .= '<li data-name="'.$option['name'].'" data-color="'.$option['value'].'" style="padding: 0;margin-right:5px;margin-bottom:5px;width:30px;height:30px;background:'.$option['value'].';float:left;list-style: none;"></li>';
  50. }
  51. }
  52. $html .= '
  53. </ul>
  54. </div>
  55. </div>
  56. ';
  57. return $html;
  58. }
  59. function url_name_type(){
  60. $url_name_type = array(
  61. 'URL_NAME_TYPE_TAKE_AWAY' => '外卖',
  62. 'URL_NAME_TYPE_RESERVATION' => '在线预定',
  63. 'URL_NAME_TYPE_USE_IMMEDIATELY' => '立即使用',
  64. 'URL_NAME_TYPE_APPOINTMENT' => '在线预约',
  65. 'URL_NAME_TYPE_EXCHANGE' => '在线兑换',
  66. 'URL_NAME_TYPE_VIP_SERVICE' => '会员服务 (仅会员卡 类型可用)',
  67. );
  68. return $url_name_type;
  69. }
  70. function coupon_fetch($id, $format = true) {
  71. global $_W;
  72. $id = intval($id);
  73. $item = pdo_fetch('SELECT * FROM ' . tablename('coupon') . ' WHERE uniacid = :aid AND id = :id', array(':aid' => $_W['uniacid'], ':id' => $id));
  74. if(empty($item)) {
  75. return error(-1, '卡券不存在或已删除');
  76. }
  77. if(!$format) {
  78. return $item;
  79. } else {
  80. $item['location-select'] = '';
  81. $item['location_count'] = 0;
  82. if(!empty($item['location_id_list'])) {
  83. $item['location_id_list'] = @iunserializer($item['location_id_list']);
  84. foreach($item['location_id_list'] as $lic) {
  85. $item['location_data'][] = pdo_fetch('SELECT business_name, address, location_id FROM ' . tablename('activity_stores') . ' WHERE uniacid = :aid AND location_id = :lid', array(':aid' => $_W['uniacid'], ':lid' => $lic), 'location_id');
  86. }
  87. $item['location_count'] = count($item['location_id_list']);
  88. if(!empty($item['location_id_list'])) {
  89. $item['location-select'] = implode('-', $item['location_id_list']);
  90. }
  91. }
  92. $item['date_info'] = iunserializer($item['date_info']);
  93. $item['logo_url'] = media2local($item['logo_url']);
  94. $item['discount_f'] = (100 - $item['discount']) / 10;
  95. if($item['type'] == 'cash') {
  96. $item['extra'] = iunserializer($item['extra']);
  97. $item['least_cost'] = $item['extra']['least_cost'];
  98. $item['reduce_cost'] = $item['extra']['reduce_cost'];
  99. }
  100. if($item['type'] == 'discount' || $item['type'] == 'cash') {
  101. $item['modules'] = pdo_fetchall('SELECT a.*, b.title FROM ' . tablename('coupon_modules') . ' AS a LEFT JOIN ' . tablename('modules') . ' AS b ON a.module = b.name WHERE a.cid = :id', array(':id' => $id));
  102. }
  103. }
  104. return $item;
  105. }
  106. function coupon_delete($id) {
  107. global $_W;
  108. $id = intval($id);
  109. $item = pdo_fetch('SELECT acid,id,card_id FROM ' . tablename('coupon') . ' WHERE uniacid = :aid AND id = :id', array(':aid' => $_W['uniacid'], ':id' => $id));
  110. if(empty($item)) {
  111. return error(-1, '卡券不存在或已经删除');
  112. }
  113. if(empty($item['card_id'])) {
  114. pdo_delete('coupon', array('id' => $id, 'uniacid' => $_W['uniacid']));
  115. return true;
  116. }
  117. $coupon = new coupon($item['acid']);
  118. $return = $coupon->DeleteCard($item['card_id']);
  119. if(is_error($return)) {
  120. return $return;
  121. }
  122. pdo_delete('coupon', array('id' => $id, 'uniacid' => $_W['uniacid']));
  123. return true;
  124. }
  125. function coupon_modifystock($id, $num) {
  126. global $_W;
  127. $id = intval($id);
  128. $num = intval($num);
  129. $item = pdo_fetch('SELECT acid,id,card_id,quantity FROM ' . tablename('coupon') . ' WHERE uniacid = :aid AND id = :id', array(':aid' => $_W['uniacid'], ':id' => $id));
  130. if(empty($item)) {
  131. return error(-1, '卡券不存在或已经删除');
  132. }
  133. if(empty($item['card_id'])) {
  134. return error(-1, '卡券id出错');
  135. }
  136. $num_tmp = $num - $item['quantity'];
  137. $coupon = new coupon($item['acid']);
  138. $return = $coupon->ModifyStockCard($item['card_id'], $num_tmp);
  139. if(is_error($return)) {
  140. return $return;
  141. }
  142. pdo_update('coupon', array('quantity' => $num), array('id' => $id, 'uniacid' => $_W['uniacid']));
  143. return true;
  144. }
  145. function coupon_qr($data) {
  146. global $_W;
  147. $id = intval($data['id']);
  148. $item = pdo_fetch('SELECT acid,id,card_id FROM ' . tablename('coupon') . ' WHERE uniacid = :aid AND id = :id', array(':aid' => $_W['uniacid'], ':id' => $id));
  149. if(empty($item)) {
  150. return error(-1, '卡券不存在或已经删除');
  151. }
  152. if(empty($item['card_id'])) {
  153. return error(-1, '卡券id出错');
  154. }
  155. $coupon = new coupon($item['acid']);
  156. $qrcode = array(
  157. 'action_name' => 'QR_CARD',
  158. 'expire_seconds' => "{$data['expire_seconds']}",
  159. 'action_info' => array(
  160. 'card' => array(
  161. 'card_id' => $item['card_id'],
  162. 'code' => '',
  163. 'openid' => '',
  164. 'is_unique_code' => false,
  165. 'outer_id' => $data['outer_id']
  166. )
  167. )
  168. );
  169. $return = $coupon->QrCard($qrcode);
  170. return $return;
  171. }
  172. function coupon_status() {
  173. return array(
  174. 'CARD_STATUS_NOT_VERIFY' => 1, 'CARD_STATUS_VERIFY_FAIL' => 2, 'CARD_STATUS_VERIFY_OK' => 3, 'CARD_STATUS_USER_DELETE' => 4,
  175. 'CARD_STATUS_DELETE' => 4, 'CARD_STATUS_USER_DISPATCH' => 5, 'CARD_STATUS_DISPATCH' => 5, );
  176. }