267 lines
7.5 KiB
PHP
267 lines
7.5 KiB
PHP
<?php
|
|
|
|
|
|
|
|
namespace addon\cases\model;
|
|
use app\model\BaseModel;
|
|
/**
|
|
* 文件
|
|
*/
|
|
class Enterprise extends BaseModel
|
|
{
|
|
|
|
/**
|
|
* 添加文件
|
|
* @param $data
|
|
* @return array
|
|
*/
|
|
public function addFiles($data)
|
|
{
|
|
$data[ 'createtime' ] = time();
|
|
|
|
model('cases_files')->startTrans();
|
|
try {
|
|
//添加文件
|
|
model('cases_files')->add($data);
|
|
model('cases_files')->commit();
|
|
return $this->success();
|
|
} catch (\Exception $e) {
|
|
model('cases_files')->rollback();
|
|
return $this->error('', $e->getMessage());
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 编辑文件
|
|
* @param $condition
|
|
* @param $data
|
|
* @return array
|
|
*/
|
|
public function editFiles($data)
|
|
{
|
|
// $data[ 'update_time' ] = time();
|
|
model('cases_files')->startTrans();
|
|
try {
|
|
//添加文件
|
|
model('cases_files')->update($data, [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'files_id', '=', $data[ 'files_id' ] ] ]);
|
|
model('cases_files')->commit();
|
|
return $this->success();
|
|
} catch (\Exception $e) {
|
|
model('cases_files')->rollback();
|
|
return $this->error('', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除文件
|
|
* @param $files_id
|
|
* @param $site_id
|
|
* @return array|\multitype
|
|
*/
|
|
public function deleteFiles($condition)
|
|
{
|
|
//文件数
|
|
$files_info = model('cases_files')->getInfo($condition, '*');
|
|
if (empty($files_info)) {
|
|
return $this->success('', '数据不合法');
|
|
} else {
|
|
|
|
model('cases_files')->startTrans();
|
|
try {
|
|
//删除文件
|
|
model('cases_files')->delete($condition);
|
|
model('cases_files')->commit();
|
|
return $this->success();
|
|
} catch (\Exception $e) {
|
|
model('cases_files')->rollback();
|
|
return $this->error('', $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取文件信息
|
|
* @param array $condition
|
|
* @param string $field
|
|
* @return array
|
|
*/
|
|
public function getFilesInfo($condition = [], $field = '*')
|
|
{
|
|
$info = model("cases_files")->getInfo($condition, $field);
|
|
return $this->success($info);
|
|
}
|
|
|
|
/**
|
|
* 获取文件信息
|
|
* @param array $condition
|
|
* @param string $field
|
|
* @param int $type
|
|
* @return array
|
|
*/
|
|
public function getFilesDetailInfo($condition = [], $field = '*', $type = 1)
|
|
{
|
|
$info = model('cases_files')->getInfo($condition, $field);
|
|
//添加浏览记录
|
|
if ($type == 2) {
|
|
model('cases_files')->setInc($condition, 'read_num', 1);
|
|
}
|
|
return $this->success($info);
|
|
}
|
|
|
|
/**
|
|
* 获取文件列表
|
|
* @param array $condition
|
|
* @param string $field
|
|
* @param string $order
|
|
* @param string $limit
|
|
*/
|
|
public function getFilesList($condition = [], $field = '*', $order = '', $limit = null, $alias = '', $join = [])
|
|
{
|
|
$list = model('cases_files')->getList($condition, $field, $order, $alias, $join, '', $limit);
|
|
return $this->success($list);
|
|
}
|
|
|
|
/**
|
|
* 获取文件分页列表
|
|
* @param array $condition
|
|
* @param int $page
|
|
* @param int $page_size
|
|
* @param string $order
|
|
* @param string $field
|
|
* @return array
|
|
*/
|
|
public function getFilesPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'pn.createtime asc', $field = 'pn.*')
|
|
{
|
|
$alias = 'pn';
|
|
$join = [];
|
|
$list = model('cases_files')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
|
return $this->success($list);
|
|
}
|
|
|
|
/**
|
|
* 生成推广二维码链接
|
|
* @param $qrcode_param
|
|
* @param $site_id
|
|
* @return array
|
|
*/
|
|
public function urlQrcode($qrcode_param, $app_type, $site_id)
|
|
{
|
|
$h5_page = '/pages_tool/files/detail';
|
|
$pc_page = '/cms/files/detail';
|
|
$params = [
|
|
'site_id' => $site_id,
|
|
'data' => $qrcode_param,
|
|
'pc_data' => [ 'id' => $qrcode_param[ 'files_id' ] ],
|
|
'page' => $h5_page,
|
|
'h5_path' => $h5_page . '?files_id=' . $qrcode_param[ 'files_id' ],
|
|
'pc_page' => $pc_page,
|
|
'pc_path' => $pc_page . '?id=' . $qrcode_param[ 'files_id' ],
|
|
'qrcode_path' => 'upload/qrcode/files',
|
|
'qrcode_name' => 'files_qrcode' . $qrcode_param[ 'files_id' ] . '_' . $site_id,
|
|
'app_type' => $app_type,
|
|
];
|
|
|
|
$solitaire = event('PromotionQrcode', $params);
|
|
return $this->success($solitaire[ 0 ]);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//视频
|
|
/**
|
|
* 获取分页列表
|
|
* @param array $condition
|
|
* @param number $page
|
|
* @param string $page_size
|
|
* @param string $order
|
|
* @param string $field
|
|
*/
|
|
public function getVideoPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'sort asc', $field = '*')
|
|
{
|
|
$check_condition = array_column($condition, 2, 0);
|
|
$site_id = $check_condition['site_id'] ?? '';
|
|
if ($site_id === '') {
|
|
return $this->error('', 'REQUEST_SITE_ID');
|
|
}
|
|
|
|
$list = model('cases_video')->pageList($condition, $field, $order, $page, $page_size);
|
|
return $this->success($list);
|
|
}
|
|
/**
|
|
* 获取视频列表
|
|
* @param array $condition
|
|
* @param string $field
|
|
* @param string $order
|
|
* @param string $limit
|
|
*/
|
|
public function getVideoList($condition = [], $field = '*', $order = '', $limit = null)
|
|
{
|
|
$list = model('cases_video')->getList($condition, $field, $order, '', '', '', $limit);
|
|
return $this->success($list);
|
|
}
|
|
|
|
/**
|
|
* 添加商户分类
|
|
* @param array $data
|
|
*/
|
|
public function addVideo($data)
|
|
{
|
|
$site_id = $data['site_id'] ?? '';
|
|
if ($site_id === '') {
|
|
return $this->error('', 'REQUEST_SITE_ID');
|
|
}
|
|
|
|
$data[ 'create_time' ] = time();
|
|
$category_id = model('cases_video')->add($data);
|
|
return $this->success($category_id);
|
|
}
|
|
|
|
public function getVideoInfo($condition = [], $field = '*')
|
|
{
|
|
$list = model('cases_video')->getInfo($condition, $field);
|
|
return $this->success($list);
|
|
}
|
|
|
|
/**
|
|
* 修改商户分类
|
|
* @param array $data
|
|
*/
|
|
public function editVideo($data)
|
|
{
|
|
$site_id = $data['site_id'] ?? '';
|
|
if ($site_id === '') {
|
|
return $this->error('', 'REQUEST_SITE_ID');
|
|
}
|
|
model('cases_video')->startTrans();
|
|
try {
|
|
//添加文件
|
|
model('cases_video')->update($data, [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'video_id', '=', $data[ 'video_id' ] ] ]);
|
|
model('cases_video')->commit();
|
|
return $this->success();
|
|
} catch (\Exception $e) {
|
|
model('cases_video')->rollback();
|
|
return $this->error('', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除商户分类
|
|
* @param array $condition
|
|
*/
|
|
public function deleteVideo($condition)
|
|
{
|
|
// file_put_contents(__DIR__ . '/debug.txt', var_export($condition,true));
|
|
$check_condition = array_column($condition, 2, 0);
|
|
$site_id = $check_condition['site_id'] ?? '';
|
|
if ($site_id === '') {
|
|
return $this->error('', 'REQUEST_SITE_ID');
|
|
}
|
|
|
|
$res = model('cases_video')->delete($condition);
|
|
return $this->success($res);
|
|
}
|
|
|
|
} |