dever 6 年之前
父节点
当前提交
6379181946
共有 5 个文件被更改,包括 73 次插入0 次删除
  1. 6 0
      code/database/info.php
  2. 38 0
      code/lib/Core.php
  3. 9 0
      journal/lib/Pay.php
  4. 11 0
      main/src/Journal.php
  5. 9 0
      service/src/Buy.php

+ 6 - 0
code/database/info.php

@@ -9,6 +9,12 @@ $type = array
 	4 => '已作废',
 );
 
+$status = array
+(
+	1 => '不可用',
+	2 => '可用',
+);
+
 $product = Dever::load('journal/api.data');
 
 $seller = function()

+ 38 - 0
code/lib/Core.php

@@ -6,6 +6,44 @@ use Dever;
 
 class Core
 {
+	public function createCodeByOrder($order)
+	{
+		$code = '';
+        if ($order['type'] == 3 && !$order['code']) {
+            # 购买兑换码
+            $product_num = 1;
+            $code_num = 1;
+            if ($order['buy_id'] > 0) {
+                $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
+                $product_num = $buy['num'];
+                $code_num = $buy['code'];
+            }
+            
+            # 检查之前有多少个兑换码,防止多发
+            $code_where['order_id'] = $order['order_id'];
+        	$total = Dever::db('code/info')->total($code_where);
+        	if ($total && $total > 0) {
+        		if ($code_num > $total) {
+        			$code_num = $code_num - $total;
+        		} else {
+        			$one = Dever::db('code/info')->one($code_where);
+        			return $one['code'];
+        		}
+        	}
+
+            if ($code_num > 1) {
+                $product_num = intval($product_num/$code_num);
+                for ($i = 0; $i < $code_num; $i++) {
+                    $code = $this->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $order['uid'], $order['order_id']);
+                }
+            } else {
+                $code = $this->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $order['uid'], $order['order_id']);
+            }
+        }
+
+        return $code;
+	}
+
 	public function createCode($product, $cate_id, $product_id, $seller_id, $product_num = 0, $create_uid = -1, $order_id = false, $score = 0)
 	{
 		$code = Dever::rand(8, 0);

+ 9 - 0
journal/lib/Pay.php

@@ -99,6 +99,14 @@ class Pay
                 $update = array();
                 $update['where_id'] = $order['id'];
                 $update['status'] = 2;
+                if ($order['type'] == 3 && !$order['code']) {
+                    $code = Dever::load('code/lib/core')->createCodeByOrder($order);
+                    if ($code) {
+                        $update['code'] = $code;
+                    }
+                }
+
+                /*
                 if ($order['type'] == 3 && !$order['code']) {
                     # 购买兑换码
                     $product_num = 1;
@@ -118,6 +126,7 @@ class Pay
                         $update['code'] = Dever::load('code/lib/core')->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $uid, $order['order_id']);
                     }
                 }
+                */
 
                 Dever::db('journal/order')->update($update);
 

+ 11 - 0
main/src/Journal.php

@@ -1085,6 +1085,17 @@ class Journal extends Core
                 Dever::alert('请正确使用小刊兑换码');
             }
 
+            if (isset($info['order_id']) && $info['order_id'] > 0) {
+                $order_info = Dever::db('journal/order')->one(array('order_id' => $info['order_id']));
+                if (!$order_info) {
+                    Dever::alert('您要使用的兑换码还未支付');
+                }
+
+                if ($order_info && $order_info['status'] != 2) {
+                    Dever::alert('您要使用的兑换码还未支付');
+                }
+            }
+
             $order = Dever::db('journal/order')->one(array('product_id' => $journal_id, 'code' => $code, 'type' => 2, 'uid' => $this->data['uid']));
 
             if ($order) {

+ 9 - 0
service/src/Buy.php

@@ -162,6 +162,15 @@ class Buy extends Base
             $this->location('list');
         }
 
+        $uid = $this->user['id'];
+
+        $code = Dever::load('code/lib/core')->createCodeByOrder($order);
+        if ($code) {
+            $update['where_id'] = $order['id'];
+            $order['code'] = $update['code'] = $code;
+            Dever::db('journal/order')->update($update);
+        }
+
         $config['code_show'] = 'display:none;';
         $config['button'] = '继续购买';
         $config['button_node'] = '';