253 lines
8.2 KiB
PHP
253 lines
8.2 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
require_once APPPATH . 'controllers/api/BaseController.php';
|
|
|
|
class Module extends BaseController
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('market/Market_sytopic_model', 'mSytopic');
|
|
$this->load->model('market/Market_sytopic_module_model', 'mSModule');
|
|
$this->load->model('market/Market_sytopic_module_option_model', 'mSModuleOption');
|
|
}
|
|
|
|
/**
|
|
* 专题模块列表
|
|
* @return void
|
|
*/
|
|
public function page_get()
|
|
{
|
|
$topicId = intval($this->input_param('topicId'));
|
|
$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 = 'sort desc,type asc';
|
|
if ($sort && $order) {
|
|
$sort_order = $sort . ' ' . $order;
|
|
}
|
|
$list = [];
|
|
$where = [
|
|
'topicId' => $topicId,
|
|
'status>=' => 0
|
|
];
|
|
$title && $where['title LIKE "%' . trim($title) . '%"'] = null;
|
|
$count = $this->mSModule->count($where);
|
|
if ($count) {
|
|
$res = $this->mSModule->select($where, $sort_order, $page, $limit);
|
|
$mSModule = new Market_sytopic_module_model();
|
|
foreach ($res as $v) {
|
|
$v['options'] = $this->mSModuleOption->count(['moduleId' => $v['id'], 'status' => 0]);
|
|
$v['type_cn'] = $mSModule::TYPE_ARRAY[$v['type']] ?: '';
|
|
$v['type'] = intval($v['type']);
|
|
$list[] = $v;
|
|
}
|
|
}
|
|
$data = ['list' => $list, 'count' => $count];
|
|
$this->return_response_list($data);
|
|
}
|
|
|
|
/**
|
|
* 添加专题模块
|
|
*/
|
|
public function index_post()
|
|
{
|
|
$topicId = intval($this->input_param('topicId'));
|
|
$title = $this->input_param('title');
|
|
$type = $this->input_param('type');
|
|
$sort = intval($this->input_param('sort'));
|
|
if (!$topicId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
if (!$title) {
|
|
$this->return_json('请输入活动标题');
|
|
}
|
|
if (!$type) {
|
|
$this->return_json('请选择类型');
|
|
}
|
|
$createTime = date('Y-m-d H:i:s');
|
|
$addData = ['title' => $title, 'topicId' => $topicId, 'createTime' => $createTime, 'type' => $type, 'sort' => $sort ?: 0];
|
|
$topicId = $this->mSModule->add($addData);
|
|
if (!$topicId) {
|
|
$this->return_json('添加专题模块失败');
|
|
}
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* 修改活动
|
|
*/
|
|
public function index_put()
|
|
{
|
|
$id = $this->input_param('id');
|
|
$title = $this->input_param('title');
|
|
$sort = intval($this->input_param('sort'));
|
|
if (!$title) {
|
|
$this->return_json('请输入活动标题');
|
|
}
|
|
$addData = ['title' => $title, 'sort' => $sort];
|
|
$topicId = $this->mSModule->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->mSModule->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->mSModule->update(['status' => -1], ["id in($str_ids)" => null]);
|
|
}
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* 类型列表
|
|
* @return void
|
|
*/
|
|
public function types_get()
|
|
{
|
|
$mSModule = new Market_sytopic_module_model();
|
|
$list = [];
|
|
if ($mSModule::TYPE_ARRAY) {
|
|
foreach ($mSModule::TYPE_ARRAY as $key => $item) {
|
|
$list[] = [
|
|
'key' => $key,
|
|
'value' => $item
|
|
];
|
|
}
|
|
}
|
|
$data = ['list' => $list];
|
|
$this->return_response_list($data);
|
|
}
|
|
|
|
/**
|
|
* 获取模块配置项
|
|
* @return void
|
|
*/
|
|
public function options_get()
|
|
{
|
|
$moduleId = $this->input_param('moduleId');
|
|
$moduleRow = $this->mSModule->get(['id' => $moduleId]);
|
|
if (!$moduleRow) $this->return_json('参数错误');
|
|
$where = [
|
|
'moduleId' => $moduleId,
|
|
'status' => 0
|
|
];
|
|
$rows = $this->mSModuleOption->select($where, 'id desc', 1, 1000);
|
|
$lists = [];
|
|
if ($rows) {
|
|
foreach ($rows as $item) {
|
|
$lists[] = $this->form_data($moduleRow, $item);
|
|
}
|
|
}
|
|
$data['lists'] = $lists;
|
|
$this->return_response_list($data);
|
|
}
|
|
|
|
/**
|
|
* 保存模块配置项
|
|
* @return void
|
|
*/
|
|
public function options_post()
|
|
{
|
|
$postData = $this->input_param('');
|
|
$modelRow = $this->mSModule->get(['id' => $postData['moduleId']]);
|
|
if (!$modelRow) $this->return_json('参数错误');
|
|
if (!$postData['title']) $this->return_json('请输入标题');
|
|
$banner = $postData['banner'] ? $postData['banner'][0]['fileUrl'] : '';
|
|
$setOtherImg = '';
|
|
if ($postData['otherImg']) {
|
|
foreach ($postData['otherImg'] as $v) {
|
|
$setOtherImg[] = $v['fileUrl'];
|
|
}
|
|
$setOtherImg = json_encode($setOtherImg, JSON_UNESCAPED_UNICODE);
|
|
}
|
|
$data = [
|
|
'title' => $postData['title'],
|
|
'banner' => $banner,
|
|
'subTitle' => $postData['subTitle'] ?: '',
|
|
'introduction' => $postData['introduction'] ?: '',
|
|
'showBtn' => $postData['showBtn'] ? 1 : 0,
|
|
'btnText' => $postData['btnText'] ?: '',
|
|
'popUpType' => $postData['popUpType'] ? 1 : 0,
|
|
'targetUrl' => $postData['targetUrl'] ?: '',
|
|
'otherImg' => $setOtherImg,
|
|
'enrollLimit' => $postData['enrollLimit'] ?: 0,
|
|
'enrollEndTime' => $postData['enrollEndTime'] ?: '0000-00-00 00:00:00'
|
|
];
|
|
if ($postData['id']) {
|
|
$result = $this->mSModuleOption->update($data, ['id' => $postData['id']]);
|
|
} else {
|
|
$data['topicId'] = $modelRow['topicId'];
|
|
$data['moduleId'] = $modelRow['id'];
|
|
$data['createTime'] = date('Y-m-d H:i:s', time());
|
|
$result = $this->mSModuleOption->add($data);
|
|
}
|
|
if (!$result) {
|
|
$this->return_json('操作失败');
|
|
}
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* 修改状态
|
|
*/
|
|
public function options_delete()
|
|
{
|
|
$id = $this->input_param('id');
|
|
if (!$id) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$this->mSModuleOption->update(['status' => -1], ['id' => $id]);
|
|
$this->return_response();
|
|
}
|
|
|
|
private function form_data($moduleType, $row)
|
|
{
|
|
$otherImg = $jsondata = $banner = [];
|
|
if ($row['banner']) {
|
|
$banner = [['uid' => 1, 'fileUrl' => $row['banner'], 'url' => build_qiniu_image_url($row['banner']), 'status' => 'done']];
|
|
}
|
|
if ($row['otherImg']) {
|
|
$getOtherImg = json_decode($row['otherImg'], true);
|
|
foreach ($getOtherImg as $key => $val) {
|
|
$otherImg[] = ['uid' => $key, 'fileUrl' => $val, 'url' => build_qiniu_image_url($val), 'status' => 'done'];
|
|
}
|
|
}
|
|
$row['otherImg'] = $otherImg;
|
|
if ($jsondata) {
|
|
$jsondata = json_decode($row['jsondata'], true);
|
|
}
|
|
$row['jsondata'] = $jsondata;
|
|
$row['banner'] = $banner;
|
|
$row['enrollEndTime'] = $row['enrollEndTime'] != '0000-00-00 00:00:00' ? $row['enrollEndTime'] : '';
|
|
return $row;
|
|
}
|
|
} |