423 lines
18 KiB
PHP
423 lines
18 KiB
PHP
<?php
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Notes:素材模板
|
|
* Created on: 2021/9/30 12:45
|
|
* Created by: dengbw
|
|
*/
|
|
class Template extends HD_Controller
|
|
{
|
|
private $cf_id = 24;//素材报名
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('app/material/Material_template_model', 'mdTemplate');
|
|
$this->load->model('app/material/Material_biz_model', 'mdMaterialBiz');
|
|
$this->load->model('app/material/Material_biz_statistics_model', 'mdBizStatistics');
|
|
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
|
|
$this->load->model('auto/auto_brand_model', 'mdAutoBrand');
|
|
$this->load->model("biz/biz_model", 'mdBiz');
|
|
}
|
|
|
|
//首页信息
|
|
public function index()
|
|
{
|
|
$this->lists();
|
|
}
|
|
|
|
//数据列表
|
|
public function lists()
|
|
{
|
|
$params = $this->input->get();
|
|
$params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$params['size'] = $params['size'] ? intval($params['size']) : 20;
|
|
$lists = $users = array();
|
|
$where = array('app_id' => $params['app_id']);
|
|
if ($params['type']) {
|
|
$where['type'] = $params['type'];
|
|
}
|
|
if (strlen($params['status'])) {
|
|
$where['status'] = $params['status'];
|
|
}
|
|
$count = $this->mdTemplate->count($where);
|
|
if ($count) {
|
|
$fileds = "id,title,type,status,brand_ids,c_time";
|
|
$res = $this->mdTemplate->select($where, "id desc", $params['page'], $params['size'], $fileds);
|
|
foreach ($res as $key => $value) {
|
|
$setValue = array();
|
|
$setValue['id'] = $value['id'];
|
|
$setValue['title'] = $value['title'];
|
|
$setValue['type_name'] = $this->mdTemplate->typeAry()[$value['type']];
|
|
$setValue['status_name'] = $this->mdTemplate->statusAry()[$value['status']];
|
|
$setValue['status'] = $value['status'];
|
|
$brands = '';
|
|
if ($value['brand_ids']) {
|
|
$res_b = $this->mdAutoBrand->select(array("id in ({$value['brand_ids']})" => null, 'status' => 1), "id desc", 0, 0, 'name');
|
|
if ($res_b) {
|
|
$brands = array_column($res_b, 'name');
|
|
$brands = implode(',', $brands);
|
|
}
|
|
}
|
|
$setValue['brands'] = $brands;
|
|
$setValue['c_time'] = date('Y-m-d H:i:s', $value["c_time"]);
|
|
$lists[] = $setValue;
|
|
}
|
|
}
|
|
$this->data['lists'] = $lists;
|
|
$this->data['params'] = $params;
|
|
$this->data['typeAry'] = $this->mdTemplate->typeAry();
|
|
$this->data['statusAry'] = $this->mdTemplate->statusAry();
|
|
$this->data['_title'] = '素材模板列表';
|
|
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
|
|
return $this->show_view('/app/material/template/lists', true);
|
|
}
|
|
|
|
public function lists_biz()
|
|
{
|
|
$params = $this->input->get();
|
|
$params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$params['size'] = $params['size'] ? intval($params['size']) : 20;
|
|
$lists = $users = array();
|
|
$where = array('app_id' => $params['app_id']);
|
|
if ($params['biz_name']) {
|
|
$where['biz_id in (select id from lc_biz where biz_name like "%' . $params['biz_name'] . '%")'] = null;
|
|
}
|
|
$count = $this->mdMaterialBiz->count($where, 'distinct(biz_id)');
|
|
if ($count) {
|
|
$fileds = "distinct(biz_id)";
|
|
$res = $this->mdMaterialBiz->select($where, "biz_id desc", $params['page'], $params['size'], $fileds);
|
|
$str_ids = implode(',', array_unique(array_column($res, 'biz_id')));
|
|
$map_biz = $this->mdBiz->map('id', 'biz_name', array("id in({$str_ids})" => null));
|
|
foreach ($res as $key => $value) {
|
|
$setValue = array();
|
|
$biz_id = intval($value['biz_id']);
|
|
$re_s = $this->mdBizStatistics->sum('browse_num', array('app_id' => $params['app_id'], 'biz_id' => $biz_id));
|
|
$count_c = $this->mdCustomers->count(array('biz_id' => $biz_id, 'cf_id' => $this->cf_id, 'status >=' => 0));
|
|
$count_o = $this->mdBizStatistics->count_order(array('c.biz_id' => $biz_id, 'c.cf_id' => $this->cf_id, 'c.status >=' => 0));
|
|
$setValue['browse_num'] = intval($re_s['browse_num']);
|
|
$setValue['baoming_num'] = $count_c;
|
|
$setValue['order_name'] = $count_o;
|
|
$setValue['biz_id'] = $biz_id;
|
|
$setValue['biz_name'] = $map_biz[$value['biz_id']];
|
|
$lists[] = $setValue;
|
|
}
|
|
}
|
|
$this->data['lists'] = $lists;
|
|
$this->data['params'] = $params;
|
|
$this->data['_title'] = '门店使用数据列表';
|
|
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
|
|
return $this->show_view('/app/material/template/lists_biz', true);
|
|
}
|
|
|
|
public function lists_t_biz()
|
|
{
|
|
$params = $this->input->get();
|
|
$t_id = intval($params['t_id']);
|
|
if (!$t_id) {
|
|
return $this->show_json(SYS_CODE_FAIL, '参数错误');
|
|
}
|
|
$re = $this->mdTemplate->get(array('id' => $t_id));
|
|
$params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$params['size'] = $params['size'] ? intval($params['size']) : 20;
|
|
$lists = $users = array();
|
|
$where = array('app_id' => $params['app_id'], 't_id' => $t_id);
|
|
if ($params['biz_name']) {
|
|
$where['biz_id in (select id from lc_biz where biz_name like "%' . $params['biz_name'] . '%")'] = null;
|
|
}
|
|
$count = $this->mdMaterialBiz->count($where);
|
|
if ($count) {
|
|
$fileds = "biz_id,c_time";
|
|
$res = $this->mdMaterialBiz->select($where, "id desc", $params['page'], $params['size'], $fileds);
|
|
$str_ids = implode(',', array_unique(array_column($res, 'biz_id')));
|
|
$map_biz = $this->mdBiz->map('id', 'biz_name', array("id in({$str_ids})" => null));
|
|
foreach ($res as $key => $value) {
|
|
$setValue = array();
|
|
$biz_id = intval($value['biz_id']);
|
|
$re_s = $this->mdBizStatistics->sum('browse_num', array('app_id' => $params['app_id'], 'biz_id' => $biz_id, 't_id' => $t_id));
|
|
$count_c = $this->mdCustomers->count(array('biz_id' => $biz_id, 'cf_id' => $this->cf_id, 'status >=' => 0, 't_id' => $t_id));
|
|
$count_o = $this->mdBizStatistics->count_order(array('c.biz_id' => $biz_id, 'c.cf_id' => $this->cf_id, 'c.status >=' => 0, 'c.t_id' => $t_id));
|
|
$setValue['browse_num'] = intval($re_s['browse_num']);
|
|
$setValue['baoming_num'] = $count_c;
|
|
$setValue['order_name'] = $count_o;
|
|
$setValue['biz_id'] = $biz_id;
|
|
$setValue['biz_name'] = $map_biz[$value['biz_id']];
|
|
$setValue['c_time'] = date('Y-m-d H:i:s', $value['c_time']);
|
|
$lists[] = $setValue;
|
|
}
|
|
}
|
|
$this->data['lists'] = $lists;
|
|
$this->data['params'] = $params;
|
|
$this->data['_title'] = $re['title'] . '_门店使用数据列表';
|
|
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
|
|
return $this->show_view('/app/material/template/lists_t_biz', true);
|
|
}
|
|
|
|
//展示单条数据
|
|
public function get()
|
|
{
|
|
$id = $this->input->get('id');
|
|
$info['app_id'] = intval($this->input->get('app_id'));
|
|
$info['status'] = 1;
|
|
$info['type'] = 4;
|
|
$info['cover'] = array('value' => '', 'src' => '');
|
|
$info['moments'] = '';
|
|
$info['tag_id'] = '';
|
|
$info['biz_pop'] = 0;
|
|
$json_lists = $json_item = $brands = $pyqwa_list = array();
|
|
foreach ($this->mdTemplate->typeAry() as $key => $value) {
|
|
$json_lists[$key] = array();
|
|
$json_item[$key] = array();
|
|
}
|
|
if ($id) {
|
|
$re = $this->mdTemplate->get(array('id' => $id));
|
|
if (!$re || empty($re)) {
|
|
return $this->show_json(SYS_CODE_FAIL, '模板不存在!');
|
|
}
|
|
$moments = $tag_id = '';
|
|
$biz_pop = 0;
|
|
if ($re['json_data']) {
|
|
$json_data = json_decode($re['json_data'], true);
|
|
$json_data['biz_pop'] && $biz_pop = $json_data['biz_pop'];
|
|
$json_data['moments'] && $moments = $json_data['moments'];
|
|
$json_data['tag_id'] && $tag_id = $json_data['tag_id'];
|
|
$lists = array();
|
|
foreach ($json_data['lists'] as $key => $value) {
|
|
if ($re['type'] == 1) {
|
|
if ($value['video_type'] == 1) {
|
|
$value['video_file_url'] = $value['video'];
|
|
$value['video_url'] = build_qiniu_image_url($value['video'], 0, 0, 'video');
|
|
$value['video_cover'] = $value['video_url'] . '?vframe/jpg/offset/1';
|
|
$value['img'] = $value['img_url'] = '';
|
|
} else {
|
|
$value['img_url'] = $value['img'] ? build_qiniu_image_url($value['img']) : '';
|
|
$value['video_file_url'] = $value['video_url'] = $value['video_cover'] = $value['width'] = $value['height'] = '';
|
|
}
|
|
} else if ($re['type'] == 2 || $re['type'] == 4) {
|
|
$value['img_url'] = $value['img'] ? build_qiniu_image_url($value['img']) : '';
|
|
} else if ($re['type'] == 3) {
|
|
if ($value['brands']) {
|
|
$value['brands'] = $this->mdAutoBrand->select(array("id in ({$value['brands']})" => null, 'status' => 1), "id desc", 0, 0, 'id,name');
|
|
} else {
|
|
$value['brands'] = array();
|
|
}
|
|
}
|
|
$lists[] = $value;
|
|
}
|
|
if ($re['type'] == 1) {
|
|
$json_lists[1] = $lists;
|
|
} else if ($re['type'] == 2) {
|
|
$json_lists[2] = $lists;
|
|
} else if ($re['type'] == 3) {
|
|
$pyqwa_list = $lists;
|
|
} else if ($re['type'] == 4) {
|
|
$json_lists[4] = $lists;
|
|
}
|
|
unset($re['json_data']);
|
|
}
|
|
$info = $re;
|
|
$info['biz_pop'] = $biz_pop;
|
|
$info['moments'] = $moments;
|
|
$info['tag_id'] = $tag_id;
|
|
$info['cover'] = $info['cover'] ? array('value' => $info['cover'], 'src' => build_qiniu_image_url($info['cover']))
|
|
: array('value' => '', 'src' => '');
|
|
if ($info['brand_ids']) {
|
|
$brand_ids = str_replace(",0", "", $info['brand_ids']);
|
|
$brand_ids = str_replace("0,", "", $brand_ids);
|
|
$brands = $this->mdAutoBrand->select(array("id in ({$brand_ids})" => null, 'status' => 1), "id desc", 0, 0, 'id,name');
|
|
}
|
|
$_title = '编辑素材模板';
|
|
$edit_url = '/app/material/template/edit';
|
|
} else {
|
|
$_title = '新增素材模板';
|
|
$edit_url = '/app/material/template/add';
|
|
}
|
|
$showInfo['statusAry'] = $this->mdTemplate->statusAry();
|
|
$showInfo['typeAry'] = $this->mdTemplate->typeAry();
|
|
$showInfo['tagAry'] = $this->mdTemplate->tagAry();
|
|
$showInfo['bizPopAry'] = [0 => '否', 1 => '是'];
|
|
$showInfo['brands'] = $brands;
|
|
$showInfo['pyqwa_list'] = $pyqwa_list;
|
|
$showInfo['json_lists'] = $json_lists;
|
|
$showInfo['json_item'] = $json_item;
|
|
$this->data['info'] = $info;
|
|
$this->data['showInfo'] = $showInfo;
|
|
$this->data['edit_url'] = $edit_url;
|
|
$this->data['_title'] = $_title;
|
|
return $this->show_view('/app/material/template/edit', true);
|
|
}
|
|
|
|
private function checkInfo($info)
|
|
{
|
|
$msg = '';
|
|
$code = SYS_CODE_FAIL;
|
|
if (!$info) {
|
|
$msg = '非法参数';
|
|
} else if (!$info['title']) {
|
|
$msg = '请输入模版名称';
|
|
} else if (!$info['cover']['value'] && $info['type'] != 3) {
|
|
$msg = '请上传封面图';
|
|
} else if (!$info['brand_ids'] && $info['type'] != 3) {
|
|
$msg = '请选择适用品牌';
|
|
} else {
|
|
$code = SYS_CODE_SUCCESS;
|
|
}
|
|
return array('code' => $code, 'msg' => $msg);
|
|
}
|
|
|
|
//添加单条数据
|
|
public function add()
|
|
{
|
|
$info = $this->input->post('info');
|
|
$checkInfo = $this->checkInfo($info);
|
|
if (!$checkInfo['code']) {
|
|
return $this->show_json($checkInfo['code'], $checkInfo['msg']);
|
|
}
|
|
$brand_ids = '';
|
|
if ($info['brand_ids']) {
|
|
$brand_ids = '0,' . implode(',', $info['brand_ids']) . ',0';
|
|
}
|
|
$json_data['biz_pop'] = $info['biz_pop'];
|
|
$json_data['moments'] = $info['moments'];
|
|
$json_data['tag_id'] = $info['tag_id'];
|
|
if ($info['lists']) {
|
|
$lists = array();
|
|
foreach ($info['lists'] as $key => $value) {
|
|
if ($info['type'] == 1) {
|
|
if ($value['video_type'] == 1) {
|
|
$value['video'] = $value['video_file_url'];
|
|
unset($value['img']);
|
|
} else {
|
|
unset($value['width']);
|
|
unset($value['height']);
|
|
}
|
|
unset($value['video_file_url']);
|
|
unset($value['video_url']);
|
|
unset($value['video_cover']);
|
|
unset($value['img_url']);
|
|
} else if ($info['type'] == 2 || $info['type'] == 4) {
|
|
unset($value['img_url']);
|
|
} else if ($info['type'] == 3) {
|
|
$brands = '';
|
|
if ($value['brands']) {
|
|
$brands = array_column($value['brands'], 'id');
|
|
$brands = implode(',', $brands);
|
|
}
|
|
$value['brands'] = $brands;
|
|
}
|
|
$lists[] = $value;
|
|
}
|
|
$json_data['lists'] = $lists;
|
|
}
|
|
$editData['json_data'] = json_encode($json_data, JSON_UNESCAPED_UNICODE);
|
|
$editData['app_id'] = $info['app_id'];
|
|
$editData['title'] = $info['title'];
|
|
$editData['cover'] = $info['cover']['value'];
|
|
$editData['type'] = $info['type'];
|
|
$editData['brand_ids'] = $info['type'] == 3 ? '' : $brand_ids;
|
|
$editData['status'] = $info['status'];
|
|
$editData['c_time'] = time();
|
|
$id = $this->mdTemplate->add($editData);
|
|
if (!$id) {
|
|
return $this->show_json(SYS_CODE_FAIL, '新增失败!');
|
|
}
|
|
return $this->show_json(SYS_CODE_SUCCESS, '新增成功!', '/app/material/template/index?app_id=' . $info['app_id']);
|
|
}
|
|
|
|
//编辑单条数据
|
|
public function edit()
|
|
{
|
|
$info = $this->input->post('info');
|
|
$checkInfo = $this->checkInfo($info);
|
|
if (!$checkInfo['code']) {
|
|
return $this->show_json($checkInfo['code'], $checkInfo['msg']);
|
|
}
|
|
$brand_ids = '';
|
|
if ($info['brand_ids']) {
|
|
$brand_ids = '0,' . implode(',', $info['brand_ids']) . ',0';
|
|
}
|
|
$json_data['biz_pop'] = $info['biz_pop'];
|
|
$json_data['moments'] = $info['moments'];
|
|
$json_data['tag_id'] = $info['tag_id'];
|
|
if ($info['lists']) {
|
|
$lists = array();
|
|
foreach ($info['lists'] as $key => $value) {
|
|
if ($info['type'] == 1) {
|
|
if ($value['video_type'] == 1) {
|
|
$value['video'] = $value['video_file_url'];
|
|
unset($value['img']);
|
|
} else {
|
|
unset($value['width']);
|
|
unset($value['height']);
|
|
}
|
|
unset($value['video_file_url']);
|
|
unset($value['video_url']);
|
|
unset($value['video_cover']);
|
|
unset($value['img_url']);
|
|
} else if ($info['type'] == 2 || $info['type'] == 4) {
|
|
unset($value['img_url']);
|
|
} else if ($info['type'] == 3) {
|
|
$brands = '';
|
|
if ($value['brands']) {
|
|
$brands = array_column($value['brands'], 'id');
|
|
$brands = implode(',', $brands);
|
|
}
|
|
$value['brands'] = $brands;
|
|
}
|
|
$lists[] = $value;
|
|
}
|
|
$json_data['lists'] = $lists;
|
|
}
|
|
$editData['json_data'] = json_encode($json_data, JSON_UNESCAPED_UNICODE);
|
|
$editData['title'] = $info['title'];
|
|
$editData['cover'] = $info['cover']['value'];
|
|
$editData['type'] = $info['type'];
|
|
$editData['brand_ids'] = $info['type'] == 3 ? '' : $brand_ids;
|
|
$editData['status'] = $info['status'];
|
|
$ret = $this->mdTemplate->update($editData, array('id' => $info['id']));
|
|
if (!$ret) {
|
|
return $this->show_json(SYS_CODE_FAIL, '修改失败!');
|
|
}
|
|
return $this->show_json(SYS_CODE_SUCCESS, '修改成功!');
|
|
}
|
|
|
|
//删除单条数据
|
|
public function del()
|
|
{
|
|
|
|
}
|
|
|
|
//批量操作(默认修改状态)
|
|
public function batch()
|
|
{
|
|
$field = $this->input->post('field');
|
|
if ($field === 'ifcheck') {
|
|
$status = intval($this->input->post('value'));
|
|
$ids = $this->input->post('id');
|
|
$ids = explode(',', $ids);
|
|
if (!$ids || count($ids) < 1) {
|
|
$this->show_json(0, '请选择要操作的选项');
|
|
}
|
|
$ids_str = implode(',', $ids);
|
|
$where = ["id in({$ids_str})" => null];
|
|
} else {
|
|
$id = intval($this->input->post('id'));
|
|
$status = intval($this->input->post('value'));
|
|
if (!$id) {
|
|
$this->show_json(0, '参数错误');
|
|
}
|
|
$where['id'] = $id;
|
|
}
|
|
$data['status'] = $status;
|
|
$this->mdTemplate->update($data, $where);
|
|
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
|
|
}
|
|
|
|
//导出数据列表
|
|
public function export()
|
|
{
|
|
|
|
}
|
|
} |