Files
liche/home/controllers/h5/market/sytopic/Welcome.php
T
lin fan db429f03ae 1
2024-11-12 11:11:57 +08:00

190 lines
7.9 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
require_once APPPATH . 'controllers/h5/market/sylive2/Common.php';
require_once COMMPATH . 'third_party/phpqrcode/phpqrcode.php';
class Welcome extends Wx
{
const ENROLL_SIGN_KEY = 'sytopic_enroll_code_'; //报名验证码key
private $a_id, $skey;
public function __construct()
{
parent::__construct();
$this->load->model('market/Market_sytopic_module_option_model', 'module_option_model');
$this->load->model('market/Market_sytopic_enroll_model', 'sytopic_enroll_model');
$this->load->model('market/market_sylive_organization_model', 'organization_model');
$this->load->library('qiniu');
$this->load->library("ssApi");
$this->skey = $this->input->get_post('skey');
$param = $this->myencryption->base64url_decode($this->skey);
$this->a_id = intval($param[self::SIGN_TOP_KEY]);//活动id
if (!$this->a_id) {
throw new Hd_exception("参数错误", 400);
}
$this->data['skey'] = $this->skey;
if($this->skey == 'dG9waWNfaWQ9Ng' || $this->skey == 'dG9waWNfaWQ9OQ'){
debug_log("params:". json_encode($this->input->get()), 'auto.txt');
}
if($this->skey == 'dG9waWNfaWQ9OA'){
debug_log("params:". json_encode($this->input->get()), 'auto3.txt');
}
}
public function index()
{
$row = $this->topic_model->get(['id' => $this->a_id]);
$actUser = $this->topic_user_model->get(['id' => $this->act_uid]);
if (!$row) {
throw new Hd_exception('参数错误', 400);
}
$channelRow = [];
$actUser['channelId'] && $channelRow = $this->user_model->get(['userId' => $actUser['channelId']]);
$jsonData = json_decode($row['jsondata'], true);
$info = [
'id' => $row['id'],
'title' => $row['title'],
'isAdmin' => $this->user_model->checkTopicIsAdmin($this->uid, $this->a_id),
'channelName' => $channelRow ? $channelRow['uname'] : '',
'channelHeadImg' => $channelRow['headimg'] ?: 'https://img.liche.cn/liche/market/202407/p_e1065373f27937f69142c28ce975a398.png',
'channelTel' => $channelRow ? $channelRow['mobile'] : '',
'banner' => $jsonData['banner'] ? build_qiniu_image_url($jsonData['banner']) : '',
'bgColor' => $jsonData['bg_color'] ?: '',
'buttonType' => $jsonData['button_type'] ? (int)$jsonData['button_type'] : '',
'bottom_img' => $jsonData['bottom_img'] ? build_qiniu_image_url($jsonData['bottom_img']) : '',
];
$moduleLists = $this->module_option_model->getTopicModelOptionsList($this->a_id);
$this->data['modules'] = array_values($moduleLists);
$this->data['logoList'] = $this->module_option_model->getTypeEnrollBannerList($this->a_id);
//获取门店信息
$orgRow = $this->organization_model->get(['organizationId' => $channelRow['bizId']]);
$ssBizId = (int)$orgRow['comments'];
$biz = [];
if ($ssBizId) {
$ssApi = new SsApi();
$req = $ssApi->getBiz($ssBizId);
if ($req['code']) {
$biz = $req['data'];
}
}
$info['biz'] = $biz;
$this->data['info'] = $info;
//获取配置信息
$wx_info = $this->share_info([], $row);//微信分享
$this->data['sign_package'] = $wx_info['sign_package'];
$this->data['share'] = $wx_info['share'];
$this->data['_title'] = $row['title'];
$this->show_view('h5/market/sytopic/index');
}
//报名
public function enroll()
{
$redis = &load_cache();
$optionId = intval($this->input->post('optionId'));
$topicId = intval($this->input->post('topicId'));
if (!$topicId) {
$this->show_json('', 400, '参数错误');
}
$info = $this->input->post('info');
$name = $info['name'];
$mobile = $info['phone'];
$code = $info['code'];
if (!$name) {
$name = '客户';
//$this->show_json('', 400, '请输入姓名');
}
$key = self::ENROLL_SIGN_KEY . $mobile;
if (!$code || $code != $redis->get($key)) {
$this->show_json('', 400, '请输入正确的验证码');
}
$result = $this->sytopic_enroll_model->enroll($topicId, $optionId, $this->act_uid, $name, $mobile);
if (!$result['code']) {
$this->show_json('', 400, $result['msg']);
}
$this->show_json('', 200, '提交成功');
}
//获取报名验证码
public function get_code()
{
$mobile = $this->input->post('mobile');
if (!mobile_valid($mobile)) {
$this->show_json('', 400, '请输入正确的手机号码');
}
$redis = &load_cache();
$key = self::ENROLL_SIGN_KEY . $mobile;
$code = $redis->get($key);
if ($code) {
$this->show_json('', 200, '验证码已发送');
}
if (!$code) {
$this->load->helper('string');
$code = random_string('numeric', 4);
$redis->save($key, $code, 60 * 5);
}
$content = "【好店云】您的验证码为: {$code},五分钟之内有效,请勿泄露于他人!";
b2m_send_sms($mobile, $content);
$this->show_json('', 200, '验证码已发送');
}
public function share()
{
$row = $this->topic_model->get(['id' => $this->a_id]);
if (!$row) {
throw new Hd_exception('参数错误', 400);
}
$shareImg = json_decode($row['shareImg'], true);
$shareTitle = $row['shareTitle'] ? json_decode($row['shareTitle'], true) : [];
$lists = [];
if ($shareImg) {
$share_skey = self::SIGN_TOP_KEY . "=" . $this->a_id . "&cf_uid=" . $this->uid;
$share_url = http_host_com('home') . "/h5/market/sytopic?skey=" . $this->myencryption->base64url_encode($share_skey);
$errorCorrectionLevel = 'L'; //容错级别
$matrixPointSize = 5; //生成图片大小
//生成二维码图片
$file_name = md5($share_url) . '.png';
$file_path = "temp/{$file_name}";
if (!file_exists(FCPATH . 'temp/')) {
$oldumask = umask(0);
mkdir(FCPATH . 'temp/', 0777, true);
umask($oldumask);
}
QRcode::png($share_url, FCPATH . $file_path, $errorCorrectionLevel, $matrixPointSize, 1);
$res = $this->qiniu->save($file_name, file_get_contents(FCPATH . $file_path));
if ($res['url']) {
@unlink(FCPATH . $file_path);
$qr_code = build_qiniu_image_url($res['url']);
} else {
$qr_code = '/h5/market/sylive2/myqrcode/get?url=' . $share_url;
}
foreach ($shareImg as $item) {
$img_url = build_qiniu_image_url($item);
$img_info = file_get_contents($img_url . '?imageInfo');
if ($img_info) {
$img_info = json_decode($img_info, true);
}
$lists[] = [
"img" => $img_url,
"code" => $qr_code,
'width' => $img_info['width'] ? $img_info['width'] : 750,
'height' => $img_info['height'] ? $img_info['height'] : 1130,
];
}
}
$user = $this->user_model->get(['userId' => $this->uid], 'uname,nickname');
$this->data['posterTip'] = "{$user['nickname']}诚挚邀请您参与";
$this->data['fillStyle'] = '#fff';
$this->data['lists'] = $lists;
$this->data['shareTitle'] = $shareTitle;
//微信分享
$wx_info = $this->share_info([], $row);
$this->data['sign_package'] = $wx_info['sign_package'];
$this->data['share'] = $wx_info['share'];
$this->show_view('h5/market/sytopic/share');
}
}