From 01ef9c234daf9fa89080213b76a8193a96d61a83 Mon Sep 17 00:00:00 2001 From: liapples Date: Fri, 10 Sep 2021 10:52:19 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=80=BB=E5=90=8E=E5=8F=B0=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Controllers/SettingController.php | 23 +++++++++ app/Admin/Forms/Setting.php | 52 +++++++++++++++++++++ app/Models/AdminSetting.php | 20 ++++++++ 3 files changed, 95 insertions(+) create mode 100644 app/Admin/Controllers/SettingController.php create mode 100644 app/Admin/Forms/Setting.php create mode 100644 app/Models/AdminSetting.php diff --git a/app/Admin/Controllers/SettingController.php b/app/Admin/Controllers/SettingController.php new file mode 100644 index 0000000..c268ef1 --- /dev/null +++ b/app/Admin/Controllers/SettingController.php @@ -0,0 +1,23 @@ +title('系统设置') + ->body(new Card(new Setting())); + } +} diff --git a/app/Admin/Forms/Setting.php b/app/Admin/Forms/Setting.php new file mode 100644 index 0000000..235c30a --- /dev/null +++ b/app/Admin/Forms/Setting.php @@ -0,0 +1,52 @@ +response()->error('Your error message.'); + admin_setting($input); + + return $this->response()->success('保存成功')->refresh(); + } + + /** + * Build a form here. + */ + public function form() + { + $this->tab('支付小程序配置', function () { + $this->text('payee_appid', '收款小程序APPID')->required(); + $this->text('payee_appsecret', '收款小程序APP_SECRET')->required(); + $this->text('payee_mchid', '收款小程序MCH_ID')->required(); + $this->text('payee_mchkey', '收款小程序MCH_KEY')->required(); + })->tab('小程序服务商配置', function () { + $this->text('service_appid', '小程序第三方平台APPID'); + $this->text('service_appsecret', '小程序第三方平台APP_SECRET'); + $this->text('service_binding_appid', '绑定小程序APPID'); + }); + } + + /** + * The data of the form. + * + * @return array + */ + public function default() + { + return admin_setting()->toArray(); + } +} diff --git a/app/Models/AdminSetting.php b/app/Models/AdminSetting.php new file mode 100644 index 0000000..7678c11 --- /dev/null +++ b/app/Models/AdminSetting.php @@ -0,0 +1,20 @@ +whereIn('slug', $slug)->pluck('value')->toArray() ?? []; + } else { + return static::query()->where('slug', $slug)->value('value') ?? null; + } + } +} From aa360958aadbf15384c26f37ceaf31f8913a2ebc Mon Sep 17 00:00:00 2001 From: liapples Date: Fri, 10 Sep 2021 10:57:18 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/Grid/AuditRefund.php | 12 ++++++--- .../Controllers/Api/SharePayController.php | 12 ++++++--- app/Http/Controllers/Api/WxpayController.php | 25 +++++++++++++------ 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/app/AdminAgent/Extensions/Grid/AuditRefund.php b/app/AdminAgent/Extensions/Grid/AuditRefund.php index fb23e37..4398b34 100644 --- a/app/AdminAgent/Extensions/Grid/AuditRefund.php +++ b/app/AdminAgent/Extensions/Grid/AuditRefund.php @@ -2,6 +2,7 @@ namespace App\AdminAgent\Extensions\Grid; use App\Common\OrderStatus; +use App\Models\AdminSetting; use App\Models\Order; use App\Models\UserMoneyLog; use Dcat\Admin\Admin; @@ -64,12 +65,17 @@ class AuditRefund extends RowAction throw new \Exception('未查询到该笔订单的支付信息,退款失败'); } + $setting = AdminSetting::val(['payee_appid', 'payee_mchid', 'payee_mchkey']); + if (!isset($setting['payee_appid'], $setting['payee_mchid'], $setting['payee_mchkey'])) { + return $this->response()->error('获取系统配置失败'); + } + //将微信发起退款申请 $config = config('wechat.payment.default'); $config = array_merge($config, [ - 'app_id' => 'wxb35ef055a4dd8ad4', - 'mch_id' => '1606181693', - 'key' => 'lfyyhyz8888888888888888888888888', + 'app_id' => $setting['payee_appid'], + 'mch_id' => $setting['payee_mchid'], + 'key' => $setting['payee_mchkey'], 'notify_url' => route('wxpay_refund', $agent->id), 'cert_path' => env('WECHAT_CERT'), 'key_path' => env('WECHAT_KEY'), diff --git a/app/Http/Controllers/Api/SharePayController.php b/app/Http/Controllers/Api/SharePayController.php index 246a3ce..9bf6412 100644 --- a/app/Http/Controllers/Api/SharePayController.php +++ b/app/Http/Controllers/Api/SharePayController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api; use App\Common\OrderStatus as Status; use App\Common\PayType; use App\Http\Controllers\Controller; +use App\Models\AdminSetting; use App\Models\Agent; use App\Models\AgentProduct; use App\Models\Order; @@ -56,11 +57,16 @@ class SharePayController extends Controller $price = $this->calc($order->price, $order->num, $order->pay_type, $order->agentProduct); } + $setting = AdminSetting::val(['payee_appid', 'payee_mchid', 'payee_mchkey']); + if (!isset($setting['payee_appid'], $setting['payee_mchid'], $setting['payee_mchkey'])) { + return $this->error('获取系统配置失败'); + } + $config = config('wechat.payment.default'); $config = array_merge($config, [ - 'app_id' => 'wxb35ef055a4dd8ad4', - 'mch_id' => '1606181693', - 'key' => 'lfyyhyz8888888888888888888888888', + 'app_id' => $setting['payee_appid'], + 'mch_id' => $setting['payee_mchid'], + 'key' => $setting['payee_mchkey'], ]); $app = Factory::payment($config); diff --git a/app/Http/Controllers/Api/WxpayController.php b/app/Http/Controllers/Api/WxpayController.php index 626bec9..f84494e 100644 --- a/app/Http/Controllers/Api/WxpayController.php +++ b/app/Http/Controllers/Api/WxpayController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Api; use App\Common\PayType; +use App\Models\AdminSetting; use App\Models\Agent; use App\Models\AgentProduct; use App\Models\AgentSetting; @@ -20,13 +21,18 @@ class WxpayController public function notify() { $agent_id = request()->route('agent_id'); - $agent = Agent::find($agent_id); +// $agent = Agent::find($agent_id); + + $setting = AdminSetting::val(['payee_appid', 'payee_mchid', 'payee_mchkey']); + if (!isset($setting['payee_appid'], $setting['payee_mchid'], $setting['payee_mchkey'])) { + return '获取系统配置失败'; + } $config = config('wechat.payment.default'); $config = array_merge($config, [ - 'app_id' => $agent->appid, - 'mch_id' => $agent->mchid, - 'key' => $agent->mchkey, + 'app_id' => $setting['payee_appid'], + 'mch_id' => $setting['payee_mchid'], + 'key' => $setting['payee_mchkey'], ]); $app = Factory::payment($config); try { @@ -147,11 +153,16 @@ class WxpayController $agent_id = request()->route('agent_id'); // $agent = Agent::find($agent_id); + $setting = AdminSetting::val(['payee_appid', 'payee_mchid', 'payee_mchkey']); + if (!isset($setting['payee_appid'], $setting['payee_mchid'], $setting['payee_mchkey'])) { + return '获取系统配置失败'; + } + $config = config('wechat.payment.default'); $config = array_merge($config, [ - 'app_id' => 'wxb35ef055a4dd8ad4', - 'mch_id' => '1606181693', - 'key' => 'lfyyhyz8888888888888888888888888', + 'app_id' => $setting['payee_appid'], + 'mch_id' => $setting['payee_mchid'], + 'key' => $setting['payee_mchkey'], ]); $app = Factory::payment($config); try { From 9d13bb960e2080221e583f4ed19ca6ecef927d28 Mon Sep 17 00:00:00 2001 From: liapples Date: Fri, 10 Sep 2021 10:58:43 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/routes.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Admin/routes.php b/app/Admin/routes.php index d46ef6d..7f66b05 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -36,4 +36,7 @@ Route::group([ $router->resource('product_statistics', 'ProductStatisticsController'); $router->resource('agent_statistics', 'AgentStatisticsController'); $router->resource('supplier_statistics', 'SupplierStatisticsController'); + + $router->resource('setting', 'SettingController'); + $router->resource('mini_program', 'MiniProgramController'); }); From f55f5faed178736f6e3f30ecfe1fb1d31aaecd30 Mon Sep 17 00:00:00 2001 From: liapples Date: Fri, 10 Sep 2021 11:05:04 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/AdminSetting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/AdminSetting.php b/app/Models/AdminSetting.php index 7678c11..7d48688 100644 --- a/app/Models/AdminSetting.php +++ b/app/Models/AdminSetting.php @@ -12,7 +12,7 @@ class AdminSetting extends Model public static function val($slug) { if (is_array($slug)) { - return static::query()->whereIn('slug', $slug)->pluck('value')->toArray() ?? []; + return static::query()->whereIn('slug', $slug)->pluck('value', 'slug')->toArray() ?? []; } else { return static::query()->where('slug', $slug)->value('value') ?? null; }