| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 | 
							- <?php
 
- namespace Code\Lib;
 
- 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);
 
- 		$data['code'] = $code;
 
- 		$total = Dever::db('code/info')->total($data);
 
- 		if ($total > 0) {
 
- 			return $this->createCode($product, $cate_id, $product_id, $seller_id, $product_num, $create_uid, $order_id, $score);
 
- 		}
 
- 		
 
- 		//$data['product'] = $product;
 
- 		$data['cate_id'] = $cate_id;
 
- 		$data['product_id'] = $product_id;
 
- 		$data['seller_id'] = $seller_id;
 
- 		$data['product_num'] = $product_num;
 
- 		
 
- 		$data['type'] = 1;
 
- 		if ($order_id) {
 
- 			$data['order_id'] = $order_id;
 
- 		}
 
- 		if ($create_uid > 0) {
 
- 			$data['create_uid'] = $create_uid;
 
- 		}
 
- 		$data['score'] = $score;
 
- 		Dever::db('code/info')->insert($data);
 
- 		return $code;
 
- 	}
 
- }
 
 
  |