You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/admin/controller/Wxserve.php

341 lines
10 KiB

8 months ago
<?php
declare (strict_types=1);
namespace app\admin\controller;
use app\common\library\wxserver\Server;
8 months ago
use app\job\controller\Wxserver as WxserverJob;
8 months ago
use PHPQRCode\QRcode;
use think\db\exception\DbException;
use think\facade\Db;
use think\response\Json;
class Wxserve extends Controller
{
/**
* @notes:生成授权二维码
* @return Json
* @author: wanghousheng
*/
public function qrcode(): Json
{
$obj = new Server();
$url = $this->request->domain(true) . '/api/wxserver/redirect';
$jumUrl = $obj->jumpH5Url($url);
$savePath = root_path() . "public/wxserve";
!is_dir($savePath) && mkdir($savePath, 0755, true);
$savePath .= '/auth_qrcode.png';
8 months ago
QRcode::png($jumUrl, $savePath, 'L', 8, 1);
8 months ago
return $this->renderSuccess(['img_url' => $this->request->domain(true) . '/wxserve/auth_qrcode.png?time=' . time()]);
8 months ago
}
/**
* @notes:授权列表
* @return Json
* @throws DbException
* @author: wanghousheng
*/
public function authList(): Json
{
$store_ids = [];
$where = [];
$store_id = intval($this->request->get('store_id'));
if ($store_id) {
$where[] = ['store_id', '=', $store_id];
}
$nick_name = $this->request->get('nick_name');
if ($nick_name) {
$where[] = ['nick_name', 'like', "%$nick_name%"];
}
$appid = $this->request->get('appid');
if ($appid) {
$where[] = ['nick_name', '=', "%$appid%"];
}
$result = Db::table('yoshop_wxserver_account')
->where($where)
->paginate(15);
$list = $result->items();
$total = $result->total();
if ($total) {
foreach ($list as &$item) {
$store_ids[] = $item['store_id'];
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
8 months ago
if ($item['exp_info']) {
$item['exp_info'] = json_decode($item['exp_info'], true);
8 months ago
if (!empty($item['exp_info']['exp_time'])) {
$item['exp_info']['exp_time'] = date('Y-m-d H:i:s', $item['exp_info']['exp_time']);
}
8 months ago
} else {
$item['exp_info']['exp_time'] = '无';
$item['exp_info']['exp_version'] = '无';
8 months ago
}
if ($item['release_info']) {
$item['release_info'] = json_decode($item['release_info'], true);
8 months ago
if (!empty($item['release_info']['release_time'])) {
$item['release_info']['release_time'] = date('Y-m-d H:i:s', $item['release_info']['release_time']);
}
8 months ago
} else {
$item['release_info']['release_time'] = '无';
$item['release_info']['release_version'] = '无';
8 months ago
}
if (!empty($item['experience_code'])) {
$item['experience_code'] = $this->request->domain(true) . $item['experience_code'] . '?time=' . time();
}
8 months ago
if ($item['audit_status'] == 0) {
8 months ago
$item['audit_status_text'] = '--';
8 months ago
} elseif ($item['audit_status'] == 1) {
$item['audit_status_text'] = '审核中';
} elseif ($item['audit_status'] == 2) {
$item['audit_status_text'] = '审核通过';
} elseif ($item['audit_status'] == 3) {
$item['audit_status_text'] = '审核失败';
} elseif ($item['audit_status'] == 4) {
$item['audit_status_text'] = '延时审核';
}
8 months ago
unset($item['access_token']);
unset($item['refresh_token']);
unset($item['signature']);
8 months ago
}
$store_list = Db::table('yoshop_store')
->whereIn('store_id', $store_ids)
->column('store_name', 'store_id');
foreach ($list as &$item) {
$item['store_name'] = $store_list[$item['store_id']] ?? '';
}
}
return $this->renderSuccess(['list' => $list, 'total' => $total]);
}
8 months ago
/**
* @notes:草稿箱列表
* @return Json
* @author: wanghousheng
*/
public function templatedraftlist(): Json
{
8 months ago
$type = intval($this->request->get('type', 0));
8 months ago
$obj = new Server();
8 months ago
$list = $obj->getTemplateDraftList($type);
8 months ago
return $this->renderSuccess($list);
}
8 months ago
8 months ago
/**
* @notes:添加草稿到模板中
* @return Json
* @author: wanghousheng
*/
public function addTotemplate(): Json
{
$draft_id = $this->request->get('draft_id');
if ($draft_id) {
$obj = new Server();
$res = $obj->addTotemplate($draft_id);
if ($res) {
return $this->renderSuccess('success');
}
}
return $this->renderError('操作失败');
}
/**
* @notes:获取模板列表
* @return Json
* @author: wanghousheng
*/
public function templatelist(): Json
{
8 months ago
$type = intval($this->request->get('type', 0));
8 months ago
$obj = new Server();
8 months ago
$list = $obj->getTemplatelist($type);
8 months ago
return $this->renderSuccess($list);
}
/**
* @notes:删除模板
* @return Json
* @author: wanghousheng
*/
public function delTemplatelist(): Json
{
$template_id = $this->request->get('template_id');
if ($template_id) {
$obj = new Server();
$res = $obj->deleTetemplate($template_id);
if ($res) {
return $this->renderSuccess('success');
}
}
return $this->renderError('操作失败');
}
/**
8 months ago
* @notes:提交体验版
8 months ago
* @return Json
* @author: wanghousheng
*/
public function commit(): Json
{
8 months ago
$appid = $this->request->get('appid');
8 months ago
$template_id = $this->request->get('template_id');
8 months ago
$appids = explode(',', $appid);
8 months ago
if ($appids && $template_id) {
foreach ($appids as $item) {
WxserverJob::dispatch(['appid' => $item, 'template_id' => $template_id]);
8 months ago
}
8 months ago
return $this->renderSuccess('success');
8 months ago
}
return $this->renderError('操作失败');
}
/**
* @notes:获取版本信息
* @return Json
* @author: wanghousheng
*/
public function getVersion(): Json
{
$appid = $this->request->get('appid');
5 months ago
if (!$appid) {
return $this->renderError('缺少参数appid');
8 months ago
}
5 months ago
$obj = new Server();
$msg = $obj->getVersioninfo($appid);
if ($msg == 'ok') {
return $this->renderSuccess('success');
}
return $this->renderError($msg);
8 months ago
}
8 months ago
/**
* @notes:提交正式版审核
* @return Json
* @author: wanghousheng
*/
public function audit(): Json
{
8 months ago
$appid = $this->request->get('appid');
$appids = explode(',', $appid);
8 months ago
if ($appids) {
foreach ($appids as $item) {
WxserverJob::dispatch(['appid' => $item]);
8 months ago
}
8 months ago
return $this->renderSuccess('success');
8 months ago
}
return $this->renderError('操作失败');
}
7 months ago
public function auditOne(): Json
{
$appid = $this->request->get('appid');
$obj = new Server();
7 months ago
$res = $obj->privacyInfo($appid);
if ($res == 'ok') {
7 months ago
$result = $obj->submitAuditOne($appid);
if ($result['status']) {
return $this->renderSuccess('success');
} else {
return $this->renderError($result['msg']);
}
7 months ago
} else {
return $this->renderError('隐私接口错误');
}
}
8 months ago
/**
* @notes:发布正式版前检查
* @return Json
* @author: wanghousheng
*/
public function auditBeforeCheck(): Json
{
$msg = '操作失败';
$appid = $this->request->get('appid');
if ($appid) {
$obj = new Server();
$msg = $obj->privacyInfo($appid);
if ($msg == 'ok') {
return $this->renderSuccess('success');
}
}
return $this->renderError($msg);
}
4 months ago
/**
* @notes:设置域名
* @return Json
* @author: wanghousheng
*/
public function setDomain(): Json
{
$msg = 'appid不能为空';
$domain = $this->request->domain(true);
$appid = $this->request->get('appid', $domain);
if ($appid) {
$obj = new Server();
$msg = $obj->setDomain($appid, $domain);
if ($msg == 'ok') {
return $this->renderSuccess('success');
}
}
return $this->renderError($msg);
}
/**
* @notes:设置隐私
* @return Json
* @author: wanghousheng
*/
public function privacySetting(): Json
{
$msg = 'appid不能为空';
$appid = $this->request->get('appid');
if ($appid) {
$obj = new Server();
$msg = $obj->getPrivacySetting($appid);
if ($msg == 'ok') {
return $this->renderSuccess('success');
}
}
return $this->renderError($msg);
}
/**
* @notes:设置业务域名
* @return Json
* @author: wanghousheng
*/
public function modifyJumpDomain(): Json
{
$msg = 'appid不能为空';
$domain = $this->request->domain(true);
$appid = $this->request->get('appid');
if ($appid) {
$obj = new Server();
$msg = $obj->modifyJumpDomain($appid, $domain);
if ($msg == 'ok') {
return $this->renderSuccess('success');
}
}
return $this->renderError($msg);
}
/**
* @notes:设置订单页
* @return Json
* @author: wanghousheng
*/
public function setOrderPath(): Json
{
$msg = 'appid不能为空';
$appid = $this->request->get('appid');
if ($appid) {
$obj = new Server();
$msg = $obj->applySetOrderPathInfo([$appid]);
4 months ago
if ($msg == 'ok') {
4 months ago
return $this->renderSuccess('success');
}
}
return $this->renderError($msg);
}
8 months ago
}