|
|
|
<?php
|
|
|
|
declare (strict_types=1);
|
|
|
|
|
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
|
|
use app\common\library\wxserver\Server;
|
|
|
|
use cores\exception\BaseException;
|
|
|
|
use PHPQRCode\QRcode;
|
|
|
|
use think\db\exception\DataNotFoundException;
|
|
|
|
use think\db\exception\DbException;
|
|
|
|
use think\db\exception\ModelNotFoundException;
|
|
|
|
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';
|
|
|
|
QRcode::png($jumUrl, $savePath, 'L', 8, 1);
|
|
|
|
//return $this->renderSuccess(['img_url' => $this->request->domain(true) . '/wxserve/auth_qrcode.png?time=' . time()]);
|
|
|
|
return $this->renderSuccess(['url' => $jumUrl]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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)
|
|
|
|
->field(['appid', 'nick_name', 'head_image', 'user_name', 'qrcode_image', 'store_id', 'create_time', 'version'])
|
|
|
|
->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']);
|
|
|
|
}
|
|
|
|
$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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @notes:草稿箱列表
|
|
|
|
* @return Json
|
|
|
|
* @author: wanghousheng
|
|
|
|
*/
|
|
|
|
public function templatedraftlist(): Json
|
|
|
|
{
|
|
|
|
$type = intval($this->request->get('type', 0));
|
|
|
|
$obj = new Server();
|
|
|
|
$list = $obj->getTemplateDraftList($type);
|
|
|
|
return $this->renderSuccess($list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
{
|
|
|
|
$type = intval($this->request->get('type', 0));
|
|
|
|
$obj = new Server();
|
|
|
|
$list = $obj->getTemplatelist($type);
|
|
|
|
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('操作失败');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @notes:提交版本审核
|
|
|
|
* @return Json
|
|
|
|
* @throws DbException
|
|
|
|
* @throws BaseException
|
|
|
|
* @throws DataNotFoundException
|
|
|
|
* @throws ModelNotFoundException
|
|
|
|
* @author: wanghousheng
|
|
|
|
*/
|
|
|
|
public function commit(): Json
|
|
|
|
{
|
|
|
|
$appid = $this->request->get('appid');
|
|
|
|
$template_id = $this->request->get('template_id');
|
|
|
|
if ($template_id && $appid) {
|
|
|
|
$obj = new Server();
|
|
|
|
$res = $obj->commit($appid, $template_id);
|
|
|
|
if ($res) {
|
|
|
|
return $this->renderSuccess('success');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->renderError('操作失败');
|
|
|
|
}
|
|
|
|
}
|