491 lines
17 KiB
PHP
491 lines
17 KiB
PHP
<?php
|
|
/**
|
|
* SAAS应用系统 --- 十年开发经验汇集巨献!
|
|
* ==========================================================
|
|
* Copy right 2020-2050 成都众联思索科技有限公司,保留所有权利。
|
|
* ----------------------------------------------------------
|
|
* 官方网址: https://www.zoomtk.com
|
|
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
|
|
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布传播。
|
|
* 唯一发布渠道www.zoomtk.com;非官方渠道统一视为侵权行为。
|
|
* ==========================================================
|
|
*/
|
|
|
|
namespace addon\wxoplatform\shop\controller;
|
|
|
|
use addon\aliapp\model\OpenPay;
|
|
use addon\weapp\model\Config as ConfigModel;
|
|
use addon\weapp\model\Config as WeappConfig;
|
|
use addon\wechatpay\model\Wepay;
|
|
use addon\wxoplatform\model\OpenPlatform;
|
|
use addon\wxoplatform\model\Oplatform as OplatformModel;
|
|
use app\model\system\Api;
|
|
use app\model\upload\Upload;
|
|
use app\model\upload\Upload as UploadModel;
|
|
use app\shop\controller\BaseShop;
|
|
use addon\wxoplatform\model\Weapp as WeappModel;
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 微信开放平台基础功能
|
|
*/
|
|
class Weapp extends BaseShop
|
|
{
|
|
protected $replace = []; //视图输出字符串内容替换 相当于配置文件中的'view_replace_str'
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->replace = [
|
|
'WEAPP_CSS' => __ROOT__ . '/addon/wxoplatform/shop/view/public/css',
|
|
'WEAPP_JS' => __ROOT__ . '/addon/wxoplatform/shop/view/public/js',
|
|
'WEAPP_IMG' => __ROOT__ . '/addon/wxoplatform/shop/view/public/img',
|
|
'WEAPP_SVG' => __ROOT__ . '/addon/wxoplatform/shop/view/public/svg',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 小程序发布和审核
|
|
*/
|
|
public function plugin()
|
|
{
|
|
$weapp_config_model = new WeappConfig();
|
|
$config_result = $weapp_config_model->getWeappConfig($this->site_id);
|
|
$config = $config_result['data'];
|
|
$this->assign("config", $config['value']);
|
|
$open_platform_model = new OpenPlatform($this->site_id);
|
|
$template_list_result = $open_platform_model->getTemplateList();
|
|
if ($template_list_result['code'] == 0) {
|
|
if (is_array($template_list_result['data']) && count($template_list_result['data']) > 1) array_multisort(array_column($template_list_result['data'], 'template_id'), SORT_DESC, $template_list_result['data']);
|
|
} else {
|
|
$template_list_result['data'] = [];
|
|
}
|
|
$where[] = ['site_id', '=', $this->site_id];
|
|
$getInfo = Db::name('weapp_audit_record')->where($where)->order('id desc')->value('info');
|
|
$live = 'no';
|
|
$isCoupon = 'no';
|
|
$location = 'no';
|
|
$isB2cStore = 'no';
|
|
if (strpos($getInfo, "live-player-plugin") != false) {
|
|
$live = 'yes';
|
|
}
|
|
if (strpos($getInfo, "userLocation") != false) {
|
|
$location = 'yes';
|
|
}
|
|
|
|
$this->assign("isB2cStore", $isB2cStore);
|
|
$this->assign("isCoupon", $isCoupon);
|
|
$this->assign("is_live", $live);
|
|
$this->assign("is_location", $location);
|
|
$this->assign("template_list", $template_list_result['data']);
|
|
return $this->fetch('weapp/plugin', [], $this->replace);
|
|
}
|
|
|
|
/**
|
|
* 微信小程序代码上传
|
|
*/
|
|
public function commit()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$api_model = new Api();
|
|
$api_config = $api_model->getApiConfig($this->site_id);
|
|
$api_config = $api_config['data'];
|
|
$open_platform_model = new OpenPlatform($this->site_id);
|
|
$template_id = input('template_id', 0);
|
|
$version = input('version', '');
|
|
$data = array(
|
|
'template_id' => $template_id,
|
|
'ext_json' => [
|
|
'extEnable' => true,
|
|
'extAppid' => $open_platform_model->appid,
|
|
'ext' => [
|
|
'site_id' => $this->site_id,
|
|
'baseUrl' => $open_platform_model->openConfig['api_url'],
|
|
'imgDomain' => $open_platform_model->openConfig['cdn_url'],
|
|
'apiSecurity' => $api_config['is_use'] ?? 0,
|
|
'publicKey' => $api_config['value']['public_key'] ?? '',
|
|
"client_type" => $this->app_module,
|
|
'platform_id' => $this->addon == 'platform' ? $this->site_id : 0,
|
|
'webSocket' => $open_platform_model->openConfig['webSocket'],
|
|
]
|
|
],
|
|
'user_version' => $version,
|
|
'user_desc' => '上传时间' . date('Y-m-d H:i:s', time())
|
|
);
|
|
if (input('isLive') == 'yes') {
|
|
$data['isLive'] = true;
|
|
$data['ext_json']['plugins'] = [
|
|
'live-player-plugin' => [
|
|
'version' => 'latest',
|
|
'provider' => 'wx2b03c6e691cd7370'
|
|
]
|
|
];
|
|
$data['recompile'] = true;
|
|
}
|
|
if (input('isCoupon') == 'yes') {
|
|
$data['isCoupon'] = true;
|
|
$data['ext_json']['plugins'] = [
|
|
'sendCoupon' => [
|
|
'version' => 'latest',
|
|
'provider' => 'wxf3f436ba9bd4be7b'
|
|
]
|
|
];
|
|
}
|
|
if (input('isB2cStore') == 'yes') {
|
|
$data['isB2cStore'] = true;
|
|
$data['ext_json']['plugins'] = [
|
|
'applystore' => [
|
|
'version' => 'latest',
|
|
'provider' => 'wx69b7451feb427f0e'
|
|
]
|
|
];
|
|
}
|
|
if (input('chooseAddress')) {
|
|
$data['chooseAddress'] = true;
|
|
}
|
|
if (input('getLocation') == 'yes') {
|
|
$data['getLocation'] = true;
|
|
$data['ext_json']['permission'] = [
|
|
'scope.userLocation' => [
|
|
'desc' => '为了更好地为您提供就近的服务点'
|
|
]
|
|
];
|
|
$data['ext_json']['requiredPrivateInfos'] = [
|
|
'getLocation',
|
|
'chooseAddress'
|
|
];
|
|
}
|
|
$result = $open_platform_model->weappCommit($data);
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 微信审核
|
|
*/
|
|
public function weappSubmitAudit()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$data = array();
|
|
$open_platform_model = new OpenPlatform($this->site_id);
|
|
$id = input('id');
|
|
$info = model('weapp_audit_record')->getValue([['id', '=', $id]], 'info');
|
|
if (strpos($info, "userLocation") != false) {
|
|
$Interface = $open_platform_model->getPrivacyInterface();
|
|
$def = [];
|
|
$temp = json_decode($info, true);
|
|
if (isset($temp['getLocation']) && $temp['getLocation']) {
|
|
array_push($def, 'wx.getLocation');
|
|
}
|
|
if (isset($temp['chooseAddress']) && $temp['chooseAddress']) {
|
|
array_push($def, 'wx.chooseAddress');
|
|
}
|
|
if (isset($temp['chooseLocation']) && $temp['chooseLocation']) {
|
|
array_push($def, 'wx.chooseLocation');
|
|
}
|
|
$interface = [];
|
|
foreach ($Interface['interface_list'] as $item) {
|
|
if ($item['status'] == 5) {
|
|
array_push($interface, $item['api_name']);
|
|
}
|
|
}
|
|
if (array_diff($def, $interface)) {
|
|
return [
|
|
'code' => -1,
|
|
'message' => '位置接口未审核或未申请,请申请并审核通过在次提交',
|
|
];
|
|
}
|
|
}
|
|
$result = $open_platform_model->weappSubmitAudit($data, input('id'));
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 滚回上次操作
|
|
* @return array|mixed
|
|
*/
|
|
public function rollver()
|
|
{
|
|
$open_platform_model = new OpenPlatform($this->site_id);
|
|
$result = $open_platform_model->revertcoderelease();
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 获取体验二维码
|
|
* @return array|mixed
|
|
*/
|
|
public function getQrcode()
|
|
{
|
|
$open_platform_model = new OpenPlatform($this->site_id);
|
|
$result = $open_platform_model->getQrcode();
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* 审核记录
|
|
*/
|
|
public function record()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$page = input('page', 1);
|
|
$page_size = input('page_size', PAGE_LIST_ROWS);
|
|
$weapp_model = new WeappModel();
|
|
$data = $weapp_model->getAuditPageList($this->site_id, [['site_id', '=', $this->site_id]], '*', 'id desc', $page, $page_size);
|
|
return $data;
|
|
}
|
|
return $this->fetch('weapp/record', [], $this->replace);
|
|
}
|
|
|
|
/**
|
|
* 体验者管理
|
|
*/
|
|
public function experiencer()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$page = input('page', 1);
|
|
$page_size = input('page_size', PAGE_LIST_ROWS);
|
|
$weapp_model = new WeappModel();
|
|
$data = $weapp_model->getExperiencerPageList([['site_id', '=', $this->site_id]], '*', 'id desc', $page, $page_size);
|
|
return $data;
|
|
}
|
|
return $this->fetch('weapp/experiencer', [], $this->replace);
|
|
}
|
|
|
|
/**
|
|
* 绑定体验者
|
|
* @return array|int|mixed|string
|
|
*/
|
|
public function bindTestUser()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$wechatid = input('wechatid', '');
|
|
$weapp_model = new WeappModel();
|
|
$res = $weapp_model->bindExperiencer($this->site_id, $wechatid);
|
|
return $res;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 解绑体验者
|
|
* @return array|int|mixed|string
|
|
*/
|
|
public function unbindTestUser()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$id = input('id', 0);
|
|
$weapp_model = new WeappModel();
|
|
$res = $weapp_model->unbindExperiencer($id, $this->site_id);
|
|
return $res;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 撤回审核
|
|
*/
|
|
public function undocodeaudit()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$id = input('id', 0);
|
|
$weapp_model = new WeappModel();
|
|
$res = $weapp_model->cancelAudit($id, $this->site_id);
|
|
return $res;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 发布
|
|
*/
|
|
public function release()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$id = input('id', 0);
|
|
$weapp_model = new WeappModel();
|
|
$res = $weapp_model->release($id, $this->site_id);
|
|
return $res;
|
|
}
|
|
}
|
|
|
|
/***
|
|
* 设置小程序隐私引导
|
|
* @return array|mixed|void
|
|
*/
|
|
public function conceal()
|
|
{
|
|
$open_platform_model = new OpenPlatform($this->site_id);
|
|
$mustarr = ['UserInfo', 'Location', 'Address', 'PhoneNumber', 'ChooseLocation'];
|
|
if (request()->isAjax()) {
|
|
$data = request()->post();
|
|
$setting_list = [];
|
|
$arr = [];
|
|
$err = '';
|
|
foreach ($data as $k => $v) {
|
|
if ($v) {
|
|
$setting_list[] = [
|
|
'privacy_key' => $k,
|
|
'privacy_text' => $v
|
|
];
|
|
array_push($arr, $k);
|
|
}
|
|
}
|
|
if ($err) {
|
|
$arr = [
|
|
'code' => 1,
|
|
'message' => $err
|
|
];
|
|
return $arr;
|
|
} else {
|
|
$setInfo = $open_platform_model->setPrivacysetting($setting_list)['data'];
|
|
if ($setInfo['errcode'] == 0) {
|
|
$arr = [
|
|
'code' => 0,
|
|
'message' => '设置成功'
|
|
];
|
|
} else {
|
|
$arr = [
|
|
'code' => 1,
|
|
'message' => $setInfo['errmsg']
|
|
];
|
|
}
|
|
return $arr;
|
|
}
|
|
}
|
|
$getInfo = $open_platform_model->getPrivacysetting(2)['data'];
|
|
if ($getInfo['errcode'] != 0) return $getInfo;
|
|
$setting_list = array_column($getInfo['setting_list'], 'privacy_text', 'privacy_key');
|
|
$privacy_list = $getInfo['privacy_list'];
|
|
$privacy_desc = $getInfo['privacy_desc']['privacy_desc_list'];
|
|
foreach ($privacy_desc as $key => &$val) {
|
|
if (in_array($val['privacy_key'], $privacy_list) || in_array($val['privacy_key'], $mustarr)) {
|
|
$val['is_must'] = true;
|
|
} else {
|
|
$val['is_must'] = false;
|
|
}
|
|
}
|
|
$def = [
|
|
'UserInfo' => '获取头像与昵称用于商城展示',
|
|
'Location' => '获取地理位置就近配送',
|
|
'Address' => '获取地址信息快速完成配送',
|
|
'PhoneNumber' => '获取手机号作为平台唯一登录账号',
|
|
'ChooseLocation' => '获取地址信息快速完成配送',
|
|
'Album' => '会员分享相册图像到店铺平台',
|
|
'Invoice' => '会员发票申请',
|
|
'Clipboard' => '快速获取剪切板内容',
|
|
'DeviceInfo' => '获取设备信息作为标记记录',
|
|
'EXOrderInfo' => '获取订单状态信息',
|
|
'Record' => '给店铺平台留言',
|
|
'Camera' => '会员分享拍摄到图像到平台',
|
|
];
|
|
$setting_list = array_merge($setting_list, $def);
|
|
$this->assign('def', $def);
|
|
$this->assign('setting_list', $setting_list);
|
|
$this->assign('privacy_desc_list', $privacy_desc);
|
|
$this->assign('info', $getInfo);
|
|
return $this->fetch('weapp/conceal', [], $this->replace);
|
|
}
|
|
|
|
/***
|
|
* 申请接口
|
|
* @return array|mixed
|
|
*/
|
|
public function apply_interface()
|
|
{
|
|
$open_platform_model = new OpenPlatform($this->site_id);
|
|
$def = [
|
|
'wx.chooseLocation' => '为客户提供快捷导航到店铺所在地',
|
|
'wx.chooseAddress' => '为客户快速填写配送地址提供便利',
|
|
'wx.choosePoi' => '获取用户地理位置为用户提供就近服务商级产品',
|
|
'wx.getLocation' => '获取用户地理位置为用户提供就近自提点位置',
|
|
'wx.onLocationChange' => '因业务涉及配送服务,需获取用户地理位置信息',
|
|
'wx.startLocationUpdateBackground' => '',
|
|
'wx.startLocationUpdate' => '',
|
|
'wx.getFuzzyLocation' => '',
|
|
];
|
|
$status = [
|
|
1 => '待申请开通',
|
|
2 => '无权限',
|
|
3 => '申请中',
|
|
4 => '申请失败',
|
|
5 => '已开通',
|
|
];
|
|
if (request()->isAjax()) {
|
|
$api_name = input('api_name');
|
|
$lists = input('status');
|
|
$pic_list = [
|
|
'wx.chooseAddress' => [],
|
|
'wx.getLocation' => [],
|
|
'wx.choosePoi' => [],
|
|
];
|
|
foreach ($lists as $key => $val) {
|
|
if ($val != 5 && $api_name[$key]) {
|
|
$pic_list = [];
|
|
$setInfo = $open_platform_model->setPrivacyInterface($key, $api_name[$key]);
|
|
}
|
|
}
|
|
$arr = [
|
|
'code' => 0,
|
|
'message' => '设置成功'
|
|
];
|
|
return $arr;
|
|
}
|
|
$Interface = $open_platform_model->getPrivacyInterface();
|
|
if (isset($Interface['interface_list'])) {
|
|
foreach ($Interface['interface_list'] as &$item) {
|
|
$item['is_must'] = 1;
|
|
if ($item['api_name'] == 'wx.onLocationChange') {
|
|
$item['is_must'] = 0;
|
|
}
|
|
$item['content'] = $def[$item['api_name']];
|
|
$item['status_desc'] = $status[$item['status']];
|
|
}
|
|
$this->assign('interface_list', $Interface['interface_list']);
|
|
}
|
|
$this->assign('status', $status);
|
|
return $this->fetch('weapp/interface', [], $this->replace);
|
|
}
|
|
|
|
|
|
/****
|
|
* 小程序在线认证
|
|
* @return void
|
|
*/
|
|
public function authentication()
|
|
{
|
|
$open_platform_model = new OpenPlatform($this->site_id);
|
|
if (request()->isAjax()) {
|
|
$config_model = new ConfigModel();
|
|
$postData=input('post.');
|
|
unset($postData['file']);
|
|
|
|
|
|
|
|
var_dump($postData);die;
|
|
}
|
|
$basicResult = $open_platform_model->getAccountBasicinfo($this->site_id);
|
|
$this->assign('basic', $basicResult);
|
|
return $this->fetch('weapp/authentication', [], $this->replace);
|
|
}
|
|
|
|
|
|
/***
|
|
* 上传图片
|
|
* @return array|bool|mixed|\multitype|string
|
|
*/
|
|
public function image()
|
|
{
|
|
// 获取表单上传文件
|
|
$file = request()->file('file');
|
|
$file = new Upload($this->site_id);
|
|
$tmp_name = $file->setPath("certificates/")->image(['name' => 'file', 'ext' => 'jpg,png'], false);
|
|
$file_path = $tmp_name['data']['pic_path'];
|
|
$tmp_file = app()->getRootPath() . $file_path;
|
|
$open_platform_model = new OpenPlatform($this->site_id);
|
|
$result = $open_platform_model->uploadImage($tmp_file);
|
|
$result['data']['pic_path'] = $file_path;
|
|
return $result;
|
|
}
|
|
}
|