人人商城

share.ctrl.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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['uid'])) {
  28. $uid = $_W['member']['uid'];
  29. } else {
  30. $uid = intval($_GPC['uid']);
  31. }
  32. if(!empty($uid)) {
  33. $user = pdo_fetchcolumn('SELECT uid FROM ' . tablename('mc_members'). ' WHERE uniacid = :uniacid AND uid = :uid', array(':uniacid' => $_W['uniacid'], ':uid' => $uid));
  34. if(empty($user)) {
  35. $ret['result'] = 'uid-error';
  36. moduleInit($_GPC['module'], $ret);
  37. }
  38. if(!empty($_GPC['action'])) {
  39. $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';
  40. $parm = array(':uniacid' => $_W['uniacid'], ':touid' => $uid, ':fromuid' => 0, ':module' => $_GPC['module'], ':sign' => $_GPC['sign'], ':action' => $_GPC['action']);
  41. $is_add = pdo_fetchcolumn($sql, $parm);
  42. if(empty($is_add)) {
  43. $creditbehaviors = pdo_fetchcolumn('SELECT creditbehaviors FROM ' . tablename('uni_settings') . ' WHERE uniacid = :uniacid', array(':uniacid' => $_W['uniacid']));
  44. $creditbehaviors = iunserializer($creditbehaviors) ? iunserializer($creditbehaviors) : array();
  45. if(empty($creditbehaviors['activity'])) {
  46. $ret['result'] = 'creditset-miss';
  47. moduleInit($_GPC['module'], $ret);
  48. } else {
  49. $credittype = $creditbehaviors['activity'];
  50. }
  51. $data = array(
  52. 'uniacid' => $_W['uniacid'],
  53. 'touid' => $uid,
  54. 'fromuid' => 0,
  55. 'module' => $_GPC['module'],
  56. 'sign' => $_GPC['sign'],
  57. 'action' => $_GPC['action'],
  58. 'credit_value' => intval($return['credit_value']),
  59. 'createtime' => TIMESTAMP
  60. );
  61. pdo_insert('mc_handsel', $data);
  62. $note = empty($_GPC['note']) ? '系统赠送积分' : $_GPC['note'];
  63. $log = array(
  64. 'uid' => $uid,
  65. 'credittype' => $credittype,
  66. 'uniacid' => $_W['uniacid'],
  67. 'num' => intval($return['credit_value']),
  68. 'createtime' => TIMESTAMP,
  69. 'operator' => 0,
  70. 'remark' => $note
  71. );
  72. $credit_value = intval($return['credit_value']);
  73. mc_credit_update($uid, $credittype, $credit_value, $log);
  74. $ret['result'] = 'success';
  75. moduleInit($_GPC['module'], $ret);
  76. } else {
  77. $ret['result'] = 'repeat';
  78. moduleInit($_GPC['module'], $ret);
  79. }
  80. } else {
  81. $ret['result'] = 'action-miss';
  82. moduleInit($_GPC['module'], $ret);
  83. }
  84. } else {
  85. $ret['result'] = 'uid-miss';
  86. moduleInit($_GPC['module'], $ret);
  87. }
  88. function moduleInit($name, $params = array()) {
  89. if(empty($name)) {
  90. return false;
  91. }
  92. $site = WeUtility::createModuleSite($name);
  93. if(!is_error($site)) {
  94. $method = 'shareResult';
  95. if(method_exists($site, $method)) {
  96. $site->$method($params);
  97. exit('success');
  98. }
  99. }
  100. }