dever 6 years ago
parent
commit
b30012103b
6 changed files with 60 additions and 20 deletions
  1. 8 6
      act/src/Order.php
  2. 3 2
      buy/src/Buy.php
  3. 30 3
      code/lib/Core.php
  4. 8 8
      journal/database/active.php
  5. 10 0
      main/src/Content.php
  6. 1 1
      main/src/Journal_v1.php

+ 8 - 6
act/src/Order.php

@@ -151,7 +151,7 @@ class Order extends Core
 
         if ($this->data['code']) {
             foreach ($this->data['code'] as $k => $v) {
-                $this->data['code'][$k]['code'] = 'M' . $v['id'];
+                $this->data['code'][$k]['code'] = Dever::load('code/lib/core')->view($v['id'], $v['create_uid']);
             }
         }
 
@@ -285,13 +285,15 @@ class Order extends Core
 
             $journal_id = Dever::input('journal_id', false, '> 0', '请传入正确的小刊ID');
 
-            if (strstr($code, 'M')) {
-                $code = str_replace('M', '', $code);
+            if (strpos($code, 'M') === 0) {
+                $code = substr($code, 5);
                 Dever::setInput('set_product_id', $journal_id);
                 $info = Dever::db('code/info')->one($code);
-            } elseif (strstr($code, 'T')) {
-                $code = str_replace('T', '', $code);
-                $info = Dever::db('code/info')->one($code);
+                $uid = substr($uid, 1, 4);
+                $uid = Dever::uid($uid, 'decode');
+                if ($info && $info['create_id'] != $uid) {
+                    Dever::alert('请正确使用小刊兑换码');
+                }
             } else {
                 $info = Dever::db('code/info')->one(array('code' => $code));
             }

+ 3 - 2
buy/src/Buy.php

@@ -89,11 +89,12 @@ class Buy extends Base
 
         if ($data) {
             foreach ($data as $k => $v) {
-                $data[$k]['code'] = '<i class="ico-code"></i>兑换码:M'.$v['id'];
+                $code = Dever::load('code/lib/core')->view($v['id'], $v['create_uid']);
+                $data[$k]['code'] = '<i class="ico-code"></i>兑换码:'.$code;
                 if ($v['type'] == 1) {
                     $data[$k]['txt'] = '未使用';
                     $data[$k]['class'] = '';
-                    $data[$k]['copy'] = '<a href="javascript:;" class="button" node-id="copy" data-clipboard-text="'.$v['id'].'">复制</a>';
+                    $data[$k]['copy'] = '<a href="javascript:;" class="button" node-id="copy" data-clipboard-text="'.$code.'">复制</a>';
                 } else {
                     $data[$k]['txt'] = '已使用';
                     $data[$k]['class'] = 'used';

+ 30 - 3
code/lib/Core.php

@@ -95,9 +95,36 @@ class Core
                 $data['uid'] = $create_uid;
             }
 		}
+        $data['score'] = $score;
 
-		$data['score'] = $score;
-		$code = Dever::db('code/info')->insert($data, $num);
-		return $code;
+        $db = Dever::db('code/info');
+        if ($product_id > 0 && $create_uid > 0) {
+            $code = $db->insert($data, $num);
+            $code = $this->view($code, $create_uid);
+            return $code;
+        } else {
+            for ($i = 0; $i <= $num; $i++) {
+                $id = $db->insert($data);
+                if ($id) {
+                    $code = $this->view($id, -1);
+                    $db->update(array('code' => $code, 'where_id' => $id));
+                }
+            }
+
+            return $code;
+        }
 	}
+
+    public function view($id, $uid)
+    {
+        if ($uid > 0) {
+            $code = Dever::uid($uid);
+            $code = 'M' . $code . $id;
+        } else {
+            $code = Dever::rand(4);
+            $code = 'T' . $code . $id;
+        }
+        
+        return $code;
+    }
 }

+ 8 - 8
journal/database/active.php

@@ -111,8 +111,8 @@ return array
             'name'      => '邀请多少个好友开启免费阅读',
             'default'   => '10',
             'desc'      => '邀请多少个好友开启免费阅读',
-            'match'     => 'is_numeric',
-            'update'    => 'text',
+            'match'     => 'option',
+            //'update'    => 'text',
         ),
 
         'invite_score'     => array
@@ -121,8 +121,8 @@ return array
             'name'      => '每邀请一个好友获得积分-仅支持邀请新用户,设置之后,积分规则里的设置将失效',
             'default'   => '2',
             'desc'      => '每邀请一个好友获得积分',
-            'match'     => 'is_numeric',
-            'update'    => 'text',
+            'match'     => 'option',
+            //'update'    => 'text',
         ),
 
         'invite_title'     => array
@@ -131,8 +131,8 @@ return array
             'name'      => '邀请好友标题',
             'default'   => '邀请好友获得积分',
             'desc'      => '邀请好友标题',
-            'match'     => 'is_string',
-            'update'    => 'text',
+            'match'     => 'option',
+            //'update'    => 'text',
         ),
 
         'invite_desc'      => array
@@ -141,8 +141,8 @@ return array
             'name'      => '邀请好友标题介绍',
             'default'   => '邀请10人开启免费阅读',
             'desc'      => '邀请好友标题介绍',
-            'match'     => 'is_string',
-            'update'    => 'textarea',
+            'match'     => 'option',
+            //'update'    => 'textarea',
         ),
 
         'content'       => array

+ 10 - 0
main/src/Content.php

@@ -226,6 +226,16 @@ class Content extends Core
     # 首页精选
     public function home()
     {
+        $code = Dever::load('code/lib/core')->view(1000,10);
+        //$code = substr($code, 0, 5);
+        $code = substr($code, 1, 4);
+                echo $code;die;
+        $code = substr($code, 5);
+        echo $code;die;
+        if (strpos($code, 'M') === 0) {
+            echo 1;die;
+        }
+        echo 2;die;
         //MWY2M2MtZThRSG1iR2NHTjV6SjlHUDZvSHNlVURQVkRiT1dtREQxVVA4SThSOEc5bFhnUW43UExo
         //echo Dever::login(12);die;
         //1 NDY3MmVlOGVsdUxxa2pzNHczckR2TEl1NGFmVmVTd2ItWWhDcDB1T04wdXBDaUpDMl9rRmU4VHM=

+ 1 - 1
main/src/Journal_v1.php

@@ -341,7 +341,7 @@ class Journal_v1 extends Core
         $id = $this->check();
 
         $config_id = 31;
-        if ($id > $config_id || $id == 26) {
+        if ($id > $config_id || $id == 26 || $id == 30) {
             $this->data['top'] = Dever::load('act/lib/num')->getList($id);
         } else {
             $this->data['score'] = Dever::load('act/lib/score')->getList($id);