|
@@ -6,6 +6,44 @@ use Dever;
|
|
|
|
|
|
class Core
|
|
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)
|
|
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);
|
|
$code = Dever::rand(8, 0);
|