Files
liche/market/controllers/api/sylive/Activity.php
T
xiaoyu ae2aa550c6 fixed
2023-07-09 18:35:15 +08:00

826 lines
37 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
/**
* Notes:私域直播_活动管理
* Created on: 2022/9/19 17:15
* Created by: dengbw
*/
class Activity extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('market/Market_sylive_activity_model', 'mdSyliveActivity');
$this->load->model('market/Market_sylive_activity_biz_model', 'mdSyliveActivityBiz');
$this->load->model('market/Market_sylive_activity_draw_model', 'mdSyliveActivityDraw');
$this->load->model('market/Market_sylive_organization_model', 'mdSyliveOrganization');
$this->load->model('market/Market_sylive_team_model', 'mdSyliveTeam');
$this->load->model('market/Market_sylive_activity_team_model', 'mdSyliveActivityTeam');
$this->load->model('market/Market_sylive_groups_model', 'mdSyliveGroups');
$this->load->model('market/Market_sylive_groups_user_model', 'mdSyliveGroupsUser');
$this->load->model('market/Market_sylive_customer_model', 'mdSyliveCustomer');
}
/**
* Notes:活动管理列表
* Created on: 2022/9/20 14:48
* Created by: dengbw
*/
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 = 'activityId 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->mdSyliveActivity->count($where);
if ($count) {
$this->load->library('MyEncryption');
$res = $this->mdSyliveActivity->select($where, $sort_order, $page, $limit);
foreach ($res as $v) {
$dateRange = $v['timeStart'] != '0000-00-00 00:00:00' ? [$v['timeStart'], $v['timeEnd']] : '';
$status = intval($v['status']);
$activityId = intval($v['activityId']);
$bgImg = $channelImg = $banner = $sharePhoto = $shareImg = $shareTitle = $pay = $bottoms = [];
$item = ['itemImg' => [], 'title' => '', 'introduction' => '', 'price' => '', 'stock' => '', 'dateRange' => ''];
$coupon = ['img' => [], 'title' => '', 'rules' => '', 'price' => '', 'dateRange' => ''];
$draw = ['bgImg' => [], 'sms' => '', 'screenDisplay' => 1, 'winNum' => [], 'winType' => []];
$pay = ['way' => 1, 'price' => '', 'img' => []];
$signBespeak = ['status' => 0, 'title' => '', 'content' => '', 'itemId' => ''];
$barrage = ['color' => 0, 'title' => ''];
$button = ['title' => ''];
$v['shareTitle'] && $shareTitle = json_decode($v['shareTitle'], true);
$jsondata = $v['jsondata'] ? json_decode($v['jsondata'], true) : [];
if ($jsondata['item']) {
$getItem = $jsondata['item'];
$item['stock'] = $v['stock'];
$item['title'] = $getItem['title'];
$item['introduction'] = $getItem['introduction'];
$item['price'] = $getItem['price'];
$item['dateRange'] = $getItem['timeStart'] ? [$getItem['timeStart'], $getItem['timeEnd']] : [];
$item['dateUseRange'] = $getItem['useTimeStart'] ? [$getItem['useTimeStart'], $getItem['useTimeEnd']] : [];
if ($getItem['itemImg']) {
$itemImg = [];
foreach ($getItem['itemImg'] as $k2 => $v2) {
$itemImg[] = ['uid' => $k2, 'fileUrl' => $v2, 'url' => build_qiniu_image_url($v2), 'status' => 'done'];
}
$item['itemImg'] = $itemImg;
}
}
if ($jsondata['coupon']) {
$getCoupon = $jsondata['coupon'];
$coupon['title'] = $getCoupon['title'];
$coupon['rules'] = $getCoupon['rules'];
$coupon['price'] = $getCoupon['price'];
$coupon['dateUseRange'] = $getCoupon['useTimeStart'] ? [$getCoupon['useTimeStart'], $getCoupon['useTimeEnd']] : [];
if ($getCoupon['img']) {
$itemImg = [];
foreach ($getCoupon['img'] as $k2 => $v2) {
$itemImg[] = ['uid' => $k2, 'fileUrl' => $v2, 'url' => build_qiniu_image_url($v2), 'status' => 'done'];
}
$coupon['img'] = $itemImg;
}
}
if (intval($jsondata['pay']['way']) > 1) {
$pay = $jsondata['pay'];
if ($pay['img']) {
$img[] = ['uid' => 1, 'fileUrl' => $pay['img'], 'url' => build_qiniu_image_url($pay['img']), 'status' => 'done'];
$pay['img'] = $img;
} else {
$pay['img'] = [];
}
}
if ($jsondata['banner']) {
$banner = [['uid' => 1, 'fileUrl' => $jsondata['banner'], 'url' => build_qiniu_image_url($jsondata['banner']), 'status' => 'done']];
}
if ($v['bgImg']) {
$bgImg = [['uid' => 1, 'fileUrl' => $v['bgImg'], 'url' => build_qiniu_image_url($v['bgImg']), 'status' => 'done']];
}
if ($v['channelImg']) {
$channelImg = [['uid' => 1, 'fileUrl' => $v['channelImg'], 'url' => build_qiniu_image_url($v['channelImg']), '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['bottoms']) {
foreach ($jsondata['bottoms'] as $k2 => $v2) {
$icon = [];
if ($v2['icon']) {
$icon[] = ['uid' => $k2, 'fileUrl' => $v2['icon'], 'url' => build_qiniu_image_url($v2['icon']), 'status' => 'done'];
}
$v2['icon'] = $icon;
$bottoms[] = $v2;
}
}
$skey = $this->myencryption->base64url_encode("a_id=" . $activityId);
if ($activityId >= 6) {
$url = http_host_com('home') . "/h5/market/sylive2?skey=" . $skey;//活动连接
} else {
$url = http_host_com('home') . "/h5/market/sylive?skey=" . $skey;//活动连接
}
$serviceLink = $jsondata['serviceLink'] ? $jsondata['serviceLink'] : '';
$activityStart = $v['activityStart'] != '0000-00-00 00:00:00' ? $v['activityStart'] : '';
$organizationId = $v['organizationId'] ? intval($v['organizationId']) : '';
$groups = 0;
$re_gro = $this->mdSyliveGroups->get(['activityId' => $activityId, 'parentId' => 0, 'status>=' => 0]);
$re_gro && $groups = 1;
$blacklist = intval($jsondata['blacklist']);
$jsondata['signBespeak'] && $signBespeak = $jsondata['signBespeak'];
$jsondata['barrage'] && $barrage = $jsondata['barrage'];
$jsondata['button'] && $button = $jsondata['button'];
//抽奖配置
$re_draw = $this->mdSyliveActivityDraw->get(['activityId' => $activityId]);
if ($re_draw) {
$draw['screenDisplay'] = intval($re_draw['screenDisplay']);
if ($re_draw['bgImg']) {
$draw['bgImg'] = [['uid' => 1, 'fileUrl' => $re_draw['bgImg'], 'url' => build_qiniu_image_url($re_draw['bgImg']), 'status' => 'done']];
}
$re_draw['sms'] && $draw['sms'] = $re_draw['sms'];
$re_draw['winNum'] && $draw['winNum'] = json_decode($re_draw['winNum'], true);
if ($re_draw['winType']) {
$winType = [];
$json_winType = json_decode($re_draw['winType'], true);
foreach ($json_winType as $v2) {
$v2['img'] = $v2['img'] ?
[['uid' => 1, 'fileUrl' => $v2['img'], 'url' => build_qiniu_image_url($v2['img']), 'status' => 'done']] : [];
$winType[] = $v2;
}
$draw['winType'] = $winType;
}
}
//访问标签
$visitTag = [];
$visitTagAry = $this->mdSyliveCustomer->visitTagAry();
foreach ($visitTagAry as $k2 => $v2) {
$tag = $jsondata['visitTag'][$k2] ? $jsondata['visitTag'][$k2] : '';
$visitTag[] = ['id' => $k2, 'title' => $v2, 'tag' => $tag];
}
$list[] = [
'activityId' => $activityId, 'title' => $v['title'], 'channelId' => $v['channelId'], 'pay' => $pay, 'organizationId' => $organizationId,
'activityStart' => $activityStart, 'shareTitle' => $shareTitle, 'dateRange' => $dateRange, 'coupon' => $coupon, 'drawCode' => $v['drawCode'],
'bgImg' => $bgImg, 'channelImg' => $channelImg, 'banner' => $banner, 'sharePhoto' => $sharePhoto, 'shareImg' => $shareImg, 'item' => $item, 'url' => $url,
'mchId' => $v['mchId'], 'protocolTitle' => $v['protocolTitle'], 'protocol' => $v['protocol'], 'serviceLink' => $serviceLink,
'bottoms' => $bottoms, 'draw' => $draw, 'visitTag' => $visitTag, 'blacklist' => $blacklist,
'signBespeak' => $signBespeak, 'barrage' => $barrage, 'button' => $button,
's_time' => $v['timeStart'], 'e_time' => $v['timeEnd'], 'status' => $status, 'groups' => $groups, 'createTime' => $v['createTime']];
}
}
$date = ['list' => $list, 'count' => $count];
$this->return_response_list($date);
}
/**
* Notes:添加活动
* Created on: 2022/9/21 16:46
* Created by: dengbw
*/
public function index_post()
{
$title = $this->input_param('title');
$channelId = $this->input_param('channelId');
$dateRange = $this->input_param('dateRange');
$shareTitle = $this->input_param('shareTitle');
$shareImg = $this->input_param('shareImg');
$bgImg = $this->input_param('bgImg');
$channelImg = $this->input_param('channelImg');
$sharePhoto = $this->input_param('sharePhoto');
$organizationId = intval($this->input_param('organizationId'));
$pay = $this->input_param('pay');
$drawCode = $this->input_param('drawCode');
$banner = $this->input_param('banner');
$mchId = $this->input_param('mchId');
$protocolTitle = $this->input_param('protocolTitle');
$protocol = $this->input_param('protocol');
$serviceLink = $this->input_param('serviceLink');
$activityStart = $this->input_param('activityStart');
$bottoms = $this->input_param('bottoms');
$signBespeak = $this->input_param('signBespeak');
if (!$title) {
$this->return_json('请输入活动标题');
}
if (!$bgImg[0]['fileUrl']) {
$this->return_json('请选择背景图');
}
if (!$channelId) {
$this->return_json('请输入直播频道');
}
if (!$dateRange) {
$this->return_json('请选择直播时间');
}
if ($drawCode) {
$re = $this->mdSyliveActivity->get(['drawCode' => $drawCode, 'status' => 0], 'drawCode');
if ($re['drawCode']) {
$this->return_json('抽奖码已存在');
}
}
$bgImg = $bgImg[0]['fileUrl'];
$sharePhoto = $sharePhoto ? $sharePhoto[0]['fileUrl'] : '';
$channelImg = $channelImg ? $channelImg[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);
}
if ($pay['way'] > 1) {
$pay['img'] = $pay['img'][0]['fileUrl'] ? $pay['img'][0]['fileUrl'] : '';
} else {
$pay = ['way' => 1, 'price' => '', 'img' => []];
}
$jsondata['pay'] = $pay;
$jsondata['banner'] = $banner;
$jsondata['serviceLink'] = $serviceLink;
$setBottoms = [];
foreach ($bottoms as $v) {
if ($v['urlType'] == 'link') {
$v['miniProgramId'] = '';
}
$v['icon'] = $v['icon'][0]['fileUrl'] ? $v['icon'][0]['fileUrl'] : '';
$setBottoms[] = $v;
}
$jsondata['bottoms'] = $setBottoms;
$jsondata['blacklist'] = intval($this->input_param('blacklist'));
!$signBespeak['status'] && $signBespeak = ['status' => 0, 'title' => '', 'content' => '', 'itemId' => ''];
$jsondata['signBespeak'] = $signBespeak;
$jsondata['barrage'] = $this->input_param('barrage');
$jsondata['button'] = $this->input_param('button');
$jsondata = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
$createTime = date('Y-m-d H:i:s');
$addData = ['title' => $title, 'bgImg' => $bgImg, 'channelImg' => $channelImg, 'channelId' => $channelId, 'jsondata' => $jsondata
, 'shareTitle' => $shareTitle, 'sharePhoto' => $sharePhoto, 'shareImg' => $setShareImg, 'organizationId' => $organizationId
, 'drawCode' => $drawCode, 'mchId' => $mchId, 'protocolTitle' => $protocolTitle, 'protocol' => $protocol, 'activityStart' => $activityStart
, 'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'status' => 1, 'createTime' => $createTime];
$activityId = $this->mdSyliveActivity->add($addData);
if (!$activityId) {
$this->return_json('添加活动失败');
}
if ($organizationId) {
$re = $this->mdSyliveOrganization->get(['organizationId' => $organizationId, 'status' => 0]);
if ($re['organizationName']) {//加顶级分组
$this->mdSyliveGroups->add(['groupsName' => $re['organizationName'], 'activityId' => $activityId,
'statisticsType' => 4, 'createTime' => $createTime]);
}
}
$this->return_response();
}
/**
* Notes:修改活动
* Created on: 2022/9/21 14:48
* Created by: dengbw
*/
public function index_put()
{
$activityId = intval($this->input_param('activityId'));
$title = $this->input_param('title');
$channelId = $this->input_param('channelId');
$dateRange = $this->input_param('dateRange');
$shareTitle = $this->input_param('shareTitle');
$shareImg = $this->input_param('shareImg');
$bgImg = $this->input_param('bgImg');
$channelImg = $this->input_param('channelImg');
$sharePhoto = $this->input_param('sharePhoto');
$pay = $this->input_param('pay');
$drawCode = $this->input_param('drawCode');
$banner = $this->input_param('banner');
$mchId = $this->input_param('mchId');
$protocolTitle = $this->input_param('protocolTitle');
$protocol = $this->input_param('protocol');
$serviceLink = $this->input_param('serviceLink');
$organizationId = intval($this->input_param('organizationId'));
$activityStart = $this->input_param('activityStart');
$bottoms = $this->input_param('bottoms');
$signBespeak = $this->input_param('signBespeak');
if (!$activityId) {
$this->return_json('参数错误');
}
if (!$title) {
$this->return_json('请输入活动标题');
}
if (!$bgImg[0]['fileUrl']) {
$this->return_json('请选择背景图');
}
if (!$channelId) {
$this->return_json('请输入直播频道');
}
if (!$dateRange) {
$this->return_json('请选择直播时间');
}
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
if (!$re) {
$this->return_json('活动不存在');
}
if ($drawCode) {
if ($drawCode != $re['drawCode']) {
$re = $this->mdSyliveActivity->get(['drawCode' => $drawCode, 'status' => 0], 'drawCode');
if ($re['drawCode']) {
$this->return_json('抽奖码已存在');
}
}
}
$bgImg = $bgImg[0]['fileUrl'];
$sharePhoto = $sharePhoto ? $sharePhoto[0]['fileUrl'] : '';
$channelImg = $channelImg ? $channelImg[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);
}
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
if ($pay['way'] > 1) {
$pay['img'] = $pay['img'][0]['fileUrl'] ? $pay['img'][0]['fileUrl'] : '';
} else {
$pay = ['way' => 1, 'price' => '', 'img' => []];
}
$jsondata['pay'] = $pay;
$jsondata['banner'] = $banner;
$jsondata['serviceLink'] = $serviceLink;
$jsondata['blacklist'] = intval($this->input_param('blacklist'));
!$signBespeak['status'] && $signBespeak = ['status' => 0, 'title' => '', 'content' => '', 'itemId' => ''];
$jsondata['signBespeak'] = $signBespeak;
$jsondata['barrage'] = $this->input_param('barrage');
$jsondata['button'] = $this->input_param('button');
$setBottoms = [];
foreach ($bottoms as $v) {
if ($v['urlType'] == 'link') {
$v['miniProgramId'] = '';
}
$v['icon'] = $v['icon'][0]['fileUrl'] ? $v['icon'][0]['fileUrl'] : '';
$setBottoms[] = $v;
}
$jsondata['bottoms'] = $setBottoms;
$jsondata = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
$upData = ['title' => $title, 'bgImg' => $bgImg, 'channelImg' => $channelImg, 'channelId' => $channelId, 'activityStart' => $activityStart,
'shareTitle' => $shareTitle, 'sharePhoto' => $sharePhoto, 'shareImg' => $setShareImg, 'jsondata' => $jsondata,
'drawCode' => $drawCode, 'mchId' => $mchId, 'protocolTitle' => $protocolTitle, 'protocol' => $protocol,
'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'organizationId' => $organizationId];
$this->mdSyliveActivity->update($upData, ['activityId' => $activityId]);
$this->return_response();
}
/**
* Notes:复制活动
* Created on: 2022/12/8 10:08
* Created by: dengbw
* @param null $activityId
*/
public function copy_get($activityId = null)
{
$activityIdOld = intval($activityId);
if (!$activityIdOld) {
$this->return_json('参数错误');
}
$re = $this->mdSyliveActivity->get(['activityId' => $activityIdOld]);
if (!$re) {
$this->return_json('活动不存在');
}
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
$jsondata['banner'] = '';
$createTime = date('Y-m-d H:i:s');
$addData = ['title' => '【复制】' . $re['title'], 'organizationId' => $re['organizationId'], 'mchId' => $re['mchId']
, 'protocolTitle' => $re['protocolTitle'], 'protocol' => $re['protocol']
, 'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE), 'status' => 1, 'createTime' => $createTime];
$activityId = $this->mdSyliveActivity->add($addData);
if (!$activityId) {
$this->return_json('复制活动失败');
}
$groupsIds = [];
if ($re['organizationId']) {//分组所属机构
//分级分组
$groupsLevel = [['groupsLevel' => 0, 'parentId' => 'parentId=0', 'title' => '顶级']
, ['groupsLevel' => 1, 'parentId' => 'parentId>0', 'title' => '1级']
, ['groupsLevel' => 2, 'parentId' => 'parentId>0', 'title' => '2级']
, ['groupsLevel' => 3, 'parentId' => 'parentId>0', 'title' => '3级']
, ['groupsLevel' => 0, 'parentId' => 'parentId>0', 'title' => '门店']];
$fileds = 'groupsId,parentId,groupsLevel,sortNumber,userFrom,groupsName,ifBiz,statisticsType,originalBizId';
foreach ($groupsLevel as $v1) {
$res = $this->mdSyliveGroups->select(['groupsLevel' => $v1['groupsLevel'], $v1['parentId'] => null
, 'status>=' => 0, 'activityId' => $activityIdOld], 'groupsId asc', 0, 0, $fileds);
foreach ($res as $v2) {
$parentId = intval($groupsIds[$v2['parentId']]);
$groupsData = ['activityId' => $activityId, 'parentId' => $parentId, 'originalBizId' => $v2['originalBizId']
, 'groupsName' => $v2['groupsName'], 'groupsLevel' => $v2['groupsLevel'], 'statisticsType' => $v2['statisticsType']
, 'userFrom' => $v2['userFrom'], 'ifBiz' => $v2['ifBiz'], 'sortNumber' => $v2['sortNumber'], 'createTime' => $createTime];
$groupsId = $this->mdSyliveGroups->add($groupsData);
$groupsId && $groupsIds[$v2['groupsId']] = $groupsId;
}
}
//分组用户
$fileds = 'userId,groupsId,bizId,levelId1,levelId2,levelId3,type,userFrom,status';
$res = $this->mdSyliveGroupsUser->select(['status>=' => 0, 'activityId' => $activityIdOld], 'groupsUserId asc', 0, 0, $fileds);
$userData = [];
foreach ($res as $v) {
$groupsId = intval($groupsIds[$v['groupsId']]);
$bizId = intval($groupsIds[$v['bizId']]);
$levelId1 = intval($groupsIds[$v['levelId1']]);
$levelId2 = intval($groupsIds[$v['levelId2']]);
$levelId3 = intval($groupsIds[$v['levelId3']]);
$userData[] = [
'activityId' => $activityId, 'userId' => $v['userId'], 'groupsId' => $groupsId, 'bizId' => $bizId, 'levelId1' => $levelId1,
'levelId1' => $levelId1, 'levelId2' => $levelId2, 'levelId3' => $levelId3,
'type' => $v['type'], 'userFrom' => $v['userFrom'], 'status' => $v['status'], 'createTime' => $createTime];
}
$userData && $this->mdSyliveGroupsUser->add_batch($userData);
}
$this->return_response($groupsIds);
}
/**
* Notes:活动信息
* Created on: 2023/3/02 10:37
* Created by: dengbw
*/
public function info_get()
{
$activityId = $this->input_param('activityId');
$type = $this->input_param('type');
if (!$activityId) {
$this->return_json('参数错误');
}
$select = 'activityId,title,channelId';
if ($type == 'customer') {
$select = 'title,jsondata';
}
$re = $this->mdSyliveActivity->get(['activityId' => $activityId], $select);
if (!$re) {
$this->return_json('活动不存在');
}
$info = [];
if ($type == 'customer') {
$info['title'] = $re['title'];
$statusAry = $visitTagAry = [];
$getStatusAry = $this->mdSyliveCustomer->statusAry();
foreach ($getStatusAry as $k => $v) {
$statusAry[] = ['value' => $k, 'label' => $v];
}
$jsonData = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
$getVisitTagAry = $this->mdSyliveCustomer->visitTagAry();
foreach ($getVisitTagAry as $k => $v) {
$label = $v;
if ($jsonData['visitTag'][$k]) {
$label = $label . '(' . $jsonData['visitTag'][$k] . ')';
}
$visitTagAry[] = ['value' => $k, 'label' => $label];
}
$info['statusAry'] = $statusAry;
$info['visitTagAry'] = $visitTagAry;
} else {
$info = $re;
}
$this->return_response($info);
}
/**
* Notes:活动详情
* Created on: 2022/9/29 10:37
* Created by: dengbw
* @param null $activityId
*/
public function index_get($activityId = null)
{
if (!$activityId) {
$this->return_json('参数错误');
}
$re = $this->mdSyliveActivity->get(['activityId' => $activityId], 'activityId,title,channelId');
if (!$re) {
$this->return_json('活动不存在');
}
$this->return_response($re);
}
/**
* Notes:删除活动
* Created on: 2022/9/21 16:10
* Created by: dengbw
* @param null $activityId
*/
public function index_delete($activityId = null)
{
if (!$activityId) {
$this->return_json('参数错误');
}
$this->mdSyliveActivity->update(['status' => -1], ['activityId' => $activityId]);
$this->return_response();
}
/**
* Notes:批量删除用户
* Created on: 2022/9/8 17:11
* Created by: dengbw
*/
public function batch_delete()
{
$ids = $this->input_param('ids');
if (!$ids) {
$this->return_json('参数错误');
}
$str_ids = implode(',', $ids);
if ($str_ids) {
$this->mdSyliveActivity->update(['status' => -1], ["activityId in($str_ids)" => null]);
}
$this->return_response();
}
/**
* Notes:修改状态
* Created on: 2022/9/8 16:10
* Created by: dengbw
*/
public function status_put()
{
$activityId = $this->input_param('activityId');
$status = $this->input_param('status');
if (!$activityId) {
$this->return_json('参数错误');
}
$this->mdSyliveActivity->update(['status' => $status], ['activityId' => $activityId]);
$this->return_response();
}
/**
* Notes:修改商品
* Created on: 2022/9/28 15:09
* Created by: dengbw
*/
public function item_put()
{
$activityId = intval($this->input_param('activityId'));
$title = $this->input_param('title');
$price = $this->input_param('price');
$stock = intval($this->input_param('stock'));
$itemImg = $this->input_param('itemImg');
$dateRange = $this->input_param('dateRange');
$dateUseRange = $this->input_param('dateUseRange');
$introduction = $this->input_param('introduction');
if (!$activityId) {
$this->return_json('参数错误');
}
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
if (!$re) {
$this->return_json('活动不存在');
}
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
$timeStart = $dateRange[0] ? $dateRange[0] : '';
$timeEnd = $dateRange[1] ? $dateRange[1] : '';
$useTimeStart = $dateUseRange[0] ? $dateUseRange[0] : '';
$useTimeEnd = $dateUseRange[1] ? $dateUseRange[1] : '';
$item = ['title' => $title, 'price' => $price, 'timeStart' => $timeStart, 'timeEnd' => $timeEnd
, 'useTimeStart' => $useTimeStart, 'useTimeEnd' => $useTimeEnd, 'introduction' => $introduction];
if ($itemImg) {
$setItemImg = [];
foreach ($itemImg as $v) {
$setItemImg[] = $v['fileUrl'];
}
$item['itemImg'] = $setItemImg;
}
$jsondata['item'] = $item;
$upDate = ['stock' => $stock, 'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)];
$this->mdSyliveActivity->update($upDate, ['activityId' => $activityId]);
$this->return_response();
}
/**
* Notes:修改券
* Created on: 2022/10/21 15:09
* Created by: dengbw
*/
public function coupon_put()
{
$activityId = intval($this->input_param('activityId'));
$title = $this->input_param('title');
$price = $this->input_param('price');
$img = $this->input_param('img');
$dateUseRange = $this->input_param('dateUseRange');
$rules = $this->input_param('rules');
if (!$activityId) {
$this->return_json('参数错误');
}
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
if (!$re) {
$this->return_json('活动不存在');
}
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
$useTimeStart = $dateUseRange[0] ? $dateUseRange[0] : '';
$useTimeEnd = $dateUseRange[1] ? $dateUseRange[1] : '';
$coupon = ['title' => $title, 'price' => $price, 'rules' => $rules,
'useTimeStart' => $useTimeStart, 'useTimeEnd' => $useTimeEnd];
if ($img) {
$setImg = [];
foreach ($img as $v) {
$setImg[] = $v['fileUrl'];
}
$coupon['img'] = $setImg;
}
$jsondata['coupon'] = $coupon;
$upDate = ['jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)];
$this->mdSyliveActivity->update($upDate, ['activityId' => $activityId]);
$this->return_response();
}
/**
* Notes:修改回访标签
* Created on: 2023/2/27 10:08
* Created by: dengbw
*/
public function visit_tag_put()
{
$activityId = intval($this->input_param('activityId'));
if (!$activityId) {
$this->return_json('参数错误');
}
$visitTag = $this->input_param('visitTag');
$re = $this->mdSyliveActivity->get(['activityId' => $activityId], 'jsondata');
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
$setVisitTag = [];
if ($visitTag) {
foreach ($visitTag as $v) {
$v['tag'] && $setVisitTag[$v['id']] = $v['tag'];
}
}
$jsondata['visitTag'] = $setVisitTag ? $setVisitTag : [];
$upDate['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
$ret = $this->mdSyliveActivity->update($upDate, ['activityId' => $activityId]);
if (!$ret) {
$this->return_json('修改回访标签失败');
}
$this->return_response();
}
/**
* Notes:修改抽奖配置
* Created on: 2023/1/30 10:08
* Created by: dengbw
*/
public function draw_put()
{
$activityId = intval($this->input_param('activityId'));
if (!$activityId) {
$this->return_json('参数错误');
}
$bgImg = $this->input_param('bgImg');
$sms = $this->input_param('sms');
$screenDisplay = $this->input_param('screenDisplay');
$winNum = $this->input_param('winNum');
$winType = $this->input_param('winType');
$re = $this->mdSyliveActivityDraw->get(['activityId' => $activityId]);
$upDate['bgImg'] = $bgImg ? $bgImg[0]['fileUrl'] : '';
$upDate['sms'] = $sms;
$upDate['screenDisplay'] = $screenDisplay;
$setWinNum = $setWinType = [];
if ($winNum) {
foreach ($winNum as $v) {
$setWinNum[] = ['title' => $v['value'] . '人', 'value' => $v['value']];
}
}
if ($winType) {
foreach ($winType as $v) {
$v['img'] = $v['img'] ? $v['img'][0]['fileUrl'] : '';
$setWinType[] = $v;
}
}
$upDate['winNum'] = $setWinNum ? json_encode($setWinNum, JSON_UNESCAPED_UNICODE) : null;
$upDate['winType'] = $setWinType ? json_encode($setWinType, JSON_UNESCAPED_UNICODE) : null;
if (!$re) {
$upDate['activityId'] = $activityId;
$upDate['createTime'] = date('Y-m-d H:i:s');
$ret = $this->mdSyliveActivityDraw->add($upDate);
} else {
$ret = $this->mdSyliveActivityDraw->update($upDate, ['activityId' => $activityId]);
}
if (!$ret) {
$this->return_json('抽奖配置失败');
}
$this->return_response();
}
/**
* Notes:修改黑名单
* Created on: 2023/3/03 10:08
* Created by: dengbw
*/
public function blacklist_put()
{
$activityId = intval($this->input_param('activityId'));
if (!$activityId) {
$this->return_json('参数错误');
}
$blacklist = $this->input_param('blacklist');
$addDate = [];
$delId = '';
foreach ($blacklist as $v) {
if ($v['type'] == 'add' && $v['mobile']) {
$re = $this->mdSyliveBlacklist->get(['activityId' => $activityId, 'mobile' => $v['mobile']]);
if (!$re) {
$addDate[] = ['mobile' => $v['mobile'], 'activityId' => $activityId, 'createTime' => date('Y-m-d H:i:s')];
}
} else if ($v['type'] == 'del' && $v['id']) {
$delId = $delId ? $delId . ',' . $v['id'] : $v['id'];
}
}
if (count($addDate)) {
$this->mdSyliveBlacklist->add_batch($addDate);
}
if ($delId) {
$this->mdSyliveBlacklist->delete(["blacklistId in({$delId})" => null]);
}
$this->return_response();
}
/**
* Notes:导入黑名单
* Created on: 2023/3/06 17:24
* Created by: dengbw
* @throws PHPExcel_Exception
* @throws PHPExcel_Reader_Exception
*/
public function blacklist_import_post()
{
require_once COMMPATH . '/third_party/PHPExcel/IOFactory.php';
$res = $this->upload();
if (!$res['code']) {
return $this->return_json($res['message']);
}
$file = $res['path'];
if ($res['file_ext'] == '.xls') {
$reader = \PHPExcel_IOFactory::createReader('Excel5'); // 读取 excel 文档
} elseif ($res['file_ext'] == '.xlsx') {
$reader = \PHPExcel_IOFactory::createReader('Excel2007'); // 读取 excel 文档
} else {
return $this->return_json('文件无法识别');
}
$PHPExcel = $reader->load($file); // 文档名称
$objWorksheet = $PHPExcel->getActiveSheet();
$rowCnt = $objWorksheet->getHighestRow(); //获取总行数
if ($rowCnt > 800) {
@unlink($file);
$this->return_json('数据大于800请拆分多个表格导入');
}
$activityId = $_POST['activityId'];
$addDate = [];
for ($_row = 2; $_row <= $rowCnt; $_row++) { //读取内容
$mobile = $objWorksheet->getCell('A' . $_row)->getValue();
if ($mobile) {
$re = $this->mdSyliveBlacklist->get(['activityId' => $activityId, 'mobile' => $mobile]);
if (!$re) {
$addDate[] = ['mobile' => $mobile, 'activityId' => $activityId, 'createTime' => date('Y-m-d H:i:s')];
}
}
}
$count = count($addDate);
if ($count) {
$this->mdSyliveBlacklist->add_batch($addDate);
}
@unlink($file);
$this->return_response('', "成功新增{$count}个黑名单");
}
private function upload()
{
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . '/temp/';
$config['allowed_types'] = '*';
$config['max_size'] = 5120;
$config['file_name'] = 'blacklist_' . time() . rand(1, 99999);
$this->load->library('upload', $config);
if (!$this->upload->do_upload('file')) {
return ['code' => SYS_CODE_FAIL, 'message' => $this->upload->display_errors('', '')];
} else {
$data = $this->upload->data();
return ['code' => SYS_CODE_SUCCESS, 'path' => $data['full_path'], 'file_ext' => $data['file_ext']];
}
}
}