dever 4 years ago
parent
commit
57081d9c1f
2 changed files with 115 additions and 3 deletions
  1. 22 1
      app/collection/database/content.php
  2. 93 2
      app/collection/src/Api.php

+ 22 - 1
app/collection/database/content.php

@@ -139,7 +139,7 @@ return array
             'default'   => '',
             'desc'      => '分享图片',
             'match'     => 'option',
-            'update'    => 'image',
+            'update'    => 'images',
             'key'       => '1',
             'place'     => '300*300',
             //'upload'  => 'qiniu',
@@ -156,6 +156,27 @@ return array
             'update'    => 'textarea',
         ),
 
+        'copy_text'       => array
+        (
+            'type'      => 'text-255',
+            'name'      => '复制文案',
+            'default'   => '',
+            'desc'      => '复制文案',
+            'match'     => 'is_string',
+            'update'    => array
+            (
+                array
+                (
+                    'col'       => 'name',
+                    'name'      => '文字内容',
+                    'default'   => '',
+                    'desc'      => '文字内容',
+                    'match'     => 'is_string',
+                    'update'    => 'textarea',
+                ),
+            ),
+        ),
+
         'reorder'       => array
         (
             'type'      => 'int-11',

+ 93 - 2
app/collection/src/Api.php

@@ -37,10 +37,101 @@ class Api extends Core
         return $data;
     }
 
-    # 获取分享的链接
+    public function qrcode($url, $content_id)
+    {
+        $file = 'shareDv_' . $this->uid . '_' . $this->id . '_' . $content_id;
+        $file = Dever::load('qrcode/api')->qrcode($url, $file, $this->user['avatar']);
+
+        return $file['url'];
+    }
+
+    # 获取分享的内容
     public function getShare()
     {
-        
+        $url = Dever::input('url');
+        $type = Dever::input('type');
+        $index = Dever::input('index');
+        $content_id = Dever::input('content_id');
+        $data = array();
+        $info = Dever::db('collection/info')->one($this->id);
+        $data['info'] = $data['pic'] = $data['text'] = $data['share'] = array();
+        $data['info']['id'] = $content_id;
+        $data['info']['platform_name'] = $info['name'];
+        $data['info']['qrcode'] = $data['info']['name'] = $data['info']['price'] = $data['info']['s_price'] = '';
+
+        $code = $this->getCode($this->id, $this->parent_page_id, $this->page_id, $index, $this->times, $this->uid);
+        $url .= '?code=' . $code;
+
+        $data['info']['qrcode'] = $this->qrcode($url, $content_id);
+
+        $background = array
+        (
+            '#ffaa00',
+            '#bababa'
+        );
+        if ($type == -1) {
+            $page = Dever::db('collection/page')->one($content_id);
+            $data['info']['name'] = $page['name'];
+            $data['pic'] = explode(',', $page['pic']);
+            $data['text'] = array(
+                array
+                (
+                    'background' => $background[0],
+                    'content' => $page['desc'],
+                )
+            );
+            $data['share'] = array
+            (
+                'title' => $page['name'],
+                'content' => $page['desc'],
+                'pic' => $page['pic'],
+            );
+        } else {
+            $content = Dever::db('collection/content')->one($content_id);
+            $data['info']['name'] = $content['share_title'] ? $content['share_title'] : $content['name'];
+            if ($content['share_pic']) {
+                $data['pic'] = explode(',', $content['share_pic']);
+            } else {
+                $data['pic'] = explode(',', $content['pic']);
+            }
+
+            if ($content['type'] == 70) {
+                $content['data'] = Dever::db('content/product')->one(array('content_id' => $content['id'], 'info_id' => $content['info_id']));
+
+                if (isset($content['data']['goods_id']) && $content['data']['goods_id'] > 0) {
+                    $goods = Dever::load('goods/lib/info')->getInfo($content['data']['goods_id']);
+                    if ($goods && isset($goods['price']['min']['price'])) {
+                        $data['info']['price'] = '¥' . $goods['price']['min']['price'];
+                        $data['info']['s_price'] = '¥' . $goods['price']['min']['s_price'];
+                    }
+                }
+            }
+            
+            $text = Dever::array_decode($content['copy_text']);
+            $i = 0;
+            foreach ($text as $k => $v) {
+                if ($v['name']) {
+                    $back = $background[1];
+                    if ($i == 0) {
+                        $back = $background[0];
+                    }
+                    $data['text'][$i] = array
+                    (
+                        'background' => $back,
+                        'content' => $v['name'],
+                    );
+                    $i++;
+                }
+            }
+            $data['share'] = array
+            (
+                'title' => $data['info']['name'],
+                'content' => $content['share_content'],
+                'pic' => $data['pic'][0],
+            );
+        }
+
+        return $data;
     }
 
     # 获取合集内容