dever 4 yıl önce
ebeveyn
işleme
247dd1d2f6

+ 15 - 8
app/collection/lib/Core.php

@@ -36,14 +36,13 @@ class Core
 
     public function __construct()
     {
-        $this->checkCode();
     	# 获取当前的用户信息
         $this->token = Dever::input('token');
-        $this->uid = 1;
-        $this->share_uid = 1;
+        $this->uid = 2;
         $this->user = $this->getUser($this->uid, $this->id);
         $this->user['id'] = $this->uid;
         $this->system_source = Dever::input('system_source', 1);
+        $this->checkCode();
     }
 
     # 获取用户信息
@@ -90,7 +89,6 @@ class Core
         unset($info['udate']);
         unset($info['state']);
         unset($info['cdate']);
-        unset($info['score_id']);
         unset($info['score_type']);
         unset($info['score_name']);
         $info['id_code'] = Dever::encode($info['id'], $this->key);
@@ -103,7 +101,7 @@ class Core
             $this->checkInfo();
         }
         if ($this->info['buy'] == 1) {
-            # 收费 从订单中读取是否已经购买
+            # 收费 获取是否已经拥有
             $this->info['buy_data'] = Dever::load('user/lib/collection')->check($this->uid, $this->info['id']);
             return $this->info['buy_data'] ? true : false;
         } else {
@@ -145,10 +143,13 @@ class Core
                 $this->id = Dever::decode($this->id_code, $this->key);
             }
         }
+        if ($this->share_uid == $this->uid) {
+            $this->share_uid = 0;
+        }
     }
 
     # 获取邀请码
-    protected function getCode($id, $parent_page_id, $page_id, $index, $times_id, $day = 0, $uid = 0)
+    protected function getCode($id, $parent_page_id, $page_id, $index, $times_id, $day = 0, $uid = 0, $ticket_id = 0)
     {
         if (Dever::project('invite')) {
             $invite = Dever::input('invite');
@@ -168,7 +169,7 @@ class Core
             $day = 0;
         }
 
-        $key = 'dlv1_' . $id. '_' . $parent_page_id . '_' . $page_id . '_' . $index . '_' . $times_id . '_' . $day . '_' . $uid;
+        $key = 'dlv1_' . $id. '_' . $parent_page_id . '_' . $page_id . '_' . $index . '_' . $times_id . '_' . $day . '_' . $uid . '_' . $ticket_id;
 
         $code = Dever::encode($key, $this->key);
 
@@ -207,8 +208,14 @@ class Core
             $day = 0;
         }
 
+        # 获取门票
+        $ticket = Dever::load('user/lib/ticket')->check($this->uid, $this->id);
+        if ($ticket) {
+            $this->ticket_id = $ticket['id'];
+        }
+
         # 获取code
-        $code = $this->getCode($this->id, $parent_page_id, $page_id, $index, $times, $day, $this->uid);
+        $code = $this->getCode($this->id, $parent_page_id, $page_id, $index, $times, $day, $this->uid, $this->ticket_id);
 
         return $code;
     }

+ 14 - 1
app/collection/src/Api.php

@@ -202,11 +202,24 @@ class Api extends Core
         $data['share'] = $this->getInfoShare($data['info']);
 
         $data['share_user'] = array();
-        if ($data['is_buy'] && $this->share_uid && $this->share_uid > 0) {
+        if ($this->share_uid && $this->share_uid > 0) {
             # 获取分享人信息
             $data['share_user'] = $this->getUser($this->share_uid, $data['info']['id']);
             if ($data['share_user']) {
                 $data['share_user']['ticket'] = Dever::load('user/lib/ticket')->check($this->share_uid, $data['info']['id']);
+                if ($data['share_user']['ticket']) {
+                    $data['share_user']['code'] = $this->getCode($data['info']['id'], 0, 0, 0, 0, 0, $this->share_uid, $data['share_user']['ticket']['id']);
+                }
+            }
+
+            $data['share_ticket'] = '';
+            $check = Dever::load('user/lib/collection')->check($this->uid, $data['info']['id']);
+            if ($check) {
+                if ($check['source_uid'] == $this->share_uid) {
+                    $data['share_ticket'] = '你真好,期待下次还有你的礼物';
+                } else {
+                    $data['share_ticket'] = '你是个好人,你的好意我心领了';
+                }
             }
         }
 

+ 13 - 2
app/user/lib/Collection.php

@@ -21,8 +21,19 @@ class Collection
             if (!$info) {
                 $where['num'] = $num;
                 $where['source_uid'] = $source_uid;
-                Dever::db('user/collection')->insert($where);
-                Dever::db('user/ticket')->des(array('where_id' => $ticket_id, 'num' => $num));
+                $state = Dever::db('user/collection')->insert($where);
+                if ($state) {
+
+                    Dever::score($uid, 'use_ticket', '使用门票', false, false, false, 'collection', $info_id);
+                    
+                    if ($source_uid && $source_uid != $uid) {
+                        # 添加积分
+                        Dever::score($source_uid, 'give_ticket', '赠送门票', false, false, false, 'collection', $info_id);
+                    }
+
+                    # 减少门票
+                    Dever::db('user/ticket')->des(array('where_id' => $ticket_id, 'num' => $num));
+                }
             }
             return true;
         } else {

+ 1 - 1
app/user/lib/Ticket.php

@@ -165,7 +165,7 @@ class Ticket
                 } else {
                     $uid = $order['uid'];
                 }
-                Dever::score($uid, 'buy_ticket', '购买门票', false, false, false, 'collection', $order['info_id']);
+                Dever::score($uid, 'buy_ticket', '购买门票', false, false, false, 'collection/info', $order['info_id']);
 
                 # 发消息
                 if (Dever::project('message')) {

+ 11 - 9
app/user/src/Api.php

@@ -33,11 +33,9 @@ class Api extends Core
         }
 
         # 有多少门票
-        if ($info['buy'] == 1) {
-            $ticket = Dever::load('user/lib/ticket')->check($this->uid, $info['id']);
-            if ($ticket) {
-                $data['num'][2] = array($ticket['num'], '', $info['ticket_name']);
-            }
+        $ticket = Dever::load('user/lib/ticket')->check($this->uid, $info['id']);
+        if ($ticket) {
+            $data['num'][2] = array($ticket['num'], '', $info['ticket_name']);
         }
 
         //$data['num'][2] = array('10', '', '好友');
@@ -47,13 +45,17 @@ class Api extends Core
     }
 
     # 收下门票
-    public function getTicket()
+    public function saveTicket()
     {
         $info = $this->checkInfo();
-        $is_buy = $this->checkView();
-        if (!$is_buy && $this->share_uid && $this->share_uid > 0) {
-            Dever::load('user/lib/collection')->up($ticket_id, $this->uid, $this->share_uid, $info['id'], 1);
+        $check = Dever::load('user/lib/collection')->check($this->uid, $info['id']);
+        if ($check) {
+            Dever::alert('你已拥有' . $info['ticket_name'] . ',告诉他:“你是个好人,你的好意我心领了”');
         }
+        if ($this->share_uid && $this->share_uid > 0 && $this->ticket_id && $this->ticket_id > 0 && $this->share_uid != $this->uid) {
+            Dever::load('user/lib/collection')->up($this->ticket_id, $this->uid, $this->share_uid, $info['id'], 1);
+        }
+        return 'ok';
     }
 
     # 保存用户信息