人人商城

processor.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. if (!defined('IN_IA')) {
  3. exit('Access Denied');
  4. }
  5. require IA_ROOT . '/addons/ewei_shopv2/defines.php';
  6. require EWEI_SHOPV2_INC . 'plugin/plugin_processor.php';
  7. class CreditshopProcessor extends PluginProcessor
  8. {
  9. public function __construct()
  10. {
  11. parent::__construct('creditshop');
  12. }
  13. public function respond($obj = NULL)
  14. {
  15. global $_W;
  16. $message = $obj->message;
  17. $openid = $obj->message['from'];
  18. $content = $obj->message['content'];
  19. $msgtype = strtolower($message['msgtype']);
  20. $event = strtolower($message['event']);
  21. if ($msgtype == 'text' || $event == 'click') {
  22. $saler = pdo_fetch('select * from ' . tablename('ewei_shop_saler') . ' where openid=:openid and uniacid=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':openid' => $openid));
  23. if (empty($saler)) {
  24. return $this->responseEmpty();
  25. }
  26. if (!$obj->inContext) {
  27. $obj->beginContext();
  28. return $obj->respText('请输入兑换码:');
  29. }
  30. if ($obj->inContext && is_numeric($content)) {
  31. $log = pdo_fetch('select * from ' . tablename('ewei_shop_creditshop_log') . ' where eno=:eno and uniacid=:uniacid limit 1', array(':eno' => $content, ':uniacid' => $_W['uniacid']));
  32. if (empty($log)) {
  33. return $obj->respText('未找到要兑换码,请重新输入!');
  34. }
  35. $logid = $log['id'];
  36. if (empty($log)) {
  37. return $obj->respText('未找到要兑换码,请重新输入!');
  38. }
  39. if (empty($log['status'])) {
  40. return $obj->respText('无效兑换记录!');
  41. }
  42. if (3 <= $log['status']) {
  43. return $obj->respText('此记录已兑换过了!');
  44. }
  45. $member = m('member')->getMember($log['openid']);
  46. $goods = $this->model->getGoods($log['goodsid'], $member);
  47. if (empty($goods['id'])) {
  48. return $obj->respText('商品记录不存在!');
  49. }
  50. if (empty($goods['isverify'])) {
  51. $obj->endContext();
  52. return $obj->respText('此商品不支持线下兑换!');
  53. }
  54. if (!empty($goods['type'])) {
  55. if ($log['status'] <= 1) {
  56. return $obj->respText('未中奖,不能兑换!');
  57. }
  58. }
  59. if (0 < $goods['money'] && empty($log['paystatus'])) {
  60. return $obj->respText('未支付,无法进行兑换!');
  61. }
  62. if (0 < $goods['dispatch'] && empty($log['dispatchstatus'])) {
  63. return $obj->respText('未支付运费,无法进行兑换!');
  64. }
  65. $stores = explode(',', $goods['storeids']);
  66. if (!empty($storeids)) {
  67. if (!empty($saler['storeid'])) {
  68. if (!in_array($saler['storeid'], $storeids)) {
  69. return $obj->respText('您无此门店的兑换权限!');
  70. }
  71. }
  72. }
  73. $time = time();
  74. pdo_update('ewei_shop_creditshop_log', array('status' => 3, 'usetime' => $time, 'verifyopenid' => $openid), array('id' => $log['id']));
  75. $this->model->sendMessage($logid);
  76. $obj->endContext();
  77. return $obj->respText('兑换成功!');
  78. }
  79. }
  80. }
  81. private function responseEmpty()
  82. {
  83. ob_clean();
  84. ob_start();
  85. echo '';
  86. ob_flush();
  87. ob_end_flush();
  88. exit(0);
  89. }
  90. }
  91. ?>