admin/addon/saasagent/shop/controller/Mincode.php

347 lines
15 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* SAAS应用系统 --- 十年开发经验汇集巨献!
* ==========================================================
* Copy right 2020-2050 成都众联思索科技有限公司,保留所有权利。
* ----------------------------------------------------------
* 官方网址: https://www.zoomtk.com
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
* 任何企业和个人未经允许对程序代码以任何形式任何目的再发布传播。
* 唯一发布渠道www.zoomtk.com;非官方渠道统一视为侵权行为。
* ==========================================================
*/
namespace addon\saasagent\shop\controller;
use addon\weapp\model\Config as WeappConfigModel;
use addon\saasagent\model\WeappletReg;
use app\model\system\Site;
use app\model\web\WebSite as WebsiteModel;
use think\facade\Db;
class Mincode extends SaasBsae
{
protected $replace = []; //视图输出字符串内容替换相当于配置文件中的'view_replace_str'
public function __construct()
{
parent::__construct();
$this->replace = [
'WEAPP_CSS' => __ROOT__ . '/addon/weapp/admin/view/public/css',
'WEAPP_JS' => __ROOT__ . '/addon/weapp/admin/view/public/js',
'WEAPP_IMG' => __ROOT__ . '/addon/weapp/admin/view/public/img',
'WEAPP_SVG' => __ROOT__ . '/addon/weapp/admin/view/public/svg',
];
}
public $statemsg = [
-1 => '企业与法人姓名不一致',
0 => '已完成认证',
1 => '已提交申请 待认证',
101 => '工商数据返回:企业已注销',
102 => '工商数据返回:企业不存在或企业信息未更新',
103 => '工商数据返回:企业法定代表人姓名不一致',
104 => '工商数据返回:企业法定代表人身份证号码不一致',
105 => '法定代表人身份证号码,工商数据未更新,请 5-15 个工作日之后尝试',
1000 => '工商数据返回:企业信息或法定代表人信息不一致',
1001 => '主体创建小程序数量达到上限',
1002 => '主体违规命中黑名单',
1003 => '管理员绑定账号数量达到上限',
1004 => '管理员违规命中黑名单',
1005 => '管理员手机绑定账号数量达到上限',
1006 => '管理员手机号违规命中黑名单',
1007 => '管理员身份证创建账号数量达到上限',
1008 => '管理员身份证违规命中黑名单',
89252 => '法人&企业信息一致性校验中',
89247 => '系统繁忙',
86004 => '无效微信号',
61070 => '法人姓名与微信号不一致',
89248 => '企业代码类型无效,请选择正确类型填写',
89253 => '缺少参数',
89254 => '第三方权限集不全,补全权限集全网发布后生效',
89255 => '企业代码参数无效,请检查企业代码长度以及内容是否正确 ',
89251 => '待法人人脸核身校验',
89249 => '该主体已有任务执行中,距上次任务 24h 后再试',
100001 => '已下发的模板消息法人并未确认且已超时24h未进行身份证校验',
100002 => '已下发的模板消息法人并未确认且已超时24h未进行人脸识别校验',
100003 => '已下发的模板消息法人并未确认且已超时24h',
];
/***
* 小程序列表
* @return mixed
*/
public function list()
{
if (request()->isAjax()) {
$apply_model = new WeappletReg();
$search_text = input('search_text', '');
$page = input('page', 1);
$page_size = input('page_size', PAGE_LIST_ROWS);
$condition[] = ['ag_site_id', '=', $this->site_id];
if ($search_text) {
$condition[] = ['name|component_phone|legal_persona_name', 'like', '%' . $search_text . '%'];
}
$res = $apply_model->getPageList($condition, $page, $page_size);
return $res;
}
// $website_model = new WebsiteModel();
// $agent_info=$website_model->getWebSite(['website_pid'=>$this->site_id,'is_agent'=>1],'agent_arrears,agent_number',false)['data'];
$this->forthMenu();
// $this->assign('agentInfo',$agent_info);
return $this->fetch('mini/list');
}
public function onlinebuy()
{
return $this->fetch('mini/onlinebuy');
}
public function miniauth()
{
if (request()->isAjax()) {
$url = addon_url('aliapp/shop/auth/authinfo');
$ag_site_id = $this->site_id;
$site_id = input('site_id');
$order_id = input('order_id','');
$text = $site_id . '|minapp|' . $ag_site_id.'|'.$order_id;
$config_info = config('alipay.platform');
$state = url_safe_base64_encode($text);
cache($state, 'no');
$data = [
'isvAppId' => $config_info['appid'],
'auth_url' => $url,
'state' => $state,
];
return success(0, '', $data);
}
$site_id = input('site_id', 0);
$siteInfo = [];
if ($site_id) {
$condition[] = ['site_id', '=', $site_id];
$shop_model = new Site();
$siteInfo = $shop_model->getSiteInfo($condition, '*')['data'];
}
$this->assign('siteInfo', $siteInfo);
$this->assign('order_id', input('order_id',''));
return $this->fetch('mini/aliapp_auth');
}
public function authState()
{
if (request()->isAjax()) {
$state = input('state');
$is_auth = cache($state);
return success(0, '', $is_auth);
}
}
/***
* 删除注册
* @param $id
*/
public function delcode()
{
$id = input('id');
if ($id && request()->isAjax()) {
$apply_model = new WeappletReg();
$wehere = [
'id' => $id,
'agent_site_id' => $this->site_id,
'status' => ['>', 1],
];
$res = $apply_model->where($wehere)->delete();
$info['code'] = -1;
$info['message'] = '认证中或无权限';
if ($res) {
$info['code'] = 0;
$info['message'] = '删除成功';
}
return $info;
}
}
/***
* 注册小程序
* @return array|mixed
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function codereg()
{
$id = input('id', 0);
if (request()->isAjax()) {
// if($this->agent_info['is_fee']==0&&$this->agent_info['agent_arrears']<=0){
// $post['code']=-1;
// $post['message']='您已欠费!无法完成本次注册';
// return $post;
// }
$weapp_model = new \addon\wxoplatform\model\Oplatform();
$this->openPlatform = $weapp_model->app;
$openPlatform = $this->openPlatform->component;
$data = request()->post();
$mobile = $data['component_phone'];
$data['component_phone'] = $mobile;
$post = $openPlatform->registerMiniProgram($data);
if ($post['errcode'] == 0) {
$data['agent_site_id'] = $this->site_id;
$data['create_time'] = time();
$data['update_time'] = time();
$data['component_phone'] = $mobile;
$uid = input('uid', 0);
if ($uid) {
$data['site_id'] = $uid;
}
if ($id) {
$data['status'] = 1;
Db::name('weapplet_reg')->where(['id' => $id])->update($data);
} else {
model('weapplet_reg')->add($data);
}
$post['message'] = '提交成功';
} else {
$post['code'] = -1;
$post['message'] = $this->statemsg[$post['errcode']] ?? '系统繁忙' . $post['errcode'];
}
return $post;
}
$reginfo = Db::name('applet_list')->where(['id' => $id])->order('id desc')->find();
$is_reg = 1;
if ($reginfo) {
$reginfo['status_msg'] = $this->statemsg[$reginfo['status']];
if (in_array($reginfo['status'], [0, 1])) {
$is_reg = 0;
}
}
$this->assign('is_reg', $is_reg);
$this->assign('reginfo', $reginfo);
return $this->fetch('mini/wxcode_reg', [], $this->replace);
}
public function aliappreg()
{
$id = input('id', 0);
$cloud_order_id = input('order_id', 0);
$business_code = input('business_code');
if (request()->isAjax()) {
$info = request()->post();
$data = [
'app_type' => 'aliapp',
'site_id' => input('site_id', 2),
'ag_site_id' => $this->site_id,
'business_code' => $business_code,
'cloud_order_id' => $cloud_order_id,
'corporate_type' => $info['code_type'],
'app_name' => $info['app_name'],
'cert_no' => $info['cert_no'],
'alipay_account' => $info['alipay_account'],
'corporate_name' => $info['cert_name'],
'legal_persona_name' => $info['legal_personal_name'],
'contact_phone' => $info['contact_phone'],
'contact_name' => $info['contact_name'],
];
$miniModel = new \addon\aliapp\model\MinCode();
$license_pic = base64_encode(file_get_contents($info['license_pic']));
$bizParams = [
'create_mini_request' => [
'out_order_no' => $business_code, // 开发者外部订单号
'alipay_account' => $info['alipay_account'], // 商家登录支付宝的邮箱帐号或手机号
'legal_personal_name' => $info['legal_personal_name'],// 商家法人名称
'cert_name' => $info['cert_name'],// 营业执照企业名称,如果是“无主体名称个体工商户”则填“个体户+法人姓名”,例如“个体户张三”
'cert_no' => $info['cert_no'],// 营业执照编码
'app_name' => $info['app_name'], // 小程序名称
'contact_phone' => $info['contact_phone'], // 商家联系人手机电话
'contact_name' => $info['contact_name'], // 商家联系人名称
'is_individual' => true, //是否支持个体工商户的账号类型
'license_pic' => $license_pic, // 营业执照图片的Base64编码字符串图片大小不能超过2M。
]
];
$res = $miniModel->MiniCreate($bizParams);
if ($res['code'] == '10000') {
$info['order_no'] = $res['order_no'];
$data['status'] = 'reg';
$res['message'] = '注册成功';
if($cloud_order_id){
Db::name('cloud_order')->where('id','=',$cloud_order_id)->update(['order_status'=>1]);
}
} else {
$res['message'] = $res['sub_msg'];
}
$data['update_time'] = time();
$data['value'] = json_encode($info);
$code = Db::name('applet_list')->where('business_code', '=', $business_code)->value('id');
if ($code) {
Db::name('applet_list')->where('business_code', '=', $business_code)->update($data);
} else {
$data['user_type'] = 'platform'; //平台注册
$data['create_time'] = time();
Db::name('applet_list')->insert($data);
}
return $res;
}
if ($id) {
$reginfo = Db::name('applet_list')
->where(['id' => $id])
->find();
if ($reginfo) {
$reginfo['status_msg'] = $this->statemsg[$reginfo['status']];
if (in_array($reginfo['status'], [0, 1])) {
$is_reg = 0;
}
}
}
$auth_value = [];
$order_info = [];
if ($cloud_order_id) {
$field = 'a.*,app.app_type,app.app_name,app.cert_no,app.corporate_name,app.legal_persona_name,app.legal_persona_name,app.contact_phone,app.contact_name,app.contact_name,app.value,app.alipay_account,app.corporate_type';
$order_info = Db::name('cloud_order')
->where('a.id', '=', $cloud_order_id)
->alias('a')
->join('applet_list app', 'a.id=app.cloud_order_id', 'left')
->json(['auth_value', 'raw_data', 'value'], true)
->field($field)
->find();
$auth_value = $order_info['auth_value'];
$auth_value['business_code'] = $order_info['third_order_id'];
$regInfo = $order_info['value'];
$order_info['license_pic'] = $regInfo['license_pic'] ?? '';
$order_info['cert_no'] = $regInfo['cert_no'] ?? '';
$order_info['cert_name'] = $regInfo['cert_name'] ?? '';
$order_info['legal_personal_name'] = $regInfo['legal_personal_name'] ?? '';
}
$this->assign('info', $order_info);
$this->assign('authInfo', $auth_value);
return $this->fetch('mini/aliapp_reg', [], $this->replace);
}
/***
* 绑定小程序店铺
* @return mixed
*/
public function bingShop()
{
$id = input('id');
if (request()->isAjax()) {
$regInfo = Db::name('weapplet_reg')->where(['id' => $id])->order('id desc')->find();
$info['message'] = '小程序未认证通过';
if ($regInfo['status'] > 0) return $info;
$site_id = input('site_id');
if ($site_id) {
$weapp_config_model = new WeappConfigModel();
$wxinfo = $weapp_config_model->getWeappConfig($site_id)['data']['value'];
$info['message'] = '请登录商家平台设置';
if ($wxinfo) return $info;
$data = json_decode($regInfo['auth_info'], true);
$res = $weapp_config_model->setWeappConfig($data, 1, $site_id);
$info['message'] = '绑定成功';
return $info;
}
}
return $this->fetch('mini/bingshop');
}
}