203 lines
7.2 KiB
PHP
203 lines
7.2 KiB
PHP
<?php
|
|
defined('WXAPP_ITEMS') OR exit('No direct script access allowed');
|
|
ini_set('display_errors', 'On');
|
|
error_reporting(E_ERROR);
|
|
|
|
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
|
|
|
|
/**
|
|
* Notes:推广素材
|
|
* Created on: 2021/10/9 15:16
|
|
* Created by: dengbw
|
|
*/
|
|
class Home extends Wxapp
|
|
{
|
|
private $biz_id = 0;
|
|
|
|
function __construct($inputs, $app_key)
|
|
{
|
|
parent::__construct($inputs, $app_key);
|
|
$this->login_white = '';//
|
|
$this->check_status = array();//用户状态校验
|
|
$this->check_mobile = array();//需要手机号
|
|
$this->check_headimg = array();//授权微信信息
|
|
$this->majia_white = array('get');//超级管理员披上马甲可操作权限
|
|
$this->load->model('app/material/Material_template_model', 'mdTemplate');
|
|
$this->load->model('app/material/Material_biz_model', 'mdMaterialBiz');
|
|
$this->load->model("biz/biz_model", 'mdBiz');
|
|
$this->biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
|
|
$this->app_id == 1 && $this->app_id = 2;//获取狸车宝数据
|
|
}
|
|
|
|
/**
|
|
* Notes:推广素材_tab
|
|
* Created on: 2021/10/13 11:42
|
|
* Created by: dengbw
|
|
* @return array
|
|
*/
|
|
protected function get_tabs()
|
|
{
|
|
$list = array();
|
|
foreach ($this->mdTemplate->typeAry() as $key => $value) {
|
|
$list[] = array('id' => $key, 'name' => $value);
|
|
}
|
|
$this->data['title'] = '推广素材';
|
|
$this->data['list'] = $list;
|
|
return $list;
|
|
}
|
|
|
|
/**
|
|
* Notes:推广素材_list
|
|
* Created on: 2021/10/11 11:47
|
|
* Created by: dengbw
|
|
* @return array
|
|
* @throws Exception
|
|
*/
|
|
protected function get_lists()
|
|
{
|
|
$page = $this->input_param('page');
|
|
$size = $this->input_param('size');
|
|
$type = intval($this->input_param('type'));
|
|
!$page && $page = 1;
|
|
!$size && $size = 10;
|
|
!$type && $type = 1;
|
|
$brand_ids = array();
|
|
if ($this->biz_id) {//查找门店授权品牌
|
|
$re_b = $this->mdBiz->get(array('id' => $this->biz_id, 'status' => 1));
|
|
if ($re_b['jsondata']) {
|
|
$jsondata = json_decode($re_b['jsondata'], true);
|
|
$jsondata['auto_brands'] && $brand_ids = $jsondata['auto_brands'];
|
|
}
|
|
}
|
|
$lists = array();
|
|
$total = 0;
|
|
$show = 'image';
|
|
if ($brand_ids) {
|
|
$where = array('app_id' => $this->app_id, 'type' => $type, 'status' => 1);
|
|
if ($type == 3) {
|
|
$show = 'text';
|
|
$res = $this->mdTemplate->select($where, "id desc", 1, 1, 'json_data');
|
|
if ($res[0]['json_data']) {
|
|
$json_data = json_decode($res[0]['json_data'], true);
|
|
$total = count($json_data['lists']);
|
|
foreach ($json_data['lists'] as $key2 => $value2) {
|
|
if ($value2['brands']) {
|
|
$brands = $value2['brands'] . ',';
|
|
foreach ($brand_ids as $key3 => $value3) {
|
|
if (strstr($brands, $value3 . ',')) {
|
|
$lists[] = array('content' => $value2['content']);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
$or_str = '';
|
|
foreach ($brand_ids as $key3 => $value3) {
|
|
$brand_id = $value3 . ',';
|
|
$or_str = $or_str ? $or_str . " OR brand_ids like '%{$brand_id}%'" : "brand_ids like '%{$brand_id}%'";
|
|
}
|
|
$where[' (' . $or_str . ') '] = null;
|
|
$total = $this->mdTemplate->count($where);
|
|
$fileds = 'id,title,cover';
|
|
$res = $this->mdTemplate->select($where, "id desc", $page, $size, $fileds);
|
|
foreach ($res as $key2 => $value2) {
|
|
$value2['cover'] = $value2['cover'] ? build_qiniu_image_url($value2['cover']) : '';
|
|
$re_biz = $this->mdMaterialBiz->get(array('app_id' => $this->app_id, 't_id' => $value2['id'], 'biz_id' => $this->biz_id));
|
|
$value2['if_add'] = $re_biz ? 1 : 0;
|
|
$lists[] = $value2;
|
|
}
|
|
}
|
|
}
|
|
$this->data['show'] = $show;
|
|
$this->data['list'] = $lists;
|
|
$this->data['total'] = $total;
|
|
return $this->data;
|
|
}
|
|
|
|
/**
|
|
* Notes:生成专题
|
|
* Created on: 2021/10/11 16:14
|
|
* Created by: dengbw
|
|
* @throws Hd_exception
|
|
*/
|
|
protected function put_topic()
|
|
{
|
|
$t_id = intval($this->input_param('t_id'));
|
|
if (!$t_id || !$this->biz_id) {
|
|
throw new Hd_exception('参数错误', API_CODE_FAIL);
|
|
}
|
|
$where = array('app_id' => $this->app_id, 't_id' => $t_id, 'biz_id' => $this->biz_id);
|
|
$re = $this->mdMaterialBiz->get($where);
|
|
if ($re) {
|
|
throw new Hd_exception('该专题已经生成过了~', API_CODE_FAIL);
|
|
}
|
|
$where['c_time'] = time();
|
|
$id = $this->mdMaterialBiz->add($where);
|
|
if ($id) {
|
|
throw new Exception('专题生成成功', API_CODE_SUCCESS);
|
|
} else {
|
|
throw new Exception('专题生成失败', API_CODE_FAIL);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Notes:获取二维码
|
|
* Created on: 2021/8/27 16:34
|
|
* Created by: dengbw
|
|
* @return array
|
|
* @throws Hd_Exception
|
|
*/
|
|
protected function get_qrcode()
|
|
{
|
|
$scene = $this->input_param('scene');
|
|
$page = $this->input_param('page');
|
|
$width = $this->input_param('width');
|
|
if (0 == strlen($scene)) {
|
|
throw new Hd_Exception('二维码参数必填', API_CODE_INVILD_PARAM);
|
|
}
|
|
return $this->qrcode($scene, $page, $width);
|
|
}
|
|
|
|
/**
|
|
* Notes:获取图片二维码
|
|
* Created on: 2021/8/27 16:33
|
|
* Created by: dengbw
|
|
* @param $scene
|
|
* @param string $page
|
|
* @param int $width
|
|
* @param string $fig
|
|
* @return array
|
|
* @throws Hd_Exception
|
|
*/
|
|
private function qrcode($scene, $page = '', $width = 0, $fig = 'liche')
|
|
{
|
|
$path = "{$page}?{$scene}";
|
|
$width && $path .= "{$width}";
|
|
if ($fig) {
|
|
$this->config->load('app', true, true);
|
|
$configs = $this->config->item('app');
|
|
$config = $configs[$fig];
|
|
if (!$config) {
|
|
debug_log("[error] " . __FUNCTION__ . ": config not exist;fig={$fig}", $this->log_file);
|
|
throw new Hd_Exception('请求的小程序不存在', API_CODE_INVILD_PARAM);
|
|
}
|
|
$wxconfig = $config['wx'];
|
|
} else {
|
|
$wxconfig = $this->wx_config;
|
|
$fig = $this->app_key;
|
|
}
|
|
$filename = "{$fig}/" . substr(md5($path), 8, 16);
|
|
$this->load->library('Hdwechat');
|
|
$hdwechat = new Hdwechat($wxconfig);
|
|
$ret = $hdwechat->qrcode($filename, $scene, $page, $width);
|
|
if (!$ret) {
|
|
throw new Hd_Exception('生成失败,稍后重试', API_CODE_FAIL);
|
|
}
|
|
$data = array('url' => $ret['url']);
|
|
return $data;
|
|
}
|
|
|
|
}
|