Files
liche/market/controllers/api/sytopic/Topic.php
T
2024-07-31 17:36:59 +08:00

227 lines
9.0 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
class Topic extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('market/Market_sytopic_model', 'mSytopic');
$this->load->library('MyEncryption');
}
/**
* 专题管理列表
* @return void
*/
public function page_get()
{
$page = $this->input_param('page');
$limit = $this->input_param('limit');
$title = $this->input_param('title');
$sort = $this->input_param('sort');
$order = $this->input_param('order');
!$page && $page = 1;
!$limit && $limit = 10;
$sort_order = 'id desc';
if ($sort && $order) {
$sort_order = $sort . ' ' . $order;
}
$list = [];
$where['status>='] = 0;
$title && $where['title LIKE "%' . trim($title) . '%"'] = null;
if ($_SESSION['brandName']) {//品牌机构
$re_org = $this->mdSyliveOrganization->get(['organizationName' => $_SESSION['brandName'], 'parentId' => 0, 'status' => 0]);
if ($re_org['organizationId']) {
$where['organizationId'] = $re_org['organizationId'];
} else {
$where['organizationId'] = -1;
}
}
$count = $this->mSytopic->count($where);
if ($count) {
$this->load->library('MyEncryption');
$res = $this->mSytopic->select($where, $sort_order, $page, $limit);
foreach ($res as $v) {
$shareImg = $sharePhoto = $banner = [];
$jsonData = json_decode($v['jsondata'], true);
$jsonData['bg_color'] = $jsonData['bg_color'] ?: '';
if ($v['banner']) {
$banner = [['uid' => 1, 'fileUrl' => $v['banner'], 'url' => build_qiniu_image_url($v['banner']), 'status' => 'done']];
}
if ($v['sharePhoto']) {
$sharePhoto = [['uid' => 1, 'fileUrl' => $v['sharePhoto'], 'url' => build_qiniu_image_url($v['sharePhoto']), 'status' => 'done']];
}
if ($v['shareImg']) {
$getShareImg = json_decode($v['shareImg'], true);
foreach ($getShareImg as $k2 => $v2) {
$shareImg[] = ['uid' => $k2, 'fileUrl' => $v2, 'url' => build_qiniu_image_url($v2), 'status' => 'done'];
}
}
if($jsonData['banner']){
$jsonData['banner'] = [['uid' => 1, 'fileUrl' => $jsonData['banner'], 'url' => build_qiniu_image_url($jsonData['banner']), 'status' => 'done']];
}else{
$jsonData['banner'] = [];
}
$v['status'] = intval($v['status']);
$v['sharePhoto'] = $sharePhoto;
$v['banner'] = $banner;
$v['shareImg'] = $shareImg;
$v['organizationId'] = intval($v['organizationId']);
$v['dateRange'] = $v['timeStart'] ? [$v['timeStart'], $v['timeEnd']] : [];
$v['shareTitle'] = $v['shareTitle'] ? json_decode($v['shareTitle'], true) : [];
$v['json'] = $jsonData;
$list[] = $v;
}
}
$date = ['list' => $list, 'count' => $count];
$this->return_response_list($date);
}
public function detail_get()
{
$id = $this->input_param('id');
$res = $this->mSytopic->get(['id' => $id]);
if (!$res) {
$this->return_json('参数错误');
}
$skey = $this->myencryption->base64url_encode("a_id=" . $res['id']);
$date = ['url' => http_host_com('home') . "/h5/market/sylive2?skey=" . $skey];
$this->return_response_list($date);
}
/**
* 添加专题
*/
public function index_post()
{
$title = $this->input_param('title');
$dateRange = $this->input_param('dateRange');
$shareTitle = $this->input_param('shareTitle');
$shareImg = $this->input_param('shareImg');
$sharePhoto = $this->input_param('sharePhoto');
$organizationId = intval($this->input_param('organizationId'));
$banner = $this->input_param('banner');
$introduction = $this->input_param('introduction');
$jsonData = $this->input_param('json');
if (!$title) {
$this->return_json('请输入活动标题');
}
if (!$banner[0]['fileUrl']) {
$this->return_json('请选择banner图');
}
if (!$dateRange) {
$this->return_json('请选择活动时间');
}
$sharePhoto = $sharePhoto ? $sharePhoto[0]['fileUrl'] : '';
$banner = $banner ? $banner[0]['fileUrl'] : '';
$shareTitle = $shareTitle ? json_encode($shareTitle, JSON_UNESCAPED_UNICODE) : '';
$setShareImg = '';
if ($shareImg) {
foreach ($shareImg as $v) {
$setShareImg[] = $v['fileUrl'];
}
$setShareImg = json_encode($setShareImg, JSON_UNESCAPED_UNICODE);
}
$setJsonData = [];
if ($jsonData['banner']) {
$setJsonData['banner'] = $jsonData['banner'] ? $jsonData['banner'][0]['fileUrl'] : '';
} else {
$setJsonData['banner'] = '';
}
$setJsonData['bg_color'] = $jsonData['bg_color'] ?: '';
$createTime = date('Y-m-d H:i:s');
$addData = ['title' => $title, 'banner' => $banner, 'status' => 1, 'createTime' => $createTime, 'organizationId' => $organizationId,
'sharePhoto' => $sharePhoto, 'shareTitle' => $shareTitle, 'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'jsondata' => json_encode($setJsonData, JSON_UNESCAPED_UNICODE)];
$setShareImg && $addData['shareImg'] = $setShareImg;
$addData['introduction'] = $introduction ?: '';
$topicId = $this->mSytopic->add($addData);
if (!$topicId) {
$this->return_json('添加专题失败');
}
$this->return_response();
}
/**
* 修改活动
*/
public function index_put()
{
$id = $this->input_param('id');
$title = $this->input_param('title');
$dateRange = $this->input_param('dateRange');
$shareTitle = $this->input_param('shareTitle');
$shareImg = $this->input_param('shareImg');
$sharePhoto = $this->input_param('sharePhoto');
$organizationId = intval($this->input_param('organizationId'));
$banner = $this->input_param('banner');
$introduction = $this->input_param('introduction');
$jsonData = $this->input_param('json');
if (!$title) {
$this->return_json('请输入活动标题');
}
if (!$banner[0]['fileUrl']) {
$this->return_json('请选择banner图');
}
if (!$dateRange) {
$this->return_json('请选择活动时间');
}
$sharePhoto = $sharePhoto ? $sharePhoto[0]['fileUrl'] : '';
$banner = $banner ? $banner[0]['fileUrl'] : '';
$shareTitle = $shareTitle ? json_encode($shareTitle, JSON_UNESCAPED_UNICODE) : '';
$setShareImg = '';
if ($shareImg) {
foreach ($shareImg as $v) {
$setShareImg[] = $v['fileUrl'];
}
$setShareImg = json_encode($setShareImg, JSON_UNESCAPED_UNICODE);
}
$setJsonData = [];
if ($jsonData['banner']) {
$setJsonData['banner'] = $jsonData['banner'] ? $jsonData['banner'][0]['fileUrl'] : '';
} else {
$setJsonData['banner'] = '';
}
$setJsonData['bg_color'] = $jsonData['bg_color'] ?: '';
$addData = ['title' => $title, 'banner' => $banner, 'status' => 1, 'organizationId' => $organizationId, 'sharePhoto' => $sharePhoto,
'shareTitle' => $shareTitle, 'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'jsondata' => json_encode($setJsonData, JSON_UNESCAPED_UNICODE)];
$setShareImg && $addData['shareImg'] = $setShareImg;
$addData['introduction'] = $introduction ?: '';
$topicId = $this->mSytopic->update($addData, ['id' => $id]);
if (!$topicId) {
$this->return_json('修改专题失败');
}
$this->return_response();
}
/**
* 修改状态
*/
public function status_put()
{
$id = $this->input_param('id');
$status = $this->input_param('status');
if (!$id) {
$this->return_json('参数错误');
}
$this->mSytopic->update(['status' => $status], ['id' => $id]);
$this->return_response();
}
/**
* 删除活动
*/
public function index_delete()
{
$ids = $this->input_param('ids');
if (!$ids) {
$this->return_json('参数错误');
}
$str_ids = is_array($ids) ? implode(',', $ids) : $ids;
if ($str_ids) {
$this->mSytopic->update(['status' => -1], ["id in($str_ids)" => null]);
}
$this->return_response();
}
}