Browse Source

资源 分享

master
unknown 1 year ago
parent
commit
89ff31c749
  1. 2
      app/common.php
  2. 25
      app/controller/ShareController.php
  3. 9
      app/model/Content.php
  4. 10
      app/model/ShareItem.php

2
app/common.php

@ -60,7 +60,7 @@ function findParent($obj, $id, &$path)
function getResourceShareInfo()
{
$code = uniqid();
$share_link = url('share/index', ['id' => $code])->domain(true);
$share_link = url('share/index', ['code' => $code])->domain(true);
$password = str_pad(rand(0, 9999), 4, '0', STR_PAD_LEFT);
return [
'code' => $code,

25
app/controller/ShareController.php

@ -0,0 +1,25 @@
<?php
namespace app\controller;
use app\model\Resource;
use app\model\Share;
use app\service\ResourceService;
use app\service\ShareService;
use app\validate\ResourceValidate;
use think\facade\Db;
use think\facade\Lang;
use think\exception\ValidateException;
use think\Request;
class ShareController
{
public function index(Request $request)
{
$code = $request->param('code');
$share = Share::with(['share_item', 'share_item.target'])
->where('code', $code)->find();
return jsonReturn(0, Lang::get('成功'), $share);
}
}

9
app/model/Content.php

@ -0,0 +1,9 @@
<?php
namespace app\model;
use app\exception\ModelException;
class Content extends Model
{
}

10
app/model/ShareItem.php

@ -6,4 +6,14 @@ use app\exception\ModelException;
class ShareItem extends Model
{
/**
* 获取关联的目标模型
*/
public function target()
{
return $this->morphTo('target', [
'1' => Resource::class,
'2' => Content::class,
]);
}
}
Loading…
Cancel
Save