dever 6 gadi atpakaļ
vecāks
revīzija
178b0c8751
2 mainītis faili ar 53 papildinājumiem un 0 dzēšanām
  1. 16 0
      journal/database/order.php
  2. 37 0
      journal/lib/Pay.php

+ 16 - 0
journal/database/order.php

@@ -473,5 +473,21 @@ return array
             'order' => array('cdate' => 'desc'),
             'col' => '*',
         ),
+
+        # 获取没有兑换码的订单
+        'getUnCode' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'code' => array('yes', '!=""'),
+                'status' => 'yes',
+                'type' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'col' => '*',
+        ),
     ),
 );

+ 37 - 0
journal/lib/Pay.php

@@ -6,6 +6,43 @@ use Dever;
 class Pay
 {
     private $key = 'jmss_2018';
+
+    public function go_api()
+    {
+        $where['type'] = 3;
+        $where['status'] = 2;
+        $data = Dever::db('journal/order')->getUnCode($where);
+
+        if ($data) {
+            print_r($data);die;
+            foreach ($data as $k => $v) {
+                # 购买兑换码
+                $order = $v;
+                $product_num = 1;
+                $code_num = 1;
+                $uid = $order['uid'];
+                if ($order['buy_id'] > 0) {
+                    $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
+                    $product_num = $buy['num'];
+                    $code_num = $buy['code'];
+                }
+                
+                if ($code_num > 1) {
+                    $product_num = intval($product_num/$code_num);
+                    for ($i = 0; $i < $code_num; $i++) {
+                        $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']);
+                    }
+                } else {
+                    $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']);
+                }
+
+                $update['where_id'] = $order['id'];
+                Dever::db('journal/order')->update($update);
+            }
+        }
+    }
+
+
     public function test_api()
     {
         $data['status'] = 1;