click.ctrl.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. $ret = array();
  8. if(empty($_GPC['module']) || empty($_GPC['sign']) || empty($_W['uniacid']) || empty($_GPC['action'])) {
  9. return false;
  10. }
  11. $name = trim($_GPC['module']);
  12. $site = WeUtility::createModuleSite($name);
  13. $return = $site->creditOperate($_GPC['sign'], $_GPC['action']);
  14. if(empty($return)) {
  15. return false;
  16. } elseif(empty($return['credit_total'])) {
  17. $ret['result'] = 'total-miss';
  18. moduleInit($_GPC['module'], $ret);
  19. }
  20. $ret = array();
  21. $total = pdo_fetchcolumn('SELECT SUM(credit_value) FROM ' . tablename('mc_handsel') . ' WHERE uniacid = :uniacid AND module = :module AND sign = :sign', array(':uniacid' => $_W['uniacid'], ':module' => $_GPC['module'], ':sign' => $_GPC['sign']));
  22. $credit_total = intval($return['credit_total']);
  23. if($total >= $credit_total) {
  24. $ret['result'] = 'total-limit';
  25. moduleInit($_GPC['module'], $ret);
  26. }
  27. if(empty($_GPC['tuid'])) {
  28. $ret['result'] = 'tuid-miss';
  29. moduleInit($_GPC['module'], $ret);
  30. } else {
  31. $tuid = intval($_GPC['tuid']);
  32. $user = pdo_fetchcolumn('SELECT uid FROM ' . tablename('mc_members'). ' WHERE uniacid = :uniacid AND uid = :uid', array(':uniacid' => $_W['uniacid'], ':uid' => $tuid));
  33. if(empty($user)) {
  34. $ret['result'] = 'tuid-error';
  35. moduleInit($_GPC['module'], $ret);
  36. }
  37. }
  38. if(empty($_GPC['fuid'])) {
  39. $fuid = $_W['member']['uid'];
  40. } else {
  41. $fuid = intval($_GPC['fuid']);
  42. $user = pdo_fetchcolumn('SELECT uid FROM ' . tablename('mc_members'). ' WHERE uniacid = :uniacid AND uid = :uid', array(':uniacid' => $_W['uniacid'], ':uid' => $fuid));
  43. if(empty($user)) {
  44. $ret['result'] = 'fuid-error';
  45. moduleInit($_GPC['module'], $ret);
  46. }
  47. }
  48. if(!empty($_GPC['action'])) {
  49. $sql = 'SELECT id FROM ' . tablename('mc_handsel') . ' WHERE uniacid = :uniacid AND touid = :touid AND fromuid = :fromuid AND module = :module AND sign = :sign AND action = :action';
  50. $parm = array(':uniacid' => $_W['uniacid'], ':touid' => $tuid, ':fromuid' => $fuid, ':module' => $_GPC['module'], ':sign' => $_GPC['sign'], ':action' => $_GPC['action']);
  51. $is_add = pdo_fetchcolumn($sql, $parm);
  52. if(empty($is_add)) {
  53. $creditbehaviors = pdo_fetchcolumn('SELECT creditbehaviors FROM ' . tablename('uni_settings') . ' WHERE uniacid = :uniacid', array(':uniacid' => $_W['uniacid']));
  54. $creditbehaviors = iunserializer($creditbehaviors) ? iunserializer($creditbehaviors) : array();
  55. if(empty($creditbehaviors['activity'])) {
  56. $ret['result'] = 'creditset-miss';
  57. moduleInit($_GPC['module'], $ret);
  58. } else {
  59. $credittype = $creditbehaviors['activity'];
  60. }
  61. $data = array(
  62. 'uniacid' => $_W['uniacid'],
  63. 'touid' => $tuid,
  64. 'fromuid' => $fuid,
  65. 'module' => $_GPC['module'],
  66. 'sign' => $_GPC['sign'],
  67. 'action' => $_GPC['action'],
  68. 'credit_value' => intval($return['credit_value']),
  69. 'createtime' => TIMESTAMP
  70. );
  71. pdo_insert('mc_handsel', $data);
  72. $note = empty($_GPC['note']) ? '系统赠送积分' : $_GPC['note'];
  73. $log = array(
  74. 'uid' => $tuid,
  75. 'credittype' => $credittype,
  76. 'uniacid' => $_W['uniacid'],
  77. 'num' => intval($return['credit_value']),
  78. 'createtime' => TIMESTAMP,
  79. 'operator' => 0,
  80. 'remark' => $note
  81. );
  82. $credit_value = intval($return['credit_value']);
  83. mc_credit_update($uid, $credittype, $credit_value, $log);
  84. $ret['result'] = 'success';
  85. moduleInit($_GPC['module'], $ret);
  86. } else {
  87. $ret['result'] = 'repeat';
  88. moduleInit($_GPC['module'], $ret);
  89. }
  90. } else {
  91. $ret['result'] = 'action-miss';
  92. moduleInit($_GPC['module'], $ret);
  93. }
  94. function moduleInit($name, $params = array()) {
  95. if(empty($name)) {
  96. return false;
  97. }
  98. $site = WeUtility::createModuleSite($name);
  99. if(!is_error($site)) {
  100. $method = 'clickResult';
  101. if(method_exists($site, $method)) {
  102. $site->$method($params);
  103. exit('success');
  104. }
  105. exit();
  106. }
  107. exit();
  108. }