Browse Source

优惠券绑定活动优惠券,修改ssdb

master
liangyuyan 6 years ago
parent
commit
fbed36329c
  1. 17
      app/Admin/Controllers/CouponTieController.php
  2. 22
      app/Admin/Repositories/CouponTie.php
  3. 2
      app/Libs/SSDB.php
  4. 36
      app/Libs/SsdbClient.php

17
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;
}
// 修改操作
});
});
}

22
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']
],
],
);

2
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");
}

36
app/Libs/SsdbClient.php

@ -0,0 +1,36 @@
<?php
namespace App\Libs;
use SimpleSSDB;
class SsdbClient
{
public $SSDB = null;
public function __construct()
{
// $host = env('SSDB_HOST');
// $port = env('SSDB_PORT');
// try{
// $SSDB = new SimpleSSDB($host, $port);
// $SSDB->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;
}
}
Loading…
Cancel
Save