From fbed36329c5a7d5bbff2cef372ac081fb126d172 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 7 Aug 2020 18:38:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E4=BC=98=E6=83=A0=E5=88=B8=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9ssdb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Controllers/CouponTieController.php | 17 +++++++++ app/Admin/Repositories/CouponTie.php | 22 ++++-------- app/Libs/SSDB.php | 2 +- app/Libs/SsdbClient.php | 36 +++++++++++++++++++ 4 files changed, 60 insertions(+), 17 deletions(-) diff --git a/app/Admin/Controllers/CouponTieController.php b/app/Admin/Controllers/CouponTieController.php index 27983e5..2b21a4e 100644 --- a/app/Admin/Controllers/CouponTieController.php +++ b/app/Admin/Controllers/CouponTieController.php @@ -59,6 +59,23 @@ class CouponTieController extends AdminController // 中断后续逻辑 return $this->error('服务器出错了~'); }); + $form->saved(function (Form $form, $result) { + // 判断是否是新增操作 + if ($form->isCreating()) { + // 自增ID + $newId = $result; + // 也可以这样获取自增ID + $newId = $form->getKey(); + + if (! $newId) { + return $form->error('数据保存失败'); + } + + return; + } + + // 修改操作 + }); }); } diff --git a/app/Admin/Repositories/CouponTie.php b/app/Admin/Repositories/CouponTie.php index 6e7eb5e..e54462b 100644 --- a/app/Admin/Repositories/CouponTie.php +++ b/app/Admin/Repositories/CouponTie.php @@ -4,7 +4,7 @@ namespace App\Admin\Repositories; use Dcat\Admin\Grid; use Dcat\Admin\Repositories\Repository; use Illuminate\Pagination\LengthAwarePaginator; -use SimpleSSDB; +use App\Libs\SsdbClient; class CouponTie extends Repository{ @@ -15,28 +15,18 @@ class CouponTie extends Repository{ public function get(Grid\Model $model) { - $host = env('SSDB_HOST'); - $port = env('SSDB_PORT'); - try{ - $ssdb = new SimpleSSDB($host, $port); - $ssdb->auth(env('SSDB_AUTH')); - }catch(\Exception $e){ - dd($e); - } - $activity = $ssdb->get('coupon_rebate_activity'); - $forward = $ssdb->hgetall('coupon_rebate_forward_'.$activity); - $forward = is_array($forward) ? implode(' , ',$forward) : $forward ; - $repay = $ssdb->get('coupon_rebate_repay_'.$activity); + $ssdb = new SsdbClient(); + $coupon = $ssdb->client()->hgetall('coupon_rebate_activity'); return $model->makePaginator( 1, [ [ 'id'=>1, - 'activity'=>$activity, - 'forward'=>$forward, - 'repay' => $repay + 'activity'=>$coupon['activity'], + 'forward'=>$coupon['forward'], + 'repay' => $coupon['repay'] ], ], ); diff --git a/app/Libs/SSDB.php b/app/Libs/SSDB.php index 1a1dc12..9b987be 100644 --- a/app/Libs/SSDB.php +++ b/app/Libs/SSDB.php @@ -74,7 +74,7 @@ class SSDB function __construct($host, $port, $timeout_ms=2000){ $timeout_f = (float)$timeout_ms/1000; - $this->sock = @stream_socket_client("[$host]:$port", $errno, $errstr, $timeout_f); + $this->sock = @stream_socket_client("$host:$port", $errno, $errstr, $timeout_f); if(!$this->sock){ throw new SSDBException("$errno: $errstr"); } diff --git a/app/Libs/SsdbClient.php b/app/Libs/SsdbClient.php index e69de29..33c740e 100644 --- a/app/Libs/SsdbClient.php +++ b/app/Libs/SsdbClient.php @@ -0,0 +1,36 @@ +auth(env('SSDB_AUTH')); + // }catch(\Exception $e){ + // dd($e); + // } + } + + public function client() + { + $host = env('SSDB_HOST'); + $port = env('SSDB_PORT'); + + try{ + $SSDB = new SimpleSSDB($host, $port); + $SSDB->auth(env('SSDB_AUTH')); + }catch(\Exception $e){ + dd($e); + } + + return $SSDB; + } +} \ No newline at end of file