349 lines
14 KiB
PHP
349 lines
14 KiB
PHP
<?php
|
|
/**
|
|
* SaaSMall商城系统 - 团队十年电商经验汇集巨献!
|
|
* =========================================================
|
|
* Copy right 2019-2029 成都SAAS云科技有限公司, 保留所有权利。
|
|
* ----------------------------------------------
|
|
* 官方网址: https://www.gobuysaas.com
|
|
* =========================================================
|
|
*/
|
|
|
|
namespace addon\topic\shop\controller;
|
|
|
|
use addon\aliapp\model\OpenPay;
|
|
use addon\form\model\Form;
|
|
use addon\postertemplate\model\PosterTemplate as PosterTemplateModel;
|
|
use app\model\system\Site;
|
|
use app\model\upload\Upload as UploadModel;
|
|
use app\shop\controller\BaseShop;
|
|
use addon\topic\model\Topic as TopicModel;
|
|
use addon\dividemoney\model\DividemoneyAccount;
|
|
|
|
/**
|
|
* 专题活动
|
|
* @author Administrator
|
|
*
|
|
*/
|
|
class Topic extends BaseShop
|
|
{
|
|
/**
|
|
* 专题活动列表
|
|
*/
|
|
public function lists()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$page = input('page', 1);
|
|
$page_size = input('page_size', PAGE_LIST_ROWS);
|
|
$topic_name = input('topic_name', '');
|
|
|
|
$condition[] = ['site_id', '=', $this->site_id];
|
|
if ($topic_name) {
|
|
$condition[] = ['topic_name', 'like', '%' . $topic_name . '%'];
|
|
}
|
|
$status = input('status', '');
|
|
if ($status !== '') {
|
|
$condition[] = ['status', '=', $status];
|
|
}
|
|
$order = 'create_time desc';
|
|
$field = '*';
|
|
|
|
$start_time = input('start_time', '');
|
|
$end_time = input('end_time', '');
|
|
|
|
if ($start_time && !$end_time) {
|
|
$condition[] = ['end_time', '>=', date_to_time($start_time)];
|
|
} elseif (!$start_time && $end_time) {
|
|
$condition[] = ['start_time', '<=', date_to_time($end_time)];
|
|
} elseif ($start_time && $end_time) {
|
|
$start_timestamp = date_to_time($start_time);
|
|
$end_timestamp = date_to_time($end_time);
|
|
$sql = "start_time between {$start_timestamp} and {$end_timestamp}";
|
|
$sql .= " or end_time between {$start_timestamp} and {$end_timestamp}";
|
|
$sql .= " or (start_time <= {$start_timestamp} and end_time >= {$end_timestamp})";
|
|
$condition[] = ['', 'exp', \think\facade\Db::raw($sql)];
|
|
}
|
|
|
|
$topic_model = new TopicModel();
|
|
$res = $topic_model->getTopicPageList($condition, $page, $page_size, $order, $field);
|
|
return $res;
|
|
} else {
|
|
$site_id = $this->site_id;
|
|
$site_agent_id = model('site')->getValue([['site_id' , '=' , $site_id]],'agent_id');
|
|
$this->assign('site_agent_id', $site_agent_id);
|
|
return $this->fetch("topic/lists");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 添加专题活动
|
|
*/
|
|
public function add()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$topic_name = input("topic_name", '');
|
|
$start_time = input("start_time", 0);
|
|
$end_time = input("end_time", 0);
|
|
$remark = input("remark", '');
|
|
$topic_adv = input("topic_adv", '');
|
|
$form_id = input("form_id", 0);
|
|
$template_id = input("template_id", 0);
|
|
$is_activity_pay = input("is_activity_pay", '');
|
|
$payee_name = input("payee_name", '');
|
|
$payee_account = input("payee_account", '');
|
|
$bg_color = input("bg_color", '#ffffff');
|
|
$goods = input("goods", '{}');
|
|
$music_url = input("music_url", '');
|
|
$content = input("content", '');
|
|
$topic_model = new TopicModel();
|
|
$data = array(
|
|
'site_id' => $this->site_id,
|
|
"topic_name" => $topic_name,
|
|
"sup_site_id" => input("site_id", 0),
|
|
"form_id" => $form_id,
|
|
"music_url" => $music_url,
|
|
"content" => $content,
|
|
"template_id" => $template_id,
|
|
"is_activity_pay" => $is_activity_pay,
|
|
"payee_name" => $payee_name,
|
|
"payee_account" => $payee_account,
|
|
"start_time" => $start_time,
|
|
"end_time" => $end_time,
|
|
"remark" => $remark,
|
|
"topic_adv" => $topic_adv,
|
|
'divide_money_ids' => json_encode(input('divide_money_ids', '')),
|
|
'bg_color' => $bg_color,
|
|
'goods' => json_decode($goods, true),
|
|
'create_time' => time()
|
|
);
|
|
$res = $topic_model->addTopic($data);
|
|
return $res;
|
|
} else {
|
|
//获取海报
|
|
$poster_template_model = new PosterTemplateModel();
|
|
$poster_list = $poster_template_model->getPosterTemplateList([['site_id', '=', $this->site_id], ['template_status', '=', 1]], 'template_id,poster_name,site_id');
|
|
$this->assign('poster_list', $poster_list['data']);
|
|
$form_is_exit = addon_is_exit('form', $this->site_id);
|
|
if ($form_is_exit) {
|
|
$form_list = (new Form())->getFormList(
|
|
[
|
|
['site_id', '=', $this->site_id],
|
|
['form_type', '=', 'custom'],
|
|
['is_use', '=', 1]
|
|
], 'id desc', 'id, form_name')['data'];
|
|
$this->assign('form_list', $form_list);
|
|
}
|
|
$this->assign('form_is_exit', $form_is_exit);
|
|
$divide_money_is_exit = addon_is_exit('dividemoney', $this->site_id);
|
|
$this->assign('divide_money_is_exit', $divide_money_is_exit);
|
|
return $this->fetch("topic/add");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 编辑专题活动
|
|
*/
|
|
public function edit()
|
|
{
|
|
$topic_id = input("topic_id", '');
|
|
$topic_model = new TopicModel();
|
|
if (request()->isAjax()) {
|
|
$topic_name = input("topic_name", '');
|
|
$start_time = input("start_time", 0);
|
|
$end_time = input("end_time", 0);
|
|
$remark = input("remark", '');
|
|
$topic_adv = input("topic_adv", '');
|
|
$bg_color = input("bg_color", '#ffffff');
|
|
$goods = input("goods", '{}');
|
|
$del_id = input('del_id', '');
|
|
$form_id = input("form_id", 0);
|
|
$template_id = input("template_id", 0);
|
|
$is_activity_pay = input("is_activity_pay", '');
|
|
$payee_name = input("payee_name", '');
|
|
$payee_account = input("payee_account", '');
|
|
$music_url = input("music_url", '');
|
|
$content = input("content", '');
|
|
$data = array(
|
|
'topic_id' => $topic_id,
|
|
'site_id' => $this->site_id,
|
|
"sup_site_id" => input("site_id", 0),
|
|
"topic_name" => $topic_name,
|
|
"form_id" => $form_id,
|
|
"music_url" => $music_url,
|
|
"content" => $content,
|
|
"template_id" => $template_id,
|
|
"is_activity_pay" => $is_activity_pay,
|
|
"payee_name" => $payee_name,
|
|
"payee_account" => $payee_account,
|
|
"start_time" => $start_time,
|
|
"end_time" => $end_time,
|
|
"remark" => $remark,
|
|
"topic_adv" => $topic_adv,
|
|
'divide_money_ids' => json_encode(input('divide_money_ids', '')),
|
|
'bg_color' => $bg_color,
|
|
'goods' => json_decode($goods, true),
|
|
'modify_time' => time()
|
|
);
|
|
$res = $topic_model->editTopic($data, $this->site_id, $del_id);
|
|
return $res;
|
|
} else {
|
|
//获取海报
|
|
$poster_template_model = new PosterTemplateModel();
|
|
$poster_list = $poster_template_model->getPosterTemplateList([['site_id', '=', $this->site_id], ['template_status', '=', 1]], 'template_id,poster_name,site_id');
|
|
$this->assign('poster_list', $poster_list['data']);
|
|
|
|
$form_is_exit = addon_is_exit('form', $this->site_id);
|
|
if ($form_is_exit) {
|
|
$form_list = (new Form())->getFormList(
|
|
[['site_id', '=', $this->site_id],
|
|
['form_type', '=', 'custom'],
|
|
['is_use', '=', 1]
|
|
], 'id desc', 'id, form_name')['data'];
|
|
$this->assign('form_list', $form_list);
|
|
} else {
|
|
$this->assign('form_list', []);
|
|
}
|
|
$this->assign('form_is_exit', $form_is_exit);
|
|
|
|
$divide_money_is_exit = addon_is_exit('dividemoney', $this->site_id);
|
|
$this->assign('divide_money_is_exit', $divide_money_is_exit);
|
|
$condition = array(
|
|
["topic_id", "=", $topic_id]
|
|
);
|
|
$topic_info_result = $topic_model->getTopicDetail($condition);
|
|
$info = $topic_info_result['data'];
|
|
$divide_money_ids = $info['divide_money_ids'];
|
|
$divide_list = [];
|
|
$divide_ids = '';
|
|
if ($divide_money_ids && $divide_money_is_exit) {
|
|
$divide_list = (new DividemoneyAccount())->getDivideList([['site_id', '=', $this->site_id], ['id', 'in', json_decode($divide_money_ids)]], 'id,account,realname,divide_rate');
|
|
$divide_ids = implode(',', array_column($divide_list, 'id'));
|
|
}
|
|
if ($info['sup_site_id']) {
|
|
$site_model = new Site();
|
|
$site_info = $site_model->getSiteInfo([['site_id', '=', $info['sup_site_id']]], 'username,site_id');
|
|
$this->assign('siteInfo', $site_info['data']);
|
|
}
|
|
$this->assign('divide_list', $divide_list);
|
|
$this->assign('divide_ids', $divide_ids);
|
|
if (empty($topic_info_result['data'])) $this->error('未获取到活动数据', addon_url('topic://shop/topic/lists'));
|
|
$this->assign("info", $topic_info_result["data"]);
|
|
$this->assign('sku_ids', implode(',', array_column($topic_info_result['data']['goods_list'], 'sku_id')));
|
|
return $this->fetch("topic/edit");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 查看专题活动
|
|
*/
|
|
public function detail()
|
|
{
|
|
$topic_id = input("topic_id", '');
|
|
$topic_model = new TopicModel();
|
|
|
|
$condition = array(
|
|
["topic_id", "=", $topic_id]
|
|
);
|
|
$topic_info_result = $topic_model->getTopicDetail($condition);
|
|
if (empty($topic_info_result['data'])) $this->error('未获取到活动数据', addon_url('topic://shop/topic/lists'));
|
|
$this->assign("info", $topic_info_result["data"]);
|
|
$this->assign('sku_ids', implode(',', array_column($topic_info_result['data']['goods_list'], 'sku_id')));
|
|
return $this->fetch("topic/detail");
|
|
}
|
|
|
|
/**
|
|
* 删除专题活动
|
|
*/
|
|
public function delete()
|
|
{
|
|
$topic_id = input("topic_id", '');
|
|
$topic_model = new TopicModel();
|
|
$res = $topic_model->deleteTopic($topic_id, $this->site_id);
|
|
return $res;
|
|
}
|
|
|
|
|
|
/***
|
|
* 获取推广二维码
|
|
* @return null
|
|
*/
|
|
public function getQrurl()
|
|
{
|
|
$topic_id = input("topic_id", '');
|
|
$topic_model = new TopicModel();
|
|
$qr = $topic_model->getQrcode($this->site_id, $topic_id);
|
|
return $qr;
|
|
}
|
|
|
|
|
|
public function SiteLists()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$page = input('page', 1);
|
|
$page_size = input('page_size', PAGE_LIST_ROWS);
|
|
$search_text = input('search_text', '');
|
|
$condition = [];
|
|
if ($this->site_id != 1) {
|
|
$condition[] = ['agent_id', '=', $this->shop_info['agent_id']];
|
|
}
|
|
if ($search_text) {
|
|
$condition[] = ['site_name|username|contacts_name|contacts_mobile|remarks', 'like', '%' . $search_text . '%'];
|
|
}
|
|
$order = 'site_id desc';
|
|
$field = '*';
|
|
$shop_model = new \app\model\system\Site();
|
|
$shopInfo = $shop_model->getSitePageList($condition, $page, $page_size, $order, $field);
|
|
return $shopInfo;
|
|
}
|
|
}
|
|
|
|
public function TopicLists(){
|
|
if (request()->isAjax()) {
|
|
$page = input('page', 1);
|
|
$page_size = input('page_size', PAGE_LIST_ROWS);
|
|
$search_text = input('search_text', '');
|
|
$condition = [];
|
|
$site_id = $this->site_id;
|
|
$site_agent_id = model('site')->getValue([['site_id' , '=' , $site_id]],'agent_id');
|
|
if ($site_agent_id > 0) {
|
|
$condition[] = ['site_id', '=', $site_agent_id];
|
|
}
|
|
if ($search_text) {
|
|
$condition[] = ['topic_name', 'like', '%' . $search_text . '%'];
|
|
}
|
|
$order = 'topic_id desc';
|
|
$field = '*';
|
|
$topic_model = new TopicModel();
|
|
$list = $topic_model->getTopicPageList($condition, $page, $page_size, $order, $field);
|
|
return $list;
|
|
}
|
|
}
|
|
|
|
public function copyTopic(){
|
|
if (request()->isAjax()) {
|
|
$id = input('copy_id', 0);
|
|
$topic_model = new TopicModel();
|
|
$site_id = $this->site_id;
|
|
$site_agent_id = model('site')->getValue([['site_id' , '=' , $site_id]],'agent_id');
|
|
|
|
return $topic_model->copyTopic($id, $site_id, $site_agent_id);
|
|
}
|
|
}
|
|
|
|
/***
|
|
* 上传图片
|
|
* @return array|bool|mixed|\multitype|string
|
|
*/
|
|
public function video()
|
|
{
|
|
$upload_model = new UploadModel($this->site_id, $this->app_module);
|
|
$param = array(
|
|
'thumb_type' => '',
|
|
'name' => 'file',
|
|
'cloud' => 0,
|
|
);
|
|
$path = 'common/video/' . date('Ymd') . '/';
|
|
$result = $upload_model->setPath($path)->video($param);
|
|
return $result;
|
|
}
|
|
}
|