获取平安核销的订单号
This commit is contained in:
@@ -15,6 +15,7 @@ class IndexController extends AdminController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Notes:
|
* Notes:
|
||||||
|
*
|
||||||
* @Author: <C.Jason>
|
* @Author: <C.Jason>
|
||||||
* @Date : 2019/9/18 14:50
|
* @Date : 2019/9/18 14:50
|
||||||
* @return Grid
|
* @return Grid
|
||||||
@@ -27,9 +28,9 @@ class IndexController extends AdminController
|
|||||||
$grid->disableActions();
|
$grid->disableActions();
|
||||||
|
|
||||||
$grid->model()
|
$grid->model()
|
||||||
->with(['outlet.province', 'outlet.city', 'outlet.district', 'user', 'user.info'])
|
->with(['outlet.province', 'outlet.city', 'outlet.district', 'user', 'user.info'])
|
||||||
->whereIn('status', [2, 3])
|
->whereIn('status', [2, 3])
|
||||||
->orderBy('id', 'desc');
|
->orderBy('id', 'desc');
|
||||||
|
|
||||||
$grid->filter(function ($filter) {
|
$grid->filter(function ($filter) {
|
||||||
$filter->column(1 / 2, function ($filter) {
|
$filter->column(1 / 2, function ($filter) {
|
||||||
@@ -56,6 +57,7 @@ class IndexController extends AdminController
|
|||||||
}, '网点名称');
|
}, '网点名称');
|
||||||
|
|
||||||
$filter->equal('type', '类型')->select(Coupon::TYPES);
|
$filter->equal('type', '类型')->select(Coupon::TYPES);
|
||||||
|
$filter->like('pa_order_id', '平安主订单号');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -64,11 +66,11 @@ class IndexController extends AdminController
|
|||||||
return $this->user->nickname;
|
return $this->user->nickname;
|
||||||
});
|
});
|
||||||
$grid->column('type', '类型')
|
$grid->column('type', '类型')
|
||||||
->using(Coupon::TYPES)
|
->using(Coupon::TYPES)
|
||||||
->label([
|
->label([
|
||||||
'1' => 'info',
|
'1' => 'info',
|
||||||
'2' => 'success',
|
'2' => 'success',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$grid->column('网点名称/编号')->display(function () {
|
$grid->column('网点名称/编号')->display(function () {
|
||||||
return $this->outlet ? $this->outlet->nickname : $this->outletId;
|
return $this->outlet ? $this->outlet->nickname : $this->outletId;
|
||||||
@@ -79,19 +81,20 @@ class IndexController extends AdminController
|
|||||||
$grid->column('price', '核销金额');
|
$grid->column('price', '核销金额');
|
||||||
$grid->column('total', '订单金额');
|
$grid->column('total', '订单金额');
|
||||||
$grid->column('orderid', '订单id');
|
$grid->column('orderid', '订单id');
|
||||||
|
$grid->column('pa_order_id', '平安主订单号')->hide();
|
||||||
|
|
||||||
$grid->column('资金通道结算')->display(function () {
|
$grid->column('资金通道结算')->display(function () {
|
||||||
$profit = $this->status == 2 ? $this->profit : '0.00';
|
$profit = $this->status == 2 ? $this->profit : '0.00';
|
||||||
|
|
||||||
return '<span style="color:red">' . $profit . '</span>';
|
return '<span style="color:red">'.$profit.'</span>';
|
||||||
});
|
});
|
||||||
$grid->column('状态')->display(function () {
|
$grid->column('状态')->display(function () {
|
||||||
switch ($this->status) {
|
switch ($this->status) {
|
||||||
case 2:
|
case 2:
|
||||||
return '<span style="color:green">' . $this->status_text . '</span>';
|
return '<span style="color:green">'.$this->status_text.'</span>';
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
return '<span style="color:red">' . $this->status_text . '</span>';
|
return '<span style="color:red">'.$this->status_text.'</span>';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return $this->status_text;
|
return $this->status_text;
|
||||||
@@ -123,13 +126,13 @@ class IndexController extends AdminController
|
|||||||
$success = $query->where('status', 2)->count();
|
$success = $query->where('status', 2)->count();
|
||||||
$faield = $total - $success;
|
$faield = $total - $success;
|
||||||
|
|
||||||
return '<label class="label label-success">全部:' . $total . '张</label> '
|
return '<label class="label label-success">全部:'.$total.'张</label> '
|
||||||
. '<label class="label label-success">成功:' . $success . '张</label> '
|
.'<label class="label label-success">成功:'.$success.'张</label> '
|
||||||
. '<label class="label label-success">失败:' . $faield . '张</label> '
|
.'<label class="label label-success">失败:'.$faield.'张</label> '
|
||||||
. '<label class="label label-success">核销金额:' . $query->sum('price') . '元</label> '
|
.'<label class="label label-success">核销金额:'.$query->sum('price').'元</label> '
|
||||||
. '<label class="label label-success">资金通道结算:' . $query->sum('profit') . '元</label> '
|
.'<label class="label label-success">资金通道结算:'.$query->sum('profit').'元</label> '
|
||||||
. '<label class="label label-success">打款金额:' . $query->where('is_profit', 1)
|
.'<label class="label label-success">打款金额:'.$query->where('is_profit', 1)
|
||||||
->sum('profit') . '元</label> ';
|
->sum('profit').'元</label> ';
|
||||||
});
|
});
|
||||||
$grid->disableExport(false);
|
$grid->disableExport(false);
|
||||||
|
|
||||||
@@ -141,13 +144,13 @@ class IndexController extends AdminController
|
|||||||
return strip_tags($value);
|
return strip_tags($value);
|
||||||
});
|
});
|
||||||
$export->column('redemptionCode', function ($value, $original) {
|
$export->column('redemptionCode', function ($value, $original) {
|
||||||
return $value . "\t";
|
return $value."\t";
|
||||||
});
|
});
|
||||||
// $export->column('price', function ($value, $original) {
|
// $export->column('price', function ($value, $original) {
|
||||||
// return $value . "\t";
|
// return $value . "\t";
|
||||||
// });
|
// });
|
||||||
$export->column('orderid', function ($value, $original) {
|
$export->column('orderid', function ($value, $original) {
|
||||||
return $value . "\t";
|
return $value."\t";
|
||||||
});
|
});
|
||||||
// $export->column('total', function ($value, $original) {
|
// $export->column('total', function ($value, $original) {
|
||||||
// return $value . "\t";
|
// return $value . "\t";
|
||||||
@@ -155,7 +158,7 @@ class IndexController extends AdminController
|
|||||||
$export->column('资金通道结算', function ($value, $original) {
|
$export->column('资金通道结算', function ($value, $original) {
|
||||||
return strip_tags($value);
|
return strip_tags($value);
|
||||||
});
|
});
|
||||||
$export->filename('卡券列表' . date("YmdHis"));
|
$export->filename('卡券列表'.date("YmdHis"));
|
||||||
});
|
});
|
||||||
|
|
||||||
return $grid;
|
return $grid;
|
||||||
|
|||||||
@@ -3,64 +3,69 @@
|
|||||||
namespace App\Admin\Controllers;
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
use App\Models\Coupon;
|
use App\Models\Coupon;
|
||||||
|
use App\Models\Log;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use XuanChen\Coupon\Action\pingan\Verification;
|
||||||
|
|
||||||
class TestController
|
class TestController
|
||||||
{
|
{
|
||||||
|
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$date = $request->date ?? date('Y-m-d');
|
$date = $request->date ?? date('Y-m-d');
|
||||||
$time = Carbon::parse($date);
|
$time = Carbon::parse($date);
|
||||||
|
|
||||||
$all = Coupon::where('status', 2)
|
$all = Coupon::where('status', 2)
|
||||||
->whereBetween('created_at', [
|
->whereBetween('created_at', [
|
||||||
$time->startOfDay()->toDateTimeString(),
|
$time->startOfDay()->toDateTimeString(),
|
||||||
$time->endOfDay()->toDateTimeString(),
|
$time->endOfDay()->toDateTimeString(),
|
||||||
])
|
])
|
||||||
->count();
|
->count();
|
||||||
$self = Coupon::where('status', 2)
|
$self = Coupon::where('status', 2)
|
||||||
->where('type', Coupon::TYPE_YSD)
|
->where('type', Coupon::TYPE_YSD)
|
||||||
->whereBetween('created_at', [
|
->whereBetween('created_at', [
|
||||||
$time->startOfDay()->toDateTimeString(),
|
$time->startOfDay()->toDateTimeString(),
|
||||||
$time->endOfDay()->toDateTimeString(),
|
$time->endOfDay()->toDateTimeString(),
|
||||||
])
|
])
|
||||||
->count();
|
->count();
|
||||||
$pingan = Coupon::where('status', 2)
|
$pingan = Coupon::where('status', 2)
|
||||||
->where('type', Coupon::TYPE_PINGAN)
|
->where('type', Coupon::TYPE_PINGAN)
|
||||||
->whereBetween('created_at', [
|
->whereBetween('created_at', [
|
||||||
$time->startOfDay()->toDateTimeString(),
|
$time->startOfDay()->toDateTimeString(),
|
||||||
$time->endOfDay()->toDateTimeString(),
|
$time->endOfDay()->toDateTimeString(),
|
||||||
])
|
])
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
$error = Coupon::where('status', 3)
|
$error = Coupon::where('status', 3)
|
||||||
->whereBetween('created_at', [
|
->whereBetween('created_at', [
|
||||||
$time->startOfDay()->toDateTimeString(),
|
$time->startOfDay()->toDateTimeString(),
|
||||||
$time->endOfDay()->toDateTimeString(),
|
$time->endOfDay()->toDateTimeString(),
|
||||||
])
|
])
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
$lists = DB::table('coupons')
|
$lists = DB::table('coupons')
|
||||||
->where('status', 2)
|
->where('status', 2)
|
||||||
->whereBetween('created_at', [
|
->whereBetween('created_at', [
|
||||||
$time->startOfDay()->toDateTimeString(),
|
$time->startOfDay()->toDateTimeString(),
|
||||||
$time->endOfDay()->toDateTimeString(),
|
$time->endOfDay()->toDateTimeString(),
|
||||||
])
|
])
|
||||||
->select('redemptionCode', DB::raw('COUNT(*) as code_count'))
|
->select('redemptionCode', DB::raw('COUNT(*) as code_count'))
|
||||||
->groupBy('redemptionCode')
|
->groupBy('redemptionCode')
|
||||||
->having('code_count', '>', 1)
|
->having('code_count', '>', 1)
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
' 日期为:' . $time->format('Y-m-d'),
|
' 日期为:'.$time->format('Y-m-d'),
|
||||||
' 核销总数为:' . $all,
|
' 核销总数为:'.$all,
|
||||||
' 自有卡券总数为:' . $self,
|
' 自有卡券总数为:'.$self,
|
||||||
' 平安卡券总数为:' . $pingan,
|
' 平安卡券总数为:'.$pingan,
|
||||||
' 核销错误总数为:' . $error,
|
' 核销错误总数为:'.$error,
|
||||||
' 核销重复数据数为:' . $lists->count(),
|
' 核销重复数据数为:'.$lists->count(),
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($data as $info) {
|
foreach ($data as $info) {
|
||||||
@@ -69,4 +74,82 @@ class TestController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 设置日志关联
|
||||||
|
*
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date: 2022/1/19 11:12
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
*/
|
||||||
|
public function coupon(Request $request)
|
||||||
|
{
|
||||||
|
$type = $request->type ?? '';
|
||||||
|
$date = $request->date ?? '';
|
||||||
|
|
||||||
|
if (! $type) {
|
||||||
|
dd('type 错误');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $date) {
|
||||||
|
dd('date 错误');
|
||||||
|
}
|
||||||
|
|
||||||
|
$name = 'api_log_'.$date;//表名
|
||||||
|
if (! Schema::hasTable($name)) {
|
||||||
|
dd('数据表不存在');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! Schema::hasColumn($name, 'coupon_no')) {
|
||||||
|
Schema::table($name, function (Blueprint $table) {
|
||||||
|
$table->string('coupon_no')->after('out_source')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置日志
|
||||||
|
*/
|
||||||
|
if ($type == 'log') {
|
||||||
|
|
||||||
|
(new Log())->setTable($name)
|
||||||
|
->whereNull('coupon_no')
|
||||||
|
->where('path', 'http://api.pingan.com.cn/open/vassPartner/appsvr/property/api/new/partner/redemption')
|
||||||
|
->where('out_source->code', 200)
|
||||||
|
->chunkById(1000, function ($logs) use ($name) {
|
||||||
|
foreach ($logs as $log) {
|
||||||
|
$data = (new Verification())->decrypt($log->in_source['json']['data']);
|
||||||
|
$data = json_decode($data, true);
|
||||||
|
$log->update([
|
||||||
|
'coupon_no' => $data['couponNo']
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dd($name.' 表日志设置完成');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($type == 'coupon') {
|
||||||
|
(new Log())->setTable($name)
|
||||||
|
->whereHas('coupon', function ($q) {
|
||||||
|
$q->whereNull('pa_order_id');
|
||||||
|
})
|
||||||
|
->where('path', 'http://api.pingan.com.cn/open/vassPartner/appsvr/property/api/new/partner/redemption')
|
||||||
|
->where('out_source->code', 200)
|
||||||
|
->chunkById(1000, function ($logs) use ($name) {
|
||||||
|
foreach ($logs as $log) {
|
||||||
|
$log->coupon->update([
|
||||||
|
'pa_order_id' => $log->out_source['data']['orderId'],
|
||||||
|
'pa_sub_order_id' => $log->out_source['data']['subOrderId'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dd($name.' 表关联的优惠券设置完成');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
dd(1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ Route::group([
|
|||||||
|
|
||||||
$router->get('/', 'HomeController@index')->name('admin.home');
|
$router->get('/', 'HomeController@index')->name('admin.home');
|
||||||
$router->get('test', 'TestController@index')->name('test.index');
|
$router->get('test', 'TestController@index')->name('test.index');
|
||||||
|
$router->get('test/coupon', 'TestController@coupon')->name('test.index');
|
||||||
|
|
||||||
$router->post('uploads/editor', 'UploadController@editor')->name('uploads.editor');
|
$router->post('uploads/editor', 'UploadController@editor')->name('uploads.editor');
|
||||||
|
|
||||||
|
|||||||
@@ -33,11 +33,11 @@ class Log extends Model
|
|||||||
public function __construct(array $attributes = [])
|
public function __construct(array $attributes = [])
|
||||||
{
|
{
|
||||||
parent::__construct($attributes);
|
parent::__construct($attributes);
|
||||||
if (!$this->table) {
|
if (! $this->table) {
|
||||||
$this->table = 'api_log_' . date('Ym');
|
$this->table = 'api_log_'.date('Ym');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Schema::hasTable($this->table)) {
|
if (! Schema::hasTable($this->table)) {
|
||||||
Schema::create($this->table, function (Blueprint $table) {
|
Schema::create($this->table, function (Blueprint $table) {
|
||||||
$table->increments('id');
|
$table->increments('id');
|
||||||
$table->string('path', 255);
|
$table->string('path', 255);
|
||||||
@@ -62,6 +62,7 @@ class Log extends Model
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 为数组 / JSON 序列化准备日期。
|
* 为数组 / JSON 序列化准备日期。
|
||||||
|
*
|
||||||
* @param \DateTimeInterface $date
|
* @param \DateTimeInterface $date
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -70,4 +71,15 @@ class Log extends Model
|
|||||||
return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
|
return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 关联优惠券
|
||||||
|
*
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date: 2022/1/19 11:24
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||||
|
*/
|
||||||
|
public function coupon()
|
||||||
|
{
|
||||||
|
return $this->hasOne(Coupon::class, 'redemptionCode', 'coupon_no');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user