From f258e2cccc36913835cb3363f60da17b86eca354 Mon Sep 17 00:00:00 2001 From: Anyon Date: Mon, 19 Aug 2019 10:36:03 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E4=BF=AE=E6=94=B9=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin_v5.sql | 6 +- application/admin/controller/User.php | 10 +- application/store/command/AutoRun.php | 147 +++++++++++++------------- 3 files changed, 85 insertions(+), 78 deletions(-) diff --git a/admin_v5.sql b/admin_v5.sql index d3d57fa8e..7b90d8c90 100644 --- a/admin_v5.sql +++ b/admin_v5.sql @@ -11,7 +11,7 @@ Target Server Version : 50562 File Encoding : 65001 - Date: 14/08/2019 10:33:20 + Date: 19/08/2019 10:34:31 */ SET NAMES utf8mb4; @@ -676,7 +676,7 @@ CREATE TABLE `system_user` ( `is_deleted` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '删除(1删除,0未删)', `create_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', PRIMARY KEY (`id`) USING BTREE, - UNIQUE INDEX `index_system_user_username`(`username`) USING BTREE, + INDEX `index_system_user_username`(`username`) USING BTREE, INDEX `index_system_user_status`(`status`) USING BTREE, INDEX `index_system_user_deleted`(`is_deleted`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 10001 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '系统-用户'; @@ -684,7 +684,7 @@ CREATE TABLE `system_user` ( -- ---------------------------- -- Records of system_user -- ---------------------------- -INSERT INTO `system_user` VALUES (10000, 'admin', '21232f297a57a5a743894a0e4a801fc3', '22222222', '', '', '2019-08-14 10:07:34', '127.0.0.1', 659, '', '', '', 1, 0, '2015-11-13 15:14:22'); +INSERT INTO `system_user` VALUES (10000, 'admin', '21232f297a57a5a743894a0e4a801fc3', '22222222', '', '', '2019-08-18 18:34:14', '127.0.0.1', 661, '', '', '', 1, 0, '2015-11-13 15:14:22'); -- ---------------------------- -- Table structure for wechat_fans diff --git a/application/admin/controller/User.php b/application/admin/controller/User.php index 4c4ed6384..e79818e58 100644 --- a/application/admin/controller/User.php +++ b/application/admin/controller/User.php @@ -118,12 +118,14 @@ class User extends Controller public function _form_filter(&$data) { if ($this->request->isPost()) { + // 刷新系统授权 NodeService::applyUserAuth(); + // 用户权限处理 $data['authorize'] = (isset($data['authorize']) && is_array($data['authorize'])) ? join(',', $data['authorize']) : ''; - if (isset($data['id'])) { - unset($data['username']); - } elseif (Db::name($this->table)->where(['username' => $data['username']])->count() > 0) { - $this->error('用户账号已经存在,请使用其它账号!'); + // 用户账号重复检查 + if (isset($data['id'])) unset($data['username']); + elseif (Db::name($this->table)->where(['username' => $data['username'], 'is_deleted' => '0'])->count() > 0) { + $this->error("账号{$data['username']}已经存在,请使用其它账号!"); } } else { $data['authorize'] = explode(',', isset($data['authorize']) ? $data['authorize'] : ''); diff --git a/application/store/command/AutoRun.php b/application/store/command/AutoRun.php index a7510afa5..54ab554fb 100644 --- a/application/store/command/AutoRun.php +++ b/application/store/command/AutoRun.php @@ -15,14 +15,23 @@ namespace app\store\command; +use think\console\Command; +use think\console\Input; +use think\console\Output; use think\Db; +use think\db\exception\DataNotFoundException; +use think\db\exception\ModelNotFoundException; +use think\Exception; +use think\exception\DbException; +use think\exception\PDOException; +use We; /** * 商城数据处理指令 * Class AutoRun * @package app\store\command */ -class AutoRun extends \think\console\Command +class AutoRun extends Command { /** @@ -35,15 +44,15 @@ class AutoRun extends \think\console\Command /** * 业务指令执行 - * @param \think\console\Input $input - * @param \think\console\Output $output - * @throws \think\Exception - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException - * @throws \think\exception\DbException - * @throws \think\exception\PDOException + * @param Input $input + * @param Output $output + * @throws Exception + * @throws DataNotFoundException + * @throws ModelNotFoundException + * @throws DbException + * @throws PDOException */ - protected function execute(\think\console\Input $input, \think\console\Output $output) + protected function execute(Input $input, Output $output) { // 自动取消30分钟未支付的订单 $this->autoCancelOrder(); @@ -57,8 +66,8 @@ class AutoRun extends \think\console\Command /** * 自动取消30分钟未支付的订单 - * @throws \think\Exception - * @throws \think\exception\PDOException + * @throws Exception + * @throws PDOException */ private function autoCancelOrder() { @@ -79,11 +88,11 @@ class AutoRun extends \think\console\Command /** * 清理一天前未支付的订单 - * @throws \think\Exception - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException - * @throws \think\exception\DbException - * @throws \think\exception\PDOException + * @throws Exception + * @throws DataNotFoundException + * @throws ModelNotFoundException + * @throws DbException + * @throws PDOException */ private function autoRemoveOrder() { @@ -101,77 +110,73 @@ class AutoRun extends \think\console\Command /** * 订单自动退款操作 - * @throws \think\Exception - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException - * @throws \think\exception\DbException - * @throws \think\exception\PDOException + * @throws Exception + * @throws DataNotFoundException + * @throws ModelNotFoundException + * @throws DbException + * @throws PDOException */ private function autoRefundOrder() { // 未完成退款的订单,执行微信退款操作 - foreach (Db::name('StoreOrder')->where(['refund_state' => '1'])->select() as $order) { - try { - $this->output->writeln("正在为 {$order['order_no']} 执行退款操作..."); - $result = \We::WePayRefund(config('wechat.wxpay'))->create([ - 'transaction_id' => $order['pay_no'], - 'out_refund_no' => $order['refund_no'], - 'total_fee' => $order['price_total'] * 100, - 'refund_fee' => $order['pay_price'] * 100, - 'refund_account' => 'REFUND_SOURCE_UNSETTLED_FUNDS', + foreach (Db::name('StoreOrder')->where(['refund_state' => '1'])->select() as $order) try { + $this->output->writeln("正在为 {$order['order_no']} 执行退款操作..."); + $result = We::WePayRefund(config('wechat.wxpay'))->create([ + 'transaction_id' => $order['pay_no'], + 'out_refund_no' => $order['refund_no'], + 'total_fee' => $order['price_total'] * 100, + 'refund_fee' => $order['pay_price'] * 100, + 'refund_account' => 'REFUND_SOURCE_UNSETTLED_FUNDS', + ]); + if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') { + Db::name('StoreOrder')->where(['order_no' => $order['order_no']])->update([ + 'refund_state' => '2', 'refund_desc' => '自动退款成功!', + ]); + } else { + Db::name('StoreOrder')->where(['order_no' => $order['order_no']])->update([ + 'refund_desc' => isset($result['err_code_des']) ? $result['err_code_des'] : '自动退款失败', ]); - if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') { - Db::name('StoreOrder')->where(['order_no' => $order['order_no']])->update([ - 'refund_state' => '2', 'refund_desc' => '自动退款成功!', - ]); - } else { - Db::name('StoreOrder')->where(['order_no' => $order['order_no']])->update([ - 'refund_desc' => isset($result['err_code_des']) ? $result['err_code_des'] : '自动退款失败', - ]); - } - } catch (\Exception $e) { - $this->output->writeln("订单 {$order['order_no']} 执行退款失败,{$e->getMessage()}!"); - Db::name('StoreOrder')->where(['order_no' => $order['order_no']])->update(['refund_desc' => $e->getMessage()]); } + } catch (\Exception $e) { + $this->output->writeln("订单 {$order['order_no']} 执行退款失败,{$e->getMessage()}!"); + Db::name('StoreOrder')->where(['order_no' => $order['order_no']])->update(['refund_desc' => $e->getMessage()]); } $this->output->writeln('自动检测退款订单执行完成!'); } /** * 自动企业打款操作 - * @throws \think\Exception - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException - * @throws \think\exception\DbException - * @throws \think\exception\PDOException + * @throws Exception + * @throws DataNotFoundException + * @throws ModelNotFoundException + * @throws DbException + * @throws PDOException */ private function autoTransfer() { # 批量企业打款 - foreach (Db::name('StoreProfitUsed')->where(['status' => '1'])->select() as $vo) { - try { - $wechat = \We::WePayTransfers(config('wechat.wxpay')); - $result = $wechat->create([ - 'partner_trade_no' => $vo['trs_no'], - 'openid' => $vo['openid'], - 'check_name' => 'NO_CHECK', - 'amount' => $vo['pay_price'] * 100, - 'desc' => '营销活动拥金提现', - 'spbill_create_ip' => '127.0.0.1', + foreach (Db::name('StoreProfitUsed')->where(['status' => '1'])->select() as $vo) try { + $wechat = We::WePayTransfers(config('wechat.wxpay')); + $result = $wechat->create([ + 'partner_trade_no' => $vo['trs_no'], + 'openid' => $vo['openid'], + 'check_name' => 'NO_CHECK', + 'amount' => $vo['pay_price'] * 100, + 'desc' => '营销活动拥金提现', + 'spbill_create_ip' => '127.0.0.1', + ]); + if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') { + Db::name('StoreProfitUsed')->where(['trs_no' => $vo['trs_no']])->update([ + 'status' => '2', 'pay_desc' => '拥金提现成功!', 'pay_no' => $result['payment_no'], 'pay_at' => date('Y-m-d H:i:s'), + ]); + } else { + Db::name('StoreProfitUsed')->where(['trs_no' => $vo['trs_no']])->update([ + 'pay_desc' => isset($result['err_code_des']) ? $result['err_code_des'] : '自动打款失败', 'last_at' => date('Y-m-d H:i:s'), ]); - if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') { - Db::name('StoreProfitUsed')->where(['trs_no' => $vo['trs_no']])->update([ - 'status' => '2', 'pay_desc' => '拥金提现成功!', 'pay_no' => $result['payment_no'], 'pay_at' => date('Y-m-d H:i:s'), - ]); - } else { - Db::name('StoreProfitUsed')->where(['trs_no' => $vo['trs_no']])->update([ - 'pay_desc' => isset($result['err_code_des']) ? $result['err_code_des'] : '自动打款失败', 'last_at' => date('Y-m-d H:i:s'), - ]); - } - } catch (\Exception $e) { - $this->output->writeln("订单 {$vo['trs_no']} 执行提现失败,{$e->getMessage()}!"); - Db::name('StoreProfitUsed')->where(['trs_no' => $vo['trs_no']])->update(['pay_desc' => $e->getMessage()]); } + } catch (\Exception $e) { + $this->output->writeln("订单 {$vo['trs_no']} 执行提现失败,{$e->getMessage()}!"); + Db::name('StoreProfitUsed')->where(['trs_no' => $vo['trs_no']])->update(['pay_desc' => $e->getMessage()]); } } @@ -179,8 +184,8 @@ class AutoRun extends \think\console\Command * 获取配置时间 * @param string $code * @return string - * @throws \think\Exception - * @throws \think\exception\PDOException + * @throws Exception + * @throws PDOException */ private function getDatetime($code) {