goods.ctrl.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. uni_user_permission_check('activity_goods_display');
  8. $dos = array('display', 'post', 'del', 'record', 'deliver', 'receiver', 'record-del');
  9. $do = in_array($do, $dos) ? $do : 'display';
  10. $creditnames = array();
  11. $unisettings = uni_setting($uniacid, array('creditnames'));
  12. foreach ($unisettings['creditnames'] as $key=>$credit) {
  13. if (!empty($credit['enabled'])) {
  14. $creditnames[$key] = $credit['title'];
  15. }
  16. }
  17. if($do == 'post') {
  18. $id = intval($_GPC['id']);
  19. if(!empty($id)){
  20. $item = pdo_fetch('SELECT * FROM '.tablename('activity_exchange').' WHERE id=:id AND uniacid=:uniacid',array(':id'=>$id, ':uniacid'=>$_W['uniacid']));
  21. if(empty($item)) {
  22. message('未找到指定兑换礼品或已删除.',url('activity/goods'),'error');
  23. } else {
  24. $item['extra'] = iunserializer($item['extra']);
  25. }
  26. } else {
  27. $item['starttime'] = TIMESTAMP;
  28. $item['endtime'] = TIMESTAMP + 6 * 86400;
  29. }
  30. if(checksubmit('submit')) {
  31. $data['title'] = !empty($_GPC['title']) ? trim($_GPC['title']) : message('请输入兑换名称!');
  32. $data['credittype'] = !empty($_GPC['credittype']) ? trim($_GPC['credittype']) : message('请选择积分类型!');
  33. $data['credit'] = intval($_GPC['credit']);
  34. if(empty($_GPC['extra']['title'])) {
  35. message('请输入兑换礼品的名称');
  36. }
  37. $data['extra'] = iserializer($_GPC['extra']);
  38. $data['thumb'] = trim($_GPC['thumb']);
  39. $data['pretotal'] = intval($_GPC['pretotal']) ? intval($_GPC['pretotal']) : message('请输入每人最大兑换次数');
  40. $data['total'] = intval($_GPC['total']) ? intval($_GPC['total']) : message('请输入兑换总数');
  41. $data['type'] = 3;
  42. $data['description'] = !empty($_GPC['description']) ? trim($_GPC['description']) : message('请输入兑换说明!');
  43. $starttime = strtotime($_GPC['datelimit']['start']);
  44. $endtime = strtotime($_GPC['datelimit']['end']);
  45. if ($endtime == $starttime) {
  46. $endtime = $endtime + 86399;
  47. }
  48. $data['starttime'] = $starttime;
  49. $data['endtime'] = $endtime;
  50. if(empty($id)) {
  51. $data['uniacid'] = $_W['uniacid'];
  52. pdo_insert('activity_exchange', $data);
  53. message('添加真实物品兑换成功',url('activity/goods', array()),'success');
  54. } else {
  55. pdo_update('activity_exchange', $data, array('id' => $id, 'uniacid'=>$_W['uniacid']));
  56. message('更新真实物品兑换成功',url('activity/goods', array()),'success');
  57. }
  58. }
  59. }
  60. if($do == 'display') {
  61. $pindex = max(1, intval($_GPC['page']));
  62. $psize = 10;
  63. $where = ' WHERE type = 3 AND uniacid = :uniacid ';
  64. $params = array(':uniacid' => $_W['uniacid']);
  65. $title = trim($_GPC['keyword']);
  66. if (!empty($title)) {
  67. $where .= " AND title LIKE '%{$title}%'";
  68. }
  69. $list = pdo_fetchall('SELECT * FROM '.tablename('activity_exchange')." $where ORDER BY id DESC LIMIT ".($pindex - 1) * $psize.','.$psize, $params);
  70. $total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('activity_exchange'). $where , $params);
  71. $pager = pagination($total, $pindex, $psize);
  72. foreach ($list as &$row) {
  73. $extra = iunserializer($row['extra']);
  74. $row['extra'] = $extra;
  75. $row['thumb'] = tomedia($row['thumb']);
  76. }
  77. }
  78. if($do == 'del') {
  79. $id = intval($_GPC['id']);
  80. if(!empty($id)){
  81. $item = pdo_fetch('SELECT id FROM '.tablename('activity_exchange').' WHERE id=:id AND uniacid=:uniacid',array(':id'=>$id, ':uniacid'=>$_W['uniacid']));
  82. }
  83. if(empty($item)) {
  84. message('删除失败,指定兑换不存在或已删除.');
  85. }
  86. pdo_delete('activity_exchange', array('id'=>$id, 'uniacid'=>$_W['uniacid']));
  87. message('删除成功.', referer(),'success');
  88. }
  89. if($do == 'record') {
  90. $exchanges = pdo_fetchall('SELECT id, title FROM ' . tablename('activity_exchange') . ' WHERE uniacid = :uniacid ORDER BY id DESC', array(':uniacid' => $_W['uniacid']));
  91. $starttime = empty($_GPC['time']['start']) ? strtotime('-1 month') : strtotime($_GPC['time']['start']);
  92. $endtime = empty($_GPC['time']['end']) ? TIMESTAMP : strtotime($_GPC['time']['end']) + 86399;
  93. $where = " WHERE a.uniacid=:uniacid AND a.type = 3 AND a.createtime>=:starttime AND a.createtime<:endtime";
  94. $params = array(
  95. ':uniacid' => $_W['uniacid'],
  96. ':starttime' => $starttime,
  97. ':endtime' => $endtime,
  98. );
  99. $uid = intval($_GPC['uid']);
  100. if (!empty($uid)) {
  101. $where .= ' AND a.uid=:uid';
  102. $params[':uid'] = $uid;
  103. }
  104. $exid = intval($_GPC['exid']);
  105. if (!empty($exid)) {
  106. $where .= " AND b.id = {$exid}";
  107. }
  108. $pindex = max(1, intval($_GPC['page']));
  109. $psize = 20;
  110. $list = pdo_fetchall("SELECT a.*, b.title,b.extra,b.thumb FROM ".tablename('activity_exchange_trades'). ' AS a LEFT JOIN ' . tablename('activity_exchange') . ' AS b ON a.exid = b.id ' . " $where ORDER BY tid DESC LIMIT ".($pindex - 1) * $psize.','.$psize, $params);
  111. $total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('activity_exchange_trades') . ' AS a LEFT JOIN ' . tablename('activity_exchange') . ' AS b ON a.exid = b.id '. $where , $params);
  112. $pager = pagination($total, $pindex, $psize);
  113. if(!empty($list)) {
  114. $uids = array();
  115. foreach ($list as $row) {
  116. $uids[] = $row['uid'];
  117. }
  118. load()->model('mc');
  119. $members = mc_fetch($uids, array('uid', 'nickname'));
  120. foreach ($list as &$row) {
  121. $row['extra'] = iunserializer($row['extra']);
  122. $row['nickname'] = $members[$row['uid']]['nickname'];
  123. $row['thumb'] = tomedia($row['thumb']);
  124. }
  125. }
  126. }
  127. if($do == 'deliver') {
  128. $exchanges = pdo_fetchall('SELECT id, title FROM ' . tablename('activity_exchange') . ' WHERE uniacid = :uniacid ORDER BY id DESC', array(':uniacid' => $_W['uniacid']));
  129. $starttime = empty($_GPC['time']['start']) ? strtotime('-1 month') : strtotime($_GPC['time']['start']);
  130. $endtime = empty($_GPC['time']['end']) ? TIMESTAMP : strtotime($_GPC['time']['end']) + 86399;
  131. $where = " WHERE a.uniacid=:uniacid AND a.createtime>=:starttime AND a.createtime<:endtime";
  132. $params = array(
  133. ':uniacid' => $_W['uniacid'],
  134. ':starttime' => $starttime,
  135. ':endtime' => $endtime,
  136. );
  137. $uid = intval($_GPC['uid']);
  138. if (!empty($uid)) {
  139. $where .= ' AND a.uid=:uid';
  140. $params[':uid'] = $uid;
  141. }
  142. $exid = intval($_GPC['exid']);
  143. if (!empty($exid)) {
  144. $where .= " AND b.id = {$exid}";
  145. }
  146. $pindex = max(1, intval($_GPC['page']));
  147. $psize = 20;
  148. $list = pdo_fetchall("SELECT a.*, b.title,b.extra,b.thumb FROM ".tablename('activity_exchange_trades_shipping'). ' AS a LEFT JOIN ' . tablename('activity_exchange') . ' AS b ON a.exid = b.id ' . " $where ORDER BY tid DESC LIMIT ".($pindex - 1) * $psize.','.$psize, $params);
  149. $total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('activity_exchange_trades_shipping') . ' AS a LEFT JOIN ' . tablename('activity_exchange') . ' AS b ON a.exid = b.id '. $where , $params);
  150. if(!empty($list)) {
  151. $uids = array();
  152. foreach ($list as $row) {
  153. $uids[] = $row['uid'];
  154. }
  155. load()->model('mc');
  156. $members = mc_fetch($uids, array('uid', 'nickname'));
  157. foreach ($list as &$row) {
  158. $row['extra'] = iunserializer($row['extra']);
  159. $row['nickname'] = $members[$row['uid']]['nickname'];
  160. $row['thumb'] = tomedia($row['thumb']);
  161. }
  162. }
  163. $pager = pagination($total, $pindex, $psize);
  164. }
  165. if($do == 'receiver') {
  166. $id = intval($_GPC['id']);
  167. $shipping = pdo_fetch('SELECT * FROM ' . tablename('activity_exchange_trades_shipping') . ' WHERE uniacid = :uniacid AND tid = :tid', array(':uniacid' => $_W['uniacid'], ':tid' => $id) );
  168. if(checksubmit('submit')) {
  169. $data = array(
  170. 'name'=>$_GPC['realname'],
  171. 'mobile'=>$_GPC['mobile'],
  172. 'province'=>$_GPC['reside']['province'],
  173. 'city'=>$_GPC['reside']['city'],
  174. 'district'=>$_GPC['reside']['district'],
  175. 'address'=>$_GPC['address'],
  176. 'zipcode'=>$_GPC['zipcode'],
  177. 'status'=>intval($_GPC['status'])
  178. );
  179. pdo_update('activity_exchange_trades_shipping', $data, array('tid' => $id));
  180. message('更新发货人信息成功', referer(), 'success');
  181. }
  182. }
  183. if($do == 'record-del') {
  184. $tid = intval($_GPC['id']);
  185. if(empty($tid)) {
  186. message('没有指定的兑换记录', url('activity/goods/record'), 'error');
  187. }
  188. pdo_delete('activity_exchange_trades_shipping', array('uniacid' => $_W['uniacid'], 'tid' => $tid));
  189. pdo_delete('activity_exchange_trades', array('uniacid' => $_W['uniacid'], 'tid' => $tid));
  190. message('删除兑换记录成功', url('activity/goods/record'), 'success');
  191. }
  192. template('activity/goods');