200 lines
7.6 KiB
PHP
200 lines
7.6 KiB
PHP
<?php
|
|
/**
|
|
* ThinkShop商城系统 - 团队十年电商经验汇集巨献!
|
|
* =========================================================
|
|
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
|
|
* ----------------------------------------------
|
|
* 官方网址: https://www.cdcloudshop.com
|
|
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
|
|
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
|
|
* =========================================================
|
|
*/
|
|
|
|
namespace addon\aliapp\storeapi\controller;
|
|
|
|
use addon\aliapp\model\AliPayApplet;
|
|
use addon\aliapp\model\AppletRelease as appletReleaseModel;
|
|
use addon\aliapp\model\Config;
|
|
use addon\aliapp\model\MinCode;
|
|
use app\model\upload\Upload as UploadModel;
|
|
use app\storeapi\controller\BaseStoreApi;
|
|
|
|
/**
|
|
* Class Account
|
|
* @package addon\shop\siteapi\controller
|
|
*/
|
|
class AppletRelease extends BaseStoreApi
|
|
{
|
|
public function __construct()
|
|
{
|
|
//执行父类构造函数
|
|
parent::__construct();
|
|
$token = $this->checkToken();
|
|
if ($token[ 'code' ] < 0) {
|
|
echo $this->response($token);
|
|
exit;
|
|
}
|
|
}
|
|
/**
|
|
* Common: 进入发布小程序
|
|
* Author: wu-hui
|
|
* Time: 2023/01/03 17:05
|
|
* @return array|mixed
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function index(){
|
|
$config = new Config();
|
|
$config_info = $config->getAppConfig($this->site_id)['data']['value'];
|
|
$baseinfo=[];
|
|
$is_baseinfo=1;
|
|
if(!empty($config_info['line_type'])&&$config_info['line_type']=='auth'){
|
|
$app = new MinCode();
|
|
$app->appAuthToken = $config_info['app_auth_token'];
|
|
$baseinfo = cache($app->appAuthToken . '_baseinfo');
|
|
if (empty($baseinfo)) {
|
|
$baseinfo = $app->requestApi('alipay.open.mini.baseinfo.query')['alipay_open_mini_baseinfo_query_response'];
|
|
cache($app->appAuthToken . '_baseinfo', $baseinfo);
|
|
}
|
|
if(!isset($baseinfo['category_names'])){
|
|
$is_baseinfo=0;
|
|
}
|
|
}
|
|
return $this->response($this->success([
|
|
'is_baseinfo' => $is_baseinfo,
|
|
'baseinfo' => $baseinfo,
|
|
'isNewest' => (new AliPayApplet($this->site_id))->isNewestVersion(),
|
|
]));
|
|
}
|
|
|
|
/**
|
|
* 编辑小程序基础信息
|
|
* 已商上架小程序无法再次修改
|
|
* @return array|mixed
|
|
*/
|
|
public function appinfo()
|
|
{
|
|
$site_id = $this->site_id;
|
|
$app = new MinCode();
|
|
$config = new Config();
|
|
$config_info = $config->getAppConfig($site_id)['data']['value'];
|
|
$app->appAuthToken = $config_info['app_auth_token'];
|
|
|
|
$baseinfo = cache($app->appAuthToken . '_baseinfo');
|
|
if (empty($baseinfo)) {
|
|
$baseinfo = $app->requestApi('alipay.open.mini.baseinfo.query')['alipay_open_mini_baseinfo_query_response'];
|
|
cache($app->appAuthToken . '_baseinfo', $baseinfo);
|
|
}
|
|
$one_category = cache($app->appAuthToken . '_category');
|
|
$category_all = cache($app->appAuthToken . '_alls_category');
|
|
if (empty($one_category)) {
|
|
$category = $app->requestApi('alipay.open.mini.category.query', ['is_filter' => true])['alipay_open_mini_category_query_response'];
|
|
if ($category['mini_category_list']) {
|
|
$category_all = array_column($category['mini_category_list'], null, 'category_id');
|
|
$one_category = [];
|
|
foreach ($category_all as $key => $item) {
|
|
if ($item['parent_category_id'] == '0') {
|
|
$one_category[] = $item;
|
|
}
|
|
}
|
|
cache($app->appAuthToken . '_category', $one_category);
|
|
cache($app->appAuthToken . '_alls_category', $category_all);
|
|
}
|
|
}
|
|
|
|
$original = [];
|
|
$mini_category_ids = [];
|
|
if(isset($baseinfo['category_names'])){
|
|
$category_names = $baseinfo['category_names'];
|
|
$category_ids = explode(';', $category_names);
|
|
$category_all_name = array_column($category_all, null, 'category_name');
|
|
foreach ($category_ids as $key => $val) {
|
|
if ($val) {
|
|
$text = explode('_', $val);
|
|
foreach ($text as $category_namet) {
|
|
$d=$category_all_name[$category_namet]??[];
|
|
if($d){
|
|
$d['checked']=true;
|
|
$category_all[$d['category_id']]['checked']=true;
|
|
$original[$key][] = $d;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ($original) { //已设置分类
|
|
foreach ($original as $value) {
|
|
$category_ids = array_column($value, 'category_id');
|
|
$mini_category_ids[] = implode('_', $category_ids);
|
|
}
|
|
}
|
|
if (isset($baseinfo['app_logo'])&&strpos($baseinfo['app_logo'], 'http')===0){
|
|
$upload=new UploadModel($site_id);
|
|
$pic_img=$upload->setPath("common/images/" . date("Ymd") . '/')->remotePullToLocal($baseinfo['app_logo']);
|
|
$baseinfo['app_logo']=$pic_img['data']['path'];
|
|
}
|
|
$res = [
|
|
'original' => $original,
|
|
'allCategory' => $this->getTreeCategory($category_all),
|
|
'info' => $baseinfo,
|
|
'mini_category_ids' => implode(';', $mini_category_ids),
|
|
'app_id_info' => model('uni_account')->getInfo([['site_id', '=', $this->site_id]],'appid'),
|
|
'isNewest' => (new AliPayApplet($this->site_id))->isNewestVersion(),
|
|
];
|
|
return $this->response($this->success($res));
|
|
}
|
|
|
|
public function list(){
|
|
$list = (new appletReleaseModel($this->site_id))->getList();
|
|
return $this->response($list);
|
|
}
|
|
|
|
public function getTreeCategory($category){
|
|
$category_all=$category;
|
|
$res = [];
|
|
//遍历寻父 O(n)
|
|
foreach ($category_all as &$item) {
|
|
if (isset($category_all[$item['parent_category_id']])){
|
|
//注意下面有一个引用符 & !
|
|
$category_all[$item['parent_category_id']]['child'] []= &$item;
|
|
}elseif(!$item['parent_category_id']){ // 此处判断是否加入到结果集 $item['pid'] === null 或者 $item['pid'] == -1 之类的
|
|
$res []= &$item;
|
|
}
|
|
}
|
|
unset($item);
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* Common: 小程序发布流程处理
|
|
* Author: wu-hui
|
|
* Time: 2023/01/04 11:05
|
|
* @return array|false|string
|
|
*/
|
|
public function publishingProcessProcessing(){
|
|
// 参数获取
|
|
$type = (string)input('type');
|
|
$id = (int)input('id');
|
|
return $this->response((new AliPayApplet($this->site_id))->publishingInit($type,$id));
|
|
}
|
|
/**
|
|
* Common: 版本管理 —— 版本同步
|
|
* Author: wu-hui
|
|
* Time: 2022/12/30 10:08
|
|
* @return array|false|string
|
|
* @throws \Exception
|
|
*/
|
|
public function versionSynchronization(){
|
|
return $this->response((new AliPayApplet($this->site_id))->versionSynchronization());
|
|
}
|
|
/**
|
|
* Common: 生成小程序推广二维码
|
|
* Author: wu-hui
|
|
* Time: 2023/01/03 14:13
|
|
* @return array|false|string
|
|
*/
|
|
public function qrcodeCreate(){
|
|
$version=config('alipay.templateInfo.template_version');
|
|
return $this->response((new AliPayApplet($this->site_id))->queryTestQrcode($version));
|
|
}
|
|
|
|
} |