From 1922b35cba16bf77ebead7c284fbbd9e98224546 Mon Sep 17 00:00:00 2001 From: zhouzhongping Date: Fri, 28 Aug 2020 10:41:05 +0800 Subject: [PATCH] v1.1.44 --- README.md | 15 ++++++ source/application/common.php | 1 + .../common/exception/ExceptionHandler.php | 18 ++++++-- .../common/library/wechat/live/Room.php | 7 +-- source/application/common/model/Express.php | 2 +- source/application/common/model/Printer.php | 6 ++- source/application/common/model/Region.php | 2 +- .../service/message/dealer/Withdraw.php | 2 +- .../common/service/qrcode/Base.php | 19 ++++---- .../store/controller/apps/dealer/Withdraw.php | 7 ++- .../store/model/dealer/Withdraw.php | 46 +++++++++++++++---- version.json | 2 +- 12 files changed, 93 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index ca09a43..66eca36 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,21 @@ ## 更新日志 +### v1.1.44 + +``` +新增:小程序转发到朋友圈(灰度安卓用户) +优化:微信打款时验证冻结资金是否合法 +优化:mysql报错时记录Error SQL +修复:后台权限缺少文件列表和回收站 +修复:地区表中部分地区不存在 +修复:获取直播房间列表接口报错 +修复:后台订单详情页报错 +修复:小程序端富文本视频高度不生效 +-------------------------------- +注:本次更新须重新发布小程序 +``` + ### v1.1.43 ``` diff --git a/source/application/common.php b/source/application/common.php index e703589..94d7bf9 100644 --- a/source/application/common.php +++ b/source/application/common.php @@ -51,6 +51,7 @@ function base_url() $request = Request::instance(); $subDir = str_replace('\\', '/', dirname($request->server('PHP_SELF'))); $baseUrl = $request->scheme() . '://' . $request->host() . $subDir . ($subDir === '/' ? '' : '/'); + // $baseUrl = 'https://' . $request->host() . $subDir . ($subDir === '/' ? '' : '/'); } return $baseUrl; } diff --git a/source/application/common/exception/ExceptionHandler.php b/source/application/common/exception/ExceptionHandler.php index 5ccb9f2..f5fac5b 100644 --- a/source/application/common/exception/ExceptionHandler.php +++ b/source/application/common/exception/ExceptionHandler.php @@ -2,8 +2,9 @@ namespace app\common\exception; -use think\exception\Handle; use think\Log; +use think\exception\Handle; +use think\exception\DbException; use Exception; /** @@ -55,13 +56,20 @@ class ExceptionHandler extends Handle private function recordErrorLog(Exception $e) { $data = [ - 'file' => $e->getFile(), - 'line' => $e->getLine(), + 'file' => $e->getFile(), + 'line' => $e->getLine(), 'message' => $this->getMessage($e), - 'code' => $this->getCode($e), + 'code' => $this->getCode($e), + 'TraceAsString' => $e->getTraceAsString() ]; + // 如果是mysql报错, 则记录Error SQL + if ($e instanceof DbException) { + $data['TraceAsString'] = "[Error SQL]: " . $e->getData()['Database Status']['Error SQL']; + } + // 日志标题 $log = "[{$data['code']}]{$data['message']} [{$data['file']}:{$data['line']}]"; - $log .= "\r\n" . $e->getTraceAsString(); + // 错误trace + $log .= "\r\n{$data['TraceAsString']}"; Log::record($log, 'error'); } } diff --git a/source/application/common/library/wechat/live/Room.php b/source/application/common/library/wechat/live/Room.php index 1a927fe..88c1ede 100644 --- a/source/application/common/library/wechat/live/Room.php +++ b/source/application/common/library/wechat/live/Room.php @@ -20,7 +20,7 @@ class Room extends WxBase { // 微信接口url $accessToken = $this->getAccessToken(); - $apiUrl = "http://api.weixin.qq.com/wxa/business/getliveinfo?access_token={$accessToken}"; + $apiUrl = "https://api.weixin.qq.com/wxa/business/getliveinfo?access_token={$accessToken}"; // 请求参数 $params = $this->jsonEncode(['start' => 0, 'limit' => 100]); // 执行请求 @@ -33,11 +33,12 @@ class Room extends WxBase $this->error = 'not found errcode'; return false; } - if ((int)$response['errcode'] > 1) { + // 容错: empty room list + if ($response['errcode'] > 1 && $response['errcode'] != 9410000) { $this->error = $response['errmsg']; return false; } return $response; } -} \ No newline at end of file +} diff --git a/source/application/common/model/Express.php b/source/application/common/model/Express.php index 2b34b98..0035871 100644 --- a/source/application/common/model/Express.php +++ b/source/application/common/model/Express.php @@ -21,7 +21,7 @@ class Express extends BaseModel public static function getAll() { $model = new static; - return $model->order(['sort' => 'asc', $this->getPk() => 'desc'])->select(); + return $model->order(['sort' => 'asc', $model->getPk() => 'desc'])->select(); } /** diff --git a/source/application/common/model/Printer.php b/source/application/common/model/Printer.php index fd14092..f08f1ce 100644 --- a/source/application/common/model/Printer.php +++ b/source/application/common/model/Printer.php @@ -64,8 +64,10 @@ class Printer extends BaseModel */ public static function getAll() { - return (new static)->where('is_delete', '=', 0) - ->order(['sort' => 'asc', $this->getPk() => 'desc'])->select(); + $model = new static; + return $model->where('is_delete', '=', 0) + ->order(['sort' => 'asc', $model->getPk() => 'desc']) + ->select(); } /** diff --git a/source/application/common/model/Region.php b/source/application/common/model/Region.php index 652be2d..f91d68c 100644 --- a/source/application/common/model/Region.php +++ b/source/application/common/model/Region.php @@ -27,7 +27,7 @@ class Region extends BaseModel ]; // 当前数据版本号 - private static $version = '1.2.4'; + private static $version = '1.2.5'; // 县级市别名 (兼容微信端命名) private static $county = [ diff --git a/source/application/common/service/message/dealer/Withdraw.php b/source/application/common/service/message/dealer/Withdraw.php index ced5e48..b33d9c1 100644 --- a/source/application/common/service/message/dealer/Withdraw.php +++ b/source/application/common/service/message/dealer/Withdraw.php @@ -119,4 +119,4 @@ class Withdraw extends Basics return false; } -} \ No newline at end of file +} diff --git a/source/application/common/service/qrcode/Base.php b/source/application/common/service/qrcode/Base.php index fb6ebee..a9b7a98 100644 --- a/source/application/common/service/qrcode/Base.php +++ b/source/application/common/service/qrcode/Base.php @@ -22,25 +22,26 @@ class Base /** * 保存小程序码到文件 - * @param $wxapp_id + * @param $wxappId * @param $scene * @param null $page * @return string * @throws \app\common\exception\BaseException + * @throws \think\Exception * @throws \think\exception\DbException */ - protected function saveQrcode($wxapp_id, $scene, $page = null) + protected function saveQrcode($wxappId, $scene, $page = null) { // 文件目录 - $dirPath = RUNTIME_PATH . 'image' . '/' . $wxapp_id; + $dirPath = RUNTIME_PATH . 'image' . '/' . $wxappId; !is_dir($dirPath) && mkdir($dirPath, 0755, true); // 文件名称 - $fileName = 'qrcode_' . md5($wxapp_id . $scene . $page) . '.png'; + $fileName = 'qrcode_' . md5($wxappId . $scene . $page) . '.png'; // 文件路径 $savePath = "{$dirPath}/{$fileName}"; if (file_exists($savePath)) return $savePath; // 小程序配置信息 - $wxConfig = WxappModel::getWxappCache($wxapp_id); + $wxConfig = WxappModel::getWxappCache($wxappId); // 请求api获取小程序码 $Qrcode = new Qrcode($wxConfig['app_id'], $wxConfig['app_secret']); $content = $Qrcode->getQrcode($scene, $page); @@ -51,14 +52,14 @@ class Base /** * 获取网络图片到临时目录 - * @param $wxapp_id + * @param $wxappId * @param $url * @param string $mark * @return string */ - protected function saveTempImage($wxapp_id, $url, $mark = 'temp') + protected function saveTempImage($wxappId, $url, $mark = 'temp') { - $dirPath = RUNTIME_PATH . 'image' . '/' . $wxapp_id; + $dirPath = RUNTIME_PATH . 'image' . '/' . $wxappId; !is_dir($dirPath) && mkdir($dirPath, 0755, true); $savePath = $dirPath . '/' . $mark . '_' . md5($url) . '.png'; if (file_exists($savePath)) return $savePath; @@ -74,4 +75,4 @@ class Base return $savePath; } -} \ No newline at end of file +} diff --git a/source/application/store/controller/apps/dealer/Withdraw.php b/source/application/store/controller/apps/dealer/Withdraw.php index 0070d97..ff5964d 100644 --- a/source/application/store/controller/apps/dealer/Withdraw.php +++ b/source/application/store/controller/apps/dealer/Withdraw.php @@ -52,8 +52,11 @@ class Withdraw extends Controller */ public function money($id) { + // 提现记录详情 $model = WithdrawModel::detail($id); - if ($model->money()) { + // 验证已冻结佣金是否合法 + // 合法 -> 确认打款 + if (!$model->verifyUserFreezeMoney($model['user_id'], $model['money']) && $model->money()) { return $this->renderSuccess('操作成功'); } return $this->renderError($model->getError() ?: '操作失败'); @@ -76,4 +79,4 @@ class Withdraw extends Controller return $this->renderError($model->getError() ?: '操作失败'); } -} \ No newline at end of file +} diff --git a/source/application/store/model/dealer/Withdraw.php b/source/application/store/model/dealer/Withdraw.php index b0636ef..6c9e8cf 100644 --- a/source/application/store/model/dealer/Withdraw.php +++ b/source/application/store/model/dealer/Withdraw.php @@ -4,12 +4,13 @@ namespace app\store\model\dealer; use app\store\model\User as UserModel; use app\store\model\Wxapp as WxappModel; +use app\common\model\dealer\User as dealerUserModel; use app\common\model\dealer\Withdraw as WithdrawModel; -use app\common\library\wechat\WxPay; use app\common\service\Order as OrderService; use app\common\service\Message as MessageService; use app\common\enum\dealer\withdraw\PayType as PayTypeEnum; use app\common\enum\dealer\withdraw\ApplyStatus as ApplyStatusEnum; +use app\common\library\wechat\WxPay; /** * 分销商提现明细模型 @@ -40,14 +41,14 @@ class Withdraw extends WithdrawModel /** * 获取分销商提现列表 - * @param null $user_id + * @param null $userId * @param int $apply_status * @param int $pay_type * @param string $search * @return \think\Paginator * @throws \think\exception\DbException */ - public function getList($user_id = null, $apply_status = -1, $pay_type = -1, $search = '') + public function getList($userId = null, $apply_status = -1, $pay_type = -1, $search = '') { // 构建查询规则 $this->alias('withdraw') @@ -57,7 +58,7 @@ class Withdraw extends WithdrawModel ->join('dealer_user dealer', 'dealer.user_id = withdraw.user_id') ->order(['withdraw.create_time' => 'desc']); // 查询条件 - $user_id > 0 && $this->where('withdraw.user_id', '=', $user_id); + $userId > 0 && $this->where('withdraw.user_id', '=', $userId); !empty($search) && $this->where('dealer.real_name|dealer.mobile', 'like', "%$search%"); $apply_status > 0 && $this->where('withdraw.apply_status', '=', $apply_status); $pay_type > 0 && $this->where('withdraw.pay_type', '=', $pay_type); @@ -100,11 +101,17 @@ class Withdraw extends WithdrawModel /** * 确认已打款 - * @return bool + * @param bool $verifyUserFreezeMoney 验证已冻结佣金是否合法 + * @return bool|mixed + * @throws \think\exception\DbException */ - public function money() + public function money($verifyUserFreezeMoney = true) { - $this->transaction(function () { + // 验证已冻结佣金是否合法 + if ($verifyUserFreezeMoney && !$this->verifyUserFreezeMoney($this['user_id'], $this['money'])) { + return false; + } + return $this->transaction(function () { // 更新申请状态 $this->allowField(true)->save([ 'apply_status' => 40, @@ -119,8 +126,8 @@ class Withdraw extends WithdrawModel 'money' => -$this['money'], 'describe' => '申请提现', ]); + return true; }); - return true; } /** @@ -132,6 +139,10 @@ class Withdraw extends WithdrawModel */ public function wechatPay() { + // 验证已冻结佣金是否合法 + if (!$this->verifyUserFreezeMoney($this['user_id'], $this['money'])) { + return false; + } // 微信用户信息 $user = $this['user']['user']; // 生成付款订单号 @@ -144,10 +155,27 @@ class Withdraw extends WithdrawModel // 请求付款api if ($WxPay->transfers($orderNO, $user['open_id'], $this['money'], $desc)) { // 确认已打款 - $this->money(); + $this->money(false); return true; } return false; } + /** + * 验证已冻结佣金是否合法 + * @param $userId + * @param $money + * @return bool + * @throws \think\exception\DbException + */ + public function verifyUserFreezeMoney($userId, $money) + { + $dealerUserInfo = dealerUserModel::detail($userId); + if ($dealerUserInfo['freeze_money'] < $money) { + $this->error = '数据错误:已冻结的佣金不能小于提现的金额'; + return false; + } + return true; + } + } diff --git a/version.json b/version.json index 4fd7b00..7842f40 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "1.1.43" + "version": "1.1.44" }