|
|
<?php
|
|
|
namespace Qrcode\Controller;
|
|
|
|
|
|
use Base\Service\PromoteService;
|
|
|
use Think\Controller;
|
|
|
|
|
|
class QrCodePromotionController extends BaseController
|
|
|
{
|
|
|
public function lists1()
|
|
|
{
|
|
|
$page = I('p', 1);
|
|
|
$row = I('row', 10);
|
|
|
|
|
|
$query = M('qrcode_promotion', 'tab_')->where([])->order('create_time desc');
|
|
|
[$items, $page, $count] = $this->paginate($query);
|
|
|
|
|
|
$baseGames = M('base_game', 'tab_')->select();
|
|
|
$baseGames = index_by_column('id', $baseGames);
|
|
|
|
|
|
$games = M('game', 'tab_')->where(['id', 'partner_id'])->select();
|
|
|
$games = index_by_column('id', $games);
|
|
|
foreach ($baseGames as $key => $baseGame) {
|
|
|
if ($baseGame['android_game_id'] > 0) {
|
|
|
$baseGame['partner_id'] = $games[$baseGame['android_game_id']]['partner_id'];
|
|
|
} else {
|
|
|
$baseGame['partner_id'] = $games[$baseGame['ios_game_id']]['partner_id'];
|
|
|
}
|
|
|
$baseGames[$key] = $baseGame;
|
|
|
}
|
|
|
//var_dump($items);die;
|
|
|
$this->assign('_page', $page);
|
|
|
$this->assign('records', $items);
|
|
|
$this->assign('baseGames', $baseGames);
|
|
|
$this->display();
|
|
|
}
|
|
|
|
|
|
public function uploadQrCodeBackground()
|
|
|
{
|
|
|
$fileController = new FileController();
|
|
|
$storageType = C('STORAGE_TYPE');
|
|
|
C('STORAGE_TYPE', null);
|
|
|
/* 调用文件上传组件上传文件 */
|
|
|
$Picture = D('Picture');
|
|
|
$pic_driver = C('PICTURE_UPLOAD_DRIVER');
|
|
|
|
|
|
$info = $Picture->upload(
|
|
|
$_FILES,
|
|
|
C('PICTURE_UPLOAD'),
|
|
|
C('PICTURE_UPLOAD_DRIVER'),
|
|
|
C("UPLOAD_{$pic_driver}_CONFIG"),
|
|
|
$_REQUEST['flag']
|
|
|
); //
|
|
|
|
|
|
C('STORAGE_TYPE', $storageType);
|
|
|
|
|
|
$path = '';
|
|
|
if ($info) {
|
|
|
$path = get_cover($info['file']['id'], 'path');
|
|
|
}
|
|
|
|
|
|
return $this->ajaxReturn([
|
|
|
'id' => $info['file']['id'],
|
|
|
'path' => $path
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
public function save()
|
|
|
{
|
|
|
$params = I('post.');
|
|
|
if (!$params['base_game_id']) {
|
|
|
$this->ajaxReturn(['status' => 0, 'message' => '参数有误!']);
|
|
|
}
|
|
|
$exists = M('qrcode_promotion', 'tab_')->where([
|
|
|
"game_id" => $params['base_game_id']
|
|
|
])->find();
|
|
|
if ($exists) {
|
|
|
M('qrcode_promotion', 'tab_')->where([
|
|
|
"game_id" => $params['base_game_id']
|
|
|
])->save([
|
|
|
'background_img' => $params['img'],
|
|
|
'update_time' => time(),
|
|
|
'admin_id' => getAdmin(),
|
|
|
'admin_name' => getAdmin('username'),
|
|
|
]);
|
|
|
} else {
|
|
|
if (!$params['base_game_id']) {
|
|
|
$this->ajaxReturn(['status' => 0, 'message' => '游戏不能为空!']);
|
|
|
}
|
|
|
M('qrcode_promotion', 'tab_')->add([
|
|
|
'game_id' => $params['base_game_id'],
|
|
|
'game_name' => $params['game_name'].'',
|
|
|
'status' => 0,
|
|
|
'background_img' => $params['img'],
|
|
|
'create_time' => time(),
|
|
|
'update_time' => 0,
|
|
|
'admin_id' => getAdmin(),
|
|
|
'admin_name' => getAdmin('username'),
|
|
|
]);
|
|
|
}
|
|
|
$this->ajaxReturn(['status' => 1, 'message' => '保存成功!']);
|
|
|
}
|
|
|
|
|
|
public function add()
|
|
|
{
|
|
|
$baseGames = M('base_game', 'tab_')->select();
|
|
|
$baseGames = index_by_column('id', $baseGames);
|
|
|
|
|
|
$games = M('game', 'tab_')->where(['id', 'partner_id'])->select();
|
|
|
$games = index_by_column('id', $games);
|
|
|
foreach ($baseGames as $key => $baseGame) {
|
|
|
if ($baseGame['android_game_id'] > 0) {
|
|
|
$baseGame['partner_id'] = $games[$baseGame['android_game_id']]['partner_id'];
|
|
|
} else {
|
|
|
$baseGame['partner_id'] = $games[$baseGame['ios_game_id']]['partner_id'];
|
|
|
}
|
|
|
$baseGames[$key] = $baseGame;
|
|
|
}
|
|
|
$this->assign('baseGames', $baseGames);
|
|
|
|
|
|
if (IS_POST) {
|
|
|
$loginer = $this->getLoginPromote();
|
|
|
$params = I('post.');
|
|
|
if (!$params['base_game_id']) {
|
|
|
$this->ajaxReturn(['status' => 0, 'message' => '参数有误!']);
|
|
|
}
|
|
|
$exists = M('qrcode_promotion', 'tab_')->where([
|
|
|
"game_id" => $params['base_game_id']
|
|
|
])->find();
|
|
|
if ($exists) {
|
|
|
M('qrcode_promotion', 'tab_')->where([
|
|
|
"game_id" => $params['base_game_id']
|
|
|
])->save([
|
|
|
'background_img' => $params['img'],
|
|
|
'update_time' => time(),
|
|
|
'admin_id' => $loginer['id'],
|
|
|
'admin_name' => $loginer['account'],
|
|
|
]);
|
|
|
} else {
|
|
|
if (!$params['base_game_id']) {
|
|
|
$this->ajaxReturn(['status' => 0, 'message' => '游戏不能为空!']);
|
|
|
}
|
|
|
M('qrcode_promotion', 'tab_')->add([
|
|
|
'game_id' => $params['base_game_id'],
|
|
|
'game_name' => $params['game_name'].'',
|
|
|
'status' => 0,
|
|
|
'background_img' => $params['img'],
|
|
|
'create_time' => time(),
|
|
|
'update_time' => 0,
|
|
|
'admin_id' => $loginer['id'],
|
|
|
'admin_name' => $loginer['account'],
|
|
|
]);
|
|
|
}
|
|
|
$this->ajaxReturn(['status' => 1, 'message' => '保存成功!']);
|
|
|
}
|
|
|
|
|
|
$this->display();
|
|
|
}
|
|
|
|
|
|
public function edit()
|
|
|
{
|
|
|
$id = I('request.id', 0);
|
|
|
if (!$id) return ;
|
|
|
|
|
|
if (IS_POST) {
|
|
|
M('qrcode_promotion', 'tab_')->where([
|
|
|
"id" => $id
|
|
|
])->save([
|
|
|
'background_img' => I('post.img')
|
|
|
]);
|
|
|
$this->ajaxReturn(['status' => 1, 'message' => '保存成功!']);
|
|
|
}
|
|
|
|
|
|
$qrcodePromotion = M('qrcode_promotion', 'tab_')->where([
|
|
|
"id" => $id
|
|
|
])->find();
|
|
|
|
|
|
$this->assign('id', $qrcodePromotion['id']);
|
|
|
$this->assign('game_name', $qrcodePromotion['game_name']);
|
|
|
$this->assign('background_img', $qrcodePromotion['background_img']);
|
|
|
$this->display();
|
|
|
}
|
|
|
|
|
|
public function linkAdd()
|
|
|
{
|
|
|
if (IS_POST) {
|
|
|
$isHttps = is_https();
|
|
|
$loginer = $this->getLoginPromote();
|
|
|
$params = I('post.');
|
|
|
if (!$params['id']) {
|
|
|
$this->ajaxReturn(['status' => 0, 'message' => '参数有误!']);
|
|
|
}
|
|
|
|
|
|
$id = M('qrcode_promotion_list', 'tab_')->add([
|
|
|
'qp_id' => $params['id'],
|
|
|
'admin_id' => $loginer['id'],
|
|
|
'admin_name' => $loginer['account'],
|
|
|
'h5_link' => '',
|
|
|
'short_link' => '',
|
|
|
'create_time' => time(),
|
|
|
'status' => 0,
|
|
|
'qrcode_img' => json_encode($params['img'], JSON_FORCE_OBJECT),
|
|
|
'interval_min' => $params['interval_min'],
|
|
|
]);
|
|
|
if ($id > 0) {
|
|
|
$uniqueStr = $this->getUniqueStr();
|
|
|
$h5Link = "https://game.chengfeng123.cn"."/index.php?s=/Qrcode/Jump/jumpMp/{$uniqueStr}";
|
|
|
$shortLink = $this->getShortUrl($h5Link);
|
|
|
|
|
|
M('qrcode_promotion_list', 'tab_')->where(['id' => $id])->save([
|
|
|
'unique_str' => $uniqueStr,
|
|
|
'h5_link' => $h5Link,
|
|
|
'short_link' => $shortLink
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
$this->ajaxReturn(['status' => 1, 'message' => '保存成功!']);
|
|
|
}
|
|
|
|
|
|
$qpId = I('get.id', 0);
|
|
|
$this->assign("qp_id", $qpId);
|
|
|
$this->display();
|
|
|
}
|
|
|
|
|
|
private function getUniqueStr() {
|
|
|
while (1) {
|
|
|
$chars = $this->getRandomStr(8);
|
|
|
$find = M('qrcode_promotion_list', 'tab_')->where([
|
|
|
'unique_str' => $chars
|
|
|
])->find();
|
|
|
if (!$find) return $chars;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private function getRandomStr($len){
|
|
|
static $pol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
|
$str = '';
|
|
|
$max = strlen($pol) - 1;
|
|
|
for ($i = 0; $i < $len; $i++) {
|
|
|
$str .= $pol[mt_rand(0, $max)];
|
|
|
}
|
|
|
|
|
|
return $str;
|
|
|
}
|
|
|
|
|
|
public function linkEdit()
|
|
|
{
|
|
|
$id = I('request.id', 0);
|
|
|
if (!$id) return ;
|
|
|
|
|
|
if (IS_POST) {
|
|
|
// var_dump(json_encode(I('post.img'), JSON_FORCE_OBJECT));die;
|
|
|
M('qrcode_promotion_list', 'tab_')->where([
|
|
|
"id" => $id
|
|
|
])->save([
|
|
|
'interval_min' => I('post.interval_min'),
|
|
|
'qrcode_img' => json_encode(I('post.img'), JSON_FORCE_OBJECT)
|
|
|
]);
|
|
|
$this->ajaxReturn(['status' => 1, 'message' => '保存成功!']);
|
|
|
}
|
|
|
|
|
|
$qrcodePromotionList = M('qrcode_promotion_list', 'tab_')->where([
|
|
|
"id" => $id
|
|
|
])->find();
|
|
|
$imgs = json_decode($qrcodePromotionList['qrcode_img'], true);
|
|
|
|
|
|
$this->assign('imgs', $imgs);
|
|
|
$this->assign('id', $id);
|
|
|
$this->assign('qp_id', $qrcodePromotionList['qp_id']);
|
|
|
$this->assign('interval_min', $qrcodePromotionList['interval_min']);
|
|
|
$this->display();
|
|
|
}
|
|
|
|
|
|
public function linkDel()
|
|
|
{
|
|
|
$id = I('request.id', 0);
|
|
|
if (!$id) return ;
|
|
|
|
|
|
M('qrcode_promotion_list', 'tab_')->where(['id' => $id])->delete();
|
|
|
|
|
|
$this->ajaxReturn(['status' => 1, 'message' => '删除成功!']);
|
|
|
}
|
|
|
|
|
|
public function linkLists()
|
|
|
{
|
|
|
$loginer = $this->getLoginPromote();
|
|
|
$page = I('p', 1);
|
|
|
$row = I('row', 10);
|
|
|
$qpId = I('get.id', 0);
|
|
|
if (!$qpId) return ;
|
|
|
|
|
|
$promotionInfo = M('qrcode_promotion', 'tab_')->where([
|
|
|
'id' => $qpId
|
|
|
])->find();
|
|
|
|
|
|
$query = M('qrcode_promotion_list', 'tab_')->where([
|
|
|
'qp_id' => I('get.id'),
|
|
|
'admin_id' => $loginer['id']
|
|
|
])->order('create_time desc');
|
|
|
[$items, $page, $count] = $this->paginate($query);
|
|
|
|
|
|
$this->assign("qp_id", $qpId);
|
|
|
$this->assign('_page', $page);
|
|
|
$this->assign('records', $items);
|
|
|
$this->assign('promotion_info', $promotionInfo);
|
|
|
$this->display();
|
|
|
}
|
|
|
|
|
|
public function lists()
|
|
|
{
|
|
|
$query = M('qrcode_promotion', 'tab_')->where([])->order('create_time desc');
|
|
|
[$items, $page, $count] = $this->paginate($query);
|
|
|
|
|
|
$this->assign('_page', $page);
|
|
|
$this->assign('records', $items);
|
|
|
|
|
|
$this->display();
|
|
|
}
|
|
|
|
|
|
public function getShortUrl($longUrl)
|
|
|
{
|
|
|
$shortUrl = '';
|
|
|
$host = "https://encsholin.market.alicloudapi.com";
|
|
|
$path = "/shortlink";
|
|
|
$method = "GET";
|
|
|
$appcode = "783dde1552fa412293c56f9ad875579b";//开通服务后 买家中心-查看AppCode
|
|
|
$headers = array();
|
|
|
array_push($headers, "Authorization:APPCODE " . $appcode);
|
|
|
$querys = "password=&url={$longUrl}";
|
|
|
$url = $host . $path . "?" . $querys;
|
|
|
|
|
|
$curl = curl_init();
|
|
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
|
|
curl_setopt($curl, CURLOPT_FAILONERROR, false);
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
|
curl_setopt($curl, CURLOPT_HEADER, true);
|
|
|
if (1 == strpos("$" . $host, "https://")) {
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
}
|
|
|
$out_put = curl_exec($curl);
|
|
|
|
|
|
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
|
|
|
|
list($header, $body) = explode("\r\n\r\n", $out_put, 2);
|
|
|
if ($httpCode == 200) {
|
|
|
$url = json_decode($body, true);
|
|
|
$shortUrl = $url['url'];
|
|
|
if (!$shortUrl) $shortUrl = $url['msg'];
|
|
|
} else {
|
|
|
if ($httpCode == 400 && strpos($header, "Invalid Param Location") !== false) {
|
|
|
$shortUrl = ("参数错误");
|
|
|
} elseif ($httpCode == 400 && strpos($header, "Invalid AppCode") !== false) {
|
|
|
$shortUrl = ("AppCode错误");
|
|
|
} elseif ($httpCode == 400 && strpos($header, "Invalid Url") !== false) {
|
|
|
$shortUrl = ("请求的 Method、Path 或者环境错误");
|
|
|
} elseif ($httpCode == 403 && strpos($header, "Unauthorized") !== false) {
|
|
|
$shortUrl = ("服务未被授权(或URL和Path不正确)");
|
|
|
} elseif ($httpCode == 403 && strpos($header, "Quota Exhausted") !== false) {
|
|
|
$shortUrl = ("套餐包次数用完");
|
|
|
} elseif ($httpCode == 500) {
|
|
|
$shortUrl = ("API网关错误");
|
|
|
} elseif ($httpCode == 0) {
|
|
|
$shortUrl = ("URL错误");
|
|
|
} else {
|
|
|
$shortUrl .= ("参数名错误 或 其他错误");
|
|
|
$shortUrl .= ($httpCode);
|
|
|
$headers = explode("\r\n", $header);
|
|
|
$headList = array();
|
|
|
foreach ($headers as $head) {
|
|
|
$value = explode(':', $head);
|
|
|
$headList[$value[0]] = $value[1];
|
|
|
}
|
|
|
$shortUrl .= ($headList['x-ca-error-message']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $shortUrl;
|
|
|
}
|
|
|
|
|
|
} |