Browse Source

Merge branch 'master' of ssh://8.134.10.79:222/Leadfyy.co/hainan

master
lemon 4 years ago
parent
commit
9c3b8f1f6b
  1. 363
      MySQL_change.sql
  2. 2
      app/Admin/Controllers/MiniProgramTemplateController.php
  3. 31
      app/Admin/Extensions/Grid/MiniProgramAuditStatus.php
  4. 35
      app/Admin/Extensions/Grid/MiniProgramReg.php
  5. 24
      app/Admin/Extensions/Grid/MiniProgramUpload.php
  6. 2
      app/AdminAgent/Controllers/OrderController.php
  7. 9
      app/AdminSupplier/Controllers/OrderController.php
  8. 7
      app/AdminSupplier/Extensions/Grid/ChangeOrderStatus.php
  9. 9
      app/Exceptions/Handler.php
  10. 10
      app/Http/Controllers/Api/AgentProductController.php
  11. 35
      app/Http/Controllers/Api/MiniProgramController.php
  12. 12
      app/Http/Controllers/Api/TestController.php
  13. 5
      app/Models/AgentProduct.php
  14. 93
      app/Service/OpenPlatform.php

363
MySQL_change.sql

@ -1,363 +0,0 @@
# 10:47 2021/8/17
ALTER TABLE `categories`
CHANGE COLUMN `template` `template` VARCHAR(50) NOT NULL DEFAULT '' COMMENT '产品模板' COLLATE 'utf8_general_ci' AFTER `sort`;
# 12:47 2021/8/17
ALTER TABLE `users`
CHANGE COLUMN `mobile` `mobile` VARCHAR(15) NOT NULL DEFAULT '' COMMENT '手机号' COLLATE 'utf8mb4_unicode_ci' AFTER `id`;
# 18:09 2021/8/17
ALTER TABLE `agents`
ADD COLUMN `type` TINYINT NOT NULL DEFAULT '0' COMMENT '1、计调版旅行社;2、供应商旅行社;3、组团版旅行社' AFTER `remember_token`;
# 23:25 2021/08/17
ALTER TABLE `agent_products`
ADD COLUMN `guide_id` INT NOT NULL DEFAULT 0 COMMENT '绑定地接(组团版旅行社才能绑定)' AFTER `category_id`;
ALTER TABLE `agents`
CHANGE COLUMN `type` `type` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '1、计调版旅行社;2、供应商旅行社;3、组团版旅行社' AFTER `status`;
ALTER TABLE `agent_products`
ADD COLUMN `verifier` INT NOT NULL DEFAULT '0' COMMENT '核销人员的user_id' AFTER `status`,
CHANGE COLUMN `product_id` `product_id` INT(11) NOT NULL COMMENT '供应商产品ID,组合产品时为第一个ID' AFTER `agent_id`,
ADD COLUMN `product_ids` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '供应商产品ID,主要用于组合产品,可能会有多个ID' COLLATE 'utf8_general_ci' AFTER `product_id`;
ALTER TABLE `orders`
CHANGE COLUMN `product_id` `product_id` INT(11) NOT NULL COMMENT '供应商产品ID,组合产品时为第一个ID' AFTER `agent_product_id`,
ADD COLUMN `product_ids` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '供应商产品ID,主要用于组合产品,可能会有多个ID' COLLATE 'utf8_general_ci' AFTER `product_id`;
# 9:37 2021/8/18
ALTER TABLE `orders`
CHANGE COLUMN `paid_at` `paid_at` TIMESTAMP NULL DEFAULT NULL COMMENT '付款时间' AFTER `paid_money`,
CHANGE COLUMN `status` `status` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '订单状态,-1:已取消;0:待付款;1:已付订金/定金/首付款;2:已付全款;3:已付尾款;4:线下未支付;5:线下已支付;6:退款中;7:已退款;16:已完成;' AFTER `picture`,
CHANGE COLUMN `pay_type` `pay_type` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '支付方式,0:在线支付,1:线下支付,2:订金支付,3:定金支付,4:首款支付;5:追加/尾款支付;【注:订单生成后不应该再修改此项的值】' AFTER `status`;
# 11:27 2021/8/18
ALTER TABLE `agents`
ADD COLUMN `rate` FLOAT(10,2) NOT NULL DEFAULT 0 COMMENT '平台分成比率' AFTER `contact_phone`;
ALTER TABLE `suppliers`
ADD COLUMN `rate` FLOAT(10,2) NOT NULL DEFAULT '0.00' COMMENT '平台分成比率' AFTER `contact_phone`;
ALTER TABLE `guides`
ADD COLUMN `rate` FLOAT(10,2) NOT NULL DEFAULT '0.00' COMMENT '平台分成比率' AFTER `status`;
# 17:54 2021/8/18
ALTER TABLE `agent_products`
DROP INDEX `agent_id_product_id`,
ADD INDEX `agent_id_product_id` (`agent_id`, `product_id`);
# 18:03 2021/8/19
ALTER TABLE `advertisings`
CHANGE COLUMN `agent_id` `agent_id` INT(10) NOT NULL COMMENT '发布者ID' AFTER `id`,
ADD INDEX `agent_id` (`agent_id`);
# 0:01 ‎2021/‎08/‎20
ALTER TABLE `orders`
ADD COLUMN `guide_id` INT NOT NULL DEFAULT '0' COMMENT '地接ID' AFTER `refund_info`,
ADD INDEX `guide_id` (`guide_id`);
# 14:27 2021/8/20
ALTER TABLE `orders`
CHANGE COLUMN `status` `status` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '订单状态,-1:已取消;0:待付款;1:已付订金/定金/首付款;2:已付全款;3:已付尾款;4:线下未支付;5:线下已支付;6:退款中;7:已退款;8:拒绝退款;16:已完成;' AFTER `picture`,
CHANGE COLUMN `refund_info` `refund_info` TEXT NULL DEFAULT NULL COMMENT '退款信息["desc":"退款说明","refund_no":"退款号,用于微信申请退款","pictures":"退款图片凭据","old_status":"申请退款前的订单状态"]' COLLATE 'utf8_general_ci' AFTER `paid_at`;
ALTER TABLE `user_money_logs`
ADD INDEX `agent_id` (`agent_id`);
CREATE TABLE `agent_product_items` (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`agent_product_id` INT(10) NOT NULL,
`agent_id` INT(10) NOT NULL,
`supplier_id` INT(10) NOT NULL,
`product_id` INT(10) NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `agent_product_id` (`agent_product_id`) USING BTREE,
INDEX `agent_id` (`agent_id`) USING BTREE,
INDEX `supplier_id` (`supplier_id`) USING BTREE,
INDEX `product_id` (`product_id`) USING BTREE
)
COMMENT='代理商产品-组合产品明细'
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;
ALTER TABLE `agent_products`
ADD COLUMN `stock` INT(10) NOT NULL DEFAULT '0' COMMENT '库存' AFTER `sale`;
# 10:42 ‎2021/‎08/‎21
ALTER TABLE `orders`
CHANGE COLUMN `order_no` `order_no` CHAR(22) NOT NULL COMMENT '订单号' COLLATE 'utf8_general_ci' AFTER `agent_id`;
ALTER TABLE `orders`
ADD COLUMN verify_code CHAR(13) NOT NULL DEFAULT '' COMMENT '核销码' AFTER `guide_id`;
# 10:35 ‎2021/‎08/‎22
ALTER TABLE `slides`
CHANGE COLUMN `url` `picture` VARCHAR(255) NOT NULL COMMENT '轮播图地址' COLLATE 'utf8_general_ci' AFTER `title`,
ADD COLUMN `type` TINYINT NOT NULL DEFAULT '0' COMMENT '链接类型,0:链接到内部页面;1:链接到webview url' AFTER `sort`,
ADD COLUMN `url` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '链接地址' AFTER `type`;
# 23:43 ‎2021/‎08/‎22
CREATE TABLE `waterfall_ads` (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`agent_id` INT(10) NOT NULL COMMENT '代理商ID',
`title` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '广告名称' COLLATE 'utf8_general_ci',
`picture` VARCHAR(255) NOT NULL COMMENT '广告图片' COLLATE 'utf8_general_ci',
`type` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '链接类型,0:链接到内部页面;1:链接到外部url',
`url` VARCHAR(50) NOT NULL COMMENT '链接' COLLATE 'utf8_general_ci',
`status` TINYINT(3) NOT NULL DEFAULT '1' COMMENT '0:未启用,1:启用',
`sort` SMALLINT(5) NOT NULL DEFAULT '255' COMMENT '排序,越小越靠前',
`created_at` TIMESTAMP NULL DEFAULT NULL,
`updated_at` TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `agent_id` (`agent_id`) USING BTREE
)
COMMENT='瀑布流内嵌广告'
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
# 12:39 2021/8/24
ALTER TABLE `notices`
ADD COLUMN `sort` SMALLINT NOT NULL DEFAULT '255' COMMENT '排序,越小越靠前' AFTER `content`;
ALTER TABLE `users`
CHANGE COLUMN `verifier` `is_verify` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '是否是核销人员,1:是;0:否' AFTER `status`;
# 15:51 2021/8/24
ALTER TABLE `articles`
ADD COLUMN `type` TINYINT NOT NULL DEFAULT 0 COMMENT '0:普通列表显示;1:大图显示;' AFTER `content`,
ADD COLUMN `sort` SMALLINT NOT NULL DEFAULT 255 COMMENT '排序,越小越靠前' AFTER `type`;
# 18:16 2021/8/24
ALTER TABLE `slides`
COMMENT='广告图、轮播图等';
RENAME TABLE `slides` TO `advertisings`;
# 23:05 ‎2021/‎08/‎24
ALTER TABLE `advertisings`
CHANGE COLUMN `agent_id` `agent_id` INT(11) NOT NULL COMMENT '发布者ID' AFTER `id`,
ADD COLUMN `display` TINYINT NOT NULL DEFAULT 0 COMMENT '显示位置,0:轮播图;1:首页横屏广告;2:瀑布流内嵌广告;' AFTER `url`;
# 23:56 ‎2021/‎08/‎24
ALTER TABLE `agent_products`
ADD INDEX `sale` (`sale`),
ADD INDEX `category_id` (`category_id`);
# 0:24 ‎2021/‎08/‎25
ALTER TABLE `specials`
DROP COLUMN `picture_ad`;
# 14:15 2021/8/25
ALTER TABLE `messages`
DROP COLUMN `is_read`;
CREATE TABLE `message_reads` (
`id` INT(10) NOT NULL COMMENT '消息ID,message_id',
`user_id` INT(10) NOT NULL COMMENT '用户ID,user_id',
PRIMARY KEY (`id`, `user_id`) USING BTREE
)
COMMENT='消息已读状态记录,如果含有记录,说明已读,否则未读'
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;
# 14:34 2021/8/25
ALTER TABLE `agent_products`
ADD COLUMN `is_rec` TINYINT NOT NULL DEFAULT 0 COMMENT '是否推荐,推荐后在我的下文显示,0:未推荐;1:推荐;' AFTER `verifier`;
# 16:35 2021/8/25
ALTER TABLE `agent_products`
ADD COLUMN `type` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '0:单品销售;1:组合销售;' AFTER `is_rec`,
ADD COLUMN `title` VARCHAR(255) NOT NULL COMMENT '标题' COLLATE 'utf8_general_ci' AFTER `type`,
ADD COLUMN `pictures` TEXT NOT NULL COMMENT '产品图片,可能有多张,JSON格式' COLLATE 'utf8_general_ci' AFTER `title`,
ADD COLUMN `know` TEXT NULL DEFAULT NULL COMMENT '旅客须知' COLLATE 'utf8_general_ci' AFTER `pictures`,
ADD COLUMN `content` MEDIUMTEXT NULL DEFAULT NULL COMMENT '产品详情' COLLATE 'utf8_general_ci' AFTER `know`;
# 11:07 2021/8/26
DROP TABLE `waterfall_ads`;
# 19:25 2021/8/26
CREATE TABLE `pay_debugs` (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`agent_id` INT(10) NOT NULL DEFAULT '0' COMMENT '代理商ID',
`type` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '1:支付;2:退款;',
`content` TEXT NULL DEFAULT NULL COMMENT '回调内容' COLLATE 'utf8_general_ci',
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) USING BTREE,
INDEX `agent_id` (`agent_id`) USING BTREE
)
COMMENT='微信支付回调记录'
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
CREATE TABLE `agent_settings` (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`agent_id` INT(10) NOT NULL COMMENT '代理商ID',
`setting` JSON NOT NULL COMMENT '设置值,JSON格式',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `agent_id` (`agent_id`) USING BTREE
)
COMMENT='代理商设置配置'
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
# 15:19 2021/8/27
ALTER TABLE `messages`
ADD COLUMN `author` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '作者' COLLATE 'utf8_general_ci' AFTER `content`;
ALTER TABLE `notices`
ADD COLUMN `author` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '作者' COLLATE 'utf8_general_ci' AFTER `sort`;
ALTER TABLE `articles`
ADD COLUMN `agent_product_ids` TEXT NULL DEFAULT NULL COMMENT '绑定产品' AFTER `sort`;
# 9:28 2021/8/30
ALTER TABLE `agent_products`
ADD COLUMN `deposit` DECIMAL(20,2) NOT NULL DEFAULT 0 COMMENT '订金' AFTER `content`,
ADD COLUMN `deposit_timeout` INT NOT NULL DEFAULT 0 COMMENT '订金支付超时时间,单位:分钟' AFTER `deposit`,
ADD COLUMN `earnest` DECIMAL(20,2) NOT NULL DEFAULT '0' COMMENT '定金' AFTER `deposit_timeout`,
ADD COLUMN `earnest_timeout` INT NOT NULL DEFAULT 0 COMMENT '定金支付超时时间,单位:分钟' AFTER `earnest`;
# 10:58 2021/8/30
ALTER TABLE `orders`
ADD COLUMN `timeout` TIMESTAMP NULL DEFAULT NULL COMMENT '订单超时时间,超过这个时间,订单将变为“已取消”' AFTER `verify_code`;
#################################################################
# 23:53 ‎2021/‎08/‎31
CREATE TABLE `order_product_items` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`order_id` INT(11) NOT NULL COMMENT '订单ID',
`agent_id` INT(11) NOT NULL COMMENT '代理商ID',
`agent_product_id` INT(11) NOT NULL COMMENT '代理商产品ID',
`supplier_id` INT(11) NOT NULL COMMENT '供应商ID',
`product_id` INT(11) NOT NULL COMMENT '供应商产品ID',
PRIMARY KEY (`id`) USING BTREE,
INDEX `order_id_supplier_id` (`order_id`, `supplier_id`) USING BTREE
)
COMMENT='订单对应产品表'
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
# 15:44 2021/9/2
ALTER TABLE `order_product_items`
ADD COLUMN `num` INT(10) NOT NULL COMMENT '购买数量' AFTER `product_id`,
ADD COLUMN `price` DECIMAL(20,2) NOT NULL COMMENT '销售价格' AFTER `num`;
# 16:42 2021/9/2
ALTER TABLE `agent_products`
CHANGE COLUMN `type` `type` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '0:单品销售;1:组合销售;2:组团旅行社的云产品;' AFTER `is_rec`,
ADD COLUMN `is_cloud` TINYINT NOT NULL DEFAULT 0 COMMENT '是否是(组团旅行社特有)云产品,。0:否;1:是;' AFTER `earnest_timeout`,
ADD COLUMN `agent_cloud_pid` INT(10) NOT NULL DEFAULT '0' COMMENT '组团版旅行社的云产品ID' AFTER `is_cloud`,
ADD INDEX `agent_cloud_pid` (`agent_cloud_pid`);
UPDATE `agent_products` ap SET `is_cloud`=1 WHERE EXISTS(SELECT 1 FROM `agents` WHERE `id`=ap.`agent_id` AND `type`=3);
# 18:15 2021/9/3
ALTER TABLE `orders`
ADD COLUMN `agent_cloud_pid` INT NOT NULL DEFAULT 0 COMMENT '组团云产品ID' AFTER `verify_code`,
ADD COLUMN `agent_cloud_price` DECIMAL(20,2) NOT NULL DEFAULT '0' COMMENT '组团云产品销售价格' AFTER `agent_cloud_pid`,
ADD INDEX `agent_cloud_pid` (`agent_cloud_pid`);
# 9:26 2021/9/6
ALTER TABLE `user_money_logs`
ADD COLUMN `out_trade_no` CHAR(24) NOT NULL DEFAULT '' COMMENT '发起支付时传给微信的订单号(格式:order_no-status)' AFTER `transaction_id`;
# 11:40 2021/9/6
ALTER TABLE `products`
CHANGE COLUMN `status` `status` TINYINT(3) NOT NULL DEFAULT '1' COMMENT '-2:下架,-1:审核拒绝,0:未审核,1:上架' AFTER `sale`;
ALTER TABLE `agent_products`
CHANGE COLUMN `status` `status` TINYINT(3) NOT NULL DEFAULT '1' COMMENT '-2:下架,-1:审核拒绝,0:未审核,1:上架' AFTER `guide_id`;
# 10:40 2021/9/7
ALTER TABLE `products`
ADD COLUMN `type` TINYINT NOT NULL DEFAULT 0 COMMENT '0:旅游线路、1:洒店、2:景区、3:餐厅、4:车队、5:单项' AFTER `category_id`,
ADD COLUMN `extends` JSON NULL DEFAULT NULL COMMENT '扩展字段,根据type不同,字段名不同' AFTER `verify_mobile`;
ALTER TABLE `suppliers`
ADD COLUMN `public_type` VARCHAR(255) NOT NULL DEFAULT '[]' COMMENT '允许发布产品的模板' AFTER `rate`;
# 9:39 2021/9/8
ALTER TABLE `suppliers`
CHANGE COLUMN `public_type` `publish_type` VARCHAR(255) NOT NULL DEFAULT '[]' COMMENT '允许发布产品的模板' COLLATE 'utf8_general_ci' AFTER `rate`;
# 15:19 2021/9/9
ALTER TABLE `orders`
ADD COLUMN `pay_user_id` INT NOT NULL DEFAULT 0 COMMENT '支付用户的user_id(跳转到外部小程序支付时用到)' AFTER `agent_cloud_price`;
# 18:47 2021/9/11
ALTER TABLE `agents`
CHANGE COLUMN `appid` `appid` VARCHAR(30) NULL COMMENT '微信AppID' COLLATE 'utf8_general_ci' AFTER `remember_token`,
CHANGE COLUMN `appsecret` `appsecret` CHAR(32) NULL COMMENT '微信AppSecret' COLLATE 'utf8_general_ci' AFTER `appid`,
CHANGE COLUMN `mchid` `mchid` VARCHAR(32) NULL COMMENT '微信支付mch_id' COLLATE 'utf8_general_ci' AFTER `appsecret`,
CHANGE COLUMN `mchkey` `mchkey` CHAR(32) NULL COMMENT '微信支付key' COLLATE 'utf8_general_ci' AFTER `mchid`;
CREATE TABLE `mini_program_drafts` (
`draft_id` INT(10) NOT NULL COMMENT '腾讯开放平台的草稿ID',
`user_version` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '版本号' COLLATE 'utf8_general_ci',
`user_desc` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '描述' COLLATE 'utf8_general_ci',
`source_miniprogram_appid` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '模板小程序APPID' COLLATE 'utf8_general_ci',
`source_miniprogram` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '来源小程序' COLLATE 'utf8_general_ci',
`developer` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '开发者' COLLATE 'utf8_general_ci',
`create_time` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '草稿创建时间',
`is_create_template` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '是否已创建模板,0:否,1:是',
PRIMARY KEY (`draft_id`) USING BTREE
)
COMMENT='第三方平台草稿列表'
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
CREATE TABLE `mini_program_events` (
`id` BIGINT(19) NOT NULL AUTO_INCREMENT,
`type` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '0:授权事件接收;1:消息与事件接收',
`response` TEXT NULL DEFAULT NULL COMMENT '所有请求信息' COLLATE 'utf8mb4_bin',
`event` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb4_bin',
`appid` VARCHAR(50) NULL DEFAULT NULL COMMENT 'msg_event时才会记录' COLLATE 'utf8mb4_bin',
`created_at` TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
)
COMMENT='第三方平台事件接收记录'
COLLATE='utf8mb4_bin'
ENGINE=InnoDB;
CREATE TABLE `mini_program_templates` (
`template_id` INT(10) NOT NULL,
`user_version` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '版本号' COLLATE 'utf8_general_ci',
`user_desc` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '描述' COLLATE 'utf8_general_ci',
`source_miniprogram_appid` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '来源小程序' COLLATE 'utf8_general_ci',
`source_miniprogram` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '模板小程序APPID' COLLATE 'utf8_general_ci',
`developer` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '上传者微信昵称' COLLATE 'utf8_general_ci',
`template_type` INT(10) NOT NULL DEFAULT '0' COMMENT '模板ID',
`create_time` INT(10) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`template_id`) USING BTREE
)
COMMENT='第三方平台模板列表'
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
CREATE TABLE `mini_program_upload_logs` (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`agent_id` INT(10) NOT NULL COMMENT '代理商ID',
`appid` VARCHAR(50) NOT NULL COMMENT '代理商APPID' COLLATE 'utf8_general_ci',
`user_version` VARCHAR(20) NOT NULL COMMENT '版本号' COLLATE 'utf8_general_ci',
`template_id` INT(10) NOT NULL COMMENT '小程序template_id',
`qrcode` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '小程序上传后获取到的二维码' COLLATE 'utf8_general_ci',
`audit_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0' COMMENT '审核ID',
`is_success` TINYINT(3) NOT NULL DEFAULT '-1' COMMENT '0:审核成功; 1:审核被拒绝; 2:审核中; 3:已撤回; 4:审核延后',
`created_at` TIMESTAMP NULL DEFAULT NULL,
`updated_at` TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `agent_id` (`agent_id`) USING BTREE
)
COMMENT='注册小程序日志'
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
# 9:29 2021/9/13
ALTER TABLE `agents`
ADD COLUMN `credit_codes` VARCHAR(50) NOT NULL DEFAULT '' COMMENT '统一社会信用代码' AFTER `company_name`,
ADD COLUMN `legal_persona_name` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '法人姓名' AFTER `contact_phone`,
ADD COLUMN `legal_persona_wechat` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '法人微信号' AFTER `legal_persona_name`;
# 17:02 2021/9/13
ALTER TABLE `user_money_logs`
CHANGE COLUMN `money` `money` DECIMAL(20,2) NOT NULL COMMENT '变动金额,正数=平台收入,负数=平台支出' AFTER `agent_id`;

2
app/Admin/Controllers/MiniProgramTemplateController.php

@ -29,7 +29,7 @@ class MiniProgramTemplateController extends AdminController
$grid->tools(new MiniProgramPull); $grid->tools(new MiniProgramPull);
$grid->column('template_id'); $grid->column('template_id');
// $grid->column('template_type')->using([0 => '普通模板', 1 => '标准模板']);
$grid->column('template_type')->using([0 => '普通模板', 1 => '标准模板']);
$grid->column('user_version'); $grid->column('user_version');
$grid->column('user_desc'); $grid->column('user_desc');
$grid->column('source_miniprogram'); $grid->column('source_miniprogram');

31
app/Admin/Extensions/Grid/MiniProgramAuditStatus.php

@ -1,12 +1,11 @@
<?php <?php
namespace App\Admin\Extensions\Grid; namespace App\Admin\Extensions\Grid;
use App\Models\AdminSetting;
use App\Models\Agent; use App\Models\Agent;
use App\Models\MiniProgramTemplate; use App\Models\MiniProgramTemplate;
use App\Models\MiniProgramUploadLog; use App\Models\MiniProgramUploadLog;
use App\Service\OpenPlatform;
use Dcat\Admin\Grid\RowAction; use Dcat\Admin\Grid\RowAction;
use EasyWeChat\Factory;
use EasyWeChat\Kernel\Exceptions\InvalidConfigException; use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code\Client; use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code\Client;
use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\GuzzleException;
@ -44,30 +43,22 @@ class MiniProgramAuditStatus extends RowAction
return $this->response()->error('该代理商未注册过小程序,请先注册'); return $this->response()->error('该代理商未注册过小程序,请先注册');
} }
$template_id = MiniProgramTemplate::max('template_id');
$log = MiniProgramUploadLog::where(['agent_id' => $agent->id, 'template_id' => $template_id])->orderBy('id', 'desc')->first();
// $template_id = MiniProgramTemplate::max('template_id');
$log = MiniProgramUploadLog::where(['agent_id' => $agent->id])->orderBy('id', 'desc')->first();
if (!$log) { if (!$log) {
return $this->response()->error('该代理商未上传及发布过最新版本的小程序'); return $this->response()->error('该代理商未上传及发布过最新版本的小程序');
} else if (!$log->audit_id){
} else if (!$log->audit_id) {
return $this->response()->error('未找到审核记录audit_id'); return $this->response()->error('未找到审核记录audit_id');
} }
try { try {
$setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']);
$config = [
'app_id' => $setting['service_appid'],
'secret' => $setting['service_appsecret'],
'token' => $setting['service_token'],
'aes_key' => $setting['service_aeskey'],
];
$openPlatform = Factory::openPlatform($config);
$refreshToken = $openPlatform->getAuthorizer($agent->appid)['authorization_info']['authorizer_refresh_token'] ?? null;
$openPlatform = new OpenPlatform();
$refreshToken = $openPlatform->refreshToken($agent->appid);
if (!$refreshToken) { if (!$refreshToken) {
return $this->response()->error('获取refresh_token失败'); return $this->response()->error('获取refresh_token失败');
} }
/** @var Client $code */ /** @var Client $code */
$code = $openPlatform->miniProgram($agent->appid, $refreshToken)['code'] ?? null;
$code = $openPlatform->code($agent->appid, $refreshToken);
if (!$code) { if (!$code) {
return $this->response()->error('获取code失败'); return $this->response()->error('获取code失败');
} }
@ -85,14 +76,14 @@ class MiniProgramAuditStatus extends RowAction
//发布结果处理 //发布结果处理
$releaseArr = [-1 => '系统繁忙', 85019 => '没有审核版本', 85020 => '审核状态未满足发布']; $releaseArr = [-1 => '系统繁忙', 85019 => '没有审核版本', 85020 => '审核状态未满足发布'];
if (isset($res_release['errcode'], $res_release['errmsg']) && $res_release['errcode'] == 0 && $res_release['errmsg'] == 'ok') { if (isset($res_release['errcode'], $res_release['errmsg']) && $res_release['errcode'] == 0 && $res_release['errmsg'] == 'ok') {
return $this->response()->success('审核成功且已发布')->refresh();
return $this->response()->success("模板ID {$log->template_id} 的小程序已审核成功且发布")->refresh();
} else if (isset($releaseArr[$res_release['errcode']])) { } else if (isset($releaseArr[$res_release['errcode']])) {
return $this->response()->success('审核成功,发布结果为:' . $releaseArr[$res_release['errcode']])->refresh();
return $this->response()->warning('审核成功,发布结果为:' . $releaseArr[$res_release['errcode']])->refresh();
} else { } else {
return $this->response()->success('审核成功,失败出错:' . join(',', $res_release))->refresh();
return $this->response()->warning('审核成功,但发布出错:' . join(',', $res_release))->refresh();
} }
} else if (isset($statusArr[$res['status']])) { } else if (isset($statusArr[$res['status']])) {
return $this->response()->success($statusArr[$res['status']])->refresh();
return $this->response()->warning($statusArr[$res['status']])->refresh();
} else { } else {
return $this->response()->error($res['reason'] ?? join(',', $res)); return $this->response()->error($res['reason'] ?? join(',', $res));
} }

35
app/Admin/Extensions/Grid/MiniProgramReg.php

@ -5,6 +5,7 @@ use App\Models\AdminSetting;
use App\Models\Agent; use App\Models\Agent;
use App\Models\MiniProgramTemplate; use App\Models\MiniProgramTemplate;
use App\Models\MiniProgramUploadLog; use App\Models\MiniProgramUploadLog;
use App\Service\OpenPlatform;
use Dcat\Admin\Grid\RowAction; use Dcat\Admin\Grid\RowAction;
use EasyWeChat\Factory; use EasyWeChat\Factory;
use EasyWeChat\OpenPlatform\Component\Client; use EasyWeChat\OpenPlatform\Component\Client;
@ -44,19 +45,11 @@ class MiniProgramReg extends RowAction
{ {
$agent = Agent::find($this->getKey()); $agent = Agent::find($this->getKey());
$setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey', 'service_component_phone']);
$config = [
'app_id' => $setting['service_appid'],
'secret' => $setting['service_appsecret'],
'token' => $setting['service_token'],
'aes_key' => $setting['service_aeskey'],
];
$openPlatform = Factory::openPlatform($config);
if (empty($openPlatform['component'])) {
return $this->response()->error('获取component失败,请检查配置信息是否正确');
$openPlatform = new OpenPlatform();
$component = $openPlatform->component();
if (empty($component)) {
return $this->response()->error('获取component失败');
} }
$component = $openPlatform['component'];
$res = $component->registerMiniProgram([ $res = $component->registerMiniProgram([
'name' => $agent->company_name, // 企业名 'name' => $agent->company_name, // 企业名
@ -64,7 +57,7 @@ class MiniProgramReg extends RowAction
'code_type' => 1, // 企业代码类型(1:统一社会信用代码, 2:组织机构代码,3:营业执照注册号) 'code_type' => 1, // 企业代码类型(1:统一社会信用代码, 2:组织机构代码,3:营业执照注册号)
'legal_persona_wechat' => $agent->legal_persona_wechat, // 法人微信 'legal_persona_wechat' => $agent->legal_persona_wechat, // 法人微信
'legal_persona_name' => $agent->legal_persona_name, // 法人姓名 'legal_persona_name' => $agent->legal_persona_name, // 法人姓名
'component_phone' => $setting['service_component_phone'], //第三方联系电话
'component_phone' => AdminSetting::val('service_component_phone'), //第三方联系电话
]); ]);
$errorArr = $this->regErrorCode(); $errorArr = $this->regErrorCode();
@ -88,20 +81,12 @@ class MiniProgramReg extends RowAction
} }
try { try {
$setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']);
$config = [
'app_id' => $setting['service_appid'],
'secret' => $setting['service_appsecret'],
'token' => $setting['service_token'],
'aes_key' => $setting['service_aeskey'],
];
$openPlatform = Factory::openPlatform($config);
if (empty($openPlatform['component'])) {
$openPlatform = new OpenPlatform();
/** @var Client $component */
$component = $openPlatform->component();
if (empty($component)) {
return $this->response()->error('获取component失败,请检查配置信息是否正确'); return $this->response()->error('获取component失败,请检查配置信息是否正确');
} }
/** @var Client $component */
$component = $openPlatform['component'];
$res = $component->getRegistrationStatus($agent->company_name, $agent->legal_persona_wechat, $agent->legal_persona_name); $res = $component->getRegistrationStatus($agent->company_name, $agent->legal_persona_wechat, $agent->legal_persona_name);
$errorArr = $this->searchErrorCode(); $errorArr = $this->searchErrorCode();

24
app/Admin/Extensions/Grid/MiniProgramUpload.php

@ -5,6 +5,7 @@ use App\Models\AdminSetting;
use App\Models\Agent; use App\Models\Agent;
use App\Models\MiniProgramTemplate; use App\Models\MiniProgramTemplate;
use App\Models\MiniProgramUploadLog; use App\Models\MiniProgramUploadLog;
use App\Service\OpenPlatform;
use Dcat\Admin\Grid\RowAction; use Dcat\Admin\Grid\RowAction;
use EasyWeChat\Factory; use EasyWeChat\Factory;
use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code\Client; use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code\Client;
@ -23,7 +24,7 @@ class MiniProgramUpload extends RowAction
public function __construct($title = null, $action = 1) public function __construct($title = null, $action = 1)
{ {
parent::__construct($title); parent::__construct($title);
$this->action = $action; //$action:1=为指定代理商上传小程序;2=批量上传小程序(一键分发小程序给所有代理商)
$this->action = $action; //$action:1=为指定代理商上传小程序;2=暂未确定
$this->title = $action == 1 ? '上传小程序' : '为所有代理商上传'; $this->title = $action == 1 ? '上传小程序' : '为所有代理商上传';
} }
@ -55,16 +56,8 @@ class MiniProgramUpload extends RowAction
} }
try { try {
$setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']);
$config = [
'app_id' => $setting['service_appid'],
'secret' => $setting['service_appsecret'],
'token' => $setting['service_token'],
'aes_key' => $setting['service_aeskey'],
];
$openPlatform = Factory::openPlatform($config);
$refreshToken = $openPlatform->getAuthorizer($agent->appid)['authorization_info']['authorizer_refresh_token'] ?? null;
$openPlatform = new OpenPlatform();
$refreshToken = $openPlatform->refreshToken($agent->appid);
if (!$refreshToken) { if (!$refreshToken) {
return $this->response()->error('获取refresh_token失败'); return $this->response()->error('获取refresh_token失败');
} }
@ -102,10 +95,6 @@ class MiniProgramUpload extends RowAction
//提交上传 //提交上传
$commit = $code->commit($templateId, $extJson, $version, $description); $commit = $code->commit($templateId, $extJson, $version, $description);
//获取体验二维码并保存
$qrcode = $code->getQrCode(storage_path("app/public/{$agent->id}-{$agent->appid}.jpg"));
Storage::put("public/mini_program_qrcode/{$agent->id}-{$agent->appid}.jpg", $qrcode);
if (!isset($commit['errcode'], $commit['errmsg']) || $commit['errcode'] != 0 || $commit['errmsg'] != 'ok') { if (!isset($commit['errcode'], $commit['errmsg']) || $commit['errcode'] != 0 || $commit['errmsg'] != 'ok') {
throw new \Exception(isset($commit['errmsg']) ? $commit['errmsg'] : join(',', $commit)); throw new \Exception(isset($commit['errmsg']) ? $commit['errmsg'] : join(',', $commit));
} }
@ -125,6 +114,11 @@ class MiniProgramUpload extends RowAction
'audit_id' => $res['auditid'], 'audit_id' => $res['auditid'],
'created_at' => now(), 'created_at' => now(),
]); ]);
//获取体验二维码并保存
$qrcode = $code->getQrCode(storage_path("app/public/{$agent->id}-{$agent->appid}.jpg"));
Storage::put("public/mini_program_qrcode/{$agent->id}-{$agent->appid}.jpg", $qrcode);
return $this->response()->success("上传成功,并已提交审核")->refresh(); return $this->response()->success("上传成功,并已提交审核")->refresh();
} else if (isset($audit_err_code[$res['errcode']])) { } else if (isset($audit_err_code[$res['errcode']])) {
throw new \Exception($audit_err_code[$res['errcode']]); throw new \Exception($audit_err_code[$res['errcode']]);

2
app/AdminAgent/Controllers/OrderController.php

@ -8,14 +8,12 @@ use App\AdminAgent\Repositories\Order;
use App\Common\OrderStatus; use App\Common\OrderStatus;
use App\Common\PayType; use App\Common\PayType;
use App\Models\OrderProductItem; use App\Models\OrderProductItem;
use App\Models\Supplier;
use Dcat\Admin\Admin; use Dcat\Admin\Admin;
use Dcat\Admin\Form; use Dcat\Admin\Form;
use Dcat\Admin\Grid; use Dcat\Admin\Grid;
use Dcat\Admin\Grid\Filter\AbstractFilter; use Dcat\Admin\Grid\Filter\AbstractFilter;
use Dcat\Admin\Show; use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController; use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Widgets\Dropdown;
use Dcat\Admin\Widgets\Table; use Dcat\Admin\Widgets\Table;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;

9
app/AdminSupplier/Controllers/OrderController.php

@ -6,7 +6,6 @@ use App\AdminSupplier\Repositories\Order;
use App\Common\OrderStatus; use App\Common\OrderStatus;
use App\Common\PayType; use App\Common\PayType;
use App\Models\Agent; use App\Models\Agent;
use App\Models\OrderProductItem;
use App\Models\Supplier; use App\Models\Supplier;
use Dcat\Admin\Admin; use Dcat\Admin\Admin;
use Dcat\Admin\Form; use Dcat\Admin\Form;
@ -96,10 +95,10 @@ class OrderController extends AdminController
$show->disableQuickEdit(); $show->disableQuickEdit();
$show->disableEditButton(); $show->disableEditButton();
//不允许查看非自己的数据,$show->model()->whereHas()不起作用?
if (!OrderProductItem::where(['order_id' => $show->model()->id, 'supplier_id' => Admin::user()->id])->exists()) {
Admin::exit('数据不存在');
}
//不允许查看非自己的数据 TODO 待筛选
$show->model()->whereHas('orderProductItem', function ($query) {
return $query->where('supplier_id', Admin::user()->id);
});
$show->field('id'); $show->field('id');
$show->field('agent.name'); $show->field('agent.name');

7
app/AdminAgent/Extensions/Grid/ChangeOrderStatus.php → app/AdminSupplier/Extensions/Grid/ChangeOrderStatus.php

@ -1,10 +1,11 @@
<?php <?php
namespace App\AdminAgent\Extensions\Grid;
namespace App\AdminSupplier\Extensions\Grid;
use App\Common\OrderStatus; use App\Common\OrderStatus;
use App\Models\Order; use App\Models\Order;
use Dcat\Admin\Admin; use Dcat\Admin\Admin;
use Dcat\Admin\Grid\RowAction; use Dcat\Admin\Grid\RowAction;
use Illuminate\Support\Facades\DB;
/** /**
* 改变订单状态 * 改变订单状态
@ -26,7 +27,9 @@ class ChangeOrderStatus extends RowAction
public function handle() public function handle()
{ {
try { try {
$order = Order::firstWhere(['id' => $this->getKey(), 'agent_id' => Admin::user()->id, 'status' => OrderStatus::OFFLINE_UNPAID]);
$order = Order::query()->whereHas('orderProductItem', function ($query) {
$query->where(['supplier_id' => Admin::user()->id, 'order_id' => $this->getKey()]);
})->firstWhere(['id' => $this->getKey(), 'status' => OrderStatus::OFFLINE_UNPAID]);
if (!$order) { if (!$order) {
return $this->response()->error("订单不存在或已处理过了")->refresh(); return $this->response()->error("订单不存在或已处理过了")->refresh();
} }

9
app/Exceptions/Handler.php

@ -36,11 +36,7 @@ class Handler extends ExceptionHandler
*/ */
public function register() public function register()
{ {
$this->reportable(function (Throwable $e) {
if ($this->shouldReport($e) && app()->bound('sentry')) {
app('sentry')->captureException($e);
}
});
//
} }
/** /**
@ -49,6 +45,9 @@ class Handler extends ExceptionHandler
*/ */
public function report(Throwable $e): bool public function report(Throwable $e): bool
{ {
if ($this->shouldReport($e) && app()->bound('sentry')) {
app('sentry')->captureException($e);
}
// 判断异常是否需要自定义报告... // 判断异常是否需要自定义报告...
return false; return false;
} }

10
app/Http/Controllers/Api/AgentProductController.php

@ -60,7 +60,7 @@ class AgentProductController extends Controller
// TODO 优惠券查询待优化 // TODO 优惠券查询待优化
$agent_product = AgentProduct::query() $agent_product = AgentProduct::query()
->with(['coupon:tag,agent_product_id', 'fav:agent_product_id'])
->with(['coupon:tag,agent_product_id'])
->whereDoesntHave('agentProductItem', function ($query) { ->whereDoesntHave('agentProductItem', function ($query) {
return $query->whereHas('product', function ($query) { return $query->whereHas('product', function ($query) {
return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE); return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE);
@ -76,8 +76,12 @@ class AgentProductController extends Controller
$prefix = Storage::disk('public')->url(''); $prefix = Storage::disk('public')->url('');
$agent_product->pictures = array_map(fn($item) => ($prefix . $item), $agent_product->pictures); $agent_product->pictures = array_map(fn($item) => ($prefix . $item), $agent_product->pictures);
$agent_product->is_collect = !is_null($agent_product->fav); //判断是否收藏
unset($agent_product->fav);
if ($this->user_id) {
$agent_product->is_collect = UserFav::query()->where(['user_id' => $this->user_id, 'agent_product_id' => $id])->exists() ? 1 : 0; //判断是否收藏
} else {
$agent_product->is_collect = 0;
}
//计算折扣 //计算折扣
if ($agent_product->price < $agent_product->original_price) { if ($agent_product->price < $agent_product->original_price) {
$agent_product->cost = round($agent_product->price / $agent_product->original_price * 10, 1); $agent_product->cost = round($agent_product->price / $agent_product->original_price * 10, 1);

35
app/Http/Controllers/Api/MiniProgramController.php

@ -5,6 +5,7 @@ use App\Http\Controllers\Controller;
use App\Models\AdminSetting; use App\Models\AdminSetting;
use App\Models\Agent; use App\Models\Agent;
use App\Models\MiniProgramUploadLog; use App\Models\MiniProgramUploadLog;
use App\Service\OpenPlatform;
use EasyWeChat\Factory; use EasyWeChat\Factory;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -27,16 +28,8 @@ class MiniProgramController extends Controller
'created_at' => now(), 'created_at' => now(),
]); ]);
$setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']);
$config = [ // 第三方平台信息
'app_id' => $setting['service_appid'],
'secret' => $setting['service_appsecret'],
'token' => $setting['service_token'],
'aes_key' => $setting['service_aeskey'],
];
$openPlatform = Factory::openPlatform($config);
$server = $openPlatform->server;
$openPlatform = new OpenPlatform();
$server = $openPlatform->server();
// 处理授权成功事件:Guard::EVENT_AUTHORIZED // 处理授权成功事件:Guard::EVENT_AUTHORIZED
// 处理授权更新事件:Guard::EVENT_UPDATE_AUTHORIZED // 处理授权更新事件:Guard::EVENT_UPDATE_AUTHORIZED
@ -75,23 +68,15 @@ class MiniProgramController extends Controller
'created_at' => now(), 'created_at' => now(),
]); ]);
$setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']);
$config = [
'app_id' => $setting['service_appid'],
'secret' => $setting['service_appsecret'],
'token' => $setting['service_token'],
'aes_key' => $setting['service_aeskey'],
];
$openPlatform = Factory::openPlatform($config);
$refreshToken = $openPlatform->getAuthorizer($appid)['authorization_info']['authorizer_refresh_token'] ?? null;
$openPlatform = new OpenPlatform();
$refreshToken = $openPlatform->refreshToken($appid);
if (!$refreshToken) { if (!$refreshToken) {
return $this->error('获取refresh_token失败'); return $this->error('获取refresh_token失败');
} }
$server = $openPlatform->miniProgram($appid, $refreshToken)->server; $server = $openPlatform->miniProgram($appid, $refreshToken)->server;
//接收事件 https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/code/audit_event.html //接收事件 https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/code/audit_event.html
$server->push(function ($message) use ($appid) {
$server->push(function ($message) use ($appid, $openPlatform, $refreshToken) {
DB::table('mini_program_events') DB::table('mini_program_events')
->insert([ ->insert([
'type' => 1, 'type' => 1,
@ -107,6 +92,14 @@ class MiniProgramController extends Controller
'weapp_audit_fail' => 1, //拒绝 'weapp_audit_fail' => 1, //拒绝
'weapp_audit_delay' => 4, //审核延后 'weapp_audit_delay' => 4, //审核延后
]; ];
//如果审核成功则发布
if ($message['Event'] == 'weapp_audit_success') {
$code = $openPlatform->code($appid, $refreshToken);
$code->release();
}
//保存到日志
$log = MiniProgramUploadLog::query() $log = MiniProgramUploadLog::query()
->where('appid', $appid) ->where('appid', $appid)
->orderBy('id', 'desc') ->orderBy('id', 'desc')

12
app/Http/Controllers/Api/TestController.php

@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api;
use App\Models\AdminSetting; use App\Models\AdminSetting;
use App\Models\AgentProduct; use App\Models\AgentProduct;
use App\Models\MiniProgramUploadLog; use App\Models\MiniProgramUploadLog;
use App\Service\OpenPlatform;
use EasyWeChat\Factory; use EasyWeChat\Factory;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -28,6 +29,9 @@ class TestController
'created_at' => now() 'created_at' => now()
]); ]);
$openPlatform = new OpenPlatform();
$refreshToken = $openPlatform->refreshToken($appid);
//审核结果通知 //审核结果通知
if (isset($message['MsgType'], $message['Event']) && $message['MsgType'] == 'event') { if (isset($message['MsgType'], $message['Event']) && $message['MsgType'] == 'event') {
$auditArr = [ $auditArr = [
@ -35,6 +39,14 @@ class TestController
'weapp_audit_fail' => 1, //拒绝 'weapp_audit_fail' => 1, //拒绝
'weapp_audit_delay' => 4, //审核延后 'weapp_audit_delay' => 4, //审核延后
]; ];
//如果审核成功则发布
if ($message['Event'] == 'weapp_audit_success') {
$code = $openPlatform->code($appid, $refreshToken);
$res = $code->release();
dump($res);
}
$log = MiniProgramUploadLog::query() $log = MiniProgramUploadLog::query()
->where('appid', $appid) ->where('appid', $appid)
->orderBy('id', 'desc') ->orderBy('id', 'desc')

5
app/Models/AgentProduct.php

@ -22,11 +22,6 @@ class AgentProduct extends BaseModel
return $this->hasMany(Coupon::class); return $this->hasMany(Coupon::class);
} }
public function fav()
{
return $this->hasOne(UserFav::class);
}
public function agent() public function agent()
{ {
return $this->belongsTo(Agent::class); return $this->belongsTo(Agent::class);

93
app/Service/OpenPlatform.php

@ -0,0 +1,93 @@
<?php
namespace App\Service;
use App\Models\AdminSetting;
use EasyWeChat\Factory;
use EasyWeChat\OpenPlatform\Application;
use EasyWeChat\OpenPlatform\Server\Guard;
/**
* 微信第三方开放平台
* Class OpenPlatform
* @package App\Service
*/
class OpenPlatform
{
public array $config = [];
private Application $openPlatform;
// private static self $instance;
public function __construct()
{
$setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']);
$this->config = [
'app_id' => $setting['service_appid'],
'secret' => $setting['service_appsecret'],
'token' => $setting['service_token'],
'aes_key' => $setting['service_aeskey'],
];
$this->openPlatform = Factory::openPlatform($this->config);
}
public function openPlatform(): Application
{
return $this->openPlatform;
}
/*public static function getInstance(): self
{
if (!self::$instance instanceof self) {
self::$instance = new self();
}
return self::$instance;
}*/
public function refreshToken($appid)
{
return $this->openPlatform->getAuthorizer($appid)['authorization_info']['authorizer_refresh_token'] ?? null;
}
public function miniProgram($appid, $refreshToken = null)
{
if (is_null($refreshToken)) {
$refreshToken = $this->refreshToken($appid);
}
return $this->openPlatform->miniProgram($appid, $refreshToken);
}
public function codeTemplate()
{
return $this->openPlatform['code_template'] ?? null;
}
public function code($appid, $refreshToken = null)
{
if (is_null($refreshToken)) {
$refreshToken = $this->refreshToken($appid);
}
return $this->openPlatform->miniProgram($appid, $refreshToken)['code'] ?? null;
}
public function component()
{
return $this->openPlatform['component'] ?? null;
}
public function server(): Guard
{
return $this->openPlatform->server;
}
public function __call($method, $args)
{
return $this->openPlatform->$method(...$args);
}
public function __get(string $name)
{
return $this->openPlatform->$name;
}
}
Loading…
Cancel
Save