partimes.ctrl.php 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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('display', 'post', 'mine', 'use', 'deliver', 'confirm');
  8. $do = in_array($_GPC['do'], $dos) ? $_GPC['do'] : 'display';
  9. if($do == 'display') {
  10. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM '. tablename('activity_exchange'). ' WHERE uniacid = :uniacid AND type = :type AND endtime > :endtime' , array(':uniacid' => $_W['uniacid'], ':type' => 5, ':endtime' => TIMESTAMP));
  11. $pindex = max(1, intval($_GPC['page']));
  12. $psize = 10;
  13. $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 ORDER BY endtime ASC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, array(':uniacid' => $_W['uniacid'], ':type' => 5, ':endtime' => TIMESTAMP));
  14. foreach($lists as &$li) {
  15. $li['extra'] = iunserializer($li['extra']);
  16. }
  17. $pager = pagination($total, $pindex, $psize);
  18. }
  19. if($do == 'post') {
  20. $id = intval($_GPC['id']);
  21. $partime = activity_exchange_info($id, $_W['uniacid']);
  22. if(empty($partime)){
  23. message('没有指定的礼品兑换.');
  24. }
  25. $credit = mc_credit_fetch($_W['member']['uid'], array($partime['credittype']));
  26. if ($credit[$partime['credittype']] < $partime['credit']) {
  27. message('您的' . $creditnames[$partime['credittype']] . '数量不够,无法兑换.');
  28. }
  29. $ret = activity_module_grant($_W['member']['uid'], $id, 'system', '用户使用' . $partime['credit'] . $creditnames[$partime['credittype']] . '兑换');
  30. if(is_error($ret)) {
  31. message($ret['message']);
  32. }
  33. mc_credit_update($_W['member']['uid'], $partime['credittype'], -1 * $partime['credit'], array($_W['member']['uid'], '礼品兑换:' . $partime['title'] . ' 消耗 ' . $creditnames[$partime['credittype']] . ':' . $partime['credit']));
  34. message("兑换成功,您消费了 {$partime['credit']} {$creditnames[$partime['credittype']]}", url('activity/partimes/mine'));
  35. }
  36. if($do == 'mine') {
  37. $psize = 10;
  38. $pindex = max(1, intval($_GPC['page']));
  39. $condition = '';
  40. if(empty($_GPC['status']) || $_GPC['status'] == 1) {
  41. $condition .= ' AND a.available > 0';
  42. } else {
  43. $condition .= ' AND a.available = 0';
  44. }
  45. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('activity_modules') . ' AS a WHERE uid = :uid AND uniacid = :uniacid ' . $condition, array(':uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid']));
  46. $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_modules') . ' AS a LEFT JOIN ' . tablename('activity_exchange'). ' AS b ON a.exid = b.id WHERE a.uid = :uid ' . $condition . ' LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, array(':uid' => $_W['member']['uid']));
  47. foreach($lists as &$list) {
  48. $list['extra'] = iunserializer($list['extra']);
  49. }
  50. $pager = pagination($total, $pindex, $psize);
  51. }
  52. if ($do == 'deliver') {
  53. $exid = intval($_GPC['exid']);
  54. $sql = 'SELECT * FROM ' . tablename('activity_exchange_trades_shipping') . ' WHERE uid = :uid AND exid = :exid';
  55. $ship = pdo_fetch($sql, array(':uid' => $_W['member']['uid'], ':exid' => $exid));
  56. if(checksubmit('submit')) {
  57. $data = array(
  58. 'name'=>$_GPC['realname'],
  59. 'mobile'=>$_GPC['mobile'],
  60. 'province'=>$_GPC['reside']['province'],
  61. 'city'=>$_GPC['reside']['city'],
  62. 'district'=>$_GPC['reside']['district'],
  63. 'address'=>$_GPC['address'],
  64. 'zipcode'=>$_GPC['zipcode']
  65. );
  66. if (empty($ship)) {
  67. $data['uniacid'] = $_W['uniacid'];
  68. $data['exid'] = $exid;
  69. $data['uid'] = $_W['member']['uid'];
  70. $data['createtime'] = TIMESTAMP;
  71. pdo_insert('activity_exchange_trades_shipping', $data);
  72. } else {
  73. pdo_update('activity_exchange_trades_shipping', $data, array('exid' => $exid, 'uid' => $_W['member']['uid']));
  74. }
  75. message('收货人信息更新成功', url('activity/partimes/mine'));
  76. }
  77. if(empty($ship)) {
  78. $getInfo = array('uid','realname','resideprovince','residecity','residedist','address','zipcode','mobile');
  79. $ship = mc_fetch($_W['member']['uid'], $getInfo);
  80. $ship['name'] = $ship['realname'];
  81. $ship['province'] = $ship['resideprovince'];
  82. $ship['city'] = $ship['residecity'];
  83. } else {
  84. $ship['residedist'] = $ship['district'];
  85. }
  86. load()->func('tpl');
  87. }
  88. template('activity/partimes');