goods.ctrl.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. load()->func('tpl');
  8. $dos = array('display', 'post', 'mine', 'use', 'deliver', 'confirm');
  9. $do = in_array($_GPC['do'], $dos) ? $_GPC['do'] : 'display';
  10. $profile = mc_fetch($_W['member']['uid']);
  11. if($do == 'display') {
  12. if ($unisettings['exchange_enable'] != '1') {
  13. message('未开启兑换功能');
  14. }
  15. $lists = pdo_fetchall('SELECT id,title,extra,thumb,type,credittype,endtime,description,credit FROM ' . tablename('activity_exchange') . ' WHERE uniacid = :uniacid AND type = :type AND endtime > :endtime AND status = 1 ORDER BY endtime ASC ', array(':uniacid' => $_W['uniacid'], ':type' => 3, ':endtime' => TIMESTAMP));
  16. foreach($lists as &$li) {
  17. $li['extra'] = iunserializer($li['extra']);
  18. if(!is_array($li['extra'])) {
  19. $li['extra'] = array();
  20. }
  21. }
  22. }
  23. if($do == 'post') {
  24. if ($unisettings['exchange_enable'] != '1') {
  25. message(error(-1, '未开启兑换功能'), '', 'ajax');
  26. }
  27. $id = intval($_GPC['id']);
  28. $shipping_data = array(
  29. 'name' => trim($_GPC['username']),
  30. 'mobile' => trim($_GPC['mobile']),
  31. 'zipcode' => trim($_GPC['zipcode']),
  32. 'province' => trim($_GPC['address_province']),
  33. 'city' => trim($_GPC['address_city']),
  34. 'district' => trim($_GPC['address_district']),
  35. 'address' => trim($_GPC['address_addr']),
  36. );
  37. foreach ($shipping_data as $val) {
  38. if (empty($val)) {
  39. message(error(-1, '请填写收货人信息'), '', 'ajax');
  40. }
  41. }
  42. $goods = activity_exchange_info($id, $_W['uniacid']);
  43. if(empty($goods)){
  44. message(error(-1, '没有指定的礼品兑换'), '', 'ajax');
  45. }
  46. $credit = mc_credit_fetch($_W['member']['uid'], array($goods['credittype']));
  47. if ($credit[$goods['credittype']] < $goods['credit']) {
  48. message(error(-1, "{$creditnames[$goods['credittype']]}不足"), '', 'ajax');
  49. }
  50. $ret = activity_goods_grant($_W['member']['uid'], $id);
  51. if(is_error($ret)) {
  52. message($ret, '', 'ajax');
  53. }
  54. pdo_update('activity_exchange_trades_shipping', $shipping_data, array('tid' => $ret));
  55. mc_credit_update($_W['member']['uid'], $goods['credittype'], -1 * $goods['credit'], array($_W['member']['uid'], '礼品兑换:' . $goods['title'] . ' 消耗 ' . $creditnames[$goods['credittype']] . ':' . $goods['credit']));
  56. if($goods['credittype'] == 'credit1') {
  57. mc_notice_credit1($_W['openid'], $_W['member']['uid'], -1 * $goods['credit'], '兑换礼品消耗积分');
  58. } else {
  59. mc_notice_credit2($_W['openid'], $_W['member']['uid'], -1 * $goods['credit'], 0, '线上消费,兑换礼品');
  60. }
  61. message(error($ret, "兑换成功"), url('activity/goods/mine'), 'ajax');
  62. }
  63. if($do == 'deliver') {
  64. $tid = intval($_GPC['tid']); $id = intval($_GPC['id']);
  65. $type = trim($_GPC['type']);
  66. $goods_info = pdo_get('activity_exchange', array('id' => $id));
  67. $goods_info['reside'] = $goods_info['total'] - $goods_info['num'];
  68. $goods_info['exp_date'] = '有效期:' . date('Y.m.d', $goods_info['starttime']) . '-' . date('Y.m.d', $goods_info['endtime']);
  69. $goods_info['description'] = htmlspecialchars_decode($goods_info['description']);
  70. $credit = mc_credit_fetch($_W['member']['uid'], array($goods_info['credittype']));
  71. $credit['name'] = $creditnames[$goods_info['credittype']];
  72. $is_exchange['error'] = '1';
  73. if ($type == 'edit') {
  74. $is_exchange['name'] = '修改信息';
  75. } else {
  76. if ($goods_info['credit'] > $credit[$goods_info['credittype']]) {
  77. $is_exchange['name'] = $credit['name'] . '不足';
  78. $is_exchange['error'] = '-1';
  79. } else {
  80. $is_exchange['name'] = '立即兑换';
  81. }
  82. }
  83. if (empty($tid)) {
  84. $address_data = pdo_get('mc_member_address', array('uniacid' => $_W['uniacid'], 'uid' => $_W['member']['uid']));
  85. } else {
  86. $address_data = pdo_get('activity_exchange_trades_shipping', array('uniacid' => $_W['uniacid'], 'uid' => $_W['member']['uid'], 'tid' => $tid));
  87. $address_data['username'] = $address_data['name'];
  88. }
  89. if($_W['isajax']) {
  90. $data = array(
  91. 'name' => trim($_GPC['username']),
  92. 'mobile' => trim($_GPC['mobile']),
  93. 'province' => trim($_GPC['address_province']),
  94. 'city' => trim($_GPC['address_city']),
  95. 'district' => trim($_GPC['address_district']),
  96. 'address' => trim($_GPC['address_addr']),
  97. 'zipcode' => trim($_GPC['zipcode']),
  98. );
  99. pdo_update('activity_exchange_trades_shipping', $data, array('tid' => intval($_GPC['tid']), 'uid' => $_W['member']['uid']));
  100. message(error(0,'修改成功'), url('activity/goods/mine'), 'ajax');
  101. }
  102. }
  103. if($do == 'mine') {
  104. $psize = 10;
  105. $pindex = max(1, intval($_GPC['page']));
  106. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('activity_exchange_trades_shipping') . ' WHERE uid = :uid', array(':uid' => $_W['member']['uid']));
  107. $lists = pdo_fetchall("SELECT a.*, b.id AS gid,b.title,b.extra,b.thumb,b.type,b.credittype,b.endtime,b.description,b.credit FROM " . tablename('activity_exchange_trades_shipping') . " AS a LEFT JOIN " . tablename('activity_exchange'). " AS b ON a.exid = b.id WHERE a.uid = :uid ORDER BY a.status LIMIT " . ($pindex - 1) * $psize . "," . $psize, array(':uid' => $_W['member']['uid']));
  108. foreach($lists as &$list) {
  109. $list['extra'] = iunserializer($list['extra']);
  110. if(!is_array($list['extra'])) {
  111. $list['extra'] = array();
  112. }
  113. }
  114. $pager = pagination($total, $pindex, $psize);
  115. }
  116. if($do == 'confirm') {
  117. if ($_W['isajax']) {
  118. $tid = intval($_GPC['tid']);
  119. $ship = pdo_fetch('SELECT tid FROM ' . tablename('activity_exchange_trades_shipping') . ' WHERE tid = :tid AND uid = :uid', array(':tid' => $tid, ':uid' => $_W['member']['uid']));
  120. if(empty($ship)) {
  121. message(error(-1,'订单信息不存在'), '', 'ajax');
  122. }
  123. pdo_update('activity_exchange_trades_shipping', array('status' => 2), array('uid' => $_W['member']['uid'], 'tid' => $tid));
  124. message(error(1,'确认收货成功'), url('activity/goods/mine', array('status' => 2)), 'ajax');
  125. }
  126. }
  127. template('activity/goods');