dever 6 år sedan
förälder
incheckning
60291ae6fe
1 ändrade filer med 82 tillägg och 0 borttagningar
  1. 82 0
      act/src/Order.php

+ 82 - 0
act/src/Order.php

@@ -300,6 +300,88 @@ class Order extends Core
         return $this->data;
         return $this->data;
     }
     }
 
 
+    # 开始兑换
+    public function checkCode()
+    {
+        if (!$this->data['uid']) {
+            Dever::alert('错误的用户信息');
+        }
+
+        $code = Dever::input('code');
+
+        if ($code) {
+            $code = trim($code);
+            $code = str_replace("\n", '', $code);
+
+            $journal_id = Dever::input('journal_id');
+            if (strstr($journal_id, 'preview_')) {
+                $journal_id = str_replace('preview_', '', $journal_id);
+            }
+
+            if (!$journal_id) {
+                Dever::alert('请传入正确的小刊ID');
+            }
+
+            if (strpos($code, 'M') === 0) {
+                Dever::setInput('set_product_id', $journal_id);
+                $code = substr($code, 1);
+                $code = Dever::uid($code, 'decode');
+                $code = $code / 10000000;
+                $info = Dever::db('code/info')->one($code);
+                
+            } else {
+                $info = Dever::db('code/info')->one(array('code' => $code));
+            }
+
+            if (!$info) {
+                Dever::alert('兑换码不存在');
+            }
+
+            if ($info['type'] == 3) {
+                Dever::alert('兑换码已被使用');
+            }
+
+            if ($info['state'] != 1) {
+                Dever::alert('兑换码已作废');
+            }
+
+            if ($info['type'] == 4) {
+                Dever::alert('兑换码已作废');
+            }
+
+            if ($info['type'] == 2 && $this->data['uid'] != $info['uid']) {
+                //Dever::alert('兑换码已被领取');
+            }
+
+            if ($info['product_id'] > 0 && $info['product_id'] != $journal_id) {
+                Dever::alert('请正确使用小刊兑换码');
+            }
+
+            if (isset($info['order_id']) && $info['order_id']) {
+                $order_info = $this->getOrder($info['order_id']);
+                if (!$order_info) {
+                    Dever::alert('您要使用的兑换码还未支付');
+                }
+
+                if ($order_info && $order_info['status'] != 2) {
+                    Dever::alert('您要使用的兑换码还未支付');
+                }
+            }
+
+            if ($info['product_id']) {
+                $product = Dever::db('journal/info')->one($info['product_id']);
+                $this->data['product'] = $product;
+
+                return $this->data;
+            }
+
+        } else {
+            Dever::alert('请输入正确的兑换码');
+        }
+
+        return 'ok';
+    }
+
     # 开始兑换
     # 开始兑换
     public function code()
     public function code()
     {
     {